add table headers

This commit is contained in:
Hans Pagel
2021-01-22 00:16:58 +01:00
parent c4f35911a0
commit 05487ea82f
8 changed files with 122 additions and 9 deletions

View File

@@ -0,0 +1,14 @@
# @tiptap/extension-table-header
[![Version](https://img.shields.io/npm/v/@tiptap/extension-table-header.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-table-header)
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-table-header.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
[![License](https://img.shields.io/npm/l/@tiptap/extension-table-header.svg)](https://www.npmjs.com/package/@tiptap/extension-table-header)
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](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).

View 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"
}
}

View File

@@ -0,0 +1,5 @@
import { TableHeader } from './table-header'
export * from './table-header'
export default TableHeader

View 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,
}
}