Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfeng33 committed Jan 15, 2025
1 parent ee06331 commit e6ab3af
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
BaseCodeBlockPlugin,
BaseCodeLinePlugin,
} from '../BaseCodeBlockPlugin';
import { htmlDeserializerCodeBlockStatic } from './htmlDeserializerCodeBlockStatic';

export const htmlDeserializerCodeBlock: HtmlDeserializer = {
parse: ({ element }) => {
Expand Down Expand Up @@ -43,11 +42,4 @@ export const htmlDeserializerCodeBlock: HtmlDeserializer = {
},
},
],
toNodeProps({ element }) {
const staticCodeBlock = htmlDeserializerCodeBlockStatic(element);

if (staticCodeBlock) {
return staticCodeBlock;
}
},
};

This file was deleted.

1 change: 0 additions & 1 deletion packages/code-block/src/lib/deserializer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
*/

export * from './htmlDeserializerCodeBlock';
export * from './htmlDeserializerCodeBlockStatic';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { SlateEditor } from '../../../editor';
import type { DeserializeHtmlNodeReturnType } from '../types';

import { isSlateNode } from '../../../static';
import { htmlBodyToFragment } from './htmlBodyToFragment';
import { htmlBrToNewLine } from './htmlBrToNewLine';
import { htmlElementToElement } from './htmlElementToElement';
Expand Down Expand Up @@ -28,7 +29,11 @@ export const deserializeHtmlNode =
if (fragment) return fragment;

// element
const element = htmlElementToElement(editor, node as HTMLElement);
const element = htmlElementToElement(
editor,
node as HTMLElement,
isSlateNode(node as HTMLElement)
);

if (element) return element;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type { SlateEditor } from '../../../editor';
import type { DeserializeHtmlChildren } from '../types';

import { isSlateNode } from '../../../static';
import { deserializeHtmlNode } from './deserializeHtmlNode';

export const deserializeHtmlNodeChildren = (
editor: SlateEditor,
node: ChildNode | HTMLElement
) =>
Array.from(node.childNodes).flatMap(
deserializeHtmlNode(editor)
) as DeserializeHtmlChildren[];
node: ChildNode | HTMLElement,
isSlate = false
): DeserializeHtmlChildren[] => {
return Array.from(node.childNodes).flatMap((child) => {
if (child.nodeType === 1 && !isSlateNode(child as HTMLElement) && isSlate) {
return deserializeHtmlNodeChildren(editor, child as HTMLElement, isSlate);
}

return deserializeHtmlNode(editor)(child);
}) as DeserializeHtmlChildren[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { pipeDeserializeHtmlElement } from './pipeDeserializeHtmlElement';
/** Deserialize HTML to Element. */
export const htmlElementToElement = (
editor: SlateEditor,
element: HTMLElement
element: HTMLElement,
isSlate = false
) => {
const deserialized = pipeDeserializeHtmlElement(editor, element);

Expand All @@ -20,7 +21,7 @@ export const htmlElementToElement = (

let descendants =
node.children ??
(deserializeHtmlNodeChildren(editor, element) as Descendant[]);
(deserializeHtmlNodeChildren(editor, element, isSlate) as Descendant[]);

if (descendants.length === 0 || withoutChildren || isSlateVoid(element)) {
descendants = [{ text: '' }];
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/lib/static/deserialize/checkUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ export const isSlateElement = (element: HTMLElement) => {
return element.dataset.slateNode === 'element';
};

export const isSlateString = (element: HTMLElement) => {
export const isSlateText = (element: HTMLElement) => {
return element.dataset.slateNode === 'text';
};

export const isSlateString = (element: HTMLElement) => {
return element.dataset.slateString === 'true';
};

export const isSlateLeaf = (element: HTMLElement) => {
return element.dataset.slateLeaf === 'true';
};
Expand All @@ -19,7 +23,8 @@ export const isSlateNode = (element: HTMLElement) => {
isSlateLeaf(element) ||
isSlateElement(element) ||
isSlateVoid(element) ||
isSlateString(element)
isSlateString(element) ||
isSlateText(element)
);
};

Expand Down
14 changes: 0 additions & 14 deletions packages/table/src/lib/BaseTablePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
bindFirst,
createSlatePlugin,
createTSlatePlugin,
isSlatePluginElement,
} from '@udecode/plate';

import type { TTableCellElement } from './types';
Expand Down Expand Up @@ -187,19 +186,6 @@ export const BaseTablePlugin = createTSlatePlugin<TableConfig>({
parsers: {
html: {
deserializer: {
parse: ({ element, type }) => {
const parent = element.parentNode?.parentNode;

if (
parent &&
element.tagName === 'TABLE' &&
isSlatePluginElement(parent as HTMLElement, type)
) {
return;
}

return { type };
},
rules: [{ validNodeName: 'TABLE' }],
},
},
Expand Down

0 comments on commit e6ab3af

Please sign in to comment.