@milkdown/preset-gfm 6.1.3 → 6.2.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/auto-link.d.ts.map +1 -1
- package/lib/footnote/definition.d.ts +1 -5
- package/lib/footnote/definition.d.ts.map +1 -1
- package/lib/footnote/reference.d.ts +1 -5
- package/lib/footnote/reference.d.ts.map +1 -1
- package/lib/index.d.ts +1 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +1671 -16
- package/lib/index.es.js.map +1 -1
- package/lib/strike-through.d.ts +1 -5
- package/lib/strike-through.d.ts.map +1 -1
- package/lib/table/command.d.ts +1 -1
- package/lib/table/command.d.ts.map +1 -1
- package/lib/table/nodes/cell-selection.d.ts +38 -0
- package/lib/table/nodes/cell-selection.d.ts.map +1 -0
- package/lib/table/nodes/column-resizing.d.ts +10 -0
- package/lib/table/nodes/column-resizing.d.ts.map +1 -0
- package/lib/table/nodes/commands.d.ts +30 -0
- package/lib/table/nodes/commands.d.ts.map +1 -0
- package/lib/table/nodes/copy-paste.d.ts +13 -0
- package/lib/table/nodes/copy-paste.d.ts.map +1 -0
- package/lib/table/nodes/fix-tables.d.ts +6 -0
- package/lib/table/nodes/fix-tables.d.ts.map +1 -0
- package/lib/table/nodes/index.d.ts +5 -23
- package/lib/table/nodes/index.d.ts.map +1 -1
- package/lib/table/nodes/schema.d.ts +3 -1
- package/lib/table/nodes/schema.d.ts.map +1 -1
- package/lib/table/nodes/table-editing.d.ts +9 -0
- package/lib/table/nodes/table-editing.d.ts.map +1 -0
- package/lib/table/nodes/table-map.d.ts +44 -0
- package/lib/table/nodes/table-map.d.ts.map +1 -0
- package/lib/table/nodes/table-view.d.ts +15 -0
- package/lib/table/nodes/table-view.d.ts.map +1 -0
- package/lib/table/nodes/types.d.ts +15 -0
- package/lib/table/nodes/types.d.ts.map +1 -0
- package/lib/table/nodes/util.d.ts +16 -0
- package/lib/table/nodes/util.d.ts.map +1 -0
- package/lib/table/operator-plugin/actions.d.ts +1 -1
- package/lib/table/operator-plugin/actions.d.ts.map +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
- package/lib/table/operator-plugin/helper.d.ts +1 -1
- package/lib/table/operator-plugin/helper.d.ts.map +1 -1
- package/lib/table/operator-plugin/index.d.ts +1 -1
- package/lib/table/operator-plugin/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/widget.d.ts +4 -4
- package/lib/table/operator-plugin/widget.d.ts.map +1 -1
- package/lib/table/utils.d.ts +4 -4
- package/lib/table/utils.d.ts.map +1 -1
- package/lib/task-list-item.d.ts +1 -5
- package/lib/task-list-item.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/auto-link.ts +4 -3
- package/src/table/command.ts +3 -3
- package/src/table/nodes/cell-selection.ts +352 -0
- package/src/table/nodes/column-resizing.ts +260 -0
- package/src/table/nodes/commands.ts +551 -0
- package/src/table/nodes/copy-paste.ts +306 -0
- package/src/table/nodes/fix-tables.ts +117 -0
- package/src/table/nodes/index.ts +7 -1
- package/src/table/nodes/schema.ts +100 -2
- package/src/table/nodes/table-editing.ts +275 -0
- package/src/table/nodes/table-map.ts +280 -0
- package/src/table/nodes/table-view.ts +76 -0
- package/src/table/nodes/types.ts +16 -0
- package/src/table/nodes/util.ts +107 -0
- package/src/table/operator-plugin/actions.ts +4 -4
- package/src/table/operator-plugin/calc-pos.ts +2 -1
- package/src/table/operator-plugin/helper.ts +2 -1
- package/src/table/operator-plugin/index.ts +1 -1
- package/src/table/operator-plugin/widget.ts +4 -14
- package/src/table/utils.ts +5 -2
- package/src/task-list-item.ts +2 -1
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Attrs, Node, ResolvedPos } from '@milkdown/prose/model';
|
|
3
|
+
import { EditorState, NodeSelection } from '@milkdown/prose/state';
|
|
4
|
+
|
|
5
|
+
import { CellSelection } from './cell-selection';
|
|
6
|
+
import { tableNodeTypes } from './schema';
|
|
7
|
+
import { TableMap } from './table-map';
|
|
8
|
+
|
|
9
|
+
export function cellAround($pos: ResolvedPos) {
|
|
10
|
+
for (let d = $pos.depth - 1; d > 0; d--)
|
|
11
|
+
if ($pos.node(d).type.spec['tableRole'] == 'row') return $pos.node(0).resolve($pos.before(d + 1));
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function cellWrapping($pos: ResolvedPos) {
|
|
16
|
+
for (let d = $pos.depth; d > 0; d--) {
|
|
17
|
+
// Sometimes the cell can be in the same depth.
|
|
18
|
+
const role = $pos.node(d).type.spec['tableRole'];
|
|
19
|
+
if (role === 'cell' || role === 'header_cell') return $pos.node(d);
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function pointsAtCell($pos: ResolvedPos): Node | null {
|
|
25
|
+
if ($pos.parent.type.spec['tableRole'] == 'row') return $pos.nodeAfter;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function moveCellForward($pos: ResolvedPos) {
|
|
30
|
+
return $pos.node(0).resolve($pos.pos + ($pos.nodeAfter as Node).nodeSize);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function inSameTable($a: ResolvedPos, $b: ResolvedPos) {
|
|
34
|
+
return $a.depth == $b.depth && $a.pos >= $b.start(-1) && $a.pos <= $b.end(-1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function nextCell($pos: ResolvedPos, axis: string, dir: number) {
|
|
38
|
+
const start = $pos.start(-1),
|
|
39
|
+
map = TableMap.get($pos.node(-1));
|
|
40
|
+
const moved = map.nextCell($pos.pos - start, axis, dir);
|
|
41
|
+
return moved == null ? null : $pos.node(0).resolve(start + moved);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function setAttr<T>(attrs: Attrs, name: string, value: T) {
|
|
45
|
+
const result: Record<string, unknown> = {};
|
|
46
|
+
for (const prop in attrs) result[prop] = attrs[prop];
|
|
47
|
+
result[name] = value;
|
|
48
|
+
return result as Attrs;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function removeColSpan(attrs: Attrs, pos: number, n = 1) {
|
|
52
|
+
const result = setAttr(attrs, 'colspan', attrs['colspan'] - n) as Record<string, unknown>;
|
|
53
|
+
if (result['colwidth']) {
|
|
54
|
+
const widths = result['colwidth'] as number[];
|
|
55
|
+
result['colwidth'] = widths.slice();
|
|
56
|
+
widths.splice(pos, n);
|
|
57
|
+
if (!widths.some((w) => w > 0)) result['colwidth'] = null;
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isInTable(state: EditorState) {
|
|
63
|
+
const $head = state.selection.$head;
|
|
64
|
+
for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec['tableRole'] == 'row') return true;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function selectionCell(state: EditorState) {
|
|
69
|
+
const sel = state.selection;
|
|
70
|
+
if (sel instanceof CellSelection) {
|
|
71
|
+
return sel.$anchorCell.pos > sel.$headCell.pos ? sel.$anchorCell : sel.$headCell;
|
|
72
|
+
} else if ((sel as NodeSelection).node && (sel as NodeSelection).node.type.spec['tableRole'] == 'cell') {
|
|
73
|
+
return sel.$anchor;
|
|
74
|
+
}
|
|
75
|
+
return cellAround(sel.$head) || cellNear(sel.$head);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function cellNear($pos: ResolvedPos) {
|
|
79
|
+
for (let after = $pos.nodeAfter, pos = $pos.pos; after; after = after.firstChild, pos++) {
|
|
80
|
+
const role = after.type.spec['tableRole'];
|
|
81
|
+
if (role == 'cell' || role == 'header_cell') return $pos.doc.resolve(pos);
|
|
82
|
+
}
|
|
83
|
+
for (let before = $pos.nodeBefore, pos = $pos.pos; before; before = before.lastChild, pos--) {
|
|
84
|
+
const role = before.type.spec['tableRole'];
|
|
85
|
+
if (role == 'cell' || role == 'header_cell') return $pos.doc.resolve(pos - before.nodeSize);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function addColSpan(attrs: Attrs, pos: number, n = 1) {
|
|
91
|
+
const result = setAttr(attrs, 'colspan', attrs['colspan'] + n) as Record<string, unknown>;
|
|
92
|
+
if (result['colwidth']) {
|
|
93
|
+
const widths = result['colwidth'] as number[];
|
|
94
|
+
result['colwidth'] = widths.slice();
|
|
95
|
+
for (let i = 0; i < n; i++) widths.splice(pos, 0, 0);
|
|
96
|
+
}
|
|
97
|
+
return result as Attrs;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function columnIsHeader(map: TableMap, table: Node, col: number) {
|
|
101
|
+
const headerCell = tableNodeTypes(table.type.schema).header_cell;
|
|
102
|
+
for (let row = 0; row < map.height; row++) {
|
|
103
|
+
const pos = map.map[col + row * map.width] as number;
|
|
104
|
+
if ((table.nodeAt(pos) as Node).type != headerCell) return false;
|
|
105
|
+
}
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
|
|
3
|
-
import { Command } from '@milkdown/prose/
|
|
3
|
+
import { Command } from '@milkdown/prose/state';
|
|
4
|
+
import { EditorView } from '@milkdown/prose/view';
|
|
5
|
+
|
|
4
6
|
import {
|
|
5
7
|
addColumnAfter,
|
|
6
8
|
addColumnBefore,
|
|
@@ -10,9 +12,7 @@ import {
|
|
|
10
12
|
isInTable,
|
|
11
13
|
selectedRect,
|
|
12
14
|
setCellAttr,
|
|
13
|
-
} from '
|
|
14
|
-
import { EditorView } from '@milkdown/prose/view';
|
|
15
|
-
|
|
15
|
+
} from '../nodes';
|
|
16
16
|
import { addRowWithAlignment } from '../utils';
|
|
17
17
|
import { getCellSelection, isFirstRowSelected } from './helper';
|
|
18
18
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
3
|
import { calculateNodePosition } from '@milkdown/prose';
|
|
4
|
-
import { CellSelection } from '@milkdown/prose/tables';
|
|
5
4
|
import { EditorView } from '@milkdown/prose/view';
|
|
6
5
|
|
|
6
|
+
import { CellSelection } from '../nodes/cell-selection';
|
|
7
|
+
|
|
7
8
|
export const calculatePosition = (view: EditorView, dom: HTMLElement) => {
|
|
8
9
|
const { selection } = view.state as unknown as { selection: CellSelection };
|
|
9
10
|
const isCol = selection.isColSelection();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { CellSelection, TableMap } from '@milkdown/prose/tables';
|
|
3
2
|
import { EditorView } from '@milkdown/prose/view';
|
|
4
3
|
|
|
4
|
+
import { CellSelection } from '../nodes/cell-selection';
|
|
5
|
+
import { TableMap } from '../nodes/table-map';
|
|
5
6
|
import { Item } from './actions';
|
|
6
7
|
|
|
7
8
|
export const getCellSelection = (view: EditorView): CellSelection => view.state.selection as unknown as CellSelection;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { Ctx } from '@milkdown/core';
|
|
4
4
|
import { Plugin, PluginKey } from '@milkdown/prose/state';
|
|
5
|
-
import { CellSelection } from '@milkdown/prose/tables';
|
|
6
5
|
import { Decoration, DecorationSet } from '@milkdown/prose/view';
|
|
7
6
|
import { Utils } from '@milkdown/utils';
|
|
8
7
|
|
|
8
|
+
import { CellSelection } from '../nodes/cell-selection';
|
|
9
9
|
import { CellPos, getCellsInColumn, getCellsInRow } from '../utils';
|
|
10
10
|
import { createActions } from './actions';
|
|
11
11
|
import { calculatePosition } from './calc-pos';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
3
|
import { Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
|
|
4
|
-
import { Decoration
|
|
4
|
+
import { Decoration } from '@milkdown/prose/view';
|
|
5
5
|
|
|
6
6
|
import { CellPos, selectLine, selectTable } from '../utils';
|
|
7
7
|
import { ToolTipPos } from './constant';
|
|
@@ -21,19 +21,9 @@ const calculateClassName = (pos: ToolTipPos) => {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Point): Decoration
|
|
25
|
-
export function createWidget(
|
|
26
|
-
|
|
27
|
-
cell: CellPos,
|
|
28
|
-
pos: ToolTipPos.Left,
|
|
29
|
-
index: number,
|
|
30
|
-
): Decoration<WidgetDecorationSpec>;
|
|
31
|
-
export function createWidget(
|
|
32
|
-
ctx: Ctx,
|
|
33
|
-
cell: CellPos,
|
|
34
|
-
pos: ToolTipPos.Top,
|
|
35
|
-
index: number,
|
|
36
|
-
): Decoration<WidgetDecorationSpec>;
|
|
24
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Point): Decoration;
|
|
25
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Left, index: number): Decoration;
|
|
26
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Top, index: number): Decoration;
|
|
37
27
|
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos, index = 0) {
|
|
38
28
|
return Decoration.widget(cell.pos + 1, (view) => {
|
|
39
29
|
const div = document.createElement('div');
|
package/src/table/utils.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { cloneTr, findParentNode } from '@milkdown/prose';
|
|
3
3
|
import { Node as ProsemirrorNode, Schema } from '@milkdown/prose/model';
|
|
4
4
|
import { Selection, Transaction } from '@milkdown/prose/state';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
import { CellSelection } from './nodes/cell-selection';
|
|
7
|
+
import { tableNodeTypes } from './nodes/schema';
|
|
8
|
+
import { Rect, TableMap } from './nodes/table-map';
|
|
6
9
|
|
|
7
10
|
export type CellPos = {
|
|
8
11
|
pos: number;
|
|
@@ -132,7 +135,7 @@ export const selectTable = (tr: Transaction) => {
|
|
|
132
135
|
return tr;
|
|
133
136
|
};
|
|
134
137
|
|
|
135
|
-
export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }:
|
|
138
|
+
export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }: Required<Rect>, row: number) {
|
|
136
139
|
const rowPos = Array(row)
|
|
137
140
|
.fill(0)
|
|
138
141
|
.reduce((acc, _, i) => {
|
package/src/task-list-item.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { createCmd, createCmdKey, editorViewCtx, ThemeTaskListItemType } from '@
|
|
|
3
3
|
import { wrapIn } from '@milkdown/prose/commands';
|
|
4
4
|
import { wrappingInputRule } from '@milkdown/prose/inputrules';
|
|
5
5
|
import { liftListItem, sinkListItem, splitListItem } from '@milkdown/prose/schema-list';
|
|
6
|
+
import { NodeView } from '@milkdown/prose/view';
|
|
6
7
|
import { createNode, createShortcut } from '@milkdown/utils';
|
|
7
8
|
|
|
8
9
|
import { SupportedKeys } from './supported-keys';
|
|
@@ -130,7 +131,7 @@ export const taskListItem = createNode<Keys>((utils) => {
|
|
|
130
131
|
},
|
|
131
132
|
});
|
|
132
133
|
|
|
133
|
-
if (!renderer) return {};
|
|
134
|
+
if (!renderer) return {} as NodeView;
|
|
134
135
|
|
|
135
136
|
const { dom, contentDOM, onUpdate } = renderer;
|
|
136
137
|
onUpdate(currNode);
|