From c8c83c1e1df9eb441c9f1efeaac34bcfa780b2e2 Mon Sep 17 00:00:00 2001 From: AzazelN28 Date: Wed, 20 Nov 2024 12:18:35 +0100 Subject: [PATCH] :paperclip: Fix some missing changes --- frontend/text-editor/editor/Event.test.js | 29 - frontend/text-editor/jsconfig.json | 2 +- frontend/text-editor/package.json | 5 +- frontend/text-editor/scripts/build.sh | 3 - .../text-editor/{ => src}/editor/Event.js | 0 frontend/text-editor/src/editor/Event.test.js | 29 + .../{ => src}/editor/TextEditor.css | 0 .../{ => src}/editor/TextEditor.js | 16 +- .../{ => src}/editor/TextEditor.test.js | 44 +- .../{ => src}/editor/clipboard/copy.js | 0 .../{ => src}/editor/clipboard/cut.js | 0 .../{ => src}/editor/clipboard/index.js | 0 .../{ => src}/editor/clipboard/paste.js | 2 +- .../editor/commands/CommandMutations.js | 0 .../editor/commands/CommandMutations.test.js | 6 +- .../{ => src}/editor/commands/deleteByCut.js | 0 .../editor/commands/deleteContentBackward.js | 0 .../editor/commands/deleteContentForward.js | 0 .../{ => src}/editor/commands/index.js | 0 .../editor/commands/insertParagraph.js | 0 .../{ => src}/editor/commands/insertText.js | 0 .../{ => src}/editor/content/Text.js | 0 .../{ => src}/editor/content/Text.test.js | 0 .../{ => src}/editor/content/dom/Color.js | 0 .../{ => src}/editor/content/dom/Content.js | 0 .../editor/content/dom/Content.test.js | 69 +- .../{ => src}/editor/content/dom/Element.js | 0 .../editor/content/dom/Element.test.js | 40 +- .../{ => src}/editor/content/dom/Inline.js | 0 .../editor/content/dom/Inline.test.js | 24 +- .../{ => src}/editor/content/dom/LineBreak.js | 0 .../editor/content/dom/LineBreak.test.js | 10 +- .../{ => src}/editor/content/dom/Paragraph.js | 3 +- .../editor/content/dom/Paragraph.test.js | 39 +- .../{ => src}/editor/content/dom/Root.js | 3 +- .../{ => src}/editor/content/dom/Root.test.js | 12 +- .../{ => src}/editor/content/dom/Style.js | 0 .../editor/content/dom/Style.test.js | 18 +- .../{ => src}/editor/content/dom/TextNode.js | 0 .../editor/content/dom/TextNode.test.js | 20 +- .../editor/content/dom/TextNodeIterator.js | 0 .../content/dom/TextNodeIterator.test.js | 9 +- .../editor/controllers/ChangeController.js | 0 .../controllers/ChangeController.test.js | 8 +- .../{ => src}/editor/controllers/SafeGuard.js | 0 .../editor/controllers/SelectionController.js | 5 - .../controllers/SelectionController.test.js | 626 +++++++++--------- .../editor/controllers/SelectionDirection.js | 0 .../editor/debug/SelectionControllerDebug.js | 0 .../{ => src}/editor/layout/LayoutType.js | 0 .../{ => src}/editor/selection/Imposter.js | 0 .../editor/selection/Imposter.spec.js | 2 +- frontend/text-editor/{ => src}/index.html | 0 frontend/text-editor/{ => src}/main.js | 0 frontend/text-editor/{ => src}/style.css | 0 .../{ => src}/test/TextEditorMock.js | 8 +- frontend/text-editor/vite.config.js | 13 +- frontend/text-editor/yarn.lock | 10 + 58 files changed, 551 insertions(+), 504 deletions(-) delete mode 100644 frontend/text-editor/editor/Event.test.js delete mode 100755 frontend/text-editor/scripts/build.sh rename frontend/text-editor/{ => src}/editor/Event.js (100%) create mode 100644 frontend/text-editor/src/editor/Event.test.js rename frontend/text-editor/{ => src}/editor/TextEditor.css (100%) rename frontend/text-editor/{ => src}/editor/TextEditor.js (95%) rename frontend/text-editor/{ => src}/editor/TextEditor.test.js (71%) rename frontend/text-editor/{ => src}/editor/clipboard/copy.js (100%) rename frontend/text-editor/{ => src}/editor/clipboard/cut.js (100%) rename frontend/text-editor/{ => src}/editor/clipboard/index.js (100%) rename frontend/text-editor/{ => src}/editor/clipboard/paste.js (97%) rename frontend/text-editor/{ => src}/editor/commands/CommandMutations.js (100%) rename frontend/text-editor/{ => src}/editor/commands/CommandMutations.test.js (95%) rename frontend/text-editor/{ => src}/editor/commands/deleteByCut.js (100%) rename frontend/text-editor/{ => src}/editor/commands/deleteContentBackward.js (100%) rename frontend/text-editor/{ => src}/editor/commands/deleteContentForward.js (100%) rename frontend/text-editor/{ => src}/editor/commands/index.js (100%) rename frontend/text-editor/{ => src}/editor/commands/insertParagraph.js (100%) rename frontend/text-editor/{ => src}/editor/commands/insertText.js (100%) rename frontend/text-editor/{ => src}/editor/content/Text.js (100%) rename frontend/text-editor/{ => src}/editor/content/Text.test.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/Color.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/Content.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/Content.test.js (73%) rename frontend/text-editor/{ => src}/editor/content/dom/Element.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/Element.test.js (85%) rename frontend/text-editor/{ => src}/editor/content/dom/Inline.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/Inline.test.js (91%) rename frontend/text-editor/{ => src}/editor/content/dom/LineBreak.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/LineBreak.test.js (51%) rename frontend/text-editor/{ => src}/editor/content/dom/Paragraph.js (98%) rename frontend/text-editor/{ => src}/editor/content/dom/Paragraph.test.js (87%) rename frontend/text-editor/{ => src}/editor/content/dom/Root.js (94%) rename frontend/text-editor/{ => src}/editor/content/dom/Root.test.js (91%) rename frontend/text-editor/{ => src}/editor/content/dom/Style.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/Style.test.js (89%) rename frontend/text-editor/{ => src}/editor/content/dom/TextNode.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/TextNode.test.js (51%) rename frontend/text-editor/{ => src}/editor/content/dom/TextNodeIterator.js (100%) rename frontend/text-editor/{ => src}/editor/content/dom/TextNodeIterator.test.js (94%) rename frontend/text-editor/{ => src}/editor/controllers/ChangeController.js (100%) rename frontend/text-editor/{ => src}/editor/controllers/ChangeController.test.js (83%) rename frontend/text-editor/{ => src}/editor/controllers/SafeGuard.js (100%) rename frontend/text-editor/{ => src}/editor/controllers/SelectionController.js (99%) rename frontend/text-editor/{ => src}/editor/controllers/SelectionController.test.js (81%) rename frontend/text-editor/{ => src}/editor/controllers/SelectionDirection.js (100%) rename frontend/text-editor/{ => src}/editor/debug/SelectionControllerDebug.js (100%) rename frontend/text-editor/{ => src}/editor/layout/LayoutType.js (100%) rename frontend/text-editor/{ => src}/editor/selection/Imposter.js (100%) rename frontend/text-editor/{ => src}/editor/selection/Imposter.spec.js (93%) rename frontend/text-editor/{ => src}/index.html (100%) rename frontend/text-editor/{ => src}/main.js (100%) rename frontend/text-editor/{ => src}/style.css (100%) rename frontend/text-editor/{ => src}/test/TextEditorMock.js (91%) diff --git a/frontend/text-editor/editor/Event.test.js b/frontend/text-editor/editor/Event.test.js deleted file mode 100644 index b1b56a1cd..000000000 --- a/frontend/text-editor/editor/Event.test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { describe, test, expect, vi } from 'vitest'; -import { addEventListeners, removeEventListeners } from './Event'; - -/* @vitest-environment jsdom */ -describe('Event', () => { - test('addEventListeners should add event listeners to an element using an object', () => { - const clickSpy = vi.fn(); - const events = { - click: clickSpy - } - const element = document.createElement('div'); - addEventListeners(element, events); - element.dispatchEvent(new Event('click')); - expect(clickSpy).toBeCalled(); - }); - - test('removeEventListeners should remove event listeners to an element using an object', () => { - const clickSpy = vi.fn(); - const events = { - click: clickSpy, - }; - const element = document.createElement("div"); - addEventListeners(element, events); - element.dispatchEvent(new Event("click")); - removeEventListeners(element, events); - element.dispatchEvent(new Event('click')) - expect(clickSpy).toBeCalledTimes(1); - }) -}); diff --git a/frontend/text-editor/jsconfig.json b/frontend/text-editor/jsconfig.json index 555103d55..e451b27fc 100644 --- a/frontend/text-editor/jsconfig.json +++ b/frontend/text-editor/jsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "paths": { - "~/*": ["./*"] + "~/*": ["./src/*"] } } } diff --git a/frontend/text-editor/package.json b/frontend/text-editor/package.json index 6ad6d9cb4..865bc5d5a 100644 --- a/frontend/text-editor/package.json +++ b/frontend/text-editor/package.json @@ -3,11 +3,9 @@ "private": true, "version": "0.0.0", "type": "module", - "main": "editor/TextEditor.js", + "main": "src/editor/TextEditor.js", "scripts": { "dev": "vite", - "build": "./scripts/build.sh", - "preview": "vite preview", "coverage": "vitest run --coverage", "test": "vitest --run", "test:watch": "vitest", @@ -23,6 +21,7 @@ "esbuild": "^0.24.0", "jsdom": "^25.0.0", "playwright": "^1.45.1", + "prettier": "^3.3.3", "vite": "^5.3.1", "vitest": "^1.6.0" }, diff --git a/frontend/text-editor/scripts/build.sh b/frontend/text-editor/scripts/build.sh deleted file mode 100755 index 0e316b616..000000000 --- a/frontend/text-editor/scripts/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -esbuild --bundle --minify --sourcemap --target=es2021 --format=esm --platform=browser editor/TextEditor.js --outfile=dist/TextEditor.mjs diff --git a/frontend/text-editor/editor/Event.js b/frontend/text-editor/src/editor/Event.js similarity index 100% rename from frontend/text-editor/editor/Event.js rename to frontend/text-editor/src/editor/Event.js diff --git a/frontend/text-editor/src/editor/Event.test.js b/frontend/text-editor/src/editor/Event.test.js new file mode 100644 index 000000000..f22bc4497 --- /dev/null +++ b/frontend/text-editor/src/editor/Event.test.js @@ -0,0 +1,29 @@ +import { describe, test, expect, vi } from "vitest"; +import { addEventListeners, removeEventListeners } from "./Event.js"; + +/* @vitest-environment jsdom */ +describe("Event", () => { + test("addEventListeners should add event listeners to an element using an object", () => { + const clickSpy = vi.fn(); + const events = { + click: clickSpy, + }; + const element = document.createElement("div"); + addEventListeners(element, events); + element.dispatchEvent(new Event("click")); + expect(clickSpy).toBeCalled(); + }); + + test("removeEventListeners should remove event listeners to an element using an object", () => { + const clickSpy = vi.fn(); + const events = { + click: clickSpy, + }; + const element = document.createElement("div"); + addEventListeners(element, events); + element.dispatchEvent(new Event("click")); + removeEventListeners(element, events); + element.dispatchEvent(new Event("click")); + expect(clickSpy).toBeCalledTimes(1); + }); +}); diff --git a/frontend/text-editor/editor/TextEditor.css b/frontend/text-editor/src/editor/TextEditor.css similarity index 100% rename from frontend/text-editor/editor/TextEditor.css rename to frontend/text-editor/src/editor/TextEditor.css diff --git a/frontend/text-editor/editor/TextEditor.js b/frontend/text-editor/src/editor/TextEditor.js similarity index 95% rename from frontend/text-editor/editor/TextEditor.js rename to frontend/text-editor/src/editor/TextEditor.js index 8ea072a29..657811f04 100644 --- a/frontend/text-editor/editor/TextEditor.js +++ b/frontend/text-editor/src/editor/TextEditor.js @@ -8,15 +8,15 @@ import clipboard from "./clipboard/index.js"; import commands from "./commands/index.js"; -import ChangeController from './controllers/ChangeController.js'; -import SelectionController from './controllers/SelectionController.js'; -import { createSelectionImposterFromClientRects } from './selection/Imposter.js'; +import ChangeController from "./controllers/ChangeController.js"; +import SelectionController from "./controllers/SelectionController.js"; +import { createSelectionImposterFromClientRects } from "./selection/Imposter.js"; import { addEventListeners, removeEventListeners } from "./Event.js"; -import { createRoot, createEmptyRoot } from './content/dom/Root.js'; -import { createParagraph, fixParagraph, getParagraph } from './content/dom/Paragraph.js'; -import { createEmptyInline, createInline } from './content/dom/Inline.js'; -import { isLineBreak } from './content/dom/LineBreak.js'; -import LayoutType from './layout/LayoutType.js'; +import { createRoot, createEmptyRoot } from "./content/dom/Root.js"; +import { createParagraph } from "./content/dom/Paragraph.js"; +import { createEmptyInline, createInline } from "./content/dom/Inline.js"; +import { isLineBreak } from "./content/dom/LineBreak.js"; +import LayoutType from "./layout/LayoutType.js"; /** * Text Editor. diff --git a/frontend/text-editor/editor/TextEditor.test.js b/frontend/text-editor/src/editor/TextEditor.test.js similarity index 71% rename from frontend/text-editor/editor/TextEditor.test.js rename to frontend/text-editor/src/editor/TextEditor.test.js index 891fbe79d..d8dc8040b 100644 --- a/frontend/text-editor/editor/TextEditor.test.js +++ b/frontend/text-editor/src/editor/TextEditor.test.js @@ -1,49 +1,49 @@ -import { describe, test, expect } from 'vitest' -import { TextEditor } from './TextEditor' +import { describe, test, expect } from "vitest"; +import { TextEditor } from "./TextEditor.js"; /* @vitest-environment jsdom */ -describe('TextEditor', () => { - test('Creating TextEditor without element should throw', () => { - expect(() => new TextEditor()).toThrowError('Invalid text editor element'); +describe("TextEditor", () => { + test("Creating TextEditor without element should throw", () => { + expect(() => new TextEditor()).toThrowError("Invalid text editor element"); }); - test('Creating TextEditor with element should success', () => { - expect(new TextEditor(document.createElement('div'))).toBeInstanceOf(TextEditor); + test("Creating TextEditor with element should success", () => { + expect(new TextEditor(document.createElement("div"))).toBeInstanceOf( + TextEditor, + ); }); - test('isEmpty should return true when editor is empty', () => { + test("isEmpty should return true when editor is empty", () => { const textEditor = new TextEditor(document.createElement("div")); expect(textEditor).toBeInstanceOf(TextEditor); expect(textEditor.isEmpty).toBe(true); }); - test('Num paragraphs should return 1 when empty', () => { + test("Num paragraphs should return 1 when empty", () => { const textEditor = new TextEditor(document.createElement("div")); expect(textEditor).toBeInstanceOf(TextEditor); expect(textEditor.numParagraphs).toBe(1); }); - test('Num paragraphs should return the number of paragraphs', () => { + test("Num paragraphs should return the number of paragraphs", () => { const textEditor = new TextEditor(document.createElement("div")); textEditor.root = textEditor.createRoot([ textEditor.createParagraph([ - textEditor.createInlineFromString('Hello, World!') + textEditor.createInlineFromString("Hello, World!"), + ]), + textEditor.createParagraph([textEditor.createInlineFromString("")]), + textEditor.createParagraph([ + textEditor.createInlineFromString("¡Hola, Mundo!"), ]), textEditor.createParagraph([ - textEditor.createInlineFromString('') + textEditor.createInlineFromString("Hallo, Welt!"), ]), - textEditor.createParagraph([ - textEditor.createInlineFromString('¡Hola, Mundo!') - ]), - textEditor.createParagraph([ - textEditor.createInlineFromString('Hallo, Welt!') - ]) ]); expect(textEditor).toBeInstanceOf(TextEditor); expect(textEditor.numParagraphs).toBe(4); }); - test('Disposing a TextEditor nullifies everything', () => { + test("Disposing a TextEditor nullifies everything", () => { const textEditor = new TextEditor(document.createElement("div")); expect(textEditor).toBeInstanceOf(TextEditor); textEditor.dispose(); @@ -51,7 +51,7 @@ describe('TextEditor', () => { expect(textEditor.element).toBe(null); }); - test('TextEditor focus should focus the contenteditable element', () => { + test("TextEditor focus should focus the contenteditable element", () => { const textEditorElement = document.createElement("div"); document.body.appendChild(textEditorElement); const textEditor = new TextEditor(textEditorElement); @@ -76,8 +76,8 @@ describe('TextEditor', () => { const textEditor = new TextEditor(textEditorElement); textEditor.root = textEditor.createRoot([ textEditor.createParagraph([ - textEditor.createInlineFromString("Hello, World!") - ]) + textEditor.createInlineFromString("Hello, World!"), + ]), ]); expect(textEditor).toBeInstanceOf(TextEditor); textEditor.focus(); diff --git a/frontend/text-editor/editor/clipboard/copy.js b/frontend/text-editor/src/editor/clipboard/copy.js similarity index 100% rename from frontend/text-editor/editor/clipboard/copy.js rename to frontend/text-editor/src/editor/clipboard/copy.js diff --git a/frontend/text-editor/editor/clipboard/cut.js b/frontend/text-editor/src/editor/clipboard/cut.js similarity index 100% rename from frontend/text-editor/editor/clipboard/cut.js rename to frontend/text-editor/src/editor/clipboard/cut.js diff --git a/frontend/text-editor/editor/clipboard/index.js b/frontend/text-editor/src/editor/clipboard/index.js similarity index 100% rename from frontend/text-editor/editor/clipboard/index.js rename to frontend/text-editor/src/editor/clipboard/index.js diff --git a/frontend/text-editor/editor/clipboard/paste.js b/frontend/text-editor/src/editor/clipboard/paste.js similarity index 97% rename from frontend/text-editor/editor/clipboard/paste.js rename to frontend/text-editor/src/editor/clipboard/paste.js index 94a6cc161..2b3525afc 100644 --- a/frontend/text-editor/editor/clipboard/paste.js +++ b/frontend/text-editor/src/editor/clipboard/paste.js @@ -6,7 +6,7 @@ * Copyright (c) KALEIDOS INC */ -import { mapContentFragmentFromHTML, mapContentFragmentFromString } from '../content/dom/Content.js'; +import { mapContentFragmentFromHTML, mapContentFragmentFromString } from "../content/dom/Content.js"; /** * When the user pastes some HTML, what we do is generate diff --git a/frontend/text-editor/editor/commands/CommandMutations.js b/frontend/text-editor/src/editor/commands/CommandMutations.js similarity index 100% rename from frontend/text-editor/editor/commands/CommandMutations.js rename to frontend/text-editor/src/editor/commands/CommandMutations.js diff --git a/frontend/text-editor/editor/commands/CommandMutations.test.js b/frontend/text-editor/src/editor/commands/CommandMutations.test.js similarity index 95% rename from frontend/text-editor/editor/commands/CommandMutations.test.js rename to frontend/text-editor/src/editor/commands/CommandMutations.test.js index 94e540ed5..0ed4c1d7e 100644 --- a/frontend/text-editor/editor/commands/CommandMutations.test.js +++ b/frontend/text-editor/src/editor/commands/CommandMutations.test.js @@ -1,5 +1,5 @@ -import { describe, test, expect } from 'vitest'; -import CommandMutations from './CommandMutations'; +import { describe, test, expect } from "vitest"; +import CommandMutations from "./CommandMutations.js"; describe("CommandMutations", () => { test("should create a new CommandMutations", () => { @@ -67,5 +67,5 @@ describe("CommandMutations", () => { expect(mutations.added).toBe(null); expect(mutations.updated).toBe(null); expect(mutations.removed).toBe(null); - }) + }); }); diff --git a/frontend/text-editor/editor/commands/deleteByCut.js b/frontend/text-editor/src/editor/commands/deleteByCut.js similarity index 100% rename from frontend/text-editor/editor/commands/deleteByCut.js rename to frontend/text-editor/src/editor/commands/deleteByCut.js diff --git a/frontend/text-editor/editor/commands/deleteContentBackward.js b/frontend/text-editor/src/editor/commands/deleteContentBackward.js similarity index 100% rename from frontend/text-editor/editor/commands/deleteContentBackward.js rename to frontend/text-editor/src/editor/commands/deleteContentBackward.js diff --git a/frontend/text-editor/editor/commands/deleteContentForward.js b/frontend/text-editor/src/editor/commands/deleteContentForward.js similarity index 100% rename from frontend/text-editor/editor/commands/deleteContentForward.js rename to frontend/text-editor/src/editor/commands/deleteContentForward.js diff --git a/frontend/text-editor/editor/commands/index.js b/frontend/text-editor/src/editor/commands/index.js similarity index 100% rename from frontend/text-editor/editor/commands/index.js rename to frontend/text-editor/src/editor/commands/index.js diff --git a/frontend/text-editor/editor/commands/insertParagraph.js b/frontend/text-editor/src/editor/commands/insertParagraph.js similarity index 100% rename from frontend/text-editor/editor/commands/insertParagraph.js rename to frontend/text-editor/src/editor/commands/insertParagraph.js diff --git a/frontend/text-editor/editor/commands/insertText.js b/frontend/text-editor/src/editor/commands/insertText.js similarity index 100% rename from frontend/text-editor/editor/commands/insertText.js rename to frontend/text-editor/src/editor/commands/insertText.js diff --git a/frontend/text-editor/editor/content/Text.js b/frontend/text-editor/src/editor/content/Text.js similarity index 100% rename from frontend/text-editor/editor/content/Text.js rename to frontend/text-editor/src/editor/content/Text.js diff --git a/frontend/text-editor/editor/content/Text.test.js b/frontend/text-editor/src/editor/content/Text.test.js similarity index 100% rename from frontend/text-editor/editor/content/Text.test.js rename to frontend/text-editor/src/editor/content/Text.test.js diff --git a/frontend/text-editor/editor/content/dom/Color.js b/frontend/text-editor/src/editor/content/dom/Color.js similarity index 100% rename from frontend/text-editor/editor/content/dom/Color.js rename to frontend/text-editor/src/editor/content/dom/Color.js diff --git a/frontend/text-editor/editor/content/dom/Content.js b/frontend/text-editor/src/editor/content/dom/Content.js similarity index 100% rename from frontend/text-editor/editor/content/dom/Content.js rename to frontend/text-editor/src/editor/content/dom/Content.js diff --git a/frontend/text-editor/editor/content/dom/Content.test.js b/frontend/text-editor/src/editor/content/dom/Content.test.js similarity index 73% rename from frontend/text-editor/editor/content/dom/Content.test.js rename to frontend/text-editor/src/editor/content/dom/Content.test.js index e27d0968e..693e54b0d 100644 --- a/frontend/text-editor/editor/content/dom/Content.test.js +++ b/frontend/text-editor/src/editor/content/dom/Content.test.js @@ -1,23 +1,26 @@ -import { describe, test, expect } from 'vitest'; -import { mapContentFragmentFromHTML, mapContentFragmentFromString } from './Content.js'; +import { describe, test, expect } from "vitest"; +import { + mapContentFragmentFromHTML, + mapContentFragmentFromString, +} from "./Content.js"; /* @vitest-environment jsdom */ -describe('Content', () => { +describe("Content", () => { test("mapContentFragmentFromHTML should return a valid content for the editor", () => { const inertElement = document.createElement("div"); const contentFragment = mapContentFragmentFromHTML( "
Hello, World!
", - inertElement.style + inertElement.style, ); expect(contentFragment).toBeInstanceOf(DocumentFragment); expect(contentFragment.children).toHaveLength(1); expect(contentFragment.firstElementChild).toBeInstanceOf(HTMLDivElement); expect(contentFragment.firstElementChild.firstElementChild).toBeInstanceOf( - HTMLSpanElement - ); - expect(contentFragment.firstElementChild.firstElementChild.firstChild).toBeInstanceOf( - Text + HTMLSpanElement, ); + expect( + contentFragment.firstElementChild.firstElementChild.firstChild, + ).toBeInstanceOf(Text); expect(contentFragment.textContent).toBe("Hello, World!"); }); @@ -25,18 +28,18 @@ describe('Content', () => { const inertElement = document.createElement("div"); const contentFragment = mapContentFragmentFromHTML( "
Hello,
World!
", - inertElement.style + inertElement.style, ); expect(contentFragment).toBeInstanceOf(DocumentFragment); expect(contentFragment.children).toHaveLength(1); expect(contentFragment.firstElementChild).toBeInstanceOf(HTMLDivElement); expect(contentFragment.firstElementChild.children).toHaveLength(2); expect(contentFragment.firstElementChild.firstElementChild).toBeInstanceOf( - HTMLSpanElement - ); - expect(contentFragment.firstElementChild.firstElementChild.firstChild).toBeInstanceOf( - Text + HTMLSpanElement, ); + expect( + contentFragment.firstElementChild.firstElementChild.firstChild, + ).toBeInstanceOf(Text); expect(contentFragment.textContent).toBe("Hello, World!"); }); @@ -49,42 +52,46 @@ describe('Content', () => { const inertElement = document.createElement("div"); const contentFragment = mapContentFragmentFromHTML( "
Lorem ipsum
Dolor sit amet

Sed iaculis blandit odio ornare sagittis.
", - inertElement.style + inertElement.style, ); expect(contentFragment).toBeInstanceOf(DocumentFragment); expect(contentFragment.children).toHaveLength(3); for (let index = 0; index < contentFragment.children.length; index++) { - expect(contentFragment.children.item(index)).toBeInstanceOf(HTMLDivElement); - expect(contentFragment.children.item(index).firstElementChild).toBeInstanceOf( - HTMLSpanElement + expect(contentFragment.children.item(index)).toBeInstanceOf( + HTMLDivElement, ); expect( - contentFragment.children.item(index).firstElementChild.firstChild + contentFragment.children.item(index).firstElementChild, + ).toBeInstanceOf(HTMLSpanElement); + expect( + contentFragment.children.item(index).firstElementChild.firstChild, ).toBeInstanceOf(Text); - expect(contentFragment.children.item(index).textContent).toBe(paragraphs[index]); + expect(contentFragment.children.item(index).textContent).toBe( + paragraphs[index], + ); } - expect(contentFragment.textContent).toBe("Lorem ipsumDolor sit ametSed iaculis blandit odio ornare sagittis."); + expect(contentFragment.textContent).toBe( + "Lorem ipsumDolor sit ametSed iaculis blandit odio ornare sagittis.", + ); }); test("mapContentFragmentFromString should return a valid content for the editor", () => { - const contentFragment = mapContentFragmentFromString( - "Hello, \nWorld!" - ); + const contentFragment = mapContentFragmentFromString("Hello, \nWorld!"); expect(contentFragment).toBeInstanceOf(DocumentFragment); expect(contentFragment.children).toHaveLength(2); expect(contentFragment.children.item(0)).toBeInstanceOf(HTMLDivElement); expect(contentFragment.children.item(1)).toBeInstanceOf(HTMLDivElement); expect(contentFragment.children.item(0).firstElementChild).toBeInstanceOf( - HTMLSpanElement - ); - expect(contentFragment.children.item(0).firstElementChild.firstChild).toBeInstanceOf( - Text - ); - expect(contentFragment.children.item(1).firstElementChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect( - contentFragment.children.item(1).firstElementChild.firstChild + contentFragment.children.item(0).firstElementChild.firstChild, + ).toBeInstanceOf(Text); + expect(contentFragment.children.item(1).firstElementChild).toBeInstanceOf( + HTMLSpanElement, + ); + expect( + contentFragment.children.item(1).firstElementChild.firstChild, ).toBeInstanceOf(Text); expect(contentFragment.textContent).toBe("Hello, World!"); }); diff --git a/frontend/text-editor/editor/content/dom/Element.js b/frontend/text-editor/src/editor/content/dom/Element.js similarity index 100% rename from frontend/text-editor/editor/content/dom/Element.js rename to frontend/text-editor/src/editor/content/dom/Element.js diff --git a/frontend/text-editor/editor/content/dom/Element.test.js b/frontend/text-editor/src/editor/content/dom/Element.test.js similarity index 85% rename from frontend/text-editor/editor/content/dom/Element.test.js rename to frontend/text-editor/src/editor/content/dom/Element.test.js index 4e91dc428..2c2de40c0 100644 --- a/frontend/text-editor/editor/content/dom/Element.test.js +++ b/frontend/text-editor/src/editor/content/dom/Element.test.js @@ -1,11 +1,17 @@ import { describe, test, expect } from "vitest"; -import { createElement, isElement, createRandomId, isOffsetAtStart, isOffsetAtEnd } from "./Element.js"; +import { + createElement, + isElement, + createRandomId, + isOffsetAtStart, + isOffsetAtEnd, +} from "./Element.js"; /* @vitest-environment jsdom */ describe("Element", () => { test("createRandomId should create a new random id", () => { const randomId = createRandomId(); - expect(typeof randomId).toBe('string'); + expect(typeof randomId).toBe("string"); expect(randomId.length).toBeGreaterThan(0); expect(randomId.length).toBeLessThan(12); }); @@ -20,8 +26,8 @@ describe("Element", () => { const element = createElement("div", { attributes: { "aria-multiline": true, - "role": "textbox" - } + role: "textbox", + }, }); expect(element.ariaMultiLine).toBe("true"); expect(element.role).toBe("textbox"); @@ -30,8 +36,8 @@ describe("Element", () => { test("createElement should create a new element with data- properties", () => { const element = createElement("div", { data: { - itype: "root" - } + itype: "root", + }, }); expect(element.dataset.itype).toBe("root"); }); @@ -41,14 +47,14 @@ describe("Element", () => { styles: { "text-decoration": "underline", }, - allowedStyles: [["text-decoration"]] + allowedStyles: [["text-decoration"]], }); expect(element.style.textDecoration).toBe("underline"); }); test("createElement should create a new element with a child", () => { const element = createElement("div", { - children: new Text("Hello, World!") + children: new Text("Hello, World!"), }); expect(element.textContent).toBe("Hello, World!"); }); @@ -59,16 +65,18 @@ describe("Element", () => { createElement("div", { children: [ createElement("div", { - children: new Text("Hello, World!") - }) - ] - }) + children: new Text("Hello, World!"), + }), + ], + }), ], }); expect(element.textContent).toBe("Hello, World!"); expect(element.firstChild.nodeType).toBe(Node.ELEMENT_NODE); expect(element.firstChild.firstChild.nodeType).toBe(Node.ELEMENT_NODE); - expect(element.firstChild.firstChild.firstChild.nodeType).toBe(Node.TEXT_NODE); + expect(element.firstChild.firstChild.firstChild.nodeType).toBe( + Node.TEXT_NODE, + ); }); test("isElement returns true if the passed element is the expected element", () => { @@ -81,9 +89,9 @@ describe("Element", () => { }); test("isOffsetAtStart should return true when offset is 0", () => { - const element = createElement('span', { - children: new Text("Hello") - }) + const element = createElement("span", { + children: new Text("Hello"), + }); expect(isOffsetAtStart(element, 0)).toBe(true); }); diff --git a/frontend/text-editor/editor/content/dom/Inline.js b/frontend/text-editor/src/editor/content/dom/Inline.js similarity index 100% rename from frontend/text-editor/editor/content/dom/Inline.js rename to frontend/text-editor/src/editor/content/dom/Inline.js diff --git a/frontend/text-editor/editor/content/dom/Inline.test.js b/frontend/text-editor/src/editor/content/dom/Inline.test.js similarity index 91% rename from frontend/text-editor/editor/content/dom/Inline.test.js rename to frontend/text-editor/src/editor/content/dom/Inline.test.js index 98272345a..4b1cff17a 100644 --- a/frontend/text-editor/editor/content/dom/Inline.test.js +++ b/frontend/text-editor/src/editor/content/dom/Inline.test.js @@ -1,12 +1,24 @@ import { describe, test, expect } from "vitest"; -import { createEmptyInline, createInline, getInline, getInlineLength, isInline, isInlineEnd, isInlineStart, isLikeInline, splitInline, TAG, TYPE } from "./Inline.js"; +import { + createEmptyInline, + createInline, + getInline, + getInlineLength, + isInline, + isInlineEnd, + isInlineStart, + isLikeInline, + splitInline, + TAG, + TYPE, +} from "./Inline.js"; import { createLineBreak } from "./LineBreak.js"; /* @vitest-environment jsdom */ describe("Inline", () => { test("createInline should throw when passed an invalid child", () => { expect(() => createInline("Hello, World!")).toThrowError( - "Invalid inline child" + "Invalid inline child", ); }); @@ -44,7 +56,7 @@ describe("Inline", () => { expect(isInline(a)).toBe(false); const b = null; expect(isInline(b)).toBe(false); - const c = document.createElement('span'); + const c = document.createElement("span"); expect(isInline(c)).toBe(false); }); @@ -82,11 +94,11 @@ describe("Inline", () => { test("getInline ", () => { expect(getInline(null)).toBe(null); - }) + }); test("getInlineLength throws when the passed node is not an inline", () => { - const inline = document.createElement('div'); - expect(() => getInlineLength(inline)).toThrowError('Invalid inline'); + const inline = document.createElement("div"); + expect(() => getInlineLength(inline)).toThrowError("Invalid inline"); }); test("getInlineLength returns the length of the inline content", () => { diff --git a/frontend/text-editor/editor/content/dom/LineBreak.js b/frontend/text-editor/src/editor/content/dom/LineBreak.js similarity index 100% rename from frontend/text-editor/editor/content/dom/LineBreak.js rename to frontend/text-editor/src/editor/content/dom/LineBreak.js diff --git a/frontend/text-editor/editor/content/dom/LineBreak.test.js b/frontend/text-editor/src/editor/content/dom/LineBreak.test.js similarity index 51% rename from frontend/text-editor/editor/content/dom/LineBreak.test.js rename to frontend/text-editor/src/editor/content/dom/LineBreak.test.js index f9faeeeb5..7701c5172 100644 --- a/frontend/text-editor/editor/content/dom/LineBreak.test.js +++ b/frontend/text-editor/src/editor/content/dom/LineBreak.test.js @@ -1,11 +1,11 @@ -import { describe, expect, test } from 'vitest'; -import { createLineBreak } from './LineBreak.js'; +import { describe, expect, test } from "vitest"; +import { createLineBreak } from "./LineBreak.js"; /* @vitest-environment jsdom */ -describe('LineBreak', () => { +describe("LineBreak", () => { test("createLineBreak should return a
element", () => { const br = createLineBreak(); expect(br.nodeType).toBe(Node.ELEMENT_NODE); - expect(br.nodeName).toBe('BR'); - }) + expect(br.nodeName).toBe("BR"); + }); }); diff --git a/frontend/text-editor/editor/content/dom/Paragraph.js b/frontend/text-editor/src/editor/content/dom/Paragraph.js similarity index 98% rename from frontend/text-editor/editor/content/dom/Paragraph.js rename to frontend/text-editor/src/editor/content/dom/Paragraph.js index 09ce69ead..ecc535158 100644 --- a/frontend/text-editor/editor/content/dom/Paragraph.js +++ b/frontend/text-editor/src/editor/content/dom/Paragraph.js @@ -7,6 +7,7 @@ */ import { + createRandomId, createElement, isElement, isOffsetAtStart, @@ -24,8 +25,6 @@ import { } from "./Inline.js"; import { createLineBreak, isLineBreak } from "./LineBreak.js"; import { setStyles } from "./Style.js"; -import { createRandomId } from "./Element.js"; -import { isEmptyTextNode, isTextNode } from './TextNode.js'; export const TAG = "DIV"; export const TYPE = "paragraph"; diff --git a/frontend/text-editor/editor/content/dom/Paragraph.test.js b/frontend/text-editor/src/editor/content/dom/Paragraph.test.js similarity index 87% rename from frontend/text-editor/editor/content/dom/Paragraph.test.js rename to frontend/text-editor/src/editor/content/dom/Paragraph.test.js index 5caadc0b0..3874c5eba 100644 --- a/frontend/text-editor/editor/content/dom/Paragraph.test.js +++ b/frontend/text-editor/src/editor/content/dom/Paragraph.test.js @@ -18,9 +18,9 @@ import { createInline, isInline } from "./Inline.js"; /* @vitest-environment jsdom */ describe("Paragraph", () => { test("createParagraph should throw when passed invalid children", () => { - expect(() => createParagraph([ - "Whatever" - ])).toThrowError("Invalid paragraph children"); + expect(() => createParagraph(["Whatever"])).toThrowError( + "Invalid paragraph children", + ); }); test("createEmptyParagraph should create a new empty paragraph", () => { @@ -33,30 +33,30 @@ describe("Paragraph", () => { test("isParagraph should return true when the passed node is a paragraph", () => { expect(isParagraph(null)).toBe(false); - expect(isParagraph(document.createElement('div'))).toBe(false); - expect(isParagraph(document.createElement('h1'))).toBe(false); + expect(isParagraph(document.createElement("div"))).toBe(false); + expect(isParagraph(document.createElement("h1"))).toBe(false); expect(isParagraph(createEmptyParagraph())).toBe(true); - expect(isParagraph(createParagraph([ - createInline(new Text('Hello, World!')) - ]))).toBe(true); + expect( + isParagraph(createParagraph([createInline(new Text("Hello, World!"))])), + ).toBe(true); }); test("isLikeParagraph should return true when node looks like a paragraph", () => { - const p = document.createElement('p'); + const p = document.createElement("p"); expect(isLikeParagraph(p)).toBe(true); - const div = document.createElement('div'); + const div = document.createElement("div"); expect(isLikeParagraph(div)).toBe(true); - const h1 = document.createElement('h1'); + const h1 = document.createElement("h1"); expect(isLikeParagraph(h1)).toBe(true); - const h2 = document.createElement('h2'); + const h2 = document.createElement("h2"); expect(isLikeParagraph(h2)).toBe(true); - const h3 = document.createElement('h3'); + const h3 = document.createElement("h3"); expect(isLikeParagraph(h3)).toBe(true); - const h4 = document.createElement('h4'); + const h4 = document.createElement("h4"); expect(isLikeParagraph(h4)).toBe(true); - const h5 = document.createElement('h5'); + const h5 = document.createElement("h5"); expect(isLikeParagraph(h5)).toBe(true); - const h6 = document.createElement('h6'); + const h6 = document.createElement("h6"); expect(isLikeParagraph(h6)).toBe(true); }); @@ -69,7 +69,7 @@ describe("Paragraph", () => { test("getParagraph should return null if there aren't closer paragraph nodes", () => { const text = new Text("Hello, World!"); - const whatever = document.createElement('div'); + const whatever = document.createElement("div"); whatever.appendChild(text); expect(getParagraph(text)).toBe(null); }); @@ -81,7 +81,7 @@ describe("Paragraph", () => { test("isParagraphStart should return true on a paragraph", () => { const paragraph = createParagraph([ - createInline(new Text("Hello, World!")) + createInline(new Text("Hello, World!")), ]); expect(isParagraphStart(paragraph.firstChild.firstChild, 0)).toBe(true); }); @@ -162,11 +162,10 @@ describe("Paragraph", () => { const nonEmptyInline = document.createElement("span"); nonEmptyInline.dataset.itype = "inline"; - nonEmptyInline.appendChild(new Text('Not empty!')); + nonEmptyInline.appendChild(new Text("Not empty!")); const nonEmptyParagraph = document.createElement("div"); nonEmptyParagraph.dataset.itype = "paragraph"; nonEmptyParagraph.appendChild(nonEmptyInline); expect(isEmptyParagraph(nonEmptyParagraph)).toBe(false); - }); }); diff --git a/frontend/text-editor/editor/content/dom/Root.js b/frontend/text-editor/src/editor/content/dom/Root.js similarity index 94% rename from frontend/text-editor/editor/content/dom/Root.js rename to frontend/text-editor/src/editor/content/dom/Root.js index 4eeec2070..fa0391321 100644 --- a/frontend/text-editor/editor/content/dom/Root.js +++ b/frontend/text-editor/src/editor/content/dom/Root.js @@ -6,10 +6,9 @@ * Copyright (c) KALEIDOS INC */ -import { createElement, isElement } from "./Element.js"; +import { createRandomId, createElement, isElement } from "./Element.js"; import { createEmptyParagraph, isParagraph } from "./Paragraph.js"; import { setStyles } from "./Style.js"; -import { createRandomId } from "./Element.js"; export const TAG = "DIV"; export const TYPE = "root"; diff --git a/frontend/text-editor/editor/content/dom/Root.test.js b/frontend/text-editor/src/editor/content/dom/Root.test.js similarity index 91% rename from frontend/text-editor/editor/content/dom/Root.test.js rename to frontend/text-editor/src/editor/content/dom/Root.test.js index a2d048bef..49b5195d5 100644 --- a/frontend/text-editor/editor/content/dom/Root.test.js +++ b/frontend/text-editor/src/editor/content/dom/Root.test.js @@ -1,11 +1,11 @@ import { describe, test, expect } from "vitest"; -import { createEmptyRoot, createRoot, setRootStyles, TAG, TYPE } from './Root.js' +import { createEmptyRoot, createRoot, setRootStyles, TAG, TYPE } from "./Root.js"; /* @vitest-environment jsdom */ describe("Root", () => { test("createRoot should throw when passed invalid children", () => { expect(() => createRoot(["Whatever"])).toThrowError( - "Invalid root children" + "Invalid root children", ); }); @@ -16,18 +16,20 @@ describe("Root", () => { expect(emptyRoot.dataset.itype).toBe(TYPE); expect(emptyRoot.firstChild).toBeInstanceOf(HTMLDivElement); expect(emptyRoot.firstChild.firstChild).toBeInstanceOf(HTMLSpanElement); - expect(emptyRoot.firstChild.firstChild.firstChild).toBeInstanceOf(HTMLBRElement); + expect(emptyRoot.firstChild.firstChild.firstChild).toBeInstanceOf( + HTMLBRElement, + ); }); test("setRootStyles should apply only the styles of root to the root", () => { const emptyRoot = createEmptyRoot(); setRootStyles(emptyRoot, { ["--vertical-align"]: "top", - ["font-size"]: "25px" + ["font-size"]: "25px", }); expect(emptyRoot.style.getPropertyValue("--vertical-align")).toBe("top"); // We expect this style to be empty because we don't apply it // to the root. expect(emptyRoot.style.getPropertyValue("font-size")).toBe(""); - }) + }); }); diff --git a/frontend/text-editor/editor/content/dom/Style.js b/frontend/text-editor/src/editor/content/dom/Style.js similarity index 100% rename from frontend/text-editor/editor/content/dom/Style.js rename to frontend/text-editor/src/editor/content/dom/Style.js diff --git a/frontend/text-editor/editor/content/dom/Style.test.js b/frontend/text-editor/src/editor/content/dom/Style.test.js similarity index 89% rename from frontend/text-editor/editor/content/dom/Style.test.js rename to frontend/text-editor/src/editor/content/dom/Style.test.js index 0c1e14735..edd065d2d 100644 --- a/frontend/text-editor/editor/content/dom/Style.test.js +++ b/frontend/text-editor/src/editor/content/dom/Style.test.js @@ -1,5 +1,11 @@ import { describe, test, expect, vi } from "vitest"; -import { getStyles, isDisplayBlock, isDisplayInline, setStyle, setStyles } from "./Style.js"; +import { + getStyles, + isDisplayBlock, + isDisplayInline, + setStyle, + setStyles, +} from "./Style.js"; /* @vitest-environment jsdom */ describe("Style", () => { @@ -39,16 +45,16 @@ describe("Style", () => { test("getStyles should retrieve a list of allowed styles", () => { const element = document.createElement("div"); - element.style.display = 'block'; - element.style.textDecoration = 'underline'; - element.style.fontSize = '32px'; + element.style.display = "block"; + element.style.textDecoration = "underline"; + element.style.fontSize = "32px"; const textDecorationStyles = getStyles(element, [["text-decoration"]]); expect(textDecorationStyles).toStrictEqual({ - "text-decoration": "underline" + "text-decoration": "underline", }); const displayStyles = getStyles(element, [["display"]]); expect(displayStyles).toStrictEqual({ - "display": "block", + display: "block", }); const fontSizeStyles = getStyles(element, [["font-size", "px"]]); expect(fontSizeStyles).toStrictEqual({ diff --git a/frontend/text-editor/editor/content/dom/TextNode.js b/frontend/text-editor/src/editor/content/dom/TextNode.js similarity index 100% rename from frontend/text-editor/editor/content/dom/TextNode.js rename to frontend/text-editor/src/editor/content/dom/TextNode.js diff --git a/frontend/text-editor/editor/content/dom/TextNode.test.js b/frontend/text-editor/src/editor/content/dom/TextNode.test.js similarity index 51% rename from frontend/text-editor/editor/content/dom/TextNode.test.js rename to frontend/text-editor/src/editor/content/dom/TextNode.test.js index d97e1395f..fc44374b8 100644 --- a/frontend/text-editor/editor/content/dom/TextNode.test.js +++ b/frontend/text-editor/src/editor/content/dom/TextNode.test.js @@ -1,6 +1,6 @@ -import { describe, test, expect } from 'vitest'; -import { isTextNode, getTextNodeLength } from './TextNode.js'; -import { createLineBreak } from './LineBreak.js'; +import { describe, test, expect } from "vitest"; +import { isTextNode, getTextNodeLength } from "./TextNode.js"; +import { createLineBreak } from "./LineBreak.js"; /* @vitest-environment jsdom */ describe("TextNode", () => { @@ -11,16 +11,18 @@ describe("TextNode", () => { expect(isTextNode("hola")).toBe(false); expect(isTextNode({})).toBe(false); expect(isTextNode([])).toBe(false); - expect(() => isTextNode(undefined)).toThrowError('Invalid text node'); - expect(() => isTextNode(null)).toThrowError('Invalid text node'); - expect(() => isTextNode(0)).toThrowError('Invalid text node'); + expect(() => isTextNode(undefined)).toThrowError("Invalid text node"); + expect(() => isTextNode(null)).toThrowError("Invalid text node"); + expect(() => isTextNode(0)).toThrowError("Invalid text node"); }); test("getTextNodeLength should return the length of the text node or 0 if it is a
", () => { expect(getTextNodeLength(new Text("Hello, World!"))).toBe(13); expect(getTextNodeLength(createLineBreak())).toBe(0); - expect(() => getTextNodeLength(undefined)).toThrowError('Invalid text node'); - expect(() => getTextNodeLength(null)).toThrowError('Invalid text node'); - expect(() => getTextNodeLength(0)).toThrowError('Invalid text node'); + expect(() => getTextNodeLength(undefined)).toThrowError( + "Invalid text node", + ); + expect(() => getTextNodeLength(null)).toThrowError("Invalid text node"); + expect(() => getTextNodeLength(0)).toThrowError("Invalid text node"); }); }); diff --git a/frontend/text-editor/editor/content/dom/TextNodeIterator.js b/frontend/text-editor/src/editor/content/dom/TextNodeIterator.js similarity index 100% rename from frontend/text-editor/editor/content/dom/TextNodeIterator.js rename to frontend/text-editor/src/editor/content/dom/TextNodeIterator.js diff --git a/frontend/text-editor/editor/content/dom/TextNodeIterator.test.js b/frontend/text-editor/src/editor/content/dom/TextNodeIterator.test.js similarity index 94% rename from frontend/text-editor/editor/content/dom/TextNodeIterator.test.js rename to frontend/text-editor/src/editor/content/dom/TextNodeIterator.test.js index 811ffc3dc..c19311a22 100644 --- a/frontend/text-editor/editor/content/dom/TextNodeIterator.test.js +++ b/frontend/text-editor/src/editor/content/dom/TextNodeIterator.test.js @@ -10,11 +10,11 @@ describe("TextNodeIterator", () => { test("Create a new TextNodeIterator with an invalid root should throw", () => { expect(() => new TextNodeIterator(null)).toThrowError("Invalid root node"); expect(() => new TextNodeIterator(Infinity)).toThrowError( - "Invalid root node" + "Invalid root node", ); expect(() => new TextNodeIterator(1)).toThrowError("Invalid root node"); expect(() => new TextNodeIterator("hola")).toThrowError( - "Invalid root node" + "Invalid root node", ); }); @@ -26,7 +26,10 @@ describe("TextNodeIterator", () => { createInline(new Text("Whatever")), ]), createParagraph([createInline(createLineBreak())]), - createParagraph([createInline(new Text("This is a ")), createInline(new Text("test"))]), + createParagraph([ + createInline(new Text("This is a ")), + createInline(new Text("test")), + ]), createParagraph([createInline(new Text("Hi!"))]), ]); diff --git a/frontend/text-editor/editor/controllers/ChangeController.js b/frontend/text-editor/src/editor/controllers/ChangeController.js similarity index 100% rename from frontend/text-editor/editor/controllers/ChangeController.js rename to frontend/text-editor/src/editor/controllers/ChangeController.js diff --git a/frontend/text-editor/editor/controllers/ChangeController.test.js b/frontend/text-editor/src/editor/controllers/ChangeController.test.js similarity index 83% rename from frontend/text-editor/editor/controllers/ChangeController.test.js rename to frontend/text-editor/src/editor/controllers/ChangeController.test.js index d5cb47852..9a09241e9 100644 --- a/frontend/text-editor/editor/controllers/ChangeController.test.js +++ b/frontend/text-editor/src/editor/controllers/ChangeController.test.js @@ -1,15 +1,15 @@ -import { expect, describe, test, vi } from 'vitest' -import ChangeController from './ChangeController' +import { expect, describe, test, vi } from "vitest"; +import ChangeController from "./ChangeController.js"; describe("ChangeController", () => { test("Creating a ChangeController without a valid time should throw", () => { - expect(() => new ChangeController(Infinity)).toThrowError('Invalid time') + expect(() => new ChangeController(Infinity)).toThrowError("Invalid time"); }); test("A ChangeController should dispatch an event when `notifyImmediately` is called", () => { const changeListener = vi.fn(); const changeController = new ChangeController(10); - changeController.addEventListener("change", changeListener) + changeController.addEventListener("change", changeListener); changeController.notifyImmediately(); expect(changeController.hasPendingChanges).toBe(false); expect(changeListener).toBeCalled(1); diff --git a/frontend/text-editor/editor/controllers/SafeGuard.js b/frontend/text-editor/src/editor/controllers/SafeGuard.js similarity index 100% rename from frontend/text-editor/editor/controllers/SafeGuard.js rename to frontend/text-editor/src/editor/controllers/SafeGuard.js diff --git a/frontend/text-editor/editor/controllers/SelectionController.js b/frontend/text-editor/src/editor/controllers/SelectionController.js similarity index 99% rename from frontend/text-editor/editor/controllers/SelectionController.js rename to frontend/text-editor/src/editor/controllers/SelectionController.js index 1c9681d81..11cca7c1b 100644 --- a/frontend/text-editor/editor/controllers/SelectionController.js +++ b/frontend/text-editor/src/editor/controllers/SelectionController.js @@ -16,7 +16,6 @@ import { isInlineStart, isInlineEnd, setInlineStyles, - mergeInlines, splitInline, createEmptyInline, } from "../content/dom/Inline.js"; @@ -29,7 +28,6 @@ import { isParagraphEnd, setParagraphStyles, splitParagraph, - splitParagraphAtNode, mergeParagraphs, fixParagraph, } from "../content/dom/Paragraph.js"; @@ -48,9 +46,6 @@ import { setRootStyles } from "../content/dom/Root.js"; import { SelectionDirection } from "./SelectionDirection.js"; import SafeGuard from "./SafeGuard.js"; -const SAFE_GUARD = true; -const SAFE_GUARD_TIME = true; - /** * Supported options for the SelectionController. * diff --git a/frontend/text-editor/editor/controllers/SelectionController.test.js b/frontend/text-editor/src/editor/controllers/SelectionController.test.js similarity index 81% rename from frontend/text-editor/editor/controllers/SelectionController.test.js rename to frontend/text-editor/src/editor/controllers/SelectionController.test.js index 2047ae884..070475e44 100644 --- a/frontend/text-editor/editor/controllers/SelectionController.test.js +++ b/frontend/text-editor/src/editor/controllers/SelectionController.test.js @@ -1,12 +1,14 @@ import { expect, describe, test } from "vitest"; -import TextEditor from "~/editor/TextEditor"; -import { createRoot } from "~/editor/content/dom/Root"; -import { createEmptyParagraph, createParagraph } from "~/editor/content/dom/Paragraph"; -import { createInline } from "~/editor/content/dom/Inline"; -import { createLineBreak } from "~/editor/content/dom/LineBreak"; -import { TextEditorMock } from "~/test/TextEditorMock"; -import { SelectionController } from "./SelectionController"; -import { SelectionDirection } from "./SelectionDirection"; +import TextEditor from "../TextEditor.js"; +import { + createEmptyParagraph, + createParagraph, +} from "../content/dom/Paragraph.js"; +import { createInline } from "../content/dom/Inline.js"; +import { createLineBreak } from "../content/dom/LineBreak.js"; +import { TextEditorMock } from "../../test/TextEditorMock.js"; +import { SelectionController } from "./SelectionController.js"; +import { SelectionDirection } from "./SelectionDirection.js"; /* @vitest-environment jsdom */ @@ -20,7 +22,14 @@ import { SelectionDirection } from "./SelectionDirection"; * @param {Node} [anchorNode=null] * @param {number} [anchorOffset=0] */ -function focus(selection, textEditor, focusNode, focusOffset = 0, anchorNode = focusNode, anchorOffset = focusOffset) { +function focus( + selection, + textEditor, + focusNode, + focusOffset = 0, + anchorNode = focusNode, + anchorOffset = focusOffset, +) { textEditor.element.focus(); selection.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset); document.dispatchEvent(new Event("selectionchange")); @@ -30,7 +39,10 @@ describe("SelectionController", () => { test("`selection` should return the Selection object kept by the SelectionController", () => { const textEditorMock = TextEditorMock.createTextEditorMockWithText(""); const selection = document.getSelection(); - const selectionController = new SelectionController(textEditorMock, selection); + const selectionController = new SelectionController( + textEditorMock, + selection, + ); expect(selectionController.selection).toBe(selection); }); @@ -40,7 +52,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); // When the editor hasn't been focused // range is null. @@ -51,7 +63,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.firstChild.firstChild, - 0 + 0, ); expect(selectionController.range).toBeInstanceOf(Range); }); @@ -62,7 +74,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -70,18 +82,19 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.firstChild.firstChild, - 0 + 0, ); expect(selectionController.focusAtStart).toBe(true); }); test("`focusAtEnd` should return `true` if the offset is the length of the `textContent`", () => { - const textEditorMock = TextEditorMock.createTextEditorMockWithText("Hello, World!"); + const textEditorMock = + TextEditorMock.createTextEditorMockWithText("Hello, World!"); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -89,7 +102,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, "Hello, World!".length, root.firstChild.firstChild.firstChild, - 0 + 0, ); expect(selectionController.focusAtEnd).toBe(true); }); @@ -100,7 +113,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -108,7 +121,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.firstChild.firstChild, - 0 + 0, ); expect(selectionController.anchorAtStart).toBe(true); }); @@ -120,7 +133,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -128,18 +141,19 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.firstChild.firstChild, - "Hello, World!".length + "Hello, World!".length, ); expect(selectionController.anchorAtEnd).toBe(true); }); test("`direction` should return the direction of the focus and anchor nodes", () => { - const textEditorMock = TextEditorMock.createTextEditorMockWithText("Hello, World!"); + const textEditorMock = + TextEditorMock.createTextEditorMockWithText("Hello, World!"); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -147,7 +161,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.firstChild.firstChild, - 0 + 0, ); expect(selectionController.direction).toBe(SelectionDirection.NONE); focus( @@ -156,7 +170,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 5, root.firstChild.firstChild.firstChild, - 0 + 0, ); expect(selectionController.direction).toBe(SelectionDirection.FORWARD); focus( @@ -165,7 +179,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.firstChild.firstChild, - 5 + 5, ); expect(selectionController.direction).toBe(SelectionDirection.BACKWARD); }); @@ -176,24 +190,32 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, textEditorMock, root.firstChild.firstChild.firstChild, - "Hello".length + "Hello".length, ); selectionController.insertText(", World!"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.dataset.itype).toBe("root"); expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); - expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf(HTMLSpanElement); - expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe("inline"); + expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( + HTMLSpanElement, + ); + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", + ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); - expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf(Text); - expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe("Hello, World!"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Hello, World!", + ); }); test("`replaceLineBreak` should replace a
with some text", () => { @@ -202,91 +224,43 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection - ); - focus( selection, - textEditorMock, - root.firstChild.firstChild.firstChild ); + focus(selection, textEditorMock, root.firstChild.firstChild.firstChild); selectionController.replaceLineBreak("Hello, World!"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.dataset.itype).toBe("root"); - expect(textEditorMock.root.firstChild).toBeInstanceOf( - HTMLDivElement + expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); + expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); + expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( + HTMLSpanElement, ); - expect(textEditorMock.root.firstChild.dataset.itype).toBe( - "paragraph" + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", ); - expect( - textEditorMock.root.firstChild.firstChild - ).toBeInstanceOf(HTMLSpanElement); - expect( - textEditorMock.root.firstChild.firstChild.dataset.itype - ).toBe("inline"); expect(textEditorMock.root.textContent).toBe("Hello, World!"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - .nodeValue - ).toBe("Hello, World!"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Hello, World!", + ); }); test("`removeBackwardText` should remove text in backward direction (backspace)", () => { - const textEditorMock = TextEditorMock.createTextEditorMockWithText("Hello, World!"); - const root = textEditorMock.root; - const selection = document.getSelection(); - const selectionController = new SelectionController( - textEditorMock, - selection - ); - focus( - selection, - textEditorMock, - root.firstChild.firstChild.firstChild, - "Hello, World!".length - ); - selectionController.removeBackwardText(); - expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); - expect(textEditorMock.root.dataset.itype).toBe("root"); - expect(textEditorMock.root.firstChild).toBeInstanceOf( - HTMLDivElement - ); - expect(textEditorMock.root.firstChild.dataset.itype).toBe( - "paragraph" - ); - expect( - textEditorMock.root.firstChild.firstChild - ).toBeInstanceOf(HTMLSpanElement); - expect( - textEditorMock.root.firstChild.firstChild.dataset.itype - ).toBe("inline"); - expect(textEditorMock.root.textContent).toBe("Hello, World"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - .nodeValue - ).toBe("Hello, World"); - }); - - test("`removeBackwardText` should remove text in backward direction (backspace) and create a new empty paragraph when there's nothing left", () => { const textEditorMock = - TextEditorMock.createTextEditorMockWithText("H"); + TextEditorMock.createTextEditorMockWithText("Hello, World!"); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, textEditorMock, root.firstChild.firstChild.firstChild, - "H".length + "Hello, World!".length, ); selectionController.removeBackwardText(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -294,10 +268,44 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", + ); + expect(textEditorMock.root.textContent).toBe("Hello, World"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Hello, World", + ); + }); + + test("`removeBackwardText` should remove text in backward direction (backspace) and create a new empty paragraph when there's nothing left", () => { + const textEditorMock = TextEditorMock.createTextEditorMockWithText("H"); + const root = textEditorMock.root; + const selection = document.getSelection(); + const selectionController = new SelectionController( + textEditorMock, + selection, + ); + focus( + selection, + textEditorMock, + root.firstChild.firstChild.firstChild, + "H".length, + ); + selectionController.removeBackwardText(); + expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); + expect(textEditorMock.root.dataset.itype).toBe("root"); + expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); + expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); + expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( + HTMLSpanElement, + ); + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", ); expect(textEditorMock.root.textContent).toBe(""); }); @@ -311,13 +319,13 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, textEditorMock, root.childNodes.item(1).firstChild.firstChild, - 0 + 0, ); selectionController.mergeBackwardParagraph(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -326,10 +334,10 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); }); @@ -338,16 +346,19 @@ describe("SelectionController", () => { const textEditorMock = TextEditorMock.createTextEditorMockWithParagraphs([ createParagraph([createInline(new Text("Hello, "))]), createEmptyParagraph(), - createParagraph([createInline(new Text("World!"))]) + createParagraph([createInline(new Text("World!"))]), ]); const root = textEditorMock.root; const selection = document.getSelection(); - const selectionController = new SelectionController(textEditorMock, selection); + const selectionController = new SelectionController( + textEditorMock, + selection, + ); focus( selection, textEditorMock, root.childNodes.item(2).firstChild.firstChild, - 0 + 0, ); selectionController.mergeBackwardParagraph(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -356,9 +367,11 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, + ); + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", ); - expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe("inline"); expect(textEditorMock.root.textContent).toBe("Hello, World!"); expect(textEditorMock.root.firstChild.textContent).toBe("Hello, "); expect(textEditorMock.root.lastChild.textContent).toBe("World!"); @@ -373,13 +386,13 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, textEditorMock, root.firstChild.firstChild.firstChild, - root.firstChild.firstChild.firstChild.nodeValue.length + root.firstChild.firstChild.firstChild.nodeValue.length, ); selectionController.mergeForwardParagraph(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -388,10 +401,10 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); }); @@ -406,13 +419,13 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, textEditorMock, root.childNodes.item(2).firstChild.firstChild, - 0 + 0, ); selectionController.mergeBackwardParagraph(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -421,10 +434,10 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); expect(textEditorMock.root.firstChild.textContent).toBe("Hello, "); @@ -438,36 +451,27 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection - ); - focus( selection, - textEditorMock, - root.firstChild.firstChild.firstChild, ); + focus(selection, textEditorMock, root.firstChild.firstChild.firstChild); selectionController.removeForwardText(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.dataset.itype).toBe("root"); - expect(textEditorMock.root.firstChild).toBeInstanceOf( - HTMLDivElement + expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); + expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); + expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( + HTMLSpanElement, ); - expect(textEditorMock.root.firstChild.dataset.itype).toBe( - "paragraph" + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", ); - expect( - textEditorMock.root.firstChild.firstChild - ).toBeInstanceOf(HTMLSpanElement); - expect( - textEditorMock.root.firstChild.firstChild.dataset.itype - ).toBe("inline"); expect(textEditorMock.root.textContent).toBe("ello, World!"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - .nodeValue - ).toBe("ello, World!"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "ello, World!", + ); }); test("`replaceText` should replace the selected text", () => { @@ -477,7 +481,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -485,44 +489,38 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 7, root.firstChild.firstChild.firstChild, - 12 + 12, ); selectionController.replaceText("Mundo"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.dataset.itype).toBe("root"); - expect(textEditorMock.root.firstChild).toBeInstanceOf( - HTMLDivElement + expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); + expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); + expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( + HTMLSpanElement, ); - expect(textEditorMock.root.firstChild.dataset.itype).toBe( - "paragraph" + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", ); - expect( - textEditorMock.root.firstChild.firstChild - ).toBeInstanceOf(HTMLSpanElement); - expect( - textEditorMock.root.firstChild.firstChild.dataset.itype - ).toBe("inline"); expect(textEditorMock.root.textContent).toBe("Hello, Mundo!"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - .nodeValue - ).toBe("Hello, Mundo!"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Hello, Mundo!", + ); }); test("`replaceInlines` should replace the selected text in multiple inlines (2 completelly selected)", () => { - const textEditorMock = - TextEditorMock.createTextEditorMockWithParagraph([ - createInline(new Text("Hello, ")), - createInline(new Text("World!")) - ]); + const textEditorMock = TextEditorMock.createTextEditorMockWithParagraph([ + createInline(new Text("Hello, ")), + createInline(new Text("World!")), + ]); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -530,33 +528,28 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.lastChild.firstChild, - "World!".length + "World!".length, ); selectionController.replaceInlines("Mundo"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.dataset.itype).toBe("root"); - expect(textEditorMock.root.firstChild).toBeInstanceOf( - HTMLDivElement - ); + expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.children).toHaveLength(1); - expect(textEditorMock.root.firstChild.dataset.itype).toBe( - "paragraph" + expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); + expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( + HTMLSpanElement, + ); + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", ); - expect( - textEditorMock.root.firstChild.firstChild - ).toBeInstanceOf(HTMLSpanElement); - expect( - textEditorMock.root.firstChild.firstChild.dataset.itype - ).toBe("inline"); expect(textEditorMock.root.textContent).toBe("Mundo"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - .nodeValue - ).toBe("Mundo"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Mundo", + ); }); test("`replaceInlines` should replace the selected text in multiple inlines (2 partially selected)", () => { @@ -568,7 +561,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -576,7 +569,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 2, root.firstChild.lastChild.firstChild, - "World!".length - 3 + "World!".length - 3, ); selectionController.replaceInlines("Mundo"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -585,23 +578,23 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(2); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("HeMundold!"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( - "HeMundo" + "HeMundo", ); expect(textEditorMock.root.firstChild.lastChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.firstChild.lastChild.firstChild.nodeValue).toBe( - "ld!" + "ld!", ); }); @@ -614,7 +607,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -622,7 +615,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 2, root.firstChild.lastChild.firstChild, - "World!".length + "World!".length, ); selectionController.replaceInlines("Mundo"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -631,17 +624,17 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("HeMundo"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( - "HeMundo" + "HeMundo", ); }); @@ -654,7 +647,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -662,7 +655,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.lastChild.firstChild, - "World!".length - 3 + "World!".length - 3, ); selectionController.replaceInlines("Mundo"); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -671,27 +664,28 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Mundold!"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( - "Mundold!" + "Mundold!", ); }); test("`removeSelected` removes a word", () => { - const textEditorMock = TextEditorMock.createTextEditorMockWithText("Hello, World!"); + const textEditorMock = + TextEditorMock.createTextEditorMockWithText("Hello, World!"); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -699,7 +693,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 7, root.firstChild.lastChild.firstChild, - "Hello, World!".length - 1 + "Hello, World!".length - 1, ); selectionController.removeSelected(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -708,18 +702,18 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Hello, !"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild.nodeValue - ).toBe("Hello, !"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Hello, !", + ); }); test("`removeSelected` multiple inlines", () => { @@ -731,7 +725,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -739,7 +733,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 0, root.firstChild.lastChild.firstChild, - "World!".length + "World!".length, ); selectionController.removeSelected(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -748,34 +742,28 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe(""); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - HTMLBRElement + HTMLBRElement, ); }); test("`removeSelected` multiple paragraphs", () => { const textEditorMock = TextEditorMock.createTextEditorMockWithParagraphs([ - createParagraph([ - createInline(new Text("Hello, ")) - ]), - createParagraph([ - createInline(createLineBreak()) - ]), - createParagraph([ - createInline(new Text("World!")) - ]), + createParagraph([createInline(new Text("Hello, "))]), + createParagraph([createInline(createLineBreak())]), + createParagraph([createInline(new Text("World!"))]), ]); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -783,7 +771,7 @@ describe("SelectionController", () => { root.lastElementChild, 0, root.children.item(1).firstChild, - 0 + 0, ); selectionController.removeSelected(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -793,38 +781,37 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( - "Hello, " + "Hello, ", ); expect(textEditorMock.root.lastChild.firstChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.lastChild.firstChild.firstChild.nodeValue).toBe( - "World!" + "World!", ); }); test("`removeSelected` and `removeBackwardParagraph`", () => { - const textEditorMock = - TextEditorMock.createTextEditorMockWithParagraphs([ - createParagraph([createInline(new Text("Hello, World!"))]), - createParagraph([createInline(createLineBreak())]), - createParagraph([createInline(new Text("This is a test"))]), - ]); + const textEditorMock = TextEditorMock.createTextEditorMockWithParagraphs([ + createParagraph([createInline(new Text("Hello, World!"))]), + createParagraph([createInline(createLineBreak())]), + createParagraph([createInline(new Text("This is a test"))]), + ]); const root = textEditorMock.root; const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -832,7 +819,7 @@ describe("SelectionController", () => { root.lastElementChild.firstElementChild.firstChild, // This is a test text 0, root.lastElementChild.firstElementChild.firstChild, - "This is a test".length + "This is a test".length, ); selectionController.removeSelected(); selectionController.removeBackwardParagraph(); @@ -843,18 +830,18 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); - expect( - textEditorMock.root.firstChild.firstChild.firstChild - ).toBeInstanceOf(Text); - expect( - textEditorMock.root.firstChild.firstChild.firstChild.nodeValue - ).toBe("Hello, World!"); + expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( + Text, + ); + expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( + "Hello, World!", + ); }); test("`removeSelected` and `removeForwardParagraph`", () => { @@ -867,7 +854,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -875,7 +862,7 @@ describe("SelectionController", () => { root.firstElementChild.firstElementChild.firstChild, // This is a test text 0, root.firstElementChild.firstElementChild.firstChild, - "Hello, World!".length + "Hello, World!".length, ); selectionController.removeSelected(); selectionController.removeForwardParagraph(); @@ -886,17 +873,17 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("This is a test"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - HTMLBRElement + HTMLBRElement, ); expect(textEditorMock.root.lastChild.firstChild.firstChild.nodeValue).toBe( - "This is a test" + "This is a test", ); }); @@ -910,7 +897,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -918,7 +905,7 @@ describe("SelectionController", () => { root.firstElementChild.firstElementChild.firstChild, // This is a test text 0, root.firstElementChild.firstElementChild.firstChild, - "Hello, World!".length + "Hello, World!".length, ); selectionController.removeSelected(); @@ -932,17 +919,17 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.children).toHaveLength(1); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.textContent).toBe("This is a test"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - HTMLBRElement + HTMLBRElement, ); expect(textEditorMock.root.lastChild.firstChild.firstChild.nodeValue).toBe( - "This is a test" + "This is a test", ); }); @@ -956,7 +943,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -964,7 +951,7 @@ describe("SelectionController", () => { root.firstElementChild.firstElementChild.firstChild, // This is a test text 0, root.lastElementChild.firstElementChild.firstChild, - "This is a test".length + "This is a test".length, ); selectionController.removeSelected(); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); @@ -975,7 +962,7 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.textContent).toBe(""); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - HTMLBRElement + HTMLBRElement, ); }); @@ -989,7 +976,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -997,7 +984,7 @@ describe("SelectionController", () => { root.firstElementChild.firstElementChild.firstChild, // This is a test text 0, root.lastElementChild.firstElementChild.firstChild, - "This is a test".length + "This is a test".length, ); selectionController.removeSelected(); selectionController.replaceLineBreak("Hello, World!"); @@ -1009,28 +996,32 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.textContent).toBe("Hello, World!"); expect(textEditorMock.root.firstChild.firstChild.firstChild).toBeInstanceOf( - Text + Text, ); expect(textEditorMock.root.firstChild.firstChild.firstChild.nodeValue).toBe( - "Hello, World!" + "Hello, World!", ); }); - test('`applyStyles` to text', () => { - const textEditorMock = TextEditorMock.createTextEditorMockWithText("Hello, World!"); + test("`applyStyles` to text", () => { + const textEditorMock = + TextEditorMock.createTextEditorMockWithText("Hello, World!"); const root = textEditorMock.root; const selection = document.getSelection(); - const selectionController = new SelectionController(textEditorMock, selection); + const selectionController = new SelectionController( + textEditorMock, + selection, + ); focus( selection, textEditorMock, root.firstChild.firstChild.firstChild, root.firstChild.firstChild.firstChild.nodeValue.length - 1, root.firstChild.firstChild.firstChild, - root.firstChild.firstChild.firstChild.nodeValue.length - 6 + root.firstChild.firstChild.firstChild.nodeValue.length - 6, ); selectionController.applyStyles({ - "font-weight": "bold" + "font-weight": "bold", }); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.children.length).toBe(1); @@ -1038,38 +1029,49 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.children.length).toBe(3); - expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe("inline"); + expect(textEditorMock.root.firstChild.firstChild.dataset.itype).toBe( + "inline", + ); expect(textEditorMock.root.textContent).toBe("Hello, World!"); - expect(textEditorMock.root.firstChild.children.item(0).textContent).toBe("Hello, "); - expect(textEditorMock.root.firstChild.children.item(1).textContent).toBe("World"); - expect(textEditorMock.root.firstChild.children.item(2).textContent).toBe("!"); + expect(textEditorMock.root.firstChild.children.item(0).textContent).toBe( + "Hello, ", + ); + expect(textEditorMock.root.firstChild.children.item(1).textContent).toBe( + "World", + ); + expect(textEditorMock.root.firstChild.children.item(2).textContent).toBe( + "!", + ); }); - test('`applyStyles` to inlines', () => { + test("`applyStyles` to inlines", () => { const textEditorMock = TextEditorMock.createTextEditorMockWithParagraph([ createInline(new Text("Hello, "), { - "font-style": "italic" + "font-style": "italic", }), createInline(new Text("World!"), { - "font-style": "oblique" - }) + "font-style": "oblique", + }), ]); const root = textEditorMock.root; const selection = document.getSelection(); - const selectionController = new SelectionController(textEditorMock, selection); + const selectionController = new SelectionController( + textEditorMock, + selection, + ); focus( selection, textEditorMock, root.firstChild.firstChild.firstChild, 2, root.firstChild.lastChild.firstChild, - root.firstChild.lastChild.firstChild.nodeValue.length - 3 + root.firstChild.lastChild.firstChild.nodeValue.length - 3, ); selectionController.applyStyles({ - "font-weight": "bold" + "font-weight": "bold", }); expect(textEditorMock.root).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.children.length).toBe(1); @@ -1078,26 +1080,36 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.children.length).toBe(4); - expect(textEditorMock.root.firstChild.children.item(0).dataset.itype).toBe("inline"); - expect(textEditorMock.root.firstChild.children.item(0).textContent).toBe("He"); + expect(textEditorMock.root.firstChild.children.item(0).dataset.itype).toBe( + "inline", + ); + expect(textEditorMock.root.firstChild.children.item(0).textContent).toBe( + "He", + ); expect(textEditorMock.root.firstChild.children.item(1).dataset.itype).toBe( - "inline" + "inline", + ); + expect(textEditorMock.root.firstChild.children.item(1).textContent).toBe( + "llo, ", ); - expect(textEditorMock.root.firstChild.children.item(1).textContent).toBe("llo, "); expect(textEditorMock.root.firstChild.children.item(2).dataset.itype).toBe( - "inline" + "inline", + ); + expect(textEditorMock.root.firstChild.children.item(2).textContent).toBe( + "Wor", ); - expect(textEditorMock.root.firstChild.children.item(2).textContent).toBe("Wor"); expect(textEditorMock.root.firstChild.children.item(3).dataset.itype).toBe( - "inline" + "inline", + ); + expect(textEditorMock.root.firstChild.children.item(3).textContent).toBe( + "ld!", ); - expect(textEditorMock.root.firstChild.children.item(3).textContent).toBe("ld!"); }); - test('`applyStyles` to paragraphs', () => { + test("`applyStyles` to paragraphs", () => { const textEditorMock = TextEditorMock.createTextEditorMockWithParagraphs([ createParagraph([ createInline(new Text("Hello, "), { @@ -1114,7 +1126,7 @@ describe("SelectionController", () => { const selection = document.getSelection(); const selectionController = new SelectionController( textEditorMock, - selection + selection, ); focus( selection, @@ -1122,7 +1134,7 @@ describe("SelectionController", () => { root.firstChild.firstChild.firstChild, 2, root.lastChild.firstChild.firstChild, - root.lastChild.firstChild.firstChild.nodeValue.length - 3 + root.lastChild.firstChild.firstChild.nodeValue.length - 3, ); selectionController.applyStyles({ "font-weight": "bold", @@ -1134,33 +1146,33 @@ describe("SelectionController", () => { expect(textEditorMock.root.firstChild).toBeInstanceOf(HTMLDivElement); expect(textEditorMock.root.firstChild.dataset.itype).toBe("paragraph"); expect(textEditorMock.root.firstChild.firstChild).toBeInstanceOf( - HTMLSpanElement + HTMLSpanElement, ); expect(textEditorMock.root.firstChild.children.length).toBe(2); expect(textEditorMock.root.firstChild.children.item(0).dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.firstChild.children.item(0).textContent).toBe( - "He" + "He", ); expect(textEditorMock.root.firstChild.children.item(1).dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.firstChild.children.item(1).textContent).toBe( - "llo, " + "llo, ", ); expect(textEditorMock.root.lastChild.children.length).toBe(2); expect(textEditorMock.root.lastChild.children.item(0).dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.lastChild.children.item(0).textContent).toBe( - "Wor" + "Wor", ); expect(textEditorMock.root.lastChild.children.item(1).dataset.itype).toBe( - "inline" + "inline", ); expect(textEditorMock.root.lastChild.children.item(1).textContent).toBe( - "ld!" + "ld!", ); }); }); diff --git a/frontend/text-editor/editor/controllers/SelectionDirection.js b/frontend/text-editor/src/editor/controllers/SelectionDirection.js similarity index 100% rename from frontend/text-editor/editor/controllers/SelectionDirection.js rename to frontend/text-editor/src/editor/controllers/SelectionDirection.js diff --git a/frontend/text-editor/editor/debug/SelectionControllerDebug.js b/frontend/text-editor/src/editor/debug/SelectionControllerDebug.js similarity index 100% rename from frontend/text-editor/editor/debug/SelectionControllerDebug.js rename to frontend/text-editor/src/editor/debug/SelectionControllerDebug.js diff --git a/frontend/text-editor/editor/layout/LayoutType.js b/frontend/text-editor/src/editor/layout/LayoutType.js similarity index 100% rename from frontend/text-editor/editor/layout/LayoutType.js rename to frontend/text-editor/src/editor/layout/LayoutType.js diff --git a/frontend/text-editor/editor/selection/Imposter.js b/frontend/text-editor/src/editor/selection/Imposter.js similarity index 100% rename from frontend/text-editor/editor/selection/Imposter.js rename to frontend/text-editor/src/editor/selection/Imposter.js diff --git a/frontend/text-editor/editor/selection/Imposter.spec.js b/frontend/text-editor/src/editor/selection/Imposter.spec.js similarity index 93% rename from frontend/text-editor/editor/selection/Imposter.spec.js rename to frontend/text-editor/src/editor/selection/Imposter.spec.js index b0b619a87..20088a83c 100644 --- a/frontend/text-editor/editor/selection/Imposter.spec.js +++ b/frontend/text-editor/src/editor/selection/Imposter.spec.js @@ -6,7 +6,7 @@ test("Create selection DOM rects from client rects", () => { const rect = new DOMRect(20, 20, 100, 50); const clientRects = [ new DOMRect(20, 20, 100, 20), - new DOMRect(20, 50, 50, 20) + new DOMRect(20, 50, 50, 20), ]; const fragment = createSelectionImposterFromClientRects(rect, clientRects); expect(fragment).toBeInstanceOf(DocumentFragment); diff --git a/frontend/text-editor/index.html b/frontend/text-editor/src/index.html similarity index 100% rename from frontend/text-editor/index.html rename to frontend/text-editor/src/index.html diff --git a/frontend/text-editor/main.js b/frontend/text-editor/src/main.js similarity index 100% rename from frontend/text-editor/main.js rename to frontend/text-editor/src/main.js diff --git a/frontend/text-editor/style.css b/frontend/text-editor/src/style.css similarity index 100% rename from frontend/text-editor/style.css rename to frontend/text-editor/src/style.css diff --git a/frontend/text-editor/test/TextEditorMock.js b/frontend/text-editor/src/test/TextEditorMock.js similarity index 91% rename from frontend/text-editor/test/TextEditorMock.js rename to frontend/text-editor/src/test/TextEditorMock.js index f41cb2107..ef66f5d6f 100644 --- a/frontend/text-editor/test/TextEditorMock.js +++ b/frontend/text-editor/src/test/TextEditorMock.js @@ -1,7 +1,7 @@ -import { createRoot } from "~/editor/content/dom/Root"; -import { createParagraph } from "~/editor/content/dom/Paragraph"; -import { createEmptyInline, createInline } from "~/editor/content/dom/Inline"; -import { createLineBreak } from "~/editor/content/dom/LineBreak"; +import { createRoot } from "../editor/content/dom/Root.js"; +import { createParagraph } from "../editor/content/dom/Paragraph.js"; +import { createEmptyInline, createInline } from "../editor/content/dom/Inline.js"; +import { createLineBreak } from "../editor/content/dom/LineBreak.js"; export class TextEditorMock extends EventTarget { /** diff --git a/frontend/text-editor/vite.config.js b/frontend/text-editor/vite.config.js index 4ff019fc1..a6e7b4daf 100644 --- a/frontend/text-editor/vite.config.js +++ b/frontend/text-editor/vite.config.js @@ -1,26 +1,23 @@ import { resolve } from "node:path"; import { defineConfig } from "vite"; -import { coverageConfigDefaults } from 'vitest/config' +import { coverageConfigDefaults } from "vitest/config" export default defineConfig({ + root: "./src", resolve: { alias: { - "~": resolve("."), + "~": resolve("./src"), }, }, build: { - minify: false, + minify: true, sourcemap: true, lib: { - entry: "editor/TextEditor.js", + entry: "src/editor/TextEditor.js", name: "TextEditor", fileName: "TextEditor", formats: ["es"], }, - terserOptions: { - compress: true, - mangle: true, - }, }, test: { coverage: { diff --git a/frontend/text-editor/yarn.lock b/frontend/text-editor/yarn.lock index 20f460e3c..0a63cb6cd 100644 --- a/frontend/text-editor/yarn.lock +++ b/frontend/text-editor/yarn.lock @@ -518,6 +518,7 @@ __metadata: esbuild: "npm:^0.24.0" jsdom: "npm:^25.0.0" playwright: "npm:^1.45.1" + prettier: "npm:^3.3.3" vite: "npm:^5.3.1" vitest: "npm:^1.6.0" languageName: unknown @@ -2292,6 +2293,15 @@ __metadata: languageName: node linkType: hard +"prettier@npm:^3.3.3": + version: 3.3.3 + resolution: "prettier@npm:3.3.3" + bin: + prettier: bin/prettier.cjs + checksum: 10c0/b85828b08e7505716324e4245549b9205c0cacb25342a030ba8885aba2039a115dbcf75a0b7ca3b37bc9d101ee61fab8113fc69ca3359f2a226f1ecc07ad2e26 + languageName: node + linkType: hard + "pretty-format@npm:^29.7.0": version: 29.7.0 resolution: "pretty-format@npm:29.7.0"