@milkdown/preset-gfm 7.0.0-next.0 → 7.0.0-next.1

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 (37) hide show
  1. package/lib/composed/commands.d.ts.map +1 -1
  2. package/lib/composed/inputrules.d.ts.map +1 -1
  3. package/lib/composed/keymap.d.ts.map +1 -1
  4. package/lib/composed/plugins.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 +164 -163
  8. package/lib/index.es.js.map +1 -1
  9. package/lib/mark/strike-through.d.ts +1 -0
  10. package/lib/mark/strike-through.d.ts.map +1 -1
  11. package/lib/node/footnote/definition.d.ts.map +1 -1
  12. package/lib/node/footnote/reference.d.ts.map +1 -1
  13. package/lib/node/table/index.d.ts.map +1 -1
  14. package/lib/node/table/utils.d.ts +1 -2
  15. package/lib/node/table/utils.d.ts.map +1 -1
  16. package/lib/node/task-list-item.d.ts.map +1 -1
  17. package/lib/plugin/auto-insert-zero-space-plugin.d.ts.map +1 -1
  18. package/lib/plugin/column-resizing-plugin.d.ts.map +1 -1
  19. package/lib/plugin/remark-gfm-plugin.d.ts.map +1 -1
  20. package/lib/plugin/table-editing-plugin.d.ts.map +1 -1
  21. package/package.json +8 -8
  22. package/src/composed/commands.ts +1 -0
  23. package/src/composed/inputrules.ts +1 -0
  24. package/src/composed/keymap.ts +1 -0
  25. package/src/composed/plugins.ts +1 -0
  26. package/src/composed/schema.ts +3 -1
  27. package/src/index.ts +1 -0
  28. package/src/mark/strike-through.ts +10 -3
  29. package/src/node/footnote/definition.ts +2 -0
  30. package/src/node/footnote/reference.ts +2 -0
  31. package/src/node/table/index.ts +35 -0
  32. package/src/node/table/utils.ts +28 -8
  33. package/src/node/task-list-item.ts +1 -0
  34. package/src/plugin/auto-insert-zero-space-plugin.ts +2 -1
  35. package/src/plugin/column-resizing-plugin.ts +2 -0
  36. package/src/plugin/remark-gfm-plugin.ts +1 -0
  37. package/src/plugin/table-editing-plugin.ts +2 -0
@@ -23,6 +23,7 @@ const originalSchema = tableNodes({
23
23
  },
24
24
  })
25
25
 
