nextgen-block-editor 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -44,7 +44,7 @@ __export(index_exports, {
44
44
  module.exports = __toCommonJS(index_exports);
45
45
 
46
46
  // src/components/BlockEditor.tsx
47
- var import_react3 = __toESM(require("react"), 1);
47
+ var import_react4 = __toESM(require("react"), 1);
48
48
  var import_editorjs2 = __toESM(require("@editorjs/editorjs"), 1);
49
49
  var import_editorjs_drag_drop = __toESM(require("editorjs-drag-drop"), 1);
50
50
  var import_editorjs_undo = __toESM(require("editorjs-undo"), 1);
@@ -292,7 +292,7 @@ function sanitizeInlineHtml(value) {
292
292
  }
293
293
  const template = document.createElement("template");
294
294
  template.innerHTML = String(value == null ? "" : value);
295
- const allowed = ["A", "MARK", "SPAN", "U", "S", "STRIKE", "CODE", "B", "STRONG", "I", "EM"];
295
+ const allowed = ["A", "MARK", "SPAN", "U", "S", "STRIKE", "CODE", "B", "STRONG", "I", "EM", "SUP", "SUB"];
296
296
  template.content.querySelectorAll("*").forEach((element) => {
297
297
  if (!allowed.includes(element.tagName)) {
298
298
  element.replaceWith(document.createTextNode(element.textContent || ""));
@@ -1634,6 +1634,141 @@ var import_client = require("react-dom/client");
1634
1634
  var import_excalidraw = require("@excalidraw/excalidraw");
1635
1635
  var import_auto = __toESM(require("chart.js/auto"), 1);
1636
1636
  var import_katex2 = __toESM(require("katex"), 1);
1637
+
1638
+ // src/utils/emojiSidePicker.ts
1639
+ var activeMenuCleanup = null;
1640
+ function openEmojiSideMenu({
1641
+ anchorRect,
1642
+ onSelect,
1643
+ onClose
1644
+ }) {
1645
+ if (activeMenuCleanup) {
1646
+ activeMenuCleanup();
1647
+ activeMenuCleanup = null;
1648
+ }
1649
+ const popover = document.createElement("div");
1650
+ popover.className = "editor-emoji-side-popover";
1651
+ popover.setAttribute("role", "dialog");
1652
+ popover.setAttribute("aria-label", "Emoji picker");
1653
+ const menuW = 264;
1654
+ const menuH = 290;
1655
+ const gap = 8;
1656
+ const fitsRight = anchorRect.right + gap + menuW <= window.innerWidth - 8;
1657
+ const left = fitsRight ? anchorRect.right + gap : Math.max(8, anchorRect.left - menuW - gap);
1658
+ const top = Math.max(
1659
+ 8,
1660
+ Math.min(anchorRect.top, window.innerHeight - menuH - 8)
1661
+ );
1662
+ popover.style.left = `${left}px`;
1663
+ popover.style.top = `${top}px`;
1664
+ const searchIn = document.createElement("input");
1665
+ searchIn.type = "search";
1666
+ searchIn.className = "cdx-input editor-form-input";
1667
+ searchIn.placeholder = "Search emoji (fire, rocket...)";
1668
+ const grid = document.createElement("div");
1669
+ grid.className = "editor-emoji-grid";
1670
+ const close = () => {
1671
+ document.removeEventListener("mousedown", onOutside, true);
1672
+ document.removeEventListener("keydown", onKey, true);
1673
+ popover.remove();
1674
+ activeMenuCleanup = null;
1675
+ onClose?.();
1676
+ };
1677
+ const renderGrid = (query = "") => {
1678
+ grid.innerHTML = "";
1679
+ const q = query.trim().toLowerCase();
1680
+ const filtered = q ? EMOJI_PRESETS.filter((p) => p.name.includes(q) || p.em.includes(q)) : EMOJI_PRESETS;
1681
+ filtered.forEach(({ em, name }) => {
1682
+ const btn = document.createElement("button");
1683
+ btn.type = "button";
1684
+ btn.title = name;
1685
+ btn.className = "editor-emoji-btn";
1686
+ btn.textContent = em;
1687
+ btn.addEventListener("mousedown", (e) => e.preventDefault());
1688
+ btn.addEventListener("click", () => {
1689
+ const cb = onSelect;
1690
+ close();
1691
+ cb(em);
1692
+ });
1693
+ grid.appendChild(btn);
1694
+ });
1695
+ };
1696
+ const onOutside = (e) => {
1697
+ if (!popover.contains(e.target)) {
1698
+ close();
1699
+ }
1700
+ };
1701
+ const onKey = (e) => {
1702
+ if (e.key === "Escape") {
1703
+ e.preventDefault();
1704
+ e.stopPropagation();
1705
+ close();
1706
+ }
1707
+ };
1708
+ searchIn.addEventListener("input", () => renderGrid(searchIn.value));
1709
+ renderGrid();
1710
+ popover.append(searchIn, grid);
1711
+ document.body.appendChild(popover);
1712
+ document.addEventListener("mousedown", onOutside, true);
1713
+ document.addEventListener("keydown", onKey, true);
1714
+ queueMicrotask(() => searchIn.focus());
1715
+ activeMenuCleanup = close;
1716
+ return close;
1717
+ }
1718
+ function attachEmojiSidePicker(container) {
1719
+ const onInput = (e) => {
1720
+ const target = e.target;
1721
+ if (!target || !target.isContentEditable) return;
1722
+ const sel = window.getSelection();
1723
+ if (!sel || sel.rangeCount === 0) return;
1724
+ const range = sel.getRangeAt(0);
1725
+ if (range.startContainer.nodeType !== Node.TEXT_NODE || !range.collapsed) {
1726
+ return;
1727
+ }
1728
+ const textNode = range.startContainer;
1729
+ const offset = range.startOffset;
1730
+ const before = textNode.data.slice(0, offset);
1731
+ if (!/(^|\s)\/emoji$/i.test(before)) return;
1732
+ const triggerStart = offset - "/emoji".length;
1733
+ const triggerRange = document.createRange();
1734
+ triggerRange.setStart(textNode, triggerStart);
1735
+ triggerRange.setEnd(textNode, offset);
1736
+ const rect = triggerRange.getBoundingClientRect();
1737
+ openEmojiSideMenu({
1738
+ anchorRect: rect,
1739
+ onSelect: (emoji) => {
1740
+ if (!textNode.isConnected) return;
1741
+ const current = textNode.data;
1742
+ const nextText = current.slice(0, triggerStart) + emoji + current.slice(offset);
1743
+ textNode.data = nextText;
1744
+ const nextCaret = triggerStart + emoji.length;
1745
+ const newRange = document.createRange();
1746
+ newRange.setStart(textNode, nextCaret);
1747
+ newRange.setEnd(textNode, nextCaret);
1748
+ const s = window.getSelection();
1749
+ if (s) {
1750
+ s.removeAllRanges();
1751
+ s.addRange(newRange);
1752
+ }
1753
+ target.focus();
1754
+ target.dispatchEvent(new Event("input", { bubbles: true }));
1755
+ },
1756
+ onClose: () => {
1757
+ target.focus();
1758
+ }
1759
+ });
1760
+ };
1761
+ container.addEventListener("input", onInput);
1762
+ return () => {
1763
+ container.removeEventListener("input", onInput);
1764
+ if (activeMenuCleanup) {
1765
+ activeMenuCleanup();
1766
+ activeMenuCleanup = null;
1767
+ }
1768
+ };
1769
+ }
1770
+
1771
+ // src/blocks/richBlocks.ts
1637
1772
  var LatexTool = class {
1638
1773
  data;
1639
1774
  wrapper = null;
@@ -3565,34 +3700,55 @@ var FlashcardTool = class {
3565
3700
  };
3566
3701
  }
3567
3702
  };
3568
- var SettingsTriggerTool = class {
3569
- api;
3570
- static get toolbox() {
3571
- return {
3572
- title: "Settings",
3573
- icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>'
3574
- };
3575
- }
3576
- constructor({ api }) {
3577
- this.api = api;
3578
- }
3579
- render() {
3580
- const el = document.createElement("div");
3581
- el.style.display = "none";
3582
- queueMicrotask(() => {
3583
- el.dispatchEvent(new CustomEvent("nextgen-open-settings", { bubbles: true }));
3584
- try {
3585
- const idx = this.api.blocks.getCurrentBlockIndex();
3586
- if (idx >= 0) this.api.blocks.delete(idx);
3587
- } catch {
3588
- }
3589
- });
3590
- return el;
3591
- }
3592
- save() {
3593
- return {};
3594
- }
3595
- };
3703
+ function createActionTriggerTool(title, icon, eventName) {
3704
+ return class {
3705
+ api;
3706
+ el = null;
3707
+ fired = false;
3708
+ static get toolbox() {
3709
+ return { title, icon };
3710
+ }
3711
+ constructor({ api }) {
3712
+ this.api = api;
3713
+ }
3714
+ render() {
3715
+ const el = document.createElement("div");
3716
+ el.style.display = "none";
3717
+ this.el = el;
3718
+ return el;
3719
+ }
3720
+ rendered() {
3721
+ if (this.fired || !this.el) return;
3722
+ this.fired = true;
3723
+ this.el.dispatchEvent(new CustomEvent(eventName, { bubbles: true }));
3724
+ window.setTimeout(() => {
3725
+ try {
3726
+ const idx = this.api.blocks.getCurrentBlockIndex();
3727
+ if (idx >= 0) this.api.blocks.delete(idx);
3728
+ } catch {
3729
+ }
3730
+ }, 0);
3731
+ }
3732
+ save() {
3733
+ return {};
3734
+ }
3735
+ };
3736
+ }
3737
+ var SettingsTriggerTool = createActionTriggerTool(
3738
+ "Settings",
3739
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 1 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 1 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 1 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 1 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>',
3740
+ "nextgen-open-settings"
3741
+ );
3742
+ var ContinueWritingTool = createActionTriggerTool(
3743
+ "Continue Writing",
3744
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l1.9 5.8L20 11l-6.1 2.2L12 19l-1.9-5.8L4 11l6.1-2.2z"/></svg>',
3745
+ "nextgen-ai-continue"
3746
+ );
3747
+ var AskAiTool = createActionTriggerTool(
3748
+ "Ask AI",
3749
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>',
3750
+ "nextgen-ai-ask"
3751
+ );
3596
3752
  var UploadTool = class {
3597
3753
  data;
3598
3754
  statusEl = null;
@@ -3934,94 +4090,66 @@ var EMOJI_PRESETS = [
3934
4090
  ];
3935
4091
  var EmojiTool = class {
3936
4092
  data;
4093
+ api;
4094
+ isNewInsert;
4095
+ anchorEl = null;
3937
4096
  static get toolbox() {
3938
4097
  return {
3939
4098
  title: "Emoji",
3940
4099
  icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M8 14s1.5 2 4 2 4-2 4-2"/><line x1="9" y1="9" x2="9.01" y2="9"/><line x1="15" y1="9" x2="15.01" y2="9"/></svg>'
3941
4100
  };
3942
4101
  }
3943
- constructor({ data }) {
4102
+ constructor({
4103
+ data,
4104
+ api
4105
+ }) {
4106
+ this.isNewInsert = !data?.emoji;
4107
+ this.api = api;
3944
4108
  this.data = {
3945
4109
  emoji: data?.emoji ?? "\u2728",
3946
4110
  label: data?.label ?? "",
3947
4111
  size: data?.size || "md"
3948
4112
  };
3949
4113
  }
4114
+ openPickerAtAnchor() {
4115
+ if (!this.anchorEl) return;
4116
+ const rect = this.anchorEl.getBoundingClientRect();
4117
+ openEmojiSideMenu({
4118
+ anchorRect: rect,
4119
+ onSelect: (em) => {
4120
+ if (this.isNewInsert && this.api?.blocks) {
4121
+ const idx = this.api.blocks.getCurrentBlockIndex();
4122
+ this.api.blocks.delete(idx);
4123
+ this.api.blocks.insert("paragraph", { text: `${em} ` }, {}, idx, true);
4124
+ queueMicrotask(() => {
4125
+ this.api?.caret?.setToBlock(idx, "end");
4126
+ });
4127
+ return;
4128
+ }
4129
+ this.data.emoji = em;
4130
+ if (this.anchorEl) {
4131
+ this.anchorEl.textContent = `${em} Pick emoji`;
4132
+ }
4133
+ }
4134
+ });
4135
+ }
3950
4136
  render() {
3951
4137
  const wrap = document.createElement("div");
3952
- wrap.className = "editor-emoji-split";
3953
- const leftPane = document.createElement("div");
3954
- leftPane.className = "editor-emoji-left";
3955
- const previewGlyph = document.createElement("div");
3956
- previewGlyph.className = `editor-emoji-hero is-${this.data.size}`;
3957
- previewGlyph.textContent = this.data.emoji;
3958
- const emojiIn = document.createElement("input");
3959
- emojiIn.type = "text";
3960
- emojiIn.className = "cdx-input editor-callout-icon-in";
3961
- emojiIn.value = this.data.emoji;
3962
- emojiIn.placeholder = "\u2728";
3963
- emojiIn.addEventListener("input", () => {
3964
- this.data.emoji = emojiIn.value || "\u2728";
3965
- previewGlyph.textContent = this.data.emoji;
3966
- });
3967
- const sizeSel = document.createElement("select");
3968
- sizeSel.className = "cdx-input editor-form-select";
3969
- ["sm", "md", "lg"].forEach((s) => {
3970
- const o = document.createElement("option");
3971
- o.value = s;
3972
- o.textContent = s.toUpperCase();
3973
- if (this.data.size === s) o.selected = true;
3974
- sizeSel.appendChild(o);
3975
- });
3976
- sizeSel.addEventListener("change", () => {
3977
- this.data.size = sizeSel.value;
3978
- previewGlyph.className = `editor-emoji-hero is-${this.data.size}`;
3979
- });
3980
- const row = document.createElement("div");
3981
- row.className = "editor-emoji-controls";
3982
- row.append(emojiIn, sizeSel);
3983
- const labelIn = document.createElement("input");
3984
- labelIn.type = "text";
3985
- labelIn.className = "cdx-input editor-form-input";
3986
- labelIn.placeholder = "Caption or reaction note...";
3987
- labelIn.value = this.data.label || "";
3988
- labelIn.addEventListener("input", () => {
3989
- this.data.label = labelIn.value;
3990
- });
3991
- leftPane.append(previewGlyph, row, labelIn);
3992
- const rightPane = document.createElement("div");
3993
- rightPane.className = "editor-emoji-picker-pane";
3994
- const searchIn = document.createElement("input");
3995
- searchIn.type = "search";
3996
- searchIn.className = "cdx-input editor-form-input";
3997
- searchIn.placeholder = "Search emojis (fire, rocket, heart...)";
3998
- const grid = document.createElement("div");
3999
- grid.className = "editor-emoji-grid";
4000
- const renderGrid = (query = "") => {
4001
- grid.innerHTML = "";
4002
- const q = query.trim().toLowerCase();
4003
- const filtered = q ? EMOJI_PRESETS.filter((p) => p.name.includes(q) || p.em.includes(q)) : EMOJI_PRESETS;
4004
- filtered.forEach(({ em, name }) => {
4005
- const btn = document.createElement("button");
4006
- btn.type = "button";
4007
- btn.title = name;
4008
- btn.className = `editor-emoji-btn${em === this.data.emoji ? " is-active" : ""}`;
4009
- btn.textContent = em;
4010
- btn.addEventListener("click", () => {
4011
- this.data.emoji = em;
4012
- emojiIn.value = em;
4013
- previewGlyph.textContent = em;
4014
- renderGrid(searchIn.value);
4015
- });
4016
- grid.appendChild(btn);
4017
- });
4018
- };
4019
- searchIn.addEventListener("input", () => renderGrid(searchIn.value));
4020
- renderGrid();
4021
- rightPane.append(searchIn, grid);
4022
- wrap.append(leftPane, rightPane);
4138
+ wrap.className = "editor-emoji-inline-wrap";
4139
+ const btn = document.createElement("button");
4140
+ btn.type = "button";
4141
+ btn.className = "b2 editor-emoji-inline-anchor";
4142
+ btn.textContent = `${this.data.emoji} Pick emoji`;
4143
+ btn.addEventListener("click", () => this.openPickerAtAnchor());
4144
+ this.anchorEl = btn;
4145
+ wrap.appendChild(btn);
4023
4146
  return wrap;
4024
4147
  }
4148
+ rendered() {
4149
+ if (this.isNewInsert) {
4150
+ queueMicrotask(() => this.openPickerAtAnchor());
4151
+ }
4152
+ }
4025
4153
  save() {
4026
4154
  return {
4027
4155
  emoji: this.data.emoji.trim() || "\u2728",
@@ -5953,6 +6081,8 @@ function getEditorTools(includeLayout = true, enabledTools) {
5953
6081
  nestedlist: import_nested_list.default,
5954
6082
  simpleImage: import_simple_image.default,
5955
6083
  comment: CommentTool,
6084
+ continueWriting: ContinueWritingTool,
6085
+ askAi: AskAiTool,
5956
6086
  settings: SettingsTriggerTool,
5957
6087
  // Inline toolbar tools
5958
6088
  inlineCode: import_inline_code.default,
@@ -6206,6 +6336,10 @@ var TOOL_CATEGORIES = [
6206
6336
  "slides"
6207
6337
  ]
6208
6338
  },
6339
+ {
6340
+ label: "AI",
6341
+ tools: ["continueWriting", "askAi"]
6342
+ },
6209
6343
  {
6210
6344
  label: "Settings",
6211
6345
  tools: ["settings"]
@@ -6221,8 +6355,80 @@ var SIMPLE_MODE_TOOLS = [
6221
6355
  "code",
6222
6356
  "image",
6223
6357
  "delimiter",
6358
+ "continueWriting",
6359
+ "askAi",
6224
6360
  "settings"
6225
6361
  ];
6362
+ var ALL_TOOL_NAMES = Array.from(
6363
+ new Set(TOOL_CATEGORIES.flatMap((g) => g.tools))
6364
+ );
6365
+ var TOOL_LABELS = {
6366
+ h1: "Heading 1",
6367
+ h2: "Heading 2",
6368
+ h3: "Heading 3",
6369
+ paragraph: "Paragraph",
6370
+ list: "List",
6371
+ nestedlist: "Nested List",
6372
+ checklist: "Checklist",
6373
+ quote: "Quote",
6374
+ pullquote: "Pull Quote",
6375
+ delimiter: "Delimiter",
6376
+ callout: "Callout",
6377
+ hotkey: "Hotkey",
6378
+ emoji: "Emoji",
6379
+ scratch: "Scratchpad",
6380
+ alert: "Alert",
6381
+ badges: "Badges",
6382
+ tags: "Tags",
6383
+ cover: "Page Cover",
6384
+ toc: "Table of Contents",
6385
+ bento: "Bento Grid",
6386
+ layout: "Multi-Column Layout",
6387
+ tabs: "Tabs",
6388
+ accordion: "Accordion",
6389
+ toggleh1: "Toggle H1",
6390
+ toggleh2: "Toggle H2",
6391
+ toggleh3: "Toggle H3",
6392
+ collapsible: "Collapsible",
6393
+ spoiler: "Spoiler",
6394
+ cards: "Cards",
6395
+ timeline: "Timeline",
6396
+ proscons: "Pros & Cons",
6397
+ upload: "Upload",
6398
+ image: "Image",
6399
+ simpleImage: "Simple Image",
6400
+ gif: "GIF",
6401
+ gallery: "Lightbox Gallery",
6402
+ masonry: "Masonry Grid",
6403
+ carousel: "Carousel",
6404
+ compare: "Before / After",
6405
+ audio: "Audio Player",
6406
+ musicCarousel: "Music Carousel",
6407
+ embed: "Embed",
6408
+ attaches: "Attachment",
6409
+ excalidraw: "Excalidraw",
6410
+ code: "Code Block",
6411
+ latex: "LaTeX Math",
6412
+ chart: "Data Chart",
6413
+ table: "Table",
6414
+ stats: "Stats",
6415
+ form: "Form Builder",
6416
+ poll: "Poll",
6417
+ quiz: "Quiz",
6418
+ flashcards: "Flashcards",
6419
+ todo: "To-Do List",
6420
+ eisenhower: "Eisenhower Matrix",
6421
+ kanban: "Kanban Board",
6422
+ timer: "Focus Timer",
6423
+ faq: "FAQ",
6424
+ footnotes: "Footnotes",
6425
+ button: "Button",
6426
+ dialogue: "Dialogue Box",
6427
+ slides: "Slides",
6428
+ continueWriting: "Continue Writing",
6429
+ askAi: "Ask AI",
6430
+ settings: "Settings"
6431
+ };
6226
6432
  function attachPopoverCategoryHeaders(container) {
6227
6433
  const applyCategories = () => {
6228
6434
  const popovers = container.querySelectorAll(".ce-popover__items");
@@ -6288,23 +6494,312 @@ function attachPopoverCategoryHeaders(container) {
6288
6494
  return () => observer.disconnect();
6289
6495
  }
6290
6496
 
6291
- // src/components/SettingsModal.tsx
6497
+ // src/components/ClassicToolbar.tsx
6292
6498
  var import_react2 = require("react");
6293
6499
  var import_jsx_runtime = require("react/jsx-runtime");
6500
+ var INSERT_ITEMS = [
6501
+ { tool: "bento", label: "Bento Grid", category: "Layout" },
6502
+ { tool: "masonry", label: "Masonry Grid", category: "Media" },
6503
+ { tool: "excalidraw", label: "Excalidraw", category: "Media" },
6504
+ { tool: "chart", label: "Data Chart", category: "Data" },
6505
+ { tool: "callout", label: "Callout", category: "Text" },
6506
+ { tool: "spoiler", label: "Spoiler", category: "Layout" },
6507
+ { tool: "dialogue", label: "Dialogue Box", category: "Interactive" },
6508
+ { tool: "scratch", label: "Scratchpad", category: "Text" },
6509
+ { tool: "hotkey", label: "Hotkey", category: "Text" },
6510
+ { tool: "image", label: "Image", category: "Media" },
6511
+ { tool: "upload", label: "File Upload", category: "Media" },
6512
+ { tool: "table", label: "Table", category: "Data" },
6513
+ { tool: "latex", label: "LaTeX Math", category: "Data" },
6514
+ { tool: "tabs", label: "Tabs", category: "Layout" },
6515
+ { tool: "accordion", label: "Accordion", category: "Layout" },
6516
+ { tool: "quiz", label: "Quiz", category: "Interactive" },
6517
+ { tool: "poll", label: "Poll", category: "Interactive" },
6518
+ { tool: "kanban", label: "Kanban Board", category: "Interactive" },
6519
+ { tool: "delimiter", label: "Delimiter", category: "Text" },
6520
+ { tool: "settings", label: "Settings", category: "System" }
6521
+ ];
6522
+ var ClassicToolbar = ({
6523
+ editorRef,
6524
+ onUndo,
6525
+ onRedo,
6526
+ fontFamily,
6527
+ onChangeFontFamily,
6528
+ enabledTools,
6529
+ onOpenSettings
6530
+ }) => {
6531
+ const allowedTools = enabledTools ? new Set(enabledTools) : null;
6532
+ const visibleInsertItems = allowedTools ? INSERT_ITEMS.filter((item) => item.tool === "settings" || allowedTools.has(item.tool)) : INSERT_ITEMS;
6533
+ const [insertOpen, setInsertOpen] = (0, import_react2.useState)(false);
6534
+ const [alignOpen, setAlignOpen] = (0, import_react2.useState)(false);
6535
+ const [blockType, setBlockType] = (0, import_react2.useState)("paragraph");
6536
+ const wrapRef = (0, import_react2.useRef)(null);
6537
+ (0, import_react2.useEffect)(() => {
6538
+ const onOutside = (e) => {
6539
+ if (wrapRef.current && !wrapRef.current.contains(e.target)) {
6540
+ setInsertOpen(false);
6541
+ setAlignOpen(false);
6542
+ }
6543
+ };
6544
+ document.addEventListener("mousedown", onOutside);
6545
+ return () => document.removeEventListener("mousedown", onOutside);
6546
+ }, []);
6547
+ const keepSelection = (e) => {
6548
+ e.preventDefault();
6549
+ };
6550
+ const exec = (cmd, value) => {
6551
+ document.execCommand(cmd, false, value);
6552
+ };
6553
+ const toggleInlineTag = (tagName) => {
6554
+ const sel = window.getSelection();
6555
+ if (!sel || sel.rangeCount === 0) return;
6556
+ const range = sel.getRangeAt(0);
6557
+ if (range.collapsed) return;
6558
+ const existing = (range.commonAncestorContainer.nodeType === Node.ELEMENT_NODE ? range.commonAncestorContainer : range.commonAncestorContainer.parentElement)?.closest(tagName);
6559
+ if (existing && existing.parentNode) {
6560
+ const parent = existing.parentNode;
6561
+ while (existing.firstChild) {
6562
+ parent.insertBefore(existing.firstChild, existing);
6563
+ }
6564
+ parent.removeChild(existing);
6565
+ return;
6566
+ }
6567
+ const el = document.createElement(tagName);
6568
+ el.appendChild(range.extractContents());
6569
+ range.insertNode(el);
6570
+ };
6571
+ const insertBlock = (tool, data = {}) => {
6572
+ const ed = editorRef.current;
6573
+ if (!ed) return;
6574
+ if (tool === "settings") {
6575
+ onOpenSettings();
6576
+ setInsertOpen(false);
6577
+ return;
6578
+ }
6579
+ try {
6580
+ const idx = ed.blocks.getCurrentBlockIndex();
6581
+ const targetIdx = idx >= 0 ? idx + 1 : ed.blocks.getBlocksCount();
6582
+ ed.blocks.insert(tool, data, {}, targetIdx, true);
6583
+ } catch {
6584
+ ed.blocks.insert(tool, data);
6585
+ }
6586
+ setInsertOpen(false);
6587
+ };
6588
+ const handleBlockTypeChange = (next) => {
6589
+ setBlockType(next);
6590
+ if (next === "paragraph") insertBlock("paragraph", { text: "" });
6591
+ else if (next === "h1") insertBlock("h1", { text: "", level: 1 });
6592
+ else if (next === "h2") insertBlock("h2", { text: "", level: 2 });
6593
+ else if (next === "h3") insertBlock("h3", { text: "", level: 3 });
6594
+ else if (next === "quote") insertBlock("quote", { text: "", caption: "" });
6595
+ else if (next === "code") insertBlock("code", { code: "" });
6596
+ };
6597
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ref: wrapRef, className: "ng-classic-toolbar", role: "toolbar", "aria-label": "Formatting toolbar", children: [
6598
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: onUndo, title: "Undo", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
6599
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 7v6h6" }),
6600
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13" })
6601
+ ] }) }),
6602
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: onRedo, title: "Redo", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
6603
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21 7v6h-6" }),
6604
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7" })
6605
+ ] }) }),
6606
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-sep" }),
6607
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6608
+ "select",
6609
+ {
6610
+ className: "ng-ct-select",
6611
+ value: blockType,
6612
+ onChange: (e) => handleBlockTypeChange(e.target.value),
6613
+ "aria-label": "Block type",
6614
+ children: [
6615
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "paragraph", children: "Paragraph" }),
6616
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "h1", children: "Heading 1" }),
6617
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "h2", children: "Heading 2" }),
6618
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "h3", children: "Heading 3" }),
6619
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "quote", children: "Quote" }),
6620
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "code", children: "Code" })
6621
+ ]
6622
+ }
6623
+ ),
6624
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6625
+ "select",
6626
+ {
6627
+ className: "ng-ct-select",
6628
+ value: fontFamily,
6629
+ onChange: (e) => onChangeFontFamily(e.target.value),
6630
+ "aria-label": "Font family",
6631
+ children: [
6632
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "sans", children: "Sans" }),
6633
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "serif", children: "Serif" }),
6634
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "mono", children: "Mono" })
6635
+ ]
6636
+ }
6637
+ ),
6638
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-sep" }),
6639
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-b", onMouseDown: keepSelection, onClick: () => exec("bold"), title: "Bold", children: "B" }),
6640
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-i", onMouseDown: keepSelection, onClick: () => exec("italic"), title: "Italic", children: "I" }),
6641
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-u", onMouseDown: keepSelection, onClick: () => exec("underline"), title: "Underline", children: "U" }),
6642
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-s", onMouseDown: keepSelection, onClick: () => exec("strikeThrough"), title: "Strikethrough", children: "S" }),
6643
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => toggleInlineTag("code"), title: "Inline Code", children: "<>" }),
6644
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn ng-ct-highlight", onMouseDown: keepSelection, onClick: () => toggleInlineTag("mark"), title: "Highlight", children: "A" }),
6645
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6646
+ "button",
6647
+ {
6648
+ type: "button",
6649
+ className: "ng-ct-btn",
6650
+ onMouseDown: keepSelection,
6651
+ onClick: () => {
6652
+ const url = window.prompt("Enter link URL (https://...)");
6653
+ if (url) exec("createLink", url.trim());
6654
+ },
6655
+ title: "Insert Link",
6656
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
6657
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71" }),
6658
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71" })
6659
+ ] })
6660
+ }
6661
+ ),
6662
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => exec("superscript"), title: "Superscript", children: "x\xB2" }),
6663
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => exec("subscript"), title: "Subscript", children: "x\u2082" }),
6664
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => exec("removeFormat"), title: "Clear Formatting", children: "T\u2093" }),
6665
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-sep" }),
6666
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("list", { style: "unordered", items: [] }), title: "Bullet List", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6667
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "8", y1: "6", x2: "21", y2: "6" }),
6668
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "8", y1: "12", x2: "21", y2: "12" }),
6669
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "8", y1: "18", x2: "21", y2: "18" }),
6670
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "4", cy: "6", r: "1" }),
6671
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "4", cy: "12", r: "1" }),
6672
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "4", cy: "18", r: "1" })
6673
+ ] }) }),
6674
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("list", { style: "ordered", items: [] }), title: "Numbered List", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6675
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "10", y1: "6", x2: "21", y2: "6" }),
6676
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "10", y1: "12", x2: "21", y2: "12" }),
6677
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "10", y1: "18", x2: "21", y2: "18" }),
6678
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 6h1v4" }),
6679
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 10h2" }),
6680
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" })
6681
+ ] }) }),
6682
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("checklist", { items: [] }), title: "Checklist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6683
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "5", width: "6", height: "6", rx: "1" }),
6684
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3 17 2 2 4-4" }),
6685
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 6h8" }),
6686
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 12h8" }),
6687
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 18h8" })
6688
+ ] }) }),
6689
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => exec("outdent"), title: "Decrease Indent", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6690
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "7 8 3 12 7 16" }),
6691
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "12", x2: "11", y2: "12" }),
6692
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "6", x2: "11", y2: "6" }),
6693
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "18", x2: "11", y2: "18" })
6694
+ ] }) }),
6695
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => exec("indent"), title: "Increase Indent", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6696
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("polyline", { points: "3 8 7 12 3 16" }),
6697
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "12", x2: "11", y2: "12" }),
6698
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "6", x2: "11", y2: "6" }),
6699
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "21", y1: "18", x2: "11", y2: "18" })
6700
+ ] }) }),
6701
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-ct-dropdown-wrap", children: [
6702
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6703
+ "button",
6704
+ {
6705
+ type: "button",
6706
+ className: "ng-ct-btn",
6707
+ onMouseDown: keepSelection,
6708
+ onClick: () => {
6709
+ setAlignOpen((v) => !v);
6710
+ setInsertOpen(false);
6711
+ },
6712
+ title: "Alignment",
6713
+ children: [
6714
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6715
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "3", y1: "6", x2: "21", y2: "6" }),
6716
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "3", y1: "12", x2: "15", y2: "12" }),
6717
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "3", y1: "18", x2: "18", y2: "18" })
6718
+ ] }),
6719
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-caret", children: "\u25BE" })
6720
+ ]
6721
+ }
6722
+ ),
6723
+ alignOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-ct-menu", children: [
6724
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onMouseDown: keepSelection, onClick: () => {
6725
+ exec("justifyLeft");
6726
+ setAlignOpen(false);
6727
+ }, children: "Align Left" }),
6728
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onMouseDown: keepSelection, onClick: () => {
6729
+ exec("justifyCenter");
6730
+ setAlignOpen(false);
6731
+ }, children: "Align Center" }),
6732
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onMouseDown: keepSelection, onClick: () => {
6733
+ exec("justifyRight");
6734
+ setAlignOpen(false);
6735
+ }, children: "Align Right" }),
6736
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onMouseDown: keepSelection, onClick: () => {
6737
+ exec("justifyFull");
6738
+ setAlignOpen(false);
6739
+ }, children: "Justify" })
6740
+ ] })
6741
+ ] }),
6742
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-sep" }),
6743
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-ct-dropdown-wrap", children: [
6744
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6745
+ "button",
6746
+ {
6747
+ type: "button",
6748
+ className: "ng-ct-insert-btn",
6749
+ onClick: () => {
6750
+ setInsertOpen((v) => !v);
6751
+ setAlignOpen(false);
6752
+ },
6753
+ children: [
6754
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "+ Insert" }),
6755
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-caret", children: "\u25BE" })
6756
+ ]
6757
+ }
6758
+ ),
6759
+ insertOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ng-ct-menu ng-ct-insert-menu", children: visibleInsertItems.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6760
+ "button",
6761
+ {
6762
+ type: "button",
6763
+ onClick: () => insertBlock(item.tool),
6764
+ children: [
6765
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: item.label }),
6766
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "ng-ct-cat", children: item.category })
6767
+ ]
6768
+ },
6769
+ item.tool
6770
+ )) })
6771
+ ] })
6772
+ ] });
6773
+ };
6774
+
6775
+ // src/components/SettingsModal.tsx
6776
+ var import_react3 = require("react");
6777
+ var import_jsx_runtime2 = require("react/jsx-runtime");
6294
6778
  var SettingsModal = ({
6295
6779
  open,
6296
6780
  theme,
6297
6781
  mode,
6298
6782
  showStats,
6299
6783
  aiConfig,
6784
+ selectedTools,
6300
6785
  onChangeTheme,
6301
6786
  onChangeMode,
6302
6787
  onChangeShowStats,
6303
6788
  onChangeAiConfig,
6789
+ onChangeSelectedTools,
6304
6790
  onClose
6305
6791
  }) => {
6306
- const [showKey, setShowKey] = (0, import_react2.useState)(false);
6792
+ const [showKey, setShowKey] = (0, import_react3.useState)(false);
6793
+ const [toolFilter, setToolFilter] = (0, import_react3.useState)("");
6307
6794
  if (!open) return null;
6795
+ const selectedSet = new Set(selectedTools);
6796
+ const toggleTool = (tool) => {
6797
+ const next = new Set(selectedTools);
6798
+ if (next.has(tool)) next.delete(tool);
6799
+ else next.add(tool);
6800
+ next.add("settings");
6801
+ onChangeSelectedTools(Array.from(next));
6802
+ };
6308
6803
  const handleProviderChange = (providerId) => {
6309
6804
  const preset = AI_PROVIDER_PRESETS.find((p) => p.id === providerId);
6310
6805
  onChangeAiConfig({
@@ -6314,39 +6809,39 @@ var SettingsModal = ({
6314
6809
  endpoint: preset?.defaultEndpoint || ""
6315
6810
  });
6316
6811
  };
6317
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Editor Settings", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-modal", children: [
6318
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-modal-head", children: [
6319
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
6320
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Editor Settings" }),
6321
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Configure appearance, editor mode, and AI provider." })
6812
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Editor Settings", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal", children: [
6813
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-head", children: [
6814
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
6815
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: "Editor Settings" }),
6816
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Configure appearance, editor mode, and AI provider." })
6322
6817
  ] }),
