@milkdown/preset-gfm 7.3.1 → 7.3.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.
- package/lib/__internal__/with-meta.d.ts +1 -1
- package/lib/__internal__/with-meta.d.ts.map +1 -1
- package/lib/composed/commands.d.ts +1 -1
- package/lib/composed/inputrules.d.ts +2 -1
- package/lib/composed/inputrules.d.ts.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +272 -240
- package/lib/index.es.js.map +1 -1
- package/lib/mark/strike-through.d.ts +1 -0
- 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 +7 -7
- package/lib/node/table/utils.d.ts.map +1 -1
- package/lib/plugin/remark-gfm-plugin.d.ts +3 -1
- package/lib/plugin/remark-gfm-plugin.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/__internal__/with-meta.ts +1 -4
- package/src/composed/inputrules.ts +6 -1
- package/src/index.ts +2 -2
- package/src/mark/strike-through.ts +12 -1
- package/src/node/table/index.ts +6 -5
- package/src/node/table/utils.ts +39 -51
- package/src/plugin/auto-insert-zero-space-plugin.ts +4 -4
- package/src/plugin/remark-gfm-plugin.ts +3 -1
package/src/node/table/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ const originalSchema = tableNodes({
|
|
|
16
16
|
cellAttributes: {
|
|
17
17
|
alignment: {
|
|
18
18
|
default: 'left',
|
|
19
|
-
getFromDOM: dom => (dom
|
|
19
|
+
getFromDOM: dom => (dom).style.textAlign || 'left',
|
|
20
20
|
setDOMAttr: (value, attrs) => {
|
|
21
21
|
attrs.style = `text-align: ${value || 'left'}`
|
|
22
22
|
},
|
|
@@ -176,7 +176,8 @@ withMeta(tableHeaderSchema.ctx, {
|
|
|
176
176
|
/// A input rule for creating table.
|
|
177
177
|
/// For example, `|2x2|` will create a 2x2 table.
|
|
178
178
|
export const insertTableInputRule = $inputRule(ctx => new InputRule(
|
|
179
|
-
/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,
|
|
179
|
+
/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/,
|
|
180
|
+
(state, match, start, end) => {
|
|
180
181
|
const $start = state.doc.resolve(start)
|
|
181
182
|
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), tableSchema.type(ctx)))
|
|
182
183
|
return null
|
|
@@ -237,7 +238,7 @@ withMeta(breakTableCommand, {
|
|
|
237
238
|
/// A command for inserting a table.
|
|
238
239
|
/// You can specify the number of rows and columns.
|
|
239
240
|
/// By default, it will insert a 3x3 table.
|
|
240
|
-
export const insertTableCommand = $command('InsertTable', ctx => ({ row, col }: { row?: number
|
|
241
|
+
export const insertTableCommand = $command('InsertTable', ctx => ({ row, col }: { row?: number, col?: number } = {}) => (state, dispatch) => {
|
|
241
242
|
const { selection, tr } = state
|
|
242
243
|
const { from } = selection
|
|
243
244
|
const table = createTable(ctx, row, col)
|
|
@@ -258,7 +259,7 @@ withMeta(insertTableCommand, {
|
|
|
258
259
|
|
|
259
260
|
/// A command for moving a row in a table.
|
|
260
261
|
/// You should specify the `from` and `to` index.
|
|
261
|
-
export const moveRowCommand = $command('MoveRow', () => ({ from, to }: { from?: number
|
|
262
|
+
export const moveRowCommand = $command('MoveRow', () => ({ from, to }: { from?: number, to?: number } = {}) => (state, dispatch) => {
|
|
262
263
|
const { tr } = state
|
|
263
264
|
const result = dispatch?.(moveRow(tr, from ?? 0, to ?? 0, true))
|
|
264
265
|
|
|
@@ -272,7 +273,7 @@ withMeta(moveRowCommand, {
|
|
|
272
273
|
|
|
273
274
|
/// A command for moving a column in a table.
|
|
274
275
|
/// You should specify the `from` and `to` index.
|
|
275
|
-
export const moveColCommand = $command('MoveCol', () => ({ from, to }: { from?: number
|
|
276
|
+
export const moveColCommand = $command('MoveCol', () => ({ from, to }: { from?: number, to?: number } = {}) => (state, dispatch) => {
|
|
276
277
|
const { tr } = state
|
|
277
278
|
const result = dispatch?.(moveCol(tr, from ?? 0, to ?? 0, true))
|
|
278
279
|
|
package/src/node/table/utils.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface CellPos {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/// @internal
|
|
21
|
-
export
|
|
21
|
+
export function createTable(ctx: Ctx, rowsCount = 3, colsCount = 3): Node {
|
|
22
22
|
const cells = Array(colsCount)
|
|
23
23
|
.fill(0)
|
|
24
24
|
.map(() => tableCellSchema.type(ctx).createAndFill()!)
|
|
@@ -35,11 +35,12 @@ export const createTable = (ctx: Ctx, rowsCount = 3, colsCount = 3): Node => {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/// Find the table node with position information for current selection.
|
|
38
|
-
export
|
|
39
|
-
findParentNode(node => node.type.spec.tableRole === 'table')(selection)
|
|
38
|
+
export function findTable(selection: Selection) {
|
|
39
|
+
return findParentNode(node => node.type.spec.tableRole === 'table')(selection)
|
|
40
|
+
}
|
|
40
41
|
|
|
41
42
|
/// Get cells in a column of a table.
|
|
42
|
-
export
|
|
43
|
+
export function getCellsInCol(columnIndex: number, selection: Selection): CellPos[] | undefined {
|
|
43
44
|
const table = findTable(selection)
|
|
44
45
|
if (!table)
|
|
45
46
|
return undefined
|
|
@@ -64,7 +65,7 @@ export const getCellsInCol = (columnIndex: number, selection: Selection): CellPo
|
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
/// Get cells in a row of a table.
|
|
67
|
-
export
|
|
68
|
+
export function getCellsInRow(rowIndex: number, selection: Selection): CellPos[] | undefined {
|
|
68
69
|
const table = findTable(selection)
|
|
69
70
|
if (!table)
|
|
70
71
|
return undefined
|
|
@@ -89,7 +90,7 @@ export const getCellsInRow = (rowIndex: number, selection: Selection): CellPos[]
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
/// Get all cells in a table.
|
|
92
|
-
export
|
|
93
|
+
export function getAllCellsInTable(selection: Selection) {
|
|
93
94
|
const table = findTable(selection)
|
|
94
95
|
if (!table)
|
|
95
96
|
return
|
|
@@ -109,7 +110,7 @@ export const getAllCellsInTable = (selection: Selection) => {
|
|
|
109
110
|
}
|
|
110
111
|
|
|
111
112
|
/// Select a possible table in current selection.
|
|
112
|
-
export
|
|
113
|
+
export function selectTable(tr: Transaction) {
|
|
113
114
|
const cells = getAllCellsInTable(tr.selection)
|
|
114
115
|
if (cells && cells[0]) {
|
|
115
116
|
const $firstCell = tr.doc.resolve(cells[0].pos)
|
|
@@ -142,29 +143,31 @@ export function addRowWithAlignment(ctx: Ctx, tr: Transaction, { map, tableStart
|
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
/// @internal
|
|
145
|
-
export
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
146
|
+
export function selectLine(type: 'row' | 'col') {
|
|
147
|
+
return (index: number) => (tr: Transaction) => {
|
|
148
|
+
const table = findTable(tr.selection)
|
|
149
|
+
const isRowSelection = type === 'row'
|
|
150
|
+
if (table) {
|
|
151
|
+
const map = TableMap.get(table.node)
|
|
152
|
+
|
|
153
|
+
// Check if the index is valid
|
|
154
|
+
if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
|
|
155
|
+
const lastCell = map.positionAt(
|
|
156
|
+
isRowSelection ? index : map.height - 1,
|
|
157
|
+
isRowSelection ? map.width - 1 : index,
|
|
158
|
+
table.node,
|
|
159
|
+
)
|
|
160
|
+
const $lastCell = tr.doc.resolve(table.start + lastCell)
|
|
161
|
+
|
|
162
|
+
const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection
|
|
163
|
+
|
|
164
|
+
const firstCell = map.positionAt(isRowSelection ? index : 0, isRowSelection ? 0 : index, table.node)
|
|
165
|
+
const $firstCell = tr.doc.resolve(table.start + firstCell)
|
|
166
|
+
return cloneTr(tr.setSelection(createCellSelection($lastCell, $firstCell) as unknown as Selection))
|
|
167
|
+
}
|
|
165
168
|
}
|
|
169
|
+
return tr
|
|
166
170
|
}
|
|
167
|
-
return tr
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
/// If the selection is in a table,
|
|
@@ -175,13 +178,13 @@ export const selectRow = selectLine('row')
|
|
|
175
178
|
/// select the {index} column.
|
|
176
179
|
export const selectCol = selectLine('col')
|
|
177
180
|
|
|
178
|
-
|
|
181
|
+
function transpose<T>(array: T[][]) {
|
|
179
182
|
return array[0]!.map((_, i) => {
|
|
180
183
|
return array.map(column => column[i])
|
|
181
184
|
}) as T[][]
|
|
182
185
|
}
|
|
183
186
|
|
|
184
|
-
|
|
187
|
+
function convertArrayOfRowsToTableNode(tableNode: Node, arrayOfNodes: (Node | null)[][]) {
|
|
185
188
|
const rowsPM = []
|
|
186
189
|
const map = TableMap.get(tableNode)
|
|
187
190
|
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
@@ -216,7 +219,7 @@ const convertArrayOfRowsToTableNode = (tableNode: Node, arrayOfNodes: (Node | nu
|
|
|
216
219
|
return newTable
|
|
217
220
|
}
|
|
218
221
|
|
|
219
|
-
|
|
222
|
+
function convertTableNodeToArrayOfRows(tableNode: Node) {
|
|
220
223
|
const map = TableMap.get(tableNode)
|
|
221
224
|
const rows: (Node | null)[][] = []
|
|
222
225
|
for (let rowIndex = 0; rowIndex < map.height; rowIndex++) {
|
|
@@ -242,12 +245,7 @@ const convertTableNodeToArrayOfRows = (tableNode: Node) => {
|
|
|
242
245
|
return rows
|
|
243
246
|
}
|
|
244
247
|
|
|
245
|
-
|
|
246
|
-
rows: (Node | null)[][],
|
|
247
|
-
indexesOrigin: number[],
|
|
248
|
-
indexesTarget: number[],
|
|
249
|
-
directionOverride: -1 | 1 | 0,
|
|
250
|
-
) => {
|
|
248
|
+
function moveRowInArrayOfRows(rows: (Node | null)[][], indexesOrigin: number[], indexesTarget: number[], directionOverride: -1 | 1 | 0) {
|
|
251
249
|
const direction = indexesOrigin[0]! > indexesTarget[0]! ? -1 : 1
|
|
252
250
|
|
|
253
251
|
const rowsExtracted = rows.splice(indexesOrigin[0]!, indexesOrigin.length)
|
|
@@ -271,12 +269,7 @@ const moveRowInArrayOfRows = (
|
|
|
271
269
|
return rows
|
|
272
270
|
}
|
|
273
271
|
|
|
274
|
-
|
|
275
|
-
table: ContentNodeWithPos,
|
|
276
|
-
indexesOrigin: number[],
|
|
277
|
-
indexesTarget: number[],
|
|
278
|
-
direction: -1 | 1 | 0,
|
|
279
|
-
) => {
|
|
272
|
+
function moveTableColumn(table: ContentNodeWithPos, indexesOrigin: number[], indexesTarget: number[], direction: -1 | 1 | 0) {
|
|
280
273
|
let rows = transpose(convertTableNodeToArrayOfRows(table.node))
|
|
281
274
|
|
|
282
275
|
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction)
|
|
@@ -285,12 +278,7 @@ const moveTableColumn = (
|
|
|
285
278
|
return convertArrayOfRowsToTableNode(table.node, rows)
|
|
286
279
|
}
|
|
287
280
|
|
|
288
|
-
|
|
289
|
-
table: ContentNodeWithPos,
|
|
290
|
-
indexesOrigin: number[],
|
|
291
|
-
indexesTarget: number[],
|
|
292
|
-
direction: -1 | 1 | 0,
|
|
293
|
-
) => {
|
|
281
|
+
function moveTableRow(table: ContentNodeWithPos, indexesOrigin: number[], indexesTarget: number[], direction: -1 | 1 | 0) {
|
|
294
282
|
let rows = convertTableNodeToArrayOfRows(table.node)
|
|
295
283
|
|
|
296
284
|
rows = moveRowInArrayOfRows(rows, indexesOrigin, indexesTarget, direction)
|
|
@@ -298,7 +286,7 @@ const moveTableRow = (
|
|
|
298
286
|
return convertArrayOfRowsToTableNode(table.node, rows)
|
|
299
287
|
}
|
|
300
288
|
|
|
301
|
-
|
|
289
|
+
function getSelectionRangeInColumn(columnIndex: number, tr: Transaction) {
|
|
302
290
|
let startIndex = columnIndex
|
|
303
291
|
let endIndex = columnIndex
|
|
304
292
|
|
|
@@ -363,7 +351,7 @@ const getSelectionRangeInColumn = (columnIndex: number, tr: Transaction) => {
|
|
|
363
351
|
return { $anchor, $head, indexes }
|
|
364
352
|
}
|
|
365
353
|
|
|
366
|
-
|
|
354
|
+
function getSelectionRangeInRow(rowIndex: number, tr: Transaction) {
|
|
367
355
|
let startIndex = rowIndex
|
|
368
356
|
let endIndex = rowIndex
|
|
369
357
|
// looking for selection start row (startIndex)
|
|
@@ -36,10 +36,10 @@ export const autoInsertZeroSpaceInTablePlugin = $prose((ctx) => {
|
|
|
36
36
|
|
|
37
37
|
if (
|
|
38
38
|
browser.safari
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
&& isInTable(state)
|
|
40
|
+
&& selection.empty
|
|
41
|
+
&& isParagraph($from.parent)
|
|
42
|
+
&& $from.parent.textContent.startsWith('\u2060')
|
|
43
43
|
)
|
|
44
44
|
dispatch(tr.delete($from.start(), $from.start() + 1))
|
|
45
45
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import type { $Remark } from '@milkdown/utils'
|
|
2
3
|
import { $remark } from '@milkdown/utils'
|
|
4
|
+
import type { Options } from 'remark-gfm'
|
|
3
5
|
import remarkGFM from 'remark-gfm'
|
|
4
6
|
import { withMeta } from '../__internal__'
|
|
5
7
|
|
|
6
8
|
/// This plugin is wrapping the [remark-gfm](https://github.com/remarkjs/remark-gfm).
|
|
7
|
-
export const remarkGFMPlugin = $remark('remarkGFM', () => remarkGFM)
|
|
9
|
+
export const remarkGFMPlugin: $Remark<'remarkGFM', Options | null | undefined> = $remark('remarkGFM', () => remarkGFM)
|
|
8
10
|
|
|
9
11
|
withMeta(remarkGFMPlugin.plugin, {
|
|
10
12
|
displayName: 'Remark<remarkGFMPlugin>',
|