@milkdown/preset-gfm 6.5.0 → 6.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/lib/footnote/definition.d.ts +1 -1
  2. package/lib/footnote/definition.d.ts.map +1 -1
  3. package/lib/footnote/index.d.ts.map +1 -1
  4. package/lib/footnote/reference.d.ts +1 -1
  5. package/lib/footnote/reference.d.ts.map +1 -1
  6. package/lib/footnote/utils.d.ts.map +1 -1
  7. package/lib/index.d.ts +1 -1
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.es.js +1007 -863
  10. package/lib/index.es.js.map +1 -1
  11. package/lib/strike-through.d.ts +1 -1
  12. package/lib/strike-through.d.ts.map +1 -1
  13. package/lib/supported-keys.d.ts +1 -1
  14. package/lib/supported-keys.d.ts.map +1 -1
  15. package/lib/table/command.d.ts +2 -2
  16. package/lib/table/command.d.ts.map +1 -1
  17. package/lib/table/index.d.ts +1 -1
  18. package/lib/table/index.d.ts.map +1 -1
  19. package/lib/table/nodes/index.d.ts +1 -1
  20. package/lib/table/nodes/index.d.ts.map +1 -1
  21. package/lib/table/operator-plugin/actions.d.ts +5 -5
  22. package/lib/table/operator-plugin/actions.d.ts.map +1 -1
  23. package/lib/table/operator-plugin/calc-pos.d.ts +1 -1
  24. package/lib/table/operator-plugin/calc-pos.d.ts.map +1 -1
  25. package/lib/table/operator-plugin/constant.d.ts.map +1 -1
  26. package/lib/table/operator-plugin/helper.d.ts +3 -3
  27. package/lib/table/operator-plugin/helper.d.ts.map +1 -1
  28. package/lib/table/operator-plugin/index.d.ts +2 -2
  29. package/lib/table/operator-plugin/index.d.ts.map +1 -1
  30. package/lib/table/operator-plugin/style.d.ts +1 -1
  31. package/lib/table/operator-plugin/style.d.ts.map +1 -1
  32. package/lib/table/operator-plugin/widget.d.ts +2 -2
  33. package/lib/table/operator-plugin/widget.d.ts.map +1 -1
  34. package/lib/table/plugin/auto-insert-zero-space.d.ts.map +1 -1
  35. package/lib/table/plugin/cell-selection.d.ts +5 -3
  36. package/lib/table/plugin/cell-selection.d.ts.map +1 -1
  37. package/lib/table/plugin/column-resizing.d.ts +2 -1
  38. package/lib/table/plugin/column-resizing.d.ts.map +1 -1
  39. package/lib/table/plugin/commands.d.ts +2 -2
  40. package/lib/table/plugin/commands.d.ts.map +1 -1
  41. package/lib/table/plugin/copy-paste.d.ts +6 -5
  42. package/lib/table/plugin/copy-paste.d.ts.map +1 -1
  43. package/lib/table/plugin/fix-tables.d.ts +3 -2
  44. package/lib/table/plugin/fix-tables.d.ts.map +1 -1
  45. package/lib/table/plugin/index.d.ts.map +1 -1
  46. package/lib/table/plugin/schema.d.ts +1 -1
  47. package/lib/table/plugin/schema.d.ts.map +1 -1
  48. package/lib/table/plugin/table-editing.d.ts +1 -1
  49. package/lib/table/plugin/table-editing.d.ts.map +1 -1
  50. package/lib/table/plugin/table-map.d.ts +2 -2
  51. package/lib/table/plugin/table-map.d.ts.map +1 -1
  52. package/lib/table/plugin/table-view.d.ts +2 -2
  53. package/lib/table/plugin/table-view.d.ts.map +1 -1
  54. package/lib/table/plugin/types.d.ts +2 -2
  55. package/lib/table/plugin/types.d.ts.map +1 -1
  56. package/lib/table/plugin/util.d.ts +2 -2
  57. package/lib/table/plugin/util.d.ts.map +1 -1
  58. package/lib/table/utils.d.ts +5 -5
  59. package/lib/table/utils.d.ts.map +1 -1
  60. package/lib/task-list-item.d.ts +2 -2
  61. package/lib/task-list-item.d.ts.map +1 -1
  62. package/package.json +17 -17
  63. package/src/footnote/definition.ts +172 -166
  64. package/src/footnote/index.ts +2 -2
  65. package/src/footnote/reference.ts +166 -162
  66. package/src/footnote/utils.ts +2 -2
  67. package/src/index.ts +83 -83
  68. package/src/strike-through.ts +36 -36
  69. package/src/supported-keys.ts +9 -8
  70. package/src/table/command.ts +17 -16
  71. package/src/table/index.ts +9 -9
  72. package/src/table/nodes/index.ts +177 -174
  73. package/src/table/operator-plugin/actions.ts +103 -102
  74. package/src/table/operator-plugin/calc-pos.ts +31 -24
  75. package/src/table/operator-plugin/constant.ts +3 -3
  76. package/src/table/operator-plugin/helper.ts +31 -32
  77. package/src/table/operator-plugin/index.ts +104 -95
  78. package/src/table/operator-plugin/style.ts +10 -9
  79. package/src/table/operator-plugin/widget.ts +47 -45
  80. package/src/table/plugin/auto-insert-zero-space.ts +41 -41
  81. package/src/table/plugin/cell-selection.ts +325 -296
  82. package/src/table/plugin/column-resizing.ts +226 -198
  83. package/src/table/plugin/commands.ts +464 -421
  84. package/src/table/plugin/copy-paste.ts +256 -240
  85. package/src/table/plugin/fix-tables.ts +103 -88
  86. package/src/table/plugin/index.ts +3 -3
  87. package/src/table/plugin/schema.ts +100 -94
  88. package/src/table/plugin/table-editing.ts +324 -230
  89. package/src/table/plugin/table-map.ts +294 -229
  90. package/src/table/plugin/table-view.ts +66 -62
  91. package/src/table/plugin/types.ts +8 -8
  92. package/src/table/plugin/util.ts +78 -66
  93. package/src/table/utils.ts +141 -138
  94. package/src/task-list-item.ts +151 -146
