@milkdown/preset-gfm 6.5.2 → 6.5.4
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 +22 -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
package/src/table/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { BreakTable, InsertTable, NextCell, PrevCell } from './nodes'
|
|
2
|
+
import { BreakTable, InsertTable, NextCell, PrevCell } from './nodes'
|
|
3
3
|
|
|
4
|
-
export { BreakTable, InsertTable, NextCell, PrevCell, SupportedKeys, table } from './nodes'
|
|
5
|
-
export { createTable } from './utils'
|
|
4
|
+
export { BreakTable, InsertTable, NextCell, PrevCell, SupportedKeys, table } from './nodes'
|
|
5
|
+
export { createTable } from './utils'
|
|
6
6
|
|
|
7
7
|
export const commands = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} as const
|
|
13
|
-
export type Commands = typeof commands
|
|
8
|
+
NextCell,
|
|
9
|
+
PrevCell,
|
|
10
|
+
BreakTable,
|
|
11
|
+
InsertTable,
|
|
12
|
+
} as const
|
|
13
|
+
export type Commands = typeof commands
|
package/src/table/nodes/index.ts
CHANGED
|
@@ -1,186 +1,189 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import type { MarkdownNode } from '@milkdown/core'
|
|
3
|
+
import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core'
|
|
4
|
+
import { InputRule } from '@milkdown/prose/inputrules'
|
|
5
|
+
import type { NodeType } from '@milkdown/prose/model'
|
|
6
|
+
import { Selection, TextSelection } from '@milkdown/prose/state'
|
|
7
|
+
import { createPlugin, createShortcut } from '@milkdown/utils'
|
|
7
8
|
|
|
8
|
-
import { exitTable } from '../command'
|
|
9
|
-
import { operatorPlugin } from '../operator-plugin'
|
|
10
|
-
import { autoInsertZeroSpace } from '../plugin/auto-insert-zero-space'
|
|
11
|
-
import { columnResizing } from '../plugin/column-resizing'
|
|
12
|
-
import { goToNextCell } from '../plugin/commands'
|
|
13
|
-
import { schema } from '../plugin/schema'
|
|
14
|
-
import { tableEditing } from '../plugin/table-editing'
|
|
15
|
-
import { createTable } from '../utils'
|
|
9
|
+
import { exitTable } from '../command'
|
|
10
|
+
import { operatorPlugin } from '../operator-plugin'
|
|
11
|
+
import { autoInsertZeroSpace } from '../plugin/auto-insert-zero-space'
|
|
12
|
+
import { columnResizing } from '../plugin/column-resizing'
|
|
13
|
+
import { goToNextCell } from '../plugin/commands'
|
|
14
|
+
import { schema } from '../plugin/schema'
|
|
15
|
+
import { tableEditing } from '../plugin/table-editing'
|
|
16
|
+
import { createTable } from '../utils'
|
|
16
17
|
|
|
17
18
|
export const SupportedKeys = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} as const
|
|
22
|
-
|
|
19
|
+
NextCell: 'NextCell',
|
|
20
|
+
PrevCell: 'PrevCell',
|
|
21
|
+
ExitTable: 'ExitTable',
|
|
22
|
+
} as const
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
24
|
+
export type SupportedKeys = typeof SupportedKeys
|
|
23
25
|
|
|
24
|
-
type Keys = keyof SupportedKeys
|
|
26
|
+
type Keys = keyof SupportedKeys
|
|
25
27
|
|
|
26
|
-
export const PrevCell = createCmdKey('PrevCell')
|
|
27
|
-
export const NextCell = createCmdKey('NextCell')
|
|
28
|
-
export const BreakTable = createCmdKey('BreakTable')
|
|
29
|
-
export const InsertTable = createCmdKey('InsertTable')
|
|
28
|
+
export const PrevCell = createCmdKey('PrevCell')
|
|
29
|
+
export const NextCell = createCmdKey('NextCell')
|
|
30
|
+
export const BreakTable = createCmdKey('BreakTable')
|
|
31
|
+
export const InsertTable = createCmdKey('InsertTable')
|
|
30
32
|
|
|
31
33
|
export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof schema>((utils) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
toMarkdown: {
|
|
52
|
-
match: (node) => node.type.name === 'table',
|
|
53
|
-
runner: (state, node) => {
|
|
54
|
-
const firstLine = node.content.firstChild?.content;
|
|
55
|
-
if (!firstLine) return;
|
|
56
|
-
|
|
57
|
-
const align: (string | null)[] = [];
|
|
58
|
-
firstLine.forEach((cell) => {
|
|
59
|
-
align.push(cell.attrs['alignment']);
|
|
60
|
-
});
|
|
61
|
-
state.openNode('table', undefined, { align });
|
|
62
|
-
state.next(node.content);
|
|
63
|
-
state.closeNode();
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
table_row: {
|
|
68
|
-
...schema.table_row,
|
|
69
|
-
parseMarkdown: {
|
|
70
|
-
match: (node) => node.type === 'tableRow',
|
|
71
|
-
runner: (state, node, type) => {
|
|
72
|
-
const align = node['align'] as (string | null)[];
|
|
73
|
-
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
74
|
-
...x,
|
|
75
|
-
align: align[i],
|
|
76
|
-
isHeader: node['isHeader'],
|
|
77
|
-
}));
|
|
78
|
-
state.openNode(type);
|
|
79
|
-
state.next(children);
|
|
80
|
-
state.closeNode();
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
toMarkdown: {
|
|
84
|
-
match: (node) => node.type.name === 'table_row',
|
|
85
|
-
runner: (state, node) => {
|
|
86
|
-
state.openNode('tableRow');
|
|
87
|
-
state.next(node.content);
|
|
88
|
-
state.closeNode();
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
table_cell: {
|
|
93
|
-
...schema.table_cell,
|
|
94
|
-
parseMarkdown: {
|
|
95
|
-
match: (node) => node.type === 'tableCell' && !node['isHeader'],
|
|
96
|
-
runner: (state, node, type) => {
|
|
97
|
-
const align = node['align'] as string;
|
|
98
|
-
state
|
|
99
|
-
.openNode(type, { alignment: align })
|
|
100
|
-
.openNode(state.schema.nodes['paragraph'] as NodeType)
|
|
101
|
-
.next(node.children)
|
|
102
|
-
.closeNode()
|
|
103
|
-
.closeNode();
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
toMarkdown: {
|
|
107
|
-
match: (node) => node.type.name === 'table_cell',
|
|
108
|
-
runner: (state, node) => {
|
|
109
|
-
state.openNode('tableCell').next(node.content).closeNode();
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
table_header: {
|
|
114
|
-
...schema.table_header,
|
|
115
|
-
parseMarkdown: {
|
|
116
|
-
match: (node) => node.type === 'tableCell' && !!node['isHeader'],
|
|
117
|
-
runner: (state, node, type) => {
|
|
118
|
-
const align = node['align'] as string;
|
|
119
|
-
state.openNode(type, { alignment: align });
|
|
120
|
-
state.openNode(state.schema.nodes['paragraph'] as NodeType);
|
|
121
|
-
state.next(node.children);
|
|
122
|
-
state.closeNode();
|
|
123
|
-
state.closeNode();
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
toMarkdown: {
|
|
127
|
-
match: (node) => node.type.name === 'table_header',
|
|
128
|
-
runner: (state, node) => {
|
|
129
|
-
state.openNode('tableCell');
|
|
130
|
-
state.next(node.content);
|
|
131
|
-
state.closeNode();
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
},
|
|
34
|
+
return {
|
|
35
|
+
schema: () => ({
|
|
36
|
+
node: {
|
|
37
|
+
table: {
|
|
38
|
+
...schema.table,
|
|
39
|
+
parseMarkdown: {
|
|
40
|
+
match: node => node.type === 'table',
|
|
41
|
+
runner: (state, node, type) => {
|
|
42
|
+
const align = node.align as (string | null)[]
|
|
43
|
+
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
44
|
+
...x,
|
|
45
|
+
align,
|
|
46
|
+
isHeader: i === 0,
|
|
47
|
+
}))
|
|
48
|
+
state.openNode(type)
|
|
49
|
+
state.next(children)
|
|
50
|
+
state.closeNode()
|
|
135
51
|
},
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const tableNode = createTable(ctx.get(schemaCtx));
|
|
144
|
-
const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView();
|
|
145
|
-
return tr.setSelection(TextSelection.create(tr.doc, start + 3));
|
|
146
|
-
}),
|
|
147
|
-
new InputRule(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
|
|
148
|
-
const $start = state.doc.resolve(start);
|
|
149
|
-
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
|
|
150
|
-
return null;
|
|
52
|
+
},
|
|
53
|
+
toMarkdown: {
|
|
54
|
+
match: node => node.type.name === 'table',
|
|
55
|
+
runner: (state, node) => {
|
|
56
|
+
const firstLine = node.content.firstChild?.content
|
|
57
|
+
if (!firstLine)
|
|
58
|
+
return
|
|
151
59
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
60
|
+
const align: (string | null)[] = []
|
|
61
|
+
firstLine.forEach((cell) => {
|
|
62
|
+
align.push(cell.attrs.alignment)
|
|
63
|
+
})
|
|
64
|
+
state.openNode('table', undefined, { align })
|
|
65
|
+
state.next(node.content)
|
|
66
|
+
state.closeNode()
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
table_row: {
|
|
71
|
+
...schema.table_row,
|
|
72
|
+
parseMarkdown: {
|
|
73
|
+
match: node => node.type === 'tableRow',
|
|
74
|
+
runner: (state, node, type) => {
|
|
75
|
+
const align = node.align as (string | null)[]
|
|
76
|
+
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
77
|
+
...x,
|
|
78
|
+
align: align[i],
|
|
79
|
+
isHeader: node.isHeader,
|
|
80
|
+
}))
|
|
81
|
+
state.openNode(type)
|
|
82
|
+
state.next(children)
|
|
83
|
+
state.closeNode()
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
toMarkdown: {
|
|
87
|
+
match: node => node.type.name === 'table_row',
|
|
88
|
+
runner: (state, node) => {
|
|
89
|
+
state.openNode('tableRow')
|
|
90
|
+
state.next(node.content)
|
|
91
|
+
state.closeNode()
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
table_cell: {
|
|
96
|
+
...schema.table_cell,
|
|
97
|
+
parseMarkdown: {
|
|
98
|
+
match: node => node.type === 'tableCell' && !node.isHeader,
|
|
99
|
+
runner: (state, node, type) => {
|
|
100
|
+
const align = node.align as string
|
|
101
|
+
state
|
|
102
|
+
.openNode(type, { alignment: align })
|
|
103
|
+
.openNode(state.schema.nodes.paragraph as NodeType)
|
|
104
|
+
.next(node.children)
|
|
105
|
+
.closeNode()
|
|
106
|
+
.closeNode()
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
toMarkdown: {
|
|
110
|
+
match: node => node.type.name === 'table_cell',
|
|
111
|
+
runner: (state, node) => {
|
|
112
|
+
state.openNode('tableCell').next(node.content).closeNode()
|
|
113
|
+
},
|
|
114
|
+
},
|
|
181
115
|
},
|
|
182
|
-
|
|
183
|
-
|
|
116
|
+
table_header: {
|
|
117
|
+
...schema.table_header,
|
|
118
|
+
parseMarkdown: {
|
|
119
|
+
match: node => node.type === 'tableCell' && !!node.isHeader,
|
|
120
|
+
runner: (state, node, type) => {
|
|
121
|
+
const align = node.align as string
|
|
122
|
+
state.openNode(type, { alignment: align })
|
|
123
|
+
state.openNode(state.schema.nodes.paragraph as NodeType)
|
|
124
|
+
state.next(node.children)
|
|
125
|
+
state.closeNode()
|
|
126
|
+
state.closeNode()
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
toMarkdown: {
|
|
130
|
+
match: node => node.type.name === 'table_header',
|
|
131
|
+
runner: (state, node) => {
|
|
132
|
+
state.openNode('tableCell')
|
|
133
|
+
state.next(node.content)
|
|
134
|
+
state.closeNode()
|
|
135
|
+
},
|
|
136
|
+
},
|
|
184
137
|
},
|
|
185
|
-
|
|
186
|
-
})
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
inputRules: (nodeType, ctx) => [
|
|
141
|
+
new InputRule(/^\|\|\s$/, (state, _match, start, end) => {
|
|
142
|
+
const $start = state.doc.resolve(start)
|
|
143
|
+
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
|
|
144
|
+
return null
|
|
145
|
+
|
|
146
|
+
const tableNode = createTable(ctx.get(schemaCtx))
|
|
147
|
+
const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView()
|
|
148
|
+
return tr.setSelection(TextSelection.create(tr.doc, start + 3))
|
|
149
|
+
}),
|
|
150
|
+
new InputRule(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
|
|
151
|
+
const $start = state.doc.resolve(start)
|
|
152
|
+
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
|
|
153
|
+
return null
|
|
154
|
+
|
|
155
|
+
const tableNode = createTable(
|
|
156
|
+
ctx.get(schemaCtx),
|
|
157
|
+
Number(match.groups?.row),
|
|
158
|
+
Number(match.groups?.col),
|
|
159
|
+
)
|
|
160
|
+
const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView()
|
|
161
|
+
return tr.setSelection(TextSelection.create(tr.doc, start + 3))
|
|
162
|
+
}),
|
|
163
|
+
],
|
|
164
|
+
commands: (_, ctx) => [
|
|
165
|
+
createCmd(PrevCell, () => goToNextCell(-1)),
|
|
166
|
+
createCmd(NextCell, () => goToNextCell(1)),
|
|
167
|
+
createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes.paragraph as NodeType)),
|
|
168
|
+
createCmd(InsertTable, () => (state, dispatch) => {
|
|
169
|
+
const { selection, tr } = state
|
|
170
|
+
const { from } = selection
|
|
171
|
+
const table = createTable(ctx.get(schemaCtx))
|
|
172
|
+
const _tr = tr.replaceSelectionWith(table)
|
|
173
|
+
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true)
|
|
174
|
+
if (sel)
|
|
175
|
+
dispatch?.(_tr.setSelection(sel))
|
|
176
|
+
|
|
177
|
+
return true
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
180
|
+
shortcuts: {
|
|
181
|
+
[SupportedKeys.NextCell]: createShortcut(NextCell, 'Mod-]'),
|
|
182
|
+
[SupportedKeys.PrevCell]: createShortcut(PrevCell, 'Mod-['),
|
|
183
|
+
[SupportedKeys.ExitTable]: createShortcut(BreakTable, 'Mod-Enter'),
|
|
184
|
+
},
|
|
185
|
+
prosePlugins: (_, ctx) => {
|
|
186
|
+
return [operatorPlugin(ctx, utils), autoInsertZeroSpace(), columnResizing(), tableEditing()]
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
})
|
|
@@ -1,115 +1,116 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Ctx
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import type { Ctx } from '@milkdown/core'
|
|
3
|
+
import { ThemeIcon, themeManagerCtx } from '@milkdown/core'
|
|
4
|
+
import type { Command } from '@milkdown/prose/state'
|
|
5
|
+
import type { EditorView } from '@milkdown/prose/view'
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from '../plugin'
|
|
16
|
-
import { addRowWithAlignment } from '../utils'
|
|
17
|
-
import { getCellSelection, isFirstRowSelected } from './helper'
|
|
8
|
+
addColumnAfter,
|
|
9
|
+
addColumnBefore,
|
|
10
|
+
deleteColumn,
|
|
11
|
+
deleteRow,
|
|
12
|
+
deleteTable,
|
|
13
|
+
isInTable,
|
|
14
|
+
selectedRect,
|
|
15
|
+
setCellAttr,
|
|
16
|
+
} from '../plugin'
|
|
17
|
+
import { addRowWithAlignment } from '../utils'
|
|
18
|
+
import { getCellSelection, isFirstRowSelected } from './helper'
|
|
18
19
|
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
20
|
+
export interface Item {
|
|
21
|
+
$: HTMLElement
|
|
22
|
+
command: (e: Event, view: EditorView) => Command
|
|
23
|
+
disable?: (view: EditorView) => boolean
|
|
24
|
+
}
|
|
24
25
|
|
|
25
26
|
export enum Action {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
AddColLeft,
|
|
28
|
+
AddColRight,
|
|
29
|
+
AddRowTop,
|
|
30
|
+
AddRowBottom,
|
|
31
|
+
AlignLeft,
|
|
32
|
+
AlignCenter,
|
|
33
|
+
AlignRight,
|
|
34
|
+
Delete,
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
export const createActions: (ctx: Ctx) => Record<Action, Item> =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
disable: (view) =>
|
|
58
|
-
!getCellSelection(view).isRowSelection() ||
|
|
59
|
-
getCellSelection(view).$head.parent.type.name === 'table_header',
|
|
60
|
-
},
|
|
61
|
-
[Action.AddRowBottom]: {
|
|
62
|
-
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'downArrow')?.dom as HTMLElement,
|
|
63
|
-
command: () => (state, dispatch) => {
|
|
64
|
-
if (!isInTable(state)) return false;
|
|
65
|
-
if (dispatch) {
|
|
66
|
-
const rect = selectedRect(state);
|
|
67
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
70
|
-
},
|
|
71
|
-
disable: (view) => !getCellSelection(view).isRowSelection(),
|
|
37
|
+
export const createActions: (ctx: Ctx) => Record<Action, Item> = ctx => ({
|
|
38
|
+
[Action.AddColLeft]: {
|
|
39
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'leftArrow')?.dom as HTMLElement,
|
|
40
|
+
command: () => addColumnBefore,
|
|
41
|
+
disable: view => !getCellSelection(view).isColSelection(),
|
|
42
|
+
},
|
|
43
|
+
[Action.AddColRight]: {
|
|
44
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'rightArrow')?.dom as HTMLElement,
|
|
45
|
+
command: () => addColumnAfter,
|
|
46
|
+
disable: view => !getCellSelection(view).isColSelection(),
|
|
47
|
+
},
|
|
48
|
+
[Action.AddRowTop]: {
|
|
49
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'upArrow')?.dom as HTMLElement,
|
|
50
|
+
command: () => (state, dispatch) => {
|
|
51
|
+
if (!isInTable(state))
|
|
52
|
+
return false
|
|
53
|
+
if (dispatch) {
|
|
54
|
+
const rect = selectedRect(state)
|
|
55
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.top))
|
|
56
|
+
}
|
|
57
|
+
return true
|
|
72
58
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
disable: view =>
|
|
60
|
+
!getCellSelection(view).isRowSelection()
|
|
61
|
+
|| getCellSelection(view).$head.parent.type.name === 'table_header',
|
|
62
|
+
},
|
|
63
|
+
[Action.AddRowBottom]: {
|
|
64
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'downArrow')?.dom as HTMLElement,
|
|
65
|
+
command: () => (state, dispatch) => {
|
|
66
|
+
if (!isInTable(state))
|
|
67
|
+
return false
|
|
68
|
+
if (dispatch) {
|
|
69
|
+
const rect = selectedRect(state)
|
|
70
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom))
|
|
71
|
+
}
|
|
72
|
+
return true
|
|
77
73
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
disable: view => !getCellSelection(view).isRowSelection(),
|
|
75
|
+
},
|
|
76
|
+
[Action.AlignLeft]: {
|
|
77
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignLeft')?.dom as HTMLElement,
|
|
78
|
+
command: () => setCellAttr('alignment', 'left'),
|
|
79
|
+
disable: view => !getCellSelection(view).isColSelection(),
|
|
80
|
+
},
|
|
81
|
+
[Action.AlignCenter]: {
|
|
82
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignCenter')?.dom as HTMLElement,
|
|
83
|
+
command: () => setCellAttr('alignment', 'center'),
|
|
84
|
+
disable: view => !getCellSelection(view).isColSelection(),
|
|
85
|
+
},
|
|
86
|
+
[Action.AlignRight]: {
|
|
87
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignRight')?.dom as HTMLElement,
|
|
88
|
+
command: () => setCellAttr('alignment', 'right'),
|
|
89
|
+
disable: view => !getCellSelection(view).isColSelection(),
|
|
90
|
+
},
|
|
91
|
+
[Action.Delete]: {
|
|
92
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'delete')?.dom as HTMLElement,
|
|
93
|
+
command: (_, view) => {
|
|
94
|
+
const selection = getCellSelection(view)
|
|
95
|
+
const isCol = selection.isColSelection()
|
|
96
|
+
const isRow = selection.isRowSelection()
|
|
97
|
+
if (isCol && isRow)
|
|
98
|
+
return deleteTable
|
|
97
99
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
if (isCol)
|
|
101
|
+
return deleteColumn
|
|
102
|
+
|
|
103
|
+
return deleteRow
|
|
104
|
+
},
|
|
105
|
+
disable: (view) => {
|
|
106
|
+
const selection = getCellSelection(view)
|
|
107
|
+
if (selection.isRowSelection()) {
|
|
108
|
+
if (selection.isColSelection())
|
|
109
|
+
return false
|
|
101
110
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const selection = getCellSelection(view);
|
|
106
|
-
if (selection.isRowSelection()) {
|
|
107
|
-
if (selection.isColSelection()) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return isFirstRowSelected(selection);
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
113
|
-
},
|
|
111
|
+
return isFirstRowSelected(selection)
|
|
112
|
+
}
|
|
113
|
+
return false
|
|
114
114
|
},
|
|
115
|
-
}
|
|
115
|
+
},
|
|
116
|
+
})
|