-
-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add table block add table block * update table data field * add advance table * hide contextmenu * update table operation: delete selected columns * latest
- Loading branch information
Showing
19 changed files
with
1,370 additions
and
41 deletions.
There are no files selected for viewing
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
97 changes: 97 additions & 0 deletions
97
packages/easy-email-core/src/blocks/advanced/generateAdvancedTableBlock.tsx
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,97 @@ | ||
import { BasicType } from '@core/constants'; | ||
import { IBlock, IBlockData } from '@core/typings'; | ||
import { createCustomBlock } from '@core/utils/createCustomBlock'; | ||
import { TemplateEngineManager, createBlock, t } from '@core/utils'; | ||
import { merge } from 'lodash'; | ||
import React from 'react'; | ||
import { IPage, standardBlocks } from '../standard'; | ||
import { BasicBlock } from '@core/components/BasicBlock'; | ||
|
||
export function generateAdvancedTableBlock(option: { | ||
type: string; | ||
baseType: BasicType; | ||
}) { | ||
return createCustomBlock<AdvancedTableBlock>({ | ||
get name() { | ||
return t('Table'); | ||
}, | ||
type: option.type, | ||
validParentType: [BasicType.COLUMN], | ||
create: payload => { | ||
const defaultData: AdvancedTableBlock = { | ||
type: option.type, | ||
data: { | ||
value: { | ||
tableSource: [ | ||
[{ content: 'header1' }, { content: 'header2' }, { content: 'header3' }], | ||
[{ content: 'body1-1' }, { content: 'body1-2' }, { content: 'body1-3' }], | ||
[{ content: 'body2-1' }, { content: 'body2-2' }, { content: 'body2-3' }], | ||
], | ||
}, | ||
}, | ||
attributes: { | ||
cellBorderColor: '#000000', | ||
cellPadding: '8px', | ||
'text-align': 'center', | ||
}, | ||
children: [], | ||
}; | ||
return merge(defaultData, payload); | ||
}, | ||
render: params => { | ||
const { data } = params; | ||
const { cellPadding, cellBorderColor } = data.attributes; | ||
const textAlign = data.attributes['text-align']; | ||
const fontStyle = data.attributes['font-style']; | ||
|
||
const content = data.data.value.tableSource | ||
.map((tr, index) => { | ||
const styles = [] as any[]; | ||
if (cellPadding) { | ||
styles.push(`padding: ${cellPadding}`); | ||
} | ||
if (cellBorderColor) { | ||
styles.push(`border: 1px solid ${cellBorderColor}`); | ||
} | ||
const _trString = tr.map( | ||
e => | ||
`<td rowspan="${e.rowSpan || 1}" colspan="${ | ||
e.colSpan || 1 | ||
}" style="${styles.join(';')}">${e.content}</td>`, | ||
); | ||
return `<tr style="text-align:${textAlign};font-style:${fontStyle};">${_trString.join( | ||
'\n', | ||
)}</tr>`; | ||
}) | ||
.join('\n'); | ||
|
||
return ( | ||
<BasicBlock | ||
params={params} | ||
tag='mj-table' | ||
> | ||
{content} | ||
</BasicBlock> | ||
); | ||
}, | ||
}); | ||
} | ||
|
||
export interface ITableData { | ||
content: string; | ||
colSpan?: number; | ||
rowSpan?: number; | ||
} | ||
|
||
export type AdvancedTableBlock = IBlockData< | ||
{ | ||
cellPadding?: string; | ||
cellBorderColor?: string; | ||
'font-style'?: string; | ||
'text-align'?: string; | ||
}, | ||
{ | ||
content?: string; | ||
tableSource: ITableData[][]; | ||
} | ||
>; |
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
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
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 { BasicType, AdvancedType } from 'easy-email-core'; | ||
|
||
export function isTableBlock(blockType: any) { | ||
return blockType === AdvancedType.TABLE; | ||
} |
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.