6323
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
6818
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
6324
6819
  ] }),
6325
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-modal-body", children: [
6326
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field", children: [
6327
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "Theme" }),
6328
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
6820
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-body", children: [
6821
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6822
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Theme" }),
6823
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6329
6824
  "select",
6330
6825
  {
6331
6826
  className: "cdx-input editor-form-select",
6332
6827
  value: theme,
6333
6828
  onChange: (e) => onChangeTheme(e.target.value),
6334
6829
  children: [
6335
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "inherit", children: "Inherit from Host App" }),
6336
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "light", children: "shadcn Light" }),
6337
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "dark", children: "shadcn Dark" }),
6338
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
6339
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
6340
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
6341
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
6830
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "inherit", children: "Inherit from Host App" }),
6831
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "light", children: "shadcn Light" }),
6832
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "dark", children: "shadcn Dark" }),
6833
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
6834
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
6835
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
6836
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
6342
6837
  ]
6343
6838
  }
6344
6839
  )
6345
6840
  ] }),
6346
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field", children: [
6347
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "Editor Mode" }),
6348
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-segmented", children: [
6349
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6841
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6842
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Editor Mode" }),
6843
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-segmented", children: [
6844
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6350
6845
  "button",
6351
6846
  {
6352
6847
  type: "button",
@@ -6355,7 +6850,7 @@ var SettingsModal = ({
6355
6850
  children: "Block Editor (Full)"
6356
6851
  }
6357
6852
  ),
6358
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6853
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6359
6854
  "button",
6360
6855
  {
6361
6856
  type: "button",
@@ -6366,9 +6861,9 @@ var SettingsModal = ({
6366
6861
  )
6367
6862
  ] })
