Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert importDOM changes from #5951 #6060

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/lexical-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
DOMChildConversion,
DOMConversion,
DOMConversionFn,
ElementFormatType,
LexicalEditor,
LexicalNode,
} from 'lexical';
Expand Down Expand Up @@ -58,7 +59,7 @@ export function $generateNodesFromDOM(
}
}
}
unwrapArtificalNodes(allArtificialNodes);
$unwrapArtificalNodes(allArtificialNodes);

return lexicalNodes;
}
Expand Down Expand Up @@ -312,12 +313,15 @@ function wrapContinuousInlines(
nodes: Array<LexicalNode>,
createWrapperFn: () => ElementNode,
): Array<LexicalNode> {
const textAlign = (domNode as HTMLElement).style
.textAlign as ElementFormatType;
const out: Array<LexicalNode> = [];
let continuousInlines: Array<LexicalNode> = [];
// wrap contiguous inline child nodes in para
for (let i = 0; i < nodes.length; i++) {
const node = nodes[i];
if ($isBlockElementNode(node)) {
node.setFormat(textAlign);
out.push(node);
} else {
continuousInlines.push(node);
Expand All @@ -326,6 +330,7 @@ function wrapContinuousInlines(
(i < nodes.length - 1 && $isBlockElementNode(nodes[i + 1]))
) {
const wrapper = createWrapperFn();
wrapper.setFormat(textAlign);
wrapper.append(...continuousInlines);
out.push(wrapper);
continuousInlines = [];
Expand All @@ -335,7 +340,7 @@ function wrapContinuousInlines(
return out;
}

function unwrapArtificalNodes(
function $unwrapArtificalNodes(
allArtificialNodes: Array<ArtificialNode__DO_NOT_USE>,
) {
for (const node of allArtificialNodes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ test.describe('HTML Links CopyAndPaste', () => {
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
dir="ltr"
style="text-align: left">
<span data-lexical-text="true">Line 0</span>
</p>
<ul class="PlaygroundEditorTheme__ul">
<li
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr"
style="text-align: left"
value="1">
<span data-lexical-text="true">â..ï¸.Â&nbsp;Line 1Â&nbsp;</span>
<a
Expand All @@ -213,6 +215,7 @@ test.describe('HTML Links CopyAndPaste', () => {
<li
class="PlaygroundEditorTheme__listItem PlaygroundEditorTheme__ltr"
dir="ltr"
style="text-align: left"
value="2">
<span data-lexical-text="true">â..ï¸.Â&nbsp;Line 2.</span>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ test.describe('HTML Tables CopyAndPaste', () => {
style="background-color: rgb(172, 206, 247); caret-color: transparent">
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
dir="ltr"
style="text-align: start">
<span data-lexical-text="true">d</span>
</p>
</td>
Expand Down
37 changes: 7 additions & 30 deletions packages/lexical-table/src/LexicalTableCellNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type {
DOMConversionOutput,
DOMExportOutput,
EditorConfig,
ElementFormatType,
LexicalEditor,
LexicalNode,
NodeKey,
Expand All @@ -23,7 +22,6 @@ import {addClassNamesToElement} from '@lexical/utils';
import {
$applyNodeReplacement,
$createParagraphNode,
$isBlockElementNode,
$isElementNode,
$isLineBreakNode,
$isTextNode,
Expand Down Expand Up @@ -85,11 +83,11 @@ export class TableCellNode extends ElementNode {
static importDOM(): DOMConversionMap | null {
return {
td: (node: Node) => ({
conversion: convertTableCellNodeElement,
conversion: $convertTableCellNodeElement,
priority: 0,
}),
th: (node: Node) => ({
conversion: convertTableCellNodeElement,
conversion: $convertTableCellNodeElement,
priority: 0,
}),
};
Expand Down Expand Up @@ -292,7 +290,7 @@ export class TableCellNode extends ElementNode {
}
}

export function convertTableCellNodeElement(
export function $convertTableCellNodeElement(
domNode: Node,
): DOMConversionOutput {
const domNode_ = domNode as HTMLTableCellElement;
Expand Down Expand Up @@ -325,39 +323,16 @@ export function convertTableCellNodeElement(
const hasLinethroughTextDecoration = textDecoration.includes('line-through');
const hasItalicFontStyle = style.fontStyle === 'italic';
const hasUnderlineTextDecoration = textDecoration.includes('underline');
const textAlign = style.textAlign;
return {
after: (childLexicalNodes) => {
const children = [];
let paragraphNode = $createParagraphNode().setFormat(
textAlign as ElementFormatType,
);
if (childLexicalNodes.length === 0) {
children.push(paragraphNode);
childLexicalNodes.push($createParagraphNode());
}

childLexicalNodes.forEach((node) => {
if ($isBlockElementNode(node)) {
if (paragraphNode.getChildrenSize() !== 0) {
children.push(paragraphNode);
paragraphNode = $createParagraphNode().setFormat(
textAlign as ElementFormatType,
);
}
children.push(node);
} else {
paragraphNode.append(node);
}
});
if (paragraphNode.getChildrenSize() !== 0) {
children.push(paragraphNode);
}
return children;
return childLexicalNodes;
},
forChild: (lexicalNode, parentLexicalNode) => {
if ($isTableCellNode(parentLexicalNode) && !$isElementNode(lexicalNode)) {
const paragraphNode = $createParagraphNode();
paragraphNode.setFormat(textAlign as ElementFormatType);
if (
$isLineBreakNode(lexicalNode) &&
lexicalNode.getTextContent() === '\n'
Expand Down Expand Up @@ -387,6 +362,8 @@ export function convertTableCellNodeElement(
node: tableCellNode,
};
}
/** @deprecated renamed to $convertTableCellNodeElement by @lexical/eslint-plugin rules-of-lexical */
export const convertTableCellNodeElement = $convertTableCellNodeElement;

export function $createTableCellNode(
headerState: TableCellHeaderState,
Expand Down
Loading