@milkdown/preset-gfm 6.5.2 → 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 +649 -607
- 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 -34
- 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,34 +1,39 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import { Node } from '@milkdown/prose/model'
|
|
4
|
-
import { EditorState,
|
|
3
|
+
import type { Node } from '@milkdown/prose/model'
|
|
4
|
+
import type { EditorState, Transaction } from '@milkdown/prose/state'
|
|
5
|
+
import { PluginKey } from '@milkdown/prose/state'
|
|
5
6
|
|
|
6
|
-
import { tableNodeTypes } from './schema'
|
|
7
|
-
import { Problem
|
|
8
|
-
import {
|
|
7
|
+
import { tableNodeTypes } from './schema'
|
|
8
|
+
import type { Problem } from './table-map'
|
|
9
|
+
import { TableMap } from './table-map'
|
|
10
|
+
import { removeColSpan, setAttr } from './util'
|
|
9
11
|
|
|
10
|
-
export const fixTablesKey = new PluginKey('fix-tables')
|
|
12
|
+
export const fixTablesKey = new PluginKey('fix-tables')
|
|
11
13
|
|
|
12
14
|
// Helper for iterating through the nodes in a document that changed
|
|
13
15
|
// compared to the given previous document. Useful for avoiding
|
|
14
16
|
// duplicate work on each transaction.
|
|
15
17
|
function changedDescendants(old: Node, cur: Node, offset: number, f: (node: Node, pos: number) => void | boolean) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (j < oldSize && old.child(j).sameMarkup(child)) changedDescendants(old.child(j), child, offset + 1, f);
|
|
29
|
-
else child.nodesBetween(0, child.content.size, f, offset + 1);
|
|
30
|
-
offset += child.nodeSize;
|
|
18
|
+
const oldSize = old.childCount
|
|
19
|
+
const curSize = cur.childCount
|
|
20
|
+
// eslint-disable-next-line no-restricted-syntax, no-labels
|
|
21
|
+
outer: for (let i = 0, j = 0; i < curSize; i++) {
|
|
22
|
+
const child = cur.child(i)
|
|
23
|
+
for (let scan = j, e = Math.min(oldSize, i + 3); scan < e; scan++) {
|
|
24
|
+
if (old.child(scan) == child) {
|
|
25
|
+
j = scan + 1
|
|
26
|
+
offset += child.nodeSize
|
|
27
|
+
// eslint-disable-next-line no-labels
|
|
28
|
+
continue outer
|
|
29
|
+
}
|
|
31
30
|
}
|
|
31
|
+
f(child, offset)
|
|
32
|
+
if (j < oldSize && old.child(j).sameMarkup(child))
|
|
33
|
+
changedDescendants(old.child(j), child, offset + 1, f)
|
|
34
|
+
else child.nodesBetween(0, child.content.size, f, offset + 1)
|
|
35
|
+
offset += child.nodeSize
|
|
36
|
+
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
// :: (EditorState, ?EditorState) → ?Transaction
|
|
@@ -38,80 +43,90 @@ function changedDescendants(old: Node, cur: Node, offset: number, f: (node: Node
|
|
|
38
43
|
// which will be used to avoid re-scanning unchanged parts of the
|
|
39
44
|
// document.
|
|
40
45
|
export function fixTables(state: EditorState, oldState: EditorState) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
let tr: undefined | Transaction
|
|
47
|
+
const check = (node: Node, pos: number) => {
|
|
48
|
+
if (node.type.spec.tableRole == 'table')
|
|
49
|
+
tr = fixTable(state, node, pos, tr)
|
|
50
|
+
}
|
|
51
|
+
if (!oldState)
|
|
52
|
+
state.doc.descendants(check)
|
|
53
|
+
else if (oldState.doc != state.doc)
|
|
54
|
+
changedDescendants(oldState.doc, state.doc, 0, check)
|
|
55
|
+
return tr
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
// : (EditorState, Node, number, ?Transaction) → ?Transaction
|
|
51
59
|
// Fix the given table, if necessary. Will append to the transaction
|
|
52
60
|
// it was given, if non-null, or create a new one if necessary.
|
|
53
61
|
export function fixTable(state: EditorState, table: Node, tablePos: number, tr?: Transaction) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
const map = TableMap.get(table)
|
|
63
|
+
if (!map.problems)
|
|
64
|
+
return tr
|
|
65
|
+
if (!tr)
|
|
66
|
+
tr = state.tr
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
} else if (prob.type == 'missing') {
|
|
73
|
-
mustAdd[prob.row] += prob.n;
|
|
74
|
-
} else if (prob.type == 'overlong_rowspan') {
|
|
75
|
-
const cell = table.nodeAt(prob.pos) as Node;
|
|
76
|
-
tr.setNodeMarkup(
|
|
77
|
-
tr.mapping.map(tablePos + 1 + prob.pos),
|
|
78
|
-
null,
|
|
79
|
-
setAttr(cell.attrs, 'rowspan', cell.attrs['rowspan'] - prob.n),
|
|
80
|
-
);
|
|
81
|
-
} else if (prob.type == 'colwidth mismatch') {
|
|
82
|
-
const cell = table.nodeAt(prob.pos) as Node;
|
|
83
|
-
tr.setNodeMarkup(
|
|
84
|
-
tr.mapping.map(tablePos + 1 + prob.pos),
|
|
85
|
-
null,
|
|
86
|
-
setAttr(cell.attrs, 'colwidth', prob.colwidth),
|
|
87
|
-
);
|
|
88
|
-
}
|
|
68
|
+
// Track which rows we must add cells to, so that we can adjust that
|
|
69
|
+
// when fixing collisions.
|
|
70
|
+
const mustAdd = []
|
|
71
|
+
for (let i = 0; i < map.height; i++) mustAdd.push(0)
|
|
72
|
+
for (let i = 0; i < map.problems.length; i++) {
|
|
73
|
+
const prob = map.problems[i] as Problem
|
|
74
|
+
if (prob.type == 'collision') {
|
|
75
|
+
const cell = table.nodeAt(prob.pos) as Node
|
|
76
|
+
for (let j = 0; j < cell.attrs.rowspan; j++) mustAdd[prob.row + j] += prob.n
|
|
77
|
+
tr.setNodeMarkup(
|
|
78
|
+
tr.mapping.map(tablePos + 1 + prob.pos),
|
|
79
|
+
null,
|
|
80
|
+
removeColSpan(cell.attrs, cell.attrs.colspan - prob.n, prob.n),
|
|
81
|
+
)
|
|
89
82
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (mustAdd[i]) {
|
|
93
|
-
if (first == null) first = i;
|
|
94
|
-
last = i;
|
|
95
|
-
}
|
|
96
|
-
// Add the necessary cells, using a heuristic for whether to add the
|
|
97
|
-
// cells at the start or end of the rows (if it looks like a 'bite'
|
|
98
|
-
// was taken out of the table, add cells at the start of the row
|
|
99
|
-
// after the bite. Otherwise add them at the end).
|
|
100
|
-
for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
|
|
101
|
-
const row = table.child(i);
|
|
102
|
-
const end = pos + row.nodeSize;
|
|
103
|
-
const add = mustAdd[i] as number;
|
|
104
|
-
if (add > 0) {
|
|
105
|
-
let tableNodeType = 'cell';
|
|
106
|
-
if (row.firstChild) {
|
|
107
|
-
tableNodeType = row.firstChild.type.spec['tableRole'];
|
|
108
|
-
}
|
|
109
|
-
const nodes = [];
|
|
110
|
-
for (let j = 0; j < add; j++) nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill());
|
|
111
|
-
const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1;
|
|
112
|
-
tr.insert(tr.mapping.map(side), nodes);
|
|
113
|
-
}
|
|
114
|
-
pos = end;
|
|
83
|
+
else if (prob.type == 'missing') {
|
|
84
|
+
mustAdd[prob.row] += prob.n
|
|
115
85
|
}
|
|
116
|
-
|
|
86
|
+
else if (prob.type == 'overlong_rowspan') {
|
|
87
|
+
const cell = table.nodeAt(prob.pos) as Node
|
|
88
|
+
tr.setNodeMarkup(
|
|
89
|
+
tr.mapping.map(tablePos + 1 + prob.pos),
|
|
90
|
+
null,
|
|
91
|
+
setAttr(cell.attrs, 'rowspan', cell.attrs.rowspan - prob.n),
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
else if (prob.type == 'colwidth mismatch') {
|
|
95
|
+
const cell = table.nodeAt(prob.pos) as Node
|
|
96
|
+
tr.setNodeMarkup(
|
|
97
|
+
tr.mapping.map(tablePos + 1 + prob.pos),
|
|
98
|
+
null,
|
|
99
|
+
setAttr(cell.attrs, 'colwidth', prob.colwidth),
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
let first, last
|
|
104
|
+
for (let i = 0; i < mustAdd.length; i++) {
|
|
105
|
+
if (mustAdd[i]) {
|
|
106
|
+
if (first == null)
|
|
107
|
+
first = i
|
|
108
|
+
last = i
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Add the necessary cells, using a heuristic for whether to add the
|
|
112
|
+
// cells at the start or end of the rows (if it looks like a 'bite'
|
|
113
|
+
// was taken out of the table, add cells at the start of the row
|
|
114
|
+
// after the bite. Otherwise add them at the end).
|
|
115
|
+
for (let i = 0, pos = tablePos + 1; i < map.height; i++) {
|
|
116
|
+
const row = table.child(i)
|
|
117
|
+
const end = pos + row.nodeSize
|
|
118
|
+
const add = mustAdd[i] as number
|
|
119
|
+
if (add > 0) {
|
|
120
|
+
let tableNodeType = 'cell'
|
|
121
|
+
if (row.firstChild)
|
|
122
|
+
tableNodeType = row.firstChild.type.spec.tableRole
|
|
123
|
+
|
|
124
|
+
const nodes = []
|
|
125
|
+
for (let j = 0; j < add; j++) nodes.push(tableNodeTypes(state.schema)[tableNodeType].createAndFill())
|
|
126
|
+
const side = (i == 0 || first == i - 1) && last == i ? pos + 1 : end - 1
|
|
127
|
+
tr.insert(tr.mapping.map(side), nodes)
|
|
128
|
+
}
|
|
129
|
+
pos = end
|
|
130
|
+
}
|
|
131
|
+
return tr.setMeta(fixTablesKey, { fixTables: true })
|
|
117
132
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
export * from './cell-selection'
|
|
3
|
-
export * from './commands'
|
|
4
|
-
export * from './util'
|
|
2
|
+
export * from './cell-selection'
|
|
3
|
+
export * from './commands'
|
|
4
|
+
export * from './util'
|
|
@@ -1,114 +1,120 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Attrs, Node, NodeSpec, Schema } from '@milkdown/prose/model'
|
|
2
|
+
import type { Attrs, Node, NodeSpec, Schema } from '@milkdown/prose/model'
|
|
3
3
|
|
|
4
|
-
import { TableNodesOptions } from './types'
|
|
4
|
+
import type { TableNodesOptions } from './types'
|
|
5
5
|
|
|
6
6
|
function getCellAttrs(dom: HTMLElement, extraAttrs: Attrs) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
const widthAttr = dom.getAttribute('data-colwidth')
|
|
8
|
+
const widths = widthAttr && /^\d+(,\d+)*$/.test(widthAttr) ? widthAttr.split(',').map(s => Number(s)) : null
|
|
9
|
+
const colspan = Number(dom.getAttribute('colspan') || 1)
|
|
10
|
+
const result = {
|
|
11
|
+
colspan,
|
|
12
|
+
rowspan: Number(dom.getAttribute('rowspan') || 1),
|
|
13
|
+
colwidth: widths && widths.length == colspan ? widths : null,
|
|
14
|
+
}
|
|
15
|
+
for (const prop in extraAttrs) {
|
|
16
|
+
const getter = extraAttrs[prop].getFromDOM
|
|
17
|
+
const value = getter && getter(dom)
|
|
18
|
+
if (value != null)
|
|
19
|
+
result[prop as keyof typeof result] = value
|
|
20
|
+
}
|
|
21
|
+
return result
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
function setCellAttrs(node: Node, extraAttrs: Attrs) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
const attrs: Record<string, unknown> = {}
|
|
26
|
+
if (node.attrs.colspan != 1)
|
|
27
|
+
attrs.colspan = node.attrs.colspan
|
|
28
|
+
if (node.attrs.rowspan != 1)
|
|
29
|
+
attrs.rowspan = node.attrs.rowspan
|
|
30
|
+
if (node.attrs.colwidth)
|
|
31
|
+
attrs['data-colwidth'] = node.attrs.colwidth.join(',')
|
|
32
|
+
for (const prop in extraAttrs) {
|
|
33
|
+
const setter = extraAttrs[prop].setDOMAttr
|
|
34
|
+
if (setter)
|
|
35
|
+
setter(node.attrs[prop], attrs)
|
|
36
|
+
}
|
|
37
|
+
return attrs
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
function tableNodesSpecCreator(options: TableNodesOptions) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const extraAttrs: Attrs = options.cellAttributes || {}
|
|
42
|
+
const cellAttrs: Record<string, unknown> = {
|
|
43
|
+
colspan: { default: 1 },
|
|
44
|
+
rowspan: { default: 1 },
|
|
45
|
+
colwidth: { default: null },
|
|
46
|
+
}
|
|
47
|
+
for (const prop in extraAttrs) cellAttrs[prop] = { default: extraAttrs[prop].default }
|
|
48
|
+
const finalAttrs = cellAttrs as Attrs
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
50
|
+
const schema: Record<'table' | 'table_row' | 'table_cell' | 'table_header', NodeSpec> = {
|
|
51
|
+
table: {
|
|
52
|
+
content: 'table_row+',
|
|
53
|
+
tableRole: 'table',
|
|
54
|
+
isolating: true,
|
|
55
|
+
group: options.tableGroup,
|
|
56
|
+
parseDOM: [{ tag: 'table' }],
|
|
57
|
+
toDOM() {
|
|
58
|
+
return ['table', ['tbody', 0]]
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
table_row: {
|
|
62
|
+
content: '(table_cell | table_header)*',
|
|
63
|
+
tableRole: 'row',
|
|
64
|
+
parseDOM: [{ tag: 'tr' }],
|
|
65
|
+
toDOM() {
|
|
66
|
+
return ['tr', 0]
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
table_cell: {
|
|
70
|
+
content: options.cellContent,
|
|
71
|
+
attrs: finalAttrs,
|
|
72
|
+
tableRole: 'cell',
|
|
73
|
+
isolating: true,
|
|
74
|
+
parseDOM: [{ tag: 'td', getAttrs: dom => getCellAttrs(dom as HTMLElement, extraAttrs) }],
|
|
75
|
+
toDOM(node) {
|
|
76
|
+
return ['td', setCellAttrs(node, extraAttrs), 0]
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
table_header: {
|
|
80
|
+
content: options.cellContent,
|
|
81
|
+
attrs: finalAttrs,
|
|
82
|
+
tableRole: 'header_cell',
|
|
83
|
+
isolating: true,
|
|
84
|
+
parseDOM: [{ tag: 'th', getAttrs: dom => getCellAttrs(dom as HTMLElement, extraAttrs) }],
|
|
85
|
+
toDOM(node) {
|
|
86
|
+
return ['th', setCellAttrs(node, extraAttrs), 0]
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
}
|
|
85
90
|
|
|
86
|
-
|
|
91
|
+
return schema
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
export function tableNodeTypes(schema: Schema) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
let result = schema.cached.tableNodeTypes
|
|
96
|
+
if (!result) {
|
|
97
|
+
result = schema.cached.tableNodeTypes = {}
|
|
98
|
+
for (const name in schema.nodes) {
|
|
99
|
+
const type = schema.nodes[name]
|
|
100
|
+
const role = type?.spec.tableRole
|
|
101
|
+
if (role)
|
|
102
|
+
result[role] = type
|
|
98
103
|
}
|
|
99
|
-
|
|
104
|
+
}
|
|
105
|
+
return result
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
export const schema = tableNodesSpecCreator({
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
},
|
|
109
|
+
tableGroup: 'block',
|
|
110
|
+
cellContent: 'paragraph',
|
|
111
|
+
cellAttributes: {
|
|
112
|
+
alignment: {
|
|
113
|
+
default: 'left',
|
|
114
|
+
getFromDOM: dom => (dom as HTMLElement).style.textAlign || 'left',
|
|
115
|
+
setDOMAttr: (value, attrs) => {
|
|
116
|
+
attrs.style = `text-align: ${value || 'left'}`
|
|
117
|
+
},
|
|
113
118
|
},
|
|
114
|
-
}
|
|
119
|
+
},
|
|
120
|
+
})
|