6368
6863
  ] }),
6369
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field ng-field-inline", children: [
6370
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
6371
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6864
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field ng-field-inline", children: [
6865
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
6866
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6372
6867
  "input",
6373
6868
  {
6374
6869
  id: "ng-stats-toggle",
@@ -6378,22 +6873,22 @@ var SettingsModal = ({
6378
6873
  }
6379
6874
  )
6380
6875
  ] }),
6381
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("hr", { className: "ng-divider" }),
6382
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field", children: [
6383
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "AI Provider" }),
6384
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6876
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "ng-divider" }),
6877
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6878
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "AI Provider" }),
6879
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6385
6880
  "select",
6386
6881
  {
6387
6882
  className: "cdx-input editor-form-select",
6388
6883
  value: aiConfig.provider,
6389
6884
  onChange: (e) => handleProviderChange(e.target.value),
6390
- children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: p.id, children: p.label }, p.id))
6885
+ children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: p.id, children: p.label }, p.id))
6391
6886
  }
6392
6887
  )
6393
6888
  ] }),
6394
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field", children: [
6395
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "Model" }),
6396
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6889
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6890
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Model" }),
6891
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6397
6892
  "input",
6398
6893
  {
6399
6894
  type: "text",
@@ -6404,10 +6899,10 @@ var SettingsModal = ({
6404
6899
  }
6405
6900
  )
6406
6901
  ] }),