@@ -1,29 +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
- 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
- const top = selected.top - parent.top - target.height - (isCol ? 14 : 0) - 14 + $editor.scrollTop;
23
-
24
- if (left < 0) {
25
- left = 0;
26
- }
27
- return [top, left];
28
- });
29
- };
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,7 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
 
3
3
  export enum ToolTipPos {
4
- Left = 'Left',
5
- Top = 'Top',
6
- Point = 'Point',
4
+ Left = 'Left',
5
+ Top = 'Top',
6
+ Point = 'Point',
7
7
  }
@@ -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
- 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
- );
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
- for (let i = 0, count = cells.length; i < count; i++) {
24
- if (selectedCells.indexOf(cells[i] as number) === -1) {
25
- return false;
26
- }
27
- }
28
- return true;
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
- Object.values(actions).forEach((item) => {
33
- const disable = item.disable?.(view);
34
- if (disable) {
35
- item.$.classList.add('hide');
36
- return;
37
- }
38
- item.$.classList.remove('hide');
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 { Plugin, PluginKey } from '@milkdown/prose/state';
5
- import { Decoration, DecorationSet } from '@milkdown/prose/view';
6
- import { ThemeUtils } from '@milkdown/utils';
7
-
8
- import { CellSelection } from '../plugin';
9
- import { CellPos, getCellsInColumn, getCellsInRow } from '../utils';
10
- import { createActions } from './actions';
11
- import { calculatePosition } from './calc-pos';
12
- import { ToolTipPos } from './constant';
13
- import { calculateItem } from './helper';
14
- import { injectStyle } from './style';
15
- import { createWidget } from './widget';
16
-
17
- export const key = 'MILKDOWN_TABLE';
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
- return new Plugin({
21
- key: new PluginKey('MILKDOWN_TABLE_OP'),
22
- props: {
23
- decorations: (state) => {
24
- const decorations: Decoration[] = [];
25
- const leftCells = getCellsInColumn(0)(state.selection);
26
- if (!leftCells) return null;
27
- const topCells = getCellsInRow(0)(state.selection);
28
- if (!topCells) return null;
29
-
30
- const [topLeft] = leftCells;
31
-
32
- decorations.push(createWidget(ctx, topLeft as CellPos, ToolTipPos.Point));
33
- leftCells.forEach((cell, i) => {
34
- decorations.push(createWidget(ctx, cell, ToolTipPos.Left, i));
35
- });
36
- topCells.forEach((cell, i) => {
37
- decorations.push(createWidget(ctx, cell, ToolTipPos.Top, i));
38
- });
39
-
40
- return DecorationSet.create(state.doc, decorations);
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
- view: (editorView) => {
44
- const items = Object.fromEntries(Object.entries(createActions(ctx)).filter(([, value]) => value.$ != null));
45
- const tooltip = document.createElement('div');
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, getPalette, ThemeBorder, ThemeManager, ThemeShadow, ThemeSize } from '@milkdown/core';
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
- const palette = getPalette(themeManager);
6
- const radius = themeManager.get(ThemeSize, 'radius');
7
- const lineWidth = themeManager.get(ThemeSize, 'lineWidth');
6
+ const palette = getPalette(themeManager)
7
+ const radius = themeManager.get(ThemeSize, 'radius')
8
+ const lineWidth = themeManager.get(ThemeSize, 'lineWidth')
8
9
 
9
- injectGlobal`
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
- return css`
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, ThemeIcon, themeManagerCtx } from '@milkdown/core';
4
- import { Decoration } from '@milkdown/prose/view';
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, selectLine, selectTable } from '../utils';
7
- import { ToolTipPos } from './constant';
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
- switch (pos) {
11
- case ToolTipPos.Left: {
12
- return 'milkdown-cell-left';
13
- }
14
- case ToolTipPos.Top: {
15
- return 'milkdown-cell-top';
16
- }
17
- case ToolTipPos.Point:
18
- default: {
19
- return 'milkdown-cell-point';
20
- }
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
- return Decoration.widget(cell.pos + 1, (view) => {
29
- const div = document.createElement('div');
30
- div.classList.add(calculateClassName(pos));
31
- if (pos === ToolTipPos.Point) {
32
- div.appendChild(ctx.get(themeManagerCtx).get(ThemeIcon, 'select')?.dom as HTMLElement);
33
- }
34
- div.addEventListener('mousedown', (e) => {
35
- if (!view) return;
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
- e.preventDefault();
38
- switch (pos) {
39
- case ToolTipPos.Point: {
40
- view.dispatch(selectTable(view.state.tr));
41
- return;
42
- }
43
- case ToolTipPos.Left: {
44
- view.dispatch(selectLine('row')(index)(view.state.tr));
45
- return;
46
- }
47
- case ToolTipPos.Top: {
48
- view.dispatch(selectLine('col')(index)(view.state.tr));
49
- return;
50
- }
51
- }
52
- });
53
- return div;
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
- return node.type.name === 'paragraph' && node.nodeSize === 2;
10
- };
9
+ return node.type.name === 'paragraph' && node.nodeSize === 2
10
+ }
11
11
 
12
12
  const isParagraph = (node: Node) => {
13
- return node.type.name === 'paragraph';
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
- 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;
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
+ }