@bagelink/vue 1.2.11 → 1.2.15

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
@@ -211,14 +211,17 @@ const _sfc_main$1j = /* @__PURE__ */ vue.defineComponent({
211
211
  setup(__props) {
212
212
  const props2 = __props;
213
213
  const isComponent = vue.computed(() => {
214
+ if (props2.disabled) return props2.is;
214
215
  if (props2.to) return vueRouter.RouterLink;
215
216
  if (props2.href) return "a";
216
217
  return props2.is;
217
218
  });
218
219
  const bind3 = vue.computed(() => {
219
220
  const obj = {};
220
- if (props2.to && !props2.disabled) obj.to = props2.to;
221
- else if (props2.href && !props2.disabled) obj.href = props2.href;
221
+ if (!props2.disabled) {
222
+ if (props2.to) obj.to = props2.to;
223
+ else if (props2.href) obj.href = props2.href;
224
+ }
222
225
  if (!props2.to && !props2.href) {
223
226
  obj.role = props2.role;
224
227
  obj.type = props2.type;
@@ -275,7 +278,7 @@ const _sfc_main$1j = /* @__PURE__ */ vue.defineComponent({
275
278
  };
276
279
  }
277
280
  });
278
- const Btn = /* @__PURE__ */ _export_sfc(_sfc_main$1j, [["__scopeId", "data-v-b609e748"]]);
281
+ const Btn = /* @__PURE__ */ _export_sfc(_sfc_main$1j, [["__scopeId", "data-v-99c4aa53"]]);
279
282
  const _hoisted_1$17 = ["dismissable"];
280
283
  const _hoisted_2$R = { class: "m-0" };
281
284
  const _sfc_main$1i = /* @__PURE__ */ vue.defineComponent({
@@ -16075,14 +16078,13 @@ const _sfc_main$R = /* @__PURE__ */ vue.defineComponent({
16075
16078
  return resolvedSchemaData.value.length > 2 || resolvedSchemaData.value.some((schema) => schema.$el === "richtext");
16076
16079
  });
16077
16080
  return (_ctx, _cache) => {
16078
- const _component_Icon = vue.resolveComponent("Icon");
16079
16081
  return vue.openBlock(), vue.createElementBlock("div", {
16080
16082
  class: vue.normalizeClass(props2.class)
16081
16083
  }, [
16082
16084
  _ctx.label ? (vue.openBlock(), vue.createElementBlock("p", _hoisted_1$K, vue.toDisplayString(_ctx.label), 1)) : vue.createCommentVNode("", true),
16083
16085
  vue.createElementVNode("div", _hoisted_2$x, [
16084
16086
  schemaState.value !== "loaded" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3$t, [
16085
- schemaState.value === "loading" ? (vue.openBlock(), vue.createBlock(vue.unref(Loading), { key: 0 })) : schemaState.value === "error" ? (vue.openBlock(), vue.createBlock(_component_Icon, {
16087
+ schemaState.value === "loading" ? (vue.openBlock(), vue.createBlock(vue.unref(Loading), { key: 0 })) : schemaState.value === "error" ? (vue.openBlock(), vue.createBlock(vue.unref(_sfc_main$s), {
16086
16088
  key: 1,
16087
16089
  icon: "error",
16088
16090
  color: "red"
@@ -23005,13 +23007,15 @@ const toolbarOptions = [
23005
23007
  { name: "fontColor", label: "Font Color", icon: "format_color_text" },
23006
23008
  { name: "bgColor", label: "Background Color", icon: "format_color_fill" },
23007
23009
  { name: "insertTable", label: "Insert Table", icon: "table" },
23008
- { name: "deleteTable", label: "Delete Table", icon: "table_rows" },
23009
- { name: "insertRowAbove", label: "Insert Row Above", icon: "table_rows" },
23010
- { name: "insertRowBelow", label: "Insert Row Below", icon: "table_rows" },
23011
- { name: "deleteRow", label: "Delete Row", icon: "table_rows" },
23012
- { name: "insertColumnLeft", label: "Insert Column Left", icon: "add_column_left" },
23013
- { name: "insertColumnRight", label: "Insert Column Right", icon: "add_column_right" },
23014
- { name: "deleteColumn", label: "Delete Column", icon: "view_column" },
23010
+ { name: "deleteTable", label: "Delete Table", icon: "delete_sweep" },
23011
+ { name: "mergeCells", label: "Merge Cells", icon: "table_chart" },
23012
+ { name: "splitCells", label: "Split Cells", icon: "dashboard" },
23013
+ { name: "addRowBefore", label: "Insert Row Above", icon: "add_box" },
23014
+ { name: "addRowAfter", label: "Insert Row Below", icon: "vertical_align_bottom" },
23015
+ { name: "deleteRow", label: "Delete Row", icon: "remove" },
23016
+ { name: "insertColumnLeft", label: "Insert Column Left", icon: "format_indent_decrease" },
23017
+ { name: "insertColumnRight", label: "Insert Column Right", icon: "format_indent_increase" },
23018
+ { name: "deleteColumn", label: "Delete Column", icon: "view_week" },
23015
23019
  { name: "separator" },
23016
23020
  { name: "undo", label: "Undo", icon: "undo" },
23017
23021
  { name: "redo", label: "Redo", icon: "redo" },
@@ -23022,12 +23026,16 @@ const _hoisted_1$u = { class: "grid grid-wrap p-05" };
23022
23026
  const _hoisted_2$j = ["onMousemove", "onClick"];
23023
23027
  const _hoisted_3$g = { class: "txt-center txt-12 color-gray" };
23024
23028
  const fb = 1;
23025
- const base = 5;
23026
23029
  const _sfc_main$B = /* @__PURE__ */ vue.defineComponent({
23027
23030
  __name: "gridBox",
23031
+ props: {
23032
+ gridSize: {}
23033
+ },
23028
23034
  emits: ["select"],
23029
23035
  setup(__props, { emit: __emit }) {
23036
+ const props2 = __props;
23030
23037
  const emit2 = __emit;
23038
+ const base = props2.gridSize || 5;
23031
23039
  const hoveredRow = vue.ref(fb);
23032
23040
  const hoveredCol = vue.ref(fb);
23033
23041
  const rowSize = vue.computed(() => {
@@ -23075,7 +23083,7 @@ const _sfc_main$B = /* @__PURE__ */ vue.defineComponent({
23075
23083
  };
23076
23084
  }
23077
23085
  });
23078
- const GridBox = /* @__PURE__ */ _export_sfc(_sfc_main$B, [["__scopeId", "data-v-4548b70f"]]);
23086
+ const GridBox = /* @__PURE__ */ _export_sfc(_sfc_main$B, [["__scopeId", "data-v-2f424c9c"]]);
23079
23087
  const _hoisted_1$t = {
23080
23088
  class: "toolbar flex gap-025 pb-05 flex-wrap",
23081
23089
  role: "toolbar"
@@ -23108,10 +23116,8 @@ const _sfc_main$A = /* @__PURE__ */ vue.defineComponent({
23108
23116
  default: vue.withCtx(({ hide }) => [
23109
23117
  vue.createVNode(GridBox, {
23110
23118
  gridSize: 5,
23111
- onSelect: ($event) => {
23112
- var _a;
23113
- runAction("insertTable", $event);
23114
- (_a = $event.target) == null ? void 0 : _a.blur();
23119
+ onSelect: (value) => {
23120
+ runAction("insertTable", value);
23115
23121
  hide();
23116
23122
  }
23117
23123
  }, null, 8, ["onSelect"])
@@ -23138,7 +23144,7 @@ const _sfc_main$A = /* @__PURE__ */ vue.defineComponent({
23138
23144
  };
23139
23145
  }
23140
23146
  });
23141
- const EditorToolbar = /* @__PURE__ */ _export_sfc(_sfc_main$A, [["__scopeId", "data-v-9d8a6eb6"]]);
23147
+ const EditorToolbar = /* @__PURE__ */ _export_sfc(_sfc_main$A, [["__scopeId", "data-v-7e9466dc"]]);
23142
23148
  function isStyleActive(style, doc) {
23143
23149
  const selection = doc.getSelection();
23144
23150
  if (!selection || !selection.rangeCount) return false;
@@ -23258,11 +23264,22 @@ function formatting(state2) {
23258
23264
  range2.surroundContents(span);
23259
23265
  }
23260
23266
  } else {
23261
- doc.execCommand(command, false);
23267
+ if (range2.collapsed) return;
23268
+ const span = doc.createElement("span");
23269
+ if (command === "bold") span.style.fontWeight = "bold";
23270
+ else if (command === "italic") span.style.fontStyle = "italic";
23271
+ else if (command === "underline") span.style.textDecoration = "underline";
23272
+ try {
23273
+ range2.surroundContents(span);
23274
+ } catch (e) {
23275
+ const fragment = range2.extractContents();
23276
+ span.appendChild(fragment);
23277
+ range2.insertNode(span);
23278
+ }
23262
23279
  }
23263
23280
  };
23264
23281
  const block = (command, tag) => {
23265
- var _a, _b;
23282
+ var _a;
23266
23283
  const selection = doc.getSelection();
23267
23284
  if (!selection || !selection.rangeCount) return;
23268
23285
  const range2 = selection.getRangeAt(0);
@@ -23279,10 +23296,18 @@ function formatting(state2) {
23279
23296
  wrapper.remove();
23280
23297
  }
23281
23298
  }
23282
- doc.execCommand("formatBlock", false, tag);
23283
- if (isRTL) {
23284
- const newBlock = (_b = (_a = selection.anchorNode) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.closest(tag.toLowerCase());
23285
- if (newBlock) newBlock.dir = "rtl";
23299
+ const newBlock = doc.createElement(tag);
23300
+ if (isRTL) newBlock.dir = "rtl";
23301
+ const currentBlock = (parentBlock == null ? void 0 : parentBlock.closest("p,h1,h2,h3,h4,h5,h6,blockquote,div")) || parentBlock;
23302
+ if (currentBlock) {
23303
+ while (currentBlock.firstChild) {
23304
+ newBlock.appendChild(currentBlock.firstChild);
23305
+ }
23306
+ (_a = currentBlock.parentNode) == null ? void 0 : _a.replaceChild(newBlock, currentBlock);
23307
+ range2.selectNodeContents(newBlock);
23308
+ range2.collapse(false);
23309
+ selection.removeAllRanges();
23310
+ selection.addRange(range2);
23286
23311
  }
23287
23312
  };
23288
23313
  const list = (command) => {
@@ -23347,13 +23372,34 @@ function formatting(state2) {
23347
23372
  restoreSelection(state2.doc, state2.range, state2.selection, selectionInfo, listEl);
23348
23373
  };
23349
23374
  const clear = () => {
23350
- if (!state2.doc || !state2.range || !state2.selection) return;
23375
+ console.log("[Clear Format] Starting clear format process", state2);
23376
+ console.assert(state2, "[Clear Format] State must exist");
23377
+ console.assert(state2.doc, "[Clear Format] Document must exist");
23378
+ console.assert(state2.range, "[Clear Format] Range must exist");
23379
+ console.assert(state2.selection, "[Clear Format] Selection must exist");
23380
+ if (!state2.doc || !state2.range || !state2.selection) {
23381
+ console.log("[Clear Format] No document or selection");
23382
+ return;
23383
+ }
23351
23384
  const selectionInfo = analyzeSelection(state2.doc, state2.range);
23352
- if (!selectionInfo) return;
23353
- const inlineTags = ["b", "i", "u", "strong", "em", "span"];
23385
+ console.log("[Clear Format] Selection info:", selectionInfo);
23386
+ if (!selectionInfo) {
23387
+ console.log("[Clear Format] No valid selection info");
23388
+ return;
23389
+ }
23390
+ if (state2.range.collapsed) {
23391
+ console.log("[Clear Format] Selection is collapsed, nothing to clear");
23392
+ return;
23393
+ }
23394
+ console.log("[Clear Format] Processing selection:", {
23395
+ startContainer: state2.range.startContainer,
23396
+ endContainer: state2.range.endContainer,
23397
+ selectedText: state2.range.toString()
23398
+ });
23354
23399
  const fragment = state2.range.cloneContents();
23355
23400
  const tempDiv = state2.doc.createElement("div");
23356
23401
  tempDiv.appendChild(fragment);
23402
+ console.log("[Clear Format] Original HTML:", tempDiv.innerHTML);
23357
23403
  const cleanNode = (node) => {
23358
23404
  if (!state2.doc) return node;
23359
23405
  if (node.nodeType === 3) {
@@ -23362,12 +23408,36 @@ function formatting(state2) {
23362
23408
  if (node.nodeType === 1) {
23363
23409
  const el = node;
23364
23410
  const nodeName = el.nodeName.toLowerCase();
23411
+ const inlineTags = ["b", "i", "u", "strong", "em", "span", "font", "strike", "sub", "sup"];
23412
+ console.log("[Clear Format] Processing element:", nodeName, {
23413
+ hasStyle: el.hasAttribute("style"),
23414
+ style: el.getAttribute("style"),
23415
+ className: el.className
23416
+ });
23365
23417
  if (inlineTags.includes(nodeName)) {
23366
- return state2.doc.createTextNode(el.textContent || "");
23418
+ const textContent = el.textContent || "";
23419
+ console.log("[Clear Format] Extracting text from inline element:", textContent);
23420
+ return state2.doc.createTextNode(textContent);
23367
23421
  }
23368
23422
  const newEl = state2.doc.createElement(nodeName);
23369
- newEl.removeAttribute("style");
23370
- newEl.removeAttribute("class");
23423
+ if (el.hasAttribute("style")) {
23424
+ console.log("[Clear Format] Removing style attribute:", el.getAttribute("style"));
23425
+ }
23426
+ if (el.className) {
23427
+ console.log("[Clear Format] Removing class:", el.className);
23428
+ }
23429
+ if (nodeName === "a" && el.hasAttribute("href")) {
23430
+ newEl.setAttribute("href", el.getAttribute("href") || "");
23431
+ if (el.hasAttribute("target")) {
23432
+ newEl.setAttribute("target", el.getAttribute("target") || "");
23433
+ }
23434
+ console.log("[Clear Format] Preserving link attributes");
23435
+ }
23436
+ if (nodeName === "img") {
23437
+ if (el.hasAttribute("src")) newEl.setAttribute("src", el.getAttribute("src") || "");
23438
+ if (el.hasAttribute("alt")) newEl.setAttribute("alt", el.getAttribute("alt") || "");
23439
+ console.log("[Clear Format] Preserving image attributes");
23440
+ }
23371
23441
  Array.from(el.childNodes).forEach((child) => {
23372
23442
  newEl.appendChild(cleanNode(child));
23373
23443
  });
@@ -23379,9 +23449,14 @@ function formatting(state2) {
23379
23449
  Array.from(tempDiv.childNodes).forEach((node) => {
23380
23450
  cleanedFragment.appendChild(cleanNode(node));
23381
23451
  });
23452
+ const debugDiv = state2.doc.createElement("div");
23453
+ debugDiv.appendChild(cleanedFragment.cloneNode(true));
23454
+ console.log("[Clear Format] Cleaned HTML:", debugDiv.innerHTML);
23382
23455
  state2.range.deleteContents();
23383
23456
  state2.range.insertNode(cleanedFragment);
23384
23457
  restoreSelection(state2.doc, state2.range, state2.selection, selectionInfo);
23458
+ state2.content = state2.doc.body.innerHTML;
23459
+ console.log("[Clear Format] Updated document HTML:", state2.content);
23385
23460
  };
23386
23461
  return { text, block, list, clear };
23387
23462
  }
@@ -23494,16 +23569,44 @@ function insertTable(rows, cols, state2) {
23494
23569
  const table = state2.doc.createElement("table");
23495
23570
  table.style.width = "100%";
23496
23571
  table.style.borderCollapse = "collapse";
23572
+ table.style.marginBottom = "1rem";
23573
+ const thead = state2.doc.createElement("thead");
23574
+ const headerRow = thead.insertRow();
23575
+ for (let j = 0; j < cols; j++) {
23576
+ const th = state2.doc.createElement("th");
23577
+ th.innerHTML = `Header ${j + 1}`;
23578
+ th.style.padding = "8px";
23579
+ th.style.border = "1px solid var(--border-color, #ddd)";
23580
+ th.style.backgroundColor = "var(--bgl-gray-light, #f4f4f4)";
23581
+ headerRow.appendChild(th);
23582
+ }
23583
+ table.appendChild(thead);
23584
+ const tbody = state2.doc.createElement("tbody");
23497
23585
  for (let i2 = 0; i2 < rows; i2++) {
23498
- const row = table.insertRow();
23586
+ const row = tbody.insertRow();
23499
23587
  for (let j = 0; j < cols; j++) {
23500
23588
  const cell = row.insertCell();
23501
23589
  cell.innerHTML = "&nbsp;";
23590
+ cell.style.padding = "8px";
23591
+ cell.style.border = "1px solid var(--border-color, #ddd)";
23502
23592
  }
23503
23593
  }
23594
+ table.appendChild(tbody);
23504
23595
  const { range: range2 } = state2;
23505
23596
  if (range2) {
23506
23597
  range2.insertNode(table);
23598
+ if (state2.doc.getSelection()) {
23599
+ const firstCell = table.querySelector("td");
23600
+ if (firstCell) {
23601
+ range2.selectNodeContents(firstCell);
23602
+ range2.collapse(true);
23603
+ const selection = state2.doc.getSelection();
23604
+ if (selection) {
23605
+ selection.removeAllRanges();
23606
+ selection.addRange(range2);
23607
+ }
23608
+ }
23609
+ }
23507
23610
  } else {
23508
23611
  state2.doc.body.appendChild(table);
23509
23612
  }
@@ -23664,12 +23767,9 @@ function createFormattingCommand(state2, type3, command, tag) {
23664
23767
  var _a, _b;
23665
23768
  if (!state2.doc) return;
23666
23769
  if (type3 === "text") {
23667
- if (command === "bold") state2.doc.execCommand("bold", false);
23668
- else if (command === "italic") state2.doc.execCommand("italic", false);
23669
- else if (command === "underline") state2.doc.execCommand("underline", false);
23670
- else format2.text(command);
23770
+ format2.text(command);
23671
23771
  } else if (type3 === "block") {
23672
- state2.doc.execCommand("formatBlock", false, `<${command}>`);
23772
+ format2.block(command, command);
23673
23773
  } else if (type3 === "list") {
23674
23774
  const selection = state2.doc.getSelection();
23675
23775
  if (!selection || !selection.rangeCount) return;
@@ -23690,10 +23790,7 @@ function createFormattingCommand(state2, type3, command, tag) {
23690
23790
  selection.removeAllRanges();
23691
23791
  selection.addRange(range2);
23692
23792
  } else {
23693
- state2.doc.execCommand(
23694
- command === "orderedList" ? "insertOrderedList" : "insertUnorderedList",
23695
- false
23696
- );
23793
+ format2.list(command);
23697
23794
  }
23698
23795
  }
23699
23796
  },
@@ -23702,34 +23799,167 @@ function createFormattingCommand(state2, type3, command, tag) {
23702
23799
  }
23703
23800
  function isNodeEmpty$1(node) {
23704
23801
  var _a;
23705
- const text = ((_a = node.textContent) == null ? void 0 : _a.trim()) || "";
23802
+ const text = ((_a = node.textContent) == null ? void 0 : _a.replace(/\s/g, "")) || "";
23706
23803
  if (text) return false;
23707
- const brElements = node.getElementsByTagName("br");
23804
+ const brElements = node.getElementsByTagName ? node.getElementsByTagName("br") : [];
23708
23805
  if (brElements.length === 0) return true;
23709
- return brElements.length === 1 && node.childNodes.length === 1;
23806
+ return brElements.length === 1 && node.childNodes.length <= 2;
23710
23807
  }
23711
23808
  function createCommandRegistry(state2) {
23712
23809
  const format2 = formatting(state2);
23713
23810
  const historyCommands = {
23714
23811
  undo: createCommand("Undo", () => {
23715
- var _a;
23716
- return (_a = state2.doc) == null ? void 0 : _a.execCommand("undo", false);
23812
+ if (state2.undoStack.length > 0 && state2.doc) {
23813
+ const lastContent = state2.undoStack.pop();
23814
+ if (lastContent !== void 0) {
23815
+ state2.redoStack.push(state2.content);
23816
+ state2.content = lastContent;
23817
+ if (state2.doc) state2.doc.body.innerHTML = lastContent;
23818
+ }
23819
+ }
23717
23820
  }),
23718
23821
  redo: createCommand("Redo", () => {
23719
- var _a;
23720
- return (_a = state2.doc) == null ? void 0 : _a.execCommand("redo", false);
23822
+ if (state2.redoStack.length > 0 && state2.doc) {
23823
+ const nextContent = state2.redoStack.pop();
23824
+ if (nextContent !== void 0) {
23825
+ state2.undoStack.push(state2.content);
23826
+ state2.content = nextContent;
23827
+ if (state2.doc) state2.doc.body.innerHTML = nextContent;
23828
+ }
23829
+ }
23830
+ })
23831
+ };
23832
+ const textCommands = {
23833
+ bold: createCommand("Bold", (state22) => {
23834
+ console.log("[Command] Bold called");
23835
+ if (!state22.doc || !state22.range || !state22.selection) return;
23836
+ const { range: range2 } = state22;
23837
+ if (range2.collapsed) return;
23838
+ try {
23839
+ const span = state22.doc.createElement("span");
23840
+ span.style.fontWeight = "bold";
23841
+ try {
23842
+ range2.surroundContents(span);
23843
+ } catch (e) {
23844
+ const fragment = range2.extractContents();
23845
+ span.appendChild(fragment);
23846
+ range2.insertNode(span);
23847
+ }
23848
+ range2.selectNodeContents(span);
23849
+ state22.selection.removeAllRanges();
23850
+ state22.selection.addRange(range2);
23851
+ state22.content = state22.doc.body.innerHTML;
23852
+ } catch (error) {
23853
+ console.error("[Command] Error applying bold:", error);
23854
+ }
23855
+ }),
23856
+ italic: createCommand("Italic", (state22) => {
23857
+ console.log("[Command] Italic called");
23858
+ if (!state22.doc || !state22.range || !state22.selection) return;
23859
+ const { range: range2 } = state22;
23860
+ if (range2.collapsed) return;
23861
+ try {
23862
+ const span = state22.doc.createElement("span");
23863
+ span.style.fontStyle = "italic";
23864
+ try {
23865
+ range2.surroundContents(span);
23866
+ } catch (e) {
23867
+ const fragment = range2.extractContents();
23868
+ span.appendChild(fragment);
23869
+ range2.insertNode(span);
23870
+ }
23871
+ range2.selectNodeContents(span);
23872
+ state22.selection.removeAllRanges();
23873
+ state22.selection.addRange(range2);
23874
+ state22.content = state22.doc.body.innerHTML;
23875
+ } catch (error) {
23876
+ console.error("[Command] Error applying italic:", error);
23877
+ }
23878
+ }),
23879
+ underline: createCommand("Underline", (state22) => {
23880
+ console.log("[Command] Underline called");
23881
+ if (!state22.doc || !state22.range || !state22.selection) return;
23882
+ const { range: range2 } = state22;
23883
+ if (range2.collapsed) return;
23884
+ try {
23885
+ const span = state22.doc.createElement("span");
23886
+ span.style.textDecoration = "underline";
23887
+ try {
23888
+ range2.surroundContents(span);
23889
+ } catch (e) {
23890
+ const fragment = range2.extractContents();
23891
+ span.appendChild(fragment);
23892
+ range2.insertNode(span);
23893
+ }
23894
+ range2.selectNodeContents(span);
23895
+ state22.selection.removeAllRanges();
23896
+ state22.selection.addRange(range2);
23897
+ state22.content = state22.doc.body.innerHTML;
23898
+ } catch (error) {
23899
+ console.error("[Command] Error applying underline:", error);
23900
+ }
23721
23901
  })
23722
23902
  };
23723
- const textCommands = ["bold", "italic", "underline"].reduce((acc, cmd) => ({
23724
- ...acc,
23725
- [cmd]: createFormattingCommand(state2, "text", cmd)
23726
- }), {});
23727
23903
  const headingCommands = ["h1", "h2", "h3", "h4", "h5", "h6"].reduce((acc, cmd) => ({
23728
23904
  ...acc,
23729
- [cmd]: createFormattingCommand(state2, "block", cmd)
23905
+ [cmd]: createCommand(`Heading ${cmd}`, (state22) => {
23906
+ var _a;
23907
+ console.log(`[Command] ${cmd} heading called`);
23908
+ if (!state22.doc || !state22.range || !state22.selection) return;
23909
+ const { range: range2, doc, selection } = state22;
23910
+ const container = range2.commonAncestorContainer;
23911
+ const parentBlock = container.nodeType === 3 ? container.parentElement : container;
23912
+ const currentBlock = (parentBlock == null ? void 0 : parentBlock.closest("p,h1,h2,h3,h4,h5,h6,blockquote,div")) || parentBlock;
23913
+ const isToggleOff = (currentBlock == null ? void 0 : currentBlock.tagName.toLowerCase()) === cmd.toLowerCase();
23914
+ const newTag = isToggleOff ? "p" : cmd;
23915
+ try {
23916
+ const newBlock = doc.createElement(newTag);
23917
+ if (currentBlock) {
23918
+ while (currentBlock.firstChild) {
23919
+ newBlock.appendChild(currentBlock.firstChild);
23920
+ }
23921
+ (_a = currentBlock.parentNode) == null ? void 0 : _a.replaceChild(newBlock, currentBlock);
23922
+ range2.selectNodeContents(newBlock);
23923
+ range2.collapse(false);
23924
+ selection.removeAllRanges();
23925
+ selection.addRange(range2);
23926
+ }
23927
+ state22.content = doc.body.innerHTML;
23928
+ } catch (error) {
23929
+ console.error(`[Command] Error applying ${cmd} heading:`, error);
23930
+ }
23931
+ })
23730
23932
  }), {});
23731
23933
  const blockCommands = {
23732
- p: createFormattingCommand(state2, "block", "p"),
23934
+ p: createCommand("Paragraph", (state22) => {
23935
+ var _a;
23936
+ console.log("[Command] Paragraph called");
23937
+ if (!state22.doc || !state22.range || !state22.selection) return;
23938
+ const { range: range2, doc, selection } = state22;
23939
+ const container = range2.commonAncestorContainer;
23940
+ const parentBlock = container.nodeType === 3 ? container.parentElement : container;
23941
+ const currentBlock = (parentBlock == null ? void 0 : parentBlock.closest("p,h1,h2,h3,h4,h5,h6,blockquote,div")) || parentBlock;
23942
+ if ((currentBlock == null ? void 0 : currentBlock.tagName.toLowerCase()) === "p") {
23943
+ console.log("[Command] Already a paragraph");
23944
+ return;
23945
+ }
23946
+ try {
23947
+ const newParagraph = doc.createElement("p");
23948
+ if (currentBlock) {
23949
+ while (currentBlock.firstChild) {
23950
+ newParagraph.appendChild(currentBlock.firstChild);
23951
+ }
23952
+ (_a = currentBlock.parentNode) == null ? void 0 : _a.replaceChild(newParagraph, currentBlock);
23953
+ range2.selectNodeContents(newParagraph);
23954
+ range2.collapse(false);
23955
+ selection.removeAllRanges();
23956
+ selection.addRange(range2);
23957
+ }
23958
+ state22.content = doc.body.innerHTML;
23959
+ } catch (error) {
23960
+ console.error("[Command] Error applying paragraph:", error);
23961
+ }
23962
+ }),
23733
23963
  blockquote: createFormattingCommand(state2, "block", "blockquote")
23734
23964
  };
23735
23965
  const listCommands = {
@@ -23772,8 +24002,62 @@ function createCommandRegistry(state2) {
23772
24002
  embed: createCommand("Insert Embed", (state22) => state22.modal && insertEmbed(state22.modal, state22))
23773
24003
  };
23774
24004
  const otherCommands = {
23775
- clear: createCommand("Clear Formatting", () => {
23776
- format2.clear();
24005
+ clear: createCommand("Clear Formatting", (state22) => {
24006
+ var _a;
24007
+ console.log("[Command] Clear formatting called");
24008
+ console.log("[Command] Current selection:", (_a = state22.selection) == null ? void 0 : _a.toString());
24009
+ console.log("[Command] Range exists:", !!state22.range);
24010
+ console.log("[Command] Document exists:", !!state22.doc);
24011
+ try {
24012
+ if (!state22.doc || !state22.range || !state22.selection) {
24013
+ console.log("[Command] Missing required state for clear formatting");
24014
+ return;
24015
+ }
24016
+ const { selection, range: range2, doc } = state22;
24017
+ if (range2.collapsed) {
24018
+ console.log("[Command] Selection is collapsed, nothing to clear");
24019
+ return;
24020
+ }
24021
+ const fragment = range2.cloneContents();
24022
+ const tempDiv = doc.createElement("div");
24023
+ tempDiv.appendChild(fragment);
24024
+ console.log("[Command] Original HTML:", tempDiv.innerHTML);
24025
+ const structuralTags = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "li", "blockquote", "div", "table", "tr", "td", "th"];
24026
+ const inlineTags = ["b", "i", "u", "strong", "em", "span", "font", "strike", "sub", "sup"];
24027
+ const cleanElement = (element) => {
24028
+ element.removeAttribute("style");
24029
+ element.removeAttribute("class");
24030
+ Array.from(element.children).forEach((child) => {
24031
+ if (inlineTags.includes(child.tagName.toLowerCase())) {
24032
+ const textContent = child.textContent || "";
24033
+ const textNode = doc.createTextNode(textContent);
24034
+ child.replaceWith(textNode);
24035
+ } else {
24036
+ cleanElement(child);
24037
+ }
24038
+ });
24039
+ };
24040
+ Array.from(tempDiv.querySelectorAll("*")).forEach((element) => {
24041
+ const tagName = element.tagName.toLowerCase();
24042
+ if (structuralTags.includes(tagName)) {
24043
+ cleanElement(element);
24044
+ }
24045
+ });
24046
+ console.log("[Command] Cleaned HTML:", tempDiv.innerHTML);
24047
+ range2.deleteContents();
24048
+ const cleanedFragment = doc.createDocumentFragment();
24049
+ while (tempDiv.firstChild) {
24050
+ cleanedFragment.appendChild(tempDiv.firstChild);
24051
+ }
24052
+ range2.insertNode(cleanedFragment);
24053
+ range2.collapse(false);
24054
+ selection.removeAllRanges();
24055
+ selection.addRange(range2);
24056
+ state22.content = doc.body.innerHTML;
24057
+ console.log("[Command] Clear formatting completed");
24058
+ } catch (error) {
24059
+ console.error("[Command] Error in clear formatting:", error);
24060
+ }
23777
24061
  }),
23778
24062
  indent: createCommand("Indent", () => {
23779
24063
  format2.text("indent");
@@ -23820,9 +24104,14 @@ function useCommands(state2, debug) {
23820
24104
  const executor = createCommandExecutor(state2, commands);
23821
24105
  return {
23822
24106
  execute: (command, value) => {
23823
- if (!state2.doc) return;
24107
+ console.log(`[useCommands] Executing command: ${command}`, value ? `with value: ${value}` : "");
24108
+ if (!state2.doc) {
24109
+ console.log("[useCommands] No document available, skipping command");
24110
+ return;
24111
+ }
23824
24112
  debug == null ? void 0 : debug.logCommand(command, value);
23825
24113
  if (["splitView", "codeView", "fullScreen"].includes(command)) {
24114
+ console.log(`[useCommands] Handling view state command: ${command}`);
23826
24115
  switch (command) {
23827
24116
  case "splitView":
23828
24117
  state2.isSplitView = !state2.isSplitView;
@@ -23835,16 +24124,29 @@ function useCommands(state2, debug) {
23835
24124
  return;
23836
24125
  }
23837
24126
  }
23838
- state2.doc.body.focus();
23839
- executor.execute(command, value);
24127
+ try {
24128
+ state2.doc.body.focus();
24129
+ console.log("[useCommands] Editor focused");
24130
+ } catch (e) {
24131
+ console.error("[useCommands] Error focusing editor:", e);
24132
+ }
24133
+ try {
24134
+ console.log("[useCommands] Executing command via executor");
24135
+ executor.execute(command, value);
24136
+ console.log("[useCommands] Command execution completed");
24137
+ } catch (e) {
24138
+ console.error("[useCommands] Error during command execution:", e);
24139
+ }
23840
24140
  const newContent = state2.doc.body.innerHTML;
23841
24141
  if (newContent !== state2.content) {
24142
+ console.log("[useCommands] Content changed, updating state");
23842
24143
  state2.content = newContent;
23843
24144
  }
23844
24145
  const selection = state2.doc.getSelection();
23845
24146
  if (selection == null ? void 0 : selection.rangeCount) {
23846
24147
  const hasSelectionChanged = !state2.selection || state2.selection !== selection || state2.rangeCount !== selection.rangeCount;
23847
24148
  if (hasSelectionChanged) {
24149
+ console.log("[useCommands] Selection changed, updating state");
23848
24150
  state2.selection = selection;
23849
24151
  state2.range = selection.getRangeAt(0).cloneRange();
23850
24152
  state2.rangeCount = selection.rangeCount;