@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jvs-milkdown/components",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "keywords": [
5
5
  "milkdown",
6
6
  "milkdown plugin"
@@ -50,15 +50,15 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@floating-ui/dom": "^1.5.1",
53
- "@jvs-milkdown/core": "^1.2.3",
54
- "@jvs-milkdown/ctx": "^1.2.3",
55
- "@jvs-milkdown/exception": "^1.2.3",
56
- "@jvs-milkdown/plugin-tooltip": "^1.2.3",
57
- "@jvs-milkdown/preset-commonmark": "^1.2.3",
58
- "@jvs-milkdown/preset-gfm": "^1.2.3",
59
- "@jvs-milkdown/prose": "^1.2.3",
60
- "@jvs-milkdown/transformer": "^1.2.3",
61
- "@jvs-milkdown/utils": "^1.2.3",
53
+ "@jvs-milkdown/core": "^1.2.5",
54
+ "@jvs-milkdown/ctx": "^1.2.5",
55
+ "@jvs-milkdown/exception": "^1.2.5",
56
+ "@jvs-milkdown/plugin-tooltip": "^1.2.5",
57
+ "@jvs-milkdown/preset-commonmark": "^1.2.5",
58
+ "@jvs-milkdown/preset-gfm": "^1.2.5",
59
+ "@jvs-milkdown/prose": "^1.2.5",
60
+ "@jvs-milkdown/transformer": "^1.2.5",
61
+ "@jvs-milkdown/utils": "^1.2.5",
62
62
  "@types/lodash-es": "^4.17.12",
63
63
  "clsx": "^2.0.0",
64
64
  "dompurify": "^3.2.5",
@@ -7,6 +7,7 @@ import {
7
7
  CellSelection,
8
8
  mergeCells,
9
9
  splitCell,
10
+ selectedRect,
10
11
  } from '@jvs-milkdown/prose/tables'
