@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.
Files changed (94) hide show
  1. package/lib/footnote/definition.d.ts +1 -1
  2. package/lib/footnote/definition.d.ts.map +1 -1
  3. package/lib/footnote/index.d.ts.map +1 -1
  4. package/lib/footnote/reference.d.ts +1 -1
  5. package/lib/footnote/reference.d.ts.map +1 -1
  6. package/lib/footnote/utils.d.ts.map +1 -1
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.es.js +649 -607
  10. package/lib/index.es.js.map +1 -1
  11. package/lib/strike-through.d.ts +1 -1
  12. package/lib/strike-through.d.ts.map +1 -1
  13. package/lib/supported-keys.d.ts +1 -1
  14. package/lib/supported-keys.d.ts.map +1 -1
  15. package/lib/table/command.d.ts +2 -2
  16. package/lib/table/command.d.ts.map +1 -1
  17. package/lib/table/index.d.ts +1 -1
  18. package/lib/table/index.d.ts.map +1 -1
  19. package/lib/table/nodes/index.d.ts +1 -1
  20. package/lib/table/nodes/index.d.ts.map +1 -1
  21. package/lib/table/operator-plugin/actions.d.ts +5 -5
  22. package/lib/table/operator-plugin/actions.d.ts.map +1 -1
  23. package/lib/table/operator-plugin/calc-pos.d.ts +1 -1
  24. package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
  25. package/lib/table/operator-plugin/constant.d.ts.map +1 -1
  26. package/lib/table/operator-plugin/helper.d.ts +3 -3
  27. package/lib/table/operator-plugin/helper.d.ts.map +1 -1
  28. package/lib/table/operator-plugin/index.d.ts +2 -2
  29. package/lib/table/operator-plugin/index.d.ts.map +1 -1
  30. package/lib/table/operator-plugin/style.d.ts +1 -1
  31. package/lib/table/operator-plugin/style.d.ts.map +1 -1
  32. package/lib/table/operator-plugin/widget.d.ts +2 -2
  33. package/lib/table/operator-plugin/widget.d.ts.map +1 -1
  34. package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -1
  35. package/lib/table/plugin/cell-selection.d.ts +5 -3
  36. package/lib/table/plugin/cell-selection.d.ts.map +1 -1
  37. package/lib/table/plugin/column-resizing.d.ts +2 -1
  38. package/lib/table/plugin/column-resizing.d.ts.map +1 -1
  39. package/lib/table/plugin/commands.d.ts +2 -2
  40. package/lib/table/plugin/commands.d.ts.map +1 -1
  41. package/lib/table/plugin/copy-paste.d.ts +6 -5
  42. package/lib/table/plugin/copy-paste.d.ts.map +1 -1
  43. package/lib/table/plugin/fix-tables.d.ts +3 -2
  44. package/lib/table/plugin/fix-tables.d.ts.map +1 -1
  45. package/lib/table/plugin/index.d.ts.map +1 -1
  46. package/lib/table/plugin/schema.d.ts +1 -1
  47. package/lib/table/plugin/schema.d.ts.map +1 -1
  48. package/lib/table/plugin/table-editing.d.ts +1 -1
  49. package/lib/table/plugin/table-editing.d.ts.map +1 -1
  50. package/lib/table/plugin/table-map.d.ts +2 -2
  51. package/lib/table/plugin/table-map.d.ts.map +1 -1
  52. package/lib/table/plugin/table-view.d.ts +2 -2
  53. package/lib/table/plugin/table-view.d.ts.map +1 -1
  54. package/lib/table/plugin/types.d.ts +2 -2
  55. package/lib/table/plugin/types.d.ts.map +1 -1
  56. package/lib/table/plugin/util.d.ts +2 -2
  57. package/lib/table/plugin/util.d.ts.map +1 -1
  58. package/lib/table/utils.d.ts +5 -5
  59. package/lib/table/utils.d.ts.map +1 -1
  60. package/lib/task-list-item.d.ts +2 -2
  61. package/lib/task-list-item.d.ts.map +1 -1
  62. package/package.json +17 -17
  63. package/src/footnote/definition.ts +172 -166
  64. package/src/footnote/index.ts +2 -2
  65. package/src/footnote/reference.ts +166 -162
  66. package/src/footnote/utils.ts +2 -2
  67. package/src/index.ts +83 -83
  68. package/src/strike-through.ts +36 -36
  69. package/src/supported-keys.ts +9 -8
  70. package/src/table/command.ts +17 -16
  71. package/src/table/index.ts +9 -9
  72. package/src/table/nodes/index.ts +177 -174
  73. package/src/table/operator-plugin/actions.ts +103 -102
  74. package/src/table/operator-plugin/calc-pos.ts +31 -34
  75. package/src/table/operator-plugin/constant.ts +3 -3
  76. package/src/table/operator-plugin/helper.ts +31 -32
  77. package/src/table/operator-plugin/index.ts +104 -95
  78. package/src/table/operator-plugin/style.ts +10 -9
  79. package/src/table/operator-plugin/widget.ts +47 -45
  80. package/src/table/plugin/auto-insert-zero-space.ts +41 -41
  81. package/src/table/plugin/cell-selection.ts +325 -296
  82. package/src/table/plugin/column-resizing.ts +226 -198
  83. package/src/table/plugin/commands.ts +464 -421
  84. package/src/table/plugin/copy-paste.ts +256 -240
  85. package/src/table/plugin/fix-tables.ts +103 -88
  86. package/src/table/plugin/index.ts +3 -3
  87. package/src/table/plugin/schema.ts +100 -94
  88. package/src/table/plugin/table-editing.ts +324 -230
  89. package/src/table/plugin/table-map.ts +294 -229
  90. package/src/table/plugin/table-view.ts +66 -62
  91. package/src/table/plugin/types.ts +8 -8
  92. package/src/table/plugin/util.ts +78 -66
  93. package/src/table/utils.ts +141 -138
  94. package/src/task-list-item.ts +151 -146
