Skip to content

Commit 865e5ae

Browse files
committed
Lexical: Source code input changes
- Increased default source code view size. - Updated HTML generation to output each top-level block on its own line.
1 parent ae4d1d8 commit 865e5ae

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
lines changed

resources/js/wysiwyg/lexical/html/__tests__/unit/LexicalHtml.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('HTML', () => {
146146
});
147147

148148
expect(html).toBe(
149-
'<p>Hello</p><p>World</p>',
149+
'<p>Hello</p>\n<p>World</p>',
150150
);
151151
});
152152

resources/js/wysiwyg/lexical/html/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,18 @@ export function $generateHtmlFromNodes(
8585
$appendNodesToHTML(editor, topLevelNode, container, selection);
8686
}
8787

88-
return container.innerHTML;
88+
const nodeCode = [];
89+
for (const node of container.childNodes) {
90+
if ("outerHTML" in node) {
91+
nodeCode.push(node.outerHTML)
92+
} else {
93+
const wrap = document.createElement('div');
94+
wrap.appendChild(node.cloneNode(true));
95+
nodeCode.push(wrap.innerHTML);
96+
}
97+
}
98+
99+
return nodeCode.join('\n');
89100
}
90101

91102
function $appendNodesToHTML(

resources/js/wysiwyg/lexical/utils/__tests__/unit/LexicalUtilsSplitNode.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,31 @@ describe('LexicalUtils#splitNode', () => {
3838
{
3939
_: 'split paragraph in between two text nodes',
4040
expectedHtml:
41-
'<p>Hello</p><p>world</p>',
41+
'<p>Hello</p>\n<p>world</p>',
4242
initialHtml: '<p><span>Hello</span><span>world</span></p>',
4343
splitOffset: 1,
4444
splitPath: [0],
4545
},
4646
{
4747
_: 'split paragraph before the first text node',
4848
expectedHtml:
49-
'<p><br></p><p>Helloworld</p>',
49+
'<p><br></p>\n<p>Helloworld</p>',
5050
initialHtml: '<p><span>Hello</span><span>world</span></p>',
5151
splitOffset: 0,
5252
splitPath: [0],
5353
},
5454
{
5555
_: 'split paragraph after the last text node',
5656
expectedHtml:
57-
'<p>Helloworld</p><p><br></p>',
57+
'<p>Helloworld</p>\n<p><br></p>',
5858
initialHtml: '<p><span>Hello</span><span>world</span></p>',
5959
splitOffset: 2, // Any offset that is higher than children size
6060
splitPath: [0],
6161
},
6262
{
6363
_: 'split list items between two text nodes',
6464
expectedHtml:
65-
'<ul><li>Hello</li></ul>' +
65+
'<ul><li>Hello</li></ul>\n' +
6666
'<ul><li>world</li></ul>',
6767
initialHtml: '<ul><li><span>Hello</span><span>world</span></li></ul>',
6868
splitOffset: 1, // Any offset that is higher than children size
@@ -71,7 +71,7 @@ describe('LexicalUtils#splitNode', () => {
7171
{
7272
_: 'split list items before the first text node',
7373
expectedHtml:
74-
'<ul><li></li></ul>' +
74+
'<ul><li></li></ul>\n' +
7575
'<ul><li>Helloworld</li></ul>',
7676
initialHtml: '<ul><li><span>Hello</span><span>world</span></li></ul>',
7777
splitOffset: 0, // Any offset that is higher than children size
@@ -83,7 +83,7 @@ describe('LexicalUtils#splitNode', () => {
8383
'<ul>' +
8484
'<li>Before</li>' +
8585
'<li style="list-style: none;"><ul><li>Hello</li></ul></li>' +
86-
'</ul>' +
86+
'</ul>\n' +
8787
'<ul>' +
8888
'<li style="list-style: none;"><ul><li>world</li></ul></li>' +
8989
'<li>After</li>' +

resources/js/wysiwyg/lexical/utils/__tests__/unit/LexlcaiUtilsInsertNodeToNearestRoot.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
4646
{
4747
_: 'insert into paragraph in between two text nodes',
4848
expectedHtml:
49-
'<p>Hello</p><test-decorator></test-decorator><p>world</p>',
49+
'<p>Hello</p>\n<test-decorator></test-decorator>\n<p>world</p>',
5050
initialHtml: '<p><span>Helloworld</span></p>',
5151
selectionOffset: 5, // Selection on text node after "Hello" world
5252
selectionPath: [0, 0],
@@ -57,8 +57,8 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
5757
'<ul>' +
5858
'<li>Before</li>' +
5959
'<li style="list-style: none;"><ul><li>Hello</li></ul></li>' +
60-
'</ul>' +
61-
'<test-decorator></test-decorator>' +
60+
'</ul>\n' +
61+
'<test-decorator></test-decorator>\n' +
6262
'<ul>' +
6363
'<li style="list-style: none;"><ul><li>world</li></ul></li>' +
6464
'<li>After</li>' +
@@ -74,16 +74,16 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
7474
},
7575
{
7676
_: 'insert into empty paragraph',
77-
expectedHtml: '<p><br></p><test-decorator></test-decorator><p><br></p>',
77+
expectedHtml: '<p><br></p>\n<test-decorator></test-decorator>\n<p><br></p>',
7878
initialHtml: '<p></p>',
7979
selectionOffset: 0, // Selection on text node after "Hello" world
8080
selectionPath: [0],
8181
},
8282
{
8383
_: 'insert in the end of paragraph',
8484
expectedHtml:
85-
'<p>Hello world</p>' +
86-
'<test-decorator></test-decorator>' +
85+
'<p>Hello world</p>\n' +
86+
'<test-decorator></test-decorator>\n' +
8787
'<p><br></p>',
8888
initialHtml: '<p>Hello world</p>',
8989
selectionOffset: 12, // Selection on text node after "Hello" world
@@ -92,8 +92,8 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
9292
{
9393
_: 'insert in the beginning of paragraph',
9494
expectedHtml:
95-
'<p><br></p>' +
96-
'<test-decorator></test-decorator>' +
95+
'<p><br></p>\n' +
96+
'<test-decorator></test-decorator>\n' +
9797
'<p>Hello world</p>',
9898
initialHtml: '<p>Hello world</p>',
9999
selectionOffset: 0, // Selection on text node after "Hello" world
@@ -102,9 +102,9 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
102102
{
103103
_: 'insert with selection on root start',
104104
expectedHtml:
105-
'<test-decorator></test-decorator>' +
106-
'<test-decorator></test-decorator>' +
107-
'<p>Before</p>' +
105+
'<test-decorator></test-decorator>\n' +
106+
'<test-decorator></test-decorator>\n' +
107+
'<p>Before</p>\n' +
108108
'<p>After</p>',
109109
initialHtml:
110110
'<test-decorator></test-decorator>' +
@@ -116,8 +116,8 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
116116
{
117117
_: 'insert with selection on root child',
118118
expectedHtml:
119-
'<p>Before</p>' +
120-
'<test-decorator></test-decorator>' +
119+
'<p>Before</p>\n' +
120+
'<test-decorator></test-decorator>\n' +
121121
'<p>After</p>',
122122
initialHtml: '<p>Before</p><p>After</p>',
123123
selectionOffset: 1,
@@ -126,7 +126,7 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
126126
{
127127
_: 'insert with selection on root end',
128128
expectedHtml:
129-
'<p>Before</p>' +
129+
'<p>Before</p>\n' +
130130
'<test-decorator></test-decorator>',
131131
initialHtml: '<p>Before</p>',
132132
selectionOffset: 1,

resources/sass/_editor.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,14 @@ textarea.editor-form-field-input {
681681
}
682682
}
683683

684+
// Specific field styles
685+
textarea.editor-form-field-input[name="source"] {
686+
width: 1000px;
687+
height: 600px;
688+
max-height: 60vh;
689+
max-width: 80vw;
690+
}
691+
684692
// Editor theme styles
685693
.editor-theme-bold {
686694
font-weight: bold;

0 commit comments

Comments
 (0)