@milkdown/preset-gfm 6.5.4 → 7.0.0-next.1

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 (156) hide show
  1. package/lib/composed/commands.d.ts +8 -0
  2. package/lib/composed/commands.d.ts.map +1 -0
  3. package/lib/composed/index.d.ts +6 -0
  4. package/lib/composed/index.d.ts.map +1 -0
  5. package/lib/composed/inputrules.d.ts +3 -0
  6. package/lib/composed/inputrules.d.ts.map +1 -0
  7. package/lib/composed/keymap.d.ts +3 -0
  8. package/lib/composed/keymap.d.ts.map +1 -0
  9. package/lib/composed/plugins.d.ts +3 -0
  10. package/lib/composed/plugins.d.ts.map +1 -0
  11. package/lib/composed/schema.d.ts +3 -0
  12. package/lib/composed/schema.d.ts.map +1 -0
  13. package/lib/index.d.ts +4 -34
  14. package/lib/index.d.ts.map +1 -1
  15. package/lib/index.es.js +634 -2328
  16. package/lib/index.es.js.map +1 -1
  17. package/lib/mark/index.d.ts +2 -0
  18. package/lib/mark/index.d.ts.map +1 -0
  19. package/lib/mark/strike-through.d.ts +5 -0
  20. package/lib/mark/strike-through.d.ts.map +1 -0
  21. package/lib/node/footnote/definition.d.ts +2 -0
  22. package/lib/node/footnote/definition.d.ts.map +1 -0
  23. package/lib/{footnote → node/footnote}/index.d.ts +0 -0
  24. package/lib/node/footnote/index.d.ts.map +1 -0
  25. package/lib/node/footnote/reference.d.ts +2 -0
  26. package/lib/node/footnote/reference.d.ts.map +1 -0
  27. package/lib/node/index.d.ts +4 -0
  28. package/lib/node/index.d.ts.map +1 -0
  29. package/lib/node/table/index.d.ts +32 -0
  30. package/lib/node/table/index.d.ts.map +1 -0
  31. package/lib/node/table/utils.d.ts +26 -0
  32. package/lib/node/table/utils.d.ts.map +1 -0
  33. package/lib/node/task-list-item.d.ts +2 -0
  34. package/lib/node/task-list-item.d.ts.map +1 -0
  35. package/lib/plugin/auto-insert-zero-space-plugin.d.ts +2 -0
  36. package/lib/plugin/auto-insert-zero-space-plugin.d.ts.map +1 -0
  37. package/lib/plugin/column-resizing-plugin.d.ts +2 -0
  38. package/lib/plugin/column-resizing-plugin.d.ts.map +1 -0
  39. package/lib/plugin/index.d.ts +5 -0
  40. package/lib/plugin/index.d.ts.map +1 -0
  41. package/lib/plugin/remark-gfm-plugin.d.ts +2 -0
  42. package/lib/plugin/remark-gfm-plugin.d.ts.map +1 -0
  43. package/lib/plugin/table-editing-plugin.d.ts +2 -0
  44. package/lib/plugin/table-editing-plugin.d.ts.map +1 -0
  45. package/package.json +13 -10
  46. package/src/composed/commands.ts +24 -0
  47. package/src/composed/index.ts +6 -0
  48. package/src/composed/inputrules.ts +8 -0
  49. package/src/composed/keymap.ts +10 -0
  50. package/src/composed/plugins.ts +11 -0
  51. package/src/composed/schema.ts +20 -0
  52. package/src/index.ts +6 -89
  53. package/src/mark/index.ts +2 -0
  54. package/src/mark/strike-through.ts +46 -0
  55. package/src/node/footnote/definition.ts +70 -0
  56. package/src/{footnote → node/footnote}/index.ts +0 -0
  57. package/src/node/footnote/reference.ts +60 -0
  58. package/src/node/index.ts +4 -0
  59. package/src/node/table/index.ts +318 -0
  60. package/src/node/table/utils.ts +509 -0
  61. package/src/node/task-list-item.ts +88 -0
  62. package/src/{table/plugin/auto-insert-zero-space.ts → plugin/auto-insert-zero-space-plugin.ts} +14 -15
  63. package/src/plugin/column-resizing-plugin.ts +6 -0
  64. package/src/plugin/index.ts +5 -0
  65. package/src/plugin/remark-gfm-plugin.ts +6 -0
  66. package/src/plugin/table-editing-plugin.ts +6 -0
  67. package/lib/footnote/definition.d.ts +0 -3
  68. package/lib/footnote/definition.d.ts.map +0 -1
  69. package/lib/footnote/index.d.ts.map +0 -1
  70. package/lib/footnote/reference.d.ts +0 -3
  71. package/lib/footnote/reference.d.ts.map +0 -1
  72. package/lib/footnote/utils.d.ts +0 -3
  73. package/lib/footnote/utils.d.ts.map +0 -1
  74. package/lib/strike-through.d.ts +0 -3
  75. package/lib/strike-through.d.ts.map +0 -1
  76. package/lib/supported-keys.d.ts +0 -28
  77. package/lib/supported-keys.d.ts.map +0 -1
  78. package/lib/table/command.d.ts +0 -4
  79. package/lib/table/command.d.ts.map +0 -1
  80. package/lib/table/index.d.ts +0 -10
  81. package/lib/table/index.d.ts.map +0 -1
  82. package/lib/table/nodes/index.d.ts +0 -12
  83. package/lib/table/nodes/index.d.ts.map +0 -1
  84. package/lib/table/operator-plugin/actions.d.ts +0 -20
  85. package/lib/table/operator-plugin/actions.d.ts.map +0 -1
  86. package/lib/table/operator-plugin/calc-pos.d.ts +0 -3
  87. package/lib/table/operator-plugin/calc-pos.d.ts.map +0 -1
  88. package/lib/table/operator-plugin/constant.d.ts +0 -6
  89. package/lib/table/operator-plugin/constant.d.ts.map +0 -1
  90. package/lib/table/operator-plugin/helper.d.ts +0 -7
  91. package/lib/table/operator-plugin/helper.d.ts.map +0 -1
  92. package/lib/table/operator-plugin/index.d.ts +0 -6
  93. package/lib/table/operator-plugin/index.d.ts.map +0 -1
  94. package/lib/table/operator-plugin/style.d.ts +0 -3
  95. package/lib/table/operator-plugin/style.d.ts.map +0 -1
  96. package/lib/table/operator-plugin/widget.d.ts +0 -8
  97. package/lib/table/operator-plugin/widget.d.ts.map +0 -1
  98. package/lib/table/plugin/auto-insert-zero-space.d.ts +0 -3
  99. package/lib/table/plugin/auto-insert-zero-space.d.ts.map +0 -1
  100. package/lib/table/plugin/cell-selection.d.ts +0 -40
  101. package/lib/table/plugin/cell-selection.d.ts.map +0 -1
  102. package/lib/table/plugin/column-resizing.d.ts +0 -18
  103. package/lib/table/plugin/column-resizing.d.ts.map +0 -1
  104. package/lib/table/plugin/commands.d.ts +0 -30
  105. package/lib/table/plugin/commands.d.ts.map +0 -1
  106. package/lib/table/plugin/copy-paste.d.ts +0 -14
  107. package/lib/table/plugin/copy-paste.d.ts.map +0 -1
  108. package/lib/table/plugin/fix-tables.d.ts +0 -7
  109. package/lib/table/plugin/fix-tables.d.ts.map +0 -1
  110. package/lib/table/plugin/index.d.ts +0 -4
  111. package/lib/table/plugin/index.d.ts.map +0 -1
  112. package/lib/table/plugin/schema.d.ts +0 -4
  113. package/lib/table/plugin/schema.d.ts.map +0 -1
  114. package/lib/table/plugin/table-editing.d.ts +0 -9
  115. package/lib/table/plugin/table-editing.d.ts.map +0 -1
  116. package/lib/table/plugin/table-map.d.ts +0 -44
  117. package/lib/table/plugin/table-map.d.ts.map +0 -1
  118. package/lib/table/plugin/table-view.d.ts +0 -15
  119. package/lib/table/plugin/table-view.d.ts.map +0 -1
  120. package/lib/table/plugin/types.d.ts +0 -15
  121. package/lib/table/plugin/types.d.ts.map +0 -1
  122. package/lib/table/plugin/util.d.ts +0 -16
  123. package/lib/table/plugin/util.d.ts.map +0 -1
  124. package/lib/table/utils.d.ts +0 -21
  125. package/lib/table/utils.d.ts.map +0 -1
  126. package/lib/task-list-item.d.ts +0 -9
  127. package/lib/task-list-item.d.ts.map +0 -1
  128. package/src/footnote/definition.ts +0 -187
  129. package/src/footnote/reference.ts +0 -178
  130. package/src/footnote/utils.ts +0 -4
  131. package/src/strike-through.ts +0 -43
  132. package/src/supported-keys.ts +0 -13
  133. package/src/table/command.ts +0 -20
  134. package/src/table/index.ts +0 -13
  135. package/src/table/nodes/index.ts +0 -189
  136. package/src/table/operator-plugin/actions.ts +0 -116
  137. package/src/table/operator-plugin/calc-pos.ts +0 -36
  138. package/src/table/operator-plugin/constant.ts +0 -7
  139. package/src/table/operator-plugin/helper.ts +0 -39
  140. package/src/table/operator-plugin/index.ts +0 -110
  141. package/src/table/operator-plugin/style.ts +0 -123
  142. package/src/table/operator-plugin/widget.ts +0 -57
  143. package/src/table/plugin/cell-selection.ts +0 -381
  144. package/src/table/plugin/column-resizing.ts +0 -288
  145. package/src/table/plugin/commands.ts +0 -594
  146. package/src/table/plugin/copy-paste.ts +0 -322
  147. package/src/table/plugin/fix-tables.ts +0 -132
  148. package/src/table/plugin/index.ts +0 -4
  149. package/src/table/plugin/schema.ts +0 -120
  150. package/src/table/plugin/table-editing.ts +0 -369
  151. package/src/table/plugin/table-map.ts +0 -345
  152. package/src/table/plugin/table-view.ts +0 -80
  153. package/src/table/plugin/types.ts +0 -16
  154. package/src/table/plugin/util.ts +0 -119
  155. package/src/table/utils.ts +0 -165
  156. package/src/task-list-item.ts +0 -159
