refactor: Clean up UI types (#26909)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// serialization must fold those back into `\n` so the emitted value never
|
||||
// diverges from what is on screen.
|
||||
|
||||
import ChatFormContenteditableHarness from './components/ChatFormContenteditableHarness.svelte';
|
||||
import ChatFormContentEditableHarness from './components/ChatFormContentEditableHarness.svelte';
|
||||
import { tick } from 'svelte';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { render } from 'vitest-browser-svelte';
|
||||
@@ -35,9 +35,9 @@ function setCaret(node: Node, offset: number) {
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
describe('ChatFormContentEditable browser newline shapes', () => {
|
||||
it('serializes a Chromium Enter <div> wrapper as a newline', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: SOURCE });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -53,7 +53,7 @@ describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
});
|
||||
|
||||
it('serializes a Firefox full <div> wrap as lines, badge included', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: SOURCE });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
});
|
||||
|
||||
it('serializes a <br> as a newline', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'here' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'here' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
});
|
||||
|
||||
it('ignores a trailing <br> (browser caret placeholder)', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -102,7 +102,7 @@ describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
});
|
||||
|
||||
it('serializes one newline per empty-line <div><br></div>', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -121,7 +121,7 @@ describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
});
|
||||
|
||||
it('treats a <div><br></div>-only buffer as empty for the placeholder', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -138,7 +138,7 @@ describe('ChatFormContenteditable browser newline shapes', () => {
|
||||
});
|
||||
|
||||
it('maps the caret across block boundaries in both directions', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc\ndef' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc\ndef' });
|
||||
|
||||
await tick();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// the native undo stack), and Tab is NOT intercepted (WCAG 2.1.2 no
|
||||
// keyboard trap), matching the plain textarea.
|
||||
|
||||
import ChatFormContenteditableHarness from './components/ChatFormContenteditableHarness.svelte';
|
||||
import ChatFormContentEditableHarness from './components/ChatFormContentEditableHarness.svelte';
|
||||
import { tick } from 'svelte';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { render } from 'vitest-browser-svelte';
|
||||
@@ -31,9 +31,9 @@ function keydown(root: HTMLElement, init: KeyboardEventInit) {
|
||||
return event;
|
||||
}
|
||||
|
||||
describe('ChatFormContenteditable undo/redo', () => {
|
||||
describe('ChatFormContentEditable undo/redo', () => {
|
||||
it('undoes and redoes an edit across a badge-containing buffer', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: SOURCE });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('ChatFormContenteditable undo/redo', () => {
|
||||
});
|
||||
|
||||
it('redoes with Ctrl+Y as well', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: SOURCE });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('ChatFormContenteditable undo/redo', () => {
|
||||
});
|
||||
|
||||
it('coalesces a typing burst into one undo step', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -92,7 +92,7 @@ describe('ChatFormContenteditable undo/redo', () => {
|
||||
});
|
||||
|
||||
it('keeps a newline as its own undo step', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -113,7 +113,7 @@ describe('ChatFormContenteditable undo/redo', () => {
|
||||
});
|
||||
|
||||
it('is a no-op when there is nothing to undo', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -127,7 +127,7 @@ describe('ChatFormContenteditable undo/redo', () => {
|
||||
});
|
||||
|
||||
it('abandons the redo branch after a fresh edit', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: 'abc' });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: 'abc' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -147,9 +147,9 @@ describe('ChatFormContenteditable undo/redo', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChatFormContenteditable Tab key', () => {
|
||||
describe('ChatFormContentEditable Tab key', () => {
|
||||
it('does not trap Tab (focus can leave the editable)', async () => {
|
||||
const screen = render(ChatFormContenteditableHarness, { value: SOURCE });
|
||||
const screen = render(ChatFormContentEditableHarness, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// contributes its full `[name](file://...)` link) and pasting such
|
||||
// markdown re-renders the badges.
|
||||
|
||||
import ChatFormContenteditable from '$lib/components/app/chat/ChatForm/ChatFormContenteditable.svelte';
|
||||
import ChatFormContentEditable from '$lib/components/app/chat/ChatForm/ChatFormContentEditable.svelte';
|
||||
import { rangeToTextOffset, serializeContent, textOffsetToRange } from '$lib/utils';
|
||||
import { tick } from 'svelte';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
@@ -43,9 +43,9 @@ function clipboardEvent(type: 'copy' | 'cut' | 'paste', text = '') {
|
||||
return { data, event };
|
||||
}
|
||||
|
||||
describe('ChatFormContenteditable clipboard', () => {
|
||||
describe('ChatFormContentEditable clipboard', () => {
|
||||
it('copy exposes the markdown source of the selection', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -62,7 +62,7 @@ describe('ChatFormContenteditable clipboard', () => {
|
||||
});
|
||||
|
||||
it('cut exposes the markdown source and removes the slice', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -88,7 +88,7 @@ describe('ChatFormContenteditable clipboard', () => {
|
||||
});
|
||||
|
||||
it('paste of markdown mention links re-renders badges', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: 'hello ' });
|
||||
const { container } = render(ChatFormContentEditable, { value: 'hello ' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -114,7 +114,7 @@ describe('ChatFormContenteditable clipboard', () => {
|
||||
});
|
||||
|
||||
it('paste without mention links keeps the DOM untouched', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: 'hello ' });
|
||||
const { container } = render(ChatFormContentEditable, { value: 'hello ' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -138,9 +138,9 @@ describe('ChatFormContenteditable clipboard', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChatFormContenteditable code spans', () => {
|
||||
describe('ChatFormContentEditable code spans', () => {
|
||||
it('renders inline code from the initial value', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: 'run `npm test` now' });
|
||||
const { container } = render(ChatFormContentEditable, { value: 'run `npm test` now' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -153,7 +153,7 @@ describe('ChatFormContenteditable code spans', () => {
|
||||
|
||||
it('renders a fenced code block with a language', async () => {
|
||||
const source = 'before\n```js\nconst a = 1;\n```\nafter';
|
||||
const { container } = render(ChatFormContenteditable, { value: source });
|
||||
const { container } = render(ChatFormContentEditable, { value: source });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -166,7 +166,7 @@ describe('ChatFormContenteditable code spans', () => {
|
||||
|
||||
it('copy exposes the markdown source of a selection spanning code', async () => {
|
||||
const source = 'run `npm test` now';
|
||||
const { container } = render(ChatFormContenteditable, { value: source });
|
||||
const { container } = render(ChatFormContentEditable, { value: source });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -183,7 +183,7 @@ describe('ChatFormContenteditable code spans', () => {
|
||||
});
|
||||
|
||||
it('paste of a code span renders the styled element', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: 'run ' });
|
||||
const { container } = render(ChatFormContentEditable, { value: 'run ' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -210,7 +210,7 @@ describe('ChatFormContenteditable code spans', () => {
|
||||
|
||||
it('highlights a fenced block content and stays byte-exact', async () => {
|
||||
const source = '```js\nconst a = 1;\n```';
|
||||
const { container } = render(ChatFormContenteditable, { value: source });
|
||||
const { container } = render(ChatFormContentEditable, { value: source });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -223,7 +223,7 @@ describe('ChatFormContenteditable code spans', () => {
|
||||
});
|
||||
|
||||
it('does not highlight inline code', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: 'run `const` now' });
|
||||
const { container } = render(ChatFormContentEditable, { value: 'run `const` now' });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -233,7 +233,7 @@ describe('ChatFormContenteditable code spans', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
describe('ChatFormContentEditable code block escape hatches', () => {
|
||||
const BLOCK_SOURCE = '```js\nconst a = 1;\n```';
|
||||
const BLOCK_SELECTOR = 'code[data-code-token="block"]';
|
||||
|
||||
@@ -273,7 +273,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
}
|
||||
|
||||
it('pads a trailing code block with a br hatch that stays invisible to copy', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -292,7 +292,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('escapes a trailing code block with ArrowDown and types after it', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -318,7 +318,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('escapes a leading code block with ArrowUp and types before it', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -343,7 +343,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('escapes a leading code block with ArrowLeft from its first character', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -358,7 +358,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('removes the transient leading hatch when the caret moves back into the block', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -378,7 +378,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('extends the selection out of the block with Shift+ArrowDown', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -397,7 +397,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('line-separates text typed right after the closing fence', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -419,7 +419,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('does not double the newline when Shift+Enter already added one', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -437,7 +437,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('moves a caret stuck before the inserted newline onto the new line', async () => {
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
value: BLOCK_SOURCE + '\ntext after the code block'
|
||||
});
|
||||
|
||||
@@ -469,7 +469,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('appends the artificial trailing newline when the browser did not add one', async () => {
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
value: BLOCK_SOURCE + '\ntext after the code block'
|
||||
});
|
||||
|
||||
@@ -501,7 +501,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('lands the caret on the new line with a single Shift+Enter after text below a block', async () => {
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
value: BLOCK_SOURCE + '\ntext after the code block'
|
||||
});
|
||||
|
||||
@@ -534,7 +534,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('lets Backspace at the text start move into the block without a source fight', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -560,7 +560,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('lets forward Delete eat the text after a block normally', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -581,7 +581,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('renders text after a block without a phantom empty line', async () => {
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
value: BLOCK_SOURCE + '\nhello'
|
||||
});
|
||||
|
||||
@@ -594,7 +594,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('keeps an intentional blank line after a block out of the separator', async () => {
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
value: BLOCK_SOURCE + '\n\nhello'
|
||||
});
|
||||
|
||||
@@ -607,7 +607,7 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
|
||||
it('re-highlights while typing inside a block and keeps the caret', async () => {
|
||||
const { container } = render(ChatFormContenteditable, { value: BLOCK_SOURCE });
|
||||
const { container } = render(ChatFormContentEditable, { value: BLOCK_SOURCE });
|
||||
|
||||
await tick();
|
||||
|
||||
@@ -639,12 +639,12 @@ describe('ChatFormContenteditable code block escape hatches', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('ChatFormContenteditable Enter in code blocks', () => {
|
||||
describe('ChatFormContentEditable Enter in code blocks', () => {
|
||||
const BLOCK_SOURCE = '```js\nconst a = 1;\n```';
|
||||
|
||||
it('adds a line instead of submitting on plain Enter inside a block', async () => {
|
||||
const onKeydown = vi.fn();
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
onKeydown,
|
||||
value: BLOCK_SOURCE
|
||||
});
|
||||
@@ -679,7 +679,7 @@ describe('ChatFormContenteditable Enter in code blocks', () => {
|
||||
|
||||
it('adds a line after a still-open fence (no closing ``` yet)', async () => {
|
||||
const onKeydown = vi.fn();
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
onKeydown,
|
||||
value: '```js\nconst a = 1;'
|
||||
});
|
||||
@@ -707,7 +707,7 @@ describe('ChatFormContenteditable Enter in code blocks', () => {
|
||||
|
||||
it('forwards plain Enter to the parent when the caret is outside a block', async () => {
|
||||
const onKeydown = vi.fn();
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
onKeydown,
|
||||
value: BLOCK_SOURCE + '\nafter'
|
||||
});
|
||||
@@ -730,7 +730,7 @@ describe('ChatFormContenteditable Enter in code blocks', () => {
|
||||
|
||||
it('forwards plain Enter on the trailing hatch line after a block', async () => {
|
||||
const onKeydown = vi.fn();
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
onKeydown,
|
||||
value: BLOCK_SOURCE
|
||||
});
|
||||
@@ -753,7 +753,7 @@ describe('ChatFormContenteditable Enter in code blocks', () => {
|
||||
|
||||
it('forwards Ctrl+Enter inside a block so explicit submit survives', async () => {
|
||||
const onKeydown = vi.fn();
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
onKeydown,
|
||||
value: BLOCK_SOURCE
|
||||
});
|
||||
@@ -780,7 +780,7 @@ describe('ChatFormContenteditable Enter in code blocks', () => {
|
||||
|
||||
it('forwards Enter inside an inline code span', async () => {
|
||||
const onKeydown = vi.fn();
|
||||
const { container } = render(ChatFormContenteditable, {
|
||||
const { container } = render(ChatFormContentEditable, {
|
||||
onKeydown,
|
||||
value: 'run `npm test` now'
|
||||
});
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import ChatFormContenteditable from '$lib/components/app/chat/ChatForm/ChatFormContenteditable.svelte';
|
||||
import ChatFormContentEditable from '$lib/components/app/chat/ChatForm/ChatFormContentEditable.svelte';
|
||||
import { untrack } from 'svelte';
|
||||
|
||||
interface Props {
|
||||
@@ -9,7 +9,7 @@
|
||||
let { value: initial = '' }: Props = $props();
|
||||
|
||||
let value = $state(untrack(() => initial));
|
||||
let inputRef: ChatFormContenteditable | undefined = $state(undefined);
|
||||
let inputRef: ChatFormContentEditable | undefined = $state(undefined);
|
||||
|
||||
export function getValue() {
|
||||
return value;
|
||||
@@ -24,4 +24,4 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<ChatFormContenteditable bind:this={inputRef} bind:value />
|
||||
<ChatFormContentEditable bind:this={inputRef} bind:value />
|
||||
Reference in New Issue
Block a user