@milkdown/preset-gfm 7.2.3 → 7.3.0
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/composed/plugins.d.ts.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +272 -265
- package/lib/index.es.js.map +1 -1
- package/lib/mark/strike-through.d.ts.map +1 -1
- package/lib/node/table/index.d.ts.map +1 -1
- package/lib/node/table/utils.d.ts +3 -2
- package/lib/node/table/utils.d.ts.map +1 -1
- package/lib/plugin/remark-gfm-plugin.d.ts +1 -1
- package/lib/plugin/remark-gfm-plugin.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/composed/plugins.ts +7 -2
- package/src/index.ts +1 -0
- package/src/mark/strike-through.ts +3 -5
- package/src/node/table/index.ts +16 -13
- package/src/node/table/utils.ts +9 -8
- package/src/plugin/auto-insert-zero-space-plugin.ts +2 -2
- package/src/plugin/remark-gfm-plugin.ts +7 -2
package/src/node/table/index.ts
CHANGED
|
@@ -175,18 +175,19 @@ withMeta(tableHeaderSchema.ctx, {
|
|
|
175
175
|
|
|
176
176
|
/// A input rule for creating table.
|
|
177
177
|
/// For example, `|2x2|` will create a 2x2 table.
|
|
178
|
-
export const insertTableInputRule = $inputRule(
|
|
178
|
+
export const insertTableInputRule = $inputRule(ctx => new InputRule(
|
|
179
179
|
/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
|
|
180
180
|
const $start = state.doc.resolve(start)
|
|
181
|
-
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), tableSchema.type()))
|
|
181
|
+
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), tableSchema.type(ctx)))
|
|
182
182
|
return null
|
|
183
183
|
|
|
184
184
|
const tableNode = createTable(
|
|
185
|
+
ctx,
|
|
185
186
|
Number(match.groups?.row),
|
|
186
187
|
Number(match.groups?.col),
|
|
187
188
|
)
|
|
188
|
-
const tr = state.tr.replaceRangeWith(start, end, tableNode)
|
|
189
|
-
return tr.setSelection(TextSelection.create(tr.doc, start + 3))
|
|
189
|
+
const tr = state.tr.replaceRangeWith(start, end, tableNode)
|
|
190
|
+
return tr.setSelection(TextSelection.create(tr.doc, start + 3)).scrollIntoView()
|
|
190
191
|
},
|
|
191
192
|
))
|
|
192
193
|
|
|
@@ -214,14 +215,14 @@ withMeta(goToNextTableCellCommand, {
|
|
|
214
215
|
/// A command for splitting current table into two tables.
|
|
215
216
|
/// If the selection is at the end of the table,
|
|
216
217
|
/// it will just quit the table and insert a new paragraph node.
|
|
217
|
-
export const breakTableCommand = $command('BreakTable',
|
|
218
|
+
export const breakTableCommand = $command('BreakTable', ctx => () => (state, dispatch) => {
|
|
218
219
|
if (!isInTable(state))
|
|
219
220
|
return false
|
|
220
221
|
|
|
221
222
|
const { $head } = state.selection
|
|
222
223
|
const pos = $head.after()
|
|
223
224
|
const tr = state.tr
|
|
224
|
-
.replaceWith(pos, pos, paragraphSchema.type().createAndFill()!)
|
|
225
|
+
.replaceWith(pos, pos, paragraphSchema.type(ctx).createAndFill()!)
|
|
225
226
|
|
|
226
227
|
tr.setSelection(Selection.near(tr.doc.resolve(pos), 1)).scrollIntoView()
|
|
227
228
|
dispatch?.(tr)
|
|
@@ -236,14 +237,16 @@ withMeta(breakTableCommand, {
|
|
|
236
237
|
/// A command for inserting a table.
|
|
237
238
|
/// You can specify the number of rows and columns.
|
|
238
239
|
/// By default, it will insert a 3x3 table.
|
|
239
|
-
export const insertTableCommand = $command('InsertTable',
|
|
240
|
+
export const insertTableCommand = $command('InsertTable', ctx => ({ row, col }: { row?: number; col?: number } = {}) => (state, dispatch) => {
|
|
240
241
|
const { selection, tr } = state
|
|
241
242
|
const { from } = selection
|
|
242
|
-
const table = createTable(row, col)
|
|
243
|
+
const table = createTable(ctx, row, col)
|
|
243
244
|
const _tr = tr.replaceSelectionWith(table)
|
|
244
245
|
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true)
|
|
245
246
|
if (sel)
|
|
246
|
-
|
|
247
|
+
_tr.setSelection(sel)
|
|
248
|
+
|
|
249
|
+
dispatch?.(_tr)
|
|
247
250
|
|
|
248
251
|
return true
|
|
249
252
|
})
|
|
@@ -363,12 +366,12 @@ withMeta(addColAfterCommand, {
|
|
|
363
366
|
})
|
|
364
367
|
|
|
365
368
|
/// A command for adding a row before the current row.
|
|
366
|
-
export const addRowBeforeCommand = $command('AddRowBefore',
|
|
369
|
+
export const addRowBeforeCommand = $command('AddRowBefore', ctx => () => (state, dispatch) => {
|
|
367
370
|
if (!isInTable(state))
|
|
368
371
|
return false
|
|
369
372
|
if (dispatch) {
|
|
370
373
|
const rect = selectedRect(state)
|
|
371
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.top))
|
|
374
|
+
dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.top))
|
|
372
375
|
}
|
|
373
376
|
return true
|
|
374
377
|
})
|
|
@@ -379,12 +382,12 @@ withMeta(addRowBeforeCommand, {
|
|
|
379
382
|
})
|
|
380
383
|
|
|
381
384
|
/// A command for adding a row after the current row.
|
|
382
|
-
export const addRowAfterCommand = $command('AddRowAfter',
|
|
385
|
+
export const addRowAfterCommand = $command('AddRowAfter', ctx => () => (state, dispatch) => {
|
|
383
386
|
if (!isInTable(state))
|
|
384
387
|
return false
|
|
385
388
|
if (dispatch) {
|
|
386
389
|
const rect = selectedRect(state)
|
|
387
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom))
|
|
390
|
+
dispatch(addRowWithAlignment(ctx, state.tr, rect, rect.bottom))
|
|
388
391
|
}
|
|
389
392
|
return true
|
|
390
393
|
})
|
package/src/node/table/utils.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { Selection, Transaction } from '@milkdown/prose/state'
|
|
|
7
7
|
import type { TableRect } from '@milkdown/prose/tables'
|
|
8
8
|
import { CellSelection, TableMap } from '@milkdown/prose/tables'
|
|
9
9
|
|
|
10
|
+
import type { Ctx } from '@milkdown/ctx'
|
|
10
11
|
import { tableCellSchema, tableHeaderSchema, tableRowSchema, tableSchema } from '.'
|
|
11
12
|
|
|
12
13
|
/// @internal
|
|
@@ -17,20 +18,20 @@ export interface CellPos {
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
/// @internal
|
|
20
|
-
export const createTable = (rowsCount = 3, colsCount = 3): Node => {
|
|
21
|
+
export const createTable = (ctx: Ctx, rowsCount = 3, colsCount = 3): Node => {
|
|
21
22
|
const cells = Array(colsCount)
|
|
22
23
|
.fill(0)
|
|
23
|
-
.map(() => tableCellSchema.type().createAndFill()!)
|
|
24
|
+
.map(() => tableCellSchema.type(ctx).createAndFill()!)
|
|
24
25
|
|
|
25
26
|
const headerCells = Array(colsCount)
|
|
26
27
|
.fill(0)
|
|
27
|
-
.map(() => tableHeaderSchema.type().createAndFill()!)
|
|
28
|
+
.map(() => tableHeaderSchema.type(ctx).createAndFill()!)
|
|
28
29
|
|
|
29
30
|
const rows = Array(rowsCount)
|
|
30
31
|
.fill(0)
|
|
31
|
-
.map((_, i) => tableRowSchema.type().create(null, i === 0 ? headerCells : cells))
|
|
32
|
+
.map((_, i) => tableRowSchema.type(ctx).create(null, i === 0 ? headerCells : cells))
|
|
32
33
|
|
|
33
|
-
return tableSchema.type().create(null, rows)
|
|
34
|
+
return tableSchema.type(ctx).create(null, rows)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/// Find the table node with position information for current selection.
|
|
@@ -122,7 +123,7 @@ export const selectTable = (tr: Transaction) => {
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
/// @internal
|
|
125
|
-
export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }: TableRect, row: number) {
|
|
126
|
+
export function addRowWithAlignment(ctx: Ctx, tr: Transaction, { map, tableStart, table }: TableRect, row: number) {
|
|
126
127
|
const rowPos = Array(row)
|
|
127
128
|
.fill(0)
|
|
128
129
|
.reduce((acc, _, i) => {
|
|
@@ -133,10 +134,10 @@ export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }:
|
|
|
133
134
|
.fill(0)
|
|
134
135
|
.map((_, col) => {
|
|
135
136
|
const headerCol = table.nodeAt(map.map[col] as number)
|
|
136
|
-
return tableCellSchema.type().createAndFill({ alignment: headerCol?.attrs.alignment }) as Node
|
|
137
|
+
return tableCellSchema.type(ctx).createAndFill({ alignment: headerCol?.attrs.alignment }) as Node
|
|
137
138
|
})
|
|
138
139
|
|
|
139
|
-
tr.insert(rowPos, tableRowSchema.type().create(null, cells))
|
|
140
|
+
tr.insert(rowPos, tableRowSchema.type(ctx).create(null, cells))
|
|
140
141
|
return tr
|
|
141
142
|
}
|
|
142
143
|
|
|
@@ -9,10 +9,10 @@ import { withMeta } from '../__internal__'
|
|
|
9
9
|
|
|
10
10
|
/// This plugin is used to fix the bug of IME composing in table in Safari browser.
|
|
11
11
|
/// original discussion in https://discuss.prosemirror.net/t/ime-composing-problems-on-td-or-th-element-in-safari-browser/4501
|
|
12
|
-
export const autoInsertZeroSpaceInTablePlugin = $prose(() => {
|
|
12
|
+
export const autoInsertZeroSpaceInTablePlugin = $prose((ctx) => {
|
|
13
13
|
const pluginKey = new PluginKey('MILKDOWN_AUTO_INSERT_ZERO_SPACE')
|
|
14
14
|
|
|
15
|
-
const isParagraph = (node: Node) => node.type === paragraphSchema.type()
|
|
15
|
+
const isParagraph = (node: Node) => node.type === paragraphSchema.type(ctx)
|
|
16
16
|
|
|
17
17
|
const isEmptyParagraph = (node: Node) => isParagraph(node) && node.nodeSize === 2
|
|
18
18
|
|
|
@@ -4,9 +4,14 @@ import remarkGFM from 'remark-gfm'
|
|
|
4
4
|
import { withMeta } from '../__internal__'
|
|
5
5
|
|
|
6
6
|
/// This plugin is wrapping the [remark-gfm](https://github.com/remarkjs/remark-gfm).
|
|
7
|
-
export const remarkGFMPlugin = $remark(() => remarkGFM)
|
|
7
|
+
export const remarkGFMPlugin = $remark('remarkGFM', () => remarkGFM)
|
|
8
8
|
|
|
9
|
-
withMeta(remarkGFMPlugin, {
|
|
9
|
+
withMeta(remarkGFMPlugin.plugin, {
|
|
10
10
|
displayName: 'Remark<remarkGFMPlugin>',
|
|
11
11
|
group: 'Remark',
|
|
12
12
|
})
|
|
13
|
+
|
|
14
|
+
withMeta(remarkGFMPlugin.options, {
|
|
15
|
+
displayName: 'RemarkConfig<remarkGFMPlugin>',
|
|
16
|
+
group: 'Remark',
|
|
17
|
+
})
|