@@ -1,116 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { Ctx } from '@milkdown/core'
3
- import { ThemeIcon, themeManagerCtx } from '@milkdown/core'
4
- import type { Command } from '@milkdown/prose/state'
5
- import type { EditorView } from '@milkdown/prose/view'
6
-
7
- import {
8
- addColumnAfter,
9
- addColumnBefore,
10
- deleteColumn,
11
- deleteRow,
12
- deleteTable,
13
- isInTable,
14
- selectedRect,
15
- setCellAttr,
16
- } from '../plugin'
17
- import { addRowWithAlignment } from '../utils'
18
- import { getCellSelection, isFirstRowSelected } from './helper'
19
-
20
- export interface Item {
21
- $: HTMLElement
22
- command: (e: Event, view: EditorView) => Command
23
- disable?: (view: EditorView) => boolean
24
- }
25
-
26
- export enum Action {
27
- AddColLeft,
28
- AddColRight,
29
- AddRowTop,
30
- AddRowBottom,
31
- AlignLeft,
32
- AlignCenter,
33
- AlignRight,
34
- Delete,
35
- }
36
-
37
- export const createActions: (ctx: Ctx) => Record<Action, Item> = ctx => ({
38
- [Action.AddColLeft]: {
39
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'leftArrow')?.dom as HTMLElement,
40
- command: () => addColumnBefore,
41
- disable: view => !getCellSelection(view).isColSelection(),
42
- },
43
- [Action.AddColRight]: {
44
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'rightArrow')?.dom as HTMLElement,
45
- command: () => addColumnAfter,
46
- disable: view => !getCellSelection(view).isColSelection(),
47
- },
48
- [Action.AddRowTop]: {
49
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'upArrow')?.dom as HTMLElement,
50
- command: () => (state, dispatch) => {
51
- if (!isInTable(state))
52
- return false
53
- if (dispatch) {
54
- const rect = selectedRect(state)
55
- dispatch(addRowWithAlignment(state.tr, rect, rect.top))
56
- }
57
- return true
58
- },
59
- disable: view =>
60
- !getCellSelection(view).isRowSelection()
61
- || getCellSelection(view).$head.parent.type.name === 'table_header',
62
- },
63
- [Action.AddRowBottom]: {
64
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'downArrow')?.dom as HTMLElement,
65
- command: () => (state, dispatch) => {
66
- if (!isInTable(state))
67
- return false
68
- if (dispatch) {
69
- const rect = selectedRect(state)
70
- dispatch(addRowWithAlignment(state.tr, rect, rect.bottom))
71
- }
72
- return true
73
- },
74
- disable: view => !getCellSelection(view).isRowSelection(),
75
- },
76
- [Action.AlignLeft]: {
77
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignLeft')?.dom as HTMLElement,
78
- command: () => setCellAttr('alignment', 'left'),
79
- disable: view => !getCellSelection(view).isColSelection(),
80
- },
81
- [Action.AlignCenter]: {
82
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignCenter')?.dom as HTMLElement,
83
- command: () => setCellAttr('alignment', 'center'),
84
- disable: view => !getCellSelection(view).isColSelection(),
85
- },
86
- [Action.AlignRight]: {
87
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignRight')?.dom as HTMLElement,
88
- command: () => setCellAttr('alignment', 'right'),
89
- disable: view => !getCellSelection(view).isColSelection(),
90
- },
91
- [Action.Delete]: {
92
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'delete')?.dom as HTMLElement,
93
- command: (_, view) => {
94
- const selection = getCellSelection(view)
95
- const isCol = selection.isColSelection()
96
- const isRow = selection.isRowSelection()
97
- if (isCol && isRow)
98
- return deleteTable
99
-
100
- if (isCol)
101
- return deleteColumn
102
-
103
- return deleteRow
104
- },
105
- disable: (view) => {
106
- const selection = getCellSelection(view)
107
- if (selection.isRowSelection()) {
108
- if (selection.isColSelection())
109
- return false
110
-
111
- return isFirstRowSelected(selection)
112
- }
113
- return false
114
- },
115
- },
116
- })
@@ -1,36 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
-
3
- import { missingRootElement } from '@milkdown/exception'
4
- import { calculateNodePosition } from '@milkdown/prose'
5
- import type { EditorView } from '@milkdown/prose/view'
6
-
7
- import type { CellSelection } from '../plugin'
8
-
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
- 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 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
-
3
- export enum ToolTipPos {
4
- Left = 'Left',
5
- Top = 'Top',
6
- Point = 'Point',
7
- }
@@ -1,39 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { EditorView } from '@milkdown/prose/view'
3
-
4
- import type { CellSelection } from '../plugin'
5
- import { TableMap } from '../plugin/table-map'
6
- import type { Item } from './actions'
7
-
8
- export const getCellSelection = (view: EditorView): CellSelection => view.state.selection as unknown as CellSelection
9
-
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
- )
22
-
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
- }
29
-
30
- export const calculateItem = (actions: Record<string, Item>, view: EditorView) => {
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,110 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
-
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'
21
-
22
- export const operatorPlugin = (ctx: Ctx, utils: ThemeUtils) => {
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)
102
- },
103
- destroy: () => {
104
- tooltip.removeEventListener('mousedown', listener)
105
- tooltip.remove()
106
- },
107
- }
108
- },
109
- })
110
- }
@@ -1,123 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { Emotion, ThemeManager } from '@milkdown/core'
3
- import { ThemeBorder, ThemeShadow, ThemeSize, getPalette } from '@milkdown/core'
4
-
5
- export const injectStyle = (themeManager: ThemeManager, { css, injectGlobal }: Emotion) => {
6
- const palette = getPalette(themeManager)
7
- const radius = themeManager.get(ThemeSize, 'radius')
8
- const lineWidth = themeManager.get(ThemeSize, 'lineWidth')
9
-
10
- injectGlobal`
11
- .milkdown {
12
- .tableWrapper {
13
- table {
14
- width: calc(100% - 32px) !important;
15
- margin: 16px 0 16px 16px !important;
16
-
17
- .milkdown-cell-left,
18
- .milkdown-cell-point,
19
- .milkdown-cell-top {
20
- position: absolute;
21
-
22
- &::after {
23
- cursor: pointer;
24
- position: absolute;
25
- top: 0;
26
- left: 0;
27
- height: 100%;
28
- width: 100%;
29
- display: block;
30
- transition: all 0.2s ease-in-out;
31
- background: ${palette('secondary', 0.12)};
32
- content: '';
33
- }
34
-
35
- &:hover::after {
36
- background: ${palette('secondary', 0.38)};
37
- }
38
- }
39
-
40
- .milkdown-cell-left {
41
- left: -14px;
42
- top: 0;
43
- bottom: 0;
44
- width: 8px;
45
- }
46
-
47
- .milkdown-cell-top {
48
- left: 0;
49
- right: 0;
50
- top: -14px;
51
- height: 8px;
52
- }
53
-
54
- .milkdown-cell-point {
55
- left: -18px;
56
- top: -18px;
57
- width: 16px;
58
- height: 16px;
59
-
60
- .icon {
61
- position: absolute;
62
- top: 0;
63
- bottom: 0;
64
- left: 0;
65
- right: 0;
66
- }
67
- }
68
- }
69
- }
70
- }
71
- `
72
-
73
- return css`
74
- display: inline-flex;
75
- cursor: pointer;
76
- z-index: 2;
77
-
78
- justify-content: space-evenly;
79
-
80
- position: absolute;
81
-
82
- border-radius: ${radius};
83
-
84
- ${themeManager.get(ThemeBorder, undefined)};
85
- ${themeManager.get(ThemeShadow, undefined)};
86
-
87
- overflow: hidden;
88
- background: ${palette('surface')};
89
-
90
- .icon {
91
- position: relative;
92
- color: ${palette('solid', 0.87)};
93
-
94
- width: 48px;
95
- line-height: 48px;
96
- text-align: center;
97
- transition: all 0.4s ease-in-out;
98
-
99
- &:hover {
100
- background-color: ${palette('secondary', 0.12)};
101
- }
102
-
103
- &.active {
104
- color: ${palette('primary')};
105
- }
106
-
107
- &:not(:last-child)::after {
108
- content: '';
109
- position: absolute;
110
- right: 0;
111
- top: 0;
112
- width: ${lineWidth};
113
- bottom: 0;
114
- background: ${palette('line')};
115
- }
116
- }
117
-
118
- &.hide,
119
- .hide {
120
- display: none;
121
- }
122
- `
123
- }
@@ -1,57 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
-
3
- import type { Ctx } from '@milkdown/core'
4
- import { ThemeIcon, themeManagerCtx } from '@milkdown/core'
5
- import { Decoration } from '@milkdown/prose/view'
6
-
7
- import type { CellPos } from '../utils'
8
- import { selectLine, selectTable } from '../utils'
9
- import { ToolTipPos } from './constant'
10
-
11
- const calculateClassName = (pos: ToolTipPos) => {
12
- switch (pos) {
13
- case ToolTipPos.Left: {
14
- return 'milkdown-cell-left'
15
- }
16
- case ToolTipPos.Top: {
17
- return 'milkdown-cell-top'
18
- }
19
- case ToolTipPos.Point:
20
- default: {
21
- return 'milkdown-cell-point'
22
- }
23
- }
24
- }
25
-
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
29
- export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos, index = 0) {
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
39
-
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
- })
57
- }