From 78655eeb78e22d08d48bd16126987cee464cf9ec Mon Sep 17 00:00:00 2001 From: anmol Date: Tue, 7 Dec 2021 15:10:26 +0530 Subject: [PATCH] Revert "feat: adds table_header_cell element support" This reverts commit 36ad6f46e93b174da8ab23b6540058715c7bd36a. --- packages/html-to-slate-ast/src/index.ts | 28 +++---- packages/react-renderer/README.md | 2 - .../react-renderer/src/defaultElements.tsx | 8 +- .../react-renderer/test/RichText.test.tsx | 40 --------- packages/react-renderer/test/content.ts | 83 +------------------ packages/types/src/index.ts | 2 - 6 files changed, 18 insertions(+), 145 deletions(-) diff --git a/packages/html-to-slate-ast/src/index.ts b/packages/html-to-slate-ast/src/index.ts index e91c959..ce168a7 100644 --- a/packages/html-to-slate-ast/src/index.ts +++ b/packages/html-to-slate-ast/src/index.ts @@ -16,7 +16,7 @@ const ELEMENT_TAGS: Record< OL: () => ({ type: 'numbered-list' }), UL: () => ({ type: 'bulleted-list' }), P: () => ({ type: 'paragraph' }), - A: el => { + A: (el) => { const href = el.getAttribute('href'); if (href === null) return {}; return { @@ -43,8 +43,8 @@ const ELEMENT_TAGS: Record< TBODY: () => ({ type: 'table_body' }), TR: () => ({ type: 'table_row' }), TD: () => ({ type: 'table_cell' }), - TH: () => ({ type: 'table_header_cell' }), - IMG: el => { + TH: () => ({ type: 'table_cell' }), + IMG: (el) => { const href = el.getAttribute('src'); const title = Boolean(el.getAttribute('alt')) ? el.getAttribute('alt') @@ -108,7 +108,7 @@ function deserialize< parent = el.childNodes[0]; } let children = Array.from(parent.childNodes) - .map(c => deserialize(c, global)) + .map((c) => deserialize(c, global)) .flat(); if (children.length === 0) { @@ -124,7 +124,7 @@ function deserialize< if ( isElementNode(el) && Array.from(el.attributes).find( - attr => attr.name === 'role' && attr.value === 'heading' + (attr) => attr.name === 'role' && attr.value === 'heading' ) ) { const level = el.attributes.getNamedItem('aria-level')?.value; @@ -158,7 +158,7 @@ function deserialize< // li children must be rendered in spans, like in list plugin if (nodeName === 'LI') { const hasNestedListChild = children.find( - item => + (item) => SlateElement.isElement(item) && // if element has a nested list as a child, all children must be wrapped in individual list-item-child nodes // TODO: sync with GCMS types for Slate elements @@ -166,7 +166,7 @@ function deserialize< (item.type === 'numbered-list' || item.type === 'bulleted-list') ); if (hasNestedListChild) { - const wrappedChildren = children.map(item => + const wrappedChildren = children.map((item) => jsx('element', { type: 'list-item-child' }, item) ); return jsx('element', attrs, wrappedChildren); @@ -202,7 +202,7 @@ function deserialize< children: [{ text: '' }], }, ] - : childNodes.map(child => ({ + : childNodes.map((child) => ({ type: 'paragraph', children: [{ text: child.textContent ? child.textContent : '' }], })); @@ -216,7 +216,7 @@ function deserialize< if (nodeName === 'DIV') { const childNodes = Array.from(el.childNodes); const isParagraph = childNodes.every( - child => + (child) => (isElementNode(child) && isInlineElement(child)) || isTextNode(child) ); if (isParagraph) { @@ -254,7 +254,7 @@ function deserialize< const attrs = tagNames.reduce((acc, current) => { return { ...acc, ...TEXT_TAGS[current]() }; }, {}); - return children.map(child => { + return children.map((child) => { if (typeof child === 'string') { return jsx('text', attrs, child); } @@ -262,7 +262,7 @@ function deserialize< if (isChildNode(child, global)) return child; if (SlateElement.isElement(child) && !SlateText.isText(child)) { - child.children = child.children.map(c => ({ ...c, ...attrs })); + child.children = child.children.map((c) => ({ ...c, ...attrs })); return child; } @@ -273,7 +273,7 @@ function deserialize< if (TEXT_TAGS[nodeName]) { const attrs = TEXT_TAGS[nodeName](el as HTMLElement); - return children.map(child => { + return children.map((child) => { if (typeof child === 'string') { return jsx('text', attrs, child); } @@ -281,7 +281,7 @@ function deserialize< if (isChildNode(child, global)) return child; if (SlateElement.isElement(child) && !SlateText.isText(child)) { - child.children = child.children.map(c => ({ ...c, ...attrs })); + child.children = child.children.map((c) => ({ ...c, ...attrs })); return child; } @@ -453,7 +453,7 @@ export async function htmlToSlateAST(html: string) { const domDocument = await parseDomDocument(normalizedHTML); const global = await (async () => { if (typeof window !== 'undefined') return window; - return await import('jsdom').then(jsdom => new jsdom.JSDOM().window); + return await import('jsdom').then((jsdom) => new jsdom.JSDOM().window); })(); return deserialize(domDocument.body, global); } diff --git a/packages/react-renderer/README.md b/packages/react-renderer/README.md index 7a12c9a..99af88f 100644 --- a/packages/react-renderer/README.md +++ b/packages/react-renderer/README.md @@ -131,8 +131,6 @@ Below you can check the full list of elements you can customize, alongside the p - `children`: ReactNode; - `table_head` - `children`: ReactNode; -- `table_header` - - `children`: ReactNode; - `table_body` - `children`: ReactNode; - `table_row` diff --git a/packages/react-renderer/src/defaultElements.tsx b/packages/react-renderer/src/defaultElements.tsx index 8e724db..77bb27b 100644 --- a/packages/react-renderer/src/defaultElements.tsx +++ b/packages/react-renderer/src/defaultElements.tsx @@ -38,7 +38,6 @@ export const defaultElements: Required = { table_body: ({ children }) => {children}, table_row: ({ children }) => {children}, table_cell: ({ children }) => {children}, - table_header_cell: ({ children }) => {children}, bold: ({ children }) => {children}, italic: ({ children }) => {children}, underline: ({ children }) => {children}, @@ -58,9 +57,9 @@ export const defaultElements: Required = { ), list_item_child: ({ children }) => <>{children}, Asset: { - audio: props =>