@milkdown/preset-gfm 6.1.4 → 6.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/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 +1979 -891
- 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/supported-keys.d.ts +1 -0
- package/lib/supported-keys.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/index.d.ts +2 -23
- package/lib/table/nodes/index.d.ts.map +1 -1
- 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/plugin/auto-insert-zero-space.d.ts +3 -0
- package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -0
- package/lib/table/plugin/cell-selection.d.ts +38 -0
- package/lib/table/plugin/cell-selection.d.ts.map +1 -0
- package/lib/table/plugin/column-resizing.d.ts +17 -0
- package/lib/table/plugin/column-resizing.d.ts.map +1 -0
- package/lib/table/plugin/commands.d.ts +30 -0
- package/lib/table/plugin/commands.d.ts.map +1 -0
- package/lib/table/plugin/copy-paste.d.ts +13 -0
- package/lib/table/plugin/copy-paste.d.ts.map +1 -0
- package/lib/table/plugin/fix-tables.d.ts +6 -0
- package/lib/table/plugin/fix-tables.d.ts.map +1 -0
- package/lib/table/plugin/index.d.ts +4 -0
- package/lib/table/plugin/index.d.ts.map +1 -0
- package/lib/table/plugin/schema.d.ts +4 -0
- package/lib/table/plugin/schema.d.ts.map +1 -0
- package/lib/table/plugin/table-editing.d.ts +9 -0
- package/lib/table/plugin/table-editing.d.ts.map +1 -0
- package/lib/table/plugin/table-map.d.ts +44 -0
- package/lib/table/plugin/table-map.d.ts.map +1 -0
- package/lib/table/plugin/table-view.d.ts +15 -0
- package/lib/table/plugin/table-view.d.ts.map +1 -0
- package/lib/table/plugin/types.d.ts +15 -0
- package/lib/table/plugin/types.d.ts.map +1 -0
- package/lib/table/plugin/util.d.ts +16 -0
- package/lib/table/plugin/util.d.ts.map +1 -0
- package/lib/table/utils.d.ts +6 -6
- 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 +8 -7
- package/src/auto-link.ts +4 -3
- package/src/footnote/definition.ts +3 -1
- package/src/footnote/reference.ts +2 -1
- package/src/table/command.ts +3 -3
- package/src/table/nodes/index.ts +7 -3
- package/src/table/operator-plugin/actions.ts +4 -4
- package/src/table/operator-plugin/calc-pos.ts +4 -2
- 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/plugin/auto-insert-zero-space.ts +51 -0
- package/src/table/plugin/cell-selection.ts +352 -0
- package/src/table/plugin/column-resizing.ts +260 -0
- package/src/table/plugin/commands.ts +551 -0
- package/src/table/plugin/copy-paste.ts +306 -0
- package/src/table/plugin/fix-tables.ts +117 -0
- package/src/table/plugin/index.ts +4 -0
- package/src/table/plugin/schema.ts +114 -0
- package/src/table/plugin/table-editing.ts +275 -0
- package/src/table/plugin/table-map.ts +280 -0
- package/src/table/plugin/table-view.ts +76 -0
- package/src/table/plugin/types.ts +16 -0
- package/src/table/plugin/util.ts +107 -0
- package/src/table/utils.ts +31 -22
- package/src/task-list-item.ts +4 -2
- package/lib/table/nodes/schema.d.ts +0 -2
- package/lib/table/nodes/schema.d.ts.map +0 -1
- package/src/table/nodes/schema.ts +0 -16
|
@@ -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
|
+
}
|
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 './plugin/cell-selection';
|
|
7
|
+
import { tableNodeTypes } from './plugin/schema';
|
|
8
|
+
import { Rect, TableMap } from './plugin/table-map';
|
|
6
9
|
|
|
7
10
|
export type CellPos = {
|
|
8
11
|
pos: number;
|
|
@@ -23,16 +26,19 @@ export const getCellsInColumn =
|
|
|
23
26
|
return undefined;
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
return map
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
pos
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
return map
|
|
30
|
+
.cellsInRect({ left: columnIndex, right: columnIndex + 1, top: 0, bottom: map.height })
|
|
31
|
+
.map((pos) => {
|
|
32
|
+
const node = table.node.nodeAt(pos);
|
|
33
|
+
if (!node) return;
|
|
34
|
+
const start = pos + table.start;
|
|
35
|
+
return {
|
|
36
|
+
pos: start,
|
|
37
|
+
start: start + 1,
|
|
38
|
+
node,
|
|
39
|
+
};
|
|
40
|
+
})
|
|
41
|
+
.filter((x): x is CellPos => x != null);
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
export const getCellsInRow =
|
|
@@ -45,16 +51,19 @@ export const getCellsInRow =
|
|
|
45
51
|
return undefined;
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
return map
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
pos
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
return map
|
|
55
|
+
.cellsInRect({ left: 0, right: map.width, top: rowIndex, bottom: rowIndex + 1 })
|
|
56
|
+
.map((pos) => {
|
|
57
|
+
const node = table.node.nodeAt(pos);
|
|
58
|
+
if (!node) return;
|
|
59
|
+
const start = pos + table.start;
|
|
60
|
+
return {
|
|
61
|
+
pos: start,
|
|
62
|
+
start: start + 1,
|
|
63
|
+
node,
|
|
64
|
+
};
|
|
65
|
+
})
|
|
66
|
+
.filter((x): x is CellPos => x != null);
|
|
58
67
|
};
|
|
59
68
|
|
|
60
69
|
export const createTable = (schema: Schema, rowsCount = 3, colsCount = 3) => {
|
|
@@ -132,7 +141,7 @@ export const selectTable = (tr: Transaction) => {
|
|
|
132
141
|
return tr;
|
|
133
142
|
};
|
|
134
143
|
|
|
135
|
-
export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }:
|
|
144
|
+
export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }: Required<Rect>, row: number) {
|
|
136
145
|
const rowPos = Array(row)
|
|
137
146
|
.fill(0)
|
|
138
147
|
.reduce((acc, _, i) => {
|
package/src/task-list-item.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { createCmd, createCmdKey, editorViewCtx, ThemeTaskListItemType } from '@milkdown/core';
|
|
3
|
+
import { expectDomTypeError } from '@milkdown/exception';
|
|
3
4
|
import { wrapIn } from '@milkdown/prose/commands';
|
|
4
5
|
import { wrappingInputRule } from '@milkdown/prose/inputrules';
|
|
5
6
|
import { liftListItem, sinkListItem, splitListItem } from '@milkdown/prose/schema-list';
|
|
7
|
+
import { NodeView } from '@milkdown/prose/view';
|
|
6
8
|
import { createNode, createShortcut } from '@milkdown/utils';
|
|
7
9
|
|
|
8
10
|
import { SupportedKeys } from './supported-keys';
|
|
@@ -34,7 +36,7 @@ export const taskListItem = createNode<Keys>((utils) => {
|
|
|
34
36
|
tag: 'li[data-type="task-item"]',
|
|
35
37
|
getAttrs: (dom) => {
|
|
36
38
|
if (!(dom instanceof HTMLElement)) {
|
|
37
|
-
throw
|
|
39
|
+
throw expectDomTypeError(dom);
|
|
38
40
|
}
|
|
39
41
|
return { checked: dom.dataset['checked'] === 'true' };
|
|
40
42
|
},
|
|
@@ -130,7 +132,7 @@ export const taskListItem = createNode<Keys>((utils) => {
|
|
|
130
132
|
},
|
|
131
133
|
});
|
|
132
134
|
|
|
133
|
-
if (!renderer) return {};
|
|
135
|
+
if (!renderer) return {} as NodeView;
|
|
134
136
|
|
|
135
137
|
const { dom, contentDOM, onUpdate } = renderer;
|
|
136
138
|
onUpdate(currNode);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/table/nodes/schema.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,6CAYjB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { tableNodes as tableNodesSpecCreator } from '@milkdown/prose/tables';
|
|
3
|
-
|
|
4
|
-
export const schema = tableNodesSpecCreator({
|
|
5
|
-
tableGroup: 'block',
|
|
6
|
-
cellContent: 'paragraph',
|
|
7
|
-
cellAttributes: {
|
|
8
|
-
alignment: {
|
|
9
|
-
default: 'left',
|
|
10
|
-
getFromDOM: (dom) => (dom as HTMLElement).style.textAlign || 'left',
|
|
11
|
-
setDOMAttr: (value, attrs) => {
|
|
12
|
-
attrs.style = `text-align: ${value || 'left'}`;
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|