@milkdown/preset-gfm 6.5.2 → 6.5.4
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/footnote/definition.d.ts +1 -1
- package/lib/footnote/definition.d.ts.map +1 -1
- package/lib/footnote/index.d.ts.map +1 -1
- package/lib/footnote/reference.d.ts +1 -1
- package/lib/footnote/reference.d.ts.map +1 -1
- package/lib/footnote/utils.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.es.js +649 -607
- package/lib/index.es.js.map +1 -1
- package/lib/strike-through.d.ts +1 -1
- package/lib/strike-through.d.ts.map +1 -1
- package/lib/supported-keys.d.ts +1 -1
- package/lib/supported-keys.d.ts.map +1 -1
- package/lib/table/command.d.ts +2 -2
- package/lib/table/command.d.ts.map +1 -1
- package/lib/table/index.d.ts +1 -1
- package/lib/table/index.d.ts.map +1 -1
- package/lib/table/nodes/index.d.ts +1 -1
- package/lib/table/nodes/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/actions.d.ts +5 -5
- package/lib/table/operator-plugin/actions.d.ts.map +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts +1 -1
- package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
- package/lib/table/operator-plugin/constant.d.ts.map +1 -1
- package/lib/table/operator-plugin/helper.d.ts +3 -3
- package/lib/table/operator-plugin/helper.d.ts.map +1 -1
- package/lib/table/operator-plugin/index.d.ts +2 -2
- package/lib/table/operator-plugin/index.d.ts.map +1 -1
- package/lib/table/operator-plugin/style.d.ts +1 -1
- package/lib/table/operator-plugin/style.d.ts.map +1 -1
- package/lib/table/operator-plugin/widget.d.ts +2 -2
- package/lib/table/operator-plugin/widget.d.ts.map +1 -1
- package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -1
- package/lib/table/plugin/cell-selection.d.ts +5 -3
- package/lib/table/plugin/cell-selection.d.ts.map +1 -1
- package/lib/table/plugin/column-resizing.d.ts +2 -1
- package/lib/table/plugin/column-resizing.d.ts.map +1 -1
- package/lib/table/plugin/commands.d.ts +2 -2
- package/lib/table/plugin/commands.d.ts.map +1 -1
- package/lib/table/plugin/copy-paste.d.ts +6 -5
- package/lib/table/plugin/copy-paste.d.ts.map +1 -1
- package/lib/table/plugin/fix-tables.d.ts +3 -2
- package/lib/table/plugin/fix-tables.d.ts.map +1 -1
- package/lib/table/plugin/index.d.ts.map +1 -1
- package/lib/table/plugin/schema.d.ts +1 -1
- package/lib/table/plugin/schema.d.ts.map +1 -1
- package/lib/table/plugin/table-editing.d.ts +1 -1
- package/lib/table/plugin/table-editing.d.ts.map +1 -1
- package/lib/table/plugin/table-map.d.ts +2 -2
- package/lib/table/plugin/table-map.d.ts.map +1 -1
- package/lib/table/plugin/table-view.d.ts +2 -2
- package/lib/table/plugin/table-view.d.ts.map +1 -1
- package/lib/table/plugin/types.d.ts +2 -2
- package/lib/table/plugin/types.d.ts.map +1 -1
- package/lib/table/plugin/util.d.ts +2 -2
- package/lib/table/plugin/util.d.ts.map +1 -1
- package/lib/table/utils.d.ts +5 -5
- package/lib/table/utils.d.ts.map +1 -1
- package/lib/task-list-item.d.ts +2 -2
- package/lib/task-list-item.d.ts.map +1 -1
- package/package.json +22 -17
- package/src/footnote/definition.ts +172 -166
- package/src/footnote/index.ts +2 -2
- package/src/footnote/reference.ts +166 -162
- package/src/footnote/utils.ts +2 -2
- package/src/index.ts +83 -83
- package/src/strike-through.ts +36 -36
- package/src/supported-keys.ts +9 -8
- package/src/table/command.ts +17 -16
- package/src/table/index.ts +9 -9
- package/src/table/nodes/index.ts +177 -174
- package/src/table/operator-plugin/actions.ts +103 -102
- package/src/table/operator-plugin/calc-pos.ts +31 -34
- package/src/table/operator-plugin/constant.ts +3 -3
- package/src/table/operator-plugin/helper.ts +31 -32
- package/src/table/operator-plugin/index.ts +104 -95
- package/src/table/operator-plugin/style.ts +10 -9
- package/src/table/operator-plugin/widget.ts +47 -45
- package/src/table/plugin/auto-insert-zero-space.ts +41 -41
- package/src/table/plugin/cell-selection.ts +325 -296
- package/src/table/plugin/column-resizing.ts +226 -198
- package/src/table/plugin/commands.ts +464 -421
- package/src/table/plugin/copy-paste.ts +256 -240
- package/src/table/plugin/fix-tables.ts +103 -88
- package/src/table/plugin/index.ts +3 -3
- package/src/table/plugin/schema.ts +100 -94
- package/src/table/plugin/table-editing.ts +324 -230
- package/src/table/plugin/table-map.ts +294 -229
- package/src/table/plugin/table-view.ts +66 -62
- package/src/table/plugin/types.ts +8 -8
- package/src/table/plugin/util.ts +78 -66
- package/src/table/utils.ts +141 -138
- package/src/task-list-item.ts +151 -146
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import { missingRootElement } from '@milkdown/exception'
|
|
4
|
-
import { calculateNodePosition } from '@milkdown/prose'
|
|
5
|
-
import { EditorView } from '@milkdown/prose/view'
|
|
3
|
+
import { missingRootElement } from '@milkdown/exception'
|
|
4
|
+
import { calculateNodePosition } from '@milkdown/prose'
|
|
5
|
+
import type { EditorView } from '@milkdown/prose/view'
|
|
6
6
|
|
|
7
|
-
import { CellSelection } from '../plugin'
|
|
7
|
+
import type { CellSelection } from '../plugin'
|
|
8
8
|
|
|
9
9
|
export const calculatePosition = (view: EditorView, dom: HTMLElement) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return [top, left];
|
|
38
|
-
});
|
|
39
|
-
};
|
|
10
|
+
const { selection } = view.state as unknown as { selection: CellSelection }
|
|
11
|
+
const isCol = selection.isColSelection()
|
|
12
|
+
const isRow = selection.isRowSelection()
|
|
13
|
+
|
|
14
|
+
calculateNodePosition(view, dom, (selected, target, parent) => {
|
|
15
|
+
const $editor = dom.parentElement
|
|
16
|
+
if (!$editor)
|
|
17
|
+
throw missingRootElement()
|
|
18
|
+
|
|
19
|
+
let left = !isRow
|
|
20
|
+
? selected.left - parent.left + (selected.width - target.width) / 2
|
|
21
|
+
: selected.left - parent.left - target.width / 2 - 8
|
|
22
|
+
let top = selected.top - parent.top - target.height - (isCol ? 14 : 0) - 14 + $editor.scrollTop
|
|
23
|
+
|
|
24
|
+
if (left < 0)
|
|
25
|
+
left = 0
|
|
26
|
+
|
|
27
|
+
const maxLeft = $editor.clientWidth - (target.width + 4)
|
|
28
|
+
if (left > maxLeft)
|
|
29
|
+
left = maxLeft
|
|
30
|
+
|
|
31
|
+
if (top < $editor.scrollTop)
|
|
32
|
+
top = selected.top - parent.top + 14 + $editor.scrollTop
|
|
33
|
+
|
|
34
|
+
return [top, left]
|
|
35
|
+
})
|
|
36
|
+
}
|
|
@@ -1,40 +1,39 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { EditorView } from '@milkdown/prose/view'
|
|
2
|
+
import type { EditorView } from '@milkdown/prose/view'
|
|
3
3
|
|
|
4
|
-
import { CellSelection } from '../plugin'
|
|
5
|
-
import { TableMap } from '../plugin/table-map'
|
|
6
|
-
import { Item } from './actions'
|
|
4
|
+
import type { CellSelection } from '../plugin'
|
|
5
|
+
import { TableMap } from '../plugin/table-map'
|
|
6
|
+
import type { Item } from './actions'
|
|
7
7
|
|
|
8
|
-
export const getCellSelection = (view: EditorView): CellSelection => view.state.selection as unknown as CellSelection
|
|
8
|
+
export const getCellSelection = (view: EditorView): CellSelection => view.state.selection as unknown as CellSelection
|
|
9
9
|
|
|
10
10
|
export const isFirstRowSelected = (selection: CellSelection) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const map = TableMap.get(selection.$anchorCell.node(-1))
|
|
12
|
+
const start = selection.$anchorCell.start(-1)
|
|
13
|
+
const cells = map.cellsInRect({
|
|
14
|
+
left: 0,
|
|
15
|
+
right: map.width,
|
|
16
|
+
top: 0,
|
|
17
|
+
bottom: 1,
|
|
18
|
+
})
|
|
19
|
+
const selectedCells = map.cellsInRect(
|
|
20
|
+
map.rectBetween(selection.$anchorCell.pos - start, selection.$headCell.pos - start),
|
|
21
|
+
)
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
23
|
+
for (let i = 0, count = cells.length; i < count; i++) {
|
|
24
|
+
if (!selectedCells.includes(cells[i] as number))
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
30
29
|
|
|
31
30
|
export const calculateItem = (actions: Record<string, Item>, view: EditorView) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
31
|
+
Object.values(actions).forEach((item) => {
|
|
32
|
+
const disable = item.disable?.(view)
|
|
33
|
+
if (disable) {
|
|
34
|
+
item.$.classList.add('hide')
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
item.$.classList.remove('hide')
|
|
38
|
+
})
|
|
39
|
+
}
|
|
@@ -1,101 +1,110 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import { Ctx } from '@milkdown/core'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
import type { Ctx } from '@milkdown/core'
|
|
4
|
+
import { editorViewCtx } from '@milkdown/core'
|
|
5
|
+
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
6
|
+
import type { Decoration } from '@milkdown/prose/view'
|
|
7
|
+
import { DecorationSet } from '@milkdown/prose/view'
|
|
8
|
+
import type { ThemeUtils } from '@milkdown/utils'
|
|
9
|
+
|
|
10
|
+
import { CellSelection } from '../plugin'
|
|
11
|
+
import type { CellPos } from '../utils'
|
|
12
|
+
import { getCellsInColumn, getCellsInRow } from '../utils'
|
|
13
|
+
import { createActions } from './actions'
|
|
14
|
+
import { calculatePosition } from './calc-pos'
|
|
15
|
+
import { ToolTipPos } from './constant'
|
|
16
|
+
import { calculateItem } from './helper'
|
|
17
|
+
import { injectStyle } from './style'
|
|
18
|
+
import { createWidget } from './widget'
|
|
19
|
+
|
|
20
|
+
export const key = 'MILKDOWN_TABLE'
|
|
18
21
|
|
|
19
22
|
export const operatorPlugin = (ctx: Ctx, utils: ThemeUtils) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
return new Plugin({
|
|
24
|
+
key: new PluginKey('MILKDOWN_TABLE_OP'),
|
|
25
|
+
props: {
|
|
26
|
+
decorations: (state) => {
|
|
27
|
+
const view = ctx.get(editorViewCtx)
|
|
28
|
+
if (!view.editable)
|
|
29
|
+
return null
|
|
30
|
+
|
|
31
|
+
const decorations: Decoration[] = []
|
|
32
|
+
const leftCells = getCellsInColumn(0)(state.selection)
|
|
33
|
+
if (!leftCells)
|
|
34
|
+
return null
|
|
35
|
+
const topCells = getCellsInRow(0)(state.selection)
|
|
36
|
+
if (!topCells)
|
|
37
|
+
return null
|
|
38
|
+
|
|
39
|
+
const [topLeft] = leftCells
|
|
40
|
+
|
|
41
|
+
decorations.push(createWidget(ctx, topLeft as CellPos, ToolTipPos.Point))
|
|
42
|
+
leftCells.forEach((cell, i) => {
|
|
43
|
+
decorations.push(createWidget(ctx, cell, ToolTipPos.Left, i))
|
|
44
|
+
})
|
|
45
|
+
topCells.forEach((cell, i) => {
|
|
46
|
+
decorations.push(createWidget(ctx, cell, ToolTipPos.Top, i))
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return DecorationSet.create(state.doc, decorations)
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
view: (editorView) => {
|
|
53
|
+
const items = Object.fromEntries(Object.entries(createActions(ctx)).filter(([, value]) => value.$ != null))
|
|
54
|
+
const tooltip = document.createElement('div')
|
|
55
|
+
utils.themeManager.onFlush(() => {
|
|
56
|
+
const style = utils.getStyle(emotion => injectStyle(utils.themeManager, emotion))
|
|
57
|
+
if (style)
|
|
58
|
+
tooltip.classList.add(style)
|
|
59
|
+
})
|
|
60
|
+
tooltip.classList.add('table-tooltip', 'hide')
|
|
61
|
+
Object.values(items).forEach(({ $ }) => tooltip.appendChild($))
|
|
62
|
+
editorView.dom.parentNode?.appendChild(tooltip)
|
|
63
|
+
|
|
64
|
+
const listener = (e: Event) => {
|
|
65
|
+
if (!editorView)
|
|
66
|
+
return
|
|
67
|
+
e.stopPropagation()
|
|
68
|
+
e.preventDefault()
|
|
69
|
+
Object.values(items).forEach(({ $, command }) => {
|
|
70
|
+
if ($.contains(e.target as Element))
|
|
71
|
+
command(e, editorView)(editorView.state, editorView.dispatch, editorView)
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const hide = () => {
|
|
76
|
+
tooltip.classList.add('hide')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
tooltip.addEventListener('mousedown', listener)
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
update: (view, prevState) => {
|
|
83
|
+
const state = view.state
|
|
84
|
+
|
|
85
|
+
if (prevState?.doc.eq(state.doc) && prevState.selection.eq(state.selection))
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
const isCellSelection = state.selection instanceof CellSelection
|
|
89
|
+
|
|
90
|
+
if (!isCellSelection || !view.editable) {
|
|
91
|
+
hide()
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
calculateItem(items, view)
|
|
96
|
+
if (Object.values(items).every(({ $ }) => $.classList.contains('hide'))) {
|
|
97
|
+
hide()
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
tooltip.classList.remove('hide')
|
|
101
|
+
calculatePosition(view, tooltip)
|
|
42
102
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
utils.themeManager.onFlush(() => {
|
|
47
|
-
const style = utils.getStyle((emotion) => injectStyle(utils.themeManager, emotion));
|
|
48
|
-
if (style) {
|
|
49
|
-
tooltip.classList.add(style);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
tooltip.classList.add('table-tooltip', 'hide');
|
|
53
|
-
Object.values(items).forEach(({ $ }) => tooltip.appendChild($));
|
|
54
|
-
editorView.dom.parentNode?.appendChild(tooltip);
|
|
55
|
-
|
|
56
|
-
const listener = (e: Event) => {
|
|
57
|
-
if (!editorView) return;
|
|
58
|
-
e.stopPropagation();
|
|
59
|
-
e.preventDefault();
|
|
60
|
-
Object.values(items).forEach(({ $, command }) => {
|
|
61
|
-
if ($.contains(e.target as Element)) {
|
|
62
|
-
command(e, editorView)(editorView.state, editorView.dispatch, editorView);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const hide = () => {
|
|
68
|
-
tooltip.classList.add('hide');
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
tooltip.addEventListener('mousedown', listener);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
update: (view, prevState) => {
|
|
75
|
-
const state = view.state;
|
|
76
|
-
|
|
77
|
-
if (prevState?.doc.eq(state.doc) && prevState.selection.eq(state.selection)) return;
|
|
78
|
-
|
|
79
|
-
const isCellSelection = state.selection instanceof CellSelection;
|
|
80
|
-
|
|
81
|
-
if (!isCellSelection || !view.editable) {
|
|
82
|
-
hide();
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
calculateItem(items, view);
|
|
87
|
-
if (Object.values(items).every(({ $ }) => $.classList.contains('hide'))) {
|
|
88
|
-
hide();
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
tooltip.classList.remove('hide');
|
|
92
|
-
calculatePosition(view, tooltip);
|
|
93
|
-
},
|
|
94
|
-
destroy: () => {
|
|
95
|
-
tooltip.removeEventListener('mousedown', listener);
|
|
96
|
-
tooltip.remove();
|
|
97
|
-
},
|
|
98
|
-
};
|
|
103
|
+
destroy: () => {
|
|
104
|
+
tooltip.removeEventListener('mousedown', listener)
|
|
105
|
+
tooltip.remove()
|
|
99
106
|
},
|
|
100
|
-
|
|
101
|
-
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Emotion,
|
|
2
|
+
import type { Emotion, ThemeManager } from '@milkdown/core'
|
|
3
|
+
import { ThemeBorder, ThemeShadow, ThemeSize, getPalette } from '@milkdown/core'
|
|
3
4
|
|
|
4
5
|
export const injectStyle = (themeManager: ThemeManager, { css, injectGlobal }: Emotion) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const palette = getPalette(themeManager)
|
|
7
|
+
const radius = themeManager.get(ThemeSize, 'radius')
|
|
8
|
+
const lineWidth = themeManager.get(ThemeSize, 'lineWidth')
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
injectGlobal`
|
|
10
11
|
.milkdown {
|
|
11
12
|
.tableWrapper {
|
|
12
13
|
table {
|
|
@@ -67,9 +68,9 @@ export const injectStyle = (themeManager: ThemeManager, { css, injectGlobal }: E
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
+
`
|
|
71
72
|
|
|
72
|
-
|
|
73
|
+
return css`
|
|
73
74
|
display: inline-flex;
|
|
74
75
|
cursor: pointer;
|
|
75
76
|
z-index: 2;
|
|
@@ -118,5 +119,5 @@ export const injectStyle = (themeManager: ThemeManager, { css, injectGlobal }: E
|
|
|
118
119
|
.hide {
|
|
119
120
|
display: none;
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
}
|
|
122
|
+
`
|
|
123
|
+
}
|
|
@@ -1,55 +1,57 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import { Ctx
|
|
4
|
-
import {
|
|
3
|
+
import type { Ctx } from '@milkdown/core'
|
|
4
|
+
import { ThemeIcon, themeManagerCtx } from '@milkdown/core'
|
|
5
|
+
import { Decoration } from '@milkdown/prose/view'
|
|
5
6
|
|
|
6
|
-
import { CellPos
|
|
7
|
-
import {
|
|
7
|
+
import type { CellPos } from '../utils'
|
|
8
|
+
import { selectLine, selectTable } from '../utils'
|
|
9
|
+
import { ToolTipPos } from './constant'
|
|
8
10
|
|
|
9
11
|
const calculateClassName = (pos: ToolTipPos) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
case ToolTipPos.Point:
|
|
18
|
-
default: {
|
|
19
|
-
return 'milkdown-cell-point';
|
|
20
|
-
}
|
|
12
|
+
switch (pos) {
|
|
13
|
+
case ToolTipPos.Left: {
|
|
14
|
+
return 'milkdown-cell-left'
|
|
15
|
+
}
|
|
16
|
+
case ToolTipPos.Top: {
|
|
17
|
+
return 'milkdown-cell-top'
|
|
21
18
|
}
|
|
22
|
-
|
|
19
|
+
case ToolTipPos.Point:
|
|
20
|
+
default: {
|
|
21
|
+
return 'milkdown-cell-point'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
23
25
|
|
|
24
|
-
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Point): Decoration
|
|
25
|
-
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Left, index: number): Decoration
|
|
26
|
-
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Top, index: number): Decoration
|
|
26
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Point): Decoration
|
|
27
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Left, index: number): Decoration
|
|
28
|
+
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos.Top, index: number): Decoration
|
|
27
29
|
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos, index = 0) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
return Decoration.widget(cell.pos + 1, (view) => {
|
|
31
|
+
const div = document.createElement('div')
|
|
32
|
+
div.classList.add(calculateClassName(pos))
|
|
33
|
+
if (pos === ToolTipPos.Point)
|
|
34
|
+
div.appendChild(ctx.get(themeManagerCtx).get(ThemeIcon, 'select')?.dom as HTMLElement)
|
|
35
|
+
|
|
36
|
+
div.addEventListener('mousedown', (e) => {
|
|
37
|
+
if (!view)
|
|
38
|
+
return
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
40
|
+
e.preventDefault()
|
|
41
|
+
switch (pos) {
|
|
42
|
+
case ToolTipPos.Point: {
|
|
43
|
+
view.dispatch(selectTable(view.state.tr))
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
case ToolTipPos.Left: {
|
|
47
|
+
view.dispatch(selectLine('row')(index)(view.state.tr))
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
case ToolTipPos.Top: {
|
|
51
|
+
view.dispatch(selectLine('col')(index)(view.state.tr))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
return div
|
|
56
|
+
})
|
|
55
57
|
}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { browser } from '@milkdown/prose'
|
|
3
|
-
import { Node } from '@milkdown/prose/model'
|
|
4
|
-
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
2
|
+
import { browser } from '@milkdown/prose'
|
|
3
|
+
import type { Node } from '@milkdown/prose/model'
|
|
4
|
+
import { Plugin, PluginKey } from '@milkdown/prose/state'
|
|
5
5
|
|
|
6
|
-
import { isInTable } from './util'
|
|
6
|
+
import { isInTable } from './util'
|
|
7
7
|
|
|
8
8
|
const isEmptyParagraph = (node: Node) => {
|
|
9
|
-
|
|
10
|
-
}
|
|
9
|
+
return node.type.name === 'paragraph' && node.nodeSize === 2
|
|
10
|
+
}
|
|
11
11
|
|
|
12
12
|
const isParagraph = (node: Node) => {
|
|
13
|
-
|
|
14
|
-
}
|
|
13
|
+
return node.type.name === 'paragraph'
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
const pluginKey = new PluginKey('plugin_autoInsertZeroSpace')
|
|
16
|
+
const pluginKey = new PluginKey('plugin_autoInsertZeroSpace')
|
|
17
17
|
|
|
18
18
|
export const autoInsertZeroSpace = () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
isInTable(state)
|
|
40
|
-
selection.empty
|
|
41
|
-
isParagraph($from.parent)
|
|
42
|
-
$from.parent.textContent.startsWith('\u2060')
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
},
|
|
19
|
+
return new Plugin({
|
|
20
|
+
key: pluginKey,
|
|
21
|
+
props: {
|
|
22
|
+
handleDOMEvents: {
|
|
23
|
+
compositionstart(view) {
|
|
24
|
+
const { state, dispatch } = view
|
|
25
|
+
const { tr, selection } = state
|
|
26
|
+
const { $from } = selection
|
|
27
|
+
if (browser.safari && isInTable(state) && selection.empty && isEmptyParagraph($from.parent))
|
|
28
|
+
dispatch(tr.insertText('\u2060', $from.start()))
|
|
29
|
+
|
|
30
|
+
return false
|
|
31
|
+
},
|
|
32
|
+
compositionend(view) {
|
|
33
|
+
const { state, dispatch } = view
|
|
34
|
+
const { tr, selection } = state
|
|
35
|
+
const { $from } = selection
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
browser.safari
|
|
39
|
+
&& isInTable(state)
|
|
40
|
+
&& selection.empty
|
|
41
|
+
&& isParagraph($from.parent)
|
|
42
|
+
&& $from.parent.textContent.startsWith('\u2060')
|
|
43
|
+
)
|
|
44
|
+
dispatch(tr.delete($from.start(), $from.start() + 1))
|
|
45
|
+
|
|
46
|
+
return false
|
|
49
47
|
},
|
|
50
|
-
|
|
51
|
-
}
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
}
|