Skip to content

Commit

Permalink
criação do ultimo botao da tabela
Browse files Browse the repository at this point in the history
  • Loading branch information
skaduhs5232 committed May 22, 2024
1 parent 933cecc commit 3f919f0
Show file tree
Hide file tree
Showing 14 changed files with 493 additions and 51 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"@tiptap/extension-strike": "^2.2.5",
"@tiptap/extension-subscript": "^2.2.5",
"@tiptap/extension-superscript": "^2.2.5",
"@tiptap/extension-table": "^2.3.1",
"@tiptap/extension-table-cell": "^2.3.1",
"@tiptap/extension-table-header": "^2.3.1",
"@tiptap/extension-table-row": "^2.3.1",
"@tiptap/extension-table": "^2.4.0",
"@tiptap/extension-table-cell": "^2.4.0",
"@tiptap/extension-table-header": "^2.4.0",
"@tiptap/extension-table-row": "^2.4.0",
"@tiptap/extension-text": "^2.2.5",
"@tiptap/extension-text-align": "^2.2.5",
"@tiptap/extension-underline": "^2.2.5",
Expand Down
14 changes: 14 additions & 0 deletions src/extensions/extension-table-cell/README.md
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).
5 changes: 5 additions & 0 deletions src/extensions/extension-table-cell/src/index.ts
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
116 changes: 116 additions & 0 deletions src/extensions/extension-table-cell/src/table-cell.ts
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

View workflow job for this annotation

GitHub Actions / deploy

Type '(this: { name: string; options: TableCellOptions; storage: any; editor: Editor; type: NodeType; parent: (() => Partial<RawCommands>) | undefined; }) => { ...; }' is not assignable to type '(this: { name: string; options: TableCellOptions; storage: any; editor: Editor; type: NodeType; parent: (() => Partial<RawCommands>) | undefined; }) => Partial<...>'.
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
}
}
}
})
24 changes: 12 additions & 12 deletions src/extensions/image/imageView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,54 @@ function clickHandler(imageWrapper: HTMLElement) {
function alinhaDireita(imageView: ImageView) {
return ({ button }: ButtonEventProps) => {
const { editor, node, imageWrapper } = imageView
if (!imageWrapper.classList.contains('ex-direita')) {
if (!imageWrapper.classList.contains('ex-margin-direita')) {
button.parentToolbar.tools.forEach(tool => tool instanceof Button && tool.off())
button.on()
imageWrapper.classList.add('ex-direita')
imageWrapper.classList.remove('ex-meio', 'ex-esquerda')
imageWrapper.classList.add('ex-margin-direita')
imageWrapper.classList.remove('ex-margin-meio', 'ex-margin-esquerda')

editor.commands.updateAttributes(node.type, {
classes: imageWrapper.className
})
} else {
button.off()
imageWrapper.classList.remove('ex-direita')
imageWrapper.classList.remove('ex-margin-direita')
}
}
}

function alinhaEsquerda(imageView: ImageView) {
return ({ button }: ButtonEventProps) => {
const { editor, node, imageWrapper } = imageView
if (!imageWrapper.classList.contains('ex-esquerda')) {
if (!imageWrapper.classList.contains('ex-margin-esquerda')) {
button.parentToolbar.tools.forEach(tool => tool instanceof Button && tool.off())
button.on()
imageWrapper.classList.add('ex-esquerda')
imageWrapper.classList.remove('ex-meio', 'ex-direita')
imageWrapper.classList.add('ex-margin-esquerda')
imageWrapper.classList.remove('ex-margin-meio', 'ex-margin-direita')
editor.commands.updateAttributes(node.type, {
classes: imageWrapper.className
})
} else {
button.off()
imageWrapper.classList.remove('ex-esquerda')
imageWrapper.classList.remove('ex-margin-esquerda')
}
}
}

function alinhaMeio(imageView: ImageView) {
return ({ button }: ButtonEventProps) => {
const { editor, node, imageWrapper } = imageView
if (!imageWrapper.classList.contains('ex-meio')) {
if (!imageWrapper.classList.contains('ex-margin-meio')) {
button.parentToolbar.tools.forEach(tool => tool instanceof Button && tool.off())
button.on()
imageWrapper.classList.add('ex-meio')
imageWrapper.classList.remove('ex-esquerda', 'ex-direita')
imageWrapper.classList.add('ex-margin-meio')
imageWrapper.classList.remove('ex-margin-esquerda', 'ex-margin-direita')
editor.commands.updateAttributes(node.type, {
classes: imageWrapper.className
})
} else {
button.off()
imageWrapper.classList.remove('ex-meio')
imageWrapper.classList.remove('ex-margin-meio')
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/extensions/table/TableView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type ExitusEditor from 'src/ExitusEditor'
import { Button, Dropdown } from '../../editor/ui'
import { Balloon } from '../../editor/ui/Balloon'

import { criaCellModal } from './itensModalCell'
import { criaTabelaModal } from './itensModalTable'
import { objParaCss } from './table'
import TableFocus from './tableFocus'
Expand Down Expand Up @@ -164,9 +165,7 @@ export class TableView implements NodeView {
toolbarButtonConfig: {
icon: starredCell + arrowDropDown,
label: 'editar celula',
events: {
click: null
}
dropdown: criaCellModal()
}
}
}
Expand Down
Loading

0 comments on commit 3f919f0

Please sign in to comment.