26
+ /// Schema for table node.
26
27
  export const tableSchema = $nodeSchema('table', () => ({
27
28
  ...originalSchema.table,
28
29
  parseMarkdown: {
@@ -58,6 +59,7 @@ export const tableSchema = $nodeSchema('table', () => ({
58
59
 
59
60
  }))
60
61
 
62
+ /// Schema for table row node.
61
63
  export const tableRowSchema = $nodeSchema('table_row', () => ({
62
64
  ...originalSchema.table_row,
63
65
  parseMarkdown: {
@@ -84,6 +86,7 @@ export const tableRowSchema = $nodeSchema('table_row', () => ({
84
86
  },
85
87
  }))
86
88
 
89
+ /// Schema for table cell node.
87
90
  export const tableCellSchema = $nodeSchema('table_cell', () => ({
88
91
  ...originalSchema.table_cell,
89
92
  parseMarkdown: {
@@ -106,6 +109,7 @@ export const tableCellSchema = $nodeSchema('table_cell', () => ({
106
109
  },
107
110
  }))
108
111
 
112
+ /// Schema for table header node.
109
113
  export const tableHeaderSchema = $nodeSchema('table_header', () => ({
110
114
  ...originalSchema.table_header,
111
115
  parseMarkdown: {
@@ -129,6 +133,8 @@ export const tableHeaderSchema = $nodeSchema('table_header', () => ({
129
133
  },
130
134
  }))
131
135
 
136
+ /// A input rule for creating table.
137
+ /// For example, `|2x2|` will create a 2x2 table.
132
138
  export const insertTableInputRule = $inputRule(() => new InputRule(
133
139
  /^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
134
140
  const $start = state.doc.resolve(start)
@@ -144,10 +150,15 @@ export const insertTableInputRule = $inputRule(() => new InputRule(
144
150
  },
145
151
  ))
146
152
 
153
+ /// A command for moving cursor to previous cell.
147
154
  export const goToPrevTableCellCommand = $command('GoToPrevTableCell', () => () => goToNextCell(-1))
148
155
 
156
+ /// A command for moving cursor to next cell.
149
157
  export const goToNextTableCellCommand = $command('GoToNextTableCell', () => () => goToNextCell(1))
150
158
 
159
+ /// A command for splitting current table into two tables.
160
+ /// If the selection is at the end of the table,
161
+ /// it will just quit the table and insert a new paragraph node.
151
162
  export const breakTableCommand = $command('BreakTable', () => () => (state, dispatch) => {
152
163
  if (!isInTable(state))
153
164
  return false
@@ -162,6 +173,9 @@ export const breakTableCommand = $command('BreakTable', () => () => (state, disp
162
173
  return true
163
174
  })
164
175
 
176
+ /// A command for inserting a table.
177
+ /// You can specify the number of rows and columns.
178
+ /// By default, it will insert a 3x3 table.
165
179
  export const insertTableCommand = $command('InsertTable', () => ({ row, col }: { row?: number; col?: number } = {}) => (state, dispatch) => {
166
180
  const { selection, tr } = state
167
181
  const { from } = selection
@@ -174,6 +188,8 @@ export const insertTableCommand = $command('InsertTable', () => ({ row, col }: {
174
188
  return true
175
189
  })
176
190
 
191
+ /// A command for moving a row in a table.
192
+ /// You should specify the `from` and `to` index.
177
193
  export const moveRowCommand = $command('MoveRow', () => ({ from, to }: { from?: number; to?: number } = {}) => (state, dispatch) => {
178
194
  const { tr } = state
179
195
  const result = dispatch?.(moveRow(tr, from ?? 0, to ?? 0, true))
@@ -181,6 +197,8 @@ export const moveRowCommand = $command('MoveRow', () => ({ from, to }: { from?:
181
197
  return Boolean(result)
182
198
  })
183
199
 
200
+ /// A command for moving a column in a table.
201
+ /// You should specify the `from` and `to` index.
184
202
  export const moveColCommand = $command('MoveCol', () => ({ from, to }: { from?: number; to?: number } = {}) => (state, dispatch) => {
185
203
  const { tr } = state
186
204
  const result = dispatch?.(moveCol(tr, from ?? 0, to ?? 0, true))
@@ -188,6 +206,7 @@ export const moveColCommand = $command('MoveCol', () => ({ from, to }: { from?:
188
206
  return Boolean(result)
189
207
  })
190
208
 
209
+ /// A command for selecting a row.
191
210
  export const selectRowCommand = $command<number, 'SelectRow'>('SelectRow', () => (index = 0) => (state, dispatch) => {
192
211
  const { tr } = state
193
212
  const result = dispatch?.(selectRow(index)(tr))
@@ -195,6 +214,7 @@ export const selectRowCommand = $command<number, 'SelectRow'>('SelectRow', () =>
195
214
  return Boolean(result)
196
215
  })
197
216
 
217
+ /// A command for selecting a column.
198
218
  export const selectColCommand = $command<number, 'SelectCol'>('SelectCol', () => (index = 0) => (state, dispatch) => {
199
219
  const { tr } = state
200
220
  const result = dispatch?.(selectCol(index)(tr))
@@ -202,6 +222,7 @@ export const selectColCommand = $command<number, 'SelectCol'>('SelectCol', () =>
202
222
  return Boolean(result)
203
223
  })
204
224
 
225
+ /// A command for selecting a table.
205
226
  export const selectTableCommand = $command('SelectTable', () => () => (state, dispatch) => {
206
227
  const { tr } = state
207
228
  const result = dispatch?.(selectTable(tr))
@@ -209,6 +230,9 @@ export const selectTableCommand = $command('SelectTable', () => () => (state, di
209
230
  return Boolean(result)
210
231
  })
211
232
 
233
+ /// A command for deleting selected cells.
234
+ /// If the selection is a row or column, the row or column will be deleted.
235
+ /// If all cells are selected, the table will be deleted.
212
236
  export const deleteSelectedCellsCommand = $command('DeleteSelectedCells', () => () => (state, dispatch) => {
213
237
  const { selection } = state
214
238
  if (!(selection instanceof CellSelection))
@@ -227,10 +251,13 @@ export const deleteSelectedCellsCommand = $command('DeleteSelectedCells', () =>
227
251
  return deleteRow(state, dispatch)
228
252
  })
229
253
 
254
+ /// A command for adding a column before the current column.
230
255
  export const addColBeforeCommand = $command('AddColBefore', () => () => addColumnBefore)
231
256
 
257
+ /// A command for adding a column after the current column.
232
258
  export const addColAfterCommand = $command('AddColAfter', () => () => addColumnAfter)
233
259
 
260
+ /// A command for adding a row before the current row.
234
261
  export const addRowBeforeCommand = $command('AddRowBefore', () => () => (state, dispatch) => {
235
262
  if (!isInTable(state))
236
263
  return false
@@ -241,6 +268,7 @@ export const addRowBeforeCommand = $command('AddRowBefore', () => () => (state,
241
268
  return true
242
269
  })
243
270
 
271
+ /// A command for adding a row after the current row.
244
272
  export const addRowAfterCommand = $command('AddRowAfter', () => () => (state, dispatch) => {
245
273
  if (!isInTable(state))
246
274
  return false
@@ -251,8 +279,15 @@ export const addRowAfterCommand = $command('AddRowAfter', () => () => (state, di
251
279
  return true
252
280
  })
253
281
 
282
+ /// A command for setting alignment property for selected cells.
283
+ /// You can specify the alignment as `left`, `center`, or `right`.
284
+ /// It's `left` by default.
254
285
  export const setAlignCommand = $command<'left' | 'center' | 'right', 'SetAlign'>('SetAlign', () => (alignment = 'left') => setCellAttr('alignment', alignment))
255
286
 
287
+ /// Keymap for table commands.
288
+ /// - `<Mod-]>`/`<Tab>`: Move to the next cell.
289
+ /// - `<Mod-[>`/`<Shift-Tab>`: Move to the previous cell.
290
+ /// - `<Mod-Enter>`: Exit the table, and break it if possible.
256
291
  export const tableKeymap = $useKeymap('tableKeymap', {
257
292
  NextCell: {
258
293
  shortcuts: ['Mod-]', 'Tab'],
@@ -9,12 +9,14 @@ import { CellSelection, TableMap } from '@milkdown/prose/tables'
9
9
 
10
10
  import { tableCellSchema, tableHeaderSchema, tableRowSchema, tableSchema } from '.'
11
11
 
12
+ /// @internal
12
13
  export interface CellPos {
13
14
  pos: number
14
15
  start: number
15
16
  node: Node
16
17
  }
17
18
 
19
+ /// @internal
18
20
  export const createTable = (rowsCount = 3, colsCount = 3): Node => {
19
21
  const cells = Array(colsCount)
20
22
  .fill(0)
@@ -31,10 +33,12 @@ export const createTable = (rowsCount = 3, colsCount = 3): Node => {
31
33
  return tableSchema.type().create(null, rows)
32
34
  }
33
35
 
36
+ /// Find the table node with position information for current selection.
34
37
  export const findTable = (selection: Selection) =>
35
38
  findParentNode(node => node.type.spec.tableRole === 'table')(selection)
36
39
 
37
- export const getCellsInColumn = (columnIndex: number, selection: Selection): CellPos[] | undefined => {
40
+ /// Get cells in a column of a table.
41
+ export const getCellsInCol = (columnIndex: number, selection: Selection): CellPos[] | undefined => {
38
42
  const table = findTable(selection)
39
43
  if (!table)
40
44
  return undefined
@@ -58,6 +62,7 @@ export const getCellsInColumn = (columnIndex: number, selection: Selection): Cel
58
62
  .filter((x): x is CellPos => x != null)
59
63
  }
60
64
 
65
+ /// Get cells in a row of a table.
61
66
  export const getCellsInRow = (rowIndex: number, selection: Selection): CellPos[] | undefined => {
62
67
  const table = findTable(selection)
63
68
  if (!table)
@@ -82,6 +87,7 @@ export const getCellsInRow = (rowIndex: number, selection: Selection): CellPos[]
82
87
  .filter((x): x is CellPos => x != null)
83
88
  }
84
89
 
90
+ /// Get all cells in a table.
85
91
  export const getAllCellsInTable = (selection: Selection) => {
86
92
  const table = findTable(selection)
87
93
  if (!table)
@@ -101,6 +107,7 @@ export const getAllCellsInTable = (selection: Selection) => {
101
107
  })
102
108
  }
103
109
 
110
+ /// Select a possible table in current selection.
104
111
  export const selectTable = (tr: Transaction) => {
105
112
  const cells = getAllCellsInTable(tr.selection)
106
113
  if (cells && cells[0]) {
@@ -114,6 +121,7 @@ export const selectTable = (tr: Transaction) => {
114
121
  return tr
115
122
  }
116
123
 
124
+ /// @internal
117
125
  export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }: TableRect, row: number) {
118
126
  const rowPos = Array(row)
119
127
  .fill(0)
@@ -132,6 +140,7 @@ export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }:
132
140
  return tr
133
141
  }
134
142
 
143
+ /// @internal
135
144
  export const selectLine = (type: 'row' | 'col') => (index: number) => (tr: Transaction) => {
136
145
  const table = findTable(tr.selection)
137
146
  const isRowSelection = type === 'row'
@@ -157,7 +166,12 @@ export const selectLine = (type: 'row' | 'col') => (index: number) => (tr: Trans
157
166
  return tr
158
167
  }
159
168
 
169
+ /// If the selection is in a table,
170
+ /// select the {index} row.
160
171
  export const selectRow = selectLine('row')
172
+
173
+ /// If the selection is in a table,
174
+ /// select the {index} column.
161
175
  export const selectCol = selectLine('col')
162
176
 
163
177
  const transpose = <T>(array: T[][]) => {
@@ -201,7 +215,7 @@ const convertArrayOfRowsToTableNode = (tableNode: Node, arrayOfNodes: (Node | nu
201
215
  return newTable
202
216
  }
203
217
 
204
- export const convertTableNodeToArrayOfRows = (tableNode: Node) => {
218
+ const convertTableNodeToArrayOfRows = (tableNode: Node) => {
205
219
  const map = TableMap.get(tableNode)
206
220
  const rows: (Node | null)[][] = []
207
221
  for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
@@ -289,7 +303,7 @@ const getSelectionRangeInColumn = (columnIndex: number, tr: Transaction) => {
289
303
 
290
304
  // looking for selection start column (startIndex)
291
305
  for (let i = columnIndex; i >= 0; i--) {
292
- const cells = getCellsInColumn(i, tr.selection)
306
+ const cells = getCellsInCol(i, tr.selection)
293
307
  if (cells) {
294
308
  cells.forEach((cell) => {
295
309
  const maybeEndIndex = cell.node.attrs.colspan + i - 1
@@ -303,7 +317,7 @@ const getSelectionRangeInColumn = (columnIndex: number, tr: Transaction) => {
303
317
  }
304
318
  // looking for selection end column (endIndex)
305
319
  for (let i = columnIndex; i <= endIndex; i++) {
306
- const cells = getCellsInColumn(i, tr.selection)
320
+ const cells = getCellsInCol(i, tr.selection)
307
321
  if (cells) {
308
322
  cells.forEach((cell) => {
309
323
  const maybeEndIndex = cell.node.attrs.colspan + i - 1
@@ -316,14 +330,14 @@ const getSelectionRangeInColumn = (columnIndex: number, tr: Transaction) => {
316
330
  // filter out columns without cells (where all rows have colspan > 1 in the same column)
317
331
  const indexes = []
318
332
  for (let i = startIndex; i <= endIndex; i++) {
319
- const maybeCells = getCellsInColumn(i, tr.selection)
333
+ const maybeCells = getCellsInCol(i, tr.selection)
320
334
  if (maybeCells && maybeCells.length)
321
335
  indexes.push(i)
322
336
  }
323
337
  startIndex = indexes[0]!
324
338
  endIndex = indexes[indexes.length - 1]!
325
339
 
326
- const firstSelectedColumnCells = getCellsInColumn(startIndex, tr.selection)!
340
+ const firstSelectedColumnCells = getCellsInCol(startIndex, tr.selection)!
327
341
  const firstRowCells = getCellsInRow(0, tr.selection)!
328
342
  const $anchor = tr.doc.resolve(
329
343
  firstSelectedColumnCells[firstSelectedColumnCells.length - 1]!.pos,
@@ -331,7 +345,7 @@ const getSelectionRangeInColumn = (columnIndex: number, tr: Transaction) => {
331
345
 
332
346
  let headCell: CellPos | undefined
333
347
  for (let i = endIndex; i >= startIndex; i--) {
334
- const columnCells = getCellsInColumn(i, tr.selection)
348
+ const columnCells = getCellsInCol(i, tr.selection)
335
349
  if (columnCells && columnCells.length) {
336
350
  for (let j = firstRowCells.length - 1; j >= 0; j--) {
337
351
  if (firstRowCells[j]!.pos === columnCells[0]!.pos) {
@@ -384,7 +398,7 @@ const getSelectionRangeInRow = (rowIndex: number, tr: Transaction) => {
384
398
  endIndex = indexes[indexes.length - 1]!
385
399
 
386
400
  const firstSelectedRowCells = getCellsInRow(startIndex, tr.selection)!
387
- const firstColumnCells = getCellsInColumn(0, tr.selection)!
401
+ const firstColumnCells = getCellsInCol(0, tr.selection)!
388
402
  const $anchor = tr.doc.resolve(firstSelectedRowCells[firstSelectedRowCells.length - 1]!.pos)
389
403
 
390
404
  let headCell: CellPos | undefined
@@ -406,6 +420,9 @@ const getSelectionRangeInRow = (rowIndex: number, tr: Transaction) => {
406
420
  return { $anchor, $head, indexes }
407
421
  }
408
422
 
423
+ /// If the selection is in a table,
424
+ /// Move the columns at `origin` to `target` in current table.
425
+ /// The `select` is true by default, which means the selection will be set to the moved column.
409
426
  export function moveCol(tr: Transaction, origin: number, target: number, select = true) {
410
427
  const table = findTable(tr.selection)
411
428
  if (!table)
@@ -447,6 +464,9 @@ export function moveCol(tr: Transaction, origin: number, target: number, select
447
464
  return _tr.setSelection(createCellSelection($lastCell, $firstCell))
448
465
  }
449
466
 
467
+ /// If the selection is in a table,
468
+ /// Move the rows at `origin` and `target` in current table.
469
+ /// The `select` is true by default, which means the selection will be set to the moved row.
450
470
  export function moveRow(tr: Transaction, origin: number, target: number, select = true) {
451
471
  const table = findTable(tr.selection)
452
472
  if (!table)
@@ -2,6 +2,7 @@
2
2
  import { expectDomTypeError } from '@milkdown/exception'
3
3
  import { listItemSchema } from '@milkdown/preset-commonmark'
4
4
 
5
+ /// This schema extends the [list item](/preset-commonmark#list-item) schema and add task list support for it.
5
6
  export const extendListItemSchemaForTask = listItemSchema.extendSchema((prev) => {
6
7
  return (ctx) => {
7
8
  const baseSchema = prev(ctx)
@@ -6,7 +6,8 @@ import { Plugin, PluginKey } from '@milkdown/prose/state'
6
6
  import { paragraphSchema } from '@milkdown/preset-commonmark'
7
7
  import { $prose } from '@milkdown/utils'
8
8
 
9
- // original discussion in https://discuss.prosemirror.net/t/ime-composing-problems-on-td-or-th-element-in-safari-browser/4501
9
+ /// This plugin is used to fix the bug of IME composing in table in Safari browser.
10
+ /// original discussion in https://discuss.prosemirror.net/t/ime-composing-problems-on-td-or-th-element-in-safari-browser/4501
10
11
  export const autoInsertZeroSpaceInTablePlugin = $prose(() => {
11
12
  const pluginKey = new PluginKey('MILKDOWN_AUTO_INSERT_ZERO_SPACE')
12
13
 
@@ -1,4 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { columnResizing } from '@milkdown/prose/tables'
3
3
  import { $prose } from '@milkdown/utils'
4
+
5
+ /// This plugin is wrapping the `columnResizing` plugin from [prosemirror-tables](https://github.com/ProseMirror/prosemirror-tables).
4
6
  export const columnResizingPlugin = $prose(() => columnResizing({}))
@@ -2,4 +2,5 @@
2
2
  import { $remark } from '@milkdown/utils'
3
3
  import remarkGFM from 'remark-gfm'
4
4
 
5
+ /// This plugin is wrapping the [remark-gfm](https://github.com/remarkjs/remark-gfm).
5
6
  export const remarkGFMPlugin = $remark(() => remarkGFM)
@@ -1,4 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { tableEditing } from '@milkdown/prose/tables'
3
3
  import { $prose } from '@milkdown/utils'
4
+
5
+ /// This plugin is wrapping the `tableEditing` plugin from [prosemirror-tables](https://github.com/ProseMirror/prosemirror-tables).
4
6
  export const tableEditingPlugin = $prose(() => tableEditing())