@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
|
@@ -1,174 +1,178 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
3
|
+
import type { ThemeInputChipType } from '@milkdown/core'
|
|
4
|
+
import { commandsCtx, createCmd, createCmdKey, editorViewCtx } from '@milkdown/core'
|
|
5
|
+
import { expectDomTypeError } from '@milkdown/exception'
|
|
6
|
+
import { findSelectedNodeOfType } from '@milkdown/prose'
|
|
7
|
+
import { InputRule } from '@milkdown/prose/inputrules'
|
|
8
|
+
import { NodeSelection, Plugin, PluginKey } from '@milkdown/prose/state'
|
|
9
|
+
import type { EditorView } from '@milkdown/prose/view'
|
|
10
|
+
import { createNode } from '@milkdown/utils'
|
|
10
11
|
|
|
11
|
-
import { getFootnoteDefId, getFootnoteRefId } from './utils'
|
|
12
|
+
import { getFootnoteDefId, getFootnoteRefId } from './utils'
|
|
12
13
|
|
|
13
|
-
export const ModifyFootnoteRef = createCmdKey<string>('ModifyFootnoteRef')
|
|
14
|
-
const key = new PluginKey('MILKDOWN_FOOTNOTE_REF_INPUT')
|
|
14
|
+
export const ModifyFootnoteRef = createCmdKey<string>('ModifyFootnoteRef')
|
|
15
|
+
const key = new PluginKey('MILKDOWN_FOOTNOTE_REF_INPUT')
|
|
15
16
|
|
|
16
17
|
export const footnoteReference = createNode((utils) => {
|
|
17
|
-
|
|
18
|
+
const id = 'footnote_reference'
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
return {
|
|
38
|
-
label: dom.dataset['label'],
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
toDOM: (node) => {
|
|
44
|
-
const label = node.attrs['label'];
|
|
45
|
-
const a = document.createElement('a');
|
|
46
|
-
const href = `#${getFootnoteDefId(label)}`;
|
|
47
|
-
a.href = href;
|
|
48
|
-
a.textContent = `[${label}]`;
|
|
49
|
-
a.onclick = (e) => {
|
|
50
|
-
const view = ctx.get(editorViewCtx);
|
|
51
|
-
if (view.editable) {
|
|
52
|
-
e.preventDefault();
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
a.ondblclick = () => {
|
|
56
|
-
const view = ctx.get(editorViewCtx);
|
|
57
|
-
if (view.editable) {
|
|
58
|
-
window.location.href = href;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
return [
|
|
62
|
-
'sup',
|
|
63
|
-
{
|
|
64
|
-
'data-label': label,
|
|
65
|
-
'data-type': id,
|
|
66
|
-
id: getFootnoteRefId(label),
|
|
67
|
-
},
|
|
68
|
-
a,
|
|
69
|
-
];
|
|
70
|
-
},
|
|
71
|
-
parseMarkdown: {
|
|
72
|
-
match: ({ type }) => type === 'footnoteReference',
|
|
73
|
-
runner: (state, node, type) => {
|
|
74
|
-
state.addNode(type, {
|
|
75
|
-
label: node['label'] as string,
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
toMarkdown: {
|
|
80
|
-
match: (node) => node.type.name === id,
|
|
81
|
-
runner: (state, node) => {
|
|
82
|
-
state.addNode('footnoteReference', undefined, undefined, {
|
|
83
|
-
label: node.attrs['label'],
|
|
84
|
-
identifier: node.attrs['label'],
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
}),
|
|
89
|
-
commands: (nodeType) => [
|
|
90
|
-
createCmd(ModifyFootnoteRef, (label = '') => (state, dispatch) => {
|
|
91
|
-
const node = findSelectedNodeOfType(state.selection, nodeType);
|
|
92
|
-
if (!node) return false;
|
|
93
|
-
|
|
94
|
-
const { tr } = state;
|
|
95
|
-
const _tr = tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, label });
|
|
96
|
-
dispatch?.(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
|
|
20
|
+
return {
|
|
21
|
+
id,
|
|
22
|
+
schema: ctx => ({
|
|
23
|
+
group: 'inline',
|
|
24
|
+
inline: true,
|
|
25
|
+
atom: true,
|
|
26
|
+
attrs: {
|
|
27
|
+
label: {
|
|
28
|
+
default: '',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
parseDOM: [
|
|
32
|
+
{
|
|
33
|
+
tag: `sup[data-type="${id}"]`,
|
|
34
|
+
getAttrs: (dom) => {
|
|
35
|
+
if (!(dom instanceof HTMLElement))
|
|
36
|
+
throw expectDomTypeError(dom)
|
|
97
37
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
38
|
+
return {
|
|
39
|
+
label: dom.dataset.label,
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
toDOM: (node) => {
|
|
45
|
+
const label = node.attrs.label
|
|
46
|
+
const a = document.createElement('a')
|
|
47
|
+
const href = `#${getFootnoteDefId(label)}`
|
|
48
|
+
a.href = href
|
|
49
|
+
a.textContent = `[${label}]`
|
|
50
|
+
a.onclick = (e) => {
|
|
51
|
+
const view = ctx.get(editorViewCtx)
|
|
52
|
+
if (view.editable)
|
|
53
|
+
e.preventDefault()
|
|
54
|
+
}
|
|
55
|
+
a.ondblclick = () => {
|
|
56
|
+
const view = ctx.get(editorViewCtx)
|
|
57
|
+
if (view.editable)
|
|
58
|
+
window.location.href = href
|
|
59
|
+
}
|
|
60
|
+
return [
|
|
61
|
+
'sup',
|
|
62
|
+
{
|
|
63
|
+
'data-label': label,
|
|
64
|
+
'data-type': id,
|
|
65
|
+
'id': getFootnoteRefId(label),
|
|
66
|
+
},
|
|
67
|
+
a,
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
parseMarkdown: {
|
|
71
|
+
match: ({ type }) => type === 'footnoteReference',
|
|
72
|
+
runner: (state, node, type) => {
|
|
73
|
+
state.addNode(type, {
|
|
74
|
+
label: node.label as string,
|
|
75
|
+
})
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
toMarkdown: {
|
|
79
|
+
match: node => node.type.name === id,
|
|
80
|
+
runner: (state, node) => {
|
|
81
|
+
state.addNode('footnoteReference', undefined, undefined, {
|
|
82
|
+
label: node.attrs.label,
|
|
83
|
+
identifier: node.attrs.label,
|
|
84
|
+
})
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
commands: nodeType => [
|
|
89
|
+
createCmd(ModifyFootnoteRef, (label = '') => (state, dispatch) => {
|
|
90
|
+
const node = findSelectedNodeOfType(state.selection, nodeType)
|
|
91
|
+
if (!node)
|
|
92
|
+
return false
|
|
134
93
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const renderByView = (view: EditorView) => {
|
|
139
|
-
if (!view.editable) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const display = shouldDisplay(view);
|
|
143
|
-
if (display) {
|
|
144
|
-
inputChipRenderer.show(view);
|
|
145
|
-
inputChipRenderer.update(getCurrentLabel(view));
|
|
146
|
-
} else {
|
|
147
|
-
inputChipRenderer.hide();
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
return [
|
|
151
|
-
new Plugin({
|
|
152
|
-
key,
|
|
153
|
-
view: (editorView) => {
|
|
154
|
-
inputChipRenderer.init(editorView);
|
|
155
|
-
renderByView(editorView);
|
|
94
|
+
const { tr } = state
|
|
95
|
+
const _tr = tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, label })
|
|
96
|
+
dispatch?.(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)))
|
|
156
97
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
98
|
+
return true
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
inputRules: nodeType => [
|
|
102
|
+
new InputRule(/(?:\[\^)([^\]]+)(?:\])$/, (state, match, start, end) => {
|
|
103
|
+
const $start = state.doc.resolve(start)
|
|
104
|
+
const index = $start.index()
|
|
105
|
+
const $end = state.doc.resolve(end)
|
|
106
|
+
if (!$start.parent.canReplaceWith(index, $end.index(), nodeType))
|
|
107
|
+
return null
|
|
162
108
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
109
|
+
const label = match[1]
|
|
110
|
+
return state.tr.replaceRangeWith(
|
|
111
|
+
start,
|
|
112
|
+
end,
|
|
113
|
+
nodeType.create({
|
|
114
|
+
label,
|
|
115
|
+
}),
|
|
116
|
+
)
|
|
117
|
+
}),
|
|
118
|
+
],
|
|
119
|
+
prosePlugins: (type, ctx) => {
|
|
120
|
+
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
121
|
+
width: '12em',
|
|
122
|
+
placeholder: 'Input Footnote Label',
|
|
123
|
+
onUpdate: (value) => {
|
|
124
|
+
ctx.get(commandsCtx).call(ModifyFootnoteRef, value)
|
|
172
125
|
},
|
|
173
|
-
|
|
174
|
-
})
|
|
126
|
+
isBindMode: true,
|
|
127
|
+
})
|
|
128
|
+
if (!inputChipRenderer)
|
|
129
|
+
return []
|
|
130
|
+
const shouldDisplay = (view: EditorView) =>
|
|
131
|
+
Boolean(type && findSelectedNodeOfType(view.state.selection, type))
|
|
132
|
+
const getCurrentLabel = (view: EditorView) => {
|
|
133
|
+
const result = findSelectedNodeOfType(view.state.selection, type)
|
|
134
|
+
if (!result)
|
|
135
|
+
return
|
|
136
|
+
|
|
137
|
+
const value = result.node.attrs.label
|
|
138
|
+
return value
|
|
139
|
+
}
|
|
140
|
+
const renderByView = (view: EditorView) => {
|
|
141
|
+
if (!view.editable)
|
|
142
|
+
return
|
|
143
|
+
|
|
144
|
+
const display = shouldDisplay(view)
|
|
145
|
+
if (display) {
|
|
146
|
+
inputChipRenderer.show(view)
|
|
147
|
+
inputChipRenderer.update(getCurrentLabel(view))
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
inputChipRenderer.hide()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return [
|
|
154
|
+
new Plugin({
|
|
155
|
+
key,
|
|
156
|
+
view: (editorView) => {
|
|
157
|
+
inputChipRenderer.init(editorView)
|
|
158
|
+
renderByView(editorView)
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
update: (view, prevState) => {
|
|
162
|
+
const isEqualSelection
|
|
163
|
+
= prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection)
|
|
164
|
+
if (isEqualSelection)
|
|
165
|
+
return
|
|
166
|
+
|
|
167
|
+
renderByView(view)
|
|
168
|
+
},
|
|
169
|
+
destroy: () => {
|
|
170
|
+
inputChipRenderer.destroy()
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
})
|
package/src/footnote/utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
export const getFootnoteRefId = (label: string) => `footnote-ref-${label}
|
|
2
|
+
export const getFootnoteRefId = (label: string) => `footnote-ref-${label}`
|
|
3
3
|
|
|
4
|
-
export const getFootnoteDefId = (label: string) => `footnote-def-${label}
|
|
4
|
+
export const getFootnoteDefId = (label: string) => `footnote-def-${label}`
|
package/src/index.ts
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { commands as commonmarkCommands
|
|
3
|
-
import { $remark, AtomList } from '@milkdown/utils'
|
|
4
|
-
import remarkGFM from 'remark-gfm'
|
|
2
|
+
import { commonmark, commands as commonmarkCommands } from '@milkdown/preset-commonmark'
|
|
3
|
+
import { $remark, AtomList } from '@milkdown/utils'
|
|
4
|
+
import remarkGFM from 'remark-gfm'
|
|
5
5
|
|
|
6
|
-
import { footnoteReference } from './footnote'
|
|
7
|
-
import { footnoteDefinition } from './footnote/definition'
|
|
8
|
-
import {
|
|
9
|
-
import { table } from './table'
|
|
6
|
+
import { footnoteReference } from './footnote'
|
|
7
|
+
import { footnoteDefinition } from './footnote/definition'
|
|
8
|
+
import { ToggleStrikeThrough, strikeThrough } from './strike-through'
|
|
9
|
+
import { table } from './table'
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} from './task-list-item'
|
|
11
|
+
LiftTaskListItem,
|
|
12
|
+
SinkTaskListItem,
|
|
13
|
+
SplitTaskListItem,
|
|
14
|
+
TurnIntoTaskList,
|
|
15
|
+
taskListItem,
|
|
16
|
+
} from './task-list-item'
|
|
17
17
|
|
|
18
|
-
export * from './footnote'
|
|
19
|
-
export * from './strike-through'
|
|
20
|
-
export { SupportedKeys } from './supported-keys'
|
|
18
|
+
export * from './footnote'
|
|
19
|
+
export * from './strike-through'
|
|
20
|
+
export { SupportedKeys } from './supported-keys'
|
|
21
21
|
export {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} from './table'
|
|
31
|
-
export * from './task-list-item'
|
|
22
|
+
BreakTable,
|
|
23
|
+
// command
|
|
24
|
+
createTable,
|
|
25
|
+
InsertTable,
|
|
26
|
+
NextCell,
|
|
27
|
+
PrevCell,
|
|
28
|
+
// gather
|
|
29
|
+
table,
|
|
30
|
+
} from './table'
|
|
31
|
+
export * from './task-list-item'
|
|
32
32
|
export {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
} from '@milkdown/preset-commonmark'
|
|
33
|
+
blockquote,
|
|
34
|
+
bulletList,
|
|
35
|
+
codeFence,
|
|
36
|
+
codeInline,
|
|
37
|
+
commonmark,
|
|
38
|
+
// gather
|
|
39
|
+
commonmarkNodes,
|
|
40
|
+
commonmarkPlugins,
|
|
41
|
+
// node
|
|
42
|
+
doc,
|
|
43
|
+
em,
|
|
44
|
+
HardbreakFilterPluginKey as hardbreak,
|
|
45
|
+
heading,
|
|
46
|
+
hr,
|
|
47
|
+
image,
|
|
48
|
+
// command
|
|
49
|
+
InsertHardbreak,
|
|
50
|
+
InsertHr,
|
|
51
|
+
InsertImage,
|
|
52
|
+
LiftListItem,
|
|
53
|
+
link,
|
|
54
|
+
listItem,
|
|
55
|
+
ModifyImage,
|
|
56
|
+
ModifyLink,
|
|
57
|
+
orderedList,
|
|
58
|
+
paragraph,
|
|
59
|
+
SinkListItem,
|
|
60
|
+
SplitListItem,
|
|
61
|
+
strong,
|
|
62
|
+
text,
|
|
63
|
+
ToggleBold,
|
|
64
|
+
ToggleInlineCode,
|
|
65
|
+
ToggleItalic,
|
|
66
|
+
ToggleLink,
|
|
67
|
+
TurnIntoCodeFence,
|
|
68
|
+
TurnIntoHeading,
|
|
69
|
+
TurnIntoText,
|
|
70
|
+
WrapInBlockquote,
|
|
71
|
+
WrapInBulletList,
|
|
72
|
+
WrapInOrderedList,
|
|
73
|
+
} from '@milkdown/preset-commonmark'
|
|
74
74
|
|
|
75
75
|
export const gfm = AtomList.create([
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
])
|
|
76
|
+
...commonmark,
|
|
77
|
+
$remark(() => remarkGFM),
|
|
78
|
+
table(),
|
|
79
|
+
strikeThrough(),
|
|
80
|
+
taskListItem(),
|
|
81
|
+
footnoteReference(),
|
|
82
|
+
footnoteDefinition(),
|
|
83
|
+
])
|
|
84
84
|
|
|
85
85
|
export const commands = {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} as const
|
|
93
|
-
export type Commands = typeof commands
|
|
86
|
+
...commonmarkCommands,
|
|
87
|
+
ToggleStrikeThrough,
|
|
88
|
+
TurnIntoTaskList,
|
|
89
|
+
SinkTaskListItem,
|
|
90
|
+
LiftTaskListItem,
|
|
91
|
+
SplitTaskListItem,
|
|
92
|
+
} as const
|
|
93
|
+
export type Commands = typeof commands
|
package/src/strike-through.ts
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
-
import { toggleMark } from '@milkdown/prose/commands'
|
|
4
|
-
import { createMark, createShortcut } from '@milkdown/utils'
|
|
2
|
+
import { createCmd, createCmdKey } from '@milkdown/core'
|
|
3
|
+
import { toggleMark } from '@milkdown/prose/commands'
|
|
4
|
+
import { createMark, createShortcut } from '@milkdown/utils'
|
|
5
5
|
|
|
6
|
-
import { SupportedKeys } from './supported-keys'
|
|
6
|
+
import { SupportedKeys } from './supported-keys'
|
|
7
7
|
|
|
8
|
-
type Keys = SupportedKeys['StrikeThrough']
|
|
8
|
+
type Keys = SupportedKeys['StrikeThrough']
|
|
9
9
|
|
|
10
|
-
export const ToggleStrikeThrough = createCmdKey('ToggleStrikeThrough')
|
|
10
|
+
export const ToggleStrikeThrough = createCmdKey('ToggleStrikeThrough')
|
|
11
11
|
|
|
12
|
-
const id = 'strike_through'
|
|
12
|
+
const id = 'strike_through'
|
|
13
13
|
export const strikeThrough = createMark<Keys>((utils) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
toMarkdown: {
|
|
32
|
-
match: (mark) => mark.type.name === id,
|
|
33
|
-
runner: (state, mark) => {
|
|
34
|
-
state.withMark(mark, 'delete');
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
}),
|
|
38
|
-
commands: (markType) => [createCmd(ToggleStrikeThrough, () => toggleMark(markType))],
|
|
39
|
-
shortcuts: {
|
|
40
|
-
[SupportedKeys.StrikeThrough]: createShortcut(ToggleStrikeThrough, 'Mod-Alt-x'),
|
|
14
|
+
return {
|
|
15
|
+
id,
|
|
16
|
+
schema: () => ({
|
|
17
|
+
inclusive: false,
|
|
18
|
+
parseDOM: [
|
|
19
|
+
{ tag: 'del' },
|
|
20
|
+
{ style: 'text-decoration', getAttrs: value => (value === 'line-through') as false },
|
|
21
|
+
],
|
|
22
|
+
toDOM: mark => ['del', { class: utils.getClassName(mark.attrs, 'strike-through') }],
|
|
23
|
+
parseMarkdown: {
|
|
24
|
+
match: node => node.type === 'delete',
|
|
25
|
+
runner: (state, node, markType) => {
|
|
26
|
+
state.openMark(markType)
|
|
27
|
+
state.next(node.children)
|
|
28
|
+
state.closeMark(markType)
|
|
41
29
|
},
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
},
|
|
31
|
+
toMarkdown: {
|
|
32
|
+
match: mark => mark.type.name === id,
|
|
33
|
+
runner: (state, mark) => {
|
|
34
|
+
state.withMark(mark, 'delete')
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}),
|
|
38
|
+
commands: markType => [createCmd(ToggleStrikeThrough, () => toggleMark(markType))],
|
|
39
|
+
shortcuts: {
|
|
40
|
+
[SupportedKeys.StrikeThrough]: createShortcut(ToggleStrikeThrough, 'Mod-Alt-x'),
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
})
|
package/src/supported-keys.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { SupportedKeys as CommonmarkKeys } from '@milkdown/preset-commonmark'
|
|
2
|
+
import { SupportedKeys as CommonmarkKeys } from '@milkdown/preset-commonmark'
|
|
3
3
|
|
|
4
|
-
import { SupportedKeys as TableKeys } from './table'
|
|
4
|
+
import { SupportedKeys as TableKeys } from './table'
|
|
5
5
|
|
|
6
6
|
export const SupportedKeys = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} as const
|
|
12
|
-
|
|
7
|
+
...CommonmarkKeys,
|
|
8
|
+
...TableKeys,
|
|
9
|
+
StrikeThrough: 'StrikeThrough',
|
|
10
|
+
TaskList: 'TaskList',
|
|
11
|
+
} as const
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
13
|
+
export type SupportedKeys = typeof SupportedKeys
|
package/src/table/command.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Node, NodeType } from '@milkdown/prose/model'
|
|
3
|
-
import { Command
|
|
2
|
+
import type { Node, NodeType } from '@milkdown/prose/model'
|
|
3
|
+
import type { Command } from '@milkdown/prose/state'
|
|
4
|
+
import { Selection } from '@milkdown/prose/state'
|
|
4
5
|
|
|
5
|
-
import { isInTable } from './plugin/util'
|
|
6
|
+
import { isInTable } from './plugin/util'
|
|
6
7
|
|
|
7
|
-
export const exitTable
|
|
8
|
-
(node: NodeType): Command =>
|
|
9
|
-
|
|
10
|
-
if (!isInTable(state))
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const { $head } = state.selection
|
|
14
|
-
const pos = $head.after()
|
|
15
|
-
const tr = state.tr.replaceWith(pos, pos, node.createAndFill() as Node)
|
|
16
|
-
tr.setSelection(Selection.near(tr.doc.resolve(pos), 1))
|
|
17
|
-
dispatch?.(tr.scrollIntoView())
|
|
18
|
-
return true
|
|
19
|
-
|
|
8
|
+
export const exitTable
|
|
9
|
+
= (node: NodeType): Command =>
|
|
10
|
+
(state, dispatch) => {
|
|
11
|
+
if (!isInTable(state))
|
|
12
|
+
return false
|
|
13
|
+
|
|
14
|
+
const { $head } = state.selection
|
|
15
|
+
const pos = $head.after()
|
|
16
|
+
const tr = state.tr.replaceWith(pos, pos, node.createAndFill() as Node)
|
|
17
|
+
tr.setSelection(Selection.near(tr.doc.resolve(pos), 1))
|
|
18
|
+
dispatch?.(tr.scrollIntoView())
|
|
19
|
+
return true
|
|
20
|
+
}
|