@bagelink/vue 1.2.13 → 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/components/form/FieldArray.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/components/EditorToolbar.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/components/gridBox.vue.d.ts +6 -3
- package/dist/components/form/inputs/RichText/components/gridBox.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/composables/useCommands.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/config.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/commands.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/formatting.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/table.d.ts.map +1 -1
- package/dist/index.cjs +355 -56
- package/dist/index.mjs +355 -56
- package/dist/style.css +3 -3
- package/package.json +1 -1
- package/src/components/form/FieldArray.vue +1 -1
- package/src/components/form/inputs/RichText/components/EditorToolbar.vue +3 -4
- package/src/components/form/inputs/RichText/components/gridBox.vue +4 -1
- package/src/components/form/inputs/RichText/composables/useCommands.ts +22 -3
- package/src/components/form/inputs/RichText/config.ts +9 -7
- package/src/components/form/inputs/RichText/utils/commands.ts +307 -23
- package/src/components/form/inputs/RichText/utils/formatting.ts +117 -17
- package/src/components/form/inputs/RichText/utils/table.ts +36 -1
package/dist/index.cjs
CHANGED
|
@@ -16078,14 +16078,13 @@ const _sfc_main$R = /* @__PURE__ */ vue.defineComponent({
|
|
|
16078
16078
|
return resolvedSchemaData.value.length > 2 || resolvedSchemaData.value.some((schema) => schema.$el === "richtext");
|
|
16079
16079
|
});
|
|
16080
16080
|
return (_ctx, _cache) => {
|
|
16081
|
-
const _component_Icon = vue.resolveComponent("Icon");
|
|
16082
16081
|
return vue.openBlock(), vue.createElementBlock("div", {
|
|
16083
16082
|
class: vue.normalizeClass(props2.class)
|
|
16084
16083
|
}, [
|
|
16085
16084
|
_ctx.label ? (vue.openBlock(), vue.createElementBlock("p", _hoisted_1$K, vue.toDisplayString(_ctx.label), 1)) : vue.createCommentVNode("", true),
|
|
16086
16085
|
vue.createElementVNode("div", _hoisted_2$x, [
|
|
16087
16086
|
schemaState.value !== "loaded" ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_3$t, [
|
|
16088
|
-
schemaState.value === "loading" ? (vue.openBlock(), vue.createBlock(vue.unref(Loading), { key: 0 })) : schemaState.value === "error" ? (vue.openBlock(), vue.createBlock(
|
|
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), {
|
|
16089
16088
|
key: 1,
|
|
16090
16089
|
icon: "error",
|
|
16091
16090
|
color: "red"
|
|
@@ -23008,13 +23007,15 @@ const toolbarOptions = [
|
|
|
23008
23007
|
{ name: "fontColor", label: "Font Color", icon: "format_color_text" },
|
|
23009
23008
|
{ name: "bgColor", label: "Background Color", icon: "format_color_fill" },
|
|
23010
23009
|
{ name: "insertTable", label: "Insert Table", icon: "table" },
|
|
23011
|
-
{ name: "deleteTable", label: "Delete Table", icon: "
|
|
23012
|
-
{ name: "
|
|
23013
|
-
{ name: "
|
|
23014
|
-
{ name: "
|
|
23015
|
-
{ name: "
|
|
23016
|
-
{ name: "
|
|
23017
|
-
{ name: "
|
|
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" },
|
|
23018
23019
|
{ name: "separator" },
|
|
23019
23020
|
{ name: "undo", label: "Undo", icon: "undo" },
|
|
23020
23021
|
{ name: "redo", label: "Redo", icon: "redo" },
|
|
@@ -23025,12 +23026,16 @@ const _hoisted_1$u = { class: "grid grid-wrap p-05" };
|
|
|
23025
23026
|
const _hoisted_2$j = ["onMousemove", "onClick"];
|
|
23026
23027
|
const _hoisted_3$g = { class: "txt-center txt-12 color-gray" };
|
|
23027
23028
|
const fb = 1;
|
|
23028
|
-
const base = 5;
|
|
23029
23029
|
const _sfc_main$B = /* @__PURE__ */ vue.defineComponent({
|
|
23030
23030
|
__name: "gridBox",
|
|
23031
|
+
props: {
|
|
23032
|
+
gridSize: {}
|
|
23033
|
+
},
|
|
23031
23034
|
emits: ["select"],
|
|
23032
23035
|
setup(__props, { emit: __emit }) {
|
|
23036
|
+
const props2 = __props;
|
|
23033
23037
|
const emit2 = __emit;
|
|
23038
|
+
const base = props2.gridSize || 5;
|
|
23034
23039
|
const hoveredRow = vue.ref(fb);
|
|
23035
23040
|
const hoveredCol = vue.ref(fb);
|
|
23036
23041
|
const rowSize = vue.computed(() => {
|
|
@@ -23078,7 +23083,7 @@ const _sfc_main$B = /* @__PURE__ */ vue.defineComponent({
|
|
|
23078
23083
|
};
|
|
23079
23084
|
}
|
|
23080
23085
|
});
|
|
23081
|
-
const GridBox = /* @__PURE__ */ _export_sfc(_sfc_main$B, [["__scopeId", "data-v-
|
|
23086
|
+
const GridBox = /* @__PURE__ */ _export_sfc(_sfc_main$B, [["__scopeId", "data-v-2f424c9c"]]);
|
|
23082
23087
|
const _hoisted_1$t = {
|
|
23083
23088
|
class: "toolbar flex gap-025 pb-05 flex-wrap",
|
|
23084
23089
|
role: "toolbar"
|
|
@@ -23111,10 +23116,8 @@ const _sfc_main$A = /* @__PURE__ */ vue.defineComponent({
|
|
|
23111
23116
|
default: vue.withCtx(({ hide }) => [
|
|
23112
23117
|
vue.createVNode(GridBox, {
|
|
23113
23118
|
gridSize: 5,
|
|
23114
|
-
onSelect: (
|
|
23115
|
-
|
|
23116
|
-
runAction("insertTable", $event);
|
|
23117
|
-
(_a = $event.target) == null ? void 0 : _a.blur();
|
|
23119
|
+
onSelect: (value) => {
|
|
23120
|
+
runAction("insertTable", value);
|
|
23118
23121
|
hide();
|
|
23119
23122
|
}
|
|
23120
23123
|
}, null, 8, ["onSelect"])
|
|
@@ -23141,7 +23144,7 @@ const _sfc_main$A = /* @__PURE__ */ vue.defineComponent({
|
|
|
23141
23144
|
};
|
|
23142
23145
|
}
|
|
23143
23146
|
});
|
|
23144
|
-
const EditorToolbar = /* @__PURE__ */ _export_sfc(_sfc_main$A, [["__scopeId", "data-v-
|
|
23147
|
+
const EditorToolbar = /* @__PURE__ */ _export_sfc(_sfc_main$A, [["__scopeId", "data-v-7e9466dc"]]);
|
|
23145
23148
|
function isStyleActive(style, doc) {
|
|
23146
23149
|
const selection = doc.getSelection();
|
|
23147
23150
|
if (!selection || !selection.rangeCount) return false;
|
|
@@ -23261,11 +23264,22 @@ function formatting(state2) {
|
|
|
23261
23264
|
range2.surroundContents(span);
|
|
23262
23265
|
}
|
|
23263
23266
|
} else {
|
|
23264
|
-
|
|
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
|
+
}
|
|
23265
23279
|
}
|
|
23266
23280
|
};
|
|
23267
23281
|
const block = (command, tag) => {
|
|
23268
|
-
var _a
|
|
23282
|
+
var _a;
|
|
23269
23283
|
const selection = doc.getSelection();
|
|
23270
23284
|
if (!selection || !selection.rangeCount) return;
|
|
23271
23285
|
const range2 = selection.getRangeAt(0);
|
|
@@ -23282,10 +23296,18 @@ function formatting(state2) {
|
|
|
23282
23296
|
wrapper.remove();
|
|
23283
23297
|
}
|
|
23284
23298
|
}
|
|
23285
|
-
doc.
|
|
23286
|
-
if (isRTL)
|
|
23287
|
-
|
|
23288
|
-
|
|
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);
|
|
23289
23311
|
}
|
|
23290
23312
|
};
|
|
23291
23313
|
const list = (command) => {
|
|
@@ -23350,13 +23372,34 @@ function formatting(state2) {
|
|
|
23350
23372
|
restoreSelection(state2.doc, state2.range, state2.selection, selectionInfo, listEl);
|
|
23351
23373
|
};
|
|
23352
23374
|
const clear = () => {
|
|
23353
|
-
|
|
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
|
+
}
|
|
23354
23384
|
const selectionInfo = analyzeSelection(state2.doc, state2.range);
|
|
23355
|
-
|
|
23356
|
-
|
|
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
|
+
});
|
|
23357
23399
|
const fragment = state2.range.cloneContents();
|
|
23358
23400
|
const tempDiv = state2.doc.createElement("div");
|
|
23359
23401
|
tempDiv.appendChild(fragment);
|
|
23402
|
+
console.log("[Clear Format] Original HTML:", tempDiv.innerHTML);
|
|
23360
23403
|
const cleanNode = (node) => {
|
|
23361
23404
|
if (!state2.doc) return node;
|
|
23362
23405
|
if (node.nodeType === 3) {
|
|
@@ -23365,12 +23408,36 @@ function formatting(state2) {
|
|
|
23365
23408
|
if (node.nodeType === 1) {
|
|
23366
23409
|
const el = node;
|
|
23367
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
|
+
});
|
|
23368
23417
|
if (inlineTags.includes(nodeName)) {
|
|
23369
|
-
|
|
23418
|
+
const textContent = el.textContent || "";
|
|
23419
|
+
console.log("[Clear Format] Extracting text from inline element:", textContent);
|
|
23420
|
+
return state2.doc.createTextNode(textContent);
|
|
23370
23421
|
}
|
|
23371
23422
|
const newEl = state2.doc.createElement(nodeName);
|
|
23372
|
-
|
|
23373
|
-
|
|
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
|
+
}
|
|
23374
23441
|
Array.from(el.childNodes).forEach((child) => {
|
|
23375
23442
|
newEl.appendChild(cleanNode(child));
|
|
23376
23443
|
});
|
|
@@ -23382,9 +23449,14 @@ function formatting(state2) {
|
|
|
23382
23449
|
Array.from(tempDiv.childNodes).forEach((node) => {
|
|
23383
23450
|
cleanedFragment.appendChild(cleanNode(node));
|
|
23384
23451
|
});
|
|
23452
|
+
const debugDiv = state2.doc.createElement("div");
|
|
23453
|
+
debugDiv.appendChild(cleanedFragment.cloneNode(true));
|
|
23454
|
+
console.log("[Clear Format] Cleaned HTML:", debugDiv.innerHTML);
|
|
23385
23455
|
state2.range.deleteContents();
|
|
23386
23456
|
state2.range.insertNode(cleanedFragment);
|
|
23387
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);
|
|
23388
23460
|
};
|
|
23389
23461
|
return { text, block, list, clear };
|
|
23390
23462
|
}
|
|
@@ -23497,16 +23569,44 @@ function insertTable(rows, cols, state2) {
|
|
|
23497
23569
|
const table = state2.doc.createElement("table");
|
|
23498
23570
|
table.style.width = "100%";
|
|
23499
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");
|
|
23500
23585
|
for (let i2 = 0; i2 < rows; i2++) {
|
|
23501
|
-
const row =
|
|
23586
|
+
const row = tbody.insertRow();
|
|
23502
23587
|
for (let j = 0; j < cols; j++) {
|
|
23503
23588
|
const cell = row.insertCell();
|
|
23504
23589
|
cell.innerHTML = " ";
|
|
23590
|
+
cell.style.padding = "8px";
|
|
23591
|
+
cell.style.border = "1px solid var(--border-color, #ddd)";
|
|
23505
23592
|
}
|
|
23506
23593
|
}
|
|
23594
|
+
table.appendChild(tbody);
|
|
23507
23595
|
const { range: range2 } = state2;
|
|
23508
23596
|
if (range2) {
|
|
23509
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
|
+
}
|
|
23510
23610
|
} else {
|
|
23511
23611
|
state2.doc.body.appendChild(table);
|
|
23512
23612
|
}
|
|
@@ -23667,12 +23767,9 @@ function createFormattingCommand(state2, type3, command, tag) {
|
|
|
23667
23767
|
var _a, _b;
|
|
23668
23768
|
if (!state2.doc) return;
|
|
23669
23769
|
if (type3 === "text") {
|
|
23670
|
-
|
|
23671
|
-
else if (command === "italic") state2.doc.execCommand("italic", false);
|
|
23672
|
-
else if (command === "underline") state2.doc.execCommand("underline", false);
|
|
23673
|
-
else format2.text(command);
|
|
23770
|
+
format2.text(command);
|
|
23674
23771
|
} else if (type3 === "block") {
|
|
23675
|
-
|
|
23772
|
+
format2.block(command, command);
|
|
23676
23773
|
} else if (type3 === "list") {
|
|
23677
23774
|
const selection = state2.doc.getSelection();
|
|
23678
23775
|
if (!selection || !selection.rangeCount) return;
|
|
@@ -23693,10 +23790,7 @@ function createFormattingCommand(state2, type3, command, tag) {
|
|
|
23693
23790
|
selection.removeAllRanges();
|
|
23694
23791
|
selection.addRange(range2);
|
|
23695
23792
|
} else {
|
|
23696
|
-
|
|
23697
|
-
command === "orderedList" ? "insertOrderedList" : "insertUnorderedList",
|
|
23698
|
-
false
|
|
23699
|
-
);
|
|
23793
|
+
format2.list(command);
|
|
23700
23794
|
}
|
|
23701
23795
|
}
|
|
23702
23796
|
},
|
|
@@ -23705,34 +23799,167 @@ function createFormattingCommand(state2, type3, command, tag) {
|
|
|
23705
23799
|
}
|
|
23706
23800
|
function isNodeEmpty$1(node) {
|
|
23707
23801
|
var _a;
|
|
23708
|
-
const text = ((_a = node.textContent) == null ? void 0 : _a.
|
|
23802
|
+
const text = ((_a = node.textContent) == null ? void 0 : _a.replace(/\s/g, "")) || "";
|
|
23709
23803
|
if (text) return false;
|
|
23710
|
-
const brElements = node.getElementsByTagName("br");
|
|
23804
|
+
const brElements = node.getElementsByTagName ? node.getElementsByTagName("br") : [];
|
|
23711
23805
|
if (brElements.length === 0) return true;
|
|
23712
|
-
return brElements.length === 1 && node.childNodes.length
|
|
23806
|
+
return brElements.length === 1 && node.childNodes.length <= 2;
|
|
23713
23807
|
}
|
|
23714
23808
|
function createCommandRegistry(state2) {
|
|
23715
23809
|
const format2 = formatting(state2);
|
|
23716
23810
|
const historyCommands = {
|
|
23717
23811
|
undo: createCommand("Undo", () => {
|
|
23718
|
-
|
|
23719
|
-
|
|
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
|
+
}
|
|
23720
23820
|
}),
|
|
23721
23821
|
redo: createCommand("Redo", () => {
|
|
23722
|
-
|
|
23723
|
-
|
|
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
|
+
}
|
|
23724
23901
|
})
|
|
23725
23902
|
};
|
|
23726
|
-
const textCommands = ["bold", "italic", "underline"].reduce((acc, cmd) => ({
|
|
23727
|
-
...acc,
|
|
23728
|
-
[cmd]: createFormattingCommand(state2, "text", cmd)
|
|
23729
|
-
}), {});
|
|
23730
23903
|
const headingCommands = ["h1", "h2", "h3", "h4", "h5", "h6"].reduce((acc, cmd) => ({
|
|
23731
23904
|
...acc,
|
|
23732
|
-
[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
|
+
})
|
|
23733
23932
|
}), {});
|
|
23734
23933
|
const blockCommands = {
|
|
23735
|
-
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
|
+
}),
|
|
23736
23963
|
blockquote: createFormattingCommand(state2, "block", "blockquote")
|
|
23737
23964
|
};
|
|
23738
23965
|
const listCommands = {
|
|
@@ -23775,8 +24002,62 @@ function createCommandRegistry(state2) {
|
|
|
23775
24002
|
embed: createCommand("Insert Embed", (state22) => state22.modal && insertEmbed(state22.modal, state22))
|
|
23776
24003
|
};
|
|
23777
24004
|
const otherCommands = {
|
|
23778
|
-
clear: createCommand("Clear Formatting", () => {
|
|
23779
|
-
|
|
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
|
+
}
|
|
23780
24061
|
}),
|
|
23781
24062
|
indent: createCommand("Indent", () => {
|
|
23782
24063
|
format2.text("indent");
|
|
@@ -23823,9 +24104,14 @@ function useCommands(state2, debug) {
|
|
|
23823
24104
|
const executor = createCommandExecutor(state2, commands);
|
|
23824
24105
|
return {
|
|
23825
24106
|
execute: (command, value) => {
|
|
23826
|
-
|
|
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
|
+
}
|
|
23827
24112
|
debug == null ? void 0 : debug.logCommand(command, value);
|
|
23828
24113
|
if (["splitView", "codeView", "fullScreen"].includes(command)) {
|
|
24114
|
+
console.log(`[useCommands] Handling view state command: ${command}`);
|
|
23829
24115
|
switch (command) {
|
|
23830
24116
|
case "splitView":
|
|
23831
24117
|
state2.isSplitView = !state2.isSplitView;
|
|
@@ -23838,16 +24124,29 @@ function useCommands(state2, debug) {
|
|
|
23838
24124
|
return;
|
|
23839
24125
|
}
|
|
23840
24126
|
}
|
|
23841
|
-
|
|
23842
|
-
|
|
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
|
+
}
|
|
23843
24140
|
const newContent = state2.doc.body.innerHTML;
|
|
23844
24141
|
if (newContent !== state2.content) {
|
|
24142
|
+
console.log("[useCommands] Content changed, updating state");
|
|
23845
24143
|
state2.content = newContent;
|
|
23846
24144
|
}
|
|
23847
24145
|
const selection = state2.doc.getSelection();
|
|
23848
24146
|
if (selection == null ? void 0 : selection.rangeCount) {
|
|
23849
24147
|
const hasSelectionChanged = !state2.selection || state2.selection !== selection || state2.rangeCount !== selection.rangeCount;
|
|
23850
24148
|
if (hasSelectionChanged) {
|
|
24149
|
+
console.log("[useCommands] Selection changed, updating state");
|
|
23851
24150
|
state2.selection = selection;
|
|
23852
24151
|
state2.range = selection.getRangeAt(0).cloneRange();
|
|
23853
24152
|
state2.rangeCount = selection.rangeCount;
|