-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext-menu-item.ts
63 lines (58 loc) · 1.82 KB
/
context-menu-item.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {
AITable,
AITableContextMenuItem,
AITableGridSelectionService,
isMac,
UpdateFieldValueOptions,
writeToAITable
} from '@ai-table/grid';
import { Actions } from '../action';
import { AIViewTable } from '../types';
import { buildClipboardData, writeToClipboard } from '@ai-table/grid';
export const RemoveRecordsItem: AITableContextMenuItem = {
type: 'removeRecords',
name: '删除行',
icon: 'trash',
exec: (
aiTable: AITable,
targetName: string,
position: { x: number; y: number },
aiTableGridSelectionService: AITableGridSelectionService
) => {
let selectedRecordIds = AITable.getActiveRecordIds(aiTable);
selectedRecordIds.forEach((id: string) => {
Actions.removeRecord(aiTable as AIViewTable, [id]);
});
aiTableGridSelectionService.clearSelection();
}
};
export const CopyCellsItem: AITableContextMenuItem = {
type: 'copyCells',
name: '复制',
shortcutKey: isMac() ? `⌘ + C` : `Ctrl + C`,
icon: 'copy',
exec: (aiTable: AITable) => {
const clipboardData = buildClipboardData(aiTable);
if (clipboardData) {
writeToClipboard(clipboardData);
}
}
};
export const PasteCellsItem: (updateValueFn: (data: UpdateFieldValueOptions) => void) => AITableContextMenuItem = (
updateValueFn: (data: UpdateFieldValueOptions) => void
) => {
return {
type: 'pasteCells',
name: '粘贴',
shortcutKey: isMac() ? `⌘ + V` : `Ctrl + V`,
icon: 'paste',
exec: async (
aiTable: AITable,
targetName: string,
position: { x: number; y: number },
aiTableGridSelectionService: AITableGridSelectionService
) => {
writeToAITable(aiTable, updateValueFn);
}
};
};