@milkdown/preset-gfm 5.2.1 → 5.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/index.d.ts +1 -36
- package/lib/index.es.js +768 -17
- package/lib/index.es.js.map +1 -1
- package/lib/src/auto-link.d.ts +2 -0
- package/lib/src/auto-link.d.ts.map +1 -0
- package/lib/src/index.d.ts +36 -0
- package/lib/src/index.d.ts.map +1 -0
- package/lib/{strike-through.d.ts → src/strike-through.d.ts} +1 -1
- package/lib/src/strike-through.d.ts.map +1 -0
- package/lib/{supported-keys.d.ts → src/supported-keys.d.ts} +0 -0
- package/lib/src/supported-keys.d.ts.map +1 -0
- package/lib/src/table/command.d.ts +3 -0
- package/lib/src/table/command.d.ts.map +1 -0
- package/lib/src/table/index.d.ts +10 -0
- package/lib/src/table/index.d.ts.map +1 -0
- package/lib/src/table/nodes/index.d.ts +32 -0
- package/lib/src/table/nodes/index.d.ts.map +1 -0
- package/lib/src/table/nodes/schema.d.ts +2 -0
- package/lib/src/table/nodes/schema.d.ts.map +1 -0
- package/lib/src/table/nodes/style.d.ts +3 -0
- package/lib/src/table/nodes/style.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/actions.d.ts +19 -0
- package/lib/src/table/operator-plugin/actions.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/calc-pos.d.ts +3 -0
- package/lib/src/table/operator-plugin/calc-pos.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/constant.d.ts +6 -0
- package/lib/src/table/operator-plugin/constant.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/helper.d.ts +6 -0
- package/lib/src/table/operator-plugin/helper.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/index.d.ts +6 -0
- package/lib/src/table/operator-plugin/index.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/style.d.ts +3 -0
- package/lib/src/table/operator-plugin/style.d.ts.map +1 -0
- package/lib/src/table/operator-plugin/widget.d.ts +8 -0
- package/lib/src/table/operator-plugin/widget.d.ts.map +1 -0
- package/lib/src/table/utils.d.ts +19 -0
- package/lib/src/table/utils.d.ts.map +1 -0
- package/lib/{task-list-item.d.ts → src/task-list-item.d.ts} +1 -1
- package/lib/src/task-list-item.d.ts.map +1 -0
- package/package.json +14 -27
- package/src/auto-link.ts +4 -9
- package/src/index.ts +13 -6
- package/src/strike-through.ts +1 -2
- package/src/supported-keys.ts +2 -1
- package/src/table/command.ts +16 -0
- package/src/table/index.ts +13 -0
- package/src/table/nodes/index.ts +169 -0
- package/src/table/nodes/schema.ts +16 -0
- package/src/table/nodes/style.ts +170 -0
- package/src/table/operator-plugin/actions.ts +115 -0
- package/src/table/operator-plugin/calc-pos.ts +25 -0
- package/src/table/operator-plugin/constant.ts +7 -0
- package/src/table/operator-plugin/helper.ts +38 -0
- package/src/table/operator-plugin/index.ts +98 -0
- package/src/table/operator-plugin/style.ts +50 -0
- package/src/table/operator-plugin/widget.ts +66 -0
- package/src/table/utils.ts +158 -0
- package/src/task-list-item.ts +3 -3
- package/lib/auto-link.d.ts +0 -16
- package/lib/auto-link.d.ts.map +0 -1
- package/lib/index.cjs.js +0 -49
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/strike-through.d.ts.map +0 -1
- package/lib/supported-keys.d.ts.map +0 -1
- package/lib/task-list-item.d.ts.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
|
|
3
|
+
import { Ctx } from '@milkdown/core';
|
|
4
|
+
import { CellSelection, Decoration, DecorationSet, Plugin, PluginKey } from '@milkdown/prose';
|
|
5
|
+
import { Utils } from '@milkdown/utils';
|
|
6
|
+
|
|
7
|
+
import { getCellsInColumn, getCellsInRow } from '../utils';
|
|
8
|
+
import { createActions } from './actions';
|
|
9
|
+
import { calculatePosition } from './calc-pos';
|
|
10
|
+
import { ToolTipPos } from './constant';
|
|
11
|
+
import { calculateItem } from './helper';
|
|
12
|
+
import { injectStyle } from './style';
|
|
13
|
+
import { createWidget } from './widget';
|
|
14
|
+
|
|
15
|
+
export const key = 'MILKDOWN_PLUGIN_TABLE';
|
|
16
|
+
|
|
17
|
+
export const operatorPlugin = (ctx: Ctx, utils: Utils) => {
|
|
18
|
+
const items = createActions(ctx);
|
|
19
|
+
const tooltip = document.createElement('div');
|
|
20
|
+
const style = utils.getStyle(injectStyle);
|
|
21
|
+
if (style) {
|
|
22
|
+
tooltip.classList.add(style);
|
|
23
|
+
}
|
|
24
|
+
tooltip.classList.add('table-tooltip', 'hide');
|
|
25
|
+
|
|
26
|
+
return new Plugin({
|
|
27
|
+
key: new PluginKey('MILKDOWN_TABLE_OP'),
|
|
28
|
+
props: {
|
|
29
|
+
decorations: (state) => {
|
|
30
|
+
const decorations: Decoration[] = [];
|
|
31
|
+
const leftCells = getCellsInColumn(0)(state.selection);
|
|
32
|
+
if (!leftCells) return null;
|
|
33
|
+
const topCells = getCellsInRow(0)(state.selection);
|
|
34
|
+
if (!topCells) return null;
|
|
35
|
+
|
|
36
|
+
const [topLeft] = leftCells;
|
|
37
|
+
|
|
38
|
+
decorations.push(createWidget(ctx, topLeft, ToolTipPos.Point));
|
|
39
|
+
leftCells.forEach((cell, i) => {
|
|
40
|
+
decorations.push(createWidget(ctx, cell, ToolTipPos.Left, i));
|
|
41
|
+
});
|
|
42
|
+
topCells.forEach((cell, i) => {
|
|
43
|
+
decorations.push(createWidget(ctx, cell, ToolTipPos.Top, i));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return DecorationSet.create(state.doc, decorations);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
view: (editorView) => {
|
|
50
|
+
Object.values(items).forEach(({ $ }) => tooltip.appendChild($));
|
|
51
|
+
editorView.dom.parentNode?.appendChild(tooltip);
|
|
52
|
+
|
|
53
|
+
const listener = (e: Event) => {
|
|
54
|
+
if (!editorView) return;
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
Object.values(items).forEach(({ $, command }) => {
|
|
58
|
+
if ($.contains(e.target as Element)) {
|
|
59
|
+
command(e, editorView)(editorView.state, editorView.dispatch, editorView);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const hide = () => {
|
|
65
|
+
tooltip.classList.add('hide');
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
tooltip.addEventListener('mousedown', listener);
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
update: (view, prevState) => {
|
|
72
|
+
const state = view.state;
|
|
73
|
+
|
|
74
|
+
if (prevState?.doc.eq(state.doc) && prevState.selection.eq(state.selection)) return;
|
|
75
|
+
|
|
76
|
+
const isCellSelection = state.selection instanceof CellSelection;
|
|
77
|
+
|
|
78
|
+
if (!isCellSelection || !view.editable) {
|
|
79
|
+
hide();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
calculateItem(items, view);
|
|
84
|
+
if (Object.values(items).every(({ $ }) => $.classList.contains('hide'))) {
|
|
85
|
+
hide();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
tooltip.classList.remove('hide');
|
|
89
|
+
calculatePosition(view, tooltip);
|
|
90
|
+
},
|
|
91
|
+
destroy: () => {
|
|
92
|
+
tooltip.removeEventListener('mousedown', listener);
|
|
93
|
+
tooltip.remove();
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import { Emotion, ThemeTool } from '@milkdown/core';
|
|
3
|
+
|
|
4
|
+
export const injectStyle = ({ size, mixin, palette }: ThemeTool, { css }: Emotion) => css`
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
z-index: 2;
|
|
8
|
+
|
|
9
|
+
justify-content: space-evenly;
|
|
10
|
+
|
|
11
|
+
position: absolute;
|
|
12
|
+
|
|
13
|
+
border-radius: ${size.radius};
|
|
14
|
+
|
|
15
|
+
${mixin.border?.()};
|
|
16
|
+
|
|
17
|
+
${mixin.shadow?.()};
|
|
18
|
+
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
background: ${palette('surface')};
|
|
21
|
+
|
|
22
|
+
.icon {
|
|
23
|
+
position: relative;
|
|
24
|
+
color: ${palette('solid', 0.87)};
|
|
25
|
+
|
|
26
|
+
width: 3rem;
|
|
27
|
+
line-height: 3rem;
|
|
28
|
+
text-align: center;
|
|
29
|
+
transition: all 0.4s ease-in-out;
|
|
30
|
+
&:hover {
|
|
31
|
+
background-color: ${palette('secondary', 0.12)};
|
|
32
|
+
}
|
|
33
|
+
&.active {
|
|
34
|
+
color: ${palette('primary')};
|
|
35
|
+
}
|
|
36
|
+
&:not(:last-child)::after {
|
|
37
|
+
content: '';
|
|
38
|
+
position: absolute;
|
|
39
|
+
right: 0px;
|
|
40
|
+
top: 0;
|
|
41
|
+
width: ${size.lineWidth};
|
|
42
|
+
bottom: 0;
|
|
43
|
+
background: ${palette('line')};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
&.hide,
|
|
47
|
+
.hide {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
|
|
3
|
+
import { Ctx, themeToolCtx } from '@milkdown/core';
|
|
4
|
+
import { Decoration, WidgetDecorationSpec } from '@milkdown/prose';
|
|
5
|
+
|
|
6
|
+
import { CellPos, selectLine, selectTable } from '../utils';
|
|
7
|
+
import { ToolTipPos } from './constant';
|
|
8
|
+
|
|
9
|
+
const calculateClassName = (pos: ToolTipPos) => {
|
|
10
|
+
switch (pos) {
|
|
11
|
+
case ToolTipPos.Left: {
|
|
12
|
+
return 'milkdown-cell-left';
|
|
13
|
+
}
|
|
14
|
+
case ToolTipPos.Top: {
|
|
15
|
+
return 'milkdown-cell-top';
|
|
16
|
+
}
|
|
17
|
+
case ToolTipPos.Point:
|
|
18
|
+
default: {
|
|
19
|
+
return 'milkdown-cell-point';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Point): Decoration<WidgetDecorationSpec>;
|
|
25
|
+
export function createWidget(
|
|
26
|
+
ctx: Ctx,
|
|
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>;
|
|
37
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos, index = 0) {
|
|
38
|
+
const widget = Decoration.widget(cell.pos + 1, (view) => {
|
|
39
|
+
const div = document.createElement('div');
|
|
40
|
+
div.classList.add(calculateClassName(pos));
|
|
41
|
+
if (pos === ToolTipPos.Point) {
|
|
42
|
+
div.appendChild(ctx.get(themeToolCtx).slots.icon('select'));
|
|
43
|
+
}
|
|
44
|
+
div.addEventListener('mousedown', (e) => {
|
|
45
|
+
if (!view) return;
|
|
46
|
+
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
switch (pos) {
|
|
49
|
+
case ToolTipPos.Point: {
|
|
50
|
+
view.dispatch(selectTable(view.state.tr));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
case ToolTipPos.Left: {
|
|
54
|
+
view.dispatch(selectLine('row')(index)(view.state.tr));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
case ToolTipPos.Top: {
|
|
58
|
+
view.dispatch(selectLine('col')(index)(view.state.tr));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return div;
|
|
64
|
+
});
|
|
65
|
+
return widget;
|
|
66
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
+
import {
|
|
3
|
+
CellSelection,
|
|
4
|
+
cloneTr,
|
|
5
|
+
findParentNode,
|
|
6
|
+
Node as ProsemirrorNode,
|
|
7
|
+
Schema,
|
|
8
|
+
Selection,
|
|
9
|
+
TableMap,
|
|
10
|
+
tableNodeTypes,
|
|
11
|
+
TableRect,
|
|
12
|
+
Transaction,
|
|
13
|
+
} from '@milkdown/prose';
|
|
14
|
+
|
|
15
|
+
export type CellPos = {
|
|
16
|
+
pos: number;
|
|
17
|
+
start: number;
|
|
18
|
+
node: ProsemirrorNode;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const findTable = (selection: Selection) =>
|
|
22
|
+
findParentNode((node) => node.type.spec.tableRole === 'table')(selection);
|
|
23
|
+
|
|
24
|
+
export const getCellsInColumn =
|
|
25
|
+
(columnIndex: number) =>
|
|
26
|
+
(selection: Selection): CellPos[] | undefined => {
|
|
27
|
+
const table = findTable(selection);
|
|
28
|
+
if (!table) return undefined;
|
|
29
|
+
const map = TableMap.get(table.node);
|
|
30
|
+
if (columnIndex < 0 || columnIndex >= map.width) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return map.cellsInRect({ left: columnIndex, right: columnIndex + 1, top: 0, bottom: map.height }).map((pos) => {
|
|
35
|
+
const node = table.node.nodeAt(pos);
|
|
36
|
+
if (!node) throw new Error();
|
|
37
|
+
const start = pos + table.start;
|
|
38
|
+
return {
|
|
39
|
+
pos: start,
|
|
40
|
+
start: start + 1,
|
|
41
|
+
node,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const getCellsInRow =
|
|
47
|
+
(rowIndex: number) =>
|
|
48
|
+
(selection: Selection): CellPos[] | undefined => {
|
|
49
|
+
const table = findTable(selection);
|
|
50
|
+
if (!table) return undefined;
|
|
51
|
+
const map = TableMap.get(table.node);
|
|
52
|
+
if (rowIndex < 0 || rowIndex >= map.height) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return map.cellsInRect({ left: 0, right: map.width, top: rowIndex, bottom: rowIndex + 1 }).map((pos) => {
|
|
57
|
+
const node = table.node.nodeAt(pos);
|
|
58
|
+
if (!node) throw new Error();
|
|
59
|
+
const start = pos + table.start;
|
|
60
|
+
return {
|
|
61
|
+
pos: start,
|
|
62
|
+
start: start + 1,
|
|
63
|
+
node,
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const createTable = (schema: Schema, rowsCount = 3, colsCount = 3) => {
|
|
69
|
+
const { cell: tableCell, header_cell: tableHeader, row: tableRow, table } = tableNodeTypes(schema);
|
|
70
|
+
|
|
71
|
+
const cells = Array(colsCount)
|
|
72
|
+
.fill(0)
|
|
73
|
+
.map(() => tableCell.createAndFill(null) as ProsemirrorNode);
|
|
74
|
+
|
|
75
|
+
const headerCells = Array(colsCount)
|
|
76
|
+
.fill(0)
|
|
77
|
+
.map(() => tableHeader.createAndFill(null) as ProsemirrorNode);
|
|
78
|
+
|
|
79
|
+
const rows = Array(rowsCount)
|
|
80
|
+
.fill(0)
|
|
81
|
+
.map((_, i) => tableRow.create(null, i === 0 ? headerCells : cells));
|
|
82
|
+
|
|
83
|
+
return table.create(null, rows);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const selectLine = (type: 'row' | 'col') => (index: number) => (tr: Transaction) => {
|
|
87
|
+
const table = findTable(tr.selection);
|
|
88
|
+
const isRowSelection = type === 'row';
|
|
89
|
+
if (table) {
|
|
90
|
+
const map = TableMap.get(table.node);
|
|
91
|
+
|
|
92
|
+
// Check if the index is valid
|
|
93
|
+
if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
|
|
94
|
+
const lastCell = map.positionAt(
|
|
95
|
+
isRowSelection ? index : map.height - 1,
|
|
96
|
+
isRowSelection ? map.width - 1 : index,
|
|
97
|
+
table.node,
|
|
98
|
+
);
|
|
99
|
+
const $lastCell = tr.doc.resolve(table.start + lastCell);
|
|
100
|
+
|
|
101
|
+
const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection;
|
|
102
|
+
|
|
103
|
+
const firstCell = map.positionAt(isRowSelection ? index : 0, isRowSelection ? 0 : index, table.node);
|
|
104
|
+
const $firstCell = tr.doc.resolve(table.start + firstCell);
|
|
105
|
+
return cloneTr(tr.setSelection(createCellSelection($lastCell, $firstCell) as unknown as Selection));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return tr;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const getCellsInTable = (selection: Selection) => {
|
|
112
|
+
const table = findTable(selection);
|
|
113
|
+
if (!table) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const map = TableMap.get(table.node);
|
|
117
|
+
const cells = map.cellsInRect({
|
|
118
|
+
left: 0,
|
|
119
|
+
right: map.width,
|
|
120
|
+
top: 0,
|
|
121
|
+
bottom: map.height,
|
|
122
|
+
});
|
|
123
|
+
return cells.map((nodePos) => {
|
|
124
|
+
const node = table.node.nodeAt(nodePos);
|
|
125
|
+
const pos = nodePos + table.start;
|
|
126
|
+
return { pos, start: pos + 1, node };
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const selectTable = (tr: Transaction) => {
|
|
131
|
+
const cells = getCellsInTable(tr.selection);
|
|
132
|
+
if (cells) {
|
|
133
|
+
const $firstCell = tr.doc.resolve(cells[0].pos);
|
|
134
|
+
const $lastCell = tr.doc.resolve(cells[cells.length - 1].pos);
|
|
135
|
+
return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell) as unknown as Selection));
|
|
136
|
+
}
|
|
137
|
+
return tr;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }: TableRect, row: number) {
|
|
141
|
+
const rowPos = Array(row)
|
|
142
|
+
.fill(0)
|
|
143
|
+
.reduce((acc, _, i) => {
|
|
144
|
+
return acc + table.child(i).nodeSize;
|
|
145
|
+
}, tableStart);
|
|
146
|
+
|
|
147
|
+
const { cell: cellType, row: rowType } = tableNodeTypes(table.type.schema);
|
|
148
|
+
|
|
149
|
+
const cells = Array(map.width)
|
|
150
|
+
.fill(0)
|
|
151
|
+
.map((_, col) => {
|
|
152
|
+
const headerCol = table.nodeAt(map.map[col]);
|
|
153
|
+
return cellType.createAndFill({ alignment: headerCol?.attrs.alignment }) as ProsemirrorNode;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
tr.insert(rowPos, rowType.create(null, cells));
|
|
157
|
+
return tr;
|
|
158
|
+
}
|
package/src/task-list-item.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { css } from '@emotion/css';
|
|
3
2
|
import { createCmd, createCmdKey, themeToolCtx } from '@milkdown/core';
|
|
4
3
|
import type { Icon } from '@milkdown/design-system';
|
|
5
4
|
import { liftListItem, sinkListItem, splitListItem, wrapIn, wrappingInputRule } from '@milkdown/prose';
|
|
@@ -17,7 +16,7 @@ export const TurnIntoTaskList = createCmdKey();
|
|
|
17
16
|
export const taskListItem = createNode<Keys>((utils) => {
|
|
18
17
|
const id = 'task_list_item';
|
|
19
18
|
const style = utils.getStyle(
|
|
20
|
-
({ palette, size }) =>
|
|
19
|
+
({ palette, size }, { css }) =>
|
|
21
20
|
css`
|
|
22
21
|
list-style-type: none;
|
|
23
22
|
position: relative;
|
|
@@ -72,6 +71,7 @@ export const taskListItem = createNode<Keys>((utils) => {
|
|
|
72
71
|
group: 'listItem',
|
|
73
72
|
content: 'paragraph block*',
|
|
74
73
|
defining: true,
|
|
74
|
+
priority: 60,
|
|
75
75
|
attrs: {
|
|
76
76
|
checked: {
|
|
77
77
|
default: false,
|
|
@@ -79,7 +79,7 @@ export const taskListItem = createNode<Keys>((utils) => {
|
|
|
79
79
|
},
|
|
80
80
|
parseDOM: [
|
|
81
81
|
{
|
|
82
|
-
tag: 'li[data-type="task-
|
|
82
|
+
tag: 'li[data-type="task-item"]',
|
|
83
83
|
getAttrs: (dom) => {
|
|
84
84
|
if (!(dom instanceof HTMLElement)) {
|
|
85
85
|
throw new Error();
|
package/lib/auto-link.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare const urlPlugin: import("@milkdown/utils/lib/types").WithExtend<string, import("@milkdown/utils").UnknownRecord, {
|
|
2
|
-
[x: string]: import("prosemirror-model").NodeType<any>;
|
|
3
|
-
} & {
|
|
4
|
-
[x: string]: import("prosemirror-model").MarkType<any>;
|
|
5
|
-
}, {
|
|
6
|
-
schema?: ((ctx: import("@milkdown/core").Ctx) => {
|
|
7
|
-
node?: Record<string, import("@milkdown/core").NodeSchema> | undefined;
|
|
8
|
-
mark?: Record<string, import("@milkdown/core").MarkSchema> | undefined;
|
|
9
|
-
}) | undefined;
|
|
10
|
-
view?: ((ctx: import("@milkdown/core").Ctx) => Partial<{
|
|
11
|
-
[x: string]: import("@milkdown/prose").NodeViewFactory;
|
|
12
|
-
} & {
|
|
13
|
-
[x: string]: import("@milkdown/prose").MarkViewFactory;
|
|
14
|
-
}>) | undefined;
|
|
15
|
-
}>;
|
|
16
|
-
//# sourceMappingURL=auto-link.d.ts.map
|
package/lib/auto-link.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-link.d.ts","sourceRoot":"","sources":["../src/auto-link.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;EAAmE,CAAC"}
|
package/lib/index.cjs.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";var B=Object.defineProperty,H=Object.defineProperties;var R=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var w=(c,n,o)=>n in c?B(c,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):c[n]=o,k=(c,n)=>{for(var o in n||(n={}))_.call(n,o)&&w(c,o,n[o]);if(x)for(var o of x(n))$.call(n,o)&&w(c,o,n[o]);return c},j=(c,n)=>H(c,R(n));Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var d=require("@milkdown/plugin-table"),t=require("@milkdown/preset-commonmark"),m=require("@milkdown/utils"),l=require("@milkdown/prose"),v=require("@emotion/css"),i=require("@milkdown/core");const D=/(https?:\/\/)?www\.[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)$/,z=()=>l.inputRules({rules:[new l.InputRule(D,(c,n,o,e)=>{const{schema:r}=c,[u]=n;return u?c.tr.replaceWith(o,e,r.text(u)).addMark(o,u.length+o,r.marks.link.create({href:u.startsWith("www")?`https://${u}`:u})):null})]}),F=m.createPlugin(()=>({prosePlugins:()=>[z()]})),g=j(k(k({},t.SupportedKeys),d.SupportedKeys),{StrikeThrough:"StrikeThrough",TaskList:"TaskList"}),h=i.createCmdKey(),A=m.createMark(c=>{const n="strike_through",o=c.getStyle(e=>v.css`
|
|
2
|
-
text-decoration-color: ${e.palette("secondary")};
|
|
3
|
-
`);return{id:n,schema:()=>({parseDOM:[{tag:"del"},{style:"text-decoration",getAttrs:e=>e==="line-through"}],toDOM:e=>["del",{class:c.getClassName(e.attrs,"strike-through",o)}],parseMarkdown:{match:e=>e.type==="delete",runner:(e,r,u)=>{e.openMark(u),e.next(r.children),e.closeMark(u)}},toMarkdown:{match:e=>e.type.name===n,runner:(e,r)=>{e.withMark(r,"delete")}}}),inputRules:e=>[l.markRule(/(?:~~)([^~]+)(?:~~)$/,e),l.markRule(/(?:^|[^~])(~([^~]+)~)$/,e)],commands:e=>[i.createCmd(h,()=>l.toggleMark(e))],shortcuts:{[g.StrikeThrough]:m.createShortcut(h,"Mod-Alt-x")}}}),y=i.createCmdKey(),I=i.createCmdKey(),P=i.createCmdKey(),O=i.createCmdKey(),E=m.createNode(c=>{const n="task_list_item",o=c.getStyle(({palette:e,size:r})=>v.css`
|
|
4
|
-
list-style-type: none;
|
|
5
|
-
position: relative;
|
|
6
|
-
|
|
7
|
-
& > div {
|
|
8
|
-
overflow: hidden;
|
|
9
|
-
padding: 0 2px;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
label {
|
|
13
|
-
position: absolute;
|
|
14
|
-
top: 0;
|
|
15
|
-
left: -2rem;
|
|
16
|
-
display: inline-block;
|
|
17
|
-
width: 1.5rem;
|
|
18
|
-
height: 1.5rem;
|
|
19
|
-
margin: 0.5rem 0;
|
|
20
|
-
input {
|
|
21
|
-
visibility: hidden;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
label:before {
|
|
25
|
-
position: absolute;
|
|
26
|
-
top: 0;
|
|
27
|
-
right: 0;
|
|
28
|
-
bottom: 0;
|
|
29
|
-
left: 0;
|
|
30
|
-
border-radius: ${r.radius};
|
|
31
|
-
}
|
|
32
|
-
label:hover:before {
|
|
33
|
-
background: ${e("background")};
|
|
34
|
-
}
|
|
35
|
-
&[data-checked='true'] {
|
|
36
|
-
label {
|
|
37
|
-
color: ${e("primary")};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
&[data-checked='false'] {
|
|
41
|
-
label {
|
|
42
|
-
color: ${e("solid",.87)};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
.paragraph {
|
|
46
|
-
margin: 0.5rem 0;
|
|
47
|
-
}
|
|
48
|
-
`);return{id:n,schema:()=>({group:"listItem",content:"paragraph block*",defining:!0,attrs:{checked:{default:!1}},parseDOM:[{tag:'li[data-type="task-list-item"]',getAttrs:e=>{if(!(e instanceof HTMLElement))throw new Error;return{checked:e.dataset.checked==="true"}}}],toDOM:e=>["li",{"data-type":"task-item","data-checked":e.attrs.checked?"true":"false",class:c.getClassName(e.attrs,"task-list-item",o)},0],parseMarkdown:{match:({type:e,checked:r})=>e==="listItem"&&r!==null,runner:(e,r,u)=>{e.openNode(u,{checked:r.checked}),e.next(r.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name===n,runner:(e,r)=>{e.openNode("listItem",void 0,{checked:r.attrs.checked}),e.next(r.content),e.closeNode()}}}),inputRules:e=>[l.wrappingInputRule(/^\s*(\[([ |x])\])\s$/,e,r=>({checked:r[r.length-1]==="x"}))],commands:e=>[i.createCmd(y,()=>l.splitListItem(e)),i.createCmd(I,()=>l.sinkListItem(e)),i.createCmd(P,()=>l.liftListItem(e)),i.createCmd(O,()=>l.wrapIn(e))],shortcuts:{[g.NextListItem]:m.createShortcut(y,"Enter"),[g.SinkListItem]:m.createShortcut(I,"Mod-]"),[g.LiftListItem]:m.createShortcut(P,"Mod-["),[g.TaskList]:m.createShortcut(O,"Mod-Alt-9")},view:e=>(r,u,N)=>{const T=e.get(i.themeToolCtx).slots.icon,f=document.createElement("li"),p=document.createElement("label"),q=document.createElement("span"),s=document.createElement("input"),M=document.createElement("div");let L=T("unchecked");p.appendChild(L);const S=a=>{const b=T(a);p.replaceChild(b,L),L=b};p.contentEditable="false",s.type="checkbox";const C=a=>{const b=a.target;if(!(b instanceof HTMLInputElement))return;if(!u.editable){s.checked=!s.checked;return}const{tr:W}=u.state;u.dispatch(W.setNodeMarkup(N(),void 0,{checked:b.checked}))};s.addEventListener("change",C),f.dataset.checked=r.attrs.checked,r.attrs.checked&&s.setAttribute("checked","checked"),p.append(s,q),f.append(p,M);const K={"data-type":"task-item","data-checked":r.attrs.checked?"true":"false",class:c.getClassName(r.attrs,"task-list-item",o)};return Object.entries(K).forEach(([a,b])=>{f.setAttribute(a,b)}),S(r.attrs.checked?"checked":"unchecked"),{dom:f,contentDOM:M,update:a=>a.type.name!==n?!1:(f.dataset.checked=a.attrs.checked,a.attrs.checked?s.setAttribute("checked","checked"):s.removeAttribute("checked"),S(a.attrs.checked?"checked":"unchecked"),!0),destroy:()=>{s.removeEventListener("change",C)}}}}}),Z=m.AtomList.create([...t.commonmark,d.tablePlugin(),F(),A(),E()]),U=j(k({},t.commands),{ToggleStrikeThrough:h,TurnIntoTaskList:O,SinkTaskListItem:I,LiftTaskListItem:P,SplitTaskListItem:y});Object.defineProperty(exports,"BreakTable",{enumerable:!0,get:function(){return d.BreakTable}});Object.defineProperty(exports,"InsertTable",{enumerable:!0,get:function(){return d.InsertTable}});Object.defineProperty(exports,"NextCell",{enumerable:!0,get:function(){return d.NextCell}});Object.defineProperty(exports,"PrevCell",{enumerable:!0,get:function(){return d.PrevCell}});Object.defineProperty(exports,"createTable",{enumerable:!0,get:function(){return d.createTable}});Object.defineProperty(exports,"table",{enumerable:!0,get:function(){return d.table}});Object.defineProperty(exports,"tablePlugin",{enumerable:!0,get:function(){return d.tablePlugin}});Object.defineProperty(exports,"InsertHardbreak",{enumerable:!0,get:function(){return t.InsertHardbreak}});Object.defineProperty(exports,"InsertHr",{enumerable:!0,get:function(){return t.InsertHr}});Object.defineProperty(exports,"InsertImage",{enumerable:!0,get:function(){return t.InsertImage}});Object.defineProperty(exports,"LiftListItem",{enumerable:!0,get:function(){return t.LiftListItem}});Object.defineProperty(exports,"ModifyImage",{enumerable:!0,get:function(){return t.ModifyImage}});Object.defineProperty(exports,"ModifyLink",{enumerable:!0,get:function(){return t.ModifyLink}});Object.defineProperty(exports,"SinkListItem",{enumerable:!0,get:function(){return t.SinkListItem}});Object.defineProperty(exports,"SplitListItem",{enumerable:!0,get:function(){return t.SplitListItem}});Object.defineProperty(exports,"ToggleBold",{enumerable:!0,get:function(){return t.ToggleBold}});Object.defineProperty(exports,"ToggleInlineCode",{enumerable:!0,get:function(){return t.ToggleInlineCode}});Object.defineProperty(exports,"ToggleItalic",{enumerable:!0,get:function(){return t.ToggleItalic}});Object.defineProperty(exports,"ToggleLink",{enumerable:!0,get:function(){return t.ToggleLink}});Object.defineProperty(exports,"TurnIntoCodeFence",{enumerable:!0,get:function(){return t.TurnIntoCodeFence}});Object.defineProperty(exports,"TurnIntoHeading",{enumerable:!0,get:function(){return t.TurnIntoHeading}});Object.defineProperty(exports,"TurnIntoText",{enumerable:!0,get:function(){return t.TurnIntoText}});Object.defineProperty(exports,"WrapInBlockquote",{enumerable:!0,get:function(){return t.WrapInBlockquote}});Object.defineProperty(exports,"WrapInBulletList",{enumerable:!0,get:function(){return t.WrapInBulletList}});Object.defineProperty(exports,"WrapInOrderedList",{enumerable:!0,get:function(){return t.WrapInOrderedList}});Object.defineProperty(exports,"blockquote",{enumerable:!0,get:function(){return t.blockquote}});Object.defineProperty(exports,"bulletList",{enumerable:!0,get:function(){return t.bulletList}});Object.defineProperty(exports,"codeFence",{enumerable:!0,get:function(){return t.codeFence}});Object.defineProperty(exports,"codeInline",{enumerable:!0,get:function(){return t.codeInline}});Object.defineProperty(exports,"commonmark",{enumerable:!0,get:function(){return t.commonmark}});Object.defineProperty(exports,"commonmarkNodes",{enumerable:!0,get:function(){return t.commonmarkNodes}});Object.defineProperty(exports,"commonmarkPlugins",{enumerable:!0,get:function(){return t.commonmarkPlugins}});Object.defineProperty(exports,"doc",{enumerable:!0,get:function(){return t.doc}});Object.defineProperty(exports,"em",{enumerable:!0,get:function(){return t.em}});Object.defineProperty(exports,"hardbreak",{enumerable:!0,get:function(){return t.hardbreak}});Object.defineProperty(exports,"heading",{enumerable:!0,get:function(){return t.heading}});Object.defineProperty(exports,"hr",{enumerable:!0,get:function(){return t.hr}});Object.defineProperty(exports,"image",{enumerable:!0,get:function(){return t.image}});Object.defineProperty(exports,"link",{enumerable:!0,get:function(){return t.link}});Object.defineProperty(exports,"listItem",{enumerable:!0,get:function(){return t.listItem}});Object.defineProperty(exports,"orderedList",{enumerable:!0,get:function(){return t.orderedList}});Object.defineProperty(exports,"paragraph",{enumerable:!0,get:function(){return t.paragraph}});Object.defineProperty(exports,"strong",{enumerable:!0,get:function(){return t.strong}});Object.defineProperty(exports,"text",{enumerable:!0,get:function(){return t.text}});exports.LiftTaskListItem=P;exports.SinkTaskListItem=I;exports.SplitTaskListItem=y;exports.SupportedKeys=g;exports.ToggleStrikeThrough=h;exports.TurnIntoTaskList=O;exports.commands=U;exports.gfm=Z;exports.strikeThrough=A;exports.taskListItem=E;
|
|
49
|
-
//# sourceMappingURL=index.cjs.js.map
|
package/lib/index.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/auto-link.ts","../src/supported-keys.ts","../src/strike-through.ts","../src/task-list-item.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { InputRule, inputRules } from '@milkdown/prose';\nimport { createPlugin } from '@milkdown/utils';\n\nconst urlRegex =\n /(https?:\\/\\/)?www\\.[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z]{2,}\\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)$/;\n\nconst proseUrlPlugin = () =>\n inputRules({\n rules: [\n new InputRule(urlRegex, (state, match, start, end) => {\n const { schema } = state;\n const [text] = match;\n if (!text) return null;\n\n return state.tr\n .replaceWith(start, end, schema.text(text))\n .addMark(\n start,\n text.length + start,\n schema.marks.link.create({ href: text.startsWith('www') ? `https://${text}` : text }),\n );\n }),\n ],\n });\n\nexport const urlPlugin = createPlugin(() => ({ prosePlugins: () => [proseUrlPlugin()] }));\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { SupportedKeys as TableKeys } from '@milkdown/plugin-table';\nimport { SupportedKeys as CommonmarkKeys } from '@milkdown/preset-commonmark';\n\nexport const SupportedKeys = {\n ...CommonmarkKeys,\n ...TableKeys,\n StrikeThrough: 'StrikeThrough',\n TaskList: 'TaskList',\n} as const;\nexport type SupportedKeys = typeof SupportedKeys;\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { css } from '@emotion/css';\nimport { createCmd, createCmdKey } from '@milkdown/core';\nimport { markRule, toggleMark } from '@milkdown/prose';\nimport { createMark, createShortcut } from '@milkdown/utils';\n\nimport { SupportedKeys } from './supported-keys';\n\ntype Keys = SupportedKeys['StrikeThrough'];\n\nexport const ToggleStrikeThrough = createCmdKey();\n\nexport const strikeThrough = createMark<Keys>((utils) => {\n const id = 'strike_through';\n const style = utils.getStyle(\n (themeTool) =>\n css`\n text-decoration-color: ${themeTool.palette('secondary')};\n `,\n );\n\n return {\n id,\n schema: () => ({\n parseDOM: [\n { tag: 'del' },\n { style: 'text-decoration', getAttrs: (value) => (value === 'line-through') as false },\n ],\n toDOM: (mark) => ['del', { class: utils.getClassName(mark.attrs, 'strike-through', style) }],\n parseMarkdown: {\n match: (node) => node.type === 'delete',\n runner: (state, node, markType) => {\n state.openMark(markType);\n state.next(node.children);\n state.closeMark(markType);\n },\n },\n toMarkdown: {\n match: (mark) => mark.type.name === id,\n runner: (state, mark) => {\n state.withMark(mark, 'delete');\n },\n },\n }),\n inputRules: (markType) => [\n markRule(/(?:~~)([^~]+)(?:~~)$/, markType),\n markRule(/(?:^|[^~])(~([^~]+)~)$/, markType),\n ],\n commands: (markType) => [createCmd(ToggleStrikeThrough, () => toggleMark(markType))],\n shortcuts: {\n [SupportedKeys.StrikeThrough]: createShortcut(ToggleStrikeThrough, 'Mod-Alt-x'),\n },\n };\n});\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { css } from '@emotion/css';\nimport { createCmd, createCmdKey, themeToolCtx } from '@milkdown/core';\nimport type { Icon } from '@milkdown/design-system';\nimport { liftListItem, sinkListItem, splitListItem, wrapIn, wrappingInputRule } from '@milkdown/prose';\nimport { createNode, createShortcut } from '@milkdown/utils';\n\nimport { SupportedKeys } from './supported-keys';\n\ntype Keys = Extract<keyof SupportedKeys, 'SinkListItem' | 'LiftListItem' | 'NextListItem' | 'TaskList'>;\n\nexport const SplitTaskListItem = createCmdKey();\nexport const SinkTaskListItem = createCmdKey();\nexport const LiftTaskListItem = createCmdKey();\nexport const TurnIntoTaskList = createCmdKey();\n\nexport const taskListItem = createNode<Keys>((utils) => {\n const id = 'task_list_item';\n const style = utils.getStyle(\n ({ palette, size }) =>\n css`\n list-style-type: none;\n position: relative;\n\n & > div {\n overflow: hidden;\n padding: 0 2px;\n }\n\n label {\n position: absolute;\n top: 0;\n left: -2rem;\n display: inline-block;\n width: 1.5rem;\n height: 1.5rem;\n margin: 0.5rem 0;\n input {\n visibility: hidden;\n }\n }\n label:before {\n position: absolute;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n border-radius: ${size.radius};\n }\n label:hover:before {\n background: ${palette('background')};\n }\n &[data-checked='true'] {\n label {\n color: ${palette('primary')};\n }\n }\n &[data-checked='false'] {\n label {\n color: ${palette('solid', 0.87)};\n }\n }\n .paragraph {\n margin: 0.5rem 0;\n }\n `,\n );\n\n return {\n id,\n schema: () => ({\n group: 'listItem',\n content: 'paragraph block*',\n defining: true,\n attrs: {\n checked: {\n default: false,\n },\n },\n parseDOM: [\n {\n tag: 'li[data-type=\"task-list-item\"]',\n getAttrs: (dom) => {\n if (!(dom instanceof HTMLElement)) {\n throw new Error();\n }\n return { checked: dom.dataset.checked === 'true' };\n },\n },\n ],\n toDOM: (node) => [\n 'li',\n {\n 'data-type': 'task-item',\n 'data-checked': node.attrs.checked ? 'true' : 'false',\n class: utils.getClassName(node.attrs, 'task-list-item', style),\n },\n 0,\n ],\n parseMarkdown: {\n match: ({ type, checked }) => {\n return type === 'listItem' && checked !== null;\n },\n runner: (state, node, type) => {\n state.openNode(type, { checked: node.checked as boolean });\n state.next(node.children);\n state.closeNode();\n },\n },\n toMarkdown: {\n match: (node) => node.type.name === id,\n runner: (state, node) => {\n state.openNode('listItem', undefined, { checked: node.attrs.checked });\n state.next(node.content);\n state.closeNode();\n },\n },\n }),\n inputRules: (nodeType) => [\n wrappingInputRule(/^\\s*(\\[([ |x])\\])\\s$/, nodeType, (match) => ({\n checked: match[match.length - 1] === 'x',\n })),\n ],\n commands: (nodeType) => [\n createCmd(SplitTaskListItem, () => splitListItem(nodeType)),\n createCmd(SinkTaskListItem, () => sinkListItem(nodeType)),\n createCmd(LiftTaskListItem, () => liftListItem(nodeType)),\n createCmd(TurnIntoTaskList, () => wrapIn(nodeType)),\n ],\n shortcuts: {\n [SupportedKeys.NextListItem]: createShortcut(SplitTaskListItem, 'Enter'),\n [SupportedKeys.SinkListItem]: createShortcut(SinkTaskListItem, 'Mod-]'),\n [SupportedKeys.LiftListItem]: createShortcut(LiftTaskListItem, 'Mod-['),\n [SupportedKeys.TaskList]: createShortcut(TurnIntoTaskList, 'Mod-Alt-9'),\n },\n view: (ctx) => (node, view, getPos) => {\n const createIcon = ctx.get(themeToolCtx).slots.icon;\n\n const listItem = document.createElement('li');\n const checkboxWrapper = document.createElement('label');\n const checkboxStyler = document.createElement('span');\n const checkbox = document.createElement('input');\n const content = document.createElement('div');\n\n let icon = createIcon('unchecked');\n checkboxWrapper.appendChild(icon);\n const setIcon = (name: Icon) => {\n const nextIcon = createIcon(name);\n checkboxWrapper.replaceChild(nextIcon, icon);\n icon = nextIcon;\n };\n\n checkboxWrapper.contentEditable = 'false';\n checkbox.type = 'checkbox';\n const onChange = (event: Event) => {\n const target = event.target;\n if (!(target instanceof HTMLInputElement)) return;\n\n if (!view.editable) {\n checkbox.checked = !checkbox.checked;\n\n return;\n }\n\n const { tr } = view.state;\n\n view.dispatch(\n tr.setNodeMarkup(getPos(), undefined, {\n checked: target.checked,\n }),\n );\n };\n checkbox.addEventListener('change', onChange);\n\n listItem.dataset.checked = node.attrs.checked;\n if (node.attrs.checked) {\n checkbox.setAttribute('checked', 'checked');\n }\n\n checkboxWrapper.append(checkbox, checkboxStyler);\n listItem.append(checkboxWrapper, content);\n\n const attributes = {\n 'data-type': 'task-item',\n 'data-checked': node.attrs.checked ? 'true' : 'false',\n class: utils.getClassName(node.attrs, 'task-list-item', style),\n };\n Object.entries(attributes).forEach(([key, value]) => {\n listItem.setAttribute(key, value);\n });\n setIcon(node.attrs.checked ? 'checked' : 'unchecked');\n\n return {\n dom: listItem,\n contentDOM: content,\n update: (updatedNode) => {\n if (updatedNode.type.name !== id) return false;\n\n listItem.dataset.checked = updatedNode.attrs.checked;\n if (updatedNode.attrs.checked) {\n checkbox.setAttribute('checked', 'checked');\n } else {\n checkbox.removeAttribute('checked');\n }\n setIcon(updatedNode.attrs.checked ? 'checked' : 'unchecked');\n\n return true;\n },\n destroy: () => {\n checkbox.removeEventListener('change', onChange);\n },\n };\n },\n };\n});\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { tablePlugin } from '@milkdown/plugin-table';\nimport { commands as commonmarkCommands, commonmark } from '@milkdown/preset-commonmark';\nimport { AtomList } from '@milkdown/utils';\n\nimport { urlPlugin } from './auto-link';\nimport { strikeThrough, ToggleStrikeThrough } from './strike-through';\nimport {\n LiftTaskListItem,\n SinkTaskListItem,\n SplitTaskListItem,\n taskListItem,\n TurnIntoTaskList,\n} from './task-list-item';\n\nexport * from './strike-through';\nexport { SupportedKeys } from './supported-keys';\nexport * from './task-list-item';\nexport {\n BreakTable,\n // command\n createTable,\n InsertTable,\n NextCell,\n PrevCell,\n // gather\n table,\n tablePlugin,\n} from '@milkdown/plugin-table';\nexport {\n blockquote,\n bulletList,\n codeFence,\n codeInline,\n commonmark,\n // gather\n commonmarkNodes,\n commonmarkPlugins,\n // node\n doc,\n em,\n hardbreak,\n heading,\n hr,\n image,\n // command\n InsertHardbreak,\n InsertHr,\n InsertImage,\n LiftListItem,\n link,\n listItem,\n ModifyImage,\n ModifyLink,\n orderedList,\n paragraph,\n SinkListItem,\n SplitListItem,\n strong,\n text,\n ToggleBold,\n ToggleInlineCode,\n ToggleItalic,\n ToggleLink,\n TurnIntoCodeFence,\n TurnIntoHeading,\n TurnIntoText,\n WrapInBlockquote,\n WrapInBulletList,\n WrapInOrderedList,\n} from '@milkdown/preset-commonmark';\n\nexport const gfm = AtomList.create([...commonmark, tablePlugin(), urlPlugin(), strikeThrough(), taskListItem()]);\n\nexport const commands = {\n ...commonmarkCommands,\n ToggleStrikeThrough,\n TurnIntoTaskList,\n SinkTaskListItem,\n LiftTaskListItem,\n SplitTaskListItem,\n} as const;\nexport type Commands = typeof commands;\n"],"names":["inputRules","InputRule","createPlugin","CommonmarkKeys","TableKeys","createCmdKey","createMark","utils","css","markRule","createCmd","toggleMark","createShortcut","createNode","wrappingInputRule","splitListItem","sinkListItem","liftListItem","wrapIn","themeToolCtx","AtomList","commonmark","tablePlugin","commonmarkCommands"],"mappings":"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"}
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACH,UAAU,EAEV,WAAW,EACX,WAAW,EACX,QAAQ,EACR,QAAQ,EAER,KAAK,EACL,WAAW,GACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACH,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,EAEV,eAAe,EACf,iBAAiB,EAEjB,GAAG,EACH,EAAE,EACF,SAAS,EACT,OAAO,EACP,EAAE,EACF,KAAK,EAEL,eAAe,EACf,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,UAAU,EACV,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,MAAM,EACN,IAAI,EACJ,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GACpB,MAAM,6BAA6B,CAAC;AAErC,eAAO,MAAM,GAAG;;+CAAgG,CAAC;AAEjH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;CAOX,CAAC;AACX,oBAAY,QAAQ,GAAG,OAAO,QAAQ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"strike-through.d.ts","sourceRoot":"","sources":["../src/strike-through.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,mBAAmB,4CAAiB,CAAC;AAElD,eAAO,MAAM,aAAa;;;;EAyCxB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"supported-keys.d.ts","sourceRoot":"","sources":["../src/supported-keys.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;CAKhB,CAAC;AACX,oBAAY,aAAa,GAAG,OAAO,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"task-list-item.d.ts","sourceRoot":"","sources":["../src/task-list-item.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,aAAK,IAAI,GAAG,OAAO,CAAC,MAAM,aAAa,EAAE,cAAc,GAAG,cAAc,GAAG,cAAc,GAAG,UAAU,CAAC,CAAC;AAExG,eAAO,MAAM,iBAAiB,4CAAiB,CAAC;AAChD,eAAO,MAAM,gBAAgB,4CAAiB,CAAC;AAC/C,eAAO,MAAM,gBAAgB,4CAAiB,CAAC;AAC/C,eAAO,MAAM,gBAAgB,4CAAiB,CAAC;AAE/C,eAAO,MAAM,YAAY;;;;EAsMvB,CAAC"}
|