@milkdown/preset-gfm 6.5.0 → 6.5.3
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/footnote/definition.d.ts +1 -1
- package/lib/footnote/definition.d.ts.map +1 -1
- package/lib/footnote/index.d.ts.map +1 -1
- package/lib/footnote/reference.d.ts +1 -1
- package/lib/footnote/reference.d.ts.map +1 -1
- package/lib/footnote/utils.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +1007 -863
- package/lib/index.es.js.map +1 -1
- package/lib/strike-through.d.ts +1 -1
- package/lib/strike-through.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -1
- package/lib/supported-keys.d.ts.map +1 -1
- package/lib/table/command.d.ts +2 -2
- package/lib/table/command.d.ts.map +1 -1
- package/lib/table/index.d.ts +1 -1
- package/lib/table/index.d.ts.map +1 -1
- package/lib/table/nodes/index.d.ts +1 -1
- package/lib/table/nodes/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/actions.d.ts +5 -5
- package/lib/table/operator-plugin/actions.d.ts.map +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
- package/lib/table/operator-plugin/constant.d.ts.map +1 -1
- package/lib/table/operator-plugin/helper.d.ts +3 -3
- package/lib/table/operator-plugin/helper.d.ts.map +1 -1
- package/lib/table/operator-plugin/index.d.ts +2 -2
- package/lib/table/operator-plugin/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/style.d.ts +1 -1
- package/lib/table/operator-plugin/style.d.ts.map +1 -1
- package/lib/table/operator-plugin/widget.d.ts +2 -2
- package/lib/table/operator-plugin/widget.d.ts.map +1 -1
- package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -1
- package/lib/table/plugin/cell-selection.d.ts +5 -3
- package/lib/table/plugin/cell-selection.d.ts.map +1 -1
- package/lib/table/plugin/column-resizing.d.ts +2 -1
- package/lib/table/plugin/column-resizing.d.ts.map +1 -1
- package/lib/table/plugin/commands.d.ts +2 -2
- package/lib/table/plugin/commands.d.ts.map +1 -1
- package/lib/table/plugin/copy-paste.d.ts +6 -5
- package/lib/table/plugin/copy-paste.d.ts.map +1 -1
- package/lib/table/plugin/fix-tables.d.ts +3 -2
- package/lib/table/plugin/fix-tables.d.ts.map +1 -1
- package/lib/table/plugin/index.d.ts.map +1 -1
- package/lib/table/plugin/schema.d.ts +1 -1
- package/lib/table/plugin/schema.d.ts.map +1 -1
- package/lib/table/plugin/table-editing.d.ts +1 -1
- package/lib/table/plugin/table-editing.d.ts.map +1 -1
- package/lib/table/plugin/table-map.d.ts +2 -2
- package/lib/table/plugin/table-map.d.ts.map +1 -1
- package/lib/table/plugin/table-view.d.ts +2 -2
- package/lib/table/plugin/table-view.d.ts.map +1 -1
- package/lib/table/plugin/types.d.ts +2 -2
- package/lib/table/plugin/types.d.ts.map +1 -1
- package/lib/table/plugin/util.d.ts +2 -2
- package/lib/table/plugin/util.d.ts.map +1 -1
- package/lib/table/utils.d.ts +5 -5
- package/lib/table/utils.d.ts.map +1 -1
- package/lib/task-list-item.d.ts +2 -2
- package/lib/task-list-item.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/footnote/definition.ts +172 -166
- package/src/footnote/index.ts +2 -2
- package/src/footnote/reference.ts +166 -162
- package/src/footnote/utils.ts +2 -2
- package/src/index.ts +83 -83
- package/src/strike-through.ts +36 -36
- package/src/supported-keys.ts +9 -8
- package/src/table/command.ts +17 -16
- package/src/table/index.ts +9 -9
- package/src/table/nodes/index.ts +177 -174
- package/src/table/operator-plugin/actions.ts +103 -102
- package/src/table/operator-plugin/calc-pos.ts +31 -24
- package/src/table/operator-plugin/constant.ts +3 -3
- package/src/table/operator-plugin/helper.ts +31 -32
- package/src/table/operator-plugin/index.ts +104 -95
- package/src/table/operator-plugin/style.ts +10 -9
- package/src/table/operator-plugin/widget.ts +47 -45
- package/src/table/plugin/auto-insert-zero-space.ts +41 -41
- package/src/table/plugin/cell-selection.ts +325 -296
- package/src/table/plugin/column-resizing.ts +226 -198
- package/src/table/plugin/commands.ts +464 -421
- package/src/table/plugin/copy-paste.ts +256 -240
- package/src/table/plugin/fix-tables.ts +103 -88
- package/src/table/plugin/index.ts +3 -3
- package/src/table/plugin/schema.ts +100 -94
- package/src/table/plugin/table-editing.ts +324 -230
- package/src/table/plugin/table-map.ts +294 -229
- package/src/table/plugin/table-view.ts +66 -62
- package/src/table/plugin/types.ts +8 -8
- package/src/table/plugin/util.ts +78 -66
- package/src/table/utils.ts +141 -138
- package/src/task-list-item.ts +151 -146
|
@@ -1,76 +1,80 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Node } from '@milkdown/prose/model'
|
|
3
|
-
import { NodeView } from '@milkdown/prose/view'
|
|
2
|
+
import type { Node } from '@milkdown/prose/model'
|
|
3
|
+
import type { NodeView } from '@milkdown/prose/view'
|
|
4
4
|
|
|
5
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
6
5
|
export class TableView implements NodeView {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
public dom: HTMLElement
|
|
7
|
+
public contentDOM: HTMLElement
|
|
8
|
+
public table: HTMLTableElement
|
|
9
|
+
public colgroup: HTMLTableColElement
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
constructor(public node: Node, public cellMinWidth: number) {
|
|
12
|
+
this.node = node
|
|
13
|
+
this.cellMinWidth = cellMinWidth
|
|
14
|
+
this.dom = document.createElement('div')
|
|
15
|
+
this.dom.className = 'tableWrapper'
|
|
16
|
+
this.table = this.dom.appendChild(document.createElement('table'))
|
|
17
|
+
this.colgroup = this.table.appendChild(document.createElement('colgroup'))
|
|
18
|
+
updateColumns(node, this.colgroup, this.table, cellMinWidth)
|
|
19
|
+
this.contentDOM = this.table.appendChild(document.createElement('tbody'))
|
|
20
|
+
}
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
update(node: Node) {
|
|
23
|
+
if (node.type != this.node.type)
|
|
24
|
+
return false
|
|
25
|
+
this.node = node
|
|
26
|
+
updateColumns(node, this.colgroup, this.table, this.cellMinWidth)
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
ignoreMutation(record: MutationRecord) {
|
|
31
|
+
return record.type == 'attributes' && (record.target == this.table || this.colgroup.contains(record.target))
|
|
32
|
+
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function updateColumns(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
node: Node,
|
|
37
|
+
colgroup: HTMLTableColElement,
|
|
38
|
+
table: HTMLTableElement,
|
|
39
|
+
cellMinWidth: number,
|
|
40
|
+
overrideCol?: number,
|
|
41
|
+
overrideValue?: number,
|
|
42
42
|
) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
let totalWidth = 0
|
|
44
|
+
let fixedWidth = true
|
|
45
|
+
let nextDOM = colgroup.firstChild
|
|
46
|
+
const row = node.firstChild as Node
|
|
47
|
+
for (let i = 0, col = 0; i < row.childCount; i++) {
|
|
48
|
+
const { colspan, colwidth } = row.child(i).attrs
|
|
49
|
+
for (let j = 0; j < colspan; j++, col++) {
|
|
50
|
+
const hasWidth = overrideCol == col ? overrideValue : colwidth && colwidth[j]
|
|
51
|
+
const cssWidth = hasWidth ? `${hasWidth}px` : ''
|
|
52
|
+
totalWidth += hasWidth || cellMinWidth
|
|
53
|
+
if (!hasWidth)
|
|
54
|
+
fixedWidth = false
|
|
55
|
+
if (!nextDOM) {
|
|
56
|
+
colgroup.appendChild(document.createElement('col')).style.width = cssWidth
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if ((nextDOM as HTMLElement).style.width != cssWidth)
|
|
60
|
+
(nextDOM as HTMLElement).style.width = cssWidth
|
|
61
|
+
nextDOM = nextDOM.nextSibling
|
|
62
|
+
}
|
|
61
63
|
}
|
|
64
|
+
}
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
while (nextDOM) {
|
|
67
|
+
const after = nextDOM.nextSibling
|
|
68
|
+
nextDOM.parentNode?.removeChild(nextDOM)
|
|
69
|
+
nextDOM = after
|
|
70
|
+
}
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
72
|
+
if (fixedWidth) {
|
|
73
|
+
table.style.width = `${totalWidth}px`
|
|
74
|
+
table.style.minWidth = ''
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
table.style.width = ''
|
|
78
|
+
table.style.minWidth = `${totalWidth}px`
|
|
79
|
+
}
|
|
76
80
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
export type getFromDOM<T> = (dom: Element) => T
|
|
4
|
-
export type setDOMAttr = <Value>(value: Value, attrs: Record<string, unknown>) => void
|
|
3
|
+
export type getFromDOM<T> = (dom: Element) => T
|
|
4
|
+
export type setDOMAttr = <Value>(value: Value, attrs: Record<string, unknown>) => void
|
|
5
5
|
|
|
6
6
|
export interface CellAttributes<T = unknown> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
default: T
|
|
8
|
+
getFromDOM?: getFromDOM<T>
|
|
9
|
+
setDOMAttr?: setDOMAttr
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export interface TableNodesOptions {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
tableGroup?: string
|
|
14
|
+
cellContent: string
|
|
15
|
+
cellAttributes: { [key: string]: CellAttributes }
|
|
16
16
|
}
|
package/src/table/plugin/util.ts
CHANGED
|
@@ -1,107 +1,119 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Attrs, Node, ResolvedPos } from '@milkdown/prose/model'
|
|
3
|
-
import { EditorState, NodeSelection } from '@milkdown/prose/state'
|
|
2
|
+
import type { Attrs, Node, ResolvedPos } from '@milkdown/prose/model'
|
|
3
|
+
import type { EditorState, NodeSelection } from '@milkdown/prose/state'
|
|
4
4
|
|
|
5
|
-
import { CellSelection } from './cell-selection'
|
|
6
|
-
import { tableNodeTypes } from './schema'
|
|
7
|
-
import { TableMap } from './table-map'
|
|
5
|
+
import { CellSelection } from './cell-selection'
|
|
6
|
+
import { tableNodeTypes } from './schema'
|
|
7
|
+
import { TableMap } from './table-map'
|
|
8
8
|
|
|
9
9
|
export function cellAround($pos: ResolvedPos) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
for (let d = $pos.depth - 1; d > 0; d--) {
|
|
11
|
+
if ($pos.node(d).type.spec.tableRole == 'row')
|
|
12
|
+
return $pos.node(0).resolve($pos.before(d + 1))
|
|
13
|
+
}
|
|
14
|
+
return undefined
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export function cellWrapping($pos: ResolvedPos) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
for (let d = $pos.depth; d > 0; d--) {
|
|
19
|
+
// Sometimes the cell can be in the same depth.
|
|
20
|
+
const role = $pos.node(d).type.spec.tableRole
|
|
21
|
+
if (role === 'cell' || role === 'header_cell')
|
|
22
|
+
return $pos.node(d)
|
|
23
|
+
}
|
|
24
|
+
return null
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
export function pointsAtCell($pos: ResolvedPos): Node | null {
|
|
25
|
-
|
|
26
|
-
return
|
|
28
|
+
if ($pos.parent.type.spec.tableRole == 'row')
|
|
29
|
+
return $pos.nodeAfter
|
|
30
|
+
return null
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
export function moveCellForward($pos: ResolvedPos) {
|
|
30
|
-
|
|
34
|
+
return $pos.node(0).resolve($pos.pos + ($pos.nodeAfter as Node).nodeSize)
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export function inSameTable($a: ResolvedPos, $b: ResolvedPos) {
|
|
34
|
-
|
|
38
|
+
return $a.depth == $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1)
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
export function nextCell($pos: ResolvedPos, axis: string, dir: number) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const start = $pos.start(-1)
|
|
43
|
+
const map = TableMap.get($pos.node(-1))
|
|
44
|
+
const moved = map.nextCell($pos.pos - start, axis, dir)
|
|
45
|
+
return moved == null ? null : $pos.node(0).resolve(start + moved)
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
export function setAttr<T>(attrs: Attrs, name: string, value: T) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const result: Record<string, unknown> = {}
|
|
50
|
+
for (const prop in attrs) result[prop] = attrs[prop]
|
|
51
|
+
result[name] = value
|
|
52
|
+
return result as Attrs
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
export function removeColSpan(attrs: Attrs, pos: number, n = 1) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
const result = setAttr(attrs, 'colspan', attrs.colspan - n) as Record<string, unknown>
|
|
57
|
+
if (result.colwidth) {
|
|
58
|
+
const widths = result.colwidth as number[]
|
|
59
|
+
result.colwidth = widths.slice()
|
|
60
|
+
widths.splice(pos, n)
|
|
61
|
+
if (!widths.some(w => w > 0))
|
|
62
|
+
result.colwidth = null
|
|
63
|
+
}
|
|
64
|
+
return result
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
export function isInTable(state: EditorState) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
const $head = state.selection.$head
|
|
69
|
+
for (let d = $head.depth; d > 0; d--) {
|
|
70
|
+
if ($head.node(d).type.spec.tableRole == 'row')
|
|
71
|
+
return true
|
|
72
|
+
}
|
|
73
|
+
return false
|
|
66
74
|
}
|
|
67
75
|
|
|
68
76
|
export function selectionCell(state: EditorState) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
const sel = state.selection
|
|
78
|
+
if (sel instanceof CellSelection)
|
|
79
|
+
return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell
|
|
80
|
+
else if ((sel as NodeSelection).node && (sel as NodeSelection).node.type.spec.tableRole == 'cell')
|
|
81
|
+
return sel.$anchor
|
|
82
|
+
|
|
83
|
+
return cellAround(sel.$head) || cellNear(sel.$head)
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
function cellNear($pos: ResolvedPos) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
|
|
88
|
+
const role = after.type.spec.tableRole
|
|
89
|
+
if (role == 'cell' || role == 'header_cell')
|
|
90
|
+
return $pos.doc.resolve(pos)
|
|
91
|
+
}
|
|
92
|
+
for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
|
|
93
|
+
const role = before.type.spec.tableRole
|
|
94
|
+
if (role == 'cell' || role == 'header_cell')
|
|
95
|
+
return $pos.doc.resolve(pos - before.nodeSize)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return undefined
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
export function addColSpan(attrs: Attrs, pos: number, n = 1) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
const result = setAttr(attrs, 'colspan', attrs.colspan + n) as Record<string, unknown>
|
|
103
|
+
if (result.colwidth) {
|
|
104
|
+
const widths = result.colwidth as number[]
|
|
105
|
+
result.colwidth = widths.slice()
|
|
106
|
+
for (let i = 0; i < n; i++) widths.splice(pos, 0, 0)
|
|
107
|
+
}
|
|
108
|
+
return result as Attrs
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
export function columnIsHeader(map: TableMap, table: Node, col: number) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
const headerCell = tableNodeTypes(table.type.schema).header_cell
|
|
113
|
+
for (let row = 0; row < map.height; row++) {
|
|
114
|
+
const pos = map.map[col + row * map.width] as number
|
|
115
|
+
if ((table.nodeAt(pos) as Node).type != headerCell)
|
|
116
|
+
return false
|
|
117
|
+
}
|
|
118
|
+
return true
|
|
107
119
|
}
|