@milkdown/preset-gfm 7.15.4 → 7.16.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/index.js +11 -309
- package/lib/index.js.map +1 -1
- package/lib/node/table/command.d.ts.map +1 -1
- package/lib/node/table/utils/get-all-cells-in-table.d.ts.map +1 -1
- package/lib/node/table/utils/get-cells-in-col.d.ts.map +1 -1
- package/lib/node/table/utils/get-cells-in-row.d.ts.map +1 -1
- package/lib/node/table/utils/index.d.ts +0 -3
- package/lib/node/table/utils/index.d.ts.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -9
- package/src/node/table/command.ts +12 -36
- package/src/node/table/utils/get-all-cells-in-table.ts +1 -3
- package/src/node/table/utils/get-cells-in-col.ts +1 -3
- package/src/node/table/utils/get-cells-in-row.ts +1 -3
- package/src/node/table/utils/index.ts +0 -3
- package/lib/node/table/utils/convert-rows-to-table.d.ts +0 -3
- package/lib/node/table/utils/convert-rows-to-table.d.ts.map +0 -1
- package/lib/node/table/utils/convert-table-to-rows.d.ts +0 -3
- package/lib/node/table/utils/convert-table-to-rows.d.ts.map +0 -1
- package/lib/node/table/utils/find-table.d.ts +0 -3
- package/lib/node/table/utils/find-table.d.ts.map +0 -1
- package/lib/node/table/utils/get-selection-range-in-col.d.ts +0 -4
- package/lib/node/table/utils/get-selection-range-in-col.d.ts.map +0 -1
- package/lib/node/table/utils/get-selection-range-in-row.d.ts +0 -4
- package/lib/node/table/utils/get-selection-range-in-row.d.ts.map +0 -1
- package/lib/node/table/utils/move-col.d.ts +0 -10
- package/lib/node/table/utils/move-col.d.ts.map +0 -1
- package/lib/node/table/utils/move-row-in-array-of-rows.d.ts +0 -3
- package/lib/node/table/utils/move-row-in-array-of-rows.d.ts.map +0 -1
- package/lib/node/table/utils/move-row.d.ts +0 -10
- package/lib/node/table/utils/move-row.d.ts.map +0 -1
- package/lib/node/table/utils/transpose.d.ts +0 -2
- package/lib/node/table/utils/transpose.d.ts.map +0 -1
- package/src/node/table/utils/convert-rows-to-table.ts +0 -43
- package/src/node/table/utils/convert-table-to-rows.ts +0 -65
- package/src/node/table/utils/find-table.ts +0 -10
- package/src/node/table/utils/get-selection-range-in-col.ts +0 -86
- package/src/node/table/utils/get-selection-range-in-row.ts +0 -86
- package/src/node/table/utils/move-col.ts +0 -73
- package/src/node/table/utils/move-row-in-array-of-rows.ts +0 -29
- package/src/node/table/utils/move-row.ts +0 -71
- package/src/node/table/utils/transpose.ts +0 -26
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Node } from '@milkdown/prose/model'
|
|
2
|
-
import type { Transaction } from '@milkdown/prose/state'
|
|
3
|
-
|
|
4
|
-
import { CellSelection, TableMap } from '@milkdown/prose/tables'
|
|
5
|
-
|
|
6
|
-
import { convertRowsToTable } from './convert-rows-to-table'
|
|
7
|
-
import { convertTableToRows } from './convert-table-to-rows'
|
|
8
|
-
import { findTable } from './find-table'
|
|
9
|
-
import { getSelectionRangeInRow } from './get-selection-range-in-row'
|
|
10
|
-
import { moveRowInArrayOfRows } from './move-row-in-array-of-rows'
|
|
11
|
-
|
|
12
|
-
export interface MoveRowParams {
|
|
13
|
-
tr: Transaction
|
|
14
|
-
origin: number
|
|
15
|
-
target: number
|
|
16
|
-
pos: number
|
|
17
|
-
select?: boolean
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/// If the selection is in a table,
|
|
21
|
-
/// Move the rows at `origin` and `target` in current table.
|
|
22
|
-
/// The `select` is true by default, which means the selection will be set to the moved row.
|
|
23
|
-
export function moveRow(moveRowParams: MoveRowParams) {
|
|
24
|
-
const { tr, origin, target, select, pos } = moveRowParams
|
|
25
|
-
const $pos = tr.doc.resolve(pos)
|
|
26
|
-
const table = findTable($pos)
|
|
27
|
-
if (!table) return false
|
|
28
|
-
|
|
29
|
-
const indexesOriginRow = getSelectionRangeInRow(tr, origin)?.indexes
|
|
30
|
-
const indexesTargetRow = getSelectionRangeInRow(tr, target)?.indexes
|
|
31
|
-
|
|
32
|
-
if (!indexesOriginRow || !indexesTargetRow) return false
|
|
33
|
-
|
|
34
|
-
if (indexesOriginRow.includes(target)) return false
|
|
35
|
-
|
|
36
|
-
const newTable = moveTableRow(
|
|
37
|
-
table.node,
|
|
38
|
-
indexesOriginRow,
|
|
39
|
-
indexesTargetRow,
|
|
40
|
-
0
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
tr.replaceWith(table.pos, table.pos + table.node.nodeSize, newTable)
|
|
44
|
-
|
|
45
|
-
if (!select) return true
|
|
46
|
-
|
|
47
|
-
const map = TableMap.get(newTable)
|
|
48
|
-
const start = table.start
|
|
49
|
-
const index = target
|
|
50
|
-
const lastCell = map.positionAt(index, map.width - 1, newTable)
|
|
51
|
-
const $lastCell = tr.doc.resolve(start + lastCell)
|
|
52
|
-
|
|
53
|
-
const firstCell = map.positionAt(index, 0, newTable)
|
|
54
|
-
const $firstCell = tr.doc.resolve(start + firstCell)
|
|
55
|
-
|
|
56
|
-
tr.setSelection(CellSelection.rowSelection($lastCell, $firstCell))
|
|
57
|
-
return true
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function moveTableRow(
|
|
61
|
-
table: Node,
|
|
62
|
-
indexesOrigin: number[],
|
|
63
|
-
indexesTarget: number[],
|
|
64
|
-
direction: -1 | 1 | 0
|
|
65
|
-
) {
|
|
66
|
-
let rows = convertTableToRows(table)
|
|
67
|
-
|
|
68
|
-
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction)
|
|
69
|
-
|
|
70
|
-
return convertRowsToTable(table, rows)
|
|
71
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/// @internal
|
|
2
|
-
///
|
|
3
|
-
/// Transposes a 2D array by flipping columns to rows.
|
|
4
|
-
///
|
|
5
|
-
/// Transposition is a familiar algebra concept where the matrix is flipped
|
|
6
|
-
/// along its diagonal. For more details, see:
|
|
7
|
-
/// https://en.wikipedia.org/wiki/Transpose
|
|
8
|
-
///
|
|
9
|
-
/// ```typescript
|
|
10
|
-
/// const arr = [
|
|
11
|
-
/// ['a1', 'a2', 'a3'],
|
|
12
|
-
/// ['b1', 'b2', 'b3'],
|
|
13
|
-
/// ['c1', 'c2', 'c3'],
|
|
14
|
-
/// ['d1', 'd2', 'd3'],
|
|
15
|
-
/// ];
|
|
16
|
-
///
|
|
17
|
-
/// const result = transpose(arr);
|
|
18
|
-
/// result === [
|
|
19
|
-
/// ['a1', 'b1', 'c1', 'd1'],
|
|
20
|
-
/// ['a2', 'b2', 'c2', 'd2'],
|
|
21
|
-
/// ['a3', 'b3', 'c3', 'd3'],
|
|
22
|
-
/// ]
|
|
23
|
-
/// ```
|
|
24
|
-
export function transpose<T>(array: T[][]) {
|
|
25
|
-
return array[0]!.map((_, i) => array.map((column) => column[i])) as T[][]
|
|
26
|
-
}
|