forked from marcelinombb/Tiptap-Exitus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
933cecc
commit 3f919f0
Showing
14 changed files
with
493 additions
and
51 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# @tiptap/extension-table-cell | ||
[![Version](https://img.shields.io/npm/v/@tiptap/extension-table-cell.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-table-cell) | ||
[![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-table-cell.svg)](https://npmcharts.com/compare/tiptap?minimal=true) | ||
[![License](https://img.shields.io/npm/l/@tiptap/extension-table-cell.svg)](https://www.npmjs.com/package/@tiptap/extension-table-cell) | ||
[![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*. | ||
|
||
## Official 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/blob/main/LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { TableCell } from './table-cell.js' | ||
|
||
export * from './table-cell.js' | ||
|
||
export default TableCell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { objParaCss } from '@extensions/table' | ||
import { mergeAttributes, Node } from '@tiptap/core' | ||
import { selectionCell } from '@tiptap/pm/tables' | ||
|
||
export interface TableCellOptions { | ||
/** | ||
* The HTML attributes for a table cell node. | ||
* @default {} | ||
* @example { class: 'foo' } | ||
*/ | ||
HTMLAttributes: Record<string, any> | ||
} | ||
|
||
/** | ||
* This extension allows you to create table cells. | ||
* @see https://www.tiptap.dev/api/nodes/table-cell | ||
*/ | ||
|
||
export function cssParaObj(cssString: string): { [key: string]: string } { | ||
const styles: { [key: string]: string } = {} | ||
|
||
// Remover espaços em branco desnecessários | ||
cssString = cssString.replace(/\s*:\s*/g, ':').replace(/\s*;\s*/g, ';') | ||
|
||
// Dividir a string por ponto e vírgula para obter as declarações individuais | ||
const declarations = cssString.split(';') | ||
|
||
// Iterar sobre as declarações e adicionar ao objeto | ||
declarations.forEach(declaration => { | ||
const [property, value] = declaration.split(':') | ||
if (property && value) { | ||
styles[property.trim()] = value.trim() | ||
} | ||
}) | ||
|
||
return styles | ||
} | ||
|
||
export const TableCell = Node.create<TableCellOptions>({ | ||
name: 'tableCell', | ||
|
||
addOptions() { | ||
return { | ||
HTMLAttributes: {} | ||
} | ||
}, | ||
|
||
content: 'block+', | ||
|
||
addAttributes() { | ||
return { | ||
colspan: { | ||
default: 1 | ||
}, | ||
rowspan: { | ||
default: 1 | ||
}, | ||
style: { | ||
default: {}, | ||
parseHTML: element => { | ||
const style = element.getAttribute('style') | ||
return style ? cssParaObj(style) : {} | ||
} | ||
}, | ||
colwidth: { | ||
default: null, | ||
parseHTML: element => { | ||
const colwidth = element.getAttribute('colwidth') | ||
return colwidth ? [parseInt(colwidth, 10)] : null | ||
} | ||
} | ||
} | ||
}, | ||
|
||
tableRole: 'cell', | ||
|
||
isolating: true, | ||
|
||
parseHTML() { | ||
return [{ tag: 'td' }] | ||
}, | ||
|
||
renderHTML({ HTMLAttributes }) { | ||
//console.log(HTMLAttributes) | ||
|
||
HTMLAttributes = { | ||
...HTMLAttributes, | ||
style: objParaCss(HTMLAttributes.style) | ||
} | ||
return ['td', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0] | ||
}, | ||
addCommands() { | ||
Check failure on line 92 in src/extensions/extension-table-cell/src/table-cell.ts GitHub Actions / deploy
|
||
return { | ||
...this.parent?.(), | ||
setCellAttribute: | ||
(attributes: { [key: string]: any }) => | ||
({ state, dispatch, tr }) => { | ||
const { nodeAfter, pos } = selectionCell(state) | ||
|
||
const attrs = { | ||
...nodeAfter?.attrs, | ||
style: { | ||
...nodeAfter?.attrs.style, | ||
...attributes | ||
} | ||
} | ||
if (dispatch) { | ||
tr.setNodeMarkup(pos, undefined, attrs) | ||
dispatch(tr) | ||
} | ||
|
||
return true | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.