-
Notifications
You must be signed in to change notification settings - Fork 31
/
table.ts
52 lines (47 loc) · 1.72 KB
/
table.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
import type { GeneralOptions } from '@/type'
import type { TableOptions as TiptapTableOptions } from '@tiptap/extension-table'
import type { TableCellOptions } from '@tiptap/extension-table-cell'
import type { TableHeaderOptions } from '@tiptap/extension-table-header'
import type { TableRowOptions } from '@tiptap/extension-table-row'
import { Table as TiptapTable } from '@tiptap/extension-table'
import { TableCell } from '@tiptap/extension-table-cell'
import { TableHeader } from '@tiptap/extension-table-header'
import { TableRow } from '@tiptap/extension-table-row'
import TableActionButton from './components/TableActionButton.vue'
/**
* Represents the interface for table options, extending TiptapTableOptions and GeneralOptions.
*/
export interface TableOptions extends TiptapTableOptions, GeneralOptions<TableOptions> {
/** options for table rows */
tableRow: Partial<TableRowOptions>
/** options for table headers */
tableHeader: Partial<TableHeaderOptions>
/** options for table cells */
tableCell: Partial<TableCellOptions>
}
export const Table = /* @__PURE__*/ TiptapTable.extend<TableOptions>({
addOptions() {
return {
...this.parent?.(),
HTMLAttributes: {
class: 'table-wrapper'
},
button: ({ editor, t }) => ({
component: TableActionButton,
componentProps: {
isActive: () => editor.isActive('table') || false,
disabled: !editor.can().insertTable(),
icon: 'table',
tooltip: t('editor.table.tooltip')
}
})
}
},
addExtensions() {
return [
TableRow.configure(this.options.tableRow),
TableHeader.configure(this.options.tableHeader),
TableCell.configure(this.options.tableCell)
]
}
})