@milkdown/preset-gfm 7.4.0 → 7.5.8

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 (54) hide show
  1. package/lib/__internal__/with-meta.d.ts.map +1 -1
  2. package/lib/composed/commands.d.ts +9 -5
  3. package/lib/composed/commands.d.ts.map +1 -1
  4. package/lib/composed/inputrules.d.ts.map +1 -1
  5. package/lib/composed/schema.d.ts.map +1 -1
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.es.js +816 -669
  8. package/lib/index.es.js.map +1 -1
  9. package/lib/mark/strike-through.d.ts.map +1 -1
  10. package/lib/node/footnote/definition.d.ts.map +1 -1
  11. package/lib/node/footnote/reference.d.ts.map +1 -1
  12. package/lib/node/table/command.d.ts +33 -0
  13. package/lib/node/table/command.d.ts.map +1 -0
  14. package/lib/node/table/index.d.ts +3 -30
  15. package/lib/node/table/index.d.ts.map +1 -1
  16. package/lib/node/table/input.d.ts +3 -0
  17. package/lib/node/table/input.d.ts.map +1 -0
  18. package/lib/node/table/schema.d.ts +6 -0
  19. package/lib/node/table/schema.d.ts.map +1 -0
  20. package/lib/node/table/utils.d.ts +21 -7
  21. package/lib/node/table/utils.d.ts.map +1 -1
  22. package/lib/node/task-list-item.d.ts.map +1 -1
  23. package/lib/plugin/auto-insert-span-plugin.d.ts +2 -0
  24. package/lib/plugin/auto-insert-span-plugin.d.ts.map +1 -0
  25. package/lib/plugin/index.d.ts +2 -1
  26. package/lib/plugin/index.d.ts.map +1 -1
  27. package/lib/plugin/keep-table-align-plugin.d.ts +2 -0
  28. package/lib/plugin/keep-table-align-plugin.d.ts.map +1 -0
  29. package/lib/plugin/remark-gfm-plugin.d.ts.map +1 -1
  30. package/lib/plugin/table-editing-plugin.d.ts.map +1 -1
  31. package/package.json +12 -17
  32. package/src/__internal__/with-meta.ts +4 -1
  33. package/src/composed/commands.ts +18 -2
  34. package/src/composed/inputrules.ts +1 -3
  35. package/src/composed/plugins.ts +4 -4
  36. package/src/composed/schema.ts +11 -1
  37. package/src/index.ts +16 -2
  38. package/src/mark/strike-through.ts +21 -9
  39. package/src/node/footnote/definition.ts +56 -54
  40. package/src/node/footnote/reference.ts +47 -45
  41. package/src/node/table/command.ts +304 -0
  42. package/src/node/table/index.ts +3 -450
  43. package/src/node/table/input.ts +90 -0
  44. package/src/node/table/schema.ts +215 -0
  45. package/src/node/table/utils.ts +163 -96
  46. package/src/node/task-list-item.ts +100 -88
  47. package/src/plugin/auto-insert-span-plugin.ts +12 -0
  48. package/src/plugin/index.ts +2 -1
  49. package/src/plugin/keep-table-align-plugin.ts +53 -0
  50. package/src/plugin/remark-gfm-plugin.ts +2 -1
  51. package/src/plugin/table-editing-plugin.ts +3 -1
  52. package/lib/plugin/auto-insert-zero-space-plugin.d.ts +0 -2
  53. package/lib/plugin/auto-insert-zero-space-plugin.d.ts.map +0 -1
  54. package/src/plugin/auto-insert-zero-space-plugin.ts +0 -55
