1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-23 23:02:08 +03:00

Packages: Updated npm packages

Spent way too many hours debugging through issues from jsdom changes.
This commit is contained in:
Dan Brown
2025-08-30 22:18:09 +01:00
parent 64b06bcf61
commit a27ce6e915
11 changed files with 2054 additions and 1260 deletions

View File

@@ -2708,6 +2708,8 @@ export function updateDOMSelection(
const range = document.createRange();
range.selectNode(selectionTarget);
selectionRect = range.getBoundingClientRect();
} else if (selectionTarget instanceof Range) {
selectionRect = selectionTarget.getBoundingClientRect();
} else {
selectionRect = selectionTarget.getBoundingClientRect();
}

View File

@@ -2510,8 +2510,8 @@ describe('LexicalEditor tests', () => {
);
});
expect(onError).toBeCalledWith(updateError);
expect(textListener).toBeCalledWith('Hello\n\nworld');
expect(onError).toHaveBeenCalledWith(updateError);
expect(textListener).toHaveBeenCalledWith('Hello\n\nworld');
expect(updateListener.mock.lastCall[0].prevEditorState).toBe(editorState);
});

View File

@@ -138,7 +138,7 @@ describe('LexicalNode tests', () => {
const validNode = new TextNode(textNode.__text, textNode.__key);
expect(textNode.getLatest()).toBe(textNode);
expect(validNode.getLatest()).toBe(textNode);
expect(() => new TestNode(textNode.__key)).toThrowError(
expect(() => new TestNode(textNode.__key)).toThrow(
/TestNode.*re-use key.*TextNode/,
);
});

View File

@@ -864,4 +864,26 @@ export function dispatchEditorMouseClick(editor: LexicalEditor, clientX: number,
});
dom?.dispatchEvent(event);
editor.commitUpdates();
}
export function patchRange() {
const RangePrototype = Object.getPrototypeOf(document.createRange());
RangePrototype.getBoundingClientRect = function (): DOMRect {
const rect = {
bottom: 0,
height: 0,
left: 0,
right: 0,
top: 0,
width: 0,
x: 0,
y: 0,
};
return {
...rect,
toJSON() {
return rect;
},
};
};
}

View File

