Skip to content

Commit b55ae26

Browse files
feat: add table preview in visual editor (#8)
* feat: add table preview in visual editor * fix: format
1 parent 586e718 commit b55ae26

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

packages/decap-cms-widget-markdown/src/MarkdownControl/renderers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const StyledTable = styled.table`
9797
`;
9898

9999
const StyledTd = styled.td`
100-
border: 2px solid black;
100+
border: 1px solid black;
101101
padding: 8px;
102102
text-align: left;
103103
`;

packages/decap-cms-widget-richtext/src/RichtextControl/VisualEditor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import BlockquoteElement from './components/Element/BlockquoteElement';
2727
import LinkElement from './components/Element/LinkElement';
2828
import ExtendedBlockquotePlugin from './plugins/ExtendedBlockquotePlugin';
2929
import ShortcodePlugin from './plugins/ShortcodePlugin';
30+
import { TablePlugin, TableRowPlugin, TableCellPlugin } from './plugins/TablePlugin';
3031
import defaultEmptyBlock from './defaultEmptyBlock';
3132
import { mergeMediaConfig } from './mergeMediaConfig';
3233
import { handleLinkClick } from './linkHandler';
@@ -146,6 +147,9 @@ export default function VisualEditor(props) {
146147
node: { component: BlockquoteElement },
147148
}),
148149
ShortcodePlugin,
150+
TablePlugin,
151+
TableRowPlugin,
152+
TableCellPlugin,
149153
],
150154
value: initialValue,
151155
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import styled from '@emotion/styled';
3+
4+
const StyledTd = styled.td`
5+
border: 1px solid black;
6+
padding: 8px;
7+
text-align: left;
8+
`;
9+
10+
function TableCellElement({ children, attributes, nodeProps }) {
11+
return (
12+
<StyledTd {...attributes} {...nodeProps}>
13+
{children}
14+
</StyledTd>
15+
);
16+
}
17+
18+
export default TableCellElement;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
import styled from '@emotion/styled';
3+
4+
const StyledTable = styled.table`
5+
border-collapse: collapse;
6+
margin-bottom: 16px;
7+
width: 100%;
8+
`;
9+
10+
function TableElement({ children, attributes, nodeProps }) {
11+
return (
12+
<StyledTable {...attributes} {...nodeProps}>
13+
<tbody>{children}</tbody>
14+
</StyledTable>
15+
);
16+
}
17+
18+
export default TableElement;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
function TableRowElement({ children, attributes, nodeProps }) {
4+
return (
5+
<tr {...attributes} {...nodeProps}>
6+
{children}
7+
</tr>
8+
);
9+
}
10+
11+
export default TableRowElement;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { createSlatePlugin } from 'platejs';
2+
import { toPlatePlugin } from 'platejs/react';
3+
4+
import TableElement from '../components/Element/TableElement';
5+
import TableRowElement from '../components/Element/TableRowElement';
6+
import TableCellElement from '../components/Element/TableCellElement';
7+
8+
const tablePlugin = createSlatePlugin({
9+
key: 'table',
10+
node: {
11+
isElement: true,
12+
component: TableElement,
13+
},
14+
});
15+
16+
const tableRowPlugin = createSlatePlugin({
17+
key: 'table-row',
18+
node: {
19+
isElement: true,
20+
component: TableRowElement,
21+
},
22+
});
23+
24+
const tableCellPlugin = createSlatePlugin({
25+
key: 'table-cell',
26+
node: {
27+
isElement: true,
28+
component: TableCellElement,
29+
},
30+
});
31+
32+
const TablePlugin = toPlatePlugin(tablePlugin);
33+
const TableRowPlugin = toPlatePlugin(tableRowPlugin);
34+
const TableCellPlugin = toPlatePlugin(tableCellPlugin);
35+
36+
export { TablePlugin, TableRowPlugin, TableCellPlugin };

0 commit comments

Comments
 (0)