6407
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field", children: [
6408
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "API Key" }),
6409
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-key-row", children: [
6410
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6902
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6903
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "API Key" }),
6904
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-key-row", children: [
6905
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6411
6906
  "input",
6412
6907
  {
6413
6908
  type: showKey ? "text" : "password",
@@ -6417,7 +6912,7 @@ var SettingsModal = ({
6417
6912
  onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
6418
6913
  }
6419
6914
  ),
6420
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6915
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6421
6916
  "button",
6422
6917
  {
6423
6918
  type: "button",
@@ -6428,9 +6923,9 @@ var SettingsModal = ({
6428
6923
  )
6429
6924
  ] })
6430
6925
  ] }),
6431
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "ng-field", children: [
6432
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { children: "Endpoint URL (optional)" }),
6433
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
6926
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6927
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Endpoint URL (optional)" }),
6928
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6434
6929
  "input",
6435
6930
  {
6436
6931
  type: "url",
@@ -6440,43 +6935,132 @@ var SettingsModal = ({
6440
6935
  onChange: (e) => onChangeAiConfig({ ...aiConfig, endpoint: e.target.value })
6441
6936
  }
6442
6937
  )
6938
+ ] }),
6939
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "ng-divider" }),
6940
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-manager", children: [
6941
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-header", children: [
6942
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
6943
+ "Registered Components (",
6944
+ selectedSet.size,
6945
+ "/",
6946
+ ALL_TOOL_NAMES.length,
6947
+ ")"
6948
+ ] }) }),
6949
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-actions", children: [
6950
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6951
+ "button",
6952
+ {
6953
+ type: "button",
6954
+ className: "excalidraw-btn",
6955
+ onClick: () => onChangeSelectedTools([...ALL_TOOL_NAMES]),
6956
+ children: "All"
6957
+ }
6958
+ ),
6959
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6960
+ "button",
6961
+ {
6962
+ type: "button",
6963
+ className: "excalidraw-btn",
6964
+ onClick: () => onChangeSelectedTools([...SIMPLE_MODE_TOOLS]),
6965
+ children: "Minimal"
6966
+ }
6967
+ )
6968
+ ] })
6969
+ ] }),
6970
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6971
+ "input",
6972
+ {
6973
+ type: "search",
6974
+ className: "cdx-input editor-form-input",
6975
+ placeholder: "Filter components (e.g. bento, chart, spoiler...)",
6976
+ value: toolFilter,
6977
+ onChange: (e) => setToolFilter(e.target.value)
6978
+ }
6979
+ ),
6980
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
6981
+ const q = toolFilter.trim().toLowerCase();
6982
+ const visible = group.tools.filter((t) => {
6983
+ const label = (TOOL_LABELS[t] || t).toLowerCase();
6984
+ return !q || label.includes(q) || t.toLowerCase().includes(q);
6985
+ });
6986
+ if (!visible.length) return null;
6987
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-group", children: [
6988
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-group-title", children: group.label }),
6989
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-grid", children: visible.map((tool) => {
6990
+ const checked = selectedSet.has(tool);
6991
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6992
+ "label",
6993
+ {
6994
+ className: `ng-tool-chip${checked ? " is-checked" : ""}`,
6995
+ children: [
6996
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6997
+ "input",
6998
+ {
6999
+ type: "checkbox",
7000
+ checked,
7001
+ onChange: () => toggleTool(tool)
7002
+ }
7003
+ ),
7004
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: TOOL_LABELS[tool] || tool })
7005
+ ]
7006
+ },
7007
+ tool
7008
+ );
7009
+ }) })
7010
+ ] }, group.label);
7011
+ }) })
6443
7012
  ] })
