-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathtable.ts
More file actions
44 lines (40 loc) · 1.33 KB
/
table.ts
File metadata and controls
44 lines (40 loc) · 1.33 KB
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
import type { TableCellOptions, TableHeaderOptions, TableRowOptions, TableOptions as TiptapTableOptions } from '@tiptap/extension-table'
import type { GeneralOptions } from '@/type'
import { TableCell, TableHeader, TableRow, Table as TiptapTable } from '@tiptap/extension-table'
import { TableActionButton } from './components/ActionButton'
/**
* 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?.() as TiptapTableOptions,
resizable: true,
HTMLAttributes: {
class: 'table-wrapper',
},
button: ({ editor, t }) => ({
component: TableActionButton,
componentProps: {
editor,
t,
},
}),
}
},
addExtensions() {
return [
TableRow.configure(this.options.tableRow),
TableHeader.configure(this.options.tableHeader),
TableCell.configure(this.options.tableCell),
]
},
})