@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,13 +1,13 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { BreakTable, InsertTable, NextCell, PrevCell } from './nodes';
2
+ import { BreakTable, InsertTable, NextCell, PrevCell } from './nodes'
3
3
 
4
- export { BreakTable, InsertTable, NextCell, PrevCell, SupportedKeys, table } from './nodes';
5
- export { createTable } from './utils';
4
+ export { BreakTable, InsertTable, NextCell, PrevCell, SupportedKeys, table } from './nodes'
5
+ export { createTable } from './utils'
6
6
 
7
7
  export const commands = {
8
- NextCell,
9
- PrevCell,
10
- BreakTable,
11
- InsertTable,
12
- } as const;
13
- export type Commands = typeof commands;
8
+ NextCell,
9
+ PrevCell,
10
+ BreakTable,
11
+ InsertTable,
12
+ } as const
13
+ export type Commands = typeof commands
@@ -1,186 +1,189 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { createCmd, createCmdKey, MarkdownNode, schemaCtx } from '@milkdown/core';
3
- import { InputRule } from '@milkdown/prose/inputrules';
4
- import { NodeType } from '@milkdown/prose/model';
5
- import { Selection, TextSelection } from '@milkdown/prose/state';
6
- import { createPlugin, createShortcut } from '@milkdown/utils';
2
+ import type { MarkdownNode } from '@milkdown/core'
3
+ import { createCmd, createCmdKey, schemaCtx } from '@milkdown/core'
4
+ import { InputRule } from '@milkdown/prose/inputrules'
5
+ import type { NodeType } from '@milkdown/prose/model'
6
+ import { Selection, TextSelection } from '@milkdown/prose/state'
7
+ import { createPlugin, createShortcut } from '@milkdown/utils'
7
8
 
8
- import { exitTable } from '../command';
9
- import { operatorPlugin } from '../operator-plugin';
10
- import { autoInsertZeroSpace } from '../plugin/auto-insert-zero-space';
11
- import { columnResizing } from '../plugin/column-resizing';
12
- import { goToNextCell } from '../plugin/commands';
13
- import { schema } from '../plugin/schema';
14
- import { tableEditing } from '../plugin/table-editing';
15
- import { createTable } from '../utils';
9
+ import { exitTable } from '../command'
10
+ import { operatorPlugin } from '../operator-plugin'
11
+ import { autoInsertZeroSpace } from '../plugin/auto-insert-zero-space'
12
+ import { columnResizing } from '../plugin/column-resizing'
13
+ import { goToNextCell } from '../plugin/commands'
14
+ import { schema } from '../plugin/schema'
15
+ import { tableEditing } from '../plugin/table-editing'
16
+ import { createTable } from '../utils'
16
17
 
17
18
  export const SupportedKeys = {
18
- NextCell: 'NextCell',
19
- PrevCell: 'PrevCell',
20
- ExitTable: 'ExitTable',
21
- } as const;
22
- export type SupportedKeys = typeof SupportedKeys;
19
+ NextCell: 'NextCell',
20
+ PrevCell: 'PrevCell',
21
+ ExitTable: 'ExitTable',
22
+ } as const
23
+ // eslint-disable-next-line @typescript-eslint/no-redeclare
24
+ export type SupportedKeys = typeof SupportedKeys
23
25
 
24
- type Keys = keyof SupportedKeys;
26
+ type Keys = keyof SupportedKeys
25
27
 
26
- export const PrevCell = createCmdKey('PrevCell');
27
- export const NextCell = createCmdKey('NextCell');
28
- export const BreakTable = createCmdKey('BreakTable');
29
- export const InsertTable = createCmdKey('InsertTable');
28
+ export const PrevCell = createCmdKey('PrevCell')
29
+ export const NextCell = createCmdKey('NextCell')
30
+ export const BreakTable = createCmdKey('BreakTable')
31
+ export const InsertTable = createCmdKey('InsertTable')
30
32
 