6444
7013
  ] })
6445
7014
  ] }) });
6446
7015
  };
6447
7016
 
6448
7017
  // src/components/BlockEditor.tsx
6449
- var import_jsx_runtime2 = require("react/jsx-runtime");
6450
- var BlockEditor = import_react3.default.forwardRef(
7018
+ var import_jsx_runtime3 = require("react/jsx-runtime");
7019
+ var BlockEditor = import_react4.default.forwardRef(
6451
7020
  ({
6452
7021
  initialData,
6453
7022
  placeholder,
6454
7023
  enabledTools,
6455
7024
  showStats = true,
6456
- showAiBar = true,
7025
+ showAiBar = false,
6457
7026
  onAiRequest,
6458
7027
  className,
6459
7028
  onReady,
6460
7029
  onChange
6461
7030
  }, ref) => {
6462
- const shellRef = (0, import_react3.useRef)(null);
6463
- const holderRef = (0, import_react3.useRef)(null);
6464
- const editorRef = (0, import_react3.useRef)(null);
6465
- const undoRef = (0, import_react3.useRef)(null);
6466
- const lifecycleRef = (0, import_react3.useRef)(Promise.resolve());
6467
- const latestDocRef = (0, import_react3.useRef)(initialData || { blocks: [] });
6468
- const onChangeRef = (0, import_react3.useRef)(onChange);
6469
- const onReadyRef = (0, import_react3.useRef)(onReady);
6470
- const [settingsOpen, setSettingsOpen] = (0, import_react3.useState)(false);
6471
- const [theme, setTheme] = (0, import_react3.useState)("inherit");
6472
- const [editorMode, setEditorMode] = (0, import_react3.useState)("block");
6473
- const [statsVisible, setStatsVisible] = (0, import_react3.useState)(showStats);
6474
- const [aiConfig, setAiConfig] = (0, import_react3.useState)(loadAiConfig);
6475
- const [askOpen, setAskOpen] = (0, import_react3.useState)(false);
6476
- const [askPrompt, setAskPrompt] = (0, import_react3.useState)("");
6477
- const [aiBusy, setAiBusy] = (0, import_react3.useState)(false);
6478
- const [aiError, setAiError] = (0, import_react3.useState)(null);
6479
- const [stats, setStats] = (0, import_react3.useState)(() => {
7031
+ const shellRef = (0, import_react4.useRef)(null);
7032
+ const holderRef = (0, import_react4.useRef)(null);
7033
+ const editorRef = (0, import_react4.useRef)(null);
7034
+ const undoRef = (0, import_react4.useRef)(null);
7035
+ const lifecycleRef = (0, import_react4.useRef)(Promise.resolve());
7036
+ const latestDocRef = (0, import_react4.useRef)(initialData || { blocks: [] });
7037
+ const onChangeRef = (0, import_react4.useRef)(onChange);
7038
+ const onReadyRef = (0, import_react4.useRef)(onReady);
7039
+ const runAiRef = (0, import_react4.useRef)(async () => {
7040
+ });
7041
+ const [settingsOpen, setSettingsOpen] = (0, import_react4.useState)(false);
7042
+ const [theme, setTheme] = (0, import_react4.useState)("inherit");
7043
+ const [editorMode, setEditorMode] = (0, import_react4.useState)("block");
7044
+ const [simpleFont, setSimpleFont] = (0, import_react4.useState)("sans");
7045
+ const [selectedTools, setSelectedTools] = (0, import_react4.useState)(() => {
7046
+ if (enabledTools && enabledTools.length > 0) return enabledTools;
7047
+ try {
7048
+ const raw = localStorage.getItem("ng-enabled-tools");
7049
+ if (raw) {
7050
+ const parsed = JSON.parse(raw);
7051
+ if (Array.isArray(parsed) && parsed.length > 0) return parsed;
7052
+ }
7053
+ } catch {
7054
+ }
7055
+ return ALL_TOOL_NAMES;
7056
+ });
7057
+ const [statsVisible, setStatsVisible] = (0, import_react4.useState)(showStats);
7058
+ const [aiConfig, setAiConfig] = (0, import_react4.useState)(loadAiConfig);
7059
+ const [askOpen, setAskOpen] = (0, import_react4.useState)(false);
7060
+ const [askPrompt, setAskPrompt] = (0, import_react4.useState)("");
7061
+ const [aiBusy, setAiBusy] = (0, import_react4.useState)(false);
7062
+ const [aiError, setAiError] = (0, import_react4.useState)(null);
7063
+ const [stats, setStats] = (0, import_react4.useState)(() => {
6480
7064
  const blocks = initialData?.blocks || [];
6481
7065
  const text = blocks.map((b) => JSON.stringify(b.data || {})).join(" ");
6482
7066
  const words = text.trim() ? text.trim().split(/\s+/).length : 0;
@@ -6484,39 +7068,57 @@ var BlockEditor = import_react3.default.forwardRef(
6484
7068
  });
6485
7069
  onChangeRef.current = onChange;
6486
7070
  onReadyRef.current = onReady;
6487
- (0, import_react3.useEffect)(() => {
7071
+ (0, import_react4.useEffect)(() => {
6488
7072
  setStatsVisible(showStats);
6489
7073
  }, [showStats]);
6490
- (0, import_react3.useEffect)(() => {
7074
+ (0, import_react4.useEffect)(() => {
6491
7075
  const shell = shellRef.current;
6492
7076
  if (!shell) return;
6493
7077
  const onOpenSettings = () => setSettingsOpen(true);
7078
+ const onAiContinue = () => void runAiRef.current?.("continue");
7079
+ const onAiAsk = () => setAskOpen(true);
6494
7080
  shell.addEventListener("nextgen-open-settings", onOpenSettings);
6495
- return () => shell.removeEventListener("nextgen-open-settings", onOpenSettings);
7081
+ shell.addEventListener("nextgen-ai-continue", onAiContinue);
7082
+ shell.addEventListener("nextgen-ai-ask", onAiAsk);
7083
+ return () => {
7084
+ shell.removeEventListener("nextgen-open-settings", onOpenSettings);
7085
+ shell.removeEventListener("nextgen-ai-continue", onAiContinue);
7086
+ shell.removeEventListener("nextgen-ai-ask", onAiAsk);
7087
+ };
6496
7088
  }, []);
6497
- (0, import_react3.useEffect)(() => {
7089
+ (0, import_react4.useEffect)(() => {
6498
7090
  const holder = holderRef.current;
6499
7091
  if (!holder) return;
6500
7092
  let cancelled = false;
6501
7093
  const detachCategories = attachPopoverCategoryHeaders(holder);
6502
- const effectiveTools = editorMode === "simple" ? enabledTools && enabledTools.length > 0 ? enabledTools.filter((t) => SIMPLE_MODE_TOOLS.includes(t)) : SIMPLE_MODE_TOOLS : enabledTools;
7094
+ const detachEmoji = attachEmojiSidePicker(holder);
7095
+ const effectiveTools = Array.from(/* @__PURE__ */ new Set([...selectedTools, "settings"]));
6503
7096
  const mount = async () => {
6504
7097
  await lifecycleRef.current;
6505
7098
  if (cancelled) return;
7099
+ const sanitizedInitial = {
7100
+ ...latestDocRef.current || { blocks: [] },
7101
+ blocks: (latestDocRef.current?.blocks || []).filter(
7102
+ (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
7103
+ )
7104
+ };
7105
+ latestDocRef.current = sanitizedInitial;
6506
7106
  holder.innerHTML = "";
6507
7107
  const instance = new import_editorjs2.default({
6508
7108
  holder,
6509
- data: latestDocRef.current || { blocks: [] },
7109
+ data: sanitizedInitial,
6510
7110
  placeholder: placeholder || "Write your story, or press / to insert blocks...",
6511
7111
  tools: getEditorTools(true, effectiveTools),
6512
7112
  onChange: async () => {
6513
7113
  try {
6514
7114
  const saved = await instance.save();
6515
- const typed = saved;
7115
+ const filteredBlocks = (saved.blocks || []).filter(
7116
+ (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
7117
+ );
7118
+ const typed = { ...saved, blocks: filteredBlocks };
6516
7119
  latestDocRef.current = typed;
6517
- const blocks = saved.blocks || [];
6518
7120
  const words = (holder.innerText || "").trim().split(/\s+/).filter(Boolean).length;
6519
- setStats({ words, blocks: blocks.length });
7121
+ setStats({ words, blocks: filteredBlocks.length });
6520
7122
  onChangeRef.current?.(typed);
6521
7123
  } catch {
6522
7124
  }
@@ -6545,6 +7147,7 @@ var BlockEditor = import_react3.default.forwardRef(
6545
7147
  return () => {
6546
7148
  cancelled = true;
6547
7149
  detachCategories();
7150
+ detachEmoji();
6548
7151
  const toDestroy = editorRef.current;
6549
7152
  editorRef.current = null;
6550
7153
  undoRef.current = null;
@@ -6555,13 +7158,16 @@ var BlockEditor = import_react3.default.forwardRef(
6555
7158
  });
6556
7159
  }
6557
7160
  };
6558
- }, [editorMode]);
6559
- (0, import_react3.useImperativeHandle)(ref, () => ({
7161
+ }, [editorMode, selectedTools]);
7162
+ (0, import_react4.useImperativeHandle)(ref, () => ({
6560
7163
  save: async () => {
6561
7164
  if (!editorRef.current) return null;
6562
7165
  await editorRef.current.isReady;
6563
7166
  const saved = await editorRef.current.save();
6564
- const typed = saved;
7167
+ const filteredBlocks = (saved.blocks || []).filter(
7168
+ (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
7169
+ );
7170
+ const typed = { ...saved, blocks: filteredBlocks };
6565
7171
  latestDocRef.current = typed;
6566
7172
  return typed;
6567
7173
  },
@@ -6614,6 +7220,7 @@ var BlockEditor = import_react3.default.forwardRef(
6614
7220
  setAiBusy(false);
6615
7221
  }
6616
7222
  };
7223
+ runAiRef.current = runAi;
6617
7224
  const handleModeSwitch = async (nextMode) => {
6618
7225
  if (nextMode === editorMode) return;
6619
7226
  if (editorRef.current) {
@@ -6627,16 +7234,17 @@ var BlockEditor = import_react3.default.forwardRef(
6627
7234
  setEditorMode(nextMode);
6628
7235
  };
6629
7236
  const readMins = Math.max(1, Math.ceil(stats.words / 200));
6630
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
7237
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
6631
7238
  "div",
6632
7239
  {
6633
7240
  ref: shellRef,
6634
7241
  "data-ng-theme": theme === "inherit" ? void 0 : theme,
7242
+ "data-ng-font": editorMode === "simple" ? simpleFont : void 0,
6635
7243
  className: className ? `nextgen-editor-shell ${className}` : "nextgen-editor-shell",
6636
7244
  children: [
6637
- showAiBar && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-ai-bar", children: [
6638
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-ai-actions", children: [
6639
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7245
+ showAiBar && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-ai-bar", children: [
7246
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-ai-actions", children: [
7247
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6640
7248
  "button",
6641
7249
  {
6642
7250
  type: "button",
@@ -6646,7 +7254,7 @@ var BlockEditor = import_react3.default.forwardRef(
6646
7254
  children: aiBusy ? "Thinking\u2026" : "\u2726 Continue Writing"
6647
7255
  }
6648
7256
  ),
6649
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7257
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6650
7258
  "button",
6651
7259
  {
6652
7260
  type: "button",
@@ -6657,7 +7265,7 @@ var BlockEditor = import_react3.default.forwardRef(
6657
7265
  }
6658
7266
  )
6659
7267
  ] }),
6660
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7268
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6661
7269
  "button",
6662
7270
  {
6663
7271
  type: "button",
@@ -6668,7 +7276,7 @@ var BlockEditor = import_react3.default.forwardRef(
6668
7276
  }
6669
7277
  )
6670
7278
  ] }),
6671
- askOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
7279
+ askOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
6672
7280
  "form",
6673
7281
  {
6674
7282
  className: "ng-ask-form",
@@ -6677,7 +7285,7 @@ var BlockEditor = import_react3.default.forwardRef(
6677
7285
  if (askPrompt.trim()) void runAi("ask", askPrompt.trim());
6678
7286
  },
6679
7287
  children: [
6680
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7288
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6681
7289
  "input",
6682
7290
  {
6683
7291
  type: "text",
@@ -6687,30 +7295,42 @@ var BlockEditor = import_react3.default.forwardRef(
6687
7295
  onChange: (e) => setAskPrompt(e.target.value)
6688
7296
  }
6689
7297
  ),
6690
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "submit", className: "editor-form-submit", disabled: aiBusy, children: aiBusy ? "Running\u2026" : "Generate" })
7298
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "submit", className: "editor-form-submit", disabled: aiBusy, children: aiBusy ? "Running\u2026" : "Generate" })
6691
7299
  ]
6692
7300
  }
6693
7301
  ),
6694
- aiError && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-ai-error", children: aiError }),
6695
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { id: "editorjs", ref: holderRef }),
6696
- statsVisible && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "nextgen-editor-stats", children: [
6697
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
6698
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "\u2022" }),
6699
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
7302
+ aiError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "ng-ai-error", children: aiError }),
7303
+ editorMode === "simple" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7304
+ ClassicToolbar,
7305
+ {
7306
+ editorRef,
7307
+ onUndo: () => undoRef.current?.undo?.(),
7308
+ onRedo: () => undoRef.current?.redo?.(),
7309
+ fontFamily: simpleFont,
7310
+ onChangeFontFamily: setSimpleFont,
7311
+ enabledTools: selectedTools,
7312
+ onOpenSettings: () => setSettingsOpen(true)
7313
+ }
7314
+ ),
7315
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { id: "editorjs", ref: holderRef }),
7316
+ statsVisible && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "nextgen-editor-stats", children: [
7317
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: editorMode === "simple" ? "Simple Mode" : "Block Editor" }),
7318
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "\u2022" }),
7319
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
6700
7320
  stats.blocks,
6701
7321
  " blocks"
6702
7322
  ] }),
6703
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
7323
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
6704
7324
  stats.words,
6705
7325
  " words"
6706
7326
  ] }),
