From 865e5aecc99ebb8051f7b1c99b11710bd9709383 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Thu, 24 Jul 2025 17:24:59 +0100 Subject: [PATCH] Lexical: Source code input changes - Increased default source code view size. - Updated HTML generation to output each top-level block on its own line. --- .../html/__tests__/unit/LexicalHtml.test.ts | 2 +- resources/js/wysiwyg/lexical/html/index.ts | 13 ++++++++- .../unit/LexicalUtilsSplitNode.test.ts | 12 ++++---- ...exlcaiUtilsInsertNodeToNearestRoot.test.ts | 28 +++++++++---------- resources/sass/_editor.scss | 8 ++++++ 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/resources/js/wysiwyg/lexical/html/__tests__/unit/LexicalHtml.test.ts b/resources/js/wysiwyg/lexical/html/__tests__/unit/LexicalHtml.test.ts index e5064121a..b466ee34a 100644 --- a/resources/js/wysiwyg/lexical/html/__tests__/unit/LexicalHtml.test.ts +++ b/resources/js/wysiwyg/lexical/html/__tests__/unit/LexicalHtml.test.ts @@ -146,7 +146,7 @@ describe('HTML', () => { }); expect(html).toBe( - '

Hello

World

', + '

Hello

\n

World

', ); }); diff --git a/resources/js/wysiwyg/lexical/html/index.ts b/resources/js/wysiwyg/lexical/html/index.ts index 5018e10b4..de5e53bb8 100644 --- a/resources/js/wysiwyg/lexical/html/index.ts +++ b/resources/js/wysiwyg/lexical/html/index.ts @@ -85,7 +85,18 @@ export function $generateHtmlFromNodes( $appendNodesToHTML(editor, topLevelNode, container, selection); } - return container.innerHTML; + const nodeCode = []; + for (const node of container.childNodes) { + if ("outerHTML" in node) { + nodeCode.push(node.outerHTML) + } else { + const wrap = document.createElement('div'); + wrap.appendChild(node.cloneNode(true)); + nodeCode.push(wrap.innerHTML); + } + } + + return nodeCode.join('\n'); } function $appendNodesToHTML( diff --git a/resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalUtilsSplitNode.test.ts b/resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalUtilsSplitNode.test.ts index 54cd8b54f..6a415d008 100644 --- a/resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalUtilsSplitNode.test.ts +++ b/resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalUtilsSplitNode.test.ts @@ -38,7 +38,7 @@ describe('LexicalUtils#splitNode', () => { { _: 'split paragraph in between two text nodes', expectedHtml: - '

Hello

world

', + '

Hello

\n

world

', initialHtml: '

Helloworld

', splitOffset: 1, splitPath: [0], @@ -46,7 +46,7 @@ describe('LexicalUtils#splitNode', () => { { _: 'split paragraph before the first text node', expectedHtml: - '


Helloworld

', + '


\n

Helloworld

', initialHtml: '

Helloworld

', splitOffset: 0, splitPath: [0], @@ -54,7 +54,7 @@ describe('LexicalUtils#splitNode', () => { { _: 'split paragraph after the last text node', expectedHtml: - '

Helloworld


', + '

Helloworld

\n


', initialHtml: '

Helloworld

', splitOffset: 2, // Any offset that is higher than children size splitPath: [0], @@ -62,7 +62,7 @@ describe('LexicalUtils#splitNode', () => { { _: 'split list items between two text nodes', expectedHtml: - '' + + '\n' + '', initialHtml: '', splitOffset: 1, // Any offset that is higher than children size @@ -71,7 +71,7 @@ describe('LexicalUtils#splitNode', () => { { _: 'split list items before the first text node', expectedHtml: - '' + + '\n' + '', initialHtml: '', splitOffset: 0, // Any offset that is higher than children size @@ -83,7 +83,7 @@ describe('LexicalUtils#splitNode', () => { '' + + '\n' + '\n' + + '\n' + '