@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,181 +1,187 @@
|
|
|
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 { wrappingInputRule } 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
|
-
const key = new PluginKey('MILKDOWN_FOOTNOTE_DEF_INPUT')
|
|
14
|
-
export const ModifyFootnoteDef = createCmdKey<string>('ModifyFootnoteDef')
|
|
14
|
+
const key = new PluginKey('MILKDOWN_FOOTNOTE_DEF_INPUT')
|
|
15
|
+
export const ModifyFootnoteDef = createCmdKey<string>('ModifyFootnoteDef')
|
|
15
16
|
|
|
16
17
|
export const footnoteDefinition = createNode((utils) => {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
const id = 'footnote_definition'
|
|
19
|
+
const markdownId = 'footnoteDefinition'
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
label: dom.dataset['label'],
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
contentElement: 'dd',
|
|
43
|
-
},
|
|
44
|
-
],
|
|
45
|
-
toDOM: (node) => {
|
|
46
|
-
const label = node.attrs['label'];
|
|
47
|
-
const className = utils.getClassName(node.attrs, 'footnote-definition');
|
|
21
|
+
return {
|
|
22
|
+
id,
|
|
23
|
+
schema: ctx => ({
|
|
24
|
+
group: 'block',
|
|
25
|
+
content: 'block+',
|
|
26
|
+
defining: true,
|
|
27
|
+
attrs: {
|
|
28
|
+
label: {
|
|
29
|
+
default: '',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
parseDOM: [
|
|
33
|
+
{
|
|
34
|
+
tag: `div[data-type="${id}"]`,
|
|
35
|
+
getAttrs: (dom) => {
|
|
36
|
+
if (!(dom instanceof HTMLElement))
|
|
37
|
+
throw expectDomTypeError(dom)
|
|
48
38
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
39
|
+
return {
|
|
40
|
+
label: dom.dataset.label,
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
contentElement: 'dd',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
toDOM: (node) => {
|
|
47
|
+
const label = node.attrs.label
|
|
48
|
+
const className = utils.getClassName(node.attrs, 'footnote-definition')
|
|
56
49
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
const dt = document.createElement('dt')
|
|
51
|
+
dt.textContent = `[${label}]:`
|
|
52
|
+
dt.onclick = () => {
|
|
53
|
+
const view = ctx.get(editorViewCtx)
|
|
54
|
+
const selection = NodeSelection.create(view.state.doc, view.state.selection.from - 2)
|
|
55
|
+
view.dispatch(view.state.tr.setSelection(selection))
|
|
56
|
+
}
|
|
64
57
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
58
|
+
const a = document.createElement('a')
|
|
59
|
+
a.href = `#${getFootnoteRefId(label)}`
|
|
60
|
+
a.contentEditable = 'false'
|
|
61
|
+
a.textContent = '↩'
|
|
62
|
+
a.onmousedown = (e) => {
|
|
63
|
+
e.preventDefault()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return [
|
|
67
|
+
'div',
|
|
68
|
+
{
|
|
69
|
+
'class': className,
|
|
70
|
+
'data-label': label,
|
|
71
|
+
'data-type': id,
|
|
72
|
+
'id': getFootnoteDefId(label),
|
|
73
|
+
},
|
|
74
|
+
['div', { class: 'footnote-definition_content' }, dt, ['dd', 0]],
|
|
75
|
+
['div', { class: 'footnote-definition_anchor' }, a],
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
parseMarkdown: {
|
|
79
|
+
match: ({ type }) => type === markdownId,
|
|
80
|
+
runner: (state, node, type) => {
|
|
81
|
+
state
|
|
82
|
+
.openNode(type, {
|
|
83
|
+
label: node.label as string,
|
|
84
|
+
})
|
|
85
|
+
.next(node.children)
|
|
86
|
+
.closeNode()
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
toMarkdown: {
|
|
90
|
+
match: node => node.type.name === id,
|
|
91
|
+
runner: (state, node) => {
|
|
92
|
+
state
|
|
93
|
+
.openNode(markdownId, undefined, {
|
|
94
|
+
label: node.attrs.label,
|
|
95
|
+
identifier: node.attrs.label,
|
|
96
|
+
})
|
|
97
|
+
.next(node.content)
|
|
98
|
+
.closeNode()
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
commands: nodeType => [
|
|
103
|
+
createCmd(ModifyFootnoteDef, (label = '') => (state, dispatch) => {
|
|
104
|
+
const node = findSelectedNodeOfType(state.selection, nodeType)
|
|
105
|
+
if (!node)
|
|
106
|
+
return false
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
const { tr } = state
|
|
109
|
+
const _tr = tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, label })
|
|
110
|
+
dispatch?.(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)))
|
|
109
111
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
112
|
+
return true
|
|
113
|
+
}),
|
|
114
|
+
],
|
|
115
|
+
inputRules: nodeType => [
|
|
116
|
+
wrappingInputRule(
|
|
117
|
+
/(?:\[\^)([^:]+)(?::)$/,
|
|
118
|
+
nodeType,
|
|
119
|
+
(match) => {
|
|
120
|
+
const label = match[1] ?? 'footnote'
|
|
121
|
+
return {
|
|
122
|
+
label,
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
() => false,
|
|
126
|
+
),
|
|
127
|
+
],
|
|
128
|
+
prosePlugins: (type, ctx) => {
|
|
129
|
+
return [
|
|
130
|
+
new Plugin({
|
|
131
|
+
key,
|
|
132
|
+
view: (editorView) => {
|
|
133
|
+
const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
|
|
134
|
+
width: '12em',
|
|
135
|
+
placeholder: 'Input Footnote Label',
|
|
136
|
+
onUpdate: (value) => {
|
|
137
|
+
ctx.get(commandsCtx).call(ModifyFootnoteDef, value)
|
|
138
|
+
},
|
|
139
|
+
isBindMode: true,
|
|
140
|
+
})
|
|
141
|
+
if (!inputChipRenderer)
|
|
142
|
+
return {}
|
|
143
|
+
const shouldDisplay = (view: EditorView) =>
|
|
144
|
+
Boolean(type && findSelectedNodeOfType(view.state.selection, type))
|
|
145
|
+
const getCurrentLabel = (view: EditorView) => {
|
|
146
|
+
const result = findSelectedNodeOfType(view.state.selection, type)
|
|
147
|
+
if (!result)
|
|
148
|
+
return
|
|
145
149
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
const display = shouldDisplay(view);
|
|
154
|
-
if (display) {
|
|
155
|
-
inputChipRenderer.show(view);
|
|
156
|
-
inputChipRenderer.update(getCurrentLabel(view));
|
|
157
|
-
} else {
|
|
158
|
-
inputChipRenderer.hide();
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
inputChipRenderer.init(editorView);
|
|
162
|
-
renderByView(editorView);
|
|
150
|
+
const value = result.node.attrs.label
|
|
151
|
+
return value
|
|
152
|
+
}
|
|
153
|
+
const renderByView = (view: EditorView) => {
|
|
154
|
+
if (!view.editable)
|
|
155
|
+
return
|
|
163
156
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
157
|
+
const display = shouldDisplay(view)
|
|
158
|
+
if (display) {
|
|
159
|
+
inputChipRenderer.show(view)
|
|
160
|
+
inputChipRenderer.update(getCurrentLabel(view))
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
inputChipRenderer.hide()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
inputChipRenderer.init(editorView)
|
|
167
|
+
renderByView(editorView)
|
|
169
168
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
169
|
+
return {
|
|
170
|
+
update: (view, prevState) => {
|
|
171
|
+
const isEqualSelection
|
|
172
|
+
= prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection)
|
|
173
|
+
if (isEqualSelection)
|
|
174
|
+
return
|
|
175
|
+
|
|
176
|
+
renderByView(view)
|
|
177
|
+
},
|
|
178
|
+
destroy: () => {
|
|
179
|
+
inputChipRenderer.destroy()
|
|
180
|
+
},
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
}),
|
|
184
|
+
]
|
|
185
|
+
},
|
|
186
|
+
}
|
|
187
|
+
})
|
package/src/footnote/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
export * from './definition'
|
|
3
|
-
export * from './reference'
|
|
2
|
+
export * from './definition'
|
|
3
|
+
export * from './reference'
|