nextgen-block-editor 0.3.1 → 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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/components/BlockEditor.tsx
2
- import React4, { useEffect as useEffect2, useImperativeHandle, useRef as useRef2, useState as useState3 } from "react";
2
+ import React5, { useEffect as useEffect2, useImperativeHandle, useRef as useRef2, useState as useState4 } from "react";
3
3
  import EditorJS2 from "@editorjs/editorjs";
4
4
  import DragDrop from "editorjs-drag-drop";
5
5
  import Undo from "editorjs-undo";
@@ -252,7 +252,7 @@ function sanitizeInlineHtml(value) {
252
252
  element.replaceWith(document.createTextNode(element.textContent || ""));
253
253
  return;
254
254
  }
255
- if (element.tagName === "SPAN" && !element.classList.contains("editor-inline-spoiler")) {
255
+ if (element.tagName === "SPAN" && !element.classList.contains("editor-inline-spoiler") && !element.classList.contains("ng-inline-color")) {
256
256
  element.replaceWith(document.createTextNode(element.textContent || ""));
257
257
  return;
258
258
  }
@@ -261,7 +261,10 @@ function sanitizeInlineHtml(value) {
261
261
  if (element.tagName === "A" && attribute.name === "class" && attribute.value === "editor-mention") {
262
262
  return;
263
263
  }
264
- if (element.tagName === "SPAN" && attribute.name === "class" && attribute.value === "editor-inline-spoiler") {
264
+ if (element.tagName === "SPAN" && attribute.name === "class" && (attribute.value === "editor-inline-spoiler" || attribute.value === "ng-inline-color")) {
265
+ return;
266
+ }
267
+ if (element.tagName === "SPAN" && element.classList.contains("ng-inline-color") && attribute.name === "style") {
265
268
  return;
266
269
  }
267
270
  if (["target", "rel"].includes(attribute.name) && element.tagName === "A") return;
@@ -545,9 +548,12 @@ function blocksToHtml(data) {
545
548
  }).join("") + "</div>";
546
549
  }
547
550
  if (block.type === "embed") {
548
- return d.embed ? `<iframe src="${escHtml(d.embed)}" title="${escHtml(
549
- d.caption
550
- )}" loading="lazy"></iframe>` : "";
551
+ if (!d.embed) return "";
552
+ const align = ["left", "center", "right"].includes(d.align) ? d.align : "center";
553
+ const size = ["small", "medium", "large", "full"].includes(d.size) ? d.size : "medium";
554
+ return `<div class="editor-embed-wrap" data-align="${align}" data-size="${size}"><iframe src="${escHtml(
555
+ d.embed
556
+ )}" title="${escHtml(d.caption)}" loading="lazy" allowfullscreen></iframe></div>`;
551
557
  }
552
558
  if (block.type === "attaches") {
553
559
  const attachmentUrl = d.file && d.file.url ? d.file.url : d.dataUrl || "";
@@ -597,6 +603,85 @@ function blocksToHtml(data) {
597
603
  d.text || ""
598
604
  )}</div></div>${overlay}</div>`;
599
605
  }
606
+ if (block.type === "mermaid") {
607
+ const code = String(d.code || "");
608
+ const caption = d.caption ? `<figcaption>${escHtml(d.caption)}</figcaption>` : "";
609
+ return `<figure class="editor-mermaid-block"><div class="editor-mermaid-diagram" data-mermaid="${escHtml(
610
+ code
611
+ )}"><pre class="editor-mermaid-fallback">${escHtml(code)}</pre></div>${caption}</figure>`;
612
+ }
613
+ if (block.type === "bookmark") {
614
+ const url = String(d.url || "#");
615
+ let host = url;
616
+ try {
617
+ host = new URL(url).hostname;
618
+ } catch {
619
+ }
620
+ return `<a class="editor-bookmark-card" href="${escHtml(
621
+ url
622
+ )}" target="_blank" rel="noopener noreferrer"><div class="editor-bookmark-body"><div class="editor-bookmark-title">${escHtml(
623
+ d.title || host
624
+ )}</div>${d.description ? `<div class="editor-bookmark-desc">${escHtml(d.description)}</div>` : ""}<div class="editor-bookmark-url">${escHtml(host)}</div></div>${d.image ? `<img class="editor-bookmark-thumb" src="${escHtml(d.image)}" alt="" loading="lazy">` : ""}</a>`;
625
+ }
626
+ if (block.type === "steps") {
627
+ const items = Array.isArray(d.items) ? d.items : [];
628
+ return `<ol class="editor-steps-list">${items.map(
629
+ (item, idx) => `<li class="editor-step-item"><div class="editor-step-badge">${idx + 1}</div><div class="editor-step-content"><h4>${escHtml(
630
+ item.title || `Step ${idx + 1}`
631
+ )}</h4><p>${escHtml(item.body || "")}</p></div></li>`
632
+ ).join("")}</ol>`;
633
+ }
634
+ if (block.type === "diff") {
635
+ const before = String(d.before || "").split("\n");
636
+ const after = String(d.after || "").split("\n");
637
+ const max = Math.max(before.length, after.length);
638
+ const rows = [];
639
+ for (let i = 0; i < max; i += 1) {
640
+ if (before[i] === after[i]) {
641
+ if (before[i] !== void 0) {
642
+ rows.push(`<span class="editor-diff-line is-same"> ${escHtml(before[i])}</span>`);
643
+ }
644
+ } else {
645
+ if (before[i] !== void 0) {
646
+ rows.push(`<span class="editor-diff-line is-del">- ${escHtml(before[i])}</span>`);
647
+ }
648
+ if (after[i] !== void 0) {
649
+ rows.push(`<span class="editor-diff-line is-add">+ ${escHtml(after[i])}</span>`);
650
+ }
651
+ }
652
+ }
653
+ return `<div class="editor-diff-block">${d.filename ? `<div class="editor-diff-filename">${escHtml(d.filename)}</div>` : ""}<pre class="editor-diff-preview">${rows.join("\n")}</pre></div>`;
654
+ }
655
+ if (block.type === "video") {
656
+ if (!d.url) return "";
657
+ return `<figure class="editor-video-block"><video controls preload="metadata" class="editor-video-el"${d.poster ? ` poster="${escHtml(d.poster)}"` : ""}><source src="${escHtml(d.url)}"></video>${d.caption ? `<figcaption>${escHtml(d.caption)}</figcaption>` : ""}</figure>`;
658
+ }
659
+ if (block.type === "changelog") {
660
+ const items = Array.isArray(d.items) ? d.items : [];
661
+ return `<section class="editor-changelog-block"><div class="editor-changelog-head"><span class="editor-changelog-version">${escHtml(
662
+ d.version || "v1.0.0"
663
+ )}</span><span class="editor-changelog-date">${escHtml(
664
+ d.date || ""
665
+ )}</span></div><ul class="editor-changelog-list">${items.map(
666
+ (i) => `<li><span class="editor-changelog-badge is-${escHtml(
667
+ i.kind || "added"
668
+ )}">${escHtml((i.kind || "added").toUpperCase())}</span><span>${escHtml(
669
+ i.text || ""
670
+ )}</span></li>`
671
+ ).join("")}</ul></section>`;
672
+ }
673
+ if (block.type === "today") {
674
+ return `<div class="editor-today-pill"><span class="editor-today-badge">\u{1F4C5} ${escHtml(
675
+ d.date || ""
676
+ )}</span></div>`;
677
+ }
678
+ if (block.type === "social") {
679
+ return `<blockquote class="editor-social-card"><div class="editor-social-head"><strong>${escHtml(
680
+ d.author || ""
681
+ )}</strong><span>${escHtml(d.handle || "")}</span>${d.date ? `<span>\xB7 ${escHtml(d.date)}</span>` : ""}</div><p class="editor-social-text">${escHtml(d.text || "")}</p>${d.url ? `<a class="editor-social-link" href="${escHtml(
682
+ d.url
683
+ )}" target="_blank" rel="noopener noreferrer">View original post \u2192</a>` : ""}</blockquote>`;
684
+ }
600
685
  if (block.type === "alert") {
601
686
  const variant = ["info", "tip", "warning", "danger"].includes(d.variant) ? d.variant : "info";
602
687
  const icons = {
@@ -4843,203 +4928,1221 @@ var TagsTool = class {
4843
4928
  }
4844
4929
  };
4845
4930
 
4846
- // src/editorTools.ts
4847
- var CustomMediaTool = class {
4848
- data;
4849
- elements;
4850
- constructor(options) {
4851
- this.data = options.data || {};
4931
+ // src/blocks/mermaidBlock.ts
4932
+ import mermaid from "mermaid";
4933
+ var MERMAID_PRESETS = {
4934
+ Flowchart: `graph TD
4935
+ A[Start] --> B{Condition?}
4936
+ B -->|Yes| C[Proceed]
4937
+ B -->|No| D[Retry]`,
4938
+ Sequence: `sequenceDiagram
4939
+ User->>Editor: Type /mermaid
4940
+ Editor->>Mermaid: Render SVG
4941
+ Mermaid-->>User: Interactive Diagram`,
4942
+ Mindmap: `mindmap
4943
+ root((NextGen Editor))
4944
+ Blocks
4945
+ Mermaid
4946
+ Charts
4947
+ Code
4948
+ AI
4949
+ Rewrite
4950
+ Continue`
4951
+ };
4952
+ var mermaidInitialized = false;
4953
+ var mermaidCounter = 0;
4954
+ function ensureMermaidInit() {
4955
+ if (mermaidInitialized) return;
4956
+ mermaidInitialized = true;
4957
+ mermaid.initialize({
4958
+ startOnLoad: false,
4959
+ securityLevel: "strict",
4960
+ theme: "neutral"
4961
+ });
4962
+ }
4963
+ async function renderMermaidInto(container, code) {
4964
+ const trimmed = code.trim();
4965
+ if (!trimmed) {
4966
+ container.innerHTML = '<span class="editor-mermaid-empty">Enter Mermaid syntax to preview</span>';
4967
+ return;
4968
+ }
4969
+ ensureMermaidInit();
4970
+ const id = `ng-mermaid-${++mermaidCounter}`;
4971
+ try {
4972
+ const { svg } = await mermaid.render(id, trimmed);
4973
+ container.innerHTML = svg;
4974
+ } catch (err) {
4975
+ const message = err instanceof Error ? err.message : "Invalid Mermaid syntax";
4976
+ container.innerHTML = `<pre class="editor-mermaid-error">${message.replace(/</g, "&lt;")}</pre>`;
4852
4977
  }
4978
+ }
4979
+ var MermaidTool = class {
4980
+ data;
4981
+ renderSeq = 0;
4853
4982
  static get toolbox() {
4854
4983
  return {
4855
- title: "Image",
4856
- 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>'
4984
+ title: "Mermaid Diagram",
4985
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="6" height="6" rx="1"/><rect x="15" y="3" width="6" height="6" rx="1"/><rect x="9" y="15" width="6" height="6" rx="1"/><path d="M6 9v3a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V9"/><path d="M12 12v3"/></svg>'
4986
+ };
4987
+ }
4988
+ constructor({ data }) {
4989
+ this.data = {
4990
+ code: data?.code ?? MERMAID_PRESETS.Flowchart,
4991
+ caption: data?.caption ?? ""
4857
4992
  };
4858
4993
  }
4859
4994
  render() {
4860
- const root = document.createElement("div");
4861
- root.className = "custom-media-fields";
4862
- const input = document.createElement("input");
4863
- input.type = "text";
4864
- input.placeholder = "Paste image URL";
4865
- input.value = this.data.url || "";
4866
- const file = document.createElement("input");
4867
- file.type = "file";
4868
- file.accept = "image/*";
4869
- const caption = document.createElement("input");
4870
- caption.type = "text";
4871
- caption.placeholder = "Caption";
4872
- caption.value = this.data.caption || "";
4995
+ const wrap = document.createElement("div");
4996
+ wrap.className = "editor-mermaid-tool";
4997
+ const head = document.createElement("div");
4998
+ head.className = "editor-mermaid-head";
4999
+ const title = document.createElement("span");
5000
+ title.className = "editor-mermaid-label";
5001
+ title.textContent = "Mermaid Diagram";
5002
+ const presets = document.createElement("div");
5003
+ presets.className = "editor-mermaid-presets";
5004
+ Object.entries(MERMAID_PRESETS).forEach(([label, snippet]) => {
5005
+ const btn = document.createElement("button");
5006
+ btn.type = "button";
5007
+ btn.className = "editor-mermaid-preset-btn";
5008
+ btn.textContent = label;
5009
+ btn.addEventListener("click", () => {
5010
+ this.data.code = snippet;
5011
+ textarea.value = snippet;
5012
+ void updatePreview();
5013
+ });
5014
+ presets.appendChild(btn);
5015
+ });
5016
+ head.append(title, presets);
5017
+ const textarea = document.createElement("textarea");
5018
+ textarea.className = "editor-mermaid-input";
5019
+ textarea.rows = 5;
5020
+ textarea.placeholder = "graph TD\n A --> B";
5021
+ textarea.value = this.data.code;
4873
5022
  const preview = document.createElement("div");
4874
- preview.className = "custom-media-preview";
4875
- const paint = (url) => {
4876
- preview.innerHTML = url ? `<img src="${escHtml(url)}" alt="">` : "";
4877
- };
4878
- paint(input.value);
4879
- input.oninput = () => paint(input.value);
4880
- file.onchange = async () => {
4881
- const selected = file.files?.[0];
4882
- if (!selected) return;
4883
- const bucketUrl = await uploadFileToBucket(selected, "writing");
4884
- if (bucketUrl) {
4885
- input.value = bucketUrl;
4886
- paint(bucketUrl);
4887
- return;
4888
- }
4889
- const reader = new FileReader();
4890
- reader.onload = () => {
4891
- const res = String(reader.result || "");
4892
- input.value = res;
4893
- paint(res);
4894
- };
4895
- reader.readAsDataURL(selected);
5023
+ preview.className = "editor-mermaid-preview";
5024
+ const captionInput = document.createElement("input");
5025
+ captionInput.type = "text";
5026
+ captionInput.className = "editor-mermaid-caption cdx-input";
5027
+ captionInput.placeholder = "Optional diagram caption";
5028
+ captionInput.value = this.data.caption || "";
5029
+ const updatePreview = async () => {
5030
+ const seq = ++this.renderSeq;
5031
+ await renderMermaidInto(preview, this.data.code);
5032
+ if (seq !== this.renderSeq) return;
4896
5033
  };
4897
- root.append(input, file, caption, preview);
4898
- this.elements = { root, input, caption };
4899
- return root;
5034
+ textarea.addEventListener("input", () => {
5035
+ this.data.code = textarea.value;
5036
+ void updatePreview();
5037
+ });
5038
+ captionInput.addEventListener("input", () => {
5039
+ this.data.caption = captionInput.value;
5040
+ });
5041
+ void updatePreview();
5042
+ wrap.append(head, textarea, preview, captionInput);
5043
+ return wrap;
4900
5044
  }
4901
5045
  save() {
4902
5046
  return {
4903
- url: this.elements?.input.value.trim() || "",
4904
- caption: this.elements?.caption.value.trim() || ""
5047
+ code: this.data.code,
5048
+ caption: this.data.caption?.trim() || void 0
4905
5049
  };
4906
5050
  }
4907
5051
  };
4908
- var GifTool = class {
5052
+
5053
+ // src/blocks/extraBlocks.ts
5054
+ function createInput(type, className, placeholder, value, onInput) {
5055
+ const input = document.createElement("input");
5056
+ input.type = type;
5057
+ input.className = className;
5058
+ input.placeholder = placeholder;
5059
+ input.value = value;
5060
+ input.addEventListener("input", () => onInput(input.value));
5061
+ return input;
5062
+ }
5063
+ function createTextarea(className, rows, placeholder, value, onInput) {
5064
+ const ta = document.createElement("textarea");
5065
+ ta.className = className;
5066
+ ta.rows = rows;
5067
+ ta.placeholder = placeholder;
5068
+ ta.value = value;
5069
+ ta.addEventListener("input", () => onInput(ta.value));
5070
+ return ta;
5071
+ }
5072
+ var BookmarkTool = class {
4909
5073
  data;
4910
- elements;
4911
- constructor(options) {
4912
- this.data = options.data || {};
4913
- }
4914
5074
  static get toolbox() {
4915
5075
  return {
4916
- title: "GIF",
4917
- 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>'
5076
+ title: "Bookmark",
5077
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z"/></svg>'
5078
+ };
5079
+ }
5080
+ constructor({ data }) {
5081
+ this.data = {
5082
+ url: data?.url ?? "",
5083
+ title: data?.title ?? "",
5084
+ description: data?.description ?? "",
5085
+ image: data?.image ?? ""
4918
5086
  };
4919
5087
  }
4920
5088
  render() {
4921
- const root = document.createElement("div");
4922
- root.className = "custom-media-fields";
4923
- const searchRow = document.createElement("div");
4924
- searchRow.className = "gif-search-row";
4925
- const searchInput = document.createElement("input");
4926
- searchInput.type = "search";
4927
- searchInput.placeholder = "Search free GIFs (trending or keyword)...";
4928
- const searchBtn = document.createElement("button");
4929
- searchBtn.type = "button";
4930
- searchBtn.className = "b2";
4931
- searchBtn.textContent = "Search";
4932
- searchRow.append(searchInput, searchBtn);
4933
- const resultsGrid = document.createElement("div");
4934
- resultsGrid.className = "gif-picker-grid";
4935
- const url = document.createElement("input");
4936
- url.type = "url";
4937
- url.placeholder = "Or paste GIF / image URL";
4938
- url.value = this.data.url || "";
4939
- const caption = document.createElement("input");
4940
- caption.type = "text";
4941
- caption.placeholder = "Caption";
4942
- caption.value = this.data.caption || "";
5089
+ const wrap = document.createElement("div");
5090
+ wrap.className = "editor-extra-card";
5091
+ const head = document.createElement("div");
5092
+ head.className = "editor-extra-head";
5093
+ head.textContent = "URL Bookmark Card";
4943
5094
  const preview = document.createElement("div");
4944
- preview.className = "custom-media-preview";
4945
- const paint = () => {
4946
- preview.innerHTML = url.value ? `<img src="${escHtml(url.value)}" alt="${escHtml(caption.value || "GIF")}">` : "";
4947
- };
4948
- paint();
4949
- url.oninput = paint;
4950
- const runSearch = async (query) => {
4951
- resultsGrid.innerHTML = '<span class="gif-picker-status">Loading GIFs\u2026</span>';
4952
- try {
4953
- const res = await fetch(
4954
- `/api/gifs?q=${encodeURIComponent(query)}&limit=12`
4955
- );
4956
- const json = await res.json();
4957
- const items = json.results || [];
4958
- if (!items.length) {
4959
- resultsGrid.innerHTML = '<span class="gif-picker-status">No GIFs found. Try another keyword or paste a URL below.</span>';
4960
- return;
5095
+ preview.className = "editor-bookmark-preview";
5096
+ const refreshPreview = () => {
5097
+ const host = (() => {
5098
+ try {
5099
+ return this.data.url ? new URL(this.data.url).hostname : "example.com";
5100
+ } catch {
5101
+ return this.data.url || "example.com";
4961
5102
  }
4962
- resultsGrid.innerHTML = "";
4963
- items.forEach((item) => {
4964
- const btn = document.createElement("button");
4965
- btn.type = "button";
4966
- btn.className = "gif-picker-item";
4967
- btn.title = item.title;
4968
- btn.innerHTML = `<img src="${escHtml(item.previewUrl)}" alt="${escHtml(item.title)}" loading="lazy">`;
4969
- btn.onclick = () => {
4970
- url.value = item.url;
4971
- if (!caption.value) caption.value = item.title;
4972
- paint();
4973
- };
4974
- resultsGrid.appendChild(btn);
4975
- });
4976
- } catch {
4977
- resultsGrid.innerHTML = '<span class="gif-picker-status">Could not load GIFs. Paste a GIF URL below.</span>';
4978
- }
5103
+ })();
5104
+ preview.innerHTML = `
5105
+ <div class="editor-bookmark-card">
5106
+ <div class="editor-bookmark-body">
5107
+ <div class="editor-bookmark-title">${escHtml(this.data.title || host)}</div>
5108
+ ${this.data.description ? `<div class="editor-bookmark-desc">${escHtml(this.data.description)}</div>` : ""}
5109
+ <div class="editor-bookmark-url">${escHtml(host)}</div>
5110
+ </div>
5111
+ ${this.data.image ? `<img class="editor-bookmark-thumb" src="${escHtml(this.data.image)}" alt="" />` : ""}
5112
+ </div>`;
4979
5113
  };
4980
- searchBtn.onclick = () => void runSearch(searchInput.value);
4981
- searchInput.addEventListener("keydown", (e) => {
4982
- if (e.key === "Enter") {
4983
- e.preventDefault();
4984
- e.stopPropagation();
4985
- void runSearch(searchInput.value);
4986
- }
4987
- });
4988
- if (!this.data.url) {
4989
- void runSearch("");
4990
- }
4991
- root.append(searchRow, resultsGrid, url, caption, preview);
4992
- this.elements = { url, caption };
4993
- return root;
5114
+ const grid = document.createElement("div");
5115
+ grid.className = "editor-extra-grid";
5116
+ grid.append(
5117
+ createInput("url", "cdx-input", "https://example.com/article", this.data.url, (v) => {
5118
+ this.data.url = v;
5119
+ refreshPreview();
5120
+ }),
5121
+ createInput("text", "cdx-input", "Link title", this.data.title, (v) => {
5122
+ this.data.title = v;
5123
+ refreshPreview();
5124
+ }),
5125
+ createInput("text", "cdx-input", "Short description", this.data.description, (v) => {
5126
+ this.data.description = v;
5127
+ refreshPreview();
5128
+ }),
5129
+ createInput("url", "cdx-input", "Optional thumbnail URL", this.data.image || "", (v) => {
5130
+ this.data.image = v;
5131
+ refreshPreview();
5132
+ })
5133
+ );
5134
+ refreshPreview();
5135
+ wrap.append(head, grid, preview);
5136
+ return wrap;
4994
5137
  }
4995
5138
  save() {
4996
5139
  return {
4997
- url: this.elements?.url.value.trim() || "",
4998
- caption: this.elements?.caption.value.trim() || ""
5140
+ url: this.data.url.trim(),
5141
+ title: this.data.title.trim(),
5142
+ description: this.data.description.trim(),
5143
+ image: this.data.image?.trim() || void 0
4999
5144
  };
5000
5145
  }
5001
5146
  };
5002
- var AttachTool = class {
5147
+ var StepsTool = class {
5003
5148
  data;
5004
- elements;
5005
- constructor(options) {
5006
- this.data = options.data || {};
5007
- }
5008
5149
  static get toolbox() {
5009
5150
  return {
5010
- title: "Attachment",
5011
- 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>'
5151
+ title: "Steps",
5152
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="10" x2="21" y1="6" y2="6"/><line x1="10" x2="21" y1="12" y2="12"/><line x1="10" x2="21" y1="18" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>'
5012
5153
  };
5013
5154
  }
5014
- render() {
5015
- const root = document.createElement("div");
5016
- root.className = "custom-media-fields";
5017
- const file = document.createElement("input");
5018
- file.type = "file";
5019
- const name = document.createElement("input");
5020
- name.type = "text";
5021
- name.placeholder = "Attachment label";
5022
- name.value = this.data.name || "";
5023
- root.append(file, name);
5024
- const elements = {
5025
- file,
5026
- name,
5027
- dataUrl: this.data.dataUrl || "",
5028
- dataName: this.data.name || ""
5155
+ constructor({ data }) {
5156
+ this.data = {
5157
+ items: Array.isArray(data?.items) && data.items.length > 0 ? data.items.map((item) => ({ title: item.title || "", body: item.body || "" })) : [
5158
+ { title: "Install dependencies", body: "Run npm install to set up the package." },
5159
+ { title: "Configure & render", body: "Pass initialData and onChange to BlockEditor." }
5160
+ ]
5029
5161
  };
5030
- this.elements = elements;
5031
- file.onchange = () => {
5032
- const selected = file.files?.[0];
5033
- if (!selected) return;
5034
- const reader = new FileReader();
5035
- reader.onload = () => {
5036
- elements.dataUrl = String(reader.result || "");
5037
- elements.dataName = selected.name;
5038
- if (!name.value) name.value = selected.name;
5039
- };
5040
- reader.readAsDataURL(selected);
5162
+ }
5163
+ render() {
5164
+ const wrap = document.createElement("div");
5165
+ wrap.className = "editor-extra-card";
5166
+ const head = document.createElement("div");
5167
+ head.className = "editor-extra-head";
5168
+ head.textContent = "Step-by-Step Walkthrough";
5169
+ const list = document.createElement("div");
5170
+ list.className = "editor-steps-editor-list";
5171
+ const renderList = () => {
5172
+ list.innerHTML = "";
5173
+ this.data.items.forEach((item, idx) => {
5174
+ const row = document.createElement("div");
5175
+ row.className = "editor-step-editor-row";
5176
+ const badge = document.createElement("span");
5177
+ badge.className = "editor-step-badge";
5178
+ badge.textContent = String(idx + 1);
5179
+ const fields = document.createElement("div");
5180
+ fields.className = "editor-step-editor-fields";
5181
+ fields.append(
5182
+ createInput("text", "cdx-input", `Step ${idx + 1} title`, item.title, (v) => {
5183
+ item.title = v;
5184
+ }),
5185
+ createTextarea("cdx-input", 2, "Step details", item.body, (v) => {
5186
+ item.body = v;
5187
+ })
5188
+ );
5189
+ const removeBtn = document.createElement("button");
5190
+ removeBtn.type = "button";
5191
+ removeBtn.className = "excalidraw-btn";
5192
+ removeBtn.textContent = "\xD7";
5193
+ removeBtn.title = "Remove step";
5194
+ removeBtn.addEventListener("click", () => {
5195
+ if (this.data.items.length <= 1) return;
5196
+ this.data.items.splice(idx, 1);
5197
+ renderList();
5198
+ });
5199
+ row.append(badge, fields, removeBtn);
5200
+ list.appendChild(row);
5201
+ });
5041
5202
  };
5042
- return root;
5203
+ const addBtn = document.createElement("button");
5204
+ addBtn.type = "button";
5205
+ addBtn.className = "excalidraw-btn";
5206
+ addBtn.textContent = "+ Add Step";
5207
+ addBtn.addEventListener("click", () => {
5208
+ this.data.items.push({ title: "", body: "" });
5209
+ renderList();
5210
+ });
5211
+ renderList();
5212
+ wrap.append(head, list, addBtn);
5213
+ return wrap;
5214
+ }
5215
+ save() {
5216
+ return {
5217
+ items: this.data.items.filter((i) => i.title.trim() || i.body.trim())
5218
+ };
5219
+ }
5220
+ };
5221
+ function computeSimpleDiff(before, after) {
5222
+ const a = before.split("\n");
5223
+ const b = after.split("\n");
5224
+ const lines = [];
5225
+ const max = Math.max(a.length, b.length);
5226
+ for (let i = 0; i < max; i += 1) {
5227
+ const left = a[i];
5228
+ const right = b[i];
5229
+ if (left === right) {
5230
+ if (left !== void 0) lines.push({ kind: "same", text: left });
5231
+ } else {
5232
+ if (left !== void 0) lines.push({ kind: "del", text: left });
5233
+ if (right !== void 0) lines.push({ kind: "add", text: right });
5234
+ }
5235
+ }
5236
+ return lines;
5237
+ }
5238
+ var DiffTool = class {
5239
+ data;
5240
+ static get toolbox() {
5241
+ return {
5242
+ title: "Code Diff",
5243
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3v14"/><path d="M5 10h14"/><path d="M5 21h14"/></svg>'
5244
+ };
5245
+ }
5246
+ constructor({ data }) {
5247
+ this.data = {
5248
+ filename: data?.filename ?? "example.ts",
5249
+ before: data?.before ?? 'const theme = "catppuccin";',
5250
+ after: data?.after ?? 'const theme = "dark";'
5251
+ };
5252
+ }
5253
+ render() {
5254
+ const wrap = document.createElement("div");
5255
+ wrap.className = "editor-extra-card";
5256
+ const head = document.createElement("div");
5257
+ head.className = "editor-extra-head";
5258
+ head.textContent = "Code Diff Viewer";
5259
+ const preview = document.createElement("pre");
5260
+ preview.className = "editor-diff-preview";
5261
+ const refreshPreview = () => {
5262
+ const diffLines = computeSimpleDiff(this.data.before, this.data.after);
5263
+ preview.innerHTML = diffLines.map((line) => {
5264
+ const prefix = line.kind === "del" ? "-" : line.kind === "add" ? "+" : " ";
5265
+ return `<span class="editor-diff-line is-${line.kind}">${prefix} ${escHtml(line.text)}</span>`;
5266
+ }).join("\n");
5267
+ };
5268
+ const cols = document.createElement("div");
5269
+ cols.className = "editor-diff-inputs";
5270
+ cols.append(
5271
+ createTextarea("editor-mermaid-input", 4, "Before code...", this.data.before, (v) => {
5272
+ this.data.before = v;
5273
+ refreshPreview();
5274
+ }),
5275
+ createTextarea("editor-mermaid-input", 4, "After code...", this.data.after, (v) => {
5276
+ this.data.after = v;
5277
+ refreshPreview();
5278
+ })
5279
+ );
5280
+ const fileInput = createInput("text", "cdx-input", "Filename (optional)", this.data.filename || "", (v) => {
5281
+ this.data.filename = v;
5282
+ });
5283
+ refreshPreview();
5284
+ wrap.append(head, fileInput, cols, preview);
5285
+ return wrap;
5286
+ }
5287
+ save() {
5288
+ return {
5289
+ filename: this.data.filename?.trim() || void 0,
5290
+ before: this.data.before,
5291
+ after: this.data.after
5292
+ };
5293
+ }
5294
+ };
5295
+ var VideoTool = class {
5296
+ data;
5297
+ static get toolbox() {
5298
+ return {
5299
+ title: "Video Player",
5300
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="6 3 20 12 6 21 6 3"/></svg>'
5301
+ };
5302
+ }
5303
+ constructor({ data }) {
5304
+ this.data = {
5305
+ url: data?.url ?? "",
5306
+ poster: data?.poster ?? "",
5307
+ caption: data?.caption ?? ""
5308
+ };
5309
+ }
5310
+ render() {
5311
+ const wrap = document.createElement("div");
5312
+ wrap.className = "editor-extra-card";
5313
+ const head = document.createElement("div");
5314
+ head.className = "editor-extra-head";
5315
+ head.textContent = "Video Player (MP4 / WebM)";
5316
+ const preview = document.createElement("div");
5317
+ preview.className = "editor-video-preview";
5318
+ const refreshPreview = () => {
5319
+ if (!this.data.url.trim()) {
5320
+ preview.innerHTML = '<div class="editor-mermaid-empty">Paste a video URL or upload a file</div>';
5321
+ return;
5322
+ }
5323
+ preview.innerHTML = `<video controls preload="metadata" class="editor-video-el"${this.data.poster ? ` poster="${escHtml(this.data.poster)}"` : ""}><source src="${escHtml(this.data.url)}" /></video>`;
5324
+ };
5325
+ const urlInput = createInput("url", "cdx-input", "https://.../video.mp4", this.data.url, (v) => {
5326
+ this.data.url = v;
5327
+ refreshPreview();
5328
+ });
5329
+ const uploadInput = document.createElement("input");
5330
+ uploadInput.type = "file";
5331
+ uploadInput.accept = "video/mp4,video/webm,video/ogg";
5332
+ uploadInput.className = "cdx-input";
5333
+ uploadInput.addEventListener("change", async () => {
5334
+ const file = uploadInput.files?.[0];
5335
+ if (!file) return;
5336
+ const uploaded = await uploadFileToBucket(file, "videos");
5337
+ if (uploaded) {
5338
+ this.data.url = uploaded;
5339
+ urlInput.value = uploaded;
5340
+ refreshPreview();
5341
+ }
5342
+ });
5343
+ const posterInput = createInput("url", "cdx-input", "Optional poster image URL", this.data.poster || "", (v) => {
5344
+ this.data.poster = v;
5345
+ refreshPreview();
5346
+ });
5347
+ const captionInput = createInput("text", "cdx-input", "Optional video caption", this.data.caption || "", (v) => {
5348
+ this.data.caption = v;
5349
+ });
5350
+ refreshPreview();
5351
+ wrap.append(head, urlInput, uploadInput, posterInput, captionInput, preview);
5352
+ return wrap;
5353
+ }
5354
+ save() {
5355
+ return {
5356
+ url: this.data.url.trim(),
5357
+ poster: this.data.poster?.trim() || void 0,
5358
+ caption: this.data.caption?.trim() || void 0
5359
+ };
5360
+ }
5361
+ };
5362
+ var ChangelogTool = class {
5363
+ data;
5364
+ static get toolbox() {
5365
+ return {
5366
+ title: "Changelog",
5367
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M16 13H8"/><path d="M16 17H8"/></svg>'
5368
+ };
5369
+ }
5370
+ constructor({ data }) {
5371
+ this.data = {
5372
+ version: data?.version ?? "v1.0.0",
5373
+ date: data?.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
5374
+ items: Array.isArray(data?.items) && data.items.length > 0 ? data.items.map((i) => ({ kind: i.kind || "added", text: i.text || "" })) : [{ kind: "added", text: "Initial release notes" }]
5375
+ };
5376
+ }
5377
+ render() {
5378
+ const wrap = document.createElement("div");
5379
+ wrap.className = "editor-extra-card";
5380
+ const head = document.createElement("div");
5381
+ head.className = "editor-extra-head";
5382
+ head.textContent = "Release Changelog";
5383
+ const meta = document.createElement("div");
5384
+ meta.className = "editor-diff-inputs";
5385
+ meta.append(
5386
+ createInput("text", "cdx-input", "Version (e.g. v1.2.0)", this.data.version, (v) => {
5387
+ this.data.version = v;
5388
+ }),
5389
+ createInput("date", "cdx-input", "Release date", this.data.date, (v) => {
5390
+ this.data.date = v;
5391
+ })
5392
+ );
5393
+ const list = document.createElement("div");
5394
+ list.className = "editor-steps-editor-list";
5395
+ const renderItems = () => {
5396
+ list.innerHTML = "";
5397
+ this.data.items.forEach((item, idx) => {
5398
+ const row = document.createElement("div");
5399
+ row.className = "editor-changelog-row";
5400
+ const select = document.createElement("select");
5401
+ select.className = "cdx-input editor-form-select";
5402
+ ["added", "changed", "fixed"].forEach((k) => {
5403
+ const opt = document.createElement("option");
5404
+ opt.value = k;
5405
+ opt.textContent = k.toUpperCase();
5406
+ if (item.kind === k) opt.selected = true;
5407
+ select.appendChild(opt);
5408
+ });
5409
+ select.addEventListener("change", () => {
5410
+ item.kind = select.value;
5411
+ });
5412
+ const text = createInput("text", "cdx-input", "Change description", item.text, (v) => {
5413
+ item.text = v;
5414
+ });
5415
+ const del = document.createElement("button");
5416
+ del.type = "button";
5417
+ del.className = "excalidraw-btn";
5418
+ del.textContent = "\xD7";
5419
+ del.addEventListener("click", () => {
5420
+ if (this.data.items.length <= 1) return;
5421
+ this.data.items.splice(idx, 1);
5422
+ renderItems();
5423
+ });
5424
+ row.append(select, text, del);
5425
+ list.appendChild(row);
5426
+ });
5427
+ };
5428
+ const addBtn = document.createElement("button");
5429
+ addBtn.type = "button";
5430
+ addBtn.className = "excalidraw-btn";
5431
+ addBtn.textContent = "+ Add Entry";
5432
+ addBtn.addEventListener("click", () => {
5433
+ this.data.items.push({ kind: "added", text: "" });
5434
+ renderItems();
5435
+ });
5436
+ renderItems();
5437
+ wrap.append(head, meta, list, addBtn);
5438
+ return wrap;
5439
+ }
5440
+ save() {
5441
+ return {
5442
+ version: this.data.version.trim() || "v1.0.0",
5443
+ date: this.data.date,
5444
+ items: this.data.items.filter((i) => i.text.trim())
5445
+ };
5446
+ }
5447
+ };
5448
+ var SocialTool = class {
5449
+ data;
5450
+ static get toolbox() {
5451
+ return {
5452
+ title: "Social Post",
5453
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>'
5454
+ };
5455
+ }
5456
+ constructor({ data }) {
5457
+ this.data = {
5458
+ author: data?.author ?? "Alex Rivera",
5459
+ handle: data?.handle ?? "@alexrivera",
5460
+ date: data?.date ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10),
5461
+ text: data?.text ?? "",
5462
+ url: data?.url ?? ""
5463
+ };
5464
+ }
5465
+ render() {
5466
+ const wrap = document.createElement("div");
5467
+ wrap.className = "editor-extra-card";
5468
+ const head = document.createElement("div");
5469
+ head.className = "editor-extra-head";
5470
+ head.textContent = "Social Post Quote Card";
5471
+ const meta = document.createElement("div");
5472
+ meta.className = "editor-diff-inputs";
5473
+ meta.append(
5474
+ createInput("text", "cdx-input", "Author name", this.data.author, (v) => {
5475
+ this.data.author = v;
5476
+ }),
5477
+ createInput("text", "cdx-input", "@handle", this.data.handle, (v) => {
5478
+ this.data.handle = v;
5479
+ })
5480
+ );
5481
+ const text = createTextarea("cdx-input", 3, "Quoted post content...", this.data.text, (v) => {
5482
+ this.data.text = v;
5483
+ });
5484
+ const extra = document.createElement("div");
5485
+ extra.className = "editor-diff-inputs";
5486
+ extra.append(
5487
+ createInput("text", "cdx-input", "Date (optional)", this.data.date || "", (v) => {
5488
+ this.data.date = v;
5489
+ }),
5490
+ createInput("url", "cdx-input", "Original post URL (optional)", this.data.url || "", (v) => {
5491
+ this.data.url = v;
5492
+ })
5493
+ );
5494
+ wrap.append(head, meta, text, extra);
5495
+ return wrap;
5496
+ }
5497
+ save() {
5498
+ return {
5499
+ author: this.data.author.trim(),
5500
+ handle: this.data.handle.trim(),
5501
+ date: this.data.date?.trim() || void 0,
5502
+ text: this.data.text.trim(),
5503
+ url: this.data.url?.trim() || void 0
5504
+ };
5505
+ }
5506
+ };
5507
+
5508
+ // src/utils/aiClient.ts
5509
+ var AI_PROVIDER_PRESETS = [
5510
+ {
5511
+ id: "openai",
5512
+ label: "OpenAI (ChatGPT)",
5513
+ defaultModel: "gpt-4o-mini",
5514
+ defaultEndpoint: "https://api.openai.com/v1/chat/completions"
5515
+ },
5516
+ {
5517
+ id: "codex",
5518
+ label: "OpenAI Codex",
5519
+ defaultModel: "codex-mini-latest",
5520
+ defaultEndpoint: "https://api.openai.com/v1/chat/completions"
5521
+ },
5522
+ {
5523
+ id: "openrouter",
5524
+ label: "OpenRouter",
5525
+ defaultModel: "openai/gpt-4o-mini",
5526
+ defaultEndpoint: "https://openrouter.ai/api/v1/chat/completions"
5527
+ },
5528
+ {
5529
+ id: "opencode",
5530
+ label: "OpenCode",
5531
+ defaultModel: "opencode/default",
5532
+ defaultEndpoint: "https://api.opencode.ai/v1/chat/completions"
5533
+ },
5534
+ {
5535
+ id: "anthropic",
5536
+ label: "Anthropic (Claude)",
5537
+ defaultModel: "claude-3-5-sonnet-latest",
5538
+ defaultEndpoint: "https://api.anthropic.com/v1/messages"
5539
+ },
5540
+ {
5541
+ id: "gemini",
5542
+ label: "Google Gemini",
5543
+ defaultModel: "gemini-2.5-flash",
5544
+ defaultEndpoint: "https://generativelanguage.googleapis.com/v1beta/models"
5545
+ },
5546
+ {
5547
+ id: "custom",
5548
+ label: "Custom OpenAI-Compatible",
5549
+ defaultModel: "gpt-4o-mini",
5550
+ defaultEndpoint: "http://localhost:11434/v1/chat/completions"
5551
+ }
5552
+ ];
5553
+ var AI_STORAGE_KEY = "nextgen-editor-ai-config";
5554
+ function loadAiConfig() {
5555
+ try {
5556
+ const raw = localStorage.getItem(AI_STORAGE_KEY);
5557
+ if (raw) {
5558
+ const parsed = JSON.parse(raw);
5559
+ if (parsed.provider) {
5560
+ return {
5561
+ provider: parsed.provider,
5562
+ model: parsed.model || "gpt-4o-mini",
5563
+ apiKey: parsed.apiKey || "",
5564
+ endpoint: parsed.endpoint || ""
5565
+ };
5566
+ }
5567
+ }
5568
+ } catch {
5569
+ }
5570
+ return {
5571
+ provider: "openai",
5572
+ model: "gpt-4o-mini",
5573
+ apiKey: "",
5574
+ endpoint: ""
5575
+ };
5576
+ }
5577
+ function saveAiConfig(cfg) {
5578
+ try {
5579
+ localStorage.setItem(AI_STORAGE_KEY, JSON.stringify(cfg));
5580
+ } catch {
5581
+ }
5582
+ }
5583
+ async function generateAiText(params) {
5584
+ const { config, mode, prompt, context } = params;
5585
+ const preset = AI_PROVIDER_PRESETS.find((p) => p.id === config.provider) || AI_PROVIDER_PRESETS[0];
5586
+ const endpoint = (config.endpoint || preset.defaultEndpoint).trim();
5587
+ const model = (config.model || preset.defaultModel).trim();
5588
+ const apiKey = config.apiKey.trim();
5589
+ if (!apiKey && config.provider !== "custom") {
5590
+ throw new Error("Please add an API key in Settings first.");
5591
+ }
5592
+ const systemPrompt = mode === "continue" ? "You are a concise writing assistant inside a block editor. Continue the document naturally from the provided context in 1-3 clear paragraphs. Return only the continuation text." : "You are a helpful writing and editing assistant inside a block editor. Fulfill the user request concisely using the provided document context.";
5593
+ const userContent = mode === "continue" ? `Document context:
5594
+ ${context || "(Empty document)"}
5595
+
5596
+ Continue writing naturally:` : `Document context:
5597
+ ${context || "(Empty document)"}
5598
+
5599
+ User request: ${prompt}`;
5600
+ if (config.provider === "gemini") {
5601
+ const url = `${endpoint.replace(/\/$/, "")}/${encodeURIComponent(
5602
+ model
5603
+ )}:generateContent?key=${encodeURIComponent(apiKey)}`;
5604
+ const res2 = await fetch(url, {
5605
+ method: "POST",
5606
+ headers: { "Content-Type": "application/json" },
5607
+ body: JSON.stringify({
5608
+ contents: [{ parts: [{ text: `${systemPrompt}
5609
+
5610
+ ${userContent}` }] }]
5611
+ })
5612
+ });
5613
+ if (!res2.ok) throw new Error(`Gemini API error (${res2.status})`);
5614
+ const json2 = await res2.json();
5615
+ return json2.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "";
5616
+ }
5617
+ if (config.provider === "anthropic") {
5618
+ const res2 = await fetch(endpoint, {
5619
+ method: "POST",
5620
+ headers: {
5621
+ "Content-Type": "application/json",
5622
+ "x-api-key": apiKey,
5623
+ "anthropic-version": "2023-06-01"
5624
+ },
5625
+ body: JSON.stringify({
5626
+ model,
5627
+ max_tokens: 1024,
5628
+ system: systemPrompt,
5629
+ messages: [{ role: "user", content: userContent }]
5630
+ })
5631
+ });
5632
+ if (!res2.ok) throw new Error(`Anthropic API error (${res2.status})`);
5633
+ const json2 = await res2.json();
5634
+ return json2.content?.[0]?.text?.trim() || "";
5635
+ }
5636
+ const headers = {
5637
+ "Content-Type": "application/json"
5638
+ };
5639
+ if (apiKey) {
5640
+ headers.Authorization = `Bearer ${apiKey}`;
5641
+ }
5642
+ const res = await fetch(endpoint, {
5643
+ method: "POST",
5644
+ headers,
5645
+ body: JSON.stringify({
5646
+ model,
5647
+ messages: [
5648
+ { role: "system", content: systemPrompt },
5649
+ { role: "user", content: userContent }
5650
+ ]
5651
+ })
5652
+ });
5653
+ if (!res.ok) throw new Error(`AI API error (${res.status})`);
5654
+ const json = await res.json();
5655
+ return json.choices?.[0]?.message?.content?.trim() || "";
5656
+ }
5657
+
5658
+ // src/blocks/inlineExtensions.ts
5659
+ var TEXT_COLOR_SWATCHES = [
5660
+ { label: "Default", value: "" },
5661
+ { label: "Gray", value: "#71717a" },
5662
+ { label: "Red", value: "#dc2626" },
5663
+ { label: "Amber", value: "#d97706" },
5664
+ { label: "Green", value: "#16a34a" },
5665
+ { label: "Blue", value: "#2563eb" },
5666
+ { label: "Purple", value: "#9333ea" }
5667
+ ];
5668
+ var HIGHLIGHT_SWATCHES = [
5669
+ { label: "None", value: "" },
5670
+ { label: "Yellow", value: "rgba(250, 204, 21, 0.35)" },
5671
+ { label: "Green", value: "rgba(74, 222, 128, 0.3)" },
5672
+ { label: "Blue", value: "rgba(96, 165, 250, 0.3)" },
5673
+ { label: "Pink", value: "rgba(244, 114, 182, 0.3)" },
5674
+ { label: "Gray", value: "rgba(161, 161, 170, 0.28)" }
5675
+ ];
5676
+ var REWRITE_ACTIONS = [
5677
+ {
5678
+ id: "improve",
5679
+ label: "Improve",
5680
+ prompt: "Rewrite the following text to be clearer, smoother, and more engaging. Return only the rewritten text."
5681
+ },
5682
+ {
5683
+ id: "shorten",
5684
+ label: "Shorten",
5685
+ prompt: "Make the following text more concise while preserving its core meaning. Return only the shortened text."
5686
+ },
5687
+ {
5688
+ id: "grammar",
5689
+ label: "Fix Grammar",
5690
+ prompt: "Fix any spelling, punctuation, or grammar mistakes in the following text. Return only the corrected text."
5691
+ },
5692
+ {
5693
+ id: "professional",
5694
+ label: "Professional",
5695
+ prompt: "Rewrite the following text in a polished, professional tone. Return only the rewritten text."
5696
+ },
5697
+ {
5698
+ id: "translate",
5699
+ label: "Translate (ES)",
5700
+ prompt: "Translate the following text into natural Spanish. Return only the translated text."
5701
+ }
5702
+ ];
5703
+ var AiRewriteInline = class {
5704
+ savedRange = null;
5705
+ actionsEl = null;
5706
+ static get isInline() {
5707
+ return true;
5708
+ }
5709
+ static get title() {
5710
+ return "AI Rewrite";
5711
+ }
5712
+ static get sanitize() {
5713
+ return {};
5714
+ }
5715
+ render() {
5716
+ const btn = document.createElement("button");
5717
+ btn.type = "button";
5718
+ btn.className = "ce-inline-tool";
5719
+ btn.title = "AI Rewrite selection";
5720
+ btn.innerHTML = '<span style="font-size:12px;font-weight:700;">\u2726 AI</span>';
5721
+ return btn;
5722
+ }
5723
+ surround(range) {
5724
+ this.savedRange = range.cloneRange();
5725
+ if (this.actionsEl) {
5726
+ this.actionsEl.hidden = false;
5727
+ }
5728
+ }
5729
+ renderActions() {
5730
+ const wrap = document.createElement("div");
5731
+ wrap.className = "ng-inline-ai-actions";
5732
+ wrap.hidden = true;
5733
+ const status = document.createElement("span");
5734
+ status.className = "ng-inline-ai-status";
5735
+ const row = document.createElement("div");
5736
+ row.className = "ng-inline-ai-row";
5737
+ REWRITE_ACTIONS.forEach((act) => {
5738
+ const b = document.createElement("button");
5739
+ b.type = "button";
5740
+ b.className = "ng-inline-action-btn";
5741
+ b.textContent = act.label;
5742
+ b.addEventListener("click", async () => {
5743
+ const range = this.savedRange;
5744
+ const selected = range?.toString().trim() || "";
5745
+ if (!range || !selected) {
5746
+ status.textContent = "Select text first.";
5747
+ return;
5748
+ }
5749
+ status.textContent = "Rewriting\u2026";
5750
+ try {
5751
+ const rewritten = await generateAiText({
5752
+ config: loadAiConfig(),
5753
+ mode: "ask",
5754
+ prompt: `${act.prompt}
5755
+
5756
+ Text:
5757
+ "${selected}"`,
5758
+ context: selected
5759
+ });
5760
+ if (rewritten) {
5761
+ range.deleteContents();
5762
+ range.insertNode(document.createTextNode(rewritten));
5763
+ status.textContent = "Done";
5764
+ } else {
5765
+ status.textContent = "Empty response";
5766
+ }
5767
+ } catch (err) {
5768
+ status.textContent = err instanceof Error ? err.message : "AI error";
5769
+ }
5770
+ });
5771
+ row.appendChild(b);
5772
+ });
5773
+ wrap.append(row, status);
5774
+ this.actionsEl = wrap;
5775
+ return wrap;
5776
+ }
5777
+ checkState() {
5778
+ const sel = window.getSelection();
5779
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
5780
+ this.savedRange = sel.getRangeAt(0).cloneRange();
5781
+ }
5782
+ return false;
5783
+ }
5784
+ };
5785
+ var ColorInline = class {
5786
+ savedRange = null;
5787
+ actionsEl = null;
5788
+ static get isInline() {
5789
+ return true;
5790
+ }
5791
+ static get title() {
5792
+ return "Color & Highlight";
5793
+ }
5794
+ static get sanitize() {
5795
+ return {
5796
+ span: {
5797
+ class: "ng-inline-color",
5798
+ style: true
5799
+ }
5800
+ };
5801
+ }
5802
+ render() {
5803
+ const btn = document.createElement("button");
5804
+ btn.type = "button";
5805
+ btn.className = "ce-inline-tool";
5806
+ btn.title = "Text & Highlight Color";
5807
+ btn.innerHTML = '<span style="font-weight:700;font-size:12px;border-bottom:2px solid currentColor;">A</span>';
5808
+ return btn;
5809
+ }
5810
+ surround(range) {
5811
+ this.savedRange = range.cloneRange();
5812
+ if (this.actionsEl) {
5813
+ this.actionsEl.hidden = false;
5814
+ }
5815
+ }
5816
+ applyStyle(prop, value) {
5817
+ const range = this.savedRange;
5818
+ if (!range || range.collapsed) return;
5819
+ if (!value) {
5820
+ const span2 = document.createElement("span");
5821
+ span2.appendChild(range.extractContents());
5822
+ span2.querySelectorAll(".ng-inline-color").forEach((el) => {
5823
+ el.style[prop] = "";
5824
+ });
5825
+ range.insertNode(span2);
5826
+ return;
5827
+ }
5828
+ const span = document.createElement("span");
5829
+ span.className = "ng-inline-color";
5830
+ span.style[prop] = value;
5831
+ try {
5832
+ range.surroundContents(span);
5833
+ } catch {
5834
+ const frag = range.extractContents();
5835
+ span.appendChild(frag);
5836
+ range.insertNode(span);
5837
+ }
5838
+ }
5839
+ renderActions() {
5840
+ const wrap = document.createElement("div");
5841
+ wrap.className = "ng-inline-color-actions";
5842
+ wrap.hidden = true;
5843
+ const makeRow = (title, swatches, prop) => {
5844
+ const row = document.createElement("div");
5845
+ row.className = "ng-inline-swatch-row";
5846
+ const lbl = document.createElement("span");
5847
+ lbl.className = "ng-inline-swatch-label";
5848
+ lbl.textContent = title;
5849
+ row.appendChild(lbl);
5850
+ swatches.forEach((sw) => {
5851
+ const dot = document.createElement("button");
5852
+ dot.type = "button";
5853
+ dot.className = "ng-inline-swatch";
5854
+ dot.title = sw.label;
5855
+ dot.style.background = sw.value || "transparent";
5856
+ if (!sw.value) dot.textContent = "\xD7";
5857
+ dot.addEventListener("click", () => this.applyStyle(prop, sw.value));
5858
+ row.appendChild(dot);
5859
+ });
5860
+ return row;
5861
+ };
5862
+ wrap.append(
5863
+ makeRow("Text", TEXT_COLOR_SWATCHES, "color"),
5864
+ makeRow("Bg", HIGHLIGHT_SWATCHES, "backgroundColor")
5865
+ );
5866
+ this.actionsEl = wrap;
5867
+ return wrap;
5868
+ }
5869
+ checkState() {
5870
+ const sel = window.getSelection();
5871
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
5872
+ this.savedRange = sel.getRangeAt(0).cloneRange();
5873
+ }
5874
+ return false;
5875
+ }
5876
+ };
5877
+ var TodayTool = class {
5878
+ data;
5879
+ static get toolbox() {
5880
+ return {
5881
+ title: "Today Date",
5882
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>'
5883
+ };
5884
+ }
5885
+ constructor({ data }) {
5886
+ const now = /* @__PURE__ */ new Date();
5887
+ this.data = {
5888
+ date: data?.date ?? now.toLocaleDateString(void 0, {
5889
+ year: "numeric",
5890
+ month: "long",
5891
+ day: "numeric"
5892
+ }),
5893
+ label: data?.label ?? "Date"
5894
+ };
5895
+ }
5896
+ render() {
5897
+ const wrap = document.createElement("div");
5898
+ wrap.className = "editor-today-pill";
5899
+ const badge = document.createElement("span");
5900
+ badge.className = "editor-today-badge";
5901
+ badge.textContent = `\u{1F4C5} ${this.data.date}`;
5902
+ const toggle = document.createElement("button");
5903
+ toggle.type = "button";
5904
+ toggle.className = "editor-mermaid-preset-btn";
5905
+ toggle.textContent = "ISO";
5906
+ toggle.addEventListener("click", () => {
5907
+ const now = /* @__PURE__ */ new Date();
5908
+ const iso = now.toISOString().slice(0, 10);
5909
+ const long = now.toLocaleDateString(void 0, {
5910
+ year: "numeric",
5911
+ month: "long",
5912
+ day: "numeric"
5913
+ });
5914
+ this.data.date = this.data.date === iso ? long : iso;
5915
+ badge.textContent = `\u{1F4C5} ${this.data.date}`;
5916
+ toggle.textContent = this.data.date === iso ? "Long" : "ISO";
5917
+ });
5918
+ wrap.append(badge, toggle);
5919
+ return wrap;
5920
+ }
5921
+ save() {
5922
+ return {
5923
+ date: this.data.date,
5924
+ label: this.data.label
5925
+ };
5926
+ }
5927
+ };
5928
+ var ExportTriggerTool = class {
5929
+ static get toolbox() {
5930
+ return {
5931
+ title: "Export / Import",
5932
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>'
5933
+ };
5934
+ }
5935
+ render() {
5936
+ const el = document.createElement("div");
5937
+ el.className = "editor-export-trigger";
5938
+ el.textContent = "Opening Export & Markdown modal\u2026";
5939
+ queueMicrotask(() => {
5940
+ el.dispatchEvent(new CustomEvent("nextgen-open-export", { bubbles: true }));
5941
+ });
5942
+ return el;
5943
+ }
5944
+ save() {
5945
+ return {};
5946
+ }
5947
+ };
5948
+
5949
+ // src/editorTools.ts
5950
+ var CustomMediaTool = class {
5951
+ data;
5952
+ elements;
5953
+ constructor(options) {
5954
+ this.data = options.data || {};
5955
+ }
5956
+ static get toolbox() {
5957
+ return {
5958
+ title: "Image",
5959
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/></svg>'
5960
+ };
5961
+ }
5962
+ render() {
5963
+ const root = document.createElement("div");
5964
+ root.className = "custom-media-fields";
5965
+ const input = document.createElement("input");
5966
+ input.type = "text";
5967
+ input.placeholder = "Paste image URL";
5968
+ input.value = this.data.url || "";
5969
+ const file = document.createElement("input");
5970
+ file.type = "file";
5971
+ file.accept = "image/*";
5972
+ const caption = document.createElement("input");
5973
+ caption.type = "text";
5974
+ caption.placeholder = "Caption";
5975
+ caption.value = this.data.caption || "";
5976
+ const preview = document.createElement("div");
5977
+ preview.className = "custom-media-preview";
5978
+ const paint = (url) => {
5979
+ preview.innerHTML = url ? `<img src="${escHtml(url)}" alt="">` : "";
5980
+ };
5981
+ paint(input.value);
5982
+ input.oninput = () => paint(input.value);
5983
+ file.onchange = async () => {
5984
+ const selected = file.files?.[0];
5985
+ if (!selected) return;
5986
+ const bucketUrl = await uploadFileToBucket(selected, "writing");
5987
+ if (bucketUrl) {
5988
+ input.value = bucketUrl;
5989
+ paint(bucketUrl);
5990
+ return;
5991
+ }
5992
+ const reader = new FileReader();
5993
+ reader.onload = () => {
5994
+ const res = String(reader.result || "");
5995
+ input.value = res;
5996
+ paint(res);
5997
+ };
5998
+ reader.readAsDataURL(selected);
5999
+ };
6000
+ root.append(input, file, caption, preview);
6001
+ this.elements = { root, input, caption };
6002
+ return root;
6003
+ }
6004
+ save() {
6005
+ return {
6006
+ url: this.elements?.input.value.trim() || "",
6007
+ caption: this.elements?.caption.value.trim() || ""
6008
+ };
6009
+ }
6010
+ };
6011
+ var GifTool = class {
6012
+ data;
6013
+ elements;
6014
+ constructor(options) {
6015
+ this.data = options.data || {};
6016
+ }
6017
+ static get toolbox() {
6018
+ return {
6019
+ title: "GIF",
6020
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M10 9H7a1 1 0 0 0-1 1v4a1 1 0 0 0 1 1h2v-3H8"/><path d="M13 9v6"/><path d="M16 15V9h3"/><path d="M16 12h2"/></svg>'
6021
+ };
6022
+ }
6023
+ render() {
6024
+ const root = document.createElement("div");
6025
+ root.className = "custom-media-fields";
6026
+ const searchRow = document.createElement("div");
6027
+ searchRow.className = "gif-search-row";
6028
+ const searchInput = document.createElement("input");
6029
+ searchInput.type = "search";
6030
+ searchInput.placeholder = "Search free GIFs (trending or keyword)...";
6031
+ const searchBtn = document.createElement("button");
6032
+ searchBtn.type = "button";
6033
+ searchBtn.className = "b2";
6034
+ searchBtn.textContent = "Search";
6035
+ searchRow.append(searchInput, searchBtn);
6036
+ const resultsGrid = document.createElement("div");
6037
+ resultsGrid.className = "gif-picker-grid";
6038
+ const url = document.createElement("input");
6039
+ url.type = "url";
6040
+ url.placeholder = "Or paste GIF / image URL";
6041
+ url.value = this.data.url || "";
6042
+ const caption = document.createElement("input");
6043
+ caption.type = "text";
6044
+ caption.placeholder = "Caption";
6045
+ caption.value = this.data.caption || "";
6046
+ const preview = document.createElement("div");
6047
+ preview.className = "custom-media-preview";
6048
+ const paint = () => {
6049
+ preview.innerHTML = url.value ? `<img src="${escHtml(url.value)}" alt="${escHtml(caption.value || "GIF")}">` : "";
6050
+ };
6051
+ paint();
6052
+ url.oninput = paint;
6053
+ const runSearch = async (query) => {
6054
+ resultsGrid.innerHTML = '<span class="gif-picker-status">Loading GIFs\u2026</span>';
6055
+ try {
6056
+ const res = await fetch(
6057
+ `/api/gifs?q=${encodeURIComponent(query)}&limit=12`
6058
+ );
6059
+ const json = await res.json();
6060
+ const items = json.results || [];
6061
+ if (!items.length) {
6062
+ resultsGrid.innerHTML = '<span class="gif-picker-status">No GIFs found. Try another keyword or paste a URL below.</span>';
6063
+ return;
6064
+ }
6065
+ resultsGrid.innerHTML = "";
6066
+ items.forEach((item) => {
6067
+ const btn = document.createElement("button");
6068
+ btn.type = "button";
6069
+ btn.className = "gif-picker-item";
6070
+ btn.title = item.title;
6071
+ btn.innerHTML = `<img src="${escHtml(item.previewUrl)}" alt="${escHtml(item.title)}" loading="lazy">`;
6072
+ btn.onclick = () => {
6073
+ url.value = item.url;
6074
+ if (!caption.value) caption.value = item.title;
6075
+ paint();
6076
+ };
6077
+ resultsGrid.appendChild(btn);
6078
+ });
6079
+ } catch {
6080
+ resultsGrid.innerHTML = '<span class="gif-picker-status">Could not load GIFs. Paste a GIF URL below.</span>';
6081
+ }
6082
+ };
6083
+ searchBtn.onclick = () => void runSearch(searchInput.value);
6084
+ searchInput.addEventListener("keydown", (e) => {
6085
+ if (e.key === "Enter") {
6086
+ e.preventDefault();
6087
+ e.stopPropagation();
6088
+ void runSearch(searchInput.value);
6089
+ }
6090
+ });
6091
+ if (!this.data.url) {
6092
+ void runSearch("");
6093
+ }
6094
+ root.append(searchRow, resultsGrid, url, caption, preview);
6095
+ this.elements = { url, caption };
6096
+ return root;
6097
+ }
6098
+ save() {
6099
+ return {
6100
+ url: this.elements?.url.value.trim() || "",
6101
+ caption: this.elements?.caption.value.trim() || ""
6102
+ };
6103
+ }
6104
+ };
6105
+ var AttachTool = class {
6106
+ data;
6107
+ elements;
6108
+ constructor(options) {
6109
+ this.data = options.data || {};
6110
+ }
6111
+ static get toolbox() {
6112
+ return {
6113
+ title: "Attachment",
6114
+ icon: '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>'
6115
+ };
6116
+ }
6117
+ render() {
6118
+ const root = document.createElement("div");
6119
+ root.className = "custom-media-fields";
6120
+ const file = document.createElement("input");
6121
+ file.type = "file";
6122
+ const name = document.createElement("input");
6123
+ name.type = "text";
6124
+ name.placeholder = "Attachment label";
6125
+ name.value = this.data.name || "";
6126
+ root.append(file, name);
6127
+ const elements = {
6128
+ file,
6129
+ name,
6130
+ dataUrl: this.data.dataUrl || "",
6131
+ dataName: this.data.name || ""
6132
+ };
6133
+ this.elements = elements;
6134
+ file.onchange = () => {
6135
+ const selected = file.files?.[0];
6136
+ if (!selected) return;
6137
+ const reader = new FileReader();
6138
+ reader.onload = () => {
6139
+ elements.dataUrl = String(reader.result || "");
6140
+ elements.dataName = selected.name;
6141
+ if (!name.value) name.value = selected.name;
6142
+ };
6143
+ reader.readAsDataURL(selected);
6144
+ };
6145
+ return root;
5043
6146
  }
5044
6147
  save() {
5045
6148
  return {
@@ -5256,7 +6359,11 @@ var CustomEmbedTool = class {
5256
6359
  data;
5257
6360
  elements;
5258
6361
  constructor(options) {
5259
- this.data = options.data || {};
6362
+ this.data = {
6363
+ align: "center",
6364
+ size: "medium",
6365
+ ...options.data || {}
6366
+ };
5260
6367
  }
5261
6368
  static get toolbox() {
5262
6369
  return {
@@ -5317,15 +6424,20 @@ var CustomEmbedTool = class {
5317
6424
  caption.value = this.data.caption || "";
5318
6425
  const preview = document.createElement("div");
5319
6426
  preview.className = "custom-embed-preview";
6427
+ preview.dataset.align = this.data.align || "center";
6428
+ preview.dataset.size = this.data.size || "medium";
5320
6429
  const elements = {
5321
6430
  url,
5322
6431
  caption,
6432
+ preview,
5323
6433
  embedUrl: this.data.embed || this.toEmbedUrl(url.value)
5324
6434
  };
5325
6435
  this.elements = elements;
5326
6436
  const paint = () => {
5327
6437
  const embedUrl = this.toEmbedUrl(url.value);
5328
6438
  elements.embedUrl = embedUrl;
6439
+ preview.dataset.align = this.data.align || "center";
6440
+ preview.dataset.size = this.data.size || "medium";
5329
6441
  preview.innerHTML = embedUrl ? `<iframe src="${escHtml(embedUrl)}" title="${escHtml(
5330
6442
  caption.value || "Embedded content"
5331
6443
  )}" loading="lazy" allowfullscreen></iframe>` : "";
@@ -5339,13 +6451,96 @@ var CustomEmbedTool = class {
5339
6451
  root.append(url, caption, preview);
5340
6452
  return root;
5341
6453
  }
6454
+ renderSettings() {
6455
+ const tunes = [
6456
+ {
6457
+ name: "align-left",
6458
+ label: "Align Left",
6459
+ icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="15" y2="12"/><line x1="3" y1="18" x2="18" y2="18"/></svg>',
6460
+ isActive: (this.data.align || "center") === "left",
6461
+ onActivate: () => {
6462
+ this.data.align = "left";
6463
+ if (this.elements?.preview) this.elements.preview.dataset.align = "left";
6464
+ }
6465
+ },
6466
+ {
6467
+ name: "align-center",
6468
+ label: "Align Center",
6469
+ icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="6" y1="12" x2="18" y2="12"/><line x1="4" y1="18" x2="20" y2="18"/></svg>',
6470
+ isActive: (this.data.align || "center") === "center",
6471
+ onActivate: () => {
6472
+ this.data.align = "center";
6473
+ if (this.elements?.preview) this.elements.preview.dataset.align = "center";
6474
+ }
6475
+ },
6476
+ {
6477
+ name: "align-right",
6478
+ label: "Align Right",
6479
+ icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="3" y1="6" x2="21" y2="6"/><line x1="9" y1="12" x2="21" y2="12"/><line x1="6" y1="18" x2="21" y2="18"/></svg>',
6480
+ isActive: (this.data.align || "center") === "right",
6481
+ onActivate: () => {
6482
+ this.data.align = "right";
6483
+ if (this.elements?.preview) this.elements.preview.dataset.align = "right";
6484
+ }
6485
+ },
6486
+ {
6487
+ name: "size-small",
6488
+ label: "Small",
6489
+ icon: '<span style="font-size:11px;font-weight:700;">S</span>',
6490
+ isActive: (this.data.size || "medium") === "small",
6491
+ onActivate: () => {
6492
+ this.data.size = "small";
6493
+ if (this.elements?.preview) this.elements.preview.dataset.size = "small";
6494
+ }
6495
+ },
6496
+ {
6497
+ name: "size-medium",
6498
+ label: "Medium",
6499
+ icon: '<span style="font-size:11px;font-weight:700;">M</span>',
6500
+ isActive: (this.data.size || "medium") === "medium",
6501
+ onActivate: () => {
6502
+ this.data.size = "medium";
6503
+ if (this.elements?.preview) this.elements.preview.dataset.size = "medium";
6504
+ }
6505
+ },
6506
+ {
6507
+ name: "size-large",
6508
+ label: "Large",
6509
+ icon: '<span style="font-size:11px;font-weight:700;">L</span>',
6510
+ isActive: (this.data.size || "medium") === "large",
6511
+ onActivate: () => {
6512
+ this.data.size = "large";
6513
+ if (this.elements?.preview) this.elements.preview.dataset.size = "large";
6514
+ }
6515
+ },
6516
+ {
6517
+ name: "size-full",
6518
+ label: "Full Page",
6519
+ icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',
6520
+ isActive: (this.data.size || "medium") === "full",
6521
+ onActivate: () => {
6522
+ this.data.size = "full";
6523
+ if (this.elements?.preview) this.elements.preview.dataset.size = "full";
6524
+ }
6525
+ }
6526
+ ];
6527
+ return tunes.map((t) => ({
6528
+ icon: t.icon,
6529
+ label: t.label,
6530
+ isActive: t.isActive,
6531
+ closeOnActivate: true,
6532
+ onActivate: t.onActivate
6533
+ }));
6534
+ }
5342
6535
  save() {
5343
6536
  const source = this.elements?.url.value.trim() || "";
5344
6537
  const embed = this.toEmbedUrl(source);
5345
6538
  return {
5346
6539
  source,
5347
6540
  embed,
5348
- caption: this.elements?.caption.value.trim() || ""
6541
+ caption: this.elements?.caption.value.trim() || "",
6542
+ align: this.data.align || "center",
6543
+ size: this.data.size || "medium"
5349
6544
  };
5350
6545
  }
5351
6546
  };
@@ -5795,6 +6990,8 @@ var SpoilerInline = class {
5795
6990
  }
5796
6991
  };
5797
6992
  var MentionInline = class {
6993
+ savedRange = null;
6994
+ actionsEl = null;
5798
6995
  static get isInline() {
5799
6996
  return true;
5800
6997
  }
@@ -5810,23 +7007,59 @@ var MentionInline = class {
5810
7007
  return button;
5811
7008
  }
5812
7009
  surround(range) {
5813
- const selectedText = range.toString().trim();
5814
- const url = window.prompt("Enter profile or mention URL (https://...)");
5815
- if (!url) return;
5816
- const anchor = document.createElement("a");
5817
- anchor.className = "editor-mention";
5818
- anchor.href = url.trim();
5819
- anchor.target = "_blank";
5820
- anchor.rel = "noopener noreferrer";
5821
- try {
5822
- range.surroundContents(anchor);
5823
- if (selectedText && !selectedText.startsWith("@")) {
5824
- anchor.textContent = `@${selectedText}`;
5825
- }
5826
- } catch {
7010
+ this.savedRange = range.cloneRange();
7011
+ if (this.actionsEl) {
7012
+ this.actionsEl.hidden = false;
7013
+ const input = this.actionsEl.querySelector("input");
7014
+ input?.focus();
5827
7015
  }
5828
7016
  }
7017
+ renderActions() {
7018
+ const wrap = document.createElement("div");
7019
+ wrap.className = "ng-mention-popover";
7020
+ wrap.hidden = true;
7021
+ const input = document.createElement("input");
7022
+ input.type = "url";
7023
+ input.className = "cdx-input";
7024
+ input.placeholder = "https://github.com/username";
7025
+ const applyBtn = document.createElement("button");
7026
+ applyBtn.type = "button";
7027
+ applyBtn.className = "ng-inline-action-btn";
7028
+ applyBtn.textContent = "Apply";
7029
+ const applyMention = (url) => {
7030
+ const range = this.savedRange;
7031
+ if (!range || !url.trim()) return;
7032
+ const selectedText = range.toString().trim();
7033
+ const anchor = document.createElement("a");
7034
+ anchor.className = "editor-mention";
7035
+ anchor.href = url.trim();
7036
+ anchor.target = "_blank";
7037
+ anchor.rel = "noopener noreferrer";
7038
+ try {
7039
+ range.surroundContents(anchor);
7040
+ if (selectedText && !selectedText.startsWith("@")) {
7041
+ anchor.textContent = `@${selectedText}`;
7042
+ }
7043
+ } catch {
7044
+ }
7045
+ wrap.hidden = true;
7046
+ };
7047
+ applyBtn.addEventListener("click", () => applyMention(input.value));
7048
+ input.addEventListener("keydown", (e) => {
7049
+ if (e.key === "Enter") {
7050
+ e.preventDefault();
7051
+ applyMention(input.value);
7052
+ }
7053
+ });
7054
+ wrap.append(input, applyBtn);
7055
+ this.actionsEl = wrap;
7056
+ return wrap;
7057
+ }
5829
7058
  checkState() {
7059
+ const sel = window.getSelection();
7060
+ if (sel && sel.rangeCount > 0 && !sel.getRangeAt(0).collapsed) {
7061
+ this.savedRange = sel.getRangeAt(0).cloneRange();
7062
+ }
5830
7063
  return false;
5831
7064
  }
5832
7065
  };
@@ -5877,277 +7110,138 @@ function makeHeadingTool(level) {
5877
7110
  placeholder: `Heading ${level}`,
5878
7111
  levels: [level],
5879
7112
  defaultLevel: level
5880
- }
5881
- });
5882
- }
5883
- };
5884
- }
5885
- var Heading1Tool = makeHeadingTool(1);
5886
- var Heading2Tool = makeHeadingTool(2);
5887
- var Heading3Tool = makeHeadingTool(3);
5888
- function getEditorTools(includeLayout = true, enabledTools) {
5889
- const tools = {
5890
- // 1. Most frequently used core blocks
5891
- cover: PageCoverTool,
5892
- h1: {
5893
- class: Heading1Tool,
5894
- inlineToolbar: true
5895
- },
5896
- h2: {
5897
- class: Heading2Tool,
5898
- inlineToolbar: true
5899
- },
5900
- h3: {
5901
- class: Heading3Tool,
5902
- inlineToolbar: true
5903
- },
5904
- header: {
5905
- class: Header,
5906
- toolbox: false,
5907
- config: { placeholder: "Heading", levels: [1, 2, 3], defaultLevel: 2 }
5908
- },
5909
- list: List,
5910
- image: CustomMediaTool,
5911
- quote: {
5912
- class: Quote,
5913
- inlineToolbar: true,
5914
- config: {
5915
- quotePlaceholder: "Enter a quote",
5916
- captionPlaceholder: "Quote author"
5917
- }
5918
- },
5919
- code: SmartCodeTool,
5920
- toc: TableOfContentsTool,
5921
- linkTool: {
5922
- class: LinkTool,
5923
- config: {
5924
- endpoint: "/api/fetchUrl"
5925
- }
5926
- },
5927
- delimiter: DelimiterTool,
5928
- table: Table,
5929
- callout: CalloutTool,
5930
- hotkey: HotkeyTool,
5931
- emoji: EmojiTool,
5932
- scratch: ScratchTool,
5933
- alert: AlertTool,
5934
- // 2. Common rich media & layout
5935
- upload: UploadTool,
5936
- audio: AudioPlayerTool,
5937
- musicCarousel: MusicCarouselTool,
5938
- embed: CustomEmbedTool,
5939
- gallery: LightboxGalleryTool,
5940
- masonry: MasonryTool,
5941
- carousel: CarouselTool,
5942
- bento: BentoTool,
5943
- ...includeLayout ? { layout: LayoutTool } : {},
5944
- tabs: TabsTool,
5945
- accordion: AccordionTool,
5946
- toggleh1: ToggleH1Tool,
5947
- toggleh2: ToggleH2Tool,
5948
- toggleh3: ToggleH3Tool,
5949
- // 3. Structured & editorial blocks
5950
- flashcards: FlashcardTool,
5951
- chart: ChartTool,
5952
- footnotes: FootnotesTool,
5953
- quiz: QuizTool,
5954
- kanban: KanbanTool,
5955
- timer: FocusTimerTool,
5956
- poll: PollTool,
5957
- faq: FaqTool,
5958
- todo: TaskChecklistTool,
5959
- eisenhower: EisenhowerMatrixTool,
5960
- form: FormBuilderTool,
5961
- latex: LatexTool,
5962
- excalidraw: ExcalidrawTool,
5963
- pullquote: PullQuoteTool,
5964
- timeline: TimelineTool,
5965
- stats: StatsTool,
5966
- proscons: ProsConsTool,
5967
- cards: CardsTool,
5968
- badges: BadgesTool,
5969
- tags: TagsTool,
5970
- button: ButtonTool,
5971
- dialogue: DialogueTool,
5972
- // 4. Specialized / least frequent blocks
5973
- gif: GifTool,
5974
- compare: CompareTool,
5975
- slides: SlidesTool,
5976
- spoiler: SpoilerTool,
5977
- collapsible: CollapsibleTool,
5978
- attaches: AttachTool,
5979
- nestedlist: NestedList,
5980
- simpleImage: SimpleImage,
5981
- comment: CommentTool,
5982
- continueWriting: ContinueWritingTool,
5983
- askAi: AskAiTool,
5984
- settings: SettingsTriggerTool,
5985
- // Inline toolbar tools
5986
- inlineCode: InlineCode,
5987
- marker: MarkerInline,
5988
- spoilerInline: SpoilerInline,
5989
- underline: Underline,
5990
- strikethrough: Strikethrough,
5991
- hyperlink: HyperlinkInline,
5992
- mention: MentionInline
5993
- };
5994
- if (enabledTools && enabledTools.length > 0) {
5995
- const allowed = new Set(enabledTools);
5996
- return Object.fromEntries(
5997
- Object.entries(tools).filter(([key]) => allowed.has(key))
5998
- );
5999
- }
6000
- return tools;
6001
- }
6002
-
6003
- // src/utils/aiClient.ts
6004
- var AI_PROVIDER_PRESETS = [
6005
- {
6006
- id: "openai",
6007
- label: "OpenAI (ChatGPT)",
6008
- defaultModel: "gpt-4o-mini",
6009
- defaultEndpoint: "https://api.openai.com/v1/chat/completions"
6010
- },
6011
- {
6012
- id: "codex",
6013
- label: "OpenAI Codex",
6014
- defaultModel: "codex-mini-latest",
6015
- defaultEndpoint: "https://api.openai.com/v1/chat/completions"
6016
- },
6017
- {
6018
- id: "openrouter",
6019
- label: "OpenRouter",
6020
- defaultModel: "openai/gpt-4o-mini",
6021
- defaultEndpoint: "https://openrouter.ai/api/v1/chat/completions"
6022
- },
6023
- {
6024
- id: "opencode",
6025
- label: "OpenCode",
6026
- defaultModel: "opencode/default",
6027
- defaultEndpoint: "https://api.opencode.ai/v1/chat/completions"
6028
- },
6029
- {
6030
- id: "anthropic",
6031
- label: "Anthropic (Claude)",
6032
- defaultModel: "claude-3-5-sonnet-latest",
6033
- defaultEndpoint: "https://api.anthropic.com/v1/messages"
6034
- },
6035
- {
6036
- id: "gemini",
6037
- label: "Google Gemini",
6038
- defaultModel: "gemini-2.5-flash",
6039
- defaultEndpoint: "https://generativelanguage.googleapis.com/v1beta/models"
6040
- },
6041
- {
6042
- id: "custom",
6043
- label: "Custom OpenAI-Compatible",
6044
- defaultModel: "gpt-4o-mini",
6045
- defaultEndpoint: "http://localhost:11434/v1/chat/completions"
6046
- }
6047
- ];
6048
- var AI_STORAGE_KEY = "nextgen-editor-ai-config";
6049
- function loadAiConfig() {
6050
- try {
6051
- const raw = localStorage.getItem(AI_STORAGE_KEY);
6052
- if (raw) {
6053
- const parsed = JSON.parse(raw);
6054
- if (parsed.provider) {
6055
- return {
6056
- provider: parsed.provider,
6057
- model: parsed.model || "gpt-4o-mini",
6058
- apiKey: parsed.apiKey || "",
6059
- endpoint: parsed.endpoint || ""
6060
- };
6061
- }
6062
- }
6063
- } catch {
6064
- }
6065
- return {
6066
- provider: "openai",
6067
- model: "gpt-4o-mini",
6068
- apiKey: "",
6069
- endpoint: ""
6070
- };
6071
- }
6072
- function saveAiConfig(cfg) {
6073
- try {
6074
- localStorage.setItem(AI_STORAGE_KEY, JSON.stringify(cfg));
6075
- } catch {
6076
- }
6077
- }
6078
- async function generateAiText(params) {
6079
- const { config, mode, prompt, context } = params;
6080
- const preset = AI_PROVIDER_PRESETS.find((p) => p.id === config.provider) || AI_PROVIDER_PRESETS[0];
6081
- const endpoint = (config.endpoint || preset.defaultEndpoint).trim();
6082
- const model = (config.model || preset.defaultModel).trim();
6083
- const apiKey = config.apiKey.trim();
6084
- if (!apiKey && config.provider !== "custom") {
6085
- throw new Error("Please add an API key in Settings first.");
6086
- }
6087
- 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.";
6088
- const userContent = mode === "continue" ? `Document context:
6089
- ${context || "(Empty document)"}
6090
-
6091
- Continue writing naturally:` : `Document context:
6092
- ${context || "(Empty document)"}
6093
-
6094
- User request: ${prompt}`;
6095
- if (config.provider === "gemini") {
6096
- const url = `${endpoint.replace(/\/$/, "")}/${encodeURIComponent(
6097
- model
6098
- )}:generateContent?key=${encodeURIComponent(apiKey)}`;
6099
- const res2 = await fetch(url, {
6100
- method: "POST",
6101
- headers: { "Content-Type": "application/json" },
6102
- body: JSON.stringify({
6103
- contents: [{ parts: [{ text: `${systemPrompt}
6104
-
6105
- ${userContent}` }] }]
6106
- })
6107
- });
6108
- if (!res2.ok) throw new Error(`Gemini API error (${res2.status})`);
6109
- const json2 = await res2.json();
6110
- return json2.candidates?.[0]?.content?.parts?.[0]?.text?.trim() || "";
6111
- }
6112
- if (config.provider === "anthropic") {
6113
- const res2 = await fetch(endpoint, {
6114
- method: "POST",
6115
- headers: {
6116
- "Content-Type": "application/json",
6117
- "x-api-key": apiKey,
6118
- "anthropic-version": "2023-06-01"
6119
- },
6120
- body: JSON.stringify({
6121
- model,
6122
- max_tokens: 1024,
6123
- system: systemPrompt,
6124
- messages: [{ role: "user", content: userContent }]
6125
- })
6126
- });
6127
- if (!res2.ok) throw new Error(`Anthropic API error (${res2.status})`);
6128
- const json2 = await res2.json();
6129
- return json2.content?.[0]?.text?.trim() || "";
6130
- }
6131
- const headers = {
6132
- "Content-Type": "application/json"
7113
+ }
7114
+ });
7115
+ }
6133
7116
  };
6134
- if (apiKey) {
6135
- headers.Authorization = `Bearer ${apiKey}`;
7117
+ }
7118
+ var Heading1Tool = makeHeadingTool(1);
7119
+ var Heading2Tool = makeHeadingTool(2);
7120
+ var Heading3Tool = makeHeadingTool(3);
7121
+ function getEditorTools(includeLayout = true, enabledTools) {
7122
+ const tools = {
7123
+ // 1. Most frequently used core blocks
7124
+ cover: PageCoverTool,
7125
+ h1: {
7126
+ class: Heading1Tool,
7127
+ inlineToolbar: true
7128
+ },
7129
+ h2: {
7130
+ class: Heading2Tool,
7131
+ inlineToolbar: true
7132
+ },
7133
+ h3: {
7134
+ class: Heading3Tool,
7135
+ inlineToolbar: true
7136
+ },
7137
+ header: {
7138
+ class: Header,
7139
+ toolbox: false,
7140
+ config: { placeholder: "Heading", levels: [1, 2, 3], defaultLevel: 2 }
7141
+ },
7142
+ list: List,
7143
+ image: CustomMediaTool,
7144
+ quote: {
7145
+ class: Quote,
7146
+ inlineToolbar: true,
7147
+ config: {
7148
+ quotePlaceholder: "Enter a quote",
7149
+ captionPlaceholder: "Quote author"
7150
+ }
7151
+ },
7152
+ code: SmartCodeTool,
7153
+ toc: TableOfContentsTool,
7154
+ linkTool: {
7155
+ class: LinkTool,
7156
+ config: {
7157
+ endpoint: "/api/fetchUrl"
7158
+ }
7159
+ },
7160
+ delimiter: DelimiterTool,
7161
+ table: Table,
7162
+ callout: CalloutTool,
7163
+ hotkey: HotkeyTool,
7164
+ emoji: EmojiTool,
7165
+ scratch: ScratchTool,
7166
+ alert: AlertTool,
7167
+ // 2. Common rich media & layout
7168
+ upload: UploadTool,
7169
+ audio: AudioPlayerTool,
7170
+ musicCarousel: MusicCarouselTool,
7171
+ embed: CustomEmbedTool,
7172
+ gallery: LightboxGalleryTool,
7173
+ masonry: MasonryTool,
7174
+ carousel: CarouselTool,
7175
+ bento: BentoTool,
7176
+ ...includeLayout ? { layout: LayoutTool } : {},
7177
+ tabs: TabsTool,
7178
+ accordion: AccordionTool,
7179
+ toggleh1: ToggleH1Tool,
7180
+ toggleh2: ToggleH2Tool,
7181
+ toggleh3: ToggleH3Tool,
7182
+ // 3. Structured & editorial blocks
7183
+ flashcards: FlashcardTool,
7184
+ chart: ChartTool,
7185
+ footnotes: FootnotesTool,
7186
+ quiz: QuizTool,
7187
+ kanban: KanbanTool,
7188
+ timer: FocusTimerTool,
7189
+ poll: PollTool,
7190
+ faq: FaqTool,
7191
+ todo: TaskChecklistTool,
7192
+ eisenhower: EisenhowerMatrixTool,
7193
+ form: FormBuilderTool,
7194
+ latex: LatexTool,
7195
+ mermaid: MermaidTool,
7196
+ bookmark: BookmarkTool,
7197
+ steps: StepsTool,
7198
+ diff: DiffTool,
7199
+ video: VideoTool,
7200
+ changelog: ChangelogTool,
7201
+ social: SocialTool,
7202
+ excalidraw: ExcalidrawTool,
7203
+ pullquote: PullQuoteTool,
7204
+ timeline: TimelineTool,
7205
+ stats: StatsTool,
7206
+ proscons: ProsConsTool,
7207
+ cards: CardsTool,
7208
+ badges: BadgesTool,
7209
+ tags: TagsTool,
7210
+ button: ButtonTool,
7211
+ dialogue: DialogueTool,
7212
+ // 4. Specialized / least frequent blocks
7213
+ gif: GifTool,
7214
+ compare: CompareTool,
7215
+ slides: SlidesTool,
7216
+ spoiler: SpoilerTool,
7217
+ collapsible: CollapsibleTool,
7218
+ attaches: AttachTool,
7219
+ nestedlist: NestedList,
7220
+ simpleImage: SimpleImage,
7221
+ comment: CommentTool,
7222
+ continueWriting: ContinueWritingTool,
7223
+ askAi: AskAiTool,
7224
+ today: TodayTool,
7225
+ export: ExportTriggerTool,
7226
+ settings: SettingsTriggerTool,
7227
+ // Inline toolbar tools
7228
+ inlineCode: InlineCode,
7229
+ marker: MarkerInline,
7230
+ textColor: ColorInline,
7231
+ aiRewrite: AiRewriteInline,
7232
+ spoilerInline: SpoilerInline,
7233
+ underline: Underline,
7234
+ strikethrough: Strikethrough,
7235
+ hyperlink: HyperlinkInline,
7236
+ mention: MentionInline
7237
+ };
7238
+ if (enabledTools && enabledTools.length > 0) {
7239
+ const allowed = new Set(enabledTools);
7240
+ return Object.fromEntries(
7241
+ Object.entries(tools).filter(([key]) => allowed.has(key))
7242
+ );
6136
7243
  }
6137
- const res = await fetch(endpoint, {
6138
- method: "POST",
6139
- headers,
6140
- body: JSON.stringify({
6141
- model,
6142
- messages: [
6143
- { role: "system", content: systemPrompt },
6144
- { role: "user", content: userContent }
6145
- ]
6146
- })
6147
- });
6148
- if (!res.ok) throw new Error(`AI API error (${res.status})`);
6149
- const json = await res.json();
6150
- return json.choices?.[0]?.message?.content?.trim() || "";
7244
+ return tools;
6151
7245
  }
6152
7246
 
6153
7247
  // src/utils/popoverCategories.ts
@@ -6171,6 +7265,7 @@ var TOOL_CATEGORIES = [
6171
7265
  "callout",
6172
7266
  "hotkey",
6173
7267
  "emoji",
7268
+ "today",
6174
7269
  "scratch",
6175
7270
  "alert",
6176
7271
  "badges",
@@ -6210,6 +7305,8 @@ var TOOL_CATEGORIES = [
6210
7305
  "audio",
6211
7306
  "musicCarousel",
6212
7307
  "embed",
7308
+ "bookmark",
7309
+ "video",
6213
7310
  "attaches",
6214
7311
  "excalidraw"
6215
7312
  ]
@@ -6219,6 +7316,11 @@ var TOOL_CATEGORIES = [
6219
7316
  tools: [
6220
7317
  "code",
6221
7318
  "latex",
7319
+ "mermaid",
7320
+ "diff",
7321
+ "steps",
7322
+ "changelog",
7323
+ "social",
6222
7324
  "chart",
6223
7325
  "table",
6224
7326
  "stats",
@@ -6239,7 +7341,7 @@ var TOOL_CATEGORIES = [
6239
7341
  },
6240
7342
  {
6241
7343
  label: "Settings",
6242
- tools: ["settings"]
7344
+ tools: ["export", "settings"]
6243
7345
  }
6244
7346
  ];
6245
7347
  var SIMPLE_MODE_TOOLS = [
@@ -6305,6 +7407,14 @@ var TOOL_LABELS = {
6305
7407
  excalidraw: "Excalidraw",
6306
7408
  code: "Code Block",
6307
7409
  latex: "LaTeX Math",
7410
+ mermaid: "Mermaid Diagram",
7411
+ bookmark: "Bookmark Card",
7412
+ steps: "Steps Walkthrough",
7413
+ diff: "Code Diff",
7414
+ video: "Video Player",
7415
+ changelog: "Changelog",
7416
+ social: "Social Quote",
7417
+ today: "Today Date",
6308
7418
  chart: "Data Chart",
6309
7419
  table: "Table",
6310
7420
  stats: "Stats",
@@ -6323,6 +7433,7 @@ var TOOL_LABELS = {
6323
7433
  slides: "Slides",
6324
7434
  continueWriting: "Continue Writing",
6325
7435
  askAi: "Ask AI",
7436
+ export: "Export / Import",
6326
7437
  settings: "Settings"
6327
7438
  };
6328
7439
  function attachPopoverCategoryHeaders(container) {
@@ -6545,6 +7656,28 @@ var ClassicToolbar = ({
6545
7656
  /* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn ng-ct-s", onMouseDown: keepSelection, onClick: () => exec("strikeThrough"), title: "Strikethrough", children: "S" }),
6546
7657
  /* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => toggleInlineTag("code"), title: "Inline Code", children: "<>" }),
6547
7658
  /* @__PURE__ */ jsx("button", { type: "button", className: "ng-ct-btn ng-ct-highlight", onMouseDown: keepSelection, onClick: () => toggleInlineTag("mark"), title: "Highlight", children: "A" }),
7659
+ /* @__PURE__ */ jsx(
7660
+ "input",
7661
+ {
7662
+ type: "color",
7663
+ className: "ng-ct-color",
7664
+ title: "Text Color",
7665
+ "aria-label": "Text Color",
7666
+ defaultValue: "#18181b",
7667
+ onChange: (e) => exec("foreColor", e.target.value)
7668
+ }
7669
+ ),
7670
+ /* @__PURE__ */ jsx(
7671
+ "input",
7672
+ {
7673
+ type: "color",
7674
+ className: "ng-ct-color",
7675
+ title: "Highlight Color",
7676
+ "aria-label": "Highlight Color",
7677
+ defaultValue: "#fef08a",
7678
+ onChange: (e) => exec("hiliteColor", e.target.value)
7679
+ }
7680
+ ),
6548
7681
  /* @__PURE__ */ jsx(
6549
7682
  "button",
6550
7683
  {
@@ -6681,11 +7814,17 @@ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
6681
7814
  var SettingsModal = ({
6682
7815
  open,
6683
7816
  theme,
7817
+ docWidth,
6684
7818
  mode,
6685
7819
  showStats,
6686
7820
  aiConfig,
6687
7821
  selectedTools,
7822
+ allowedTools,
7823
+ canConfigureTools,
7824
+ developerRestricted,
7825
+ accessNoticeText,
6688
7826
  onChangeTheme,
7827
+ onChangeDocWidth,
6689
7828
  onChangeMode,
6690
7829
  onChangeShowStats,
6691
7830
  onChangeAiConfig,
@@ -6741,7 +7880,7 @@ var SettingsModal = ({
6741
7880
  /* @__PURE__ */ jsxs2("div", { className: "ng-modal-main", children: [
6742
7881
  activeTab === "appearance" && /* @__PURE__ */ jsxs2("div", { className: "ng-modal-panel", children: [
6743
7882
  /* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
6744
- /* @__PURE__ */ jsx2("label", { children: "Theme" }),
7883
+ /* @__PURE__ */ jsx2("label", { children: "Appearance" }),
6745
7884
  /* @__PURE__ */ jsxs2(
6746
7885
  "select",
6747
7886
  {
@@ -6750,16 +7889,29 @@ var SettingsModal = ({
6750
7889
  onChange: (e) => onChangeTheme(e.target.value),
6751
7890
  children: [
6752
7891
  /* @__PURE__ */ jsx2("option", { value: "inherit", children: "Inherit from Host App" }),
6753
- /* @__PURE__ */ jsx2("option", { value: "light", children: "shadcn Light" }),
6754
- /* @__PURE__ */ jsx2("option", { value: "dark", children: "shadcn Dark" }),
6755
- /* @__PURE__ */ jsx2("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
6756
- /* @__PURE__ */ jsx2("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
6757
- /* @__PURE__ */ jsx2("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
6758
- /* @__PURE__ */ jsx2("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
7892
+ /* @__PURE__ */ jsx2("option", { value: "light", children: "Light (White)" }),
7893
+ /* @__PURE__ */ jsx2("option", { value: "dark", children: "Dark (Black)" })
6759
7894
  ]
6760
7895
  }
6761
7896
  )
6762
7897
  ] }),
7898
+ /* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
7899
+ /* @__PURE__ */ jsx2("label", { children: "Document Width" }),
7900
+ /* @__PURE__ */ jsx2("div", { className: "ng-segmented", children: [
7901
+ { id: "narrow", label: "Narrow" },
7902
+ { id: "standard", label: "Standard" },
7903
+ { id: "full", label: "Full-Width" }
7904
+ ].map((w) => /* @__PURE__ */ jsx2(
7905
+ "button",
7906
+ {
7907
+ type: "button",
7908
+ className: `excalidraw-btn${docWidth === w.id ? " is-active" : ""}`,
7909
+ onClick: () => onChangeDocWidth(w.id),
7910
+ children: w.label
7911
+ },
7912
+ w.id
7913
+ )) })
7914
+ ] }),
6763
7915
  /* @__PURE__ */ jsxs2("div", { className: "ng-field", children: [
6764
7916
  /* @__PURE__ */ jsx2("label", { children: "Editor Mode" }),
6765
7917
  /* @__PURE__ */ jsxs2("div", { className: "ng-segmented", children: [
@@ -6861,21 +8013,28 @@ var SettingsModal = ({
6861
8013
  ] })
6862
8014
  ] }),
6863
8015
  activeTab === "components" && /* @__PURE__ */ jsxs2("div", { className: "ng-tools-manager", children: [
8016
+ (developerRestricted || !canConfigureTools) && /* @__PURE__ */ jsxs2("div", { className: "ng-dev-access-bar", role: "status", children: [
8017
+ /* @__PURE__ */ jsx2("strong", { children: "Access Managed by Developer:" }),
8018
+ " ",
8019
+ accessNoticeText || "Some commands are not enabled for this workspace and are hidden."
8020
+ ] }),
6864
8021
  /* @__PURE__ */ jsxs2("div", { className: "ng-tools-header", children: [
6865
8022
  /* @__PURE__ */ jsx2("div", { children: /* @__PURE__ */ jsxs2("label", { children: [
6866
8023
  "Registered Components (",
6867
8024
  selectedSet.size,
6868
8025
  "/",
6869
- ALL_TOOL_NAMES.length,
8026
+ developerRestricted && allowedTools ? allowedTools.length : ALL_TOOL_NAMES.length,
6870
8027
  ")"
6871
8028
  ] }) }),
6872
- /* @__PURE__ */ jsxs2("div", { className: "ng-tools-actions", children: [
8029
+ canConfigureTools && /* @__PURE__ */ jsxs2("div", { className: "ng-tools-actions", children: [
6873
8030
  /* @__PURE__ */ jsx2(
6874
8031
  "button",
6875
8032
  {
6876
8033
  type: "button",
6877
8034
  className: "excalidraw-btn",
6878
- onClick: () => onChangeSelectedTools([...ALL_TOOL_NAMES]),
8035
+ onClick: () => onChangeSelectedTools(
8036
+ developerRestricted && allowedTools ? [...allowedTools] : [...ALL_TOOL_NAMES]
8037
+ ),
6879
8038
  children: "All"
6880
8039
  }
6881
8040
  ),
@@ -6884,7 +8043,11 @@ var SettingsModal = ({
6884
8043
  {
6885
8044
  type: "button",
6886
8045
  className: "excalidraw-btn",
6887
- onClick: () => onChangeSelectedTools([...SIMPLE_MODE_TOOLS]),
8046
+ onClick: () => {
8047
+ const base = new Set(SIMPLE_MODE_TOOLS);
8048
+ const minimal = developerRestricted && allowedTools ? allowedTools.filter((t) => base.has(t)) : [...SIMPLE_MODE_TOOLS];
8049
+ onChangeSelectedTools(minimal);
8050
+ },
6888
8051
  children: "Minimal"
6889
8052
  }
6890
8053
  )
@@ -6902,7 +8065,9 @@ var SettingsModal = ({
6902
8065
  ),
6903
8066
  /* @__PURE__ */ jsx2("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
6904
8067
  const q = toolFilter.trim().toLowerCase();
8068
+ const allowedSet = developerRestricted && allowedTools ? new Set(allowedTools) : null;
6905
8069
  const visible = group.tools.filter((t) => {
8070
+ if (allowedSet && !allowedSet.has(t)) return false;
6906
8071
  const label = (TOOL_LABELS[t] || t).toLowerCase();
6907
8072
  return !q || label.includes(q) || t.toLowerCase().includes(q);
6908
8073
  });
@@ -6914,14 +8079,17 @@ var SettingsModal = ({
6914
8079
  return /* @__PURE__ */ jsxs2(
6915
8080
  "label",
6916
8081
  {
6917
- className: `ng-tool-chip${checked ? " is-checked" : ""}`,
8082
+ className: `ng-tool-chip${checked ? " is-checked" : ""}${!canConfigureTools ? " is-locked" : ""}`,
6918
8083
  children: [
6919
8084
  /* @__PURE__ */ jsx2(
6920
8085
  "input",
6921
8086
  {
6922
8087
  type: "checkbox",
6923
8088
  checked,
6924
- onChange: () => toggleTool(tool)
8089
+ disabled: !canConfigureTools,
8090
+ onChange: () => {
8091
+ if (canConfigureTools) toggleTool(tool);
8092
+ }
6925
8093
  }
6926
8094
  ),
6927
8095
  /* @__PURE__ */ jsx2("span", { children: TOOL_LABELS[tool] || tool })
@@ -6938,13 +8106,320 @@ var SettingsModal = ({
6938
8106
  ] }) });
6939
8107
  };
6940
8108
 
6941
- // src/components/BlockEditor.tsx
8109
+ // src/components/ExportModal.tsx
8110
+ import { useMemo, useState as useState3 } from "react";
8111
+
8112
+ // src/utils/markdown.ts
8113
+ function stripHtmlTags(html) {
8114
+ return String(html == null ? "" : html).replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div|li)>/gi, "\n").replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&#39;/g, "'").trim();
8115
+ }
8116
+ function blocksToMarkdown(data) {
8117
+ if (!data || !Array.isArray(data.blocks)) return "";
8118
+ const parts = [];
8119
+ for (const block of data.blocks) {
8120
+ const d = block.data || {};
8121
+ switch (block.type) {
8122
+ case "header":
8123
+ case "h1":
8124
+ case "h2":
8125
+ case "h3": {
8126
+ const lvl = block.type === "h1" ? 1 : block.type === "h2" ? 2 : block.type === "h3" ? 3 : Number(d.level) || 2;
8127
+ parts.push(`${"#".repeat(Math.min(6, Math.max(1, lvl)))} ${stripHtmlTags(d.text)}`);
8128
+ break;
8129
+ }
8130
+ case "paragraph":
8131
+ parts.push(stripHtmlTags(d.text));
8132
+ break;
8133
+ case "quote":
8134
+ case "pullquote": {
8135
+ const quote = stripHtmlTags(d.text).split("\n").map((l) => `> ${l}`).join("\n");
8136
+ const cap = d.caption ? `
8137
+ > \u2014 ${stripHtmlTags(d.caption)}` : "";
8138
+ parts.push(`${quote}${cap}`);
8139
+ break;
8140
+ }
8141
+ case "list":
8142
+ case "nestedlist": {
8143
+ const ordered = d.style === "ordered";
8144
+ const items = Array.isArray(d.items) ? d.items : [];
8145
+ const lines = items.map((item, idx) => {
8146
+ const txt = typeof item === "string" ? item : item?.content || item?.text || "";
8147
+ return `${ordered ? `${idx + 1}.` : "-"} ${stripHtmlTags(txt)}`;
8148
+ });
8149
+ parts.push(lines.join("\n"));
8150
+ break;
8151
+ }
8152
+ case "checklist":
8153
+ case "todo": {
8154
+ const items = Array.isArray(d.items) ? d.items : [];
8155
+ parts.push(
8156
+ items.map((item) => `- [${item.checked || item.done ? "x" : " "}] ${stripHtmlTags(item.text || item.title)}`).join("\n")
8157
+ );
8158
+ break;
8159
+ }
8160
+ case "code":
8161
+ parts.push(`\`\`\`${d.language || ""}
8162
+ ${d.code || ""}
8163
+ \`\`\``);
8164
+ break;
8165
+ case "mermaid":
8166
+ parts.push(`\`\`\`mermaid
8167
+ ${d.code || ""}
8168
+ \`\`\``);
8169
+ break;
8170
+ case "latex":
8171
+ parts.push(`$$
8172
+ ${d.tex || ""}
8173
+ $$`);
8174
+ break;
8175
+ case "delimiter":
8176
+ parts.push("---");
8177
+ break;
8178
+ case "image":
8179
+ case "simpleImage": {
8180
+ const url = d.file?.url || d.url || "";
8181
+ if (url) parts.push(`![${stripHtmlTags(d.caption || "")}](${url})`);
8182
+ break;
8183
+ }
8184
+ case "bookmark":
8185
+ parts.push(`[${d.title || d.url || "Link"}](${d.url || "#"})`);
8186
+ break;
8187
+ case "steps": {
8188
+ const items = Array.isArray(d.items) ? d.items : [];
8189
+ parts.push(
8190
+ items.map((s, i) => `${i + 1}. **${s.title || ""}** \u2014 ${s.body || ""}`).join("\n")
8191
+ );
8192
+ break;
8193
+ }
8194
+ case "diff":
8195
+ parts.push(`\`\`\`diff
8196
+ - ${String(d.before || "").replace(/\n/g, "\n- ")}
8197
+ + ${String(d.after || "").replace(/\n/g, "\n+ ")}
8198
+ \`\`\``);
8199
+ break;
8200
+ case "changelog": {
8201
+ const items = Array.isArray(d.items) ? d.items : [];
8202
+ parts.push(
8203
+ `### ${d.version || "Release"} (${d.date || ""})
8204
+ ` + items.map((i) => `- **${(i.kind || "added").toUpperCase()}**: ${i.text || ""}`).join("\n")
8205
+ );
8206
+ break;
8207
+ }
8208
+ case "social":
8209
+ parts.push(`> ${d.text || ""}
8210
+ > \u2014 ${d.author || ""} (${d.handle || ""})`);
8211
+ break;
8212
+ case "today":
8213
+ parts.push(`\u{1F4C5} ${d.date || ""}`);
8214
+ break;
8215
+ default:
8216
+ if (d.text) parts.push(stripHtmlTags(d.text));
8217
+ break;
8218
+ }
8219
+ }
8220
+ return parts.filter(Boolean).join("\n\n");
8221
+ }
8222
+ function markdownToBlocks(markdown) {
8223
+ const lines = markdown.replace(/\r\n/g, "\n").split("\n");
8224
+ const blocks = [];
8225
+ let i = 0;
8226
+ while (i < lines.length) {
8227
+ const line = lines[i];
8228
+ const trimmed = line.trim();
8229
+ if (!trimmed) {
8230
+ i += 1;
8231
+ continue;
8232
+ }
8233
+ if (trimmed.startsWith("```")) {
8234
+ const lang = trimmed.slice(3).trim();
8235
+ const codeLines = [];
8236
+ i += 1;
8237
+ while (i < lines.length && !lines[i].trim().startsWith("```")) {
8238
+ codeLines.push(lines[i]);
8239
+ i += 1;
8240
+ }
8241
+ i += 1;
8242
+ if (lang === "mermaid") {
8243
+ blocks.push({ type: "mermaid", data: { code: codeLines.join("\n") } });
8244
+ } else {
8245
+ blocks.push({ type: "code", data: { code: codeLines.join("\n"), language: lang || void 0 } });
8246
+ }
8247
+ continue;
8248
+ }
8249
+ const headingMatch = trimmed.match(/^(#{1,3})\s+(.+)$/);
8250
+ if (headingMatch) {
8251
+ const level = headingMatch[1].length;
8252
+ const type = level === 1 ? "h1" : level === 2 ? "h2" : "h3";
8253
+ blocks.push({ type, data: { text: headingMatch[2], level } });
8254
+ i += 1;
8255
+ continue;
8256
+ }
8257
+ if (/^[-*_]{3,}$/.test(trimmed)) {
8258
+ blocks.push({ type: "delimiter", data: {} });
8259
+ i += 1;
8260
+ continue;
8261
+ }
8262
+ if (trimmed.startsWith("> ")) {
8263
+ const quoteLines = [];
8264
+ while (i < lines.length && lines[i].trim().startsWith("> ")) {
8265
+ quoteLines.push(lines[i].trim().slice(2));
8266
+ i += 1;
8267
+ }
8268
+ blocks.push({ type: "quote", data: { text: quoteLines.join("\n"), caption: "" } });
8269
+ continue;
8270
+ }
8271
+ if (/^[-*]\s+/.test(trimmed) || /^\d+\.\s+/.test(trimmed)) {
8272
+ const ordered = /^\d+\.\s+/.test(trimmed);
8273
+ const items = [];
8274
+ while (i < lines.length && (ordered ? /^\d+\.\s+/.test(lines[i].trim()) : /^[-*]\s+/.test(lines[i].trim()))) {
8275
+ items.push(lines[i].trim().replace(ordered ? /^\d+\.\s+/ : /^[-*]\s+/, ""));
8276
+ i += 1;
8277
+ }
8278
+ blocks.push({ type: "list", data: { style: ordered ? "ordered" : "unordered", items } });
8279
+ continue;
8280
+ }
8281
+ blocks.push({ type: "paragraph", data: { text: trimmed } });
8282
+ i += 1;
8283
+ }
8284
+ return blocks;
8285
+ }
8286
+
8287
+ // src/components/ExportModal.tsx
6942
8288
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
6943
- var BlockEditor = React4.forwardRef(
8289
+ var ExportModal = ({
8290
+ open,
8291
+ data,
8292
+ onImportBlocks,
8293
+ onClose
8294
+ }) => {
8295
+ const [importText, setImportText] = useState3("");
8296
+ const [copiedKind, setCopiedKind] = useState3(null);
8297
+ const markdown = useMemo(() => open ? blocksToMarkdown(data) : "", [open, data]);
8298
+ const html = useMemo(() => open ? blocksToHtml(data) : "", [open, data]);
8299
+ if (!open) return null;
8300
+ const copyText = async (text, kind) => {
8301
+ try {
8302
+ await navigator.clipboard.writeText(text);
8303
+ setCopiedKind(kind);
8304
+ window.setTimeout(() => setCopiedKind(null), 1500);
8305
+ } catch {
8306
+ }
8307
+ };
8308
+ const downloadFile = (content, filename, mime) => {
8309
+ const blob = new Blob([content], { type: mime });
8310
+ const url = URL.createObjectURL(blob);
8311
+ const a = document.createElement("a");
8312
+ a.href = url;
8313
+ a.download = filename;
8314
+ a.click();
8315
+ URL.revokeObjectURL(url);
8316
+ };
8317
+ return /* @__PURE__ */ jsx3("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Export & Import", children: /* @__PURE__ */ jsxs3("div", { className: "ng-modal", children: [
8318
+ /* @__PURE__ */ jsxs3("div", { className: "ng-modal-head", children: [
8319
+ /* @__PURE__ */ jsxs3("div", { children: [
8320
+ /* @__PURE__ */ jsx3("h3", { children: "Export & Markdown" }),
8321
+ /* @__PURE__ */ jsx3("p", { children: "Export to Markdown, HTML, PDF, or import Markdown into blocks." })
8322
+ ] }),
8323
+ /* @__PURE__ */ jsx3("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
8324
+ ] }),
8325
+ /* @__PURE__ */ jsxs3("div", { className: "ng-modal-panel", children: [
8326
+ /* @__PURE__ */ jsxs3("div", { className: "ng-field", children: [
8327
+ /* @__PURE__ */ jsx3("label", { children: "Quick Export" }),
8328
+ /* @__PURE__ */ jsxs3("div", { className: "ng-inline-ai-row", children: [
8329
+ /* @__PURE__ */ jsx3(
8330
+ "button",
8331
+ {
8332
+ type: "button",
8333
+ className: "excalidraw-btn",
8334
+ onClick: () => void copyText(markdown, "md"),
8335
+ children: copiedKind === "md" ? "Copied MD!" : "Copy Markdown"
8336
+ }
8337
+ ),
8338
+ /* @__PURE__ */ jsx3(
8339
+ "button",
8340
+ {
8341
+ type: "button",
8342
+ className: "excalidraw-btn",
8343
+ onClick: () => downloadFile(markdown, "document.md", "text/markdown"),
8344
+ children: "Download .md"
8345
+ }
8346
+ ),
8347
+ /* @__PURE__ */ jsx3(
8348
+ "button",
8349
+ {
8350
+ type: "button",
8351
+ className: "excalidraw-btn",
8352
+ onClick: () => void copyText(html, "html"),
8353
+ children: copiedKind === "html" ? "Copied HTML!" : "Copy HTML"
8354
+ }
8355
+ ),
8356
+ /* @__PURE__ */ jsx3(
8357
+ "button",
8358
+ {
8359
+ type: "button",
8360
+ className: "excalidraw-btn",
8361
+ onClick: () => downloadFile(
8362
+ `<!doctype html><html><head><meta charset="utf-8"><title>Document</title></head><body>${html}</body></html>`,
8363
+ "document.html",
8364
+ "text/html"
8365
+ ),
8366
+ children: "Download .html"
8367
+ }
8368
+ ),
8369
+ /* @__PURE__ */ jsx3(
8370
+ "button",
8371
+ {
8372
+ type: "button",
8373
+ className: "excalidraw-btn",
8374
+ onClick: () => window.print(),
8375
+ children: "Print / PDF"
8376
+ }
8377
+ )
8378
+ ] })
8379
+ ] }),
8380
+ /* @__PURE__ */ jsxs3("div", { className: "ng-field", children: [
8381
+ /* @__PURE__ */ jsx3("label", { children: "Import Markdown" }),
8382
+ /* @__PURE__ */ jsx3(
8383
+ "textarea",
8384
+ {
8385
+ className: "editor-mermaid-input",
8386
+ rows: 5,
8387
+ placeholder: "Paste Markdown here (# Heading, - list, ```mermaid ...```)...",
8388
+ value: importText,
8389
+ onChange: (e) => setImportText(e.target.value)
8390
+ }
8391
+ ),
8392
+ /* @__PURE__ */ jsx3("div", { children: /* @__PURE__ */ jsx3(
8393
+ "button",
8394
+ {
8395
+ type: "button",
8396
+ className: "excalidraw-btn is-active",
8397
+ disabled: !importText.trim(),
8398
+ onClick: () => {
8399
+ const blocks = markdownToBlocks(importText);
8400
+ if (blocks.length > 0) {
8401
+ onImportBlocks(blocks);
8402
+ setImportText("");
8403
+ onClose();
8404
+ }
8405
+ },
8406
+ children: "Append Markdown as Blocks"
8407
+ }
8408
+ ) })
8409
+ ] })
8410
+ ] })
8411
+ ] }) });
8412
+ };
8413
+
8414
+ // src/components/BlockEditor.tsx
8415
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
8416
+ var BlockEditor = React5.forwardRef(
6944
8417
  ({
6945
8418
  initialData,
6946
8419
  placeholder,
6947
8420
  enabledTools,
8421
+ allowToolConfiguration,
8422
+ accessNoticeText,
6948
8423
  showStats = true,
6949
8424
  showAiBar = false,
6950
8425
  onAiRequest,
@@ -6963,18 +8438,27 @@ var BlockEditor = React4.forwardRef(
6963
8438
  const onReadyRef = useRef2(onReady);
6964
8439
  const runAiRef = useRef2(async () => {
6965
8440
  });
6966
- const [settingsOpen, setSettingsOpen] = useState3(false);
6967
- const [theme, setTheme] = useState3(() => {
8441
+ const [settingsOpen, setSettingsOpen] = useState4(false);
8442
+ const [exportOpen, setExportOpen] = useState4(false);
8443
+ const [theme, setTheme] = useState4(() => {
6968
8444
  try {
6969
8445
  const saved = localStorage.getItem("ng-editor-theme");
6970
- if (saved) return saved;
8446
+ if (saved === "light" || saved === "dark" || saved === "inherit") return saved;
6971
8447
  } catch {
6972
8448
  }
6973
8449
  return "inherit";
6974
8450
  });
6975
- const [editorMode, setEditorMode] = useState3("block");
6976
- const [simpleFont, setSimpleFont] = useState3("sans");
6977
- const [selectedTools, setSelectedTools] = useState3(() => {
8451
+ const [docWidth, setDocWidth] = useState4(() => {
8452
+ try {
8453
+ const saved = localStorage.getItem("ng-editor-width");
8454
+ if (saved === "narrow" || saved === "standard" || saved === "full") return saved;
8455
+ } catch {
8456
+ }
8457
+ return "full";
8458
+ });
8459
+ const [editorMode, setEditorMode] = useState4("block");
8460
+ const [simpleFont, setSimpleFont] = useState4("sans");
8461
+ const [selectedTools, setSelectedTools] = useState4(() => {
6978
8462
  if (enabledTools && enabledTools.length > 0) return enabledTools;
6979
8463
  try {
6980
8464
  const raw = localStorage.getItem("ng-enabled-tools");
@@ -6986,23 +8470,28 @@ var BlockEditor = React4.forwardRef(
6986
8470
  }
6987
8471
  return ALL_TOOL_NAMES;
6988
8472
  });
6989
- const [statsVisible, setStatsVisible] = useState3(showStats);
6990
- const [aiConfig, setAiConfig] = useState3(loadAiConfig);
6991
- const [aiPopover, setAiPopover] = useState3(null);
6992
- const [askPrompt, setAskPrompt] = useState3("");
6993
- const [aiBusy, setAiBusy] = useState3(false);
6994
- const [aiError, setAiError] = useState3(null);
6995
- const [scratchOpen, setScratchOpen] = useState3(false);
6996
- const [scratchText, setScratchText] = useState3(() => {
8473
+ const [statsVisible, setStatsVisible] = useState4(showStats);
8474
+ const developerRestricted = Boolean(
8475
+ enabledTools && enabledTools.length > 0 && allowToolConfiguration !== true
8476
+ );
8477
+ const canConfigureTools = allowToolConfiguration ?? !developerRestricted;
8478
+ const effectiveSelectedTools = developerRestricted && enabledTools ? enabledTools : selectedTools;
8479
+ const [aiConfig, setAiConfig] = useState4(loadAiConfig);
8480
+ const [aiPopover, setAiPopover] = useState4(null);
8481
+ const [askPrompt, setAskPrompt] = useState4("");
8482
+ const [aiBusy, setAiBusy] = useState4(false);
8483
+ const [aiError, setAiError] = useState4(null);
8484
+ const [scratchOpen, setScratchOpen] = useState4(false);
8485
+ const [scratchText, setScratchText] = useState4(() => {
6997
8486
  try {
6998
8487
  return localStorage.getItem("ng-scratchpad-note") || "";
6999
8488
  } catch {
7000
8489
  return "";
7001
8490
  }
7002
8491
  });
7003
- const [scratchCopied, setScratchCopied] = useState3(false);
7004
- const [scratchOffset, setScratchOffset] = useState3({ x: 0, y: 0 });
7005
- const [stats, setStats] = useState3(() => {
8492
+ const [scratchCopied, setScratchCopied] = useState4(false);
8493
+ const [scratchOffset, setScratchOffset] = useState4({ x: 0, y: 0 });
8494
+ const [stats, setStats] = useState4(() => {
7006
8495
  const blocks = initialData?.blocks || [];
7007
8496
  const text = blocks.map((b) => JSON.stringify(b.data || {})).join(" ");
7008
8497
  const words = text.trim() ? text.trim().split(/\s+/).length : 0;
@@ -7042,18 +8531,39 @@ var BlockEditor = React4.forwardRef(
7042
8531
  setAiPopover({ mode, top, left });
7043
8532
  };
7044
8533
  const onOpenSettings = () => setSettingsOpen(true);
8534
+ const onOpenExport = () => setExportOpen(true);
7045
8535
  const onAiContinue = (e) => openAiNearRect("continue", e);
7046
8536
  const onAiAsk = (e) => openAiNearRect("ask", e);
7047
8537
  const onOpenScratch = () => setScratchOpen(true);
8538
+ const onKeyDown = async (e) => {
8539
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "d") {
8540
+ e.preventDefault();
8541
+ const ed = editorRef.current;
8542
+ if (!ed) return;
8543
+ try {
8544
+ const idx = ed.blocks.getCurrentBlockIndex();
8545
+ const saved = await ed.save();
8546
+ const blk = saved.blocks?.[idx];
8547
+ if (blk) {
8548
+ ed.blocks.insert(blk.type, blk.data, {}, idx + 1, true);
8549
+ }
8550
+ } catch {
8551
+ }
8552
+ }
8553
+ };
7048
8554
  shell.addEventListener("nextgen-open-settings", onOpenSettings);
8555
+ shell.addEventListener("nextgen-open-export", onOpenExport);
7049
8556
  shell.addEventListener("nextgen-ai-continue", onAiContinue);
7050
8557
  shell.addEventListener("nextgen-ai-ask", onAiAsk);
7051
8558
  shell.addEventListener("nextgen-open-scratch", onOpenScratch);
8559
+ shell.addEventListener("keydown", onKeyDown);
7052
8560
  return () => {
7053
8561
  shell.removeEventListener("nextgen-open-settings", onOpenSettings);
8562
+ shell.removeEventListener("nextgen-open-export", onOpenExport);
7054
8563
  shell.removeEventListener("nextgen-ai-continue", onAiContinue);
7055
8564
  shell.removeEventListener("nextgen-ai-ask", onAiAsk);
7056
8565
  shell.removeEventListener("nextgen-open-scratch", onOpenScratch);
8566
+ shell.removeEventListener("keydown", onKeyDown);
7057
8567
  };
7058
8568
  }, []);
7059
8569
  useEffect2(() => {
@@ -7062,7 +8572,7 @@ var BlockEditor = React4.forwardRef(
7062
8572
  let cancelled = false;
7063
8573
  const detachCategories = attachPopoverCategoryHeaders(holder);
7064
8574
  const detachEmoji = attachEmojiSidePicker(holder);
7065
- const effectiveTools = Array.from(/* @__PURE__ */ new Set([...selectedTools, "settings"]));
8575
+ const effectiveTools = Array.from(/* @__PURE__ */ new Set([...effectiveSelectedTools, "settings"]));
7066
8576
  const mount = async () => {
7067
8577
  await lifecycleRef.current;
7068
8578
  if (cancelled) return;
@@ -7128,7 +8638,7 @@ var BlockEditor = React4.forwardRef(
7128
8638
  });
7129
8639
  }
7130
8640
  };
7131
- }, [editorMode, selectedTools]);
8641
+ }, [editorMode, effectiveSelectedTools]);
7132
8642
  useImperativeHandle(ref, () => ({
7133
8643
  save: async () => {
7134
8644
  if (!editorRef.current) return null;
@@ -7204,17 +8714,18 @@ var BlockEditor = React4.forwardRef(
7204
8714
  setEditorMode(nextMode);
7205
8715
  };
7206
8716
  const readMins = Math.max(1, Math.ceil(stats.words / 200));
7207
- return /* @__PURE__ */ jsxs3(
8717
+ return /* @__PURE__ */ jsxs4(
7208
8718
  "div",
7209
8719
  {
7210
8720
  ref: shellRef,
7211
8721
  "data-ng-theme": theme === "inherit" ? void 0 : theme,
8722
+ "data-ng-width": docWidth,
7212
8723
  "data-ng-font": editorMode === "simple" ? simpleFont : void 0,
7213
8724
  className: className ? `nextgen-editor-shell ${className}` : "nextgen-editor-shell",
7214
8725
  children: [
7215
- showAiBar && /* @__PURE__ */ jsxs3("div", { className: "ng-ai-bar", children: [
7216
- /* @__PURE__ */ jsxs3("div", { className: "ng-ai-actions", children: [
7217
- /* @__PURE__ */ jsx3(
8726
+ showAiBar && /* @__PURE__ */ jsxs4("div", { className: "ng-ai-bar", children: [
8727
+ /* @__PURE__ */ jsxs4("div", { className: "ng-ai-actions", children: [
8728
+ /* @__PURE__ */ jsx4(
7218
8729
  "button",
7219
8730
  {
7220
8731
  type: "button",
@@ -7224,7 +8735,7 @@ var BlockEditor = React4.forwardRef(
7224
8735
  children: aiBusy ? "Thinking\u2026" : "\u2726 Continue Writing"
7225
8736
  }
7226
8737
  ),
7227
- /* @__PURE__ */ jsx3(
8738
+ /* @__PURE__ */ jsx4(
7228
8739
  "button",
7229
8740
  {
7230
8741
  type: "button",
@@ -7237,7 +8748,7 @@ var BlockEditor = React4.forwardRef(
7237
8748
  }
7238
8749
  )
7239
8750
  ] }),
7240
- /* @__PURE__ */ jsx3(
8751
+ /* @__PURE__ */ jsx4(
7241
8752
  "button",
7242
8753
  {
7243
8754
  type: "button",
@@ -7248,7 +8759,7 @@ var BlockEditor = React4.forwardRef(
7248
8759
  }
7249
8760
  )
7250
8761
  ] }),
7251
- editorMode === "simple" && /* @__PURE__ */ jsx3(
8762
+ editorMode === "simple" && /* @__PURE__ */ jsx4(
7252
8763
  ClassicToolbar,
7253
8764
  {
7254
8765
  editorRef,
@@ -7256,38 +8767,50 @@ var BlockEditor = React4.forwardRef(
7256
8767
  onRedo: () => undoRef.current?.redo?.(),
7257
8768
  fontFamily: simpleFont,
7258
8769
  onChangeFontFamily: setSimpleFont,
7259
- enabledTools: selectedTools,
8770
+ enabledTools: effectiveSelectedTools,
7260
8771
  onOpenSettings: () => setSettingsOpen(true)
7261
8772
  }
7262
8773
  ),
7263
- /* @__PURE__ */ jsx3("div", { id: "editorjs", ref: holderRef }),
7264
- statsVisible && /* @__PURE__ */ jsxs3("div", { className: "nextgen-editor-stats", children: [
7265
- /* @__PURE__ */ jsx3("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
7266
- /* @__PURE__ */ jsx3("span", { children: "\u2022" }),
7267
- /* @__PURE__ */ jsxs3("span", { children: [
8774
+ /* @__PURE__ */ jsx4("div", { id: "editorjs", ref: holderRef }),
8775
+ statsVisible && /* @__PURE__ */ jsxs4("div", { className: "nextgen-editor-stats", children: [
8776
+ /* @__PURE__ */ jsx4("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
8777
+ /* @__PURE__ */ jsx4("span", { children: "\u2022" }),
8778
+ /* @__PURE__ */ jsxs4("span", { children: [
7268
8779
  stats.blocks,
7269
8780
  " blocks"
7270
8781
  ] }),
7271
- /* @__PURE__ */ jsxs3("span", { children: [
8782
+ /* @__PURE__ */ jsxs4("span", { children: [
7272
8783
  stats.words,
7273
8784
  " words"
7274
8785
  ] }),
7275
- /* @__PURE__ */ jsxs3("span", { children: [
8786
+ /* @__PURE__ */ jsxs4("span", { children: [
7276
8787
  "~",
7277
8788
  readMins,
7278
8789
  " min read"
7279
8790
  ] })
7280
8791
  ] }),
7281
- /* @__PURE__ */ jsx3(
8792
+ /* @__PURE__ */ jsx4(
7282
8793
  SettingsModal,
7283
8794
  {
7284
8795
  open: settingsOpen,
7285
8796
  theme,
8797
+ docWidth,
7286
8798
  mode: editorMode,
7287
8799
  showStats: statsVisible,
7288
8800
  aiConfig,
7289
- selectedTools,
8801
+ selectedTools: effectiveSelectedTools,
8802
+ allowedTools: enabledTools,
8803
+ canConfigureTools,
8804
+ developerRestricted,
8805
+ accessNoticeText,
7290
8806
  onChangeTheme: setTheme,
8807
+ onChangeDocWidth: (w) => {
8808
+ setDocWidth(w);
8809
+ try {
8810
+ localStorage.setItem("ng-editor-width", w);
8811
+ } catch {
8812
+ }
8813
+ },
7291
8814
  onChangeMode: (m) => void handleModeSwitch(m),
7292
8815
  onChangeShowStats: setStatsVisible,
7293
8816
  onChangeAiConfig: (cfg) => {
@@ -7305,7 +8828,22 @@ var BlockEditor = React4.forwardRef(
7305
8828
  onClose: () => setSettingsOpen(false)
7306
8829
  }
7307
8830
  ),
7308
- aiPopover && /* @__PURE__ */ jsxs3(
8831
+ /* @__PURE__ */ jsx4(
8832
+ ExportModal,
8833
+ {
8834
+ open: exportOpen,
8835
+ data: latestDocRef.current,
8836
+ onImportBlocks: (blocks) => {
8837
+ const ed = editorRef.current;
8838
+ if (!ed) return;
8839
+ blocks.forEach((b) => {
8840
+ ed.blocks.insert(b.type, b.data);
8841
+ });
8842
+ },
8843
+ onClose: () => setExportOpen(false)
8844
+ }
8845
+ ),
8846
+ aiPopover && /* @__PURE__ */ jsxs4(
7309
8847
  "form",
7310
8848
  {
7311
8849
  className: "ng-ai-inline-popover",
@@ -7319,9 +8857,9 @@ var BlockEditor = React4.forwardRef(
7319
8857
  }
7320
8858
  },
7321
8859
  children: [
7322
- /* @__PURE__ */ jsxs3("div", { className: "ng-ai-inline-head", children: [
7323
- /* @__PURE__ */ jsx3("span", { children: aiPopover.mode === "continue" ? "\u2726 Continue Writing" : "Ask AI" }),
7324
- /* @__PURE__ */ jsx3(
8860
+ /* @__PURE__ */ jsxs4("div", { className: "ng-ai-inline-head", children: [
8861
+ /* @__PURE__ */ jsx4("span", { children: aiPopover.mode === "continue" ? "\u2726 Continue Writing" : "Ask AI" }),
8862
+ /* @__PURE__ */ jsx4(
7325
8863
  "button",
7326
8864
  {
7327
8865
  type: "button",
@@ -7332,8 +8870,8 @@ var BlockEditor = React4.forwardRef(
7332
8870
  }
7333
8871
  )
7334
8872
  ] }),
7335
- /* @__PURE__ */ jsxs3("div", { className: "ng-ai-inline-row", children: [
7336
- /* @__PURE__ */ jsx3(
8873
+ /* @__PURE__ */ jsxs4("div", { className: "ng-ai-inline-row", children: [
8874
+ /* @__PURE__ */ jsx4(
7337
8875
  "input",
7338
8876
  {
7339
8877
  type: "text",
@@ -7347,7 +8885,7 @@ var BlockEditor = React4.forwardRef(
7347
8885
  }
7348
8886
  }
7349
8887
  ),
7350
- /* @__PURE__ */ jsx3(
8888
+ /* @__PURE__ */ jsx4(
7351
8889
  "button",
7352
8890
  {
7353
8891
  type: "submit",
@@ -7357,11 +8895,11 @@ var BlockEditor = React4.forwardRef(
7357
8895
  }
7358
8896
  )
7359
8897
  ] }),
7360
- aiError && /* @__PURE__ */ jsx3("div", { className: "ng-ai-error", children: aiError })
8898
+ aiError && /* @__PURE__ */ jsx4("div", { className: "ng-ai-error", children: aiError })
7361
8899
  ]
7362
8900
  }
7363
8901
  ),
7364
- scratchOpen && /* @__PURE__ */ jsxs3(
8902
+ scratchOpen && /* @__PURE__ */ jsxs4(
7365
8903
  "div",
7366
8904
  {
7367
8905
  className: "ng-scratch-sticky",
@@ -7371,7 +8909,7 @@ var BlockEditor = React4.forwardRef(
7371
8909
  transform: `translate(${scratchOffset.x}px, ${scratchOffset.y}px)`
7372
8910
  },
7373
8911
  children: [
7374
- /* @__PURE__ */ jsxs3(
8912
+ /* @__PURE__ */ jsxs4(
7375
8913
  "div",
7376
8914
  {
7377
8915
  className: "ng-scratch-sticky-head",
@@ -7390,15 +8928,15 @@ var BlockEditor = React4.forwardRef(
7390
8928
  window.addEventListener("mouseup", onUp);
7391
8929
  },
7392
8930
  children: [
7393
- /* @__PURE__ */ jsx3("span", { className: "ng-scratch-sticky-title", children: "\u{1F4DD} Scratchpad" }),
7394
- /* @__PURE__ */ jsxs3("span", { className: "ng-scratch-sticky-count", children: [
8931
+ /* @__PURE__ */ jsx4("span", { className: "ng-scratch-sticky-title", children: "\u{1F4DD} Scratchpad" }),
8932
+ /* @__PURE__ */ jsxs4("span", { className: "ng-scratch-sticky-count", children: [
7395
8933
  scratchText.trim() ? scratchText.trim().split(/\s+/).length : 0,
7396
8934
  "w \xB7 ",
7397
8935
  scratchText.length,
7398
8936
  "c"
7399
8937
  ] }),
7400
- /* @__PURE__ */ jsxs3("div", { className: "ng-scratch-sticky-actions", children: [
7401
- /* @__PURE__ */ jsx3(
8938
+ /* @__PURE__ */ jsxs4("div", { className: "ng-scratch-sticky-actions", children: [
8939
+ /* @__PURE__ */ jsx4(
7402
8940
  "button",
7403
8941
  {
7404
8942
  type: "button",
@@ -7412,7 +8950,7 @@ var BlockEditor = React4.forwardRef(
7412
8950
  children: scratchCopied ? "Copied" : "Copy"
7413
8951
  }
7414
8952
  ),
7415
- /* @__PURE__ */ jsx3(
8953
+ /* @__PURE__ */ jsx4(
7416
8954
  "button",
7417
8955
  {
7418
8956
  type: "button",
@@ -7427,7 +8965,7 @@ var BlockEditor = React4.forwardRef(
7427
8965
  children: "Clear"
7428
8966
  }
7429
8967
  ),
7430
- /* @__PURE__ */ jsx3(
8968
+ /* @__PURE__ */ jsx4(
7431
8969
  "button",
7432
8970
  {
7433
8971
  type: "button",
@@ -7441,7 +8979,7 @@ var BlockEditor = React4.forwardRef(
7441
8979
  ]
7442
8980
  }
7443
8981
  ),
7444
- /* @__PURE__ */ jsx3(
8982
+ /* @__PURE__ */ jsx4(
7445
8983
  "textarea",
7446
8984
  {
7447
8985
  className: "ng-scratch-sticky-body",
@@ -7468,7 +9006,7 @@ var BlockEditor = React4.forwardRef(
7468
9006
  BlockEditor.displayName = "BlockEditor";
7469
9007
 
7470
9008
  // src/components/BlockRenderer.tsx
7471
- import { useMemo, useRef as useRef3 } from "react";
9009
+ import { useEffect as useEffect4, useMemo as useMemo2, useRef as useRef3, useState as useState5 } from "react";
7472
9010
 
7473
9011
  // src/hooks/useInteractiveArticle.ts
7474
9012
  import Chart2 from "chart.js/auto";
@@ -8157,6 +9695,12 @@ function useInteractiveArticle(containerRef, depKey) {
8157
9695
  btn.addEventListener("click", onOpen);
8158
9696
  cleanups.push(() => btn.removeEventListener("click", onOpen));
8159
9697
  });
9698
+ root.querySelectorAll("[data-mermaid]").forEach((el) => {
9699
+ const code = el.getAttribute("data-mermaid") || "";
9700
+ if (code.trim()) {
9701
+ void renderMermaidInto(el, code);
9702
+ }
9703
+ });
8160
9704
  return () => {
8161
9705
  cleanups.forEach((fn) => fn());
8162
9706
  };
@@ -8164,15 +9708,33 @@ function useInteractiveArticle(containerRef, depKey) {
8164
9708
  }
8165
9709
 
8166
9710
  // src/components/BlockRenderer.tsx
8167
- import { jsx as jsx4 } from "react/jsx-runtime";
9711
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
8168
9712
  var BlockRenderer = ({
8169
9713
  data,
8170
9714
  theme,
8171
9715
  className
8172
9716
  }) => {
8173
9717
  const bodyRef = useRef3(null);
8174
- const html = useMemo(() => blocksToHtml(data), [data]);
9718
+ const [progress, setProgress] = useState5(0);
9719
+ const html = useMemo2(() => blocksToHtml(data), [data]);
8175
9720
  useInteractiveArticle(bodyRef, html);
9721
+ useEffect4(() => {
9722
+ const updateProgress = () => {
9723
+ const el = bodyRef.current;
9724
+ if (!el) return;
9725
+ const rect = el.getBoundingClientRect();
9726
+ const total = Math.max(1, el.scrollHeight - window.innerHeight);
9727
+ const scrolled = Math.min(total, Math.max(0, -rect.top));
9728
+ setProgress(Math.round(scrolled / total * 100));
9729
+ };
9730
+ updateProgress();
9731
+ window.addEventListener("scroll", updateProgress, { passive: true });
9732
+ window.addEventListener("resize", updateProgress);
9733
+ return () => {
9734
+ window.removeEventListener("scroll", updateProgress);
9735
+ window.removeEventListener("resize", updateProgress);
9736
+ };
9737
+ }, [html]);
8176
9738
  let resolvedTheme = theme;
8177
9739
  if (!resolvedTheme && typeof window !== "undefined") {
8178
9740
  resolvedTheme = document.documentElement.getAttribute("data-ng-theme") || (() => {
@@ -8183,20 +9745,23 @@ var BlockRenderer = ({
8183
9745
  }
8184
9746
  })();
8185
9747
  }
8186
- const attrTheme = resolvedTheme && resolvedTheme !== "inherit" ? resolvedTheme : void 0;
8187
- return /* @__PURE__ */ jsx4(
9748
+ const attrTheme = resolvedTheme === "light" || resolvedTheme === "dark" ? resolvedTheme : void 0;
9749
+ return /* @__PURE__ */ jsxs5(
8188
9750
  "div",
8189
9751
  {
8190
9752
  ref: bodyRef,
8191
9753
  "data-ng-theme": attrTheme,
8192
9754
  className: className ? `article nextgen-editor-article ${className}` : "article nextgen-editor-article",
8193
- dangerouslySetInnerHTML: { __html: html }
9755
+ children: [
9756
+ /* @__PURE__ */ jsx5("div", { className: "ng-reading-progress", "aria-hidden": "true", children: /* @__PURE__ */ jsx5("div", { className: "ng-reading-progress-fill", style: { width: `${progress}%` } }) }),
9757
+ /* @__PURE__ */ jsx5("div", { dangerouslySetInnerHTML: { __html: html } })
9758
+ ]
8194
9759
  }
8195
9760
  );
8196
9761
  };
8197
9762
 
8198
9763
  // src/components/DocumentHeader.tsx
8199
- import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
9764
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
8200
9765
  var DocumentHeader = ({
8201
9766
  coverUrl,
8202
9767
  gradient = "linear-gradient(135deg, #27272a 0%, #52525b 100%)",
@@ -8206,12 +9771,12 @@ var DocumentHeader = ({
8206
9771
  className
8207
9772
  }) => {
8208
9773
  const bannerStyle = coverUrl ? { backgroundImage: `url("${coverUrl}")`, backgroundSize: "cover", backgroundPosition: "center" } : { background: gradient };
8209
- return /* @__PURE__ */ jsxs4("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
8210
- /* @__PURE__ */ jsx5("div", { className: "editor-cover-banner", style: bannerStyle }),
8211
- icon ? /* @__PURE__ */ jsx5("div", { className: "editor-cover-icon", children: icon }) : null,
8212
- /* @__PURE__ */ jsxs4("div", { className: "editor-cover-meta", children: [
8213
- /* @__PURE__ */ jsx5("h1", { className: "editor-cover-title", children: title }),
8214
- subtitle ? /* @__PURE__ */ jsx5("p", { className: "editor-cover-subtitle", children: subtitle }) : null
9774
+ return /* @__PURE__ */ jsxs6("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
9775
+ /* @__PURE__ */ jsx6("div", { className: "editor-cover-banner", style: bannerStyle }),
9776
+ icon ? /* @__PURE__ */ jsx6("div", { className: "editor-cover-icon", children: icon }) : null,
9777
+ /* @__PURE__ */ jsxs6("div", { className: "editor-cover-meta", children: [
9778
+ /* @__PURE__ */ jsx6("h1", { className: "editor-cover-title", children: title }),
9779
+ subtitle ? /* @__PURE__ */ jsx6("p", { className: "editor-cover-subtitle", children: subtitle }) : null
8215
9780
  ] })
8216
9781
  ] });
8217
9782
  };
@@ -8220,8 +9785,10 @@ export {
8220
9785
  BlockRenderer,
8221
9786
  DocumentHeader,
8222
9787
  blocksToHtml,
9788
+ blocksToMarkdown,
8223
9789
  escHtml,
8224
9790
  getEditorTools,
9791
+ markdownToBlocks,
8225
9792
  sanitizeInlineHtml,
8226
9793
  slugify,
8227
9794
  uploadFileToBucket,