This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
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
879e23a
commit f256192
Showing
5 changed files
with
136 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { v4 as uuid } from 'uuid'; | ||
import { Editor, Transforms } from 'slate'; | ||
import { TABLE, TD } from 'volto-slate/constants'; | ||
|
||
export function syncCreateTableBlock(content) { | ||
const id = uuid(); | ||
const block = { | ||
'@type': 'slateTable', | ||
...content, | ||
}; | ||
return [id, block]; | ||
} | ||
|
||
export const extractTables = (editor, pathRef) => { | ||
const tableNodes = Array.from( | ||
Editor.nodes(editor, { | ||
at: pathRef.current, | ||
match: (node) => node.type === TABLE, | ||
}), | ||
); | ||
const tables = tableNodes.map(([el]) => extractVoltoTable(el)); | ||
|
||
Transforms.removeNodes(editor, { | ||
at: pathRef.current, | ||
match: (node) => node.type === TABLE, | ||
}); | ||
|
||
return tables.map((el) => syncCreateTableBlock(el)); | ||
}; | ||
|
||
function extractVoltoTable(el) { | ||
console.log('table', el); | ||
return null; | ||
} | ||
|
||
// import { v4 as uuid } from 'uuid'; | ||
// import { Transforms } from 'slate'; | ||
// import { IMAGE } from 'volto-slate/constants'; | ||
// import { jsx } from 'slate-hyperscript'; | ||
// import { getBaseUrl } from '@plone/volto/helpers'; | ||
// import { createSlateTableBlock } from 'volto-slate/utils'; | ||
// export const deserializeTableTag = (editor, el) => { | ||
// if (el.localName !== 'table') { | ||
// return null; | ||
// } | ||
// | ||
// let rows = []; | ||
// | ||
// el.querySelectorAll('tr').forEach((val, idx) => { | ||
// let row = { key: uuid(), cells: [] }; | ||
// val.childNodes.forEach((val2, idx2) => { | ||
// let ds = deserialize(editor, val2); | ||
// | ||
// function dsx(ds) { | ||
// return Array.isArray(ds) | ||
// ? ds.map((x) => { | ||
// if (typeof x === 'string') { | ||
// return { type: 'p', children: [{ text: x }] }; | ||
// } | ||
// return dsx(x); | ||
// }) | ||
// : ds; | ||
// } | ||
// ds = dsx(ds); | ||
// | ||
// if (val2.localName === 'th') { | ||
// row.cells.push({ | ||
// key: uuid(), | ||
// type: 'header', | ||
// value: ds, | ||
// }); | ||
// } else if (val2.localName === 'td') { | ||
// row.cells.push({ | ||
// key: uuid(), | ||
// type: 'data', | ||
// value: ds, | ||
// }); | ||
// } | ||
// }); | ||
// | ||
// rows.push(row); | ||
// }); | ||
// | ||
// console.log('TABLE', rows); | ||
// | ||
// // TODO: get the correct index here | ||
// | ||
// // const { onChangeBlock, onAddBlock } = editor.getBlockProps(); | ||
// // createSlateTableBlock(rows, 0, { onChangeBlock, onAddBlock }); | ||
// | ||
// // const attrs = { type: IMAGE }; | ||
// | ||
// // for (const name of el.getAttributeNames()) { | ||
// // attrs[name] = el.getAttribute(name); | ||
// // } | ||
// | ||
// // return jsx('text', {}, ''); | ||
// // return [jsx('element', attrs, [{ text: '' }]), jsx('text', {}, '')]; | ||
// return null; // [jsx('element', attrs, [{ text: '' }])]; | ||
// }; |
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