@jvs-milkdown/components 1.1.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/table-block/index.js
CHANGED
|
@@ -556,6 +556,7 @@ function useOperation(refs, ctx, getPos) {
|
|
|
556
556
|
const deleteSelected = (e) => {
|
|
557
557
|
if (!ctx) return;
|
|
558
558
|
if (!ctx.get(editorViewCtx).editable) return;
|
|
559
|
+
if (e.button !== 0) return;
|
|
559
560
|
e.preventDefault();
|
|
560
561
|
e.stopPropagation();
|
|
561
562
|
const commands = ctx.get(commandsCtx);
|
|
@@ -567,6 +568,7 @@ function useOperation(refs, ctx, getPos) {
|
|
|
567
568
|
const onAlign = (direction) => (e) => {
|
|
568
569
|
if (!ctx) return;
|
|
569
570
|
if (!ctx.get(editorViewCtx).editable) return;
|
|
571
|
+
if (e.button !== 0) return;
|
|
570
572
|
e.preventDefault();
|
|
571
573
|
e.stopPropagation();
|
|
572
574
|
const commands = ctx.get(commandsCtx);
|
|
@@ -578,6 +580,7 @@ function useOperation(refs, ctx, getPos) {
|
|
|
578
580
|
const onMergeCells = (e) => {
|
|
579
581
|
if (!ctx) return;
|
|
580
582
|
if (!ctx.get(editorViewCtx).editable) return;
|
|
583
|
+
if (e.button !== 0) return;
|
|
581
584
|
e.preventDefault();
|
|
582
585
|
e.stopPropagation();
|
|
583
586
|
const commands = ctx.get(commandsCtx);
|
|
@@ -590,6 +593,7 @@ function useOperation(refs, ctx, getPos) {
|
|
|
590
593
|
var _a, _b;
|
|
591
594
|
if (!ctx) return;
|
|
592
595
|
if (!ctx.get(editorViewCtx).editable) return;
|
|
596
|
+
if (e.button !== 0) return;
|
|
593
597
|
e.preventDefault();
|
|
594
598
|
e.stopPropagation();
|
|
595
599
|
const view = ctx.get(editorViewCtx);
|
|
@@ -728,22 +732,60 @@ const TableBlock = defineComponent({
|
|
|
728
732
|
const xLineHandleRef = ref();
|
|
729
733
|
const resizingCol = ref(-1);
|
|
730
734
|
const colWidths = ref([]);
|
|
735
|
+
const getColCount = () => {
|
|
736
|
+
let maxCols = 0;
|
|
737
|
+
node.value.forEach((row) => {
|
|
738
|
+
let cols = 0;
|
|
739
|
+
row.forEach((cell) => {
|
|
740
|
+
cols += cell.attrs.colspan || 1;
|
|
741
|
+
});
|
|
742
|
+
if (cols > maxCols) maxCols = cols;
|
|
743
|
+
});
|
|
744
|
+
return maxCols;
|
|
745
|
+
};
|
|
731
746
|
const syncColWidths = () => {
|
|
732
747
|
if (resizingCol.value >= 0) return;
|
|
733
|
-
const
|
|
734
|
-
if (!firstRow) return;
|
|
735
|
-
const colCount = firstRow.content.childCount;
|
|
748
|
+
const colCount = getColCount();
|
|
736
749
|
const widths = [];
|
|
737
750
|
const hasBounds = colBounds.value.length === colCount;
|
|
738
751
|
for (let i = 0; i < colCount; i++) {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
752
|
+
let found = false;
|
|
753
|
+
node.value.forEach((row) => {
|
|
754
|
+
if (found) return;
|
|
755
|
+
let colIdx = 0;
|
|
756
|
+
row.forEach((cell) => {
|
|
757
|
+
if (found) return;
|
|
758
|
+
const colspan = cell.attrs.colspan || 1;
|
|
759
|
+
const colwidth = cell.attrs.colwidth;
|
|
760
|
+
if (colIdx === i) {
|
|
761
|
+
if (colspan > 1) {
|
|
762
|
+
if (Array.isArray(colwidth) && colwidth.length > 0) {
|
|
763
|
+
const totalW = colwidth.reduce(
|
|
764
|
+
(sum, w) => sum + (w || 0),
|
|
765
|
+
0
|
|
766
|
+
);
|
|
767
|
+
widths.push(Math.round(totalW / colspan));
|
|
768
|
+
} else if (hasBounds) {
|
|
769
|
+
widths.push(Math.round(colBounds.value[i].width));
|
|
770
|
+
} else {
|
|
771
|
+
widths.push(0);
|
|
772
|
+
}
|
|
773
|
+
} else {
|
|
774
|
+
if (Array.isArray(colwidth) && colwidth[0]) {
|
|
775
|
+
widths.push(colwidth[0]);
|
|
776
|
+
} else if (hasBounds) {
|
|
777
|
+
widths.push(Math.round(colBounds.value[i].width));
|
|
778
|
+
} else {
|
|
779
|
+
widths.push(0);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
found = true;
|
|
783
|
+
}
|
|
784
|
+
colIdx += colspan;
|
|
785
|
+
});
|
|
786
|
+
});
|
|
787
|
+
if (!found) {
|
|
788
|
+
widths.push(hasBounds ? Math.round(colBounds.value[i].width) : 0);
|
|
747
789
|
}
|
|
748
790
|
}
|
|
749
791
|
colWidths.value = widths;
|
|
@@ -839,15 +881,23 @@ const TableBlock = defineComponent({
|
|
|
839
881
|
const updateBounds = () => {
|
|
840
882
|
const content = contentWrapperRef.value;
|
|
841
883
|
if (!content) return;
|
|
842
|
-
const
|
|
884
|
+
const rows = content.querySelectorAll("tr");
|
|
843
885
|
const tableRect = content.getBoundingClientRect();
|
|
844
|
-
|
|
845
|
-
|
|
886
|
+
const expectedColCount = getColCount();
|
|
887
|
+
let bestRow = null;
|
|
888
|
+
rows.forEach((row) => {
|
|
889
|
+
if (bestRow) return;
|
|
890
|
+
if (row.children.length === expectedColCount) {
|
|
891
|
+
bestRow = row;
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
const measureRow = bestRow != null ? bestRow : content.querySelector("tr");
|
|
895
|
+
if (measureRow) {
|
|
896
|
+
colBounds.value = Array.from(measureRow.children).map((c) => {
|
|
846
897
|
const rect = c.getBoundingClientRect();
|
|
847
898
|
return { left: rect.left - tableRect.left, width: rect.width };
|
|
848
899
|
});
|
|
849
900
|
}
|
|
850
|
-
const rows = content.querySelectorAll("tr");
|
|
851
901
|
rowBounds.value = Array.from(rows).map((c) => {
|
|
852
902
|
const rect = c.getBoundingClientRect();
|
|
853
903
|
return { top: rect.top - tableRect.top, height: rect.height };
|
|
@@ -971,6 +1021,7 @@ const TableBlock = defineComponent({
|
|
|
971
1021
|
});
|
|
972
1022
|
watch(node, () => {
|
|
973
1023
|
dispatchListener();
|
|
1024
|
+
requestAnimationFrame(updateBounds);
|
|
974
1025
|
});
|
|
975
1026
|
onBeforeUnmount(() => {
|
|
976
1027
|
view.dom.removeEventListener("keyup", dispatchListener);
|
|
@@ -1012,7 +1063,7 @@ const TableBlock = defineComponent({
|
|
|
1012
1063
|
contenteditable: "false",
|
|
1013
1064
|
onPointerdown: (e) => e.stopPropagation()
|
|
1014
1065
|
},
|
|
1015
|
-
/* @__PURE__ */ h(
|
|
1066
|
+
canMerge.value ? /* @__PURE__ */ h(
|
|
1016
1067
|
"button",
|
|
1017
1068
|
{
|
|
1018
1069
|
type: "button",
|
|
@@ -1020,8 +1071,7 @@ const TableBlock = defineComponent({
|
|
|
1020
1071
|
onPointerdown: onMergeCells
|
|
1021
1072
|
},
|
|
1022
1073
|
/* @__PURE__ */ h(Icon, { icon: config.renderButton("merge_cells") })
|
|
1023
|
-
)
|
|
1024
|
-
/* @__PURE__ */ h(
|
|
1074
|
+
) : canSplit.value ? /* @__PURE__ */ h(
|
|
1025
1075
|
"button",
|
|
1026
1076
|
{
|
|
1027
1077
|
type: "button",
|
|
@@ -1029,7 +1079,7 @@ const TableBlock = defineComponent({
|
|
|
1029
1079
|
onPointerdown: onSplitCell
|
|
1030
1080
|
},
|
|
1031
1081
|
/* @__PURE__ */ h(Icon, { icon: config.renderButton("split_cell") })
|
|
1032
|
-
)
|
|
1082
|
+
) : void 0
|
|
1033
1083
|
),
|
|
1034
1084
|
/* @__PURE__ */ h("div", { class: "table-wrapper", ref: tableWrapperRef }, /* @__PURE__ */ h("div", { contenteditable: "false", class: "fixed-handles-col" }, colBounds.value.map((bound, i) => /* @__PURE__ */ h(
|
|
1035
1085
|
"div",
|
|
@@ -1060,6 +1110,7 @@ const TableBlock = defineComponent({
|
|
|
1060
1110
|
"data-show": activeColIndex.value === i ? "true" : "false",
|
|
1061
1111
|
onPointermove: (e) => e.stopPropagation()
|
|
1062
1112
|
},
|
|
1113
|
+
canMerge.value ? /* @__PURE__ */ h("button", { type: "button", onPointerdown: onMergeCells }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("merge_cells") })) : canSplit.value ? /* @__PURE__ */ h("button", { type: "button", onPointerdown: onSplitCell }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("split_cell") })) : void 0,
|
|
1063
1114
|
/* @__PURE__ */ h(
|
|
1064
1115
|
"button",
|
|
1065
1116
|
{
|
|
@@ -1103,9 +1154,7 @@ const TableBlock = defineComponent({
|
|
|
1103
1154
|
}
|
|
1104
1155
|
},
|
|
1105
1156
|
/* @__PURE__ */ h(Icon, { icon: config.renderButton("delete_col") })
|
|
1106
|
-
)
|
|
1107
|
-
canMerge.value && /* @__PURE__ */ h("button", { type: "button", onPointerdown: onMergeCells }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("merge_cells") })),
|
|
1108
|
-
canSplit.value && /* @__PURE__ */ h("button", { type: "button", onPointerdown: onSplitCell }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("split_cell") }))
|
|
1157
|
+
)
|
|
1109
1158
|
)
|
|
1110
1159
|
))), /* @__PURE__ */ h("div", { contenteditable: "false", class: "add-dots-col" }, [
|
|
1111
1160
|
...colBounds.value.map((b) => b.left),
|
|
@@ -1161,6 +1210,7 @@ const TableBlock = defineComponent({
|
|
|
1161
1210
|
"data-show": activeRowIndex.value === i ? "true" : "false",
|
|
1162
1211
|
onPointermove: (e) => e.stopPropagation()
|
|
1163
1212
|
},
|
|
1213
|
+
canMerge.value ? /* @__PURE__ */ h("button", { type: "button", onPointerdown: onMergeCells }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("merge_cells") })) : canSplit.value ? /* @__PURE__ */ h("button", { type: "button", onPointerdown: onSplitCell }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("split_cell") })) : void 0,
|
|
1164
1214
|
/* @__PURE__ */ h(
|
|
1165
1215
|
"button",
|
|
1166
1216
|
{
|
|
@@ -1171,9 +1221,7 @@ const TableBlock = defineComponent({
|
|
|
1171
1221
|
}
|
|
1172
1222
|
},
|
|
1173
1223
|
/* @__PURE__ */ h(Icon, { icon: config.renderButton("delete_row") })
|
|
1174
|
-
)
|
|
1175
|
-
canMerge.value && /* @__PURE__ */ h("button", { type: "button", onPointerdown: onMergeCells }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("merge_cells") })),
|
|
1176
|
-
canSplit.value && /* @__PURE__ */ h("button", { type: "button", onPointerdown: onSplitCell }, /* @__PURE__ */ h(Icon, { icon: config.renderButton("split_cell") }))
|
|
1224
|
+
)
|
|
1177
1225
|
)
|
|
1178
1226
|
))), /* @__PURE__ */ h("div", { contenteditable: "false", class: "add-dots-row" }, [
|
|
1179
1227
|
...rowBounds.value.map((b) => b.top),
|