@milkdown/preset-gfm 5.5.0 → 6.0.0-next.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/README.md +4 -4
- package/lib/{src/auto-link.d.ts → auto-link.d.ts} +0 -0
- package/lib/auto-link.d.ts.map +1 -0
- package/lib/index.d.ts +36 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +251 -419
- package/lib/index.es.js.map +1 -1
- package/lib/{src/strike-through.d.ts → strike-through.d.ts} +1 -1
- package/lib/strike-through.d.ts.map +1 -0
- package/lib/{src/supported-keys.d.ts → supported-keys.d.ts} +0 -0
- package/lib/supported-keys.d.ts.map +1 -0
- package/lib/{src/table → table}/command.d.ts +0 -0
- package/lib/table/command.d.ts.map +1 -0
- package/lib/{src/table → table}/index.d.ts +0 -0
- package/lib/table/index.d.ts.map +1 -0
- package/lib/{src/table → table}/nodes/index.d.ts +3 -3
- package/lib/table/nodes/index.d.ts.map +1 -0
- package/lib/{src/table → table}/nodes/schema.d.ts +0 -0
- package/lib/table/nodes/schema.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/actions.d.ts +0 -0
- package/lib/table/operator-plugin/actions.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/calc-pos.d.ts +0 -0
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/constant.d.ts +0 -0
- package/lib/table/operator-plugin/constant.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/helper.d.ts +0 -0
- package/lib/table/operator-plugin/helper.d.ts.map +1 -0
- package/lib/{src/table → table}/operator-plugin/index.d.ts +0 -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/{src/table → table}/operator-plugin/widget.d.ts +0 -0
- package/lib/table/operator-plugin/widget.d.ts.map +1 -0
- package/lib/{src/table → table}/utils.d.ts +1 -0
- package/lib/table/utils.d.ts.map +1 -0
- package/lib/{src/task-list-item.d.ts → task-list-item.d.ts} +1 -1
- package/lib/task-list-item.d.ts.map +1 -0
- package/package.json +36 -12
- package/src/strike-through.ts +2 -9
- package/src/table/nodes/index.ts +0 -2
- package/src/table/operator-plugin/actions.ts +9 -9
- package/src/table/operator-plugin/index.ts +6 -4
- package/src/table/operator-plugin/style.ts +109 -37
- package/src/table/operator-plugin/widget.ts +3 -4
- package/src/task-list-item.ts +62 -127
- package/lib/src/auto-link.d.ts.map +0 -1
- package/lib/src/index.d.ts +0 -36
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/strike-through.d.ts.map +0 -1
- package/lib/src/supported-keys.d.ts.map +0 -1
- package/lib/src/table/command.d.ts.map +0 -1
- package/lib/src/table/index.d.ts.map +0 -1
- package/lib/src/table/nodes/index.d.ts.map +0 -1
- package/lib/src/table/nodes/schema.d.ts.map +0 -1
- package/lib/src/table/nodes/style.d.ts +0 -3
- package/lib/src/table/nodes/style.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/actions.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/calc-pos.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/constant.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/helper.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/index.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/style.d.ts +0 -3
- package/lib/src/table/operator-plugin/style.d.ts.map +0 -1
- package/lib/src/table/operator-plugin/widget.d.ts.map +0 -1
- package/lib/src/table/utils.d.ts.map +0 -1
- package/lib/src/task-list-item.d.ts.map +0 -1
- package/src/table/nodes/style.ts +0 -170
package/lib/index.es.js
CHANGED
|
@@ -21,8 +21,8 @@ import { SupportedKeys as SupportedKeys$2, commonmark, commands as commands$1 }
|
|
|
21
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
22
|
import { $prose, createPlugin, createShortcut, createMark, createNode, AtomList, $remark } from "@milkdown/utils";
|
|
23
23
|
import remarkGFM from "remark-gfm";
|
|
24
|
-
import { inputRules, InputRule, isInTable, Selection, findParentNode, TableMap,
|
|
25
|
-
import {
|
|
24
|
+
import { inputRules, InputRule, isInTable, Selection, findParentNode, TableMap, CellSelection, cloneTr, tableNodeTypes, 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 { themeManagerCtx, ThemeIcon, getPalette, ThemeSize, ThemeBorder, ThemeShadow, createCmdKey, schemaCtx, createCmd, editorViewCtx } from "@milkdown/core";
|
|
26
26
|
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)$/;
|
|
27
27
|
const proseUrlPlugin = () => inputRules({
|
|
28
28
|
rules: [
|
|
@@ -182,95 +182,87 @@ const calculateItem = (actions, view) => {
|
|
|
182
182
|
item.$.classList.remove("hide");
|
|
183
183
|
});
|
|
184
184
|
};
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
Action2[Action2["AlignCenter"] = 5] = "AlignCenter";
|
|
193
|
-
Action2[Action2["AlignRight"] = 6] = "AlignRight";
|
|
194
|
-
Action2[Action2["Delete"] = 7] = "Delete";
|
|
195
|
-
})(Action || (Action = {}));
|
|
196
|
-
const createActions = (ctx) => ({
|
|
197
|
-
[0]: {
|
|
198
|
-
$: ctx.get(themeToolCtx).slots.icon("leftArrow"),
|
|
199
|
-
command: () => addColumnBefore,
|
|
200
|
-
disable: (view) => !getCellSelection(view).isColSelection()
|
|
201
|
-
},
|
|
202
|
-
[1]: {
|
|
203
|
-
$: ctx.get(themeToolCtx).slots.icon("rightArrow"),
|
|
204
|
-
command: () => addColumnAfter,
|
|
205
|
-
disable: (view) => !getCellSelection(view).isColSelection()
|
|
206
|
-
},
|
|
207
|
-
[2]: {
|
|
208
|
-
$: ctx.get(themeToolCtx).slots.icon("upArrow"),
|
|
209
|
-
command: () => (state, dispatch) => {
|
|
210
|
-
if (!isInTable(state))
|
|
211
|
-
return false;
|
|
212
|
-
if (dispatch) {
|
|
213
|
-
const rect = selectedRect(state);
|
|
214
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.top));
|
|
215
|
-
}
|
|
216
|
-
return true;
|
|
185
|
+
const createActions = (ctx) => {
|
|
186
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
187
|
+
return {
|
|
188
|
+
[0]: {
|
|
189
|
+
$: (_a = ctx.get(themeManagerCtx).get(ThemeIcon, "leftArrow")) == null ? void 0 : _a.dom,
|
|
190
|
+
command: () => addColumnBefore,
|
|
191
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
217
192
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
command: () => (state, dispatch) => {
|
|
223
|
-
if (!isInTable(state))
|
|
224
|
-
return false;
|
|
225
|
-
if (dispatch) {
|
|
226
|
-
const rect = selectedRect(state);
|
|
227
|
-
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
|
|
228
|
-
}
|
|
229
|
-
return true;
|
|
193
|
+
[1]: {
|
|
194
|
+
$: (_b = ctx.get(themeManagerCtx).get(ThemeIcon, "rightArrow")) == null ? void 0 : _b.dom,
|
|
195
|
+
command: () => addColumnAfter,
|
|
196
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
230
197
|
},
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
[6]: {
|
|
244
|
-
$: ctx.get(themeToolCtx).slots.icon("alignRight"),
|
|
245
|
-
command: () => setCellAttr("alignment", "right"),
|
|
246
|
-
disable: (view) => !getCellSelection(view).isColSelection()
|
|
247
|
-
},
|
|
248
|
-
[7]: {
|
|
249
|
-
$: ctx.get(themeToolCtx).slots.icon("delete"),
|
|
250
|
-
command: (_, view) => {
|
|
251
|
-
const selection = getCellSelection(view);
|
|
252
|
-
const isCol = selection.isColSelection();
|
|
253
|
-
const isRow = selection.isRowSelection();
|
|
254
|
-
if (isCol && isRow) {
|
|
255
|
-
return deleteTable;
|
|
256
|
-
}
|
|
257
|
-
if (isCol) {
|
|
258
|
-
return deleteColumn;
|
|
259
|
-
}
|
|
260
|
-
return deleteRow;
|
|
198
|
+
[2]: {
|
|
199
|
+
$: (_c = ctx.get(themeManagerCtx).get(ThemeIcon, "upArrow")) == null ? void 0 : _c.dom,
|
|
200
|
+
command: () => (state, dispatch) => {
|
|
201
|
+
if (!isInTable(state))
|
|
202
|
+
return false;
|
|
203
|
+
if (dispatch) {
|
|
204
|
+
const rect = selectedRect(state);
|
|
205
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.top));
|
|
206
|
+
}
|
|
207
|
+
return true;
|
|
208
|
+
},
|
|
209
|
+
disable: (view) => !getCellSelection(view).isRowSelection() || getCellSelection(view).$head.parent.type.name === "table_header"
|
|
261
210
|
},
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (
|
|
211
|
+
[3]: {
|
|
212
|
+
$: (_d = ctx.get(themeManagerCtx).get(ThemeIcon, "downArrow")) == null ? void 0 : _d.dom,
|
|
213
|
+
command: () => (state, dispatch) => {
|
|
214
|
+
if (!isInTable(state))
|
|
266
215
|
return false;
|
|
216
|
+
if (dispatch) {
|
|
217
|
+
const rect = selectedRect(state);
|
|
218
|
+
dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
},
|
|
222
|
+
disable: (view) => !getCellSelection(view).isRowSelection()
|
|
223
|
+
},
|
|
224
|
+
[4]: {
|
|
225
|
+
$: (_e = ctx.get(themeManagerCtx).get(ThemeIcon, "alignLeft")) == null ? void 0 : _e.dom,
|
|
226
|
+
command: () => setCellAttr("alignment", "left"),
|
|
227
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
228
|
+
},
|
|
229
|
+
[5]: {
|
|
230
|
+
$: (_f = ctx.get(themeManagerCtx).get(ThemeIcon, "alignCenter")) == null ? void 0 : _f.dom,
|
|
231
|
+
command: () => setCellAttr("alignment", "center"),
|
|
232
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
233
|
+
},
|
|
234
|
+
[6]: {
|
|
235
|
+
$: (_g = ctx.get(themeManagerCtx).get(ThemeIcon, "alignRight")) == null ? void 0 : _g.dom,
|
|
236
|
+
command: () => setCellAttr("alignment", "right"),
|
|
237
|
+
disable: (view) => !getCellSelection(view).isColSelection()
|
|
238
|
+
},
|
|
239
|
+
[7]: {
|
|
240
|
+
$: (_h = ctx.get(themeManagerCtx).get(ThemeIcon, "delete")) == null ? void 0 : _h.dom,
|
|
241
|
+
command: (_, view) => {
|
|
242
|
+
const selection = getCellSelection(view);
|
|
243
|
+
const isCol = selection.isColSelection();
|
|
244
|
+
const isRow = selection.isRowSelection();
|
|
245
|
+
if (isCol && isRow) {
|
|
246
|
+
return deleteTable;
|
|
247
|
+
}
|
|
248
|
+
if (isCol) {
|
|
249
|
+
return deleteColumn;
|
|
267
250
|
}
|
|
268
|
-
return
|
|
251
|
+
return deleteRow;
|
|
252
|
+
},
|
|
253
|
+
disable: (view) => {
|
|
254
|
+
const selection = getCellSelection(view);
|
|
255
|
+
if (selection.isRowSelection()) {
|
|
256
|
+
if (selection.isColSelection()) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
return isFirstRowSelected(selection);
|
|
260
|
+
}
|
|
261
|
+
return false;
|
|
269
262
|
}
|
|
270
|
-
return false;
|
|
271
263
|
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
264
|
+
};
|
|
265
|
+
};
|
|
274
266
|
const calculatePosition = (view, dom) => {
|
|
275
267
|
const { selection } = view.state;
|
|
276
268
|
const isCol = selection.isColSelection();
|
|
@@ -288,61 +280,128 @@ const calculatePosition = (view, dom) => {
|
|
|
288
280
|
return [top, left];
|
|
289
281
|
});
|
|
290
282
|
};
|
|
291
|
-
var ToolTipPos
|
|
292
|
-
(function(ToolTipPos2) {
|
|
283
|
+
var ToolTipPos = /* @__PURE__ */ ((ToolTipPos2) => {
|
|
293
284
|
ToolTipPos2["Left"] = "Left";
|
|
294
285
|
ToolTipPos2["Top"] = "Top";
|
|
295
286
|
ToolTipPos2["Point"] = "Point";
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
287
|
+
return ToolTipPos2;
|
|
288
|
+
})(ToolTipPos || {});
|
|
289
|
+
const injectStyle = (themeManager, { css, injectGlobal }) => {
|
|
290
|
+
const palette = getPalette(themeManager);
|
|
291
|
+
const radius = themeManager.get(ThemeSize, "radius");
|
|
292
|
+
const lineWidth = themeManager.get(ThemeSize, "lineWidth");
|
|
293
|
+
injectGlobal`
|
|
294
|
+
.milkdown {
|
|
295
|
+
.tableWrapper {
|
|
296
|
+
table {
|
|
297
|
+
width: calc(100% - 2em) !important;
|
|
298
|
+
margin: 1em 0 1em 1em !important;
|
|
299
|
+
|
|
300
|
+
.milkdown-cell-left,
|
|
301
|
+
.milkdown-cell-point,
|
|
302
|
+
.milkdown-cell-top {
|
|
303
|
+
position: absolute;
|
|
304
|
+
|
|
305
|
+
&::after {
|
|
306
|
+
cursor: pointer;
|
|
307
|
+
position: absolute;
|
|
308
|
+
top: 0;
|
|
309
|
+
left: 0;
|
|
310
|
+
height: 100%;
|
|
311
|
+
width: 100%;
|
|
312
|
+
display: block;
|
|
313
|
+
transition: all 0.2s ease-in-out;
|
|
314
|
+
background: ${palette("secondary", 0.12)};
|
|
315
|
+
content: '';
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
&:hover::after {
|
|
319
|
+
background: ${palette("secondary", 0.38)};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.milkdown-cell-left {
|
|
324
|
+
left: calc(-6px - 0.5em);
|
|
325
|
+
top: 0;
|
|
326
|
+
bottom: 0;
|
|
327
|
+
width: 0.5em;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.milkdown-cell-top {
|
|
331
|
+
left: 0;
|
|
332
|
+
right: 0;
|
|
333
|
+
top: calc(-6px - 0.5em);
|
|
334
|
+
height: 0.5em;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.milkdown-cell-point {
|
|
338
|
+
left: calc(-2px - 1em);
|
|
339
|
+
top: calc(-2px - 1em);
|
|
340
|
+
width: 1em;
|
|
341
|
+
height: 1em;
|
|
342
|
+
|
|
343
|
+
.icon {
|
|
344
|
+
position: absolute;
|
|
345
|
+
top: 0;
|
|
346
|
+
bottom: 0;
|
|
347
|
+
left: 0;
|
|
348
|
+
right: 0;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
`;
|
|
299
355
|
return css`
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
356
|
+
display: inline-flex;
|
|
357
|
+
cursor: pointer;
|
|
358
|
+
z-index: 2;
|
|
303
359
|
|
|
304
|
-
|
|
360
|
+
justify-content: space-evenly;
|
|
305
361
|
|
|
306
|
-
|
|
362
|
+
position: absolute;
|
|
307
363
|
|
|
308
|
-
|
|
364
|
+
border-radius: ${radius};
|
|
309
365
|
|
|
310
|
-
|
|
366
|
+
${themeManager.get(ThemeBorder, void 0)};
|
|
367
|
+
${themeManager.get(ThemeShadow, void 0)};
|
|
311
368
|
|
|
312
|
-
|
|
369
|
+
overflow: hidden;
|
|
370
|
+
background: ${palette("surface")};
|
|
313
371
|
|
|
314
|
-
|
|
315
|
-
|
|
372
|
+
.icon {
|
|
373
|
+
position: relative;
|
|
374
|
+
color: ${palette("solid", 0.87)};
|
|
316
375
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
376
|
+
width: 2em;
|
|
377
|
+
line-height: 2em;
|
|
378
|
+
text-align: center;
|
|
379
|
+
transition: all 0.4s ease-in-out;
|
|
320
380
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
381
|
+
&:hover {
|
|
382
|
+
background-color: ${palette("secondary", 0.12)};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
&.active {
|
|
386
|
+
color: ${palette("primary")};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
&:not(:last-child)::after {
|
|
390
|
+
content: '';
|
|
391
|
+
position: absolute;
|
|
392
|
+
right: 0;
|
|
393
|
+
top: 0;
|
|
394
|
+
width: ${lineWidth};
|
|
395
|
+
bottom: 0;
|
|
396
|
+
background: ${palette("line")};
|
|
397
|
+
}
|
|
330
398
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
top: 0;
|
|
336
|
-
width: ${size.lineWidth};
|
|
337
|
-
bottom: 0;
|
|
338
|
-
background: ${palette("line")};
|
|
399
|
+
|
|
400
|
+
&.hide,
|
|
401
|
+
.hide {
|
|
402
|
+
display: none;
|
|
339
403
|
}
|
|
340
|
-
|
|
341
|
-
&.hide,
|
|
342
|
-
.hide {
|
|
343
|
-
display: none;
|
|
344
|
-
}
|
|
345
|
-
`;
|
|
404
|
+
`;
|
|
346
405
|
};
|
|
347
406
|
const calculateClassName = (pos) => {
|
|
348
407
|
switch (pos) {
|
|
@@ -359,11 +418,12 @@ const calculateClassName = (pos) => {
|
|
|
359
418
|
}
|
|
360
419
|
};
|
|
361
420
|
function createWidget(ctx, cell, pos, index = 0) {
|
|
362
|
-
|
|
421
|
+
return Decoration.widget(cell.pos + 1, (view) => {
|
|
422
|
+
var _a;
|
|
363
423
|
const div = document.createElement("div");
|
|
364
424
|
div.classList.add(calculateClassName(pos));
|
|
365
425
|
if (pos === ToolTipPos.Point) {
|
|
366
|
-
div.appendChild(ctx.get(
|
|
426
|
+
div.appendChild((_a = ctx.get(themeManagerCtx).get(ThemeIcon, "select")) == null ? void 0 : _a.dom);
|
|
367
427
|
}
|
|
368
428
|
div.addEventListener("mousedown", (e) => {
|
|
369
429
|
if (!view)
|
|
@@ -386,15 +446,16 @@ function createWidget(ctx, cell, pos, index = 0) {
|
|
|
386
446
|
});
|
|
387
447
|
return div;
|
|
388
448
|
});
|
|
389
|
-
return widget;
|
|
390
449
|
}
|
|
391
450
|
const operatorPlugin = (ctx, utils) => {
|
|
392
451
|
const items = createActions(ctx);
|
|
393
452
|
const tooltip = document.createElement("div");
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
453
|
+
utils.themeManager.onFlush(() => {
|
|
454
|
+
const style = utils.getStyle(injectStyle);
|
|
455
|
+
if (style) {
|
|
456
|
+
tooltip.classList.add(style);
|
|
457
|
+
}
|
|
458
|
+
});
|
|
398
459
|
tooltip.classList.add("table-tooltip", "hide");
|
|
399
460
|
return new Plugin({
|
|
400
461
|
key: new PluginKey("MILKDOWN_TABLE_OP"),
|
|
@@ -476,172 +537,6 @@ const schema = tableNodes({
|
|
|
476
537
|
}
|
|
477
538
|
}
|
|
478
539
|
});
|
|
479
|
-
const proseTableStyle = ({ css }) => css`
|
|
480
|
-
/* copy from https://github.com/ProseMirror/prosemirror-tables/blob/master/style/tables.css */
|
|
481
|
-
.ProseMirror .tableWrapper {
|
|
482
|
-
overflow-x: auto;
|
|
483
|
-
}
|
|
484
|
-
.ProseMirror table {
|
|
485
|
-
border-collapse: collapse;
|
|
486
|
-
table-layout: fixed;
|
|
487
|
-
width: 100%;
|
|
488
|
-
overflow: hidden;
|
|
489
|
-
}
|
|
490
|
-
.ProseMirror td,
|
|
491
|
-
.ProseMirror th {
|
|
492
|
-
vertical-align: top;
|
|
493
|
-
box-sizing: border-box;
|
|
494
|
-
position: relative;
|
|
495
|
-
}
|
|
496
|
-
.ProseMirror .column-resize-handle {
|
|
497
|
-
position: absolute;
|
|
498
|
-
right: -2px;
|
|
499
|
-
top: 0;
|
|
500
|
-
bottom: 0;
|
|
501
|
-
width: 4px;
|
|
502
|
-
z-index: 20;
|
|
503
|
-
background-color: #adf;
|
|
504
|
-
pointer-events: none;
|
|
505
|
-
}
|
|
506
|
-
.ProseMirror.resize-cursor {
|
|
507
|
-
cursor: ew-resize;
|
|
508
|
-
cursor: col-resize;
|
|
509
|
-
}
|
|
510
|
-
/* Give selected cells a blue overlay */
|
|
511
|
-
.ProseMirror .selectedCell:after {
|
|
512
|
-
z-index: 2;
|
|
513
|
-
position: absolute;
|
|
514
|
-
content: '';
|
|
515
|
-
left: 0;
|
|
516
|
-
right: 0;
|
|
517
|
-
top: 0;
|
|
518
|
-
bottom: 0;
|
|
519
|
-
background: rgba(200, 200, 255, 0.4);
|
|
520
|
-
pointer-events: none;
|
|
521
|
-
}
|
|
522
|
-
`;
|
|
523
|
-
const injectStyle = (utils) => {
|
|
524
|
-
return utils.getStyle(({ size, palette, mixin }, emotion) => {
|
|
525
|
-
var _a, _b, _c;
|
|
526
|
-
const css = emotion.injectGlobal;
|
|
527
|
-
css`
|
|
528
|
-
${proseTableStyle(emotion)}
|
|
529
|
-
|
|
530
|
-
.tableWrapper {
|
|
531
|
-
margin: 0 !important;
|
|
532
|
-
|
|
533
|
-
${(_a = mixin.scrollbar) == null ? void 0 : _a.call(mixin, "x")};
|
|
534
|
-
|
|
535
|
-
width: 100%;
|
|
536
|
-
|
|
537
|
-
table {
|
|
538
|
-
width: calc(100% - 2rem) !important;
|
|
539
|
-
border-radius: ${size.radius};
|
|
540
|
-
box-sizing: border-box;
|
|
541
|
-
margin: 1rem 0 1rem 1rem !important;
|
|
542
|
-
overflow: auto !important;
|
|
543
|
-
* {
|
|
544
|
-
margin: 0 !important;
|
|
545
|
-
box-sizing: border-box;
|
|
546
|
-
font-size: 1rem;
|
|
547
|
-
}
|
|
548
|
-
tr {
|
|
549
|
-
${(_b = mixin.border) == null ? void 0 : _b.call(mixin, "bottom")};
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
th {
|
|
553
|
-
background: ${palette("background", 0.5)};
|
|
554
|
-
font-weight: 400;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
th,
|
|
558
|
-
td {
|
|
559
|
-
min-width: 100px;
|
|
560
|
-
${(_c = mixin.border) == null ? void 0 : _c.call(mixin)};
|
|
561
|
-
text-align: left;
|
|
562
|
-
position: relative;
|
|
563
|
-
line-height: 3rem;
|
|
564
|
-
box-sizing: border-box;
|
|
565
|
-
height: 3rem;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
.selectedCell {
|
|
569
|
-
&::after {
|
|
570
|
-
background: ${palette("secondary", 0.38)};
|
|
571
|
-
}
|
|
572
|
-
& ::selection {
|
|
573
|
-
background: transparent;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
.column-resize-handle {
|
|
578
|
-
background: ${palette("primary")};
|
|
579
|
-
width: ${size.lineWidth};
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
th,
|
|
583
|
-
td {
|
|
584
|
-
padding: 0 1rem;
|
|
585
|
-
p {
|
|
586
|
-
line-height: unset !important;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
.milkdown-cell-left,
|
|
591
|
-
.milkdown-cell-point,
|
|
592
|
-
.milkdown-cell-top {
|
|
593
|
-
position: absolute;
|
|
594
|
-
|
|
595
|
-
&::after {
|
|
596
|
-
cursor: pointer;
|
|
597
|
-
position: absolute;
|
|
598
|
-
top: 0;
|
|
599
|
-
left: 0;
|
|
600
|
-
height: 100%;
|
|
601
|
-
width: 100%;
|
|
602
|
-
display: block;
|
|
603
|
-
transition: all 0.2s ease-in-out;
|
|
604
|
-
background: ${palette("secondary", 0.12)};
|
|
605
|
-
content: '';
|
|
606
|
-
}
|
|
607
|
-
&:hover::after {
|
|
608
|
-
background: ${palette("secondary", 0.38)};
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
.milkdown-cell-left {
|
|
613
|
-
left: calc(-6px - 0.5rem);
|
|
614
|
-
top: 0;
|
|
615
|
-
bottom: 0;
|
|
616
|
-
width: 0.5rem;
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
.milkdown-cell-top {
|
|
620
|
-
left: 0;
|
|
621
|
-
right: 0;
|
|
622
|
-
top: calc(-6px - 0.5rem);
|
|
623
|
-
height: 0.5rem;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
.milkdown-cell-point {
|
|
627
|
-
left: calc(-2px - 1rem);
|
|
628
|
-
top: calc(-2px - 1rem);
|
|
629
|
-
width: 1rem;
|
|
630
|
-
height: 1rem;
|
|
631
|
-
|
|
632
|
-
.icon {
|
|
633
|
-
position: absolute;
|
|
634
|
-
top: 0;
|
|
635
|
-
bottom: 0;
|
|
636
|
-
left: 0;
|
|
637
|
-
right: 0;
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
`;
|
|
643
|
-
});
|
|
644
|
-
};
|
|
645
540
|
const SupportedKeys$1 = {
|
|
646
541
|
NextCell: "NextCell",
|
|
647
542
|
PrevCell: "PrevCell",
|
|
@@ -652,7 +547,6 @@ const NextCell = createCmdKey("NextCell");
|
|
|
652
547
|
const BreakTable = createCmdKey("BreakTable");
|
|
653
548
|
const InsertTable = createCmdKey("InsertTable");
|
|
654
549
|
const table = createPlugin((utils) => {
|
|
655
|
-
injectStyle(utils);
|
|
656
550
|
return {
|
|
657
551
|
schema: () => ({
|
|
658
552
|
node: {
|
|
@@ -789,11 +683,8 @@ const SupportedKeys = __spreadProps(__spreadValues(__spreadValues({}, SupportedK
|
|
|
789
683
|
TaskList: "TaskList"
|
|
790
684
|
});
|
|
791
685
|
const ToggleStrikeThrough = createCmdKey("ToggleStrikeThrough");
|
|
686
|
+
const id = "strike_through";
|
|
792
687
|
const strikeThrough = createMark((utils) => {
|
|
793
|
-
const id = "strike_through";
|
|
794
|
-
const style = utils.getStyle((themeTool, { css }) => css`
|
|
795
|
-
text-decoration-color: ${themeTool.palette("secondary")};
|
|
796
|
-
`);
|
|
797
688
|
return {
|
|
798
689
|
id,
|
|
799
690
|
schema: () => ({
|
|
@@ -801,7 +692,7 @@ const strikeThrough = createMark((utils) => {
|
|
|
801
692
|
{ tag: "del" },
|
|
802
693
|
{ style: "text-decoration", getAttrs: (value) => value === "line-through" }
|
|
803
694
|
],
|
|
804
|
-
toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through"
|
|
695
|
+
toDOM: (mark) => ["del", { class: utils.getClassName(mark.attrs, "strike-through") }],
|
|
805
696
|
parseMarkdown: {
|
|
806
697
|
match: (node) => node.type === "delete",
|
|
807
698
|
runner: (state, node, markType) => {
|
|
@@ -832,56 +723,10 @@ const SinkTaskListItem = createCmdKey("SinkTaskListItem");
|
|
|
832
723
|
const LiftTaskListItem = createCmdKey("LiftTaskListItem");
|
|
833
724
|
const TurnIntoTaskList = createCmdKey("TurnIntoTaskList");
|
|
834
725
|
const taskListItem = createNode((utils) => {
|
|
835
|
-
const
|
|
836
|
-
const style = utils.getStyle(({ palette, size }, { css }) => css`
|
|
837
|
-
list-style-type: none;
|
|
838
|
-
position: relative;
|
|
839
|
-
|
|
840
|
-
& > div {
|
|
841
|
-
overflow: hidden;
|
|
842
|
-
padding: 0 2px;
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
label {
|
|
846
|
-
position: absolute;
|
|
847
|
-
top: 0;
|
|
848
|
-
left: -2rem;
|
|
849
|
-
display: inline-block;
|
|
850
|
-
width: 1.5rem;
|
|
851
|
-
height: 1.5rem;
|
|
852
|
-
margin: 0.5rem 0;
|
|
853
|
-
input {
|
|
854
|
-
visibility: hidden;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
label:before {
|
|
858
|
-
position: absolute;
|
|
859
|
-
top: 0;
|
|
860
|
-
right: 0;
|
|
861
|
-
bottom: 0;
|
|
862
|
-
left: 0;
|
|
863
|
-
border-radius: ${size.radius};
|
|
864
|
-
}
|
|
865
|
-
label:hover:before {
|
|
866
|
-
background: ${palette("background")};
|
|
867
|
-
}
|
|
868
|
-
&[data-checked='true'] {
|
|
869
|
-
label {
|
|
870
|
-
color: ${palette("primary")};
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
&[data-checked='false'] {
|
|
874
|
-
label {
|
|
875
|
-
color: ${palette("solid", 0.87)};
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
.paragraph {
|
|
879
|
-
margin: 0.5rem 0;
|
|
880
|
-
}
|
|
881
|
-
`);
|
|
726
|
+
const id2 = "task_list_item";
|
|
882
727
|
return {
|
|
883
|
-
id,
|
|
884
|
-
schema: () => ({
|
|
728
|
+
id: id2,
|
|
729
|
+
schema: (ctx) => ({
|
|
885
730
|
group: "listItem",
|
|
886
731
|
content: "paragraph block*",
|
|
887
732
|
defining: true,
|
|
@@ -902,15 +747,40 @@ const taskListItem = createNode((utils) => {
|
|
|
902
747
|
}
|
|
903
748
|
}
|
|
904
749
|
],
|
|
905
|
-
toDOM: (node) =>
|
|
906
|
-
"
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
750
|
+
toDOM: (node) => {
|
|
751
|
+
const checkbox = document.createElement("input");
|
|
752
|
+
checkbox.type = "checkbox";
|
|
753
|
+
checkbox.checked = node.attrs["checked"];
|
|
754
|
+
checkbox.className = utils.getClassName(node.attrs, "task-list-item_checkbox");
|
|
755
|
+
checkbox.onchange = (event) => {
|
|
756
|
+
const target = event.target;
|
|
757
|
+
if (!(target instanceof HTMLInputElement))
|
|
758
|
+
return;
|
|
759
|
+
const view = ctx.get(editorViewCtx);
|
|
760
|
+
if (!view.editable) {
|
|
761
|
+
checkbox.checked = !checkbox.checked;
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
const { top, left } = target.getBoundingClientRect();
|
|
765
|
+
const result = view.posAtCoords({ top, left });
|
|
766
|
+
if (!result)
|
|
767
|
+
return;
|
|
768
|
+
const { tr } = view.state;
|
|
769
|
+
view.dispatch(tr.setNodeMarkup(result.inside, void 0, {
|
|
770
|
+
checked: target.checked
|
|
771
|
+
}));
|
|
772
|
+
};
|
|
773
|
+
return [
|
|
774
|
+
"li",
|
|
775
|
+
{
|
|
776
|
+
"data-type": "task-item",
|
|
777
|
+
"data-checked": node.attrs["checked"] ? "true" : "false",
|
|
778
|
+
class: utils.getClassName(node.attrs, "task-list-item")
|
|
779
|
+
},
|
|
780
|
+
checkbox,
|
|
781
|
+
["span", { class: utils.getClassName(node.attrs, "task-list-item_body") }, 0]
|
|
782
|
+
];
|
|
783
|
+
},
|
|
914
784
|
parseMarkdown: {
|
|
915
785
|
match: ({ type, checked }) => {
|
|
916
786
|
return type === "listItem" && checked !== null;
|
|
@@ -922,7 +792,7 @@ const taskListItem = createNode((utils) => {
|
|
|
922
792
|
}
|
|
923
793
|
},
|
|
924
794
|
toMarkdown: {
|
|
925
|
-
match: (node) => node.type.name ===
|
|
795
|
+
match: (node) => node.type.name === id2,
|
|
926
796
|
runner: (state, node) => {
|
|
927
797
|
state.openNode("listItem", void 0, { checked: node.attrs["checked"] });
|
|
928
798
|
state.next(node.content);
|
|
@@ -947,68 +817,30 @@ const taskListItem = createNode((utils) => {
|
|
|
947
817
|
[SupportedKeys.LiftListItem]: createShortcut(LiftTaskListItem, "Mod-["),
|
|
948
818
|
[SupportedKeys.TaskList]: createShortcut(TurnIntoTaskList, "Mod-Alt-9")
|
|
949
819
|
},
|
|
950
|
-
view: (
|
|
951
|
-
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
const setIcon = (name) => {
|
|
960
|
-
const nextIcon = createIcon(name);
|
|
961
|
-
checkboxWrapper.replaceChild(nextIcon, icon);
|
|
962
|
-
icon = nextIcon;
|
|
963
|
-
};
|
|
964
|
-
checkboxWrapper.contentEditable = "false";
|
|
965
|
-
checkbox.type = "checkbox";
|
|
966
|
-
const onChange = (event) => {
|
|
967
|
-
const target = event.target;
|
|
968
|
-
if (!(target instanceof HTMLInputElement))
|
|
969
|
-
return;
|
|
970
|
-
if (!view.editable) {
|
|
971
|
-
checkbox.checked = !checkbox.checked;
|
|
972
|
-
return;
|
|
820
|
+
view: () => (node, view, getPos) => {
|
|
821
|
+
let currNode = node;
|
|
822
|
+
const renderer = utils.themeManager.get("task-list-item", {
|
|
823
|
+
editable: () => view.editable,
|
|
824
|
+
onChange: (selected) => {
|
|
825
|
+
const { tr } = view.state;
|
|
826
|
+
view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
|
|
827
|
+
checked: selected
|
|
828
|
+
}));
|
|
973
829
|
}
|
|
974
|
-
const { tr } = view.state;
|
|
975
|
-
view.dispatch(tr.setNodeMarkup(getPos(), void 0, {
|
|
976
|
-
checked: target.checked
|
|
977
|
-
}));
|
|
978
|
-
};
|
|
979
|
-
checkbox.addEventListener("change", onChange);
|
|
980
|
-
listItem2.dataset["checked"] = node.attrs["checked"];
|
|
981
|
-
if (node.attrs["checked"]) {
|
|
982
|
-
checkbox.setAttribute("checked", "checked");
|
|
983
|
-
}
|
|
984
|
-
checkboxWrapper.append(checkbox, checkboxStyler);
|
|
985
|
-
listItem2.append(checkboxWrapper, content);
|
|
986
|
-
const attributes = {
|
|
987
|
-
"data-type": "task-item",
|
|
988
|
-
"data-checked": node.attrs["checked"] ? "true" : "false",
|
|
989
|
-
class: utils.getClassName(node.attrs, "task-list-item", style)
|
|
990
|
-
};
|
|
991
|
-
Object.entries(attributes).forEach(([key, value]) => {
|
|
992
|
-
listItem2.setAttribute(key, value);
|
|
993
830
|
});
|
|
994
|
-
|
|
831
|
+
if (!renderer)
|
|
832
|
+
return {};
|
|
833
|
+
const { dom, contentDOM, onUpdate } = renderer;
|
|
834
|
+
onUpdate(currNode);
|
|
995
835
|
return {
|
|
996
|
-
dom
|
|
997
|
-
contentDOM
|
|
836
|
+
dom,
|
|
837
|
+
contentDOM,
|
|
998
838
|
update: (updatedNode) => {
|
|
999
|
-
if (updatedNode.type.name !==
|
|
839
|
+
if (updatedNode.type.name !== id2)
|
|
1000
840
|
return false;
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
checkbox.setAttribute("checked", "checked");
|
|
1004
|
-
} else {
|
|
1005
|
-
checkbox.removeAttribute("checked");
|
|
1006
|
-
}
|
|
1007
|
-
setIcon(updatedNode.attrs["checked"] ? "checked" : "unchecked");
|
|
841
|
+
currNode = updatedNode;
|
|
842
|
+
onUpdate(currNode);
|
|
1008
843
|
return true;
|
|
1009
|
-
},
|
|
1010
|
-
destroy: () => {
|
|
1011
|
-
checkbox.removeEventListener("change", onChange);
|
|
1012
844
|
}
|
|
1013
845
|
};
|
|
1014
846
|
}
|