6707
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
7327
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { children: [
6708
7328
  "~",
6709
7329
  readMins,
6710
7330
  " min read"
6711
7331
  ] })
6712
7332
  ] }),
6713
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7333
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
6714
7334
  SettingsModal,
6715
7335
  {
6716
7336
  open: settingsOpen,
@@ -6718,6 +7338,7 @@ var BlockEditor = import_react3.default.forwardRef(
6718
7338
  mode: editorMode,
6719
7339
  showStats: statsVisible,
6720
7340
  aiConfig,
7341
+ selectedTools,
6721
7342
  onChangeTheme: setTheme,
6722
7343
  onChangeMode: (m) => void handleModeSwitch(m),
6723
7344
  onChangeShowStats: setStatsVisible,
@@ -6726,6 +7347,13 @@ var BlockEditor = import_react3.default.forwardRef(
6726
7347
  saveAiConfig(cfg);
6727
7348
  setAiError(null);
6728
7349
  },
7350
+ onChangeSelectedTools: (tools) => {
7351
+ setSelectedTools(tools);
7352
+ try {
7353
+ localStorage.setItem("ng-enabled-tools", JSON.stringify(tools));
7354
+ } catch {
7355
+ }
7356
+ },
6729
7357
  onClose: () => setSettingsOpen(false)
6730
7358
  }
6731
7359
  )