@@ -18,10 +18,12 @@ import {
} from 'lexical';
import {
$createTestElementNode,
createTestEditor,
$createTestElementNode,
createTestEditor, patchRange,
} from '../../../__tests__/utils';
patchRange();
describe('LexicalElementNode tests', () => {
let container: HTMLElement;
@@ -54,6 +56,7 @@ describe('LexicalElementNode tests', () => {
editor = createTestEditor();
editor.setRootElement(root);
root.focus();
// Insert initial block
await update(() => {
@@ -63,11 +66,11 @@ describe('LexicalElementNode tests', () => {
// Prevent text nodes from combining.
text2.setMode('segmented');
const text3 = $createTextNode('Baz');
// Some operations require a selection to exist, hence
// we make a selection in the setup code.
text.select(0, 0);
block.append(text, text2, text3);
$getRoot().append(block);
// Some operations require a selection to exist, hence
// we make a selection in the setup code.
text.select(0, 0);
});
}

View File

@@ -146,12 +146,12 @@ describe('LexicalHeadlessEditor', () => {
editor.dispatchCommand(CONTROLLED_TEXT_INSERTION_COMMAND, 'foo');
});
expect(onUpdate).toBeCalled();
expect(onCommand).toBeCalledWith('foo', expect.anything());
expect(onTransform).toBeCalledWith(
expect(onUpdate).toHaveBeenCalled();
expect(onCommand).toHaveBeenCalledWith('foo', expect.anything());
expect(onTransform).toHaveBeenCalledWith(
expect.objectContaining({__type: 'paragraph'}),
);
expect(onTextContent).toBeCalledWith('Helloworld');
expect(onTextContent).toHaveBeenCalledWith('Helloworld');
});
it('can preserve selection for pending editor state (within update loop)', async () => {

View File

@@ -37,12 +37,12 @@ import {
TextNode,
} from 'lexical';
import {
$assertRangeSelection,
$createTestDecoratorNode,
$createTestElementNode,
createTestEditor,
initializeClipboard,
invariant,
$assertRangeSelection,
$createTestDecoratorNode,
$createTestElementNode,
createTestEditor,
initializeClipboard,
invariant, patchRange,
} from 'lexical/__tests__/utils';
import {
@@ -91,24 +91,7 @@ jest.mock('lexical/shared/environment', () => {
return {...originalModule, IS_FIREFOX: true};
});
Range.prototype.getBoundingClientRect = function (): DOMRect {
const rect = {
bottom: 0,
height: 0,
left: 0,
right: 0,
top: 0,
width: 0,
x: 0,
y: 0,
};
return {
...rect,
toJSON() {
return rect;
},
};
};
patchRange();
describe('LexicalSelection tests', () => {
let container: HTMLElement;

View File

@@ -422,9 +422,6 @@ export function setNativeSelection(
range.setEnd(focusNode, focusOffset);
domSelection.removeAllRanges();
domSelection.addRange(range);
Promise.resolve().then(() => {
document.dispatchEvent(new Event('selectionchange'));
});
}
export function setNativeSelectionWithPaths(
@@ -647,6 +644,8 @@ export async function applySelectionInputs(
editor: LexicalEditor,
) {
const rootElement = editor.getRootElement()!;
// Set initial focus as if we're in the editor
rootElement.focus();
for (let i = 0; i < inputs.length; i++) {
const input = inputs[i];

View File

@@ -114,7 +114,7 @@ describe('LexicalTableNode tests', () => {
});
// Make sure paragraph is inserted inside empty cells
expect(testEnv.innerHTML).toBe(
`<table style="border-collapse: collapse; table-layout: fixed; width: 468pt;"><colgroup><col><col></colgroup><tr style="height: 22.015pt;"><td style="border-left: 1pt solid #000000; border-right: 1pt solid #000000; border-bottom: 1pt solid #000000; border-top: 1pt solid #000000; vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><span style="color: rgb(0, 0, 0);" data-lexical-text="true">Hello there</span></p></td><td style="border-left: 1pt solid #000000; border-right: 1pt solid #000000; border-bottom: 1pt solid #000000; border-top: 1pt solid #000000; vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><span style="color: rgb(0, 0, 0);" data-lexical-text="true">General Kenobi!</span></p></td></tr><tr style="height: 22.015pt;"><td style="border-left: 1pt solid #000000; border-right: 1pt solid #000000; border-bottom: 1pt solid #000000; border-top: 1pt solid #000000; vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><span style="color: rgb(0, 0, 0);" data-lexical-text="true">Lexical is nice</span></p></td><td style="border-left: 1pt solid #000000; border-right: 1pt solid #000000; border-bottom: 1pt solid #000000; border-top: 1pt solid #000000; vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><br></p></td></tr></table>`,
`<table style="border-collapse: collapse; table-layout: fixed; width: 468pt;"><colgroup><col><col></colgroup><tr style="height: 22.015pt;"><td style="border-left: 1pt solid rgb(0, 0, 0); border-right: 1pt solid rgb(0, 0, 0); border-bottom: 1pt solid rgb(0, 0, 0); border-top: 1pt solid rgb(0, 0, 0); vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><span style="color: rgb(0, 0, 0);" data-lexical-text="true">Hello there</span></p></td><td style="border-left: 1pt solid rgb(0, 0, 0); border-right: 1pt solid rgb(0, 0, 0); border-bottom: 1pt solid rgb(0, 0, 0); border-top: 1pt solid rgb(0, 0, 0); vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><span style="color: rgb(0, 0, 0);" data-lexical-text="true">General Kenobi!</span></p></td></tr><tr style="height: 22.015pt;"><td style="border-left: 1pt solid rgb(0, 0, 0); border-right: 1pt solid rgb(0, 0, 0); border-bottom: 1pt solid rgb(0, 0, 0); border-top: 1pt solid rgb(0, 0, 0); vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><span style="color: rgb(0, 0, 0);" data-lexical-text="true">Lexical is nice</span></p></td><td style="border-left: 1pt solid rgb(0, 0, 0); border-right: 1pt solid rgb(0, 0, 0); border-bottom: 1pt solid rgb(0, 0, 0); border-top: 1pt solid rgb(0, 0, 0); vertical-align: top; padding: 5pt 5pt 5pt 5pt; overflow: hidden; overflow-wrap: break-word;"><p><br></p></td></tr></table>`,
);
});