@@ -0,0 +1,304 @@
1
+ import { paragraphSchema } from '@milkdown/preset-commonmark'
2
+ import { Selection } from '@milkdown/prose/state'
3
+ import {
4
+ CellSelection,
5
+ addColumnAfter,
6
+ addColumnBefore,
7
+ deleteColumn,
8
+ deleteRow,
9
+ deleteTable,
10
+ goToNextCell,
11
+ isInTable,
12
+ selectedRect,
13
+ setCellAttr,
14
+ } from '@milkdown/prose/tables'
15
+ import { $command } from '@milkdown/utils'
16
+ import { findParentNodeType } from '@milkdown/prose'
17
+ import { withMeta } from '../../__internal__'
18
+ import {
19
+ addRowWithAlignment,
20
+ createTable,
21
+ moveCol,
22
+ moveRow,
23
+ selectCol,
24
+ selectRow,
25
+ selectTable,
26
+ } from './utils'
27
+ import { tableSchema } from './schema'
28
+
29
+ /// A command for moving cursor to previous cell.
30
+ export const goToPrevTableCellCommand = $command(
31
+ 'GoToPrevTableCell',
32
+ () => () => goToNextCell(-1)
33
+ )
34
+
35
+ withMeta(goToPrevTableCellCommand, {
36
+ displayName: 'Command<goToPrevTableCellCommand>',
37
+ group: 'Table',
38
+ })
39
+
40
+ /// A command for moving cursor to next cell.
41
+ export const goToNextTableCellCommand = $command(
42
+ 'GoToNextTableCell',
43
+ () => () => goToNextCell(1)
44
+ )
45
+
46
+ withMeta(goToNextTableCellCommand, {
47
+ displayName: 'Command<goToNextTableCellCommand>',
48
+ group: 'Table',
49
+ })
50
+
51
+ /// A command for quitting current table and insert a new paragraph node.
52
+ export const exitTable = $command(
53
+ 'ExitTable',
54
+ (ctx) => () => (state, dispatch) => {
55
+ if (!isInTable(state)) return false
56
+
57
+ const { $head } = state.selection
58
+ const table = findParentNodeType($head, tableSchema.type(ctx))
59
+ if (!table) return false
60
+
61
+ const { to } = table
62
+
63
+ const tr = state.tr.replaceWith(
64
+ to,
65
+ to,
66
+ paragraphSchema.type(ctx).createAndFill()!
67
+ )
68
+
69
+ tr.setSelection(Selection.near(tr.doc.resolve(to), 1)).scrollIntoView()
70
+ dispatch?.(tr)
71
+ return true
72
+ }
73
+ )
74
+
75
+ withMeta(exitTable, {
76
+ displayName: 'Command<breakTableCommand>',
77
+ group: 'Table',
78
+ })
79
+
80
+ /// A command for inserting a table.
81
+ /// You can specify the number of rows and columns.
82
+ /// By default, it will insert a 3x3 table.
83
+ export const insertTableCommand = $command(
84
+ 'InsertTable',
85
+ (ctx) =>
86
+ ({ row, col }: { row?: number; col?: number } = {}) =>
87
+ (state, dispatch) => {
88
+ const { selection, tr } = state
89
+ const { from } = selection
90
+ const table = createTable(ctx, row, col)
91
+ const _tr = tr.replaceSelectionWith(table)
92
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true)
93
+ if (sel) _tr.setSelection(sel)
94
+
95
+ dispatch?.(_tr)
96
+
97
+ return true
98
+ }
99
+ )
100
+
101
+ withMeta(insertTableCommand, {
102
+ displayName: 'Command<insertTableCommand>',
103
+ group: 'Table',
104
+ })
105
+
106
+ /// A command for moving a row in a table.
107
+ /// You should specify the `from` and `to` index.
108
+ export const moveRowCommand = $command(
109
+ 'MoveRow',
110
+ () =>
111
+ ({ from, to, pos }: { from?: number; to?: number; pos?: number } = {}) =>
112
+ (state, dispatch) => {
113
+ const { tr } = state
114
+ const result = dispatch?.(
115
+ moveRow({ tr, origin: from ?? 0, target: to ?? 0, pos, select: true })
116
+ )
117
+
118
+ return Boolean(result)
119
+ }
120
+ )
121
+
122
+ withMeta(moveRowCommand, {
123
+ displayName: 'Command<moveRowCommand>',
124
+ group: 'Table',
125
+ })
126
+
127
+ /// A command for moving a column in a table.
128
+ /// You should specify the `from` and `to` index.
129
+ export const moveColCommand = $command(
130
+ 'MoveCol',
131
+ () =>
132
+ ({ from, to, pos }: { from?: number; to?: number; pos?: number } = {}) =>
133
+ (state, dispatch) => {
134
+ const { tr } = state
135
+ const result = dispatch?.(
136
+ moveCol({ tr, origin: from ?? 0, target: to ?? 0, pos, select: true })
137
+ )
138
+
139
+ return Boolean(result)
140
+ }
141
+ )
142
+
143
+ withMeta(moveColCommand, {
144
+ displayName: 'Command<moveColCommand>',
145
+ group: 'Table',
146
+ })
147
+
148
+ /// A command for selecting a row.
149
+ export const selectRowCommand = $command<
150
+ { index: number; pos?: number },
151
+ 'SelectRow'
152
+ >(
153
+ 'SelectRow',
154
+ () =>
155
+ (payload: { index: number; pos?: number } = { index: 0 }) =>
156
+ (state, dispatch) => {
157
+ const { tr } = state
158
+ const result = dispatch?.(selectRow(payload.index, payload.pos)(tr))
159
+
160
+ return Boolean(result)
161
+ }
162
+ )
163
+
164
+ withMeta(selectRowCommand, {
165
+ displayName: 'Command<selectRowCommand>',
166
+ group: 'Table',
167
+ })
168
+
169
+ /// A command for selecting a column.
170
+ export const selectColCommand = $command<
171
+ { index: number; pos?: number },
172
+ 'SelectCol'
173
+ >(
174
+ 'SelectCol',
175
+ () =>
176
+ (payload: { index: number; pos?: number } = { index: 0 }) =>
177
+ (state, dispatch) => {
178
+ const { tr } = state
179
+ const result = dispatch?.(selectCol(payload.index, payload.pos)(tr))
180
+
181
+ return Boolean(result)
182
+ }
183
+ )
184
+
185
+ withMeta(selectColCommand, {
186
+ displayName: 'Command<selectColCommand>',
187
+ group: 'Table',
188
+ })
189
+
190
+ /// A command for selecting a table.
191
+ export const selectTableCommand = $command(
192
+ 'SelectTable',
193
+ () => () => (state, dispatch) => {
194
+ const { tr } = state
195
+ const result = dispatch?.(selectTable(tr))
196
+
197
+ return Boolean(result)
198
+ }
199
+ )
200
+
201
+ withMeta(selectTableCommand, {
202
+ displayName: 'Command<selectTableCommand>',
203
+ group: 'Table',
204
+ })
205
+
206
+ /// A command for deleting selected cells.
207
+ /// If the selection is a row or column, the row or column will be deleted.
208
+ /// If all cells are selected, the table will be deleted.
209
+ export const deleteSelectedCellsCommand = $command(
210
+ 'DeleteSelectedCells',
211
+ () => () => (state, dispatch) => {
212
+ const { selection } = state
213
+ if (!(selection instanceof CellSelection)) return false
214
+
215
+ const isRow = selection.isRowSelection()
216
+ const isCol = selection.isColSelection()
217
+
218
+ if (isRow && isCol) return deleteTable(state, dispatch)
219
+
220
+ if (isCol) return deleteColumn(state, dispatch)
221
+ else return deleteRow(state, dispatch)
222
+ }
223
+ )
224
+
225
+ withMeta(deleteSelectedCellsCommand, {
226
+ displayName: 'Command<deleteSelectedCellsCommand>',
227
+ group: 'Table',
228
+ })
229
+
230
+ /// A command for adding a column before the current column.
231
+ export const addColBeforeCommand = $command(
232
+ 'AddColBefore',
233
+ () => () => addColumnBefore
234
+ )
235
+
236
+ withMeta(addColBeforeCommand, {
237
+ displayName: 'Command<addColBeforeCommand>',
238
+ group: 'Table',
239
+ })
240
+
241
+ /// A command for adding a column after the current column.
242
+ export const addColAfterCommand = $command(
243
+ 'AddColAfter',
244
+ () => () => addColumnAfter
245
+ )
246
+
247
+ withMeta(addColAfterCommand, {
248
+ displayName: 'Command<addColAfterCommand>',
249
+ group: 'Table',
250
+ })
251
+
252
+ /// A command for adding a row before the current row.
253
+ export const addRowBeforeCommand = $command(
254
+ 'AddRowBefore',
255
+ (ctx) => () => (state, dispatch) => {
256
+ if (!isInTable(state)) return false
257
+ if (dispatch) {
258
+ const rect = selectedRect(state)
259
+ dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.top))
260
+ }
261
+ return true
262
+ }
263
+ )
264
+
265
+ withMeta(addRowBeforeCommand, {
266
+ displayName: 'Command<addRowBeforeCommand>',
267
+ group: 'Table',
268
+ })
269
+
270
+ /// A command for adding a row after the current row.
271
+ export const addRowAfterCommand = $command(
272
+ 'AddRowAfter',
273
+ (ctx) => () => (state, dispatch) => {
274
+ if (!isInTable(state)) return false
275
+ if (dispatch) {
276
+ const rect = selectedRect(state)
277
+ dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.bottom))
278
+ }
279
+ return true
280
+ }
281
+ )
282
+
283
+ withMeta(addRowAfterCommand, {
284
+ displayName: 'Command<addRowAfterCommand>',
285
+ group: 'Table',
286
+ })
287
+
288
+ /// A command for setting alignment property for selected cells.
289
+ /// You can specify the alignment as `left`, `center`, or `right`.
290
+ /// It's `left` by default.
291
+ export const setAlignCommand = $command<
292
+ 'left' | 'center' | 'right',
293
+ 'SetAlign'
294
+ >(
295
+ 'SetAlign',
296
+ () =>
297
+ (alignment = 'left') =>
298
+ setCellAttr('alignment', alignment)
299
+ )
300
+
301
+ withMeta(setAlignCommand, {
302
+ displayName: 'Command<setAlignCommand>',
303
+ group: 'Table',
304
+ })