@@ -6737,13 +7365,13 @@ var BlockEditor = import_react3.default.forwardRef(
6737
7365
  BlockEditor.displayName = "BlockEditor";
6738
7366
 
6739
7367
  // src/components/BlockRenderer.tsx
6740
- var import_react5 = require("react");
7368
+ var import_react6 = require("react");
6741
7369
 
6742
7370
  // src/hooks/useInteractiveArticle.ts
6743
7371
  var import_auto2 = __toESM(require("chart.js/auto"), 1);
6744
- var import_react4 = require("react");
7372
+ var import_react5 = require("react");
6745
7373
  function useInteractiveArticle(containerRef, depKey) {
6746
- (0, import_react4.useEffect)(() => {
7374
+ (0, import_react5.useEffect)(() => {
6747
7375
  const root = containerRef.current;
6748
7376
  if (!root) return;
6749
7377
  const cleanups = [];
@@ -7433,15 +8061,15 @@ function useInteractiveArticle(containerRef, depKey) {
7433
8061
  }
7434
8062
 
7435
8063
  // src/components/BlockRenderer.tsx
7436
- var import_jsx_runtime3 = require("react/jsx-runtime");
8064
+ var import_jsx_runtime4 = require("react/jsx-runtime");
7437
8065
  var BlockRenderer = ({
7438
8066
  data,
7439
8067
  className
7440
8068
  }) => {
7441
- const bodyRef = (0, import_react5.useRef)(null);
7442
- const html = (0, import_react5.useMemo)(() => blocksToHtml(data), [data]);
8069
+ const bodyRef = (0, import_react6.useRef)(null);
8070
+ const html = (0, import_react6.useMemo)(() => blocksToHtml(data), [data]);
7443
8071
  useInteractiveArticle(bodyRef, html);
7444
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8072
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7445
8073
  "div",
7446
8074
  {
7447
8075
  ref: bodyRef,
@@ -7452,7 +8080,7 @@ var BlockRenderer = ({
7452
8080
  };
7453
8081
 
7454
8082
  // src/components/DocumentHeader.tsx
7455
- var import_jsx_runtime4 = require("react/jsx-runtime");
8083
+ var import_jsx_runtime5 = require("react/jsx-runtime");
7456
8084
  var DocumentHeader = ({
7457
8085
  coverUrl,
7458
8086
  gradient = "linear-gradient(135deg, #27272a 0%, #52525b 100%)",
@@ -7462,12 +8090,12 @@ var DocumentHeader = ({
7462
8090
  className
7463
8091
  }) => {
7464
8092
  const bannerStyle = coverUrl ? { backgroundImage: `url("${coverUrl}")`, backgroundSize: "cover", backgroundPosition: "center" } : { background: gradient };
7465
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
7466
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "editor-cover-banner", style: bannerStyle }),
7467
- icon ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "editor-cover-icon", children: icon }) : null,
7468
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "editor-cover-meta", children: [
7469
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h1", { className: "editor-cover-title", children: title }),
7470
- subtitle ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { className: "editor-cover-subtitle", children: subtitle }) : null
8093
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("header", { className: className ? `editor-cover-card ${className}` : "editor-cover-card", children: [
8094
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "editor-cover-banner", style: bannerStyle }),
8095
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "editor-cover-icon", children: icon }) : null,
8096
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "editor-cover-meta", children: [
8097
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { className: "editor-cover-title", children: title }),
8098
+ subtitle ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "editor-cover-subtitle", children: subtitle }) : null
7471
8099
  ] })
7472
8100
  ] });
7473
8101
  };