31
33
  export const table = createPlugin<Keys, Record<string, unknown>, keyof typeof schema>((utils) => {
32
- return {
33
- schema: () => ({
34
- node: {
35
- table: {
36
- ...schema.table,
37
- parseMarkdown: {
38
- match: (node) => node.type === 'table',
39
- runner: (state, node, type) => {
40
- const align = node['align'] as (string | null)[];
41
- const children = (node.children as MarkdownNode[]).map((x, i) => ({
42
- ...x,
43
- align,
44
- isHeader: i === 0,
45
- }));
46
- state.openNode(type);
47
- state.next(children);
48
- state.closeNode();
49
- },
50
- },
51
- toMarkdown: {
52
- match: (node) => node.type.name === 'table',
53
- runner: (state, node) => {
54
- const firstLine = node.content.firstChild?.content;
55
- if (!firstLine) return;
56
-
57
- const align: (string | null)[] = [];
58
- firstLine.forEach((cell) => {
59
- align.push(cell.attrs['alignment']);
60
- });
61
- state.openNode('table', undefined, { align });
62
- state.next(node.content);
63
- state.closeNode();
64
- },
65
- },
66
- },
67
- table_row: {
68
- ...schema.table_row,
69
- parseMarkdown: {
70
- match: (node) => node.type === 'tableRow',
71
- runner: (state, node, type) => {
72
- const align = node['align'] as (string | null)[];
73
- const children = (node.children as MarkdownNode[]).map((x, i) => ({
74
- ...x,
75
- align: align[i],
76
- isHeader: node['isHeader'],
77
- }));
78
- state.openNode(type);
79
- state.next(children);
80
- state.closeNode();
81
- },
82
- },
83
- toMarkdown: {
84
- match: (node) => node.type.name === 'table_row',
85
- runner: (state, node) => {
86
- state.openNode('tableRow');
87
- state.next(node.content);
88
- state.closeNode();
89
- },
90
- },
91
- },
92
- table_cell: {
93
- ...schema.table_cell,
94
- parseMarkdown: {
95
- match: (node) => node.type === 'tableCell' && !node['isHeader'],
96
- runner: (state, node, type) => {
97
- const align = node['align'] as string;
98
- state
99
- .openNode(type, { alignment: align })
100
- .openNode(state.schema.nodes['paragraph'] as NodeType)
101
- .next(node.children)
102
- .closeNode()
103
- .closeNode();
104
- },
105
- },
106
- toMarkdown: {
107
- match: (node) => node.type.name === 'table_cell',
108
- runner: (state, node) => {
109
- state.openNode('tableCell').next(node.content).closeNode();
110
- },
111
- },
112
- },
113
- table_header: {
114
- ...schema.table_header,
115
- parseMarkdown: {
116
- match: (node) => node.type === 'tableCell' && !!node['isHeader'],
117
- runner: (state, node, type) => {
118
- const align = node['align'] as string;
119
- state.openNode(type, { alignment: align });
120
- state.openNode(state.schema.nodes['paragraph'] as NodeType);
121
- state.next(node.children);
122
- state.closeNode();
123
- state.closeNode();
124
- },
125
- },
126
- toMarkdown: {
127
- match: (node) => node.type.name === 'table_header',
128
- runner: (state, node) => {
129
- state.openNode('tableCell');
130
- state.next(node.content);
131
- state.closeNode();
132
- },
133
- },
134
- },
34
+ return {
35
+ schema: () => ({
36
+ node: {
37
+ table: {
38
+ ...schema.table,
39
+ parseMarkdown: {
40
+ match: node => node.type === 'table',
41
+ runner: (state, node, type) => {
42
+ const align = node.align as (string | null)[]
43
+ const children = (node.children as MarkdownNode[]).map((x, i) => ({
44
+ ...x,
45
+ align,
46
+ isHeader: i === 0,
47
+ }))
48
+ state.openNode(type)
49
+ state.next(children)
50
+ state.closeNode()
135
51
  },
136
- }),
137
- inputRules: (nodeType, ctx) => [
138
- new InputRule(/^\|\|\s$/, (state, _match, start, end) => {
139
- const $start = state.doc.resolve(start);
140
- if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
141
- return null;
142
-
143
- const tableNode = createTable(ctx.get(schemaCtx));
144
- const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView();
145
- return tr.setSelection(TextSelection.create(tr.doc, start + 3));
146
- }),
147
- new InputRule(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
148
- const $start = state.doc.resolve(start);
149
- if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
150
- return null;
52
+ },
53
+ toMarkdown: {
54
+ match: node => node.type.name === 'table',
55
+ runner: (state, node) => {
56
+ const firstLine = node.content.firstChild?.content
57
+ if (!firstLine)
58
+ return
151
59
 
152
- const tableNode = createTable(
153
- ctx.get(schemaCtx),
154
- Number(match.groups?.['row']),
155
- Number(match.groups?.['col']),
156
- );
157
- const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView();
158
- return tr.setSelection(TextSelection.create(tr.doc, start + 3));
159
- }),
160
- ],
161
- commands: (_, ctx) => [
162
- createCmd(PrevCell, () => goToNextCell(-1)),
163
- createCmd(NextCell, () => goToNextCell(1)),
164
- createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes['paragraph'] as NodeType)),
165
- createCmd(InsertTable, () => (state, dispatch) => {
166
- const { selection, tr } = state;
167
- const { from } = selection;
168
- const table = createTable(ctx.get(schemaCtx));
169
- const _tr = tr.replaceSelectionWith(table);
170
- const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true);
171
- if (sel) {
172
- dispatch?.(_tr.setSelection(sel));
173
- }
174
- return true;
175
- }),
176
- ],
177
- shortcuts: {
178
- [SupportedKeys.NextCell]: createShortcut(NextCell, 'Mod-]'),
179
- [SupportedKeys.PrevCell]: createShortcut(PrevCell, 'Mod-['),
180
- [SupportedKeys.ExitTable]: createShortcut(BreakTable, 'Mod-Enter'),
60
+ const align: (string | null)[] = []
61
+ firstLine.forEach((cell) => {
62
+ align.push(cell.attrs.alignment)
63
+ })
64
+ state.openNode('table', undefined, { align })
65
+ state.next(node.content)
66
+ state.closeNode()
67
+ },
68
+ },
69
+ },
70
+ table_row: {
71
+ ...schema.table_row,
72
+ parseMarkdown: {
73
+ match: node => node.type === 'tableRow',
74
+ runner: (state, node, type) => {
75
+ const align = node.align as (string | null)[]
76
+ const children = (node.children as MarkdownNode[]).map((x, i) => ({
77
+ ...x,
78
+ align: align[i],
79
+ isHeader: node.isHeader,
80
+ }))
81
+ state.openNode(type)
82
+ state.next(children)
83
+ state.closeNode()
84
+ },
85
+ },
86
+ toMarkdown: {
87
+ match: node => node.type.name === 'table_row',
88
+ runner: (state, node) => {
89
+ state.openNode('tableRow')
90
+ state.next(node.content)
91
+ state.closeNode()
92
+ },
93
+ },
94
+ },
95
+ table_cell: {
96
+ ...schema.table_cell,
97
+ parseMarkdown: {
98
+ match: node => node.type === 'tableCell' && !node.isHeader,
99
+ runner: (state, node, type) => {
100
+ const align = node.align as string
101
+ state
102
+ .openNode(type, { alignment: align })
103
+ .openNode(state.schema.nodes.paragraph as NodeType)
104
+ .next(node.children)
105
+ .closeNode()
106
+ .closeNode()
107
+ },
108
+ },
109
+ toMarkdown: {
110
+ match: node => node.type.name === 'table_cell',
111
+ runner: (state, node) => {
112
+ state.openNode('tableCell').next(node.content).closeNode()
113
+ },
114
+ },
181
115
  },
182
- prosePlugins: (_, ctx) => {
183
- return [operatorPlugin(ctx, utils), autoInsertZeroSpace(), columnResizing(), tableEditing()];
116
+ table_header: {
117
+ ...schema.table_header,
118
+ parseMarkdown: {
119
+ match: node => node.type === 'tableCell' && !!node.isHeader,
120
+ runner: (state, node, type) => {
121
+ const align = node.align as string
122
+ state.openNode(type, { alignment: align })
123
+ state.openNode(state.schema.nodes.paragraph as NodeType)
124
+ state.next(node.children)
125
+ state.closeNode()
126
+ state.closeNode()
127
+ },
128
+ },
129
+ toMarkdown: {
130
+ match: node => node.type.name === 'table_header',
131
+ runner: (state, node) => {
132
+ state.openNode('tableCell')
133
+ state.next(node.content)
134
+ state.closeNode()
135
+ },
136
+ },
184
137
  },
185
- };
186
- });
138
+ },
139
+ }),
140
+ inputRules: (nodeType, ctx) => [
141
+ new InputRule(/^\|\|\s$/, (state, _match, start, end) => {
142
+ const $start = state.doc.resolve(start)
143
+ if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
144
+ return null
145
+
146
+ const tableNode = createTable(ctx.get(schemaCtx))
147
+ const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView()
148
+ return tr.setSelection(TextSelection.create(tr.doc, start + 3))
149
+ }),
150
+ new InputRule(/^\|(?<col>\d+)[xX](?<row>\d+)\|\s$/, (state, match, start, end) => {
151
+ const $start = state.doc.resolve(start)
152
+ if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType.table))
153
+ return null
154
+
155
+ const tableNode = createTable(
156
+ ctx.get(schemaCtx),
157
+ Number(match.groups?.row),
158
+ Number(match.groups?.col),
159
+ )
160
+ const tr = state.tr.replaceRangeWith(start, end, tableNode).scrollIntoView()
161
+ return tr.setSelection(TextSelection.create(tr.doc, start + 3))
162
+ }),
163
+ ],
164
+ commands: (_, ctx) => [
165
+ createCmd(PrevCell, () => goToNextCell(-1)),
166
+ createCmd(NextCell, () => goToNextCell(1)),
167
+ createCmd(BreakTable, () => exitTable(ctx.get(schemaCtx).nodes.paragraph as NodeType)),
168
+ createCmd(InsertTable, () => (state, dispatch) => {
169
+ const { selection, tr } = state
170
+ const { from } = selection
171
+ const table = createTable(ctx.get(schemaCtx))
172
+ const _tr = tr.replaceSelectionWith(table)
173
+ const sel = Selection.findFrom(_tr.doc.resolve(from), 1, true)
174
+ if (sel)
175
+ dispatch?.(_tr.setSelection(sel))
176
+
177
+ return true
178
+ }),
179
+ ],
180
+ shortcuts: {
181
+ [SupportedKeys.NextCell]: createShortcut(NextCell, 'Mod-]'),
182
+ [SupportedKeys.PrevCell]: createShortcut(PrevCell, 'Mod-['),
183
+ [SupportedKeys.ExitTable]: createShortcut(BreakTable, 'Mod-Enter'),
184
+ },
185
+ prosePlugins: (_, ctx) => {
186
+ return [operatorPlugin(ctx, utils), autoInsertZeroSpace(), columnResizing(), tableEditing()]
187
+ },
188
+ }
189
+ })
@@ -1,115 +1,116 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
3
- import { Command } from '@milkdown/prose/state';
4
- import { EditorView } from '@milkdown/prose/view';
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'
5
6
 
