nextgen-block-editor 0.3.0 → 0.3.1

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
@@ -54,7 +54,6 @@ var import_editorjs = __toESM(require("@editorjs/editorjs"), 1);
54
54
  var import_header = __toESM(require("@editorjs/header"), 1);
55
55
  var import_list = __toESM(require("@editorjs/list"), 1);
56
56
  var import_nested_list = __toESM(require("@editorjs/nested-list"), 1);
57
- var import_checklist = __toESM(require("@editorjs/checklist"), 1);
58
57
  var import_table = __toESM(require("@editorjs/table"), 1);
59
58
  var import_quote = __toESM(require("@editorjs/quote"), 1);
60
59
  var import_inline_code = __toESM(require("@editorjs/inline-code"), 1);
@@ -1733,22 +1732,25 @@ function attachEmojiSidePicker(container) {
1733
1732
  const triggerRange = document.createRange();
1734
1733
  triggerRange.setStart(textNode, triggerStart);
1735
1734
  triggerRange.setEnd(textNode, offset);
1736
- const rect = triggerRange.getBoundingClientRect();
1735
+ const rawRect = triggerRange.getBoundingClientRect();
1736
+ const rect = rawRect.width > 0 || rawRect.height > 0 ? rawRect : target.getBoundingClientRect();
1737
1737
  openEmojiSideMenu({
1738
1738
  anchorRect: rect,
1739
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);
1740
+ if (textNode.isConnected) {
1741
+ const current = textNode.data;
1742
+ textNode.data = current.slice(0, triggerStart) + emoji + current.slice(offset);
1743
+ const nextCaret = triggerStart + emoji.length;
1744
+ const newRange = document.createRange();
1745
+ newRange.setStart(textNode, nextCaret);
1746
+ newRange.setEnd(textNode, nextCaret);
1747
+ const s = window.getSelection();
1748
+ if (s) {
1749
+ s.removeAllRanges();
1750
+ s.addRange(newRange);
1751
+ }
1752
+ } else if (target.isConnected) {
1753
+ target.innerHTML = target.innerHTML.replace(/\/emoji/i, emoji);
1752
1754
  }
1753
1755
  target.focus();
1754
1756
  target.dispatchEvent(new Event("input", { bubbles: true }));
@@ -3713,14 +3715,23 @@ function createActionTriggerTool(title, icon, eventName) {
3713
3715
  }
3714
3716
  render() {
3715
3717
  const el = document.createElement("div");
3716
- el.style.display = "none";
3718
+ el.style.height = "1px";
3719
+ el.style.opacity = "0";
3720
+ el.style.pointerEvents = "none";
3717
3721
  this.el = el;
3718
3722
  return el;
3719
3723
  }
3720
3724
  rendered() {
3721
3725
  if (this.fired || !this.el) return;
3722
3726
  this.fired = true;
3723
- this.el.dispatchEvent(new CustomEvent(eventName, { bubbles: true }));
3727
+ const contentEl = this.el.closest(".ce-block__content") || this.el.closest(".ce-block") || this.el;
3728
+ const blockRect = contentEl.getBoundingClientRect();
3729
+ this.el.dispatchEvent(
3730
+ new CustomEvent(eventName, {
3731
+ bubbles: true,
3732
+ detail: { rect: blockRect }
3733
+ })
3734
+ );
3724
3735
  window.setTimeout(() => {
3725
3736
  try {
3726
3737
  const idx = this.api.blocks.getCurrentBlockIndex();
@@ -4118,12 +4129,17 @@ var EmojiTool = class {
4118
4129
  anchorRect: rect,
4119
4130
  onSelect: (em) => {
4120
4131
  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
- });
4132
+ const blockEl = this.anchorEl?.closest(".ce-block");
4133
+ const parent = blockEl?.parentElement;
4134
+ const domIdx = blockEl && parent ? Array.from(parent.children).indexOf(blockEl) : -1;
4135
+ const idx = domIdx >= 0 ? domIdx : this.api.blocks.getCurrentBlockIndex();
4136
+ if (idx >= 0) {
4137
+ this.api.blocks.insert("paragraph", { text: `${em} ` }, {}, idx + 1, true);
4138
+ this.api.blocks.delete(idx);
4139
+ window.requestAnimationFrame(() => {
4140
+ this.api?.caret?.setToBlock(idx, "end");
4141
+ });
4142
+ }
4127
4143
  return;
4128
4144
  }
4129
4145
  this.data.emoji = em;
@@ -4147,7 +4163,7 @@ var EmojiTool = class {
4147
4163
  }
4148
4164
  rendered() {
4149
4165
  if (this.isNewInsert) {
4150
- queueMicrotask(() => this.openPickerAtAnchor());
4166
+ window.requestAnimationFrame(() => this.openPickerAtAnchor());
4151
4167
  }
4152
4168
  }
4153
4169
  save() {
@@ -4158,83 +4174,11 @@ var EmojiTool = class {
4158
4174
  };
4159
4175
  }
4160
4176
  };
4161
- var ScratchTool = class {
4162
- data;
4163
- static get toolbox() {
4164
- return {
4165
- title: "Scratchpad",
4166
- icon: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4Z"/></svg>'
4167
- };
4168
- }
4169
- constructor({ data }) {
4170
- this.data = {
4171
- title: data?.title ?? "Scratchpad",
4172
- text: data?.text ?? ""
4173
- };
4174
- }
4175
- render() {
4176
- const wrap = document.createElement("div");
4177
- wrap.className = "editor-scratch-tool";
4178
- const head = document.createElement("div");
4179
- head.className = "editor-scratch-head";
4180
- const titleIn = document.createElement("input");
4181
- titleIn.type = "text";
4182
- titleIn.className = "cdx-input editor-scratch-title";
4183
- titleIn.placeholder = "Scratchpad title...";
4184
- titleIn.value = this.data.title ?? "Scratchpad";
4185
- titleIn.addEventListener("input", () => {
4186
- this.data.title = titleIn.value;
4187
- });
4188
- const stats = document.createElement("span");
4189
- stats.className = "editor-scratch-stats";
4190
- const updateStats = () => {
4191
- const len = this.data.text.length;
4192
- const words = this.data.text.trim() ? this.data.text.trim().split(/\s+/).length : 0;
4193
- stats.textContent = `${words}w \xB7 ${len}c`;
4194
- };
4195
- const copyBtn = document.createElement("button");
4196
- copyBtn.type = "button";
4197
- copyBtn.className = "b2";
4198
- copyBtn.textContent = "Copy";
4199
- copyBtn.addEventListener("click", () => {
4200
- if (!this.data.text) return;
4201
- void navigator.clipboard?.writeText(this.data.text);
4202
- copyBtn.textContent = "Copied";
4203
- window.setTimeout(() => {
4204
- copyBtn.textContent = "Copy";
4205
- }, 1200);
4206
- });
4207
- const clearBtn = document.createElement("button");
4208
- clearBtn.type = "button";
4209
- clearBtn.className = "b2";
4210
- clearBtn.textContent = "Clear";
4211
- head.append(titleIn, stats, copyBtn, clearBtn);
4212
- const textarea = document.createElement("textarea");
4213
- textarea.className = "cdx-input editor-scratch-textarea";
4214
- textarea.rows = 4;
4215
- textarea.placeholder = "Quick brain dump, rough notes, snippets...";
4216
- textarea.value = this.data.text || "";
4217
- textarea.addEventListener("input", () => {
4218
- this.data.text = textarea.value;
4219
- updateStats();
4220
- });
4221
- clearBtn.addEventListener("click", () => {
4222
- this.data.text = "";
4223
- textarea.value = "";
4224
- updateStats();
4225
- textarea.focus();
4226
- });
4227
- updateStats();
4228
- wrap.append(head, textarea);
4229
- return wrap;
4230
- }
4231
- save() {
4232
- return {
4233
- title: this.data.title?.trim() || "Scratchpad",
4234
- text: this.data.text
4235
- };
4236
- }
4237
- };
4177
+ var ScratchTool = createActionTriggerTool(
4178
+ "Scratchpad",
4179
+ '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 1 1 3 3L7 19l-4 1 1-4Z"/></svg>',
4180
+ "nextgen-open-scratch"
4181
+ );
4238
4182
  var DialogueTool = class {
4239
4183
  data;
4240
4184
  static get toolbox() {
@@ -6026,7 +5970,6 @@ function getEditorTools(includeLayout = true, enabledTools) {
6026
5970
  }
6027
5971
  },
6028
5972
  delimiter: DelimiterTool,
6029
- checklist: import_checklist.default,
6030
5973
  table: import_table.default,
6031
5974
  callout: CalloutTool,
6032
5975
  hotkey: HotkeyTool,
@@ -6254,6 +6197,10 @@ ${userContent}` }] }]
6254
6197
 
6255
6198
  // src/utils/popoverCategories.ts
6256
6199
  var TOOL_CATEGORIES = [
6200
+ {
6201
+ label: "AI",
6202
+ tools: ["continueWriting", "askAi"]
6203
+ },
6257
6204
  {
6258
6205
  label: "Text & Style",
6259
6206
  tools: [
@@ -6263,7 +6210,6 @@ var TOOL_CATEGORIES = [
6263
6210
  "paragraph",
6264
6211
  "list",
6265
6212
  "nestedlist",
6266
- "checklist",
6267
6213
  "quote",
6268
6214
  "pullquote",
6269
6215
  "delimiter",
@@ -6336,10 +6282,6 @@ var TOOL_CATEGORIES = [
6336
6282
  "slides"
6337
6283
  ]
6338
6284
  },
6339
- {
6340
- label: "AI",
6341
- tools: ["continueWriting", "askAi"]
6342
- },
6343
6285
  {
6344
6286
  label: "Settings",
6345
6287
  tools: ["settings"]
@@ -6367,9 +6309,8 @@ var TOOL_LABELS = {
6367
6309
  h2: "Heading 2",
6368
6310
  h3: "Heading 3",
6369
6311
  paragraph: "Paragraph",
6370
- list: "List",
6312
+ list: "List (Ordered / Unordered / Checklist)",
6371
6313
  nestedlist: "Nested List",
6372
- checklist: "Checklist",
6373
6314
  quote: "Quote",
6374
6315
  pullquote: "Pull Quote",
6375
6316
  delimiter: "Delimiter",
@@ -6454,18 +6395,25 @@ function attachPopoverCategoryHeaders(container) {
6454
6395
  titleEl.textContent = "Paragraph";
6455
6396
  }
6456
6397
  }
6457
- if (name) byName.set(name, el);
6458
- else uncategorized.push(el);
6398
+ if (name) {
6399
+ const arr = byName.get(name) || [];
6400
+ arr.push(el);
6401
+ byName.set(name, arr);
6402
+ } else {
6403
+ uncategorized.push(el);
6404
+ }
6459
6405
  });
6460
6406
  const frag = document.createDocumentFragment();
6461
6407
  const placed = /* @__PURE__ */ new Set();
6462
6408
  for (const group of TOOL_CATEGORIES) {
6463
6409
  const matched = [];
6464
6410
  for (const toolName of group.tools) {
6465
- const el = byName.get(toolName);
6466
- if (el && !placed.has(el)) {
6467
- matched.push(el);
6468
- placed.add(el);
6411
+ const els = byName.get(toolName) || [];
6412
+ for (const el of els) {
6413
+ if (!placed.has(el)) {
6414
+ matched.push(el);
6415
+ placed.add(el);
6416
+ }
6469
6417
  }
6470
6418
  }
6471
6419
  if (matched.length > 0) {
@@ -6679,7 +6627,7 @@ var ClassicToolbar = ({
6679
6627
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M4 10h2" }),
6680
6628
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" })
6681
6629
  ] }) }),
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: [
6630
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "ng-ct-btn", onMouseDown: keepSelection, onClick: () => insertBlock("list", { style: "checklist", items: [] }), title: "Checklist", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
6683
6631
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "3", y: "5", width: "6", height: "6", rx: "1" }),
6684
6632
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3 17 2 2 4-4" }),
6685
6633
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M13 6h8" }),
@@ -6791,6 +6739,7 @@ var SettingsModal = ({
6791
6739
  }) => {
6792
6740
  const [showKey, setShowKey] = (0, import_react3.useState)(false);
6793
6741
  const [toolFilter, setToolFilter] = (0, import_react3.useState)("");
6742
+ const [activeTab, setActiveTab] = (0, import_react3.useState)("appearance");
6794
6743
  if (!open) return null;
6795
6744
  const selectedSet = new Set(selectedTools);
6796
6745
  const toggleTool = (tool) => {
@@ -6809,206 +6758,226 @@ var SettingsModal = ({
6809
6758
  endpoint: preset?.defaultEndpoint || ""
6810
6759
  });
6811
6760
  };
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: [
6761
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-modal-backdrop", role: "dialog", "aria-modal": "true", "aria-label": "Editor Settings", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal ng-modal-wide", children: [
6813
6762
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-head", children: [
6814
6763
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
6815
6764
  /* @__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." })
6765
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: "Configure appearance, AI provider, and registered components." })
6817
6766
  ] }),
6818
6767
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "excalidraw-btn", onClick: onClose, children: "Done" })
6819
6768
  ] }),
6820
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-body", children: [
6821
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6822
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Theme" }),
6823
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6824
- "select",
6825
- {
6826
- className: "cdx-input editor-form-select",
6827
- value: theme,
6828
- onChange: (e) => onChangeTheme(e.target.value),
6829
- children: [
6830
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "inherit", children: "Inherit from Host App" }),
6831
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "light", children: "shadcn Light" }),
6832
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "dark", children: "shadcn Dark" }),
6833
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
6834
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
6835
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
6836
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
6837
- ]
6838
- }
6839
- )
6840
- ] }),
6841
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6842
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Editor Mode" }),
6843
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-segmented", children: [
6844
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6845
- "button",
6846
- {
6847
- type: "button",
6848
- className: `excalidraw-btn${mode === "block" ? " is-active" : ""}`,
6849
- onClick: () => onChangeMode("block"),
6850
- children: "Block Editor (Full)"
6851
- }
6852
- ),
6853
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6854
- "button",
6855
- {
6856
- type: "button",
6857
- className: `excalidraw-btn${mode === "simple" ? " is-active" : ""}`,
6858
- onClick: () => onChangeMode("simple"),
6859
- children: "Simple Mode"
6860
- }
6861
- )
6862
- ] })
6863
- ] }),
6864
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field ng-field-inline", children: [
6865
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
6866
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6867
- "input",
6868
- {
6869
- id: "ng-stats-toggle",
6870
- type: "checkbox",
6871
- checked: showStats,
6872
- onChange: (e) => onChangeShowStats(e.target.checked)
6873
- }
6874
- )
6875
- ] }),
6876
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("hr", { className: "ng-divider" }),
6877
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6878
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "AI Provider" }),
6879
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6880
- "select",
6881
- {
6882
- className: "cdx-input editor-form-select",
6883
- value: aiConfig.provider,
6884
- onChange: (e) => handleProviderChange(e.target.value),
6885
- children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: p.id, children: p.label }, p.id))
6886
- }
6887
- )
6888
- ] }),
6889
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6890
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Model" }),
6891
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6892
- "input",
6893
- {
6894
- type: "text",
6895
- className: "cdx-input editor-form-input",
6896
- value: aiConfig.model,
6897
- placeholder: "e.g. gpt-4o-mini",
6898
- onChange: (e) => onChangeAiConfig({ ...aiConfig, model: e.target.value })
6899
- }
6900
- )
6901
- ] }),
6902
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6903
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "API Key" }),
6904
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-key-row", children: [
6905
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6906
- "input",
6907
- {
6908
- type: showKey ? "text" : "password",
6909
- className: "cdx-input editor-form-input",
6910
- value: aiConfig.apiKey,
6911
- placeholder: "sk-...",
6912
- onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
6913
- }
6914
- ),
6915
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6916
- "button",
6917
- {
6918
- type: "button",
6919
- className: "excalidraw-btn",
6920
- onClick: () => setShowKey((s) => !s),
6921
- children: showKey ? "Hide" : "Show"
6922
- }
6923
- )
6924
- ] })
6925
- ] }),
6926
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6927
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Endpoint URL (optional)" }),
6928
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6929
- "input",
6930
- {
6931
- type: "url",
6932
- className: "cdx-input editor-form-input",
6933
- value: aiConfig.endpoint || "",
6934
- placeholder: "Default provider endpoint",
6935
- onChange: (e) => onChangeAiConfig({ ...aiConfig, endpoint: e.target.value })
6936
- }
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: [
6769
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-layout", children: [
6770
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("aside", { className: "ng-modal-sidebar", role: "tablist", "aria-label": "Settings sections", children: [
6771
+ { id: "appearance", label: "Appearance" },
6772
+ { id: "ai", label: "AI Provider" },
6773
+ { id: "components", label: `Components (${selectedSet.size})` }
6774
+ ].map((t) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6775
+ "button",
6776
+ {
6777
+ type: "button",
6778
+ role: "tab",
6779
+ "aria-selected": activeTab === t.id,
6780
+ className: `ng-modal-tab${activeTab === t.id ? " is-active" : ""}`,
6781
+ onClick: () => setActiveTab(t.id),
6782
+ children: t.label
6783
+ },
6784
+ t.id
6785
+ )) }),
6786
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-main", children: [
6787
+ activeTab === "appearance" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-panel", children: [
6788
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6789
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Theme" }),
6790
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6791
+ "select",
6792
+ {
6793
+ className: "cdx-input editor-form-select",
6794
+ value: theme,
6795
+ onChange: (e) => onChangeTheme(e.target.value),
6796
+ children: [
6797
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "inherit", children: "Inherit from Host App" }),
6798
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "light", children: "shadcn Light" }),
6799
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "dark", children: "shadcn Dark" }),
6800
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-mocha", children: "Catppuccin Mocha" }),
6801
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-macchiato", children: "Catppuccin Macchiato" }),
6802
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-frappe", children: "Catppuccin Frapp\xE9" }),
6803
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "catppuccin-latte", children: "Catppuccin Latte" })
6804
+ ]
6805
+ }
6806
+ )
6807
+ ] }),
6808
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6809
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Editor Mode" }),
6810
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-segmented", children: [
6811
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6812
+ "button",
6813
+ {
6814
+ type: "button",
6815
+ className: `excalidraw-btn${mode === "block" ? " is-active" : ""}`,
6816
+ onClick: () => onChangeMode("block"),
6817
+ children: "Block Editor (Full)"
6818
+ }
6819
+ ),
6820
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6821
+ "button",
6822
+ {
6823
+ type: "button",
6824
+ className: `excalidraw-btn${mode === "simple" ? " is-active" : ""}`,
6825
+ onClick: () => onChangeMode("simple"),
6826
+ children: "Simple Mode"
6827
+ }
6828
+ )
6829
+ ] })
6830
+ ] }),
6831
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field ng-field-inline", children: [
6832
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: "ng-stats-toggle", children: "Show word count & read time" }),
6950
6833
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6951
- "button",
6834
+ "input",
6952
6835
  {
6953
- type: "button",
6954
- className: "excalidraw-btn",
6955
- onClick: () => onChangeSelectedTools([...ALL_TOOL_NAMES]),
6956
- children: "All"
6836
+ id: "ng-stats-toggle",
6837
+ type: "checkbox",
6838
+ checked: showStats,
6839
+ onChange: (e) => onChangeShowStats(e.target.checked)
6957
6840
  }
6958
- ),
6841
+ )
6842
+ ] })
6843
+ ] }),
6844
+ activeTab === "ai" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-modal-panel", children: [
6845
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6846
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "AI Provider" }),
6959
6847
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6960
- "button",
6848
+ "select",
6961
6849
  {
6962
- type: "button",
6963
- className: "excalidraw-btn",
6964
- onClick: () => onChangeSelectedTools([...SIMPLE_MODE_TOOLS]),
6965
- children: "Minimal"
6850
+ className: "cdx-input editor-form-select",
6851
+ value: aiConfig.provider,
6852
+ onChange: (e) => handleProviderChange(e.target.value),
6853
+ children: AI_PROVIDER_PRESETS.map((p) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: p.id, children: p.label }, p.id))
6854
+ }
6855
+ )
6856
+ ] }),
6857
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6858
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Model" }),
6859
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6860
+ "input",
6861
+ {
6862
+ type: "text",
6863
+ className: "cdx-input editor-form-input",
6864
+ value: aiConfig.model,
6865
+ placeholder: "e.g. gpt-4o-mini",
6866
+ onChange: (e) => onChangeAiConfig({ ...aiConfig, model: e.target.value })
6867
+ }
6868
+ )
6869
+ ] }),
6870
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6871
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "API Key" }),
6872
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-key-row", children: [
6873
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6874
+ "input",
6875
+ {
6876
+ type: showKey ? "text" : "password",
6877
+ className: "cdx-input editor-form-input",
6878
+ value: aiConfig.apiKey,
6879
+ placeholder: "sk-...",
6880
+ onChange: (e) => onChangeAiConfig({ ...aiConfig, apiKey: e.target.value })
6881
+ }
6882
+ ),
6883
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6884
+ "button",
6885
+ {
6886
+ type: "button",
6887
+ className: "excalidraw-btn",
6888
+ onClick: () => setShowKey((s) => !s),
6889
+ children: showKey ? "Hide" : "Show"
6890
+ }
6891
+ )
6892
+ ] })
6893
+ ] }),
6894
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-field", children: [
6895
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { children: "Endpoint URL (optional)" }),
6896
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6897
+ "input",
6898
+ {
6899
+ type: "url",
6900
+ className: "cdx-input editor-form-input",
6901
+ value: aiConfig.endpoint || "",
6902
+ placeholder: "Default provider endpoint",
6903
+ onChange: (e) => onChangeAiConfig({ ...aiConfig, endpoint: e.target.value })
6966
6904
  }
6967
6905
  )
6968
6906
  ] })
6969
6907
  ] }),
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",
6908
+ activeTab === "components" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-manager", children: [
6909
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-header", children: [
6910
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { children: [
6911
+ "Registered Components (",
6912
+ selectedSet.size,
6913
+ "/",
6914
+ ALL_TOOL_NAMES.length,
6915
+ ")"
6916
+ ] }) }),
6917
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-actions", children: [
6918
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6919
+ "button",
6993
6920
  {
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
- }) })
6921
+ type: "button",
6922
+ className: "excalidraw-btn",
6923
+ onClick: () => onChangeSelectedTools([...ALL_TOOL_NAMES]),
6924
+ children: "All"
6925
+ }
6926
+ ),
6927
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6928
+ "button",
6929
+ {
6930
+ type: "button",
6931
+ className: "excalidraw-btn",
6932
+ onClick: () => onChangeSelectedTools([...SIMPLE_MODE_TOOLS]),
6933
+ children: "Minimal"
6934
+ }
6935
+ )
6936
+ ] })
6937
+ ] }),
6938
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6939
+ "input",
6940
+ {
6941
+ type: "search",
6942
+ className: "cdx-input editor-form-input",
6943
+ placeholder: "Filter components (e.g. bento, chart, spoiler...)",
6944
+ value: toolFilter,
6945
+ onChange: (e) => setToolFilter(e.target.value)
6946
+ }
6947
+ ),
6948
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-groups", children: TOOL_CATEGORIES.filter((g) => g.label !== "Settings").map((group) => {
6949
+ const q = toolFilter.trim().toLowerCase();
6950
+ const visible = group.tools.filter((t) => {
6951
+ const label = (TOOL_LABELS[t] || t).toLowerCase();
6952
+ return !q || label.includes(q) || t.toLowerCase().includes(q);
6953
+ });
6954
+ if (!visible.length) return null;
6955
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "ng-tools-group", children: [
6956
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-group-title", children: group.label }),
6957
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "ng-tools-grid", children: visible.map((tool) => {
6958
+ const checked = selectedSet.has(tool);
6959
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
6960
+ "label",
6961
+ {
6962
+ className: `ng-tool-chip${checked ? " is-checked" : ""}`,
6963
+ children: [
6964
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
6965
+ "input",
6966
+ {
6967
+ type: "checkbox",
6968
+ checked,
6969
+ onChange: () => toggleTool(tool)
6970
+ }
6971
+ ),
6972
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: TOOL_LABELS[tool] || tool })
6973
+ ]
6974
+ },
6975
+ tool
6976
+ );
6977
+ }) })
6978
+ ] }, group.label);
6979
+ }) })
6980
+ ] })
7012
6981
  ] })
7013
6982
  ] })
7014
6983
  ] }) });
@@ -7026,7 +6995,8 @@ var BlockEditor = import_react4.default.forwardRef(
7026
6995
  onAiRequest,
7027
6996
  className,
7028
6997
  onReady,
7029
- onChange
6998
+ onChange,
6999
+ onThemeChange
7030
7000
  }, ref) => {
7031
7001
  const shellRef = (0, import_react4.useRef)(null);
7032
7002
  const holderRef = (0, import_react4.useRef)(null);
@@ -7039,7 +7009,14 @@ var BlockEditor = import_react4.default.forwardRef(
7039
7009
  const runAiRef = (0, import_react4.useRef)(async () => {
7040
7010
  });
7041
7011
  const [settingsOpen, setSettingsOpen] = (0, import_react4.useState)(false);
7042
- const [theme, setTheme] = (0, import_react4.useState)("inherit");
7012
+ const [theme, setTheme] = (0, import_react4.useState)(() => {
7013
+ try {
7014
+ const saved = localStorage.getItem("ng-editor-theme");
7015
+ if (saved) return saved;
7016
+ } catch {
7017
+ }
7018
+ return "inherit";
7019
+ });
7043
7020
  const [editorMode, setEditorMode] = (0, import_react4.useState)("block");
7044
7021
  const [simpleFont, setSimpleFont] = (0, import_react4.useState)("sans");
7045
7022
  const [selectedTools, setSelectedTools] = (0, import_react4.useState)(() => {
@@ -7056,10 +7033,20 @@ var BlockEditor = import_react4.default.forwardRef(
7056
7033
  });
7057
7034
  const [statsVisible, setStatsVisible] = (0, import_react4.useState)(showStats);
7058
7035
  const [aiConfig, setAiConfig] = (0, import_react4.useState)(loadAiConfig);
7059
- const [askOpen, setAskOpen] = (0, import_react4.useState)(false);
7036
+ const [aiPopover, setAiPopover] = (0, import_react4.useState)(null);
7060
7037
  const [askPrompt, setAskPrompt] = (0, import_react4.useState)("");
7061
7038
  const [aiBusy, setAiBusy] = (0, import_react4.useState)(false);
7062
7039
  const [aiError, setAiError] = (0, import_react4.useState)(null);
7040
+ const [scratchOpen, setScratchOpen] = (0, import_react4.useState)(false);
7041
+ const [scratchText, setScratchText] = (0, import_react4.useState)(() => {
7042
+ try {
7043
+ return localStorage.getItem("ng-scratchpad-note") || "";
7044
+ } catch {
7045
+ return "";
7046
+ }
7047
+ });
7048
+ const [scratchCopied, setScratchCopied] = (0, import_react4.useState)(false);
7049
+ const [scratchOffset, setScratchOffset] = (0, import_react4.useState)({ x: 0, y: 0 });
7063
7050
  const [stats, setStats] = (0, import_react4.useState)(() => {
7064
7051
  const blocks = initialData?.blocks || [];
7065
7052
  const text = blocks.map((b) => JSON.stringify(b.data || {})).join(" ");
@@ -7071,19 +7058,47 @@ var BlockEditor = import_react4.default.forwardRef(
7071
7058
  (0, import_react4.useEffect)(() => {
7072
7059
  setStatsVisible(showStats);
7073
7060
  }, [showStats]);
7061
+ (0, import_react4.useEffect)(() => {
7062
+ try {
7063
+ localStorage.setItem("ng-editor-theme", theme);
7064
+ } catch {
7065
+ }
7066
+ if (theme === "inherit") {
7067
+ document.documentElement.removeAttribute("data-ng-theme");
7068
+ } else {
7069
+ document.documentElement.setAttribute("data-ng-theme", theme);
7070
+ }
7071
+ onThemeChange?.(theme);
7072
+ }, [theme, onThemeChange]);
7074
7073
  (0, import_react4.useEffect)(() => {
7075
7074
  const shell = shellRef.current;
7076
7075
  if (!shell) return;
7076
+ const openAiNearRect = (mode, e) => {
7077
+ const rect = e.detail?.rect;
7078
+ const shellRect = shell.getBoundingClientRect();
7079
+ const popW = 320;
7080
+ const rawLeft = rect ? rect.left - shellRect.left : 60;
7081
+ const rawTop = rect ? rect.top - shellRect.top + 4 : 60;
7082
+ const maxLeft = Math.max(12, shellRect.width - popW - 12);
7083
+ const left = Math.max(12, Math.min(rawLeft, maxLeft));
7084
+ const top = Math.max(12, rawTop);
7085
+ setAiError(null);
7086
+ setAskPrompt("");
7087
+ setAiPopover({ mode, top, left });
7088
+ };
7077
7089
  const onOpenSettings = () => setSettingsOpen(true);
7078
- const onAiContinue = () => void runAiRef.current?.("continue");
7079
- const onAiAsk = () => setAskOpen(true);
7090
+ const onAiContinue = (e) => openAiNearRect("continue", e);
7091
+ const onAiAsk = (e) => openAiNearRect("ask", e);
7092
+ const onOpenScratch = () => setScratchOpen(true);
7080
7093
  shell.addEventListener("nextgen-open-settings", onOpenSettings);
7081
7094
  shell.addEventListener("nextgen-ai-continue", onAiContinue);
7082
7095
  shell.addEventListener("nextgen-ai-ask", onAiAsk);
7096
+ shell.addEventListener("nextgen-open-scratch", onOpenScratch);
7083
7097
  return () => {
7084
7098
  shell.removeEventListener("nextgen-open-settings", onOpenSettings);
7085
7099
  shell.removeEventListener("nextgen-ai-continue", onAiContinue);
7086
7100
  shell.removeEventListener("nextgen-ai-ask", onAiAsk);
7101
+ shell.removeEventListener("nextgen-open-scratch", onOpenScratch);
7087
7102
  };
7088
7103
  }, []);
7089
7104
  (0, import_react4.useEffect)(() => {
@@ -7099,7 +7114,7 @@ var BlockEditor = import_react4.default.forwardRef(
7099
7114
  const sanitizedInitial = {
7100
7115
  ...latestDocRef.current || { blocks: [] },
7101
7116
  blocks: (latestDocRef.current?.blocks || []).filter(
7102
- (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
7117
+ (b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
7103
7118
  )
7104
7119
  };
7105
7120
  latestDocRef.current = sanitizedInitial;
@@ -7113,7 +7128,7 @@ var BlockEditor = import_react4.default.forwardRef(
7113
7128
  try {
7114
7129
  const saved = await instance.save();
7115
7130
  const filteredBlocks = (saved.blocks || []).filter(
7116
- (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
7131
+ (b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
7117
7132
  );
7118
7133
  const typed = { ...saved, blocks: filteredBlocks };
7119
7134
  latestDocRef.current = typed;
@@ -7165,7 +7180,7 @@ var BlockEditor = import_react4.default.forwardRef(
7165
7180
  await editorRef.current.isReady;
7166
7181
  const saved = await editorRef.current.save();
7167
7182
  const filteredBlocks = (saved.blocks || []).filter(
7168
- (b) => !["settings", "continueWriting", "askAi"].includes(b.type)
7183
+ (b) => !["settings", "continueWriting", "askAi", "scratch"].includes(b.type)
7169
7184
  );
7170
7185
  const typed = { ...saved, blocks: filteredBlocks };
7171
7186
  latestDocRef.current = typed;
@@ -7212,7 +7227,7 @@ var BlockEditor = import_react4.default.forwardRef(
7212
7227
  }
7213
7228
  if (mode === "ask") {
7214
7229
  setAskPrompt("");
7215
- setAskOpen(false);
7230
+ setAiPopover(null);
7216
7231
  }
7217
7232
  } catch (err) {
7218
7233
  setAiError(err instanceof Error ? err.message : "AI request failed.");
@@ -7258,9 +7273,11 @@ var BlockEditor = import_react4.default.forwardRef(
7258
7273
  "button",
7259
7274
  {
7260
7275
  type: "button",
7261
- className: `excalidraw-btn${askOpen ? " is-active" : ""}`,
7276
+ className: `excalidraw-btn${aiPopover?.mode === "ask" ? " is-active" : ""}`,
7262
7277
  disabled: aiBusy,
7263
- onClick: () => setAskOpen((o) => !o),
7278
+ onClick: () => setAiPopover(
7279
+ (p) => p ? null : { mode: "ask", top: 120, left: 120 }
7280
+ ),
7264
7281
  children: "Ask AI"
7265
7282
  }
7266
7283
  )
@@ -7276,30 +7293,6 @@ var BlockEditor = import_react4.default.forwardRef(
7276
7293
  }
7277
7294
  )
7278
7295
  ] }),
7279
- askOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
7280
- "form",
7281
- {
7282
- className: "ng-ask-form",
7283
- onSubmit: (e) => {
7284
- e.preventDefault();
7285
- if (askPrompt.trim()) void runAi("ask", askPrompt.trim());
7286
- },
7287
- children: [
7288
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7289
- "input",
7290
- {
7291
- type: "text",
7292
- className: "cdx-input editor-form-input",
7293
- placeholder: "Ask AI to draft, summarize, or expand...",
7294
- value: askPrompt,
7295
- onChange: (e) => setAskPrompt(e.target.value)
7296
- }
7297
- ),
7298
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "submit", className: "editor-form-submit", disabled: aiBusy, children: aiBusy ? "Running\u2026" : "Generate" })
7299
- ]
7300
- }
7301
- ),
7302
- aiError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "ng-ai-error", children: aiError }),
7303
7296
  editorMode === "simple" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7304
7297
  ClassicToolbar,
7305
7298
  {
@@ -7356,6 +7349,161 @@ var BlockEditor = import_react4.default.forwardRef(
7356
7349
  },
7357
7350
  onClose: () => setSettingsOpen(false)
7358
7351
  }
7352
+ ),
7353
+ aiPopover && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
7354
+ "form",
7355
+ {
7356
+ className: "ng-ai-inline-popover",
7357
+ style: { top: `${aiPopover.top}px`, left: `${aiPopover.left}px` },
7358
+ onSubmit: (e) => {
7359
+ e.preventDefault();
7360
+ if (aiPopover.mode === "continue") {
7361
+ void runAi("continue", askPrompt.trim());
7362
+ } else if (askPrompt.trim()) {
7363
+ void runAi("ask", askPrompt.trim());
7364
+ }
7365
+ },
7366
+ children: [
7367
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-ai-inline-head", children: [
7368
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: aiPopover.mode === "continue" ? "\u2726 Continue Writing" : "Ask AI" }),
7369
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7370
+ "button",
7371
+ {
7372
+ type: "button",
7373
+ className: "b2",
7374
+ "aria-label": "Close AI prompt",
7375
+ onClick: () => setAiPopover(null),
7376
+ children: "\xD7"
7377
+ }
7378
+ )
7379
+ ] }),
7380
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-ai-inline-row", children: [
7381
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7382
+ "input",
7383
+ {
7384
+ type: "text",
7385
+ autoFocus: true,
7386
+ className: "cdx-input editor-form-input",
7387
+ placeholder: aiPopover.mode === "continue" ? "How should AI continue? (optional)" : "What do you want AI to write?",
7388
+ value: askPrompt,
7389
+ onChange: (e) => setAskPrompt(e.target.value),
7390
+ onKeyDown: (e) => {
7391
+ if (e.key === "Escape") setAiPopover(null);
7392
+ }
7393
+ }
7394
+ ),
7395
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7396
+ "button",
7397
+ {
7398
+ type: "submit",
7399
+ className: "editor-form-submit",
7400
+ disabled: aiBusy || aiPopover.mode === "ask" && !askPrompt.trim(),
7401
+ children: aiBusy ? "Running\u2026" : aiPopover.mode === "continue" ? "Continue" : "Generate"
7402
+ }
7403
+ )
7404
+ ] }),
7405
+ aiError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "ng-ai-error", children: aiError })
7406
+ ]
7407
+ }
7408
+ ),
7409
+ scratchOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
7410
+ "div",
7411
+ {
7412
+ className: "ng-scratch-sticky",
7413
+ role: "dialog",
7414
+ "aria-label": "Scratchpad sticky note",
7415
+ style: {
7416
+ transform: `translate(${scratchOffset.x}px, ${scratchOffset.y}px)`
7417
+ },
7418
+ children: [
7419
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
7420
+ "div",
7421
+ {
7422
+ className: "ng-scratch-sticky-head",
7423
+ onMouseDown: (e) => {
7424
+ if (e.target.closest("button")) return;
7425
+ const startX = e.clientX - scratchOffset.x;
7426
+ const startY = e.clientY - scratchOffset.y;
7427
+ const onMove = (ev) => {
7428
+ setScratchOffset({ x: ev.clientX - startX, y: ev.clientY - startY });
7429
+ };
7430
+ const onUp = () => {
7431
+ window.removeEventListener("mousemove", onMove);
7432
+ window.removeEventListener("mouseup", onUp);
7433
+ };
7434
+ window.addEventListener("mousemove", onMove);
7435
+ window.addEventListener("mouseup", onUp);
7436
+ },
7437
+ children: [
7438
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "ng-scratch-sticky-title", children: "\u{1F4DD} Scratchpad" }),
7439
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "ng-scratch-sticky-count", children: [
7440
+ scratchText.trim() ? scratchText.trim().split(/\s+/).length : 0,
7441
+ "w \xB7 ",
7442
+ scratchText.length,
7443
+ "c"
7444
+ ] }),
7445
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "ng-scratch-sticky-actions", children: [
7446
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7447
+ "button",
7448
+ {
7449
+ type: "button",
7450
+ className: "ng-scratch-sticky-btn",
7451
+ onClick: () => {
7452
+ if (!scratchText) return;
7453
+ void navigator.clipboard?.writeText(scratchText);
7454
+ setScratchCopied(true);
7455
+ window.setTimeout(() => setScratchCopied(false), 1200);
7456
+ },
7457
+ children: scratchCopied ? "Copied" : "Copy"
7458
+ }
7459
+ ),
7460
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7461
+ "button",
7462
+ {
7463
+ type: "button",
7464
+ className: "ng-scratch-sticky-btn",
7465
+ onClick: () => {
7466
+ setScratchText("");
7467
+ try {
7468
+ localStorage.setItem("ng-scratchpad-note", "");
7469
+ } catch {
7470
+ }
7471
+ },
7472
+ children: "Clear"
7473
+ }
7474
+ ),
7475
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7476
+ "button",
7477
+ {
7478
+ type: "button",
7479
+ className: "ng-scratch-sticky-btn",
7480
+ "aria-label": "Close scratchpad",
7481
+ onClick: () => setScratchOpen(false),
7482
+ children: "\xD7"
7483
+ }
7484
+ )
7485
+ ] })
7486
+ ]
7487
+ }
7488
+ ),
7489
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7490
+ "textarea",
7491
+ {
7492
+ className: "ng-scratch-sticky-body",
7493
+ placeholder: "Quick sticky note, rough ideas, snippets...",
7494
+ value: scratchText,
7495
+ onChange: (e) => {
7496
+ const val = e.target.value;
7497
+ setScratchText(val);
7498
+ try {
7499
+ localStorage.setItem("ng-scratchpad-note", val);
7500
+ } catch {
7501
+ }
7502
+ }
7503
+ }
7504
+ )
7505
+ ]
7506
+ }
7359
7507
  )
7360
7508
  ]
7361
7509
  }
@@ -8064,15 +8212,28 @@ function useInteractiveArticle(containerRef, depKey) {
8064
8212
  var import_jsx_runtime4 = require("react/jsx-runtime");
8065
8213
  var BlockRenderer = ({
8066
8214
  data,
8215
+ theme,
8067
8216
  className
8068
8217
  }) => {
8069
8218
  const bodyRef = (0, import_react6.useRef)(null);
8070
8219
  const html = (0, import_react6.useMemo)(() => blocksToHtml(data), [data]);
8071
8220
  useInteractiveArticle(bodyRef, html);
8221
+ let resolvedTheme = theme;
8222
+ if (!resolvedTheme && typeof window !== "undefined") {
8223
+ resolvedTheme = document.documentElement.getAttribute("data-ng-theme") || (() => {
8224
+ try {
8225
+ return localStorage.getItem("ng-editor-theme") || void 0;
8226
+ } catch {
8227
+ return void 0;
8228
+ }
8229
+ })();
8230
+ }
8231
+ const attrTheme = resolvedTheme && resolvedTheme !== "inherit" ? resolvedTheme : void 0;
8072
8232
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8073
8233
  "div",
8074
8234
  {
8075
8235
  ref: bodyRef,
8236
+ "data-ng-theme": attrTheme,
8076
8237
  className: className ? `article nextgen-editor-article ${className}` : "article nextgen-editor-article",
8077
8238
  dangerouslySetInnerHTML: { __html: html }
8078
8239
  }