@@ -1,174 +1,178 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
- import { commandsCtx, createCmd, createCmdKey, editorViewCtx, ThemeInputChipType } from '@milkdown/core';
4
- import { expectDomTypeError } from '@milkdown/exception';
5
- import { findSelectedNodeOfType } from '@milkdown/prose';
6
- import { InputRule } from '@milkdown/prose/inputrules';
7
- import { NodeSelection, Plugin, PluginKey } from '@milkdown/prose/state';
8
- import { EditorView } from '@milkdown/prose/view';
9
- import { createNode } from '@milkdown/utils';
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
- const id = 'footnote_reference';
18
+ const id = 'footnote_reference'
18
19
 
19
- return {
20
- id,
21
- schema: (ctx) => ({
22
- group: 'inline',
23
- inline: true,
24
- atom: true,
25
- attrs: {
26
- label: {
27
- default: '',
28
- },
29
- },
30
- parseDOM: [
31
- {
32
- tag: `sup[data-type="${id}"]`,
33
- getAttrs: (dom) => {
34
- if (!(dom instanceof HTMLElement)) {
35
- throw expectDomTypeError(dom);
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
- 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;
108
- }
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);
125
- },
126
- isBindMode: true,
127
- });
128
- if (!inputChipRenderer) return [];
129
- const shouldDisplay = (view: EditorView) =>
130
- Boolean(type && findSelectedNodeOfType(view.state.selection, type));
131
- const getCurrentLabel = (view: EditorView) => {
132
- const result = findSelectedNodeOfType(view.state.selection, type);
133
- if (!result) return;
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
- const value = result.node.attrs['label'];
136
- return value;
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
- return {
158
- update: (view, prevState) => {
159
- const isEqualSelection =
160
- prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
161
- if (isEqualSelection) return;
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
- renderByView(view);
164
- },
165
- destroy: () => {
166
- inputChipRenderer.destroy();
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
+ })
@@ -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, commonmark } from '@milkdown/preset-commonmark';
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 { strikeThrough, ToggleStrikeThrough } from './strike-through';
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
- LiftTaskListItem,
12
- SinkTaskListItem,
13
- SplitTaskListItem,
14
- taskListItem,
15
- TurnIntoTaskList,
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
- BreakTable,
23
- // command
24
- createTable,
25
- InsertTable,
26
- NextCell,
27
- PrevCell,
28
- // gather
29
- table,
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
- 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';
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
- ...commonmark,
77
- $remark(() => remarkGFM),
78
- table(),
79
- strikeThrough(),
80
- taskListItem(),
81
- footnoteReference(),
82
- footnoteDefinition(),
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
- ...commonmarkCommands,
87
- ToggleStrikeThrough,
88
- TurnIntoTaskList,
89
- SinkTaskListItem,
90
- LiftTaskListItem,
91
- SplitTaskListItem,
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
@@ -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
- 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);
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
+ })
@@ -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
- ...CommonmarkKeys,
8
- ...TableKeys,
9
- StrikeThrough: 'StrikeThrough',
10
- TaskList: 'TaskList',
11
- } as const;
12
- export type SupportedKeys = typeof SupportedKeys;
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
@@ -1,19 +1,20 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Node, NodeType } from '@milkdown/prose/model';
3
- import { Command, Selection } from '@milkdown/prose/state';
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
- (state, dispatch) => {
10
- if (!isInTable(state)) {
11
- return false;
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
+ }