6
7
  import {
7
- addColumnAfter,
8
- addColumnBefore,
9
- deleteColumn,
10
- deleteRow,
11
- deleteTable,
12
- isInTable,
13
- selectedRect,
14
- setCellAttr,
15
- } from '../plugin';
16
- import { addRowWithAlignment } from '../utils';
17
- import { getCellSelection, isFirstRowSelected } from './helper';
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'
18
19
 
19
- export type Item = {
20
- $: HTMLElement;
21
- command: (e: Event, view: EditorView) => Command;
22
- disable?: (view: EditorView) => boolean;
23
- };
20
+ export interface Item {
21
+ $: HTMLElement
22
+ command: (e: Event, view: EditorView) => Command
23
+ disable?: (view: EditorView) => boolean
24
+ }
24
25
 
25
26
  export enum Action {
26
- AddColLeft,
27
- AddColRight,
28
- AddRowTop,
29
- AddRowBottom,
30
- AlignLeft,
31
- AlignCenter,
32
- AlignRight,
33
- Delete,
27
+ AddColLeft,
28
+ AddColRight,
29
+ AddRowTop,
30
+ AddRowBottom,
31
+ AlignLeft,
32
+ AlignCenter,
33
+ AlignRight,
34
+ Delete,
34
35
  }
35
36
 
