Skip to content

Commit

Permalink
feat: Improve slateTable block conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Jan 7, 2022
1 parent fda42be commit dd71acd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/converters/slate.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,20 @@ const deserialize = (el) => {
}
};

const createCell = (type, value) => ({
key: getId(),
type: type,
value: value,
});
const createCell = (type, rawValue) => {
const value = rawValue.map(function (el) {
if (Array.isArray(el)) {
return el;
} else {
return jsx('element', { type: 'p' }, el);
}
});
return {
key: getId(),
type: type,
value: value,
};
};

const createTable = (rows) => ({
basic: false,
Expand Down
4 changes: 3 additions & 1 deletion src/converters/slate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ describe('slateTableBlock processing a simple table', () => {
expect(rows[0].cells).toHaveLength(1);
expect(rows[0].cells[0].type).toBe('data');
expect(rows[0].cells[0].value).toHaveLength(1);
expect(rows[0].cells[0].value[0]).toBe('A value');
const value = rows[0].cells[0].value[0];
expect(value['type']).toBe('p');
expect(value['children'][0]['text']).toBe('A value');
});
});

0 comments on commit dd71acd

Please sign in to comment.