add table headers
This commit is contained in:
@@ -31,13 +31,13 @@
|
|||||||
⚠️ splitCell
|
⚠️ splitCell
|
||||||
</button>
|
</button>
|
||||||
<button @click="editor.chain().focus().toggleHeaderColumn().run()">
|
<button @click="editor.chain().focus().toggleHeaderColumn().run()">
|
||||||
⚠️ toggleHeaderColumn
|
✅ toggleHeaderColumn
|
||||||
</button>
|
</button>
|
||||||
<button @click="editor.chain().focus().toggleHeaderRow().run()">
|
<button @click="editor.chain().focus().toggleHeaderRow().run()">
|
||||||
⚠️ toggleHeaderRow
|
✅ toggleHeaderRow
|
||||||
</button>
|
</button>
|
||||||
<button @click="editor.chain().focus().toggleHeaderCell().run()">
|
<button @click="editor.chain().focus().toggleHeaderCell().run()">
|
||||||
⚠️ toggleHeaderCell
|
✅ toggleHeaderCell
|
||||||
</button>
|
</button>
|
||||||
<editor-content :editor="editor" />
|
<editor-content :editor="editor" />
|
||||||
</div>
|
</div>
|
||||||
@@ -52,6 +52,7 @@ import Text from '@tiptap/extension-text'
|
|||||||
import Table from '@tiptap/extension-table'
|
import Table from '@tiptap/extension-table'
|
||||||
import TableRow from '@tiptap/extension-table-row'
|
import TableRow from '@tiptap/extension-table-row'
|
||||||
import TableCell from '@tiptap/extension-table-cell'
|
import TableCell from '@tiptap/extension-table-cell'
|
||||||
|
import TableHeader from '@tiptap/extension-table-header'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -72,6 +73,7 @@ export default {
|
|||||||
Text,
|
Text,
|
||||||
Table,
|
Table,
|
||||||
TableRow,
|
TableRow,
|
||||||
|
TableHeader,
|
||||||
TableCell,
|
TableCell,
|
||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
@@ -79,9 +81,9 @@ export default {
|
|||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Test</td>
|
<th>Test</th>
|
||||||
<td>Test</td>
|
<th>Test</th>
|
||||||
<td>Test</td>
|
<th>Test</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Test</td>
|
<td>Test</td>
|
||||||
@@ -103,8 +105,12 @@ export default {
|
|||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.ProseMirror {
|
.ProseMirror {
|
||||||
table, tr, td {
|
table, td {
|
||||||
border: 3px solid red;
|
border: 3px solid red;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
border: 3px solid blue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
8
docs/src/docPages/api/nodes/table-header.md
Normal file
8
docs/src/docPages/api/nodes/table-header.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# TableHeader
|
||||||
|
|
||||||
|
:::pro Fund the development 💖
|
||||||
|
We need your support to maintain, update, support and develop tiptap 2. If you’re waiting for this extension, [become a sponsor and fund open source](/sponsor).
|
||||||
|
:::
|
||||||
|
|
||||||
|
TODO
|
||||||
|
|
||||||
@@ -135,6 +135,9 @@
|
|||||||
- title: TableCell
|
- title: TableCell
|
||||||
link: /api/nodes/table-cell
|
link: /api/nodes/table-cell
|
||||||
type: draft
|
type: draft
|
||||||
|
- title: TableHeader
|
||||||
|
link: /api/nodes/table-header
|
||||||
|
type: draft
|
||||||
- title: TaskList
|
- title: TaskList
|
||||||
link: /api/nodes/task-list
|
link: /api/nodes/task-list
|
||||||
- title: TaskItem
|
- title: TaskItem
|
||||||
|
|||||||
14
packages/extension-table-header/README.md
Normal file
14
packages/extension-table-header/README.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# @tiptap/extension-table-header
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-table-header)
|
||||||
|
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
||||||
|
[](https://www.npmjs.com/package/@tiptap/extension-table-header)
|
||||||
|
[](https://github.com/sponsors/ueberdosis)
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
||||||
|
|
||||||
|
## Offical Documentation
|
||||||
|
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
||||||
|
|
||||||
|
## License
|
||||||
|
tiptap is open-sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap-next/blob/main/LICENSE.md).
|
||||||
27
packages/extension-table-header/package.json
Normal file
27
packages/extension-table-header/package.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "@tiptap/extension-table-header",
|
||||||
|
"description": "table cell extension for tiptap",
|
||||||
|
"version": "2.0.0-alpha.5",
|
||||||
|
"homepage": "https://tiptap.dev",
|
||||||
|
"keywords": [
|
||||||
|
"tiptap",
|
||||||
|
"tiptap extension"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ueberdosis"
|
||||||
|
},
|
||||||
|
"main": "dist/tiptap-extension-table-header.cjs.js",
|
||||||
|
"umd": "dist/tiptap-extension-table-header.umd.js",
|
||||||
|
"module": "dist/tiptap-extension-table-header.esm.js",
|
||||||
|
"unpkg": "dist/tiptap-extension-table-header.bundle.umd.min.js",
|
||||||
|
"types": "dist/packages/extension-table-header/src/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"src",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"peerDependencies": {
|
||||||
|
"@tiptap/core": "^2.0.0-alpha.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
packages/extension-table-header/src/index.ts
Normal file
5
packages/extension-table-header/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { TableHeader } from './table-header'
|
||||||
|
|
||||||
|
export * from './table-header'
|
||||||
|
|
||||||
|
export default TableHeader
|
||||||
51
packages/extension-table-header/src/table-header.ts
Normal file
51
packages/extension-table-header/src/table-header.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { Node, mergeAttributes } from '@tiptap/core'
|
||||||
|
|
||||||
|
export interface TableHeaderOptions {
|
||||||
|
HTMLAttributes: {
|
||||||
|
[key: string]: any
|
||||||
|
},
|
||||||
|
}
|
||||||
|
export const TableHeader = Node.create({
|
||||||
|
name: 'table_header',
|
||||||
|
|
||||||
|
defaultOptions: <TableHeaderOptions>{
|
||||||
|
HTMLAttributes: {},
|
||||||
|
},
|
||||||
|
|
||||||
|
content: 'block+',
|
||||||
|
|
||||||
|
addAttributes() {
|
||||||
|
return {
|
||||||
|
colspan: {
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
rowspan: {
|
||||||
|
default: 1,
|
||||||
|
},
|
||||||
|
colwidth: {
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
tableRole: 'header_cell',
|
||||||
|
|
||||||
|
isolating: true,
|
||||||
|
|
||||||
|
parseHTML() {
|
||||||
|
// return [{ tag: 'th', getAttrs: dom => getCellAttrs(dom, extraAttrs) }]
|
||||||
|
return [{ tag: 'th' }]
|
||||||
|
},
|
||||||
|
|
||||||
|
renderHTML({ HTMLAttributes }) {
|
||||||
|
// toDOM(node) { return ["th", setCellAttrs(node, extraAttrs), 0] }
|
||||||
|
return ['th', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]
|
||||||
|
},
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
declare module '@tiptap/core' {
|
||||||
|
interface AllExtensions {
|
||||||
|
TableHeader: typeof TableHeader,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,7 @@ export const TableRow = Node.create({
|
|||||||
HTMLAttributes: {},
|
HTMLAttributes: {},
|
||||||
},
|
},
|
||||||
|
|
||||||
// content: '(tableCell | tableHeader)*',
|
content: '(table_cell | table_header)*',
|
||||||
content: 'table_cell*',
|
|
||||||
|
|
||||||
tableRole: 'row',
|
tableRole: 'row',
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user