36
- export const createActions: (ctx: Ctx) => Record<Action, Item> = (ctx) => ({
37
- [Action.AddColLeft]: {
38
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'leftArrow')?.dom as HTMLElement,
39
- command: () => addColumnBefore,
40
- disable: (view) => !getCellSelection(view).isColSelection(),
41
- },
42
- [Action.AddColRight]: {
43
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'rightArrow')?.dom as HTMLElement,
44
- command: () => addColumnAfter,
45
- disable: (view) => !getCellSelection(view).isColSelection(),
46
- },
47
- [Action.AddRowTop]: {
48
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'upArrow')?.dom as HTMLElement,
49
- command: () => (state, dispatch) => {
50
- if (!isInTable(state)) return false;
51
- if (dispatch) {
52
- const rect = selectedRect(state);
53
- dispatch(addRowWithAlignment(state.tr, rect, rect.top));
54
- }
55
- return true;
56
- },
57
- disable: (view) =>
58
- !getCellSelection(view).isRowSelection() ||
59
- getCellSelection(view).$head.parent.type.name === 'table_header',
60
- },
61
- [Action.AddRowBottom]: {
62
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'downArrow')?.dom as HTMLElement,
63
- command: () => (state, dispatch) => {
64
- if (!isInTable(state)) return false;
65
- if (dispatch) {
66
- const rect = selectedRect(state);
67
- dispatch(addRowWithAlignment(state.tr, rect, rect.bottom));
68
- }
69
- return true;
70
- },
71
- disable: (view) => !getCellSelection(view).isRowSelection(),
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
72
58
  },
