@milkdown/preset-gfm 5.4.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 +283 -448
- 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 +7 -6
- 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/auto-link.ts +1 -1
- package/src/strike-through.ts +3 -10
- package/src/table/nodes/index.ts +24 -18
- package/src/table/operator-plugin/actions.ts +9 -9
- package/src/table/operator-plugin/helper.ts +1 -1
- package/src/table/operator-plugin/index.ts +8 -6
- package/src/table/operator-plugin/style.ts +109 -37
- package/src/table/operator-plugin/widget.ts +3 -4
- package/src/table/utils.ts +9 -6
- package/src/task-list-item.ts +69 -134
- 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/src/table/nodes/index.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
import { createCmd, createCmdKey, MarkdownNode, schemaCtx } from '@milkdown/core';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
columnResizing,
|
|
5
|
+
goToNextCell,
|
|
6
|
+
InputRule,
|
|
7
|
+
NodeType,
|
|
8
|
+
Selection,
|
|
9
|
+
tableEditing,
|
|
10
|
+
TextSelection,
|
|
11
|
+
} from '@milkdown/prose';
|
|
4
12
|
import { createPlugin, createShortcut } from '@milkdown/utils';
|
|
5
13
|
|
|
6
14
|
import { exitTable } from '../command';
|
|
7
15
|
import { operatorPlugin } from '../operator-plugin';
|
|
8
16
|
import { createTable } from '../utils';
|
|
9
17
|
import { schema } from './schema';
|
|
10
|
-
import { injectStyle } from './style';
|
|
11
18
|
|
|
12
19
|
export const SupportedKeys = {
|
|
13
20
|
NextCell: 'NextCell',
|
|
@@ -18,13 +25,12 @@ export type SupportedKeys = typeof SupportedKeys;
|
|
|
18
25
|
|
|
19
26
|
type Keys = keyof SupportedKeys;
|
|
20
27
|
|
|
21
|
-
export const PrevCell = createCmdKey();
|
|
22
|
-
export const NextCell = createCmdKey();
|
|
23
|
-
export const BreakTable = createCmdKey();
|
|
24
|
-
export const InsertTable = createCmdKey();
|
|
28
|
+
export const PrevCell = createCmdKey('PrevCell');
|
|
29
|
+
export const NextCell = createCmdKey('NextCell');
|
|
30
|
+
export const BreakTable = createCmdKey('BreakTable');
|
|
31
|
+
export const InsertTable = createCmdKey('InsertTable');
|
|
25
32
|
|
|
26
33
|
export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof schema>((utils) => {
|
|
27
|
-
injectStyle(utils);
|
|
28
34
|
return {
|
|
29
35
|
schema: () => ({
|
|
30
36
|
node: {
|
|
@@ -33,7 +39,7 @@ export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof sc
|
|
|
33
39
|
parseMarkdown: {
|
|
34
40
|
match: (node) => node.type === 'table',
|
|
35
41
|
runner: (state, node, type) => {
|
|
36
|
-
const align = node
|
|
42
|
+
const align = node['align'] as (string | null)[];
|
|
37
43
|
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
38
44
|
...x,
|
|
39
45
|
align,
|
|
@@ -52,7 +58,7 @@ export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof sc
|
|
|
52
58
|
|
|
53
59
|
const align: (string | null)[] = [];
|
|
54
60
|
firstLine.forEach((cell) => {
|
|
55
|
-
align.push(cell.attrs
|
|
61
|
+
align.push(cell.attrs['alignment']);
|
|
56
62
|
});
|
|
57
63
|
state.openNode('table', undefined, { align });
|
|
58
64
|
state.next(node.content);
|
|
@@ -65,11 +71,11 @@ export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof sc
|
|
|
65
71
|
parseMarkdown: {
|
|
66
72
|
match: (node) => node.type === 'tableRow',
|
|
67
73
|
runner: (state, node, type) => {
|
|
68
|
-
const align = node
|
|
74
|
+
const align = node['align'] as (string | null)[];
|
|
69
75
|
const children = (node.children as MarkdownNode[]).map((x, i) => ({
|
|
70
76
|
...x,
|
|
71
77
|
align: align[i],
|
|
72
|
-
isHeader: node
|
|
78
|
+
isHeader: node['isHeader'],
|
|
73
79
|
}));
|
|
74
80
|
state.openNode(type);
|
|
75
81
|
state.next(children);
|
|
@@ -88,12 +94,12 @@ export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof sc
|
|
|
88
94
|
table_cell: {
|
|
89
95
|
...schema.table_cell,
|
|
90
96
|
parseMarkdown: {
|
|
91
|
-
match: (node) => node.type === 'tableCell' && !node
|
|
97
|
+
match: (node) => node.type === 'tableCell' && !node['isHeader'],
|
|
92
98
|
runner: (state, node, type) => {
|
|
93
|
-
const align = node
|
|
99
|
+
const align = node['align'] as string;
|
|
94
100
|
state
|
|
95
101
|
.openNode(type, { alignment: align })
|
|
96
|
-
.openNode(state.schema.nodes
|
|
102
|
+
.openNode(state.schema.nodes['paragraph'] as NodeType)
|
|
97
103
|
.next(node.children)
|
|
98
104
|
.closeNode()
|
|
99
105
|
.closeNode();
|
|
@@ -109,11 +115,11 @@ export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof sc
|
|
|
109
115
|
table_header: {
|
|
110
116
|
...schema.table_header,
|
|
111
117
|
parseMarkdown: {
|
|
112
|
-
match: (node) => node.type === 'tableCell' && !!node
|
|
118
|
+
match: (node) => node.type === 'tableCell' && !!node['isHeader'],
|
|
113
119
|
runner: (state, node, type) => {
|
|
114
|
-
const align = node
|
|
120
|
+
const align = node['align'] as string;
|
|
115
121
|
state.openNode(type, { alignment: align });
|
|
116
|
-
state.openNode(state.schema.nodes
|
|
122
|
+
state.openNode(state.schema.nodes['paragraph'] as NodeType);
|
|
117
123
|
state.next(node.children);
|
|
118
124
|
state.closeNode();
|
|
119
125
|
state.closeNode();
|
|
@@ -144,7 +150,7 @@ export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof sc
|
|
|
144
150
|
commands: (_, ctx) => [
|
|
145
151
|
createCmd(PrevCell, () => goToNextCell(-1)),
|
|
146
152
|
createCmd(NextCell, () => goToNextCell(1)),
|
|
147
|
-
createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes
|
|
153
|
+
createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes['paragraph'] as NodeType)),
|
|
148
154
|
createCmd(InsertTable, () => (state, dispatch) => {
|
|
149
155
|
const { selection, tr } = state;
|
|
150
156
|
const { from } = selection;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Ctx,
|
|
2
|
+
import { Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
|
|
3
3
|
import {
|
|
4
4
|
addColumnAfter,
|
|
5
5
|
addColumnBefore,
|
|
@@ -35,17 +35,17 @@ export enum Action {
|
|
|
35
35
|
|
|
36
36
|
export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
|
|
37
37
|
[Action.AddColLeft]: {
|
|
38
|
-
$: ctx.get(
|
|
38
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'leftArrow')?.dom as HTMLElement,
|
|
39
39
|
command: () => addColumnBefore,
|
|
40
40
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
41
41
|
},
|
|
42
42
|
[Action.AddColRight]: {
|
|
43
|
-
$: ctx.get(
|
|
43
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'rightArrow')?.dom as HTMLElement,
|
|
44
44
|
command: () => addColumnAfter,
|
|
45
45
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
46
46
|
},
|
|
47
47
|
[Action.AddRowTop]: {
|
|
48
|
-
$: ctx.get(
|
|
48
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'upArrow')?.dom as HTMLElement,
|
|
49
49
|
command: () => (state, dispatch) => {
|
|
50
50
|
if (!isInTable(state)) return false;
|
|
51
51
|
if (dispatch) {
|
|
@@ -59,7 +59,7 @@ export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
|
|
|
59
59
|
getCellSelection(view).$head.parent.type.name === 'table_header',
|
|
60
60
|
},
|
|
61
61
|
[Action.AddRowBottom]: {
|
|
62
|
-
$: ctx.get(
|
|
62
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'downArrow')?.dom as HTMLElement,
|
|
63
63
|
command: () => (state, dispatch) => {
|
|
64
64
|
if (!isInTable(state)) return false;
|
|
65
65
|
if (dispatch) {
|
|
@@ -71,22 +71,22 @@ export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
|
|
|
71
71
|
disable: (view) => !getCellSelection(view).isRowSelection(),
|
|
72
72
|
},
|
|
73
73
|
[Action.AlignLeft]: {
|
|
74
|
-
$: ctx.get(
|
|
74
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignLeft')?.dom as HTMLElement,
|
|
75
75
|
command: () => setCellAttr('alignment', 'left'),
|
|
76
76
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
77
77
|
},
|
|
78
78
|
[Action.AlignCenter]: {
|
|
79
|
-
$: ctx.get(
|
|
79
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignCenter')?.dom as HTMLElement,
|
|
80
80
|
command: () => setCellAttr('alignment', 'center'),
|
|
81
81
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
82
82
|
},
|
|
83
83
|
[Action.AlignRight]: {
|
|
84
|
-
$: ctx.get(
|
|
84
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignRight')?.dom as HTMLElement,
|
|
85
85
|
command: () => setCellAttr('alignment', 'right'),
|
|
86
86
|
disable: (view) => !getCellSelection(view).isColSelection(),
|
|
87
87
|
},
|
|
88
88
|
[Action.Delete]: {
|
|
89
|
-
$: ctx.get(
|
|
89
|
+
$: ctx.get(themeManagerCtx).get(ThemeIcon, 'delete')?.dom as HTMLElement,
|
|
90
90
|
command: (_, view) => {
|
|
91
91
|
const selection = getCellSelection(view);
|
|
92
92
|
const isCol = selection.isColSelection();
|
|
@@ -19,7 +19,7 @@ export const isFirstRowSelected = (selection: CellSelection) => {
|
|
|
19
19
|
);
|
|
20
20
|
|
|
21
21
|
for (let i = 0, count = cells.length; i < count; i++) {
|
|
22
|
-
if (selectedCells.indexOf(cells[i]) === -1) {
|
|
22
|
+
if (selectedCells.indexOf(cells[i] as number) === -1) {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -4,7 +4,7 @@ import { Ctx } from '@milkdown/core';
|
|
|
4
4
|
import { CellSelection, Decoration, DecorationSet, Plugin, PluginKey } from '@milkdown/prose';
|
|
5
5
|
import { Utils } from '@milkdown/utils';
|
|
6
6
|
|
|
7
|
-
import { getCellsInColumn, getCellsInRow } from '../utils';
|
|
7
|
+
import { CellPos, getCellsInColumn, getCellsInRow } from '../utils';
|
|
8
8
|
import { createActions } from './actions';
|
|
9
9
|
import { calculatePosition } from './calc-pos';
|
|
10
10
|
import { ToolTipPos } from './constant';
|
|
@@ -17,10 +17,12 @@ export const key = 'MILKDOWN_PLUGIN_TABLE';
|
|
|
17
17
|
export const operatorPlugin = (ctx: Ctx, utils: Utils) => {
|
|
18
18
|
const items = createActions(ctx);
|
|
19
19
|
const tooltip = document.createElement('div');
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
utils.themeManager.onFlush(() => {
|
|
21
|
+
const style = utils.getStyle(injectStyle);
|
|
22
|
+
if (style) {
|
|
23
|
+
tooltip.classList.add(style);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
24
26
|
tooltip.classList.add('table-tooltip', 'hide');
|
|
25
27
|
|
|
26
28
|
return new Plugin({
|
|
@@ -35,7 +37,7 @@ export const operatorPlugin = (ctx: Ctx, utils: Utils) => {
|
|
|
35
37
|
|
|
36
38
|
const [topLeft] = leftCells;
|
|
37
39
|
|
|
38
|
-
decorations.push(createWidget(ctx, topLeft, ToolTipPos.Point));
|
|
40
|
+
decorations.push(createWidget(ctx, topLeft as CellPos, ToolTipPos.Point));
|
|
39
41
|
leftCells.forEach((cell, i) => {
|
|
40
42
|
decorations.push(createWidget(ctx, cell, ToolTipPos.Left, i));
|
|
41
43
|
});
|
|
@@ -1,50 +1,122 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
|
-
import { Emotion,
|
|
2
|
+
import { Emotion, getPalette, ThemeBorder, ThemeManager, ThemeShadow, ThemeSize } from '@milkdown/core';
|
|
3
3
|
|
|
4
|
-
export const injectStyle = (
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
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');
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
injectGlobal`
|
|
10
|
+
.milkdown {
|
|
11
|
+
.tableWrapper {
|
|
12
|
+
table {
|
|
13
|
+
width: calc(100% - 2em) !important;
|
|
14
|
+
margin: 1em 0 1em 1em !important;
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
.milkdown-cell-left,
|
|
17
|
+
.milkdown-cell-point,
|
|
18
|
+
.milkdown-cell-top {
|
|
19
|
+
position: absolute;
|
|
12
20
|
|
|
13
|
-
|
|
21
|
+
&::after {
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
position: absolute;
|
|
24
|
+
top: 0;
|
|
25
|
+
left: 0;
|
|
26
|
+
height: 100%;
|
|
27
|
+
width: 100%;
|
|
28
|
+
display: block;
|
|
29
|
+
transition: all 0.2s ease-in-out;
|
|
30
|
+
background: ${palette('secondary', 0.12)};
|
|
31
|
+
content: '';
|
|
32
|
+
}
|
|
14
33
|
|
|
15
|
-
|
|
34
|
+
&:hover::after {
|
|
35
|
+
background: ${palette('secondary', 0.38)};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
16
38
|
|
|
17
|
-
|
|
39
|
+
.milkdown-cell-left {
|
|
40
|
+
left: calc(-6px - 0.5em);
|
|
41
|
+
top: 0;
|
|
42
|
+
bottom: 0;
|
|
43
|
+
width: 0.5em;
|
|
44
|
+
}
|
|
18
45
|
|
|
19
|
-
|
|
20
|
-
|
|
46
|
+
.milkdown-cell-top {
|
|
47
|
+
left: 0;
|
|
48
|
+
right: 0;
|
|
49
|
+
top: calc(-6px - 0.5em);
|
|
50
|
+
height: 0.5em;
|
|
51
|
+
}
|
|
21
52
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
53
|
+
.milkdown-cell-point {
|
|
54
|
+
left: calc(-2px - 1em);
|
|
55
|
+
top: calc(-2px - 1em);
|
|
56
|
+
width: 1em;
|
|
57
|
+
height: 1em;
|
|
25
58
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
59
|
+
.icon {
|
|
60
|
+
position: absolute;
|
|
61
|
+
top: 0;
|
|
62
|
+
bottom: 0;
|
|
63
|
+
left: 0;
|
|
64
|
+
right: 0;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
32
69
|
}
|
|
33
|
-
|
|
34
|
-
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
return css`
|
|
73
|
+
display: inline-flex;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
z-index: 2;
|
|
76
|
+
|
|
77
|
+
justify-content: space-evenly;
|
|
78
|
+
|
|
79
|
+
position: absolute;
|
|
80
|
+
|
|
81
|
+
border-radius: ${radius};
|
|
82
|
+
|
|
83
|
+
${themeManager.get(ThemeBorder, undefined)};
|
|
84
|
+
${themeManager.get(ThemeShadow, undefined)};
|
|
85
|
+
|
|
86
|
+
overflow: hidden;
|
|
87
|
+
background: ${palette('surface')};
|
|
88
|
+
|
|
89
|
+
.icon {
|
|
90
|
+
position: relative;
|
|
91
|
+
color: ${palette('solid', 0.87)};
|
|
92
|
+
|
|
93
|
+
width: 2em;
|
|
94
|
+
line-height: 2em;
|
|
95
|
+
text-align: center;
|
|
96
|
+
transition: all 0.4s ease-in-out;
|
|
97
|
+
|
|
98
|
+
&:hover {
|
|
99
|
+
background-color: ${palette('secondary', 0.12)};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&.active {
|
|
103
|
+
color: ${palette('primary')};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
&:not(:last-child)::after {
|
|
107
|
+
content: '';
|
|
108
|
+
position: absolute;
|
|
109
|
+
right: 0;
|
|
110
|
+
top: 0;
|
|
111
|
+
width: ${lineWidth};
|
|
112
|
+
bottom: 0;
|
|
113
|
+
background: ${palette('line')};
|
|
114
|
+
}
|
|
35
115
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
top: 0;
|
|
41
|
-
width: ${size.lineWidth};
|
|
42
|
-
bottom: 0;
|
|
43
|
-
background: ${palette('line')};
|
|
116
|
+
|
|
117
|
+
&.hide,
|
|
118
|
+
.hide {
|
|
119
|
+
display: none;
|
|
44
120
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.hide {
|
|
48
|
-
display: none;
|
|
49
|
-
}
|
|
50
|
-
`;
|
|
121
|
+
`;
|
|
122
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* Copyright 2021, Milkdown by Mirone. */
|
|
2
2
|
|
|
3
|
-
import { Ctx,
|
|
3
|
+
import { Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
|
|
4
4
|
import { Decoration, WidgetDecorationSpec } from '@milkdown/prose';
|
|
5
5
|
|
|
6
6
|
import { CellPos, selectLine, selectTable } from '../utils';
|
|
@@ -35,11 +35,11 @@ export function createWidget(
|
|
|
35
35
|
index: number,
|
|
36
36
|
): Decoration<WidgetDecorationSpec>;
|
|
37
37
|
export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos, index = 0) {
|
|
38
|
-
|
|
38
|
+
return Decoration.widget(cell.pos + 1, (view) => {
|
|
39
39
|
const div = document.createElement('div');
|
|
40
40
|
div.classList.add(calculateClassName(pos));
|
|
41
41
|
if (pos === ToolTipPos.Point) {
|
|
42
|
-
div.appendChild(ctx.get(
|
|
42
|
+
div.appendChild(ctx.get(themeManagerCtx).get(ThemeIcon, 'select')?.dom as HTMLElement);
|
|
43
43
|
}
|
|
44
44
|
div.addEventListener('mousedown', (e) => {
|
|
45
45
|
if (!view) return;
|
|
@@ -62,5 +62,4 @@ export function createWidget(ctx: Ctx, cell: CellPos, pos: ToolTipPos, index = 0
|
|
|
62
62
|
});
|
|
63
63
|
return div;
|
|
64
64
|
});
|
|
65
|
-
return widget;
|
|
66
65
|
}
|
package/src/table/utils.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type CellPos = {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const findTable = (selection: Selection) =>
|
|
22
|
-
findParentNode((node) => node.type.spec
|
|
22
|
+
findParentNode((node) => node.type.spec['tableRole'] === 'table')(selection);
|
|
23
23
|
|
|
24
24
|
export const getCellsInColumn =
|
|
25
25
|
(columnIndex: number) =>
|
|
@@ -129,10 +129,13 @@ export const getCellsInTable = (selection: Selection) => {
|
|
|
129
129
|
|
|
130
130
|
export const selectTable = (tr: Transaction) => {
|
|
131
131
|
const cells = getCellsInTable(tr.selection);
|
|
132
|
-
if (cells) {
|
|
132
|
+
if (cells && cells[0]) {
|
|
133
133
|
const $firstCell = tr.doc.resolve(cells[0].pos);
|
|
134
|
-
const
|
|
135
|
-
|
|
134
|
+
const last = cells[cells.length - 1];
|
|
135
|
+
if (last) {
|
|
136
|
+
const $lastCell = tr.doc.resolve(last.pos);
|
|
137
|
+
return cloneTr(tr.setSelection(new CellSelection($lastCell, $firstCell) as unknown as Selection));
|
|
138
|
+
}
|
|
136
139
|
}
|
|
137
140
|
return tr;
|
|
138
141
|
};
|
|
@@ -149,8 +152,8 @@ export function addRowWithAlignment(tr: Transaction, { map, tableStart, table }:
|
|
|
149
152
|
const cells = Array(map.width)
|
|
150
153
|
.fill(0)
|
|
151
154
|
.map((_, col) => {
|
|
152
|
-
const headerCol = table.nodeAt(map.map[col]);
|
|
153
|
-
return cellType.createAndFill({ alignment: headerCol?.attrs
|
|
155
|
+
const headerCol = table.nodeAt(map.map[col] as number);
|
|
156
|
+
return cellType.createAndFill({ alignment: headerCol?.attrs['alignment'] }) as ProsemirrorNode;
|
|
154
157
|
});
|
|
155
158
|
|
|
156
159
|
tr.insert(rowPos, rowType.create(null, cells));
|