@milkdown/preset-gfm 5.2.0 → 5.3.2
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 +1 -15
- package/lib/auto-link.d.ts.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +1031 -0
- package/lib/index.es.js.map +1 -0
- package/lib/supported-keys.d.ts.map +1 -1
- package/lib/table/command.d.ts +3 -0
- package/lib/table/command.d.ts.map +1 -0
- package/lib/table/index.d.ts +10 -0
- package/lib/table/index.d.ts.map +1 -0
- package/lib/table/nodes/index.d.ts +32 -0
- package/lib/table/nodes/index.d.ts.map +1 -0
- package/lib/table/nodes/schema.d.ts +2 -0
- package/lib/table/nodes/schema.d.ts.map +1 -0
- package/lib/table/nodes/style.d.ts +3 -0
- package/lib/table/nodes/style.d.ts.map +1 -0
- package/lib/table/operator-plugin/actions.d.ts +19 -0
- package/lib/table/operator-plugin/actions.d.ts.map +1 -0
- package/lib/table/operator-plugin/calc-pos.d.ts +3 -0
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -0
- package/lib/table/operator-plugin/constant.d.ts +6 -0
- package/lib/table/operator-plugin/constant.d.ts.map +1 -0
- package/lib/table/operator-plugin/helper.d.ts +6 -0
- package/lib/table/operator-plugin/helper.d.ts.map +1 -0
- package/lib/table/operator-plugin/index.d.ts +6 -0
- package/lib/table/operator-plugin/index.d.ts.map +1 -0
- package/lib/table/operator-plugin/style.d.ts +3 -0
- package/lib/table/operator-plugin/style.d.ts.map +1 -0
- package/lib/table/operator-plugin/widget.d.ts +8 -0
- package/lib/table/operator-plugin/widget.d.ts.map +1 -0
- package/lib/table/utils.d.ts +20 -0
- package/lib/table/utils.d.ts.map +1 -0
- package/lib/task-list-item.d.ts.map +1 -1
- package/package.json +15 -20
- package/src/auto-link.ts +4 -9
- package/src/index.ts +13 -6
- 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 +51 -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.js +0 -19
- package/lib/auto-link.js.map +0 -1
- package/lib/index.js +0 -29
- package/lib/index.js.map +0 -1
- package/lib/strike-through.js +0 -46
- package/lib/strike-through.js.map +0 -1
- package/lib/supported-keys.js +0 -5
- package/lib/supported-keys.js.map +0 -1
- package/lib/task-list-item.js +0 -195
- package/lib/task-list-item.js.map +0 -1
package/lib/index.es.js
ADDED
|
@@ -0,0 +1,1031 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { SupportedKeys as SupportedKeys$2, commonmark, commands as commands$1 } from "@milkdown/preset-commonmark";
|
|
21
|
+
export { InsertHardbreak, InsertHr, InsertImage, LiftListItem, ModifyImage, ModifyLink, SinkListItem, SplitListItem, ToggleBold, ToggleInlineCode, ToggleItalic, ToggleLink, TurnIntoCodeFence, TurnIntoHeading, TurnIntoText, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, blockquote, bulletList, codeFence, codeInline, commonmark, commonmarkNodes, commonmarkPlugins, doc, em, hardbreak, heading, hr, image, link, listItem, orderedList, paragraph, strong, text } from "@milkdown/preset-commonmark";
|
|
22
|
+
import { $prose, createPlugin, createShortcut, createMark, createNode, AtomList, $remark } from "@milkdown/utils";
|
|
23
|
+
import remarkGFM from "remark-gfm";
|
|
24
|
+
import { inputRules, InputRule, isInTable, Selection, findParentNode, TableMap, tableNodeTypes, CellSelection, cloneTr, addColumnBefore, addColumnAfter, selectedRect, setCellAttr, deleteTable, deleteColumn, deleteRow, calculateNodePosition, Decoration, Plugin, PluginKey, DecorationSet, tableNodes, TextSelection, goToNextCell, columnResizing, tableEditing, markRule, toggleMark, wrappingInputRule, splitListItem, sinkListItem, liftListItem, wrapIn } from "@milkdown/prose";
|
|
25
|
+
import { css, injectGlobal } from "@emotion/css";
|
|
26
|
+
import { themeToolCtx, createCmdKey, schemaCtx, createCmd } from "@milkdown/core";
|
|
27
|
+
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/;
|
|
28
|
+
const proseUrlPlugin = () => inputRules({
|
|
29
|
+
rules: [
|
|
30
|
+
new InputRule(urlRegex, (state, match, start, end) => {
|
|
31
|
+
const { schema: schema2 } = state;
|
|
32
|
+
const [text2] = match;
|
|
33
|
+
if (!text2)
|
|
34
|
+
return null;
|
|
35
|
+
return state.tr.replaceWith(start, end, schema2.text(text2)).addMark(start, text2.length + start, schema2.marks.link.create({ href: text2 }));
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
const urlPlugin = $prose(() => proseUrlPlugin());
|
|
40
|
+
const exitTable = (node) => (state, dispatch) => {
|
|
41
|
+
if (!isInTable(state)) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const { $head } = state.selection;
|
|
45
|
+
const pos = $head.after();
|
|
46
|
+
const tr = state.tr.replaceWith(pos, pos, node.createAndFill());
|
|
47
|
+
tr.setSelection(Selection.near(tr.doc.resolve(pos), 1));
|
|
48
|
+
dispatch == null ? void 0 : dispatch(tr.scrollIntoView());
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
const findTable = (selection) => findParentNode((node) => node.type.spec.tableRole === "table")(selection);
|
|
52
|
+
const getCellsInColumn = (columnIndex) => (selection) => {
|
|
53
|
+
const table2 = findTable(selection);
|
|
54
|
+
if (!table2)
|
|
55
|
+
return void 0;
|
|
56
|
+
const map = TableMap.get(table2.node);
|
|
57
|
+
if (columnIndex < 0 || columnIndex >= map.width) {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
return map.cellsInRect({ left: columnIndex, right: columnIndex + 1, top: 0, bottom: map.height }).map((pos) => {
|
|
61
|
+
const node = table2.node.nodeAt(pos);
|
|
62
|
+
if (!node)
|
|
63
|
+
throw new Error();
|
|
64
|
+
const start = pos + table2.start;
|
|
65
|
+
return {
|
|
66
|
+
pos: start,
|
|
67
|
+
start: start + 1,
|
|
68
|
+
node
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const getCellsInRow = (rowIndex) => (selection) => {
|
|
73
|
+
const table2 = findTable(selection);
|
|
74
|
+
if (!table2)
|
|
75
|
+
return void 0;
|
|
76
|
+
const map = TableMap.get(table2.node);
|
|
77
|
+
if (rowIndex < 0 || rowIndex >= map.height) {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
return map.cellsInRect({ left: 0, right: map.width, top: rowIndex, bottom: rowIndex + 1 }).map((pos) => {
|
|
81
|
+
const node = table2.node.nodeAt(pos);
|
|
82
|
+
if (!node)
|
|
83
|
+
throw new Error();
|
|
84
|
+
const start = pos + table2.start;
|
|
85
|
+
return {
|
|
86
|
+
pos: start,
|
|
87
|
+
start: start + 1,
|
|
88
|
+
node
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const createTable = (schema2, rowsCount = 3, colsCount = 3) => {
|
|
93
|
+
const { cell: tableCell, header_cell: tableHeader, row: tableRow, table: table2 } = tableNodeTypes(schema2);
|
|
94
|
+
const cells = Array(colsCount).fill(0).map(() => tableCell.createAndFill(null));
|
|
95
|
+
const headerCells = Array(colsCount).fill(0).map(() => tableHeader.createAndFill(null));
|
|
96
|
+
const rows = Array(rowsCount).fill(0).map((_, i) => tableRow.create(null, i === 0 ? headerCells : cells));
|
|
97
|
+
return table2.create(null, rows);
|
|
98
|
+
};
|
|
99
|
+
const selectLine = (type) => (index) => (tr) => {
|
|
100
|
+
const table2 = findTable(tr.selection);
|
|
101
|
+
const isRowSelection = type === "row";
|
|
102
|
+
if (table2) {
|
|
103
|
+
const map = TableMap.get(table2.node);
|
|
104
|
+
if (index >= 0 && index < (isRowSelection ? map.height : map.width)) {
|
|
105
|
+
const lastCell = map.positionAt(isRowSelection ? index : map.height - 1, isRowSelection ? map.width - 1 : index, table2.node);
|
|
106
|
+
const $lastCell = tr.doc.resolve(table2.start + lastCell);
|
|
107
|
+
const createCellSelection = isRowSelection ? CellSelection.rowSelection : CellSelection.colSelection;
|
|
108
|
+
const firstCell = map.positionAt(isRowSelection ? index : 0, isRowSelection ? 0 : index, table2.node);
|
|
109
|
+
const $firstCell = tr.doc.resolve(table2.start + firstCell);
|
|
110
|
+
return cloneTr(tr.setSelection(createCellSelection($lastCell, $firstCell)));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return tr;
|
|
114
|
+
};
|
|
115
|
+
const getCellsInTable = (selection) => {
|
|
116
|
+
const table2 = findTable(selection);
|
|
117
|
+
if (!table2) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const map = TableMap.get(table2.node);
|
|
121
|
+
const cells = map.cellsInRect({
|
|
122
|
+
left: 0,
|
|
123
|
+
right: map.width,
|
|
124
|
+
top: 0,
|
|
125
|
+
bottom: map.height
|
|
126
|
+
});
|
|
127
|
+
return cells.map((nodePos) => {
|
|
128
|
+
const node = table2.node.nodeAt(nodePos);
|
|
129
|
+
const pos = nodePos + table2.start;
|
|
130
|
+
return { pos, start: pos + 1, node };
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
const selectTable = (tr) => {
|
|
134
|
+
const cells = getCellsInTable(tr.selection);
|
|
135
|
+
if (cells) {
|
|
136
|
+
const $firstCell = tr.doc.resolve(cells[0].pos);
|
|
137
|
+
const $lastCell = tr.doc.resolve(cells[cells.length - 1].pos);
|
|
138
|
+
return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell)));
|
|
139
|
+
}
|
|
140
|
+
return tr;
|
|
141
|
+
};
|
|
142
|
+
function addRowWithAlignment(tr, { map, tableStart, table: table2 }, row) {
|
|
143
|
+
const rowPos = Array(row).fill(0).reduce((acc, _, i) => {
|
|
144
|
+
return acc + table2.child(i).nodeSize;
|
|
145
|
+
}, tableStart);
|
|
146
|
+
const { cell: cellType, row: rowType } = tableNodeTypes(table2.type.schema);
|
|
147
|
+
const cells = Array(map.width).fill(0).map((_, col) => {
|
|
148
|
+
const headerCol = table2.nodeAt(map.map[col]);
|
|
149
|
+
return cellType.createAndFill({ alignment: headerCol == null ? void 0 : headerCol.attrs.alignment });
|
|
150
|
+
});
|
|
151
|
+
tr.insert(rowPos, rowType.create(null, cells));
|
|
152
|
+
return tr;
|
|
153
|
+
}
|
|
154
|
+
const getCellSelection = (view) => view.state.selection;
|
|
155
|
+
const isFirstRowSelected = (selection) => {
|
|
156
|
+
const map = TableMap.get(selection.$anchorCell.node(-1));
|
|
157
|
+
const start = selection.$anchorCell.start(-1);
|
|
158
|
+
const cells = map.cellsInRect({
|
|
159
|
+
left: 0,
|
|
160
|
+
right: map.width,
|
|
161
|
+
top: 0,
|
|
162
|
+
bottom: 1
|
|
163
|
+
});
|
|
164
|
+
const selectedCells = map.cellsInRect(map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start));
|
|
165
|
+
for (let i = 0, count = cells.length; i < count; i++) {
|
|
166
|
+
if (selectedCells.indexOf(cells[i]) === -1) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
};
|
|
172
|
+
const calculateItem = (actions, view) => {
|
|
173
|
+
Object.values(actions).forEach((item) => {
|
|
174
|
+
var _a;
|
|
175
|
+
const disable = (_a = item.disable) == null ? void 0 : _a.call(item, view);
|
|
176
|
+
if (disable) {
|
|
177
|
+
item.$.classList.add("hide");
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
item.$.classList.remove("hide");
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
var Action;
|
|
184
|
+
(function(Action2) {
|
|
185
|
+
Action2[Action2["AddColLeft"] = 0] = "AddColLeft";
|
|
186
|
+
Action2[Action2["AddColRight"] = 1] = "AddColRight";
|
|
187
|
+
Action2[Action2["AddRowTop"] = 2] = "AddRowTop";
|
|
188
|
+
Action2[Action2["AddRowBottom"] = 3] = "AddRowBottom";
|
|
189
|
+
Action2[Action2["AlignLeft"] = 4] = "AlignLeft";
|
|
190
|
+
Action2[Action2["AlignCenter"] = 5] = "AlignCenter";
|
|
191
|
+
Action2[Action2["AlignRight"] = 6] = "AlignRight";
|
|
192
|
+
Action2[Action2["Delete"] = 7] = "Delete";
|
|
193
|
+
})(Action || (Action = {}));
|
|
194
|
+
const createActions = (ctx) => ({
|
|
195
|
+
[0]: {
|
|
196
|
+
$: ctx.get(themeToolCtx).slots.icon("leftArrow"),
|
|
197
|
+
command: () => addColumnBefore,
|
|
198
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
199
|
+
},
|
|
200
|
+
[1]: {
|
|
201
|
+
$: ctx.get(themeToolCtx).slots.icon("rightArrow"),
|
|
202
|
+
command: () => addColumnAfter,
|
|
203
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
204
|
+
},
|
|
205
|
+
[2]: {
|
|
206
|
+
$: ctx.get(themeToolCtx).slots.icon("upArrow"),
|
|
207
|
+
command: () => (state, dispatch) => {
|
|
208
|
+
if (!isInTable(state))
|
|
209
|
+
return false;
|
|
210
|
+
if (dispatch) {
|
|
211
|
+
const rect = selectedRect(state);
|
|
212
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.top));
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
},
|
|
216
|
+
disable: (view) => !getCellSelection(view).isRowSelection() || getCellSelection(view).$head.parent.type.name === "table_header"
|
|
217
|
+
},
|
|
218
|
+
[3]: {
|
|
219
|
+
$: ctx.get(themeToolCtx).slots.icon("downArrow"),
|
|
220
|
+
command: () => (state, dispatch) => {
|
|
221
|
+
if (!isInTable(state))
|
|
222
|
+
return false;
|
|
223
|
+
if (dispatch) {
|
|
224
|
+
const rect = selectedRect(state);
|
|
225
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
},
|
|
229
|
+
disable: (view) => !getCellSelection(view).isRowSelection()
|
|
230
|
+
},
|
|
231
|
+
[4]: {
|
|
232
|
+
$: ctx.get(themeToolCtx).slots.icon("alignLeft"),
|
|
233
|
+
command: () => setCellAttr("alignment", "left"),
|
|
234
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
235
|
+
},
|
|
236
|
+
[5]: {
|
|
237
|
+
$: ctx.get(themeToolCtx).slots.icon("alignCenter"),
|
|
238
|
+
command: () => setCellAttr("alignment", "center"),
|
|
239
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
240
|
+
},
|
|
241
|
+
[6]: {
|
|
242
|
+
$: ctx.get(themeToolCtx).slots.icon("alignRight"),
|
|
243
|
+
command: () => setCellAttr("alignment", "right"),
|
|
244
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
245
|
+
},
|
|
246
|
+
[7]: {
|
|
247
|
+
$: ctx.get(themeToolCtx).slots.icon("delete"),
|
|
248
|
+
command: (_, view) => {
|
|
249
|
+
const selection = getCellSelection(view);
|
|
250
|
+
const isCol = selection.isColSelection();
|
|
251
|
+
const isRow = selection.isRowSelection();
|
|
252
|
+
if (isCol && isRow) {
|
|
253
|
+
return deleteTable;
|
|
254
|
+
}
|
|
255
|
+
if (isCol) {
|
|
256
|
+
return deleteColumn;
|
|
257
|
+
}
|
|
258
|
+
return deleteRow;
|
|
259
|
+
},
|
|
260
|
+
disable: (view) => {
|
|
261
|
+
const selection = getCellSelection(view);
|
|
262
|
+
if (selection.isRowSelection()) {
|
|
263
|
+
if (selection.isColSelection()) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
return isFirstRowSelected(selection);
|
|
267
|
+
}
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
const calculatePosition = (view, dom) => {
|
|
273
|
+
const { selection } = view.state;
|
|
274
|
+
const isCol = selection.isColSelection();
|
|
275
|
+
const isRow = selection.isRowSelection();
|
|
276
|
+
calculateNodePosition(view, dom, (selected, target, parent) => {
|
|
277
|
+
const $editor = dom.parentElement;
|
|
278
|
+
if (!$editor) {
|
|
279
|
+
throw new Error();
|
|
280
|
+
}
|
|
281
|
+
let left = !isRow ? selected.left - parent.left + (selected.width - target.width) / 2 : selected.left - parent.left - target.width / 2 - 8;
|
|
282
|
+
const top = selected.top - parent.top - target.height - (isCol ? 14 : 0) - 14 + $editor.scrollTop;
|
|
283
|
+
if (left < 0) {
|
|
284
|
+
left = 0;
|
|
285
|
+
}
|
|
286
|
+
return [top, left];
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
var ToolTipPos;
|
|
290
|
+
(function(ToolTipPos2) {
|
|
291
|
+
ToolTipPos2["Left"] = "Left";
|
|
292
|
+
ToolTipPos2["Top"] = "Top";
|
|
293
|
+
ToolTipPos2["Point"] = "Point";
|
|
294
|
+
})(ToolTipPos || (ToolTipPos = {}));
|
|
295
|
+
const injectStyle$1 = ({ size, mixin, palette }) => {
|
|
296
|
+
var _a, _b;
|
|
297
|
+
return css`
|
|
298
|
+
display: inline-flex;
|
|
299
|
+
cursor: pointer;
|
|
300
|
+
z-index: 2;
|
|
301
|
+
|
|
302
|
+
justify-content: space-evenly;
|
|
303
|
+
|
|
304
|
+
position: absolute;
|
|
305
|
+
|
|
306
|
+
border-radius: ${size.radius};
|
|
307
|
+
|
|
308
|
+
${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
|
|
309
|
+
|
|
310
|
+
${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
|
|
311
|
+
|
|
312
|
+
overflow: hidden;
|
|
313
|
+
background: ${palette("surface")};
|
|
314
|
+
|
|
315
|
+
.icon {
|
|
316
|
+
position: relative;
|
|
317
|
+
color: ${palette("solid", 0.87)};
|
|
318
|
+
|
|
319
|
+
width: 3rem;
|
|
320
|
+
line-height: 3rem;
|
|
321
|
+
text-align: center;
|
|
322
|
+
transition: all 0.4s ease-in-out;
|
|
323
|
+
&:hover {
|
|
324
|
+
background-color: ${palette("secondary", 0.12)};
|
|
325
|
+
}
|
|
326
|
+
&.active {
|
|
327
|
+
color: ${palette("primary")};
|
|
328
|
+
}
|
|
329
|
+
&:not(:last-child)::after {
|
|
330
|
+
content: '';
|
|
331
|
+
position: absolute;
|
|
332
|
+
right: 0px;
|
|
333
|
+
top: 0;
|
|
334
|
+
width: ${size.lineWidth};
|
|
335
|
+
bottom: 0;
|
|
336
|
+
background: ${palette("line")};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
&.hide,
|
|
340
|
+
.hide {
|
|
341
|
+
display: none;
|
|
342
|
+
}
|
|
343
|
+
`;
|
|
344
|
+
};
|
|
345
|
+
const calculateClassName = (pos) => {
|
|
346
|
+
switch (pos) {
|
|
347
|
+
case ToolTipPos.Left: {
|
|
348
|
+
return "milkdown-cell-left";
|
|
349
|
+
}
|
|
350
|
+
case ToolTipPos.Top: {
|
|
351
|
+
return "milkdown-cell-top";
|
|
352
|
+
}
|
|
353
|
+
case ToolTipPos.Point:
|
|
354
|
+
default: {
|
|
355
|
+
return "milkdown-cell-point";
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
function createWidget(ctx, cell, pos, index = 0) {
|
|
360
|
+
const widget = Decoration.widget(cell.pos + 1, (view) => {
|
|
361
|
+
const div = document.createElement("div");
|
|
362
|
+
div.classList.add(calculateClassName(pos));
|
|
363
|
+
if (pos === ToolTipPos.Point) {
|
|
364
|
+
div.appendChild(ctx.get(themeToolCtx).slots.icon("select"));
|
|
365
|
+
}
|
|
366
|
+
div.addEventListener("mousedown", (e) => {
|
|
367
|
+
if (!view)
|
|
368
|
+
return;
|
|
369
|
+
e.preventDefault();
|
|
370
|
+
switch (pos) {
|
|
371
|
+
case ToolTipPos.Point: {
|
|
372
|
+
view.dispatch(selectTable(view.state.tr));
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
case ToolTipPos.Left: {
|
|
376
|
+
view.dispatch(selectLine("row")(index)(view.state.tr));
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
case ToolTipPos.Top: {
|
|
380
|
+
view.dispatch(selectLine("col")(index)(view.state.tr));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
return div;
|
|
386
|
+
});
|
|
387
|
+
return widget;
|
|
388
|
+
}
|
|
389
|
+
const operatorPlugin = (ctx, utils) => {
|
|
390
|
+
const items = createActions(ctx);
|
|
391
|
+
const tooltip = document.createElement("div");
|
|
392
|
+
const style = utils.getStyle(injectStyle$1);
|
|
393
|
+
if (style) {
|
|
394
|
+
tooltip.classList.add(style);
|
|
395
|
+
}
|
|
396
|
+
tooltip.classList.add("table-tooltip", "hide");
|
|
397
|
+
return new Plugin({
|
|
398
|
+
key: new PluginKey("MILKDOWN_TABLE_OP"),
|
|
399
|
+
props: {
|
|
400
|
+
decorations: (state) => {
|
|
401
|
+
const decorations = [];
|
|
402
|
+
const leftCells = getCellsInColumn(0)(state.selection);
|
|
403
|
+
if (!leftCells)
|
|
404
|
+
return null;
|
|
405
|
+
const topCells = getCellsInRow(0)(state.selection);
|
|
406
|
+
if (!topCells)
|
|
407
|
+
return null;
|
|
408
|
+
const [topLeft] = leftCells;
|
|
409
|
+
decorations.push(createWidget(ctx, topLeft, ToolTipPos.Point));
|
|
410
|
+
leftCells.forEach((cell, i) => {
|
|
411
|
+
decorations.push(createWidget(ctx, cell, ToolTipPos.Left, i));
|
|
412
|
+
});
|
|
413
|
+
topCells.forEach((cell, i) => {
|
|
414
|
+
decorations.push(createWidget(ctx, cell, ToolTipPos.Top, i));
|
|
415
|
+
});
|
|
416
|
+
return DecorationSet.create(state.doc, decorations);
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
view: (editorView) => {
|
|
420
|
+
var _a;
|
|
421
|
+
Object.values(items).forEach(({ $ }) => tooltip.appendChild($));
|
|
422
|
+
(_a = editorView.dom.parentNode) == null ? void 0 : _a.appendChild(tooltip);
|
|
423
|
+
const listener = (e) => {
|
|
424
|
+
if (!editorView)
|
|
425
|
+
return;
|
|
426
|
+
e.stopPropagation();
|
|
427
|
+
e.preventDefault();
|
|
428
|
+
Object.values(items).forEach(({ $, command }) => {
|
|
429
|
+
if ($.contains(e.target)) {
|
|
430
|
+
command(e, editorView)(editorView.state, editorView.dispatch, editorView);
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
};
|
|
434
|
+
const hide = () => {
|
|
435
|
+
tooltip.classList.add("hide");
|
|
436
|
+
};
|
|
437
|
+
tooltip.addEventListener("mousedown", listener);
|
|
438
|
+
return {
|
|
439
|
+
update: (view, prevState) => {
|
|
440
|
+
const state = view.state;
|
|
441
|
+
if ((prevState == null ? void 0 : prevState.doc.eq(state.doc)) && prevState.selection.eq(state.selection))
|
|
442
|
+
return;
|
|
443
|
+
const isCellSelection = state.selection instanceof CellSelection;
|
|
444
|
+
if (!isCellSelection || !view.editable) {
|
|
445
|
+
hide();
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
calculateItem(items, view);
|
|
449
|
+
if (Object.values(items).every(({ $ }) => $.classList.contains("hide"))) {
|
|
450
|
+
hide();
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
tooltip.classList.remove("hide");
|
|
454
|
+
calculatePosition(view, tooltip);
|
|
455
|
+
},
|
|
456
|
+
destroy: () => {
|
|
457
|
+
tooltip.removeEventListener("mousedown", listener);
|
|
458
|
+
tooltip.remove();
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
};
|
|
464
|
+
const schema = tableNodes({
|
|
465
|
+
tableGroup: "block",
|
|
466
|
+
cellContent: "paragraph",
|
|
467
|
+
cellAttributes: {
|
|
468
|
+
alignment: {
|
|
469
|
+
default: "left",
|
|
470
|
+
getFromDOM: (dom) => dom.style.textAlign || "left",
|
|
471
|
+
setDOMAttr: (value, attrs) => {
|
|
472
|
+
attrs.style = `text-align: ${value || "left"}`;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
const proseTableStyle = css`
|
|
478
|
+
/* copy from https://github.com/ProseMirror/prosemirror-tables/blob/master/style/tables.css */
|
|
479
|
+
.ProseMirror .tableWrapper {
|
|
480
|
+
overflow-x: auto;
|
|
481
|
+
}
|
|
482
|
+
.ProseMirror table {
|
|
483
|
+
border-collapse: collapse;
|
|
484
|
+
table-layout: fixed;
|
|
485
|
+
width: 100%;
|
|
486
|
+
overflow: hidden;
|
|
487
|
+
}
|
|
488
|
+
.ProseMirror td,
|
|
489
|
+
.ProseMirror th {
|
|
490
|
+
vertical-align: top;
|
|
491
|
+
box-sizing: border-box;
|
|
492
|
+
position: relative;
|
|
493
|
+
}
|
|
494
|
+
.ProseMirror .column-resize-handle {
|
|
495
|
+
position: absolute;
|
|
496
|
+
right: -2px;
|
|
497
|
+
top: 0;
|
|
498
|
+
bottom: 0;
|
|
499
|
+
width: 4px;
|
|
500
|
+
z-index: 20;
|
|
501
|
+
background-color: #adf;
|
|
502
|
+
pointer-events: none;
|
|
503
|
+
}
|
|
504
|
+
.ProseMirror.resize-cursor {
|
|
505
|
+
cursor: ew-resize;
|
|
506
|
+
cursor: col-resize;
|
|
507
|
+
}
|
|
508
|
+
/* Give selected cells a blue overlay */
|
|
509
|
+
.ProseMirror .selectedCell:after {
|
|
510
|
+
z-index: 2;
|
|
511
|
+
position: absolute;
|
|
512
|
+
content: '';
|
|
513
|
+
left: 0;
|
|
514
|
+
right: 0;
|
|
515
|
+
top: 0;
|
|
516
|
+
bottom: 0;
|
|
517
|
+
background: rgba(200, 200, 255, 0.4);
|
|
518
|
+
pointer-events: none;
|
|
519
|
+
}
|
|
520
|
+
`;
|
|
521
|
+
const injectStyle = (utils) => {
|
|
522
|
+
const css2 = injectGlobal;
|
|
523
|
+
return utils.getStyle(({ size, palette, mixin }) => {
|
|
524
|
+
var _a, _b, _c;
|
|
525
|
+
css2`
|
|
526
|
+
${proseTableStyle}
|
|
527
|
+
|
|
528
|
+
.tableWrapper {
|
|
529
|
+
margin: 0 !important;
|
|
530
|
+
|
|
531
|
+
${(_a = mixin.scrollbar) == null ? void 0 : _a.call(mixin, "x")};
|
|
532
|
+
|
|
533
|
+
width: 100%;
|
|
534
|
+
|
|
535
|
+
table {
|
|
536
|
+
width: calc(100% - 2rem) !important;
|
|
537
|
+
border-radius: ${size.radius};
|
|
538
|
+
box-sizing: border-box;
|
|
539
|
+
margin: 1rem 0 1rem 1rem !important;
|
|
540
|
+
overflow: auto !important;
|
|
541
|
+
* {
|
|
542
|
+
margin: 0 !important;
|
|
543
|
+
box-sizing: border-box;
|
|
544
|
+
font-size: 1rem;
|
|
545
|
+
}
|
|
546
|
+
tr {
|
|
547
|
+
${(_b = mixin.border) == null ? void 0 : _b.call(mixin, "bottom")};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
th {
|
|
551
|
+
background: ${palette("background", 0.5)};
|
|
552
|
+
font-weight: 400;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
th,
|
|
556
|
+
td {
|
|
557
|
+
min-width: 100px;
|
|
558
|
+
${(_c = mixin.border) == null ? void 0 : _c.call(mixin)};
|
|
559
|
+
text-align: left;
|
|
560
|
+
position: relative;
|
|
561
|
+
line-height: 3rem;
|
|
562
|
+
box-sizing: border-box;
|
|
563
|
+
height: 3rem;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
.selectedCell {
|
|
567
|
+
&::after {
|
|
568
|
+
background: ${palette("secondary", 0.38)};
|
|
569
|
+
}
|
|
570
|
+
& ::selection {
|
|
571
|
+
background: transparent;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
.column-resize-handle {
|
|
576
|
+
background: ${palette("primary")};
|
|
577
|
+
width: ${size.lineWidth};
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
th,
|
|
581
|
+
td {
|
|
582
|
+
padding: 0 1rem;
|
|
583
|
+
p {
|
|
584
|
+
line-height: unset !important;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
.milkdown-cell-left,
|
|
589
|
+
.milkdown-cell-point,
|
|
590
|
+
.milkdown-cell-top {
|
|
591
|
+
position: absolute;
|
|
592
|
+
|
|
593
|
+
&::after {
|
|
594
|
+
cursor: pointer;
|
|
595
|
+
position: absolute;
|
|
596
|
+
top: 0;
|
|
597
|
+
left: 0;
|
|
598
|
+
height: 100%;
|
|
599
|
+
width: 100%;
|
|
600
|
+
display: block;
|
|
601
|
+
transition: all 0.2s ease-in-out;
|
|
602
|
+
background: ${palette("secondary", 0.12)};
|
|
603
|
+
content: '';
|
|
604
|
+
}
|
|
605
|
+
&:hover::after {
|
|
606
|
+
background: ${palette("secondary", 0.38)};
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
.milkdown-cell-left {
|
|
611
|
+
left: calc(-6px - 0.5rem);
|
|
612
|
+
top: 0;
|
|
613
|
+
bottom: 0;
|
|
614
|
+
width: 0.5rem;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.milkdown-cell-top {
|
|
618
|
+
left: 0;
|
|
619
|
+
right: 0;
|
|
620
|
+
top: calc(-6px - 0.5rem);
|
|
621
|
+
height: 0.5rem;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
.milkdown-cell-point {
|
|
625
|
+
left: calc(-2px - 1rem);
|
|
626
|
+
top: calc(-2px - 1rem);
|
|
627
|
+
width: 1rem;
|
|
628
|
+
height: 1rem;
|
|
629
|
+
|
|
630
|
+
.icon {
|
|
631
|
+
position: absolute;
|
|
632
|
+
top: 0;
|
|
633
|
+
bottom: 0;
|
|
634
|
+
left: 0;
|
|
635
|
+
right: 0;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
`;
|
|
641
|
+
});
|
|
642
|
+
};
|
|
643
|
+
const SupportedKeys$1 = {
|
|
644
|
+
NextCell: "NextCell",
|
|
645
|
+
PrevCell: "PrevCell",
|
|
646
|
+
ExitTable: "ExitTable"
|
|
647
|
+
};
|
|
648
|
+
const PrevCell = createCmdKey();
|
|
649
|
+
const NextCell = createCmdKey();
|
|
650
|
+
const BreakTable = createCmdKey();
|
|
651
|
+
const InsertTable = createCmdKey();
|
|
652
|
+
const table = createPlugin((utils) => {
|
|
653
|
+
injectStyle(utils);
|
|
654
|
+
return {
|
|
655
|
+
schema: () => ({
|
|
656
|
+
node: {
|
|
657
|
+
table: __spreadProps(__spreadValues({}, schema.table), {
|
|
658
|
+
parseMarkdown: {
|
|
659
|
+
match: (node) => node.type === "table",
|
|
660
|
+
runner: (state, node, type) => {
|
|
661
|
+
const align = node.align;
|
|
662
|
+
const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
|
|
663
|
+
align,
|
|
664
|
+
isHeader: i === 0
|
|
665
|
+
}));
|
|
666
|
+
state.openNode(type);
|
|
667
|
+
state.next(children);
|
|
668
|
+
state.closeNode();
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
toMarkdown: {
|
|
672
|
+
match: (node) => node.type.name === "table",
|
|
673
|
+
runner: (state, node) => {
|
|
674
|
+
var _a;
|
|
675
|
+
const firstLine = (_a = node.content.firstChild) == null ? void 0 : _a.content;
|
|
676
|
+
if (!firstLine)
|
|
677
|
+
return;
|
|
678
|
+
const align = [];
|
|
679
|
+
firstLine.forEach((cell) => {
|
|
680
|
+
align.push(cell.attrs.alignment);
|
|
681
|
+
});
|
|
682
|
+
state.openNode("table", void 0, { align });
|
|
683
|
+
state.next(node.content);
|
|
684
|
+
state.closeNode();
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}),
|
|
688
|
+
table_row: __spreadProps(__spreadValues({}, schema.table_row), {
|
|
689
|
+
parseMarkdown: {
|
|
690
|
+
match: (node) => node.type === "tableRow",
|
|
691
|
+
runner: (state, node, type) => {
|
|
692
|
+
const align = node.align;
|
|
693
|
+
const children = node.children.map((x, i) => __spreadProps(__spreadValues({}, x), {
|
|
694
|
+
align: align[i],
|
|
695
|
+
isHeader: node.isHeader
|
|
696
|
+
}));
|
|
697
|
+
state.openNode(type);
|
|
698
|
+
state.next(children);
|
|
699
|
+
state.closeNode();
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
toMarkdown: {
|
|
703
|
+
match: (node) => node.type.name === "table_row",
|
|
704
|
+
runner: (state, node) => {
|
|
705
|
+
state.openNode("tableRow");
|
|
706
|
+
state.next(node.content);
|
|
707
|
+
state.closeNode();
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}),
|
|
711
|
+
table_cell: __spreadProps(__spreadValues({}, schema.table_cell), {
|
|
712
|
+
parseMarkdown: {
|
|
713
|
+
match: (node) => node.type === "tableCell" && !node.isHeader,
|
|
714
|
+
runner: (state, node, type) => {
|
|
715
|
+
const align = node.align;
|
|
716
|
+
state.openNode(type, { alignment: align }).openNode(state.schema.nodes.paragraph).next(node.children).closeNode().closeNode();
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
toMarkdown: {
|
|
720
|
+
match: (node) => node.type.name === "table_cell",
|
|
721
|
+
runner: (state, node) => {
|
|
722
|
+
state.openNode("tableCell").next(node.content).closeNode();
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
}),
|
|
726
|
+
table_header: __spreadProps(__spreadValues({}, schema.table_header), {
|
|
727
|
+
parseMarkdown: {
|
|
728
|
+
match: (node) => node.type === "tableCell" && !!node.isHeader,
|
|
729
|
+
runner: (state, node, type) => {
|
|
730
|
+
const align = node.align;
|
|
731
|
+
state.openNode(type, { alignment: align });
|
|
732
|
+
state.openNode(state.schema.nodes.paragraph);
|
|
733
|
+
state.next(node.children);
|
|
734
|
+
state.closeNode();
|
|
735
|
+
state.closeNode();
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
toMarkdown: {
|
|
739
|
+
match: (node) => node.type.name === "table_header",
|
|
740
|
+
runner: (state, node) => {
|
|
741
|
+
state.openNode("tableCell");
|
|
742
|
+
state.next(node.content);
|
|
743
|
+
state.closeNode();
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
})
|
|
747
|
+
}
|
|
748
|
+
}),
|
|
749
|
+
inputRules: (nodeType, ctx) => [
|
|
750
|
+
new InputRule(/^\|\|\s$/, (state, _match, start, end) => {
|
|
751
|
+
const $start = state.doc.resolve(start);
|
|
752
|
+
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
|
|
753
|
+
return null;
|
|
754
|
+
const tableNode = createTable(ctx.get(schemaCtx));
|
|
755
|
+
const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView();
|
|
756
|
+
return tr.setSelection(TextSelection.create(tr.doc, start + 3));
|
|
757
|
+
})
|
|
758
|
+
],
|
|
759
|
+
commands: (_, ctx) => [
|
|
760
|
+
createCmd(PrevCell, () => goToNextCell(-1)),
|
|
761
|
+
createCmd(NextCell, () => goToNextCell(1)),
|
|
762
|
+
createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes.paragraph)),
|
|
763
|
+
createCmd(InsertTable, () => (state, dispatch) => {
|
|
764
|
+
const { selection, tr } = state;
|
|
765
|
+
const { from } = selection;
|
|
766
|
+
const table2 = createTable(ctx.get(schemaCtx));
|
|
767
|
+
const _tr = tr.replaceSelectionWith(table2);
|
|
768
|
+
const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
|
|
769
|
+
if (sel) {
|
|
770
|
+
dispatch == null ? void 0 : dispatch(_tr.setSelection(sel));
|
|
771
|
+
}
|
|
772
|
+
return true;
|
|
773
|
+
})
|
|
774
|
+
],
|
|
775
|
+
shortcuts: {
|
|
776
|
+
[SupportedKeys$1.NextCell]: createShortcut(NextCell, "Mod-]"),
|
|
777
|
+
[SupportedKeys$1.PrevCell]: createShortcut(PrevCell, "Mod-["),
|
|
778
|
+
[SupportedKeys$1.ExitTable]: createShortcut(BreakTable, "Mod-Enter")
|
|
779
|
+
},
|
|
780
|
+
prosePlugins: (_, ctx) => {
|
|
781
|
+
return [operatorPlugin(ctx, utils), columnResizing({}), tableEditing()];
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
});
|
|
785
|
+
const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedKeys$2), SupportedKeys$1), {
|
|
786
|
+
StrikeThrough: "StrikeThrough",
|
|
787
|
+
TaskList: "TaskList"
|
|
788
|
+
});
|
|
789
|
+
const ToggleStrikeThrough = createCmdKey();
|
|
790
|
+
const strikeThrough = createMark((utils) => {
|
|
791
|
+
const id = "strike_through";
|
|
792
|
+
const style = utils.getStyle((themeTool) => css`
|
|
793
|
+
text-decoration-color: ${themeTool.palette("secondary")};
|
|
794
|
+
`);
|
|
795
|
+
return {
|
|
796
|
+
id,
|
|
797
|
+
schema: () => ({
|
|
798
|
+
parseDOM: [
|
|
799
|
+
{ tag: "del" },
|
|
800
|
+
{ style: "text-decoration", getAttrs: (value) => value === "line-through" }
|
|
801
|
+
],
|
|
802
|
+
toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through", style) }],
|
|
803
|
+
parseMarkdown: {
|
|
804
|
+
match: (node) => node.type === "delete",
|
|
805
|
+
runner: (state, node, markType) => {
|
|
806
|
+
state.openMark(markType);
|
|
807
|
+
state.next(node.children);
|
|
808
|
+
state.closeMark(markType);
|
|
809
|
+
}
|
|
810
|
+
},
|
|
811
|
+
toMarkdown: {
|
|
812
|
+
match: (mark) => mark.type.name === id,
|
|
813
|
+
runner: (state, mark) => {
|
|
814
|
+
state.withMark(mark, "delete");
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
}),
|
|
818
|
+
inputRules: (markType) => [
|
|
819
|
+
markRule(/(?:~~)([^~]+)(?:~~)$/, markType),
|
|
820
|
+
markRule(/(?:^|[^~])(~([^~]+)~)$/, markType)
|
|
821
|
+
],
|
|
822
|
+
commands: (markType) => [createCmd(ToggleStrikeThrough, () => toggleMark(markType))],
|
|
823
|
+
shortcuts: {
|
|
824
|
+
[SupportedKeys.StrikeThrough]: createShortcut(ToggleStrikeThrough, "Mod-Alt-x")
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
});
|
|
828
|
+
const SplitTaskListItem = createCmdKey();
|
|
829
|
+
const SinkTaskListItem = createCmdKey();
|
|
830
|
+
const LiftTaskListItem = createCmdKey();
|
|
831
|
+
const TurnIntoTaskList = createCmdKey();
|
|
832
|
+
const taskListItem = createNode((utils) => {
|
|
833
|
+
const id = "task_list_item";
|
|
834
|
+
const style = utils.getStyle(({ palette, size }) => css`
|
|
835
|
+
list-style-type: none;
|
|
836
|
+
position: relative;
|
|
837
|
+
|
|
838
|
+
& > div {
|
|
839
|
+
overflow: hidden;
|
|
840
|
+
padding: 0 2px;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
label {
|
|
844
|
+
position: absolute;
|
|
845
|
+
top: 0;
|
|
846
|
+
left: -2rem;
|
|
847
|
+
display: inline-block;
|
|
848
|
+
width: 1.5rem;
|
|
849
|
+
height: 1.5rem;
|
|
850
|
+
margin: 0.5rem 0;
|
|
851
|
+
input {
|
|
852
|
+
visibility: hidden;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
label:before {
|
|
856
|
+
position: absolute;
|
|
857
|
+
top: 0;
|
|
858
|
+
right: 0;
|
|
859
|
+
bottom: 0;
|
|
860
|
+
left: 0;
|
|
861
|
+
border-radius: ${size.radius};
|
|
862
|
+
}
|
|
863
|
+
label:hover:before {
|
|
864
|
+
background: ${palette("background")};
|
|
865
|
+
}
|
|
866
|
+
&[data-checked='true'] {
|
|
867
|
+
label {
|
|
868
|
+
color: ${palette("primary")};
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
&[data-checked='false'] {
|
|
872
|
+
label {
|
|
873
|
+
color: ${palette("solid", 0.87)};
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
.paragraph {
|
|
877
|
+
margin: 0.5rem 0;
|
|
878
|
+
}
|
|
879
|
+
`);
|
|
880
|
+
return {
|
|
881
|
+
id,
|
|
882
|
+
schema: () => ({
|
|
883
|
+
group: "listItem",
|
|
884
|
+
content: "paragraph block*",
|
|
885
|
+
defining: true,
|
|
886
|
+
attrs: {
|
|
887
|
+
checked: {
|
|
888
|
+
default: false
|
|
889
|
+
}
|
|
890
|
+
},
|
|
891
|
+
parseDOM: [
|
|
892
|
+
{
|
|
893
|
+
tag: 'li[data-type="task-item"]',
|
|
894
|
+
getAttrs: (dom) => {
|
|
895
|
+
if (!(dom instanceof HTMLElement)) {
|
|
896
|
+
throw new Error();
|
|
897
|
+
}
|
|
898
|
+
return { checked: dom.dataset.checked === "true" };
|
|
899
|
+
},
|
|
900
|
+
priority: 60
|
|
901
|
+
}
|
|
902
|
+
],
|
|
903
|
+
toDOM: (node) => [
|
|
904
|
+
"li",
|
|
905
|
+
{
|
|
906
|
+
"data-type": "task-item",
|
|
907
|
+
"data-checked": node.attrs.checked ? "true" : "false",
|
|
908
|
+
class: utils.getClassName(node.attrs, "task-list-item", style)
|
|
909
|
+
},
|
|
910
|
+
0
|
|
911
|
+
],
|
|
912
|
+
parseMarkdown: {
|
|
913
|
+
match: ({ type, checked }) => {
|
|
914
|
+
return type === "listItem" && checked !== null;
|
|
915
|
+
},
|
|
916
|
+
runner: (state, node, type) => {
|
|
917
|
+
state.openNode(type, { checked: node.checked });
|
|
918
|
+
state.next(node.children);
|
|
919
|
+
state.closeNode();
|
|
920
|
+
}
|
|
921
|
+
},
|
|
922
|
+
toMarkdown: {
|
|
923
|
+
match: (node) => node.type.name === id,
|
|
924
|
+
runner: (state, node) => {
|
|
925
|
+
state.openNode("listItem", void 0, { checked: node.attrs.checked });
|
|
926
|
+
state.next(node.content);
|
|
927
|
+
state.closeNode();
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
}),
|
|
931
|
+
inputRules: (nodeType) => [
|
|
932
|
+
wrappingInputRule(/^\s*(\[([ |x])\])\s$/, nodeType, (match) => ({
|
|
933
|
+
checked: match[match.length - 1] === "x"
|
|
934
|
+
}))
|
|
935
|
+
],
|
|
936
|
+
commands: (nodeType) => [
|
|
937
|
+
createCmd(SplitTaskListItem, () => splitListItem(nodeType)),
|
|
938
|
+
createCmd(SinkTaskListItem, () => sinkListItem(nodeType)),
|
|
939
|
+
createCmd(LiftTaskListItem, () => liftListItem(nodeType)),
|
|
940
|
+
createCmd(TurnIntoTaskList, () => wrapIn(nodeType))
|
|
941
|
+
],
|
|
942
|
+
shortcuts: {
|
|
943
|
+
[SupportedKeys.NextListItem]: createShortcut(SplitTaskListItem, "Enter"),
|
|
944
|
+
[SupportedKeys.SinkListItem]: createShortcut(SinkTaskListItem, "Mod-]"),
|
|
945
|
+
[SupportedKeys.LiftListItem]: createShortcut(LiftTaskListItem, "Mod-["),
|
|
946
|
+
[SupportedKeys.TaskList]: createShortcut(TurnIntoTaskList, "Mod-Alt-9")
|
|
947
|
+
},
|
|
948
|
+
view: (ctx) => (node, view, getPos) => {
|
|
949
|
+
const createIcon = ctx.get(themeToolCtx).slots.icon;
|
|
950
|
+
const listItem2 = document.createElement("li");
|
|
951
|
+
const checkboxWrapper = document.createElement("label");
|
|
952
|
+
const checkboxStyler = document.createElement("span");
|
|
953
|
+
const checkbox = document.createElement("input");
|
|
954
|
+
const content = document.createElement("div");
|
|
955
|
+
let icon = createIcon("unchecked");
|
|
956
|
+
checkboxWrapper.appendChild(icon);
|
|
957
|
+
const setIcon = (name) => {
|
|
958
|
+
const nextIcon = createIcon(name);
|
|
959
|
+
checkboxWrapper.replaceChild(nextIcon, icon);
|
|
960
|
+
icon = nextIcon;
|
|
961
|
+
};
|
|
962
|
+
checkboxWrapper.contentEditable = "false";
|
|
963
|
+
checkbox.type = "checkbox";
|
|
964
|
+
const onChange = (event) => {
|
|
965
|
+
const target = event.target;
|
|
966
|
+
if (!(target instanceof HTMLInputElement))
|
|
967
|
+
return;
|
|
968
|
+
if (!view.editable) {
|
|
969
|
+
checkbox.checked = !checkbox.checked;
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
const { tr } = view.state;
|
|
973
|
+
view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
|
|
974
|
+
checked: target.checked
|
|
975
|
+
}));
|
|
976
|
+
};
|
|
977
|
+
checkbox.addEventListener("change", onChange);
|
|
978
|
+
listItem2.dataset.checked = node.attrs.checked;
|
|
979
|
+
if (node.attrs.checked) {
|
|
980
|
+
checkbox.setAttribute("checked", "checked");
|
|
981
|
+
}
|
|
982
|
+
checkboxWrapper.append(checkbox, checkboxStyler);
|
|
983
|
+
listItem2.append(checkboxWrapper, content);
|
|
984
|
+
const attributes = {
|
|
985
|
+
"data-type": "task-item",
|
|
986
|
+
"data-checked": node.attrs.checked ? "true" : "false",
|
|
987
|
+
class: utils.getClassName(node.attrs, "task-list-item", style)
|
|
988
|
+
};
|
|
989
|
+
Object.entries(attributes).forEach(([key, value]) => {
|
|
990
|
+
listItem2.setAttribute(key, value);
|
|
991
|
+
});
|
|
992
|
+
setIcon(node.attrs.checked ? "checked" : "unchecked");
|
|
993
|
+
return {
|
|
994
|
+
dom: listItem2,
|
|
995
|
+
contentDOM: content,
|
|
996
|
+
update: (updatedNode) => {
|
|
997
|
+
if (updatedNode.type.name !== id)
|
|
998
|
+
return false;
|
|
999
|
+
listItem2.dataset.checked = updatedNode.attrs.checked;
|
|
1000
|
+
if (updatedNode.attrs.checked) {
|
|
1001
|
+
checkbox.setAttribute("checked", "checked");
|
|
1002
|
+
} else {
|
|
1003
|
+
checkbox.removeAttribute("checked");
|
|
1004
|
+
}
|
|
1005
|
+
setIcon(updatedNode.attrs.checked ? "checked" : "unchecked");
|
|
1006
|
+
return true;
|
|
1007
|
+
},
|
|
1008
|
+
destroy: () => {
|
|
1009
|
+
checkbox.removeEventListener("change", onChange);
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
});
|
|
1015
|
+
const gfm = AtomList.create([
|
|
1016
|
+
...commonmark,
|
|
1017
|
+
$remark(() => remarkGFM),
|
|
1018
|
+
table(),
|
|
1019
|
+
urlPlugin,
|
|
1020
|
+
strikeThrough(),
|
|
1021
|
+
taskListItem()
|
|
1022
|
+
]);
|
|
1023
|
+
const commands = __spreadProps(__spreadValues({}, commands$1), {
|
|
1024
|
+
ToggleStrikeThrough,
|
|
1025
|
+
TurnIntoTaskList,
|
|
1026
|
+
SinkTaskListItem,
|
|
1027
|
+
LiftTaskListItem,
|
|
1028
|
+
SplitTaskListItem
|
|
1029
|
+
});
|
|
1030
|
+
export { BreakTable, InsertTable, LiftTaskListItem, NextCell, PrevCell, SinkTaskListItem, SplitTaskListItem, SupportedKeys, ToggleStrikeThrough, TurnIntoTaskList, commands, createTable, gfm, strikeThrough, table, taskListItem };
|
|
1031
|
+
//# sourceMappingURL=index.es.js.map
|