diff --git a/package-lock.json b/package-lock.json index 6d8fa63920..4f97c74dd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -82,7 +82,6 @@ "@gravity-ui/ui-logger": "^1.1.0", "@gravity-ui/uikit": "^6.31.0", "@jest/types": "^29.6.3", - "@litejs/dom": "^24.8.0", "@microsoft/fetch-event-source": "^2.0.1", "@playwright/test": "^1.48.2", "@statoscope/cli": "^5.28.2", @@ -7257,13 +7256,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@litejs/dom": { - "version": "24.8.0", - "resolved": "https://registry.npmjs.org/@litejs/dom/-/dom-24.8.0.tgz", - "integrity": "sha512-K47hyS8pgU578UQ3/DmmOoaqskeb6q+h37OzFsltFWXGVypjLmsWR+KxtocoDy+UocQkXtODNtHRsP7pho3XNg==", - "dev": true, - "license": "MIT" - }, "node_modules/@microsoft/fetch-event-source": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/@microsoft%2ffetch-event-source/-/fetch-event-source-2.0.1.tgz", diff --git a/package.json b/package.json index d71dc45330..27a27bccbf 100644 --- a/package.json +++ b/package.json @@ -126,7 +126,6 @@ "@gravity-ui/ui-logger": "^1.1.0", "@gravity-ui/uikit": "^6.31.0", "@jest/types": "^29.6.3", - "@litejs/dom": "^24.8.0", "@microsoft/fetch-event-source": "^2.0.1", "@playwright/test": "^1.48.2", "@statoscope/cli": "^5.28.2", diff --git a/src/@types/light-js-dom.d.ts b/src/@types/light-js-dom.d.ts deleted file mode 100644 index d216c97115..0000000000 --- a/src/@types/light-js-dom.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -declare module '@litejs/dom' { - export type HtmlElement = HTMLElement & { - attributes?: { - names: () => string[]; - }; - }; - - interface Document { - createElement: (tag: string) => HTMLElement; - } - - export const document: Document; -} diff --git a/src/ui/libs/DatalensChartkit/ChartKit/components/Widget/components/Table/Table.tsx b/src/ui/libs/DatalensChartkit/ChartKit/components/Widget/components/Table/Table.tsx index 53abc833d9..06a5b3c6e4 100644 --- a/src/ui/libs/DatalensChartkit/ChartKit/components/Widget/components/Table/Table.tsx +++ b/src/ui/libs/DatalensChartkit/ChartKit/components/Widget/components/Table/Table.tsx @@ -345,9 +345,6 @@ export class Table extends React.PureComponent { nullBeforeNumbers // To avoid drawing No Data line when after pagination there is only a footer renderEmptyRow={onlyFooterExists ? () => null : undefined} - onError={(error) => { - throw error; - }} /> ); } diff --git a/src/ui/libs/DatalensChartkit/modules/html-generator/index.ts b/src/ui/libs/DatalensChartkit/modules/html-generator/index.ts index ba57622ef6..4c11b7d0d2 100644 --- a/src/ui/libs/DatalensChartkit/modules/html-generator/index.ts +++ b/src/ui/libs/DatalensChartkit/modules/html-generator/index.ts @@ -1,5 +1,3 @@ -import type {HtmlElement} from '@litejs/dom'; -import {document as sandboxDocument} from '@litejs/dom'; import escape from 'lodash/escape'; import type {ChartKitHtmlItem} from '../../../../../shared'; @@ -24,13 +22,13 @@ type GenerateHtmlOptions = { tooltipId?: string; }; -function jsonToHtml( - item?: ChartKitHtmlItem | string | (ChartKitHtmlItem | string)[], +export function generateHtml( + item?: ChartKitHtmlItem | ChartKitHtmlItem[] | string, options: GenerateHtmlOptions = {}, ): string { if (item) { if (Array.isArray(item)) { - return item.map((it) => jsonToHtml(it, options)).join(''); + return item.map((it) => generateHtml(it, options)).join(''); } if (typeof item === 'string') { @@ -103,62 +101,10 @@ function jsonToHtml( themeStyle = getThemeStyle(theme, dataThemeId); } - elem.innerHTML = `${themeStyle}${jsonToHtml(content, nextOptions)}`; + elem.innerHTML = `${themeStyle}${generateHtml(content, nextOptions)}`; return elem.outerHTML; } return ''; } - -function nodeToJson(node: HtmlElement) { - if (!node?.tagName) { - return node.textContent ?? ''; - } - - const attrs: string[] | undefined = node.attributes?.names(); - const style = node?.getAttribute('style'); - - let content: any = Array.from(node.childNodes).map((childNode) => - nodeToJson(childNode as HtmlElement), - ); - if (content?.length === 1) { - content = content[0]; - } - - const result: ChartKitHtmlItem = { - tag: node.tagName.toLowerCase(), - content, - attributes: attrs?.reduce((acc, attr) => { - return { - ...acc, - [attr]: node?.getAttribute(attr), - }; - }, {}), - style: style - ? Object.fromEntries(style?.split(';').map((rule) => rule.split(':'))) - : undefined, - }; - return result; -} - -function convertHtmlToJson(value: string) { - const fragment = sandboxDocument.createElement('div'); - fragment.innerHTML = value; - const elements = Array.from(fragment.childNodes) as HtmlElement[]; - - if (elements.length > 1) { - return elements.map(nodeToJson); - } - - return elements.length ? nodeToJson(elements[0]) : ''; -} - -export function generateHtml(item?: ChartKitHtmlItem | ChartKitHtmlItem[] | string): string { - if (typeof item === 'string') { - const json = convertHtmlToJson(item); - return jsonToHtml(json); - } - - return jsonToHtml(item); -}