11
12
  import {
12
13
  defineComponent,
@@ -195,7 +196,8 @@ export const TableBlock = defineComponent<TableBlockProps>({
195
196
  addColByIndex,
196
197
  selectCol,
197
198
  selectRow,
198
- deleteSelected,
199
+ deleteRowByIndex,
200
+ deleteColByIndex,
199
201
  onAlign,
200
202
  onMergeCells,
201
203
  onSplitCell,
@@ -397,18 +399,34 @@ export const TableBlock = defineComponent<TableBlockProps>({
397
399
 
398
400
  if (isCellSelection(selection)) {
399
401
  const selAny = selection as any
402
+ const rect = selectedRect(view.state)
403
+
400
404
  if (selAny.isColSelection()) {
401
- const $headCell = selAny.$headCell
402
- activeColIndex.value = $headCell
403
- ? $headCell.index($headCell.depth)
404
- : -1
405
+ if (
406
+ activeColIndex.value >= rect.left &&
407
+ activeColIndex.value < rect.right
408
+ ) {
409
+ // Keep current col index if it's within the selection
410
+ } else {
411
+ const $headCell = selAny.$headCell
412
+ activeColIndex.value = $headCell
413
+ ? $headCell.index($headCell.depth)
414
+ : -1
415
+ }
405
416
  activeRowIndex.value = -1
406
417
  } else if (selAny.isRowSelection()) {
407
- const $headCell = selAny.$headCell
418
+ if (
419
+ activeRowIndex.value >= rect.top &&
420
+ activeRowIndex.value < rect.bottom
421
+ ) {
422
+ // Keep current row index if it's within the selection
423
+ } else {
424
+ const $headCell = selAny.$headCell
425
+ activeRowIndex.value = $headCell
426
+ ? $headCell.index($headCell.depth - 1)
427
+ : -1
428
+ }
408
429
  activeColIndex.value = -1
409
- activeRowIndex.value = $headCell
410
- ? $headCell.index($headCell.depth - 1)
411
- : -1
412
430
  } else {
413
431
  activeColIndex.value = -1
414
432
  activeRowIndex.value = -1
@@ -603,9 +621,9 @@ export const TableBlock = defineComponent<TableBlockProps>({
603
621
  </button>
604
622
  <button
605
623
  type="button"
606
- onPointerdown={(e) => {
624
+ onPointerdown={() => {
607
625
  hoverIndex.value = [0, i]
608
- deleteSelected(e)
626
+ deleteColByIndex(i)
609
627
  }}
610
628
  >
611
629
  <Icon icon={config.renderButton('delete_col')} />
@@ -691,9 +709,9 @@ export const TableBlock = defineComponent<TableBlockProps>({
691
709
  ) : undefined}
692
710
  <button
693
711
  type="button"
694
- onPointerdown={(e) => {
712
+ onPointerdown={() => {
695
713
  hoverIndex.value = [i, 0]
696
- deleteSelected(e)
714
+ deleteRowByIndex(i)
697
715
  }}
698
716
  >
699
717
  <Icon icon={config.renderButton('delete_row')} />
@@ -17,6 +17,8 @@ import {
17
17
  TableMap,
18
18
  type TableRect,
19
19
  addColumn,
20
+ removeRow,
21
+ removeColumn,
20
22
  } from '@jvs-milkdown/prose/tables'
21
23
 
22
24
  import type { Refs } from './types'
@@ -116,6 +118,64 @@ export function useOperation(
116
118
  })
117
119
  }
118
120
 
121
+ const deleteRowByIndex = (index: number) => {
122
+ if (!ctx || !ctx.get(editorViewCtx).editable) return
123
+ const view = ctx.get(editorViewCtx)
124
+ const tablePos = getPos?.()
125
+ if (tablePos == null) return
126
+
127
+ const table = view.state.doc.nodeAt(tablePos)
128
+ if (!table) return
129
+
130
+ const tableStart = tablePos + 1
131
+ const map = TableMap.get(table)
132
+ const tr = view.state.tr
133
+ const rect: TableRect = {
134
+ map,
135
+ tableStart,
136
+ table,
137
+ left: 0,
138
+ right: map.width,
139
+ top: 0,
140
+ bottom: map.height,
141
+ }
142
+
143
+ removeRow(tr, rect, index)
144
+ view.dispatch(tr)
145
+ requestAnimationFrame(() => {
146
+ ctx.get(editorViewCtx).focus()
147
+ })
148
+ }
149
+
150
+ const deleteColByIndex = (index: number) => {
151
+ if (!ctx || !ctx.get(editorViewCtx).editable) return
152
+ const view = ctx.get(editorViewCtx)
153
+ const tablePos = getPos?.()
154
+ if (tablePos == null) return
155
+
156
+ const table = view.state.doc.nodeAt(tablePos)
157
+ if (!table) return
158
+
159
+ const tableStart = tablePos + 1
160
+ const map = TableMap.get(table)
161
+ const tr = view.state.tr
162
+ const rect: TableRect = {
163
+ map,
164
+ tableStart,
165
+ table,
166
+ left: 0,
167
+ right: map.width,
168
+ top: 0,
169
+ bottom: map.height,
170
+ }
171
+
172
+ removeColumn(tr, rect, index)
173
+ view.dispatch(tr)
174
+ requestAnimationFrame(() => {
175
+ ctx.get(editorViewCtx).focus()
176
+ })
177
+ }
178
+
119
179
  const onAlign =
120
180
  (direction: 'left' | 'center' | 'right') => (e: PointerEvent) => {
121
181
  if (!ctx) return
@@ -225,6 +285,8 @@ export function useOperation(
225
285
  selectCol,
226
286
  selectRow,
227
287
  deleteSelected,
288
+ deleteRowByIndex,
289
+ deleteColByIndex,
228
290
  onAlign,
229
291
  onMergeCells,
230
292
  onSplitCell,