1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Updated toolbar & text node exporting

- Updated toolbar to match existing editor, including dynamic RTL/LTR
  controls.
- Updated text node handling to not include spans and extra classes when
  not needed. Added & update tests to cover.
This commit is contained in:
Dan Brown
2024-09-23 17:36:16 +01:00
parent 8b32e6c15a
commit a62d8381be
16 changed files with 152 additions and 51 deletions

View File

@ -330,7 +330,7 @@ describe('LexicalEventHelpers', () => {
const suite = [
{
expectedHTML:
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><span data-lexical-text="true">Get schwifty!</span></p></div>',
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><span style="color: rgb(0, 0, 0);" data-lexical-text="true">Get schwifty!</span></p></div>',
inputs: [
pasteHTML(
`<b style="font-weight:normal;" id="docs-internal-guid-2c706577-7fff-f54a-fe65-12f480020fac"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Get schwifty!</span></b>`,
@ -340,7 +340,7 @@ describe('LexicalEventHelpers', () => {
},
{
expectedHTML:
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><strong class="editor-text-bold" data-lexical-text="true">Get schwifty!</strong></p></div>',
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><strong class="editor-text-bold" style="color: rgb(0, 0, 0);" data-lexical-text="true">Get schwifty!</strong></p></div>',
inputs: [
pasteHTML(
`<b style="font-weight:normal;" id="docs-internal-guid-9db03964-7fff-c26c-8b1e-9484fb3b54a4"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:700;font-style:normal;font-variant:normal;text-decoration:none;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Get schwifty!</span></b>`,
@ -350,7 +350,7 @@ describe('LexicalEventHelpers', () => {
},
{
expectedHTML:
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><em class="editor-text-italic" data-lexical-text="true">Get schwifty!</em></p></div>',
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><em class="editor-text-italic" style="color: rgb(0, 0, 0);" data-lexical-text="true">Get schwifty!</em></p></div>',
inputs: [
pasteHTML(
`<b style="font-weight:normal;" id="docs-internal-guid-9db03964-7fff-c26c-8b1e-9484fb3b54a4"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:italic;font-variant:normal;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Get schwifty!</span></b>`,
@ -360,7 +360,7 @@ describe('LexicalEventHelpers', () => {
},
{
expectedHTML:
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><span class="editor-text-strikethrough" data-lexical-text="true">Get schwifty!</span></p></div>',
'<div contenteditable="true" style="user-select: text; white-space: pre-wrap; word-break: break-word;" data-lexical-editor="true"><p class="editor-paragraph"><span class="editor-text-strikethrough" style="color: rgb(0, 0, 0);" data-lexical-text="true">Get schwifty!</span></p></div>',
inputs: [
pasteHTML(
`<b style="font-weight:normal;" id="docs-internal-guid-9db03964-7fff-c26c-8b1e-9484fb3b54a4"><span style="font-size:11pt;font-family:Arial;color:#000000;background-color:transparent;font-weight:400;font-style:normal;font-variant:normal;text-decoration:line-through;vertical-align:baseline;white-space:pre;white-space:pre-wrap;">Get schwifty!</span></b>`,

View File

@ -38,7 +38,7 @@ describe('LexicalUtils#splitNode', () => {
{
_: 'split paragraph in between two text nodes',
expectedHtml:
'<p><span style="white-space: pre-wrap;">Hello</span></p><p><span style="white-space: pre-wrap;">world</span></p>',
'<p>Hello</p><p>world</p>',
initialHtml: '<p><span>Hello</span><span>world</span></p>',
splitOffset: 1,
splitPath: [0],
@ -46,7 +46,7 @@ describe('LexicalUtils#splitNode', () => {
{
_: 'split paragraph before the first text node',
expectedHtml:
'<p><br></p><p><span style="white-space: pre-wrap;">Hello</span><span style="white-space: pre-wrap;">world</span></p>',
'<p><br></p><p>Helloworld</p>',
initialHtml: '<p><span>Hello</span><span>world</span></p>',
splitOffset: 0,
splitPath: [0],
@ -54,7 +54,7 @@ describe('LexicalUtils#splitNode', () => {
{
_: 'split paragraph after the last text node',
expectedHtml:
'<p><span style="white-space: pre-wrap;">Hello</span><span style="white-space: pre-wrap;">world</span></p><p><br></p>',
'<p>Helloworld</p><p><br></p>',
initialHtml: '<p><span>Hello</span><span>world</span></p>',
splitOffset: 2, // Any offset that is higher than children size
splitPath: [0],
@ -62,8 +62,8 @@ describe('LexicalUtils#splitNode', () => {
{
_: 'split list items between two text nodes',
expectedHtml:
'<ul><li><span style="white-space: pre-wrap;">Hello</span></li></ul>' +
'<ul><li><span style="white-space: pre-wrap;">world</span></li></ul>',
'<ul><li>Hello</li></ul>' +
'<ul><li>world</li></ul>',
initialHtml: '<ul><li><span>Hello</span><span>world</span></li></ul>',
splitOffset: 1, // Any offset that is higher than children size
splitPath: [0, 0],
@ -72,7 +72,7 @@ describe('LexicalUtils#splitNode', () => {
_: 'split list items before the first text node',
expectedHtml:
'<ul><li></li></ul>' +
'<ul><li><span style="white-space: pre-wrap;">Hello</span><span style="white-space: pre-wrap;">world</span></li></ul>',
'<ul><li>Helloworld</li></ul>',
initialHtml: '<ul><li><span>Hello</span><span>world</span></li></ul>',
splitOffset: 0, // Any offset that is higher than children size
splitPath: [0, 0],
@ -81,12 +81,12 @@ describe('LexicalUtils#splitNode', () => {
_: 'split nested list items',
expectedHtml:
'<ul>' +
'<li><span style="white-space: pre-wrap;">Before</span></li>' +
'<li><ul><li><span style="white-space: pre-wrap;">Hello</span></li></ul></li>' +
'<li>Before</li>' +
'<li><ul><li>Hello</li></ul></li>' +
'</ul>' +
'<ul>' +
'<li><ul><li><span style="white-space: pre-wrap;">world</span></li></ul></li>' +
'<li><span style="white-space: pre-wrap;">After</span></li>' +
'<li><ul><li>world</li></ul></li>' +
'<li>After</li>' +
'</ul>',
initialHtml:
'<ul>' +

View File

@ -46,7 +46,7 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
{
_: 'insert into paragraph in between two text nodes',
expectedHtml:
'<p><span style="white-space: pre-wrap;">Hello</span></p><test-decorator></test-decorator><p><span style="white-space: pre-wrap;">world</span></p>',
'<p>Hello</p><test-decorator></test-decorator><p>world</p>',
initialHtml: '<p><span>Helloworld</span></p>',
selectionOffset: 5, // Selection on text node after "Hello" world
selectionPath: [0, 0],
@ -55,13 +55,13 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
_: 'insert into nested list items',
expectedHtml:
'<ul>' +
'<li><span style="white-space: pre-wrap;">Before</span></li>' +
'<li><ul><li><span style="white-space: pre-wrap;">Hello</span></li></ul></li>' +
'<li>Before</li>' +
'<li><ul><li>Hello</li></ul></li>' +
'</ul>' +
'<test-decorator></test-decorator>' +
'<ul>' +
'<li><ul><li><span style="white-space: pre-wrap;">world</span></li></ul></li>' +
'<li><span style="white-space: pre-wrap;">After</span></li>' +
'<li><ul><li>world</li></ul></li>' +
'<li>After</li>' +
'</ul>',
initialHtml:
'<ul>' +
@ -82,7 +82,7 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
{
_: 'insert in the end of paragraph',
expectedHtml:
'<p><span style="white-space: pre-wrap;">Hello world</span></p>' +
'<p>Hello world</p>' +
'<test-decorator></test-decorator>' +
'<p><br></p>',
initialHtml: '<p>Hello world</p>',
@ -94,7 +94,7 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
expectedHtml:
'<p><br></p>' +
'<test-decorator></test-decorator>' +
'<p><span style="white-space: pre-wrap;">Hello world</span></p>',
'<p>Hello world</p>',
initialHtml: '<p>Hello world</p>',
selectionOffset: 0, // Selection on text node after "Hello" world
selectionPath: [0, 0],
@ -104,8 +104,8 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
expectedHtml:
'<test-decorator></test-decorator>' +
'<test-decorator></test-decorator>' +
'<p><span style="white-space: pre-wrap;">Before</span></p>' +
'<p><span style="white-space: pre-wrap;">After</span></p>',
'<p>Before</p>' +
'<p>After</p>',
initialHtml:
'<test-decorator></test-decorator>' +
'<p><span>Before</span></p>' +
@ -116,9 +116,9 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
{
_: 'insert with selection on root child',
expectedHtml:
'<p><span style="white-space: pre-wrap;">Before</span></p>' +
'<p>Before</p>' +
'<test-decorator></test-decorator>' +
'<p><span style="white-space: pre-wrap;">After</span></p>',
'<p>After</p>',
initialHtml: '<p>Before</p><p>After</p>',
selectionOffset: 1,
selectionPath: [],
@ -126,7 +126,7 @@ describe('LexicalUtils#insertNodeToNearestRoot', () => {
{
_: 'insert with selection on root end',
expectedHtml:
'<p><span style="white-space: pre-wrap;">Before</span></p>' +
'<p>Before</p>' +
'<test-decorator></test-decorator>',
initialHtml: '<p>Before</p>',
selectionOffset: 1,