73
- [Action.AlignLeft]: {
74
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignLeft')?.dom as HTMLElement,
75
- command: () => setCellAttr('alignment', 'left'),
76
- disable: (view) => !getCellSelection(view).isColSelection(),
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
77
73
  },
78
- [Action.AlignCenter]: {
79
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignCenter')?.dom as HTMLElement,
80
- command: () => setCellAttr('alignment', 'center'),
81
- disable: (view) => !getCellSelection(view).isColSelection(),
82
- },
83
- [Action.AlignRight]: {
84
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'alignRight')?.dom as HTMLElement,
85
- command: () => setCellAttr('alignment', 'right'),
86
- disable: (view) => !getCellSelection(view).isColSelection(),
87
- },
88
- [Action.Delete]: {
89
- $: ctx.get(themeManagerCtx).get(ThemeIcon, 'delete')?.dom as HTMLElement,
90
- command: (_, view) => {
91
- const selection = getCellSelection(view);
92
- const isCol = selection.isColSelection();
93
- const isRow = selection.isRowSelection();
94
- if (isCol && isRow) {
95
- return deleteTable;
96
- }
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
97
99
 
98
- if (isCol) {
99
- return deleteColumn;
100
- }
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
101
110
 
102
- return deleteRow;
103
- },
104
- disable: (view) => {
105
- const selection = getCellSelection(view);
106
- if (selection.isRowSelection()) {
107
- if (selection.isColSelection()) {
108
- return false;
109
- }
110
- return isFirstRowSelected(selection);
111
- }
112
- return false;
113
- },
111
+ return isFirstRowSelected(selection)
112
+ }
113
+ return false
114
114
  },
115
- });
115
+ },
116
+ })