@jvs-milkdown/components 1.2.3 → 1.2.5
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 +68 -10
- package/lib/table-block/index.js.map +1 -1
- package/lib/table-block/view/component.d.ts.map +1 -1
- package/lib/table-block/view/operation.d.ts +2 -0
- package/lib/table-block/view/operation.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/table-block/view/component.tsx +31 -13
- package/src/table-block/view/operation.ts +62 -0
package/lib/table-block/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { $ctx, $view } from '@jvs-milkdown/utils';
|
|
|
2
2
|
import { selectColCommand, moveColCommand, selectRowCommand, moveRowCommand, mergeCellsCommand, setAlignCommand, deleteSelectedCellsCommand, addRowWithAlignment, tableSchema } from '@jvs-milkdown/preset-gfm';
|
|
3
3
|
import { h, defineComponent, ref, onMounted, watch, onBeforeUnmount, shallowRef, createApp, triggerRef } from 'vue';
|
|
4
4
|
import { computePosition, offset } from '@floating-ui/dom';
|
|
5
|
-
import { findTable, CellSelection, selectedRect, splitCellWithType, TableMap, addColumn, mergeCells, splitCell } from '@jvs-milkdown/prose/tables';
|
|
5
|
+
import { findTable, CellSelection, selectedRect, splitCellWithType, TableMap, removeColumn, removeRow, addColumn, mergeCells, splitCell } from '@jvs-milkdown/prose/tables';
|
|
6
6
|
import clsx from 'clsx';
|
|
7
7
|
import DOMPurify from 'dompurify';
|
|
8
8
|
import { editorViewCtx, commandsCtx } from '@jvs-milkdown/core';
|
|
@@ -577,6 +577,56 @@ function useOperation(refs, ctx, getPos) {
|
|
|
577
577
|
ctx.get(editorViewCtx).focus();
|
|
578
578
|
});
|
|
579
579
|
};
|
|
580
|
+
const deleteRowByIndex = (index) => {
|
|
581
|
+
if (!ctx || !ctx.get(editorViewCtx).editable) return;
|
|
582
|
+
const view = ctx.get(editorViewCtx);
|
|
583
|
+
const tablePos = getPos == null ? void 0 : getPos();
|
|
584
|
+
if (tablePos == null) return;
|
|
585
|
+
const table = view.state.doc.nodeAt(tablePos);
|
|
586
|
+
if (!table) return;
|
|
587
|
+
const tableStart = tablePos + 1;
|
|
588
|
+
const map = TableMap.get(table);
|
|
589
|
+
const tr = view.state.tr;
|
|
590
|
+
const rect = {
|
|
591
|
+
map,
|
|
592
|
+
tableStart,
|
|
593
|
+
table,
|
|
594
|
+
left: 0,
|
|
595
|
+
right: map.width,
|
|
596
|
+
top: 0,
|
|
597
|
+
bottom: map.height
|
|
598
|
+
};
|
|
599
|
+
removeRow(tr, rect, index);
|
|
600
|
+
view.dispatch(tr);
|
|
601
|
+
requestAnimationFrame(() => {
|
|
602
|
+
ctx.get(editorViewCtx).focus();
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
const deleteColByIndex = (index) => {
|
|
606
|
+
if (!ctx || !ctx.get(editorViewCtx).editable) return;
|
|
607
|
+
const view = ctx.get(editorViewCtx);
|
|
608
|
+
const tablePos = getPos == null ? void 0 : getPos();
|
|
609
|
+
if (tablePos == null) return;
|
|
610
|
+
const table = view.state.doc.nodeAt(tablePos);
|
|
611
|
+
if (!table) return;
|
|
612
|
+
const tableStart = tablePos + 1;
|
|
613
|
+
const map = TableMap.get(table);
|
|
614
|
+
const tr = view.state.tr;
|
|
615
|
+
const rect = {
|
|
616
|
+
map,
|
|
617
|
+
tableStart,
|
|
618
|
+
table,
|
|
619
|
+
left: 0,
|
|
620
|
+
right: map.width,
|
|
621
|
+
top: 0,
|
|
622
|
+
bottom: map.height
|
|
623
|
+
};
|
|
624
|
+
removeColumn(tr, rect, index);
|
|
625
|
+
view.dispatch(tr);
|
|
626
|
+
requestAnimationFrame(() => {
|
|
627
|
+
ctx.get(editorViewCtx).focus();
|
|
628
|
+
});
|
|
629
|
+
};
|
|
580
630
|
const onAlign = (direction) => (e) => {
|
|
581
631
|
if (!ctx) return;
|
|
582
632
|
if (!ctx.get(editorViewCtx).editable) return;
|
|
@@ -656,6 +706,8 @@ function useOperation(refs, ctx, getPos) {
|
|
|
656
706
|
selectCol,
|
|
657
707
|
selectRow,
|
|
658
708
|
deleteSelected,
|
|
709
|
+
deleteRowByIndex,
|
|
710
|
+
deleteColByIndex,
|
|
659
711
|
onAlign,
|
|
660
712
|
onMergeCells,
|
|
661
713
|
onSplitCell
|
|
@@ -830,7 +882,8 @@ const TableBlock = defineComponent({
|
|
|
830
882
|
addColByIndex,
|
|
831
883
|
selectCol,
|
|
832
884
|
selectRow,
|
|
833
|
-
|
|
885
|
+
deleteRowByIndex,
|
|
886
|
+
deleteColByIndex,
|
|
834
887
|
onAlign,
|
|
835
888
|
onMergeCells,
|
|
836
889
|
onSplitCell
|
|
@@ -980,14 +1033,19 @@ const TableBlock = defineComponent({
|
|
|
980
1033
|
const isCellSelection = (sel) => sel && typeof sel.isColSelection === "function" && typeof sel.forEachCell === "function";
|
|
981
1034
|
if (isCellSelection(selection)) {
|
|
982
1035
|
const selAny = selection;
|
|
1036
|
+
const rect = selectedRect(view.state);
|
|
983
1037
|
if (selAny.isColSelection()) {
|
|
984
|
-
|
|
985
|
-
|
|
1038
|
+
if (activeColIndex.value >= rect.left && activeColIndex.value < rect.right) ; else {
|
|
1039
|
+
const $headCell = selAny.$headCell;
|
|
1040
|
+
activeColIndex.value = $headCell ? $headCell.index($headCell.depth) : -1;
|
|
1041
|
+
}
|
|
986
1042
|
activeRowIndex.value = -1;
|
|
987
1043
|
} else if (selAny.isRowSelection()) {
|
|
988
|
-
|
|
1044
|
+
if (activeRowIndex.value >= rect.top && activeRowIndex.value < rect.bottom) ; else {
|
|
1045
|
+
const $headCell = selAny.$headCell;
|
|
1046
|
+
activeRowIndex.value = $headCell ? $headCell.index($headCell.depth - 1) : -1;
|
|
1047
|
+
}
|
|
989
1048
|
activeColIndex.value = -1;
|
|
990
|
-
activeRowIndex.value = $headCell ? $headCell.index($headCell.depth - 1) : -1;
|
|
991
1049
|
} else {
|
|
992
1050
|
activeColIndex.value = -1;
|
|
993
1051
|
activeRowIndex.value = -1;
|
|
@@ -1168,9 +1226,9 @@ const TableBlock = defineComponent({
|
|
|
1168
1226
|
"button",
|
|
1169
1227
|
{
|
|
1170
1228
|
type: "button",
|
|
1171
|
-
onPointerdown: (
|
|
1229
|
+
onPointerdown: () => {
|
|
1172
1230
|
hoverIndex.value = [0, i];
|
|
1173
|
-
|
|
1231
|
+
deleteColByIndex(i);
|
|
1174
1232
|
}
|
|
1175
1233
|
},
|
|
1176
1234
|
/* @__PURE__ */ h(Icon, { icon: config.renderButton("delete_col") })
|
|
@@ -1235,9 +1293,9 @@ const TableBlock = defineComponent({
|
|
|
1235
1293
|
"button",
|
|
1236
1294
|
{
|
|
1237
1295
|
type: "button",
|
|
1238
|
-
onPointerdown: (
|
|
1296
|
+
onPointerdown: () => {
|
|
1239
1297
|
hoverIndex.value = [i, 0];
|
|
1240
|
-
|
|
1298
|
+
deleteRowByIndex(i);
|
|
1241
1299
|
}
|
|
1242
1300
|
},
|
|
1243
1301
|
/* @__PURE__ */ h(Icon, { icon: config.renderButton("delete_row") })
|