@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,181 +1,187 @@
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 { wrappingInputRule } 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 { 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
- const id = 'footnote_definition';
18
- const markdownId = 'footnoteDefinition';
18
+ const id = 'footnote_definition'
19
+ const markdownId = 'footnoteDefinition'
19
20
 
20
- return {
21
- id,
22
- schema: (ctx) => ({
23
- group: 'block',
24
- content: 'block+',
25
- defining: true,
26
- attrs: {
27
- label: {
28
- default: '',
29
- },
30
- },
31
- parseDOM: [
32
- {
33
- tag: `div[data-type="${id}"]`,
34
- getAttrs: (dom) => {
35
- if (!(dom instanceof HTMLElement)) {
36
- throw expectDomTypeError(dom);
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
- const dt = document.createElement('dt');
50
- dt.textContent = `[${label}]:`;
51
- dt.onclick = () => {
52
- const view = ctx.get(editorViewCtx);
53
- const selection = NodeSelection.create(view.state.doc, view.state.selection.from - 2);
54
- view.dispatch(view.state.tr.setSelection(selection));
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
- const a = document.createElement('a');
58
- a.href = `#${getFootnoteRefId(label)}`;
59
- a.contentEditable = 'false';
60
- a.textContent = '↩';
61
- a.onmousedown = (e) => {
62
- e.preventDefault();
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
- return [
66
- 'div',
67
- {
68
- class: className,
69
- 'data-label': label,
70
- 'data-type': id,
71
- id: getFootnoteDefId(label),
72
- },
73
- ['div', { class: 'footnote-definition_content' }, dt, ['dd', 0]],
74
- ['div', { class: 'footnote-definition_anchor' }, a],
75
- ];
76
- },
77
- parseMarkdown: {
78
- match: ({ type }) => type === markdownId,
79
- runner: (state, node, type) => {
80
- state
81
- .openNode(type, {
82
- label: node['label'] as string,
83
- })
84
- .next(node.children)
85
- .closeNode();
86
- },
87
- },
88
- toMarkdown: {
89
- match: (node) => node.type.name === id,
90
- runner: (state, node) => {
91
- state
92
- .openNode(markdownId, undefined, {
93
- label: node.attrs['label'],
94
- identifier: node.attrs['label'],
95
- })
96
- .next(node.content)
97
- .closeNode();
98
- },
99
- },
100
- }),
101
- commands: (nodeType) => [
102
- createCmd(ModifyFootnoteDef, (label = '') => (state, dispatch) => {
103
- const node = findSelectedNodeOfType(state.selection, nodeType);
104
- if (!node) return false;
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
- const { tr } = state;
107
- const _tr = tr.setNodeMarkup(node.pos, undefined, { ...node.node.attrs, label });
108
- dispatch?.(_tr.setSelection(NodeSelection.create(_tr.doc, node.pos)));
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
- return true;
111
- }),
112
- ],
113
- inputRules: (nodeType) => [
114
- wrappingInputRule(
115
- /(?:\[\^)([^:]+)(?::)$/,
116
- nodeType,
117
- (match) => {
118
- const label = match[1] ?? 'footnote';
119
- return {
120
- label,
121
- };
122
- },
123
- () => false,
124
- ),
125
- ],
126
- prosePlugins: (type, ctx) => {
127
- return [
128
- new Plugin({
129
- key,
130
- view: (editorView) => {
131
- const inputChipRenderer = utils.themeManager.get<ThemeInputChipType>('input-chip', {
132
- width: '12em',
133
- placeholder: 'Input Footnote Label',
134
- onUpdate: (value) => {
135
- ctx.get(commandsCtx).call(ModifyFootnoteDef, value);
136
- },
137
- isBindMode: true,
138
- });
139
- if (!inputChipRenderer) return {};
140
- const shouldDisplay = (view: EditorView) =>
141
- Boolean(type && findSelectedNodeOfType(view.state.selection, type));
142
- const getCurrentLabel = (view: EditorView) => {
143
- const result = findSelectedNodeOfType(view.state.selection, type);
144
- if (!result) return;
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
- const value = result.node.attrs['label'];
147
- return value;
148
- };
149
- const renderByView = (view: EditorView) => {
150
- if (!view.editable) {
151
- return;
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
- return {
165
- update: (view, prevState) => {
166
- const isEqualSelection =
167
- prevState?.doc.eq(view.state.doc) && prevState.selection.eq(view.state.selection);
168
- if (isEqualSelection) return;
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
- renderByView(view);
171
- },
172
- destroy: () => {
173
- inputChipRenderer.destroy();
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
+ })
@@ -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'