Skip to content

Commit 50756f1

Browse files
committed
General clean-up and removal of dead code
1 parent eaab44d commit 50756f1

File tree

7 files changed

+13
-134
lines changed

7 files changed

+13
-134
lines changed

src/prompt-input/__tests__/dom-utils.test.ts

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
createTrailingBreak,
1111
findAllParagraphs,
1212
findElement,
13-
findElements,
1413
getLogicalDirection,
1514
getTokenType,
1615
hasOnlyTrailingBR,
@@ -97,42 +96,6 @@ describe('createTrailingBreak', () => {
9796
});
9897
});
9998

100-
describe('findElements', () => {
101-
test('finds elements by tokenType', () => {
102-
const container = document.createElement('div');
103-
const ref1 = document.createElement('span');
104-
ref1.setAttribute('data-type', 'reference');
105-
const ref2 = document.createElement('span');
106-
ref2.setAttribute('data-type', 'reference');
107-
const other = document.createElement('span');
108-
other.setAttribute('data-type', 'text');
109-
container.appendChild(ref1);
110-
container.appendChild(ref2);
111-
container.appendChild(other);
112-
113-
const results = findElements(container, { tokenType: 'reference' });
114-
expect(results).toHaveLength(2);
115-
});
116-
117-
test('finds elements by array of tokenTypes', () => {
118-
const container = document.createElement('div');
119-
const refEl = document.createElement('span');
120-
refEl.setAttribute('data-type', 'reference');
121-
const pinned = document.createElement('span');
122-
pinned.setAttribute('data-type', 'pinned');
123-
container.appendChild(refEl);
124-
container.appendChild(pinned);
125-
126-
const results = findElements(container, { tokenType: ['reference', 'pinned'] });
127-
expect(results).toHaveLength(2);
128-
});
129-
130-
test('returns empty array when no options provided', () => {
131-
const container = document.createElement('div');
132-
expect(findElements(container, {})).toEqual([]);
133-
});
134-
});
135-
13699
describe('findElement', () => {
137100
test('finds first matching element', () => {
138101
const container = document.createElement('div');
@@ -318,32 +281,6 @@ describe('setEmptyState', () => {
318281
});
319282
});
320283

321-
describe('findElements with tokenId', () => {
322-
test('finds element by data-id for non-trigger types', () => {
323-
const container = document.createElement('div');
324-
const el = document.createElement('span');
325-
el.setAttribute('data-type', 'reference');
326-
el.setAttribute('data-id', 'ref-123');
327-
container.appendChild(el);
328-
329-
const results = findElements(container, { tokenType: 'reference', tokenId: 'ref-123' });
330-
expect(results).toHaveLength(1);
331-
expect(results[0]).toBe(el);
332-
});
333-
334-
test('finds trigger element by data-id attribute', () => {
335-
const container = document.createElement('div');
336-
const el = document.createElement('span');
337-
el.setAttribute('data-type', ElementType.Trigger);
338-
el.setAttribute('data-id', 'trigger-123');
339-
container.appendChild(el);
340-
341-
const results = findElements(container, { tokenType: ElementType.Trigger, tokenId: 'trigger-123' });
342-
expect(results).toHaveLength(1);
343-
expect(results[0]).toBe(el);
344-
});
345-
});
346-
347284
describe('getLogicalDirection', () => {
348285
let el: HTMLDivElement;
349286

src/prompt-input/__tests__/token-utils.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
getCaretPositionAfterTokenRemoval,
1414
mergeConsecutiveTextTokens,
1515
validateTrigger,
16-
validateTriggerWithPinnedTokens,
1716
} from '../core/token-utils';
1817
import { PromptInputProps } from '../interfaces';
1918

@@ -123,37 +122,6 @@ describe('areAllTokensPinned', () => {
123122
});
124123
});
125124

126-
describe('validateTriggerWithPinnedTokens', () => {
127-
const useAtStartMenu: PromptInputProps.MenuDefinition = {
128-
id: 'files',
129-
trigger: '#',
130-
options: [],
131-
useAtStart: true,
132-
};
133-
const normalMenu: PromptInputProps.MenuDefinition = {
134-
id: 'mentions',
135-
trigger: '@',
136-
options: [],
137-
};
138-
139-
test('returns true for useAtStart menu when all preceding tokens are pinned', () => {
140-
expect(validateTriggerWithPinnedTokens(useAtStartMenu, [pinnedRef('p1', '#a', 'a', 'f')])).toBe(true);
141-
});
142-
143-
test('returns true for useAtStart menu when no preceding tokens', () => {
144-
expect(validateTriggerWithPinnedTokens(useAtStartMenu, [])).toBe(true);
145-
});
146-
147-
test('returns false for useAtStart menu when preceding tokens include non-pinned', () => {
148-
expect(validateTriggerWithPinnedTokens(useAtStartMenu, [text('hello')])).toBe(false);
149-
});
150-
151-
test('returns true for normal menu regardless of preceding tokens', () => {
152-
expect(validateTriggerWithPinnedTokens(normalMenu, [text('hello')])).toBe(true);
153-
expect(validateTriggerWithPinnedTokens(normalMenu, [])).toBe(true);
154-
});
155-
});
156-
157125
describe('validateTrigger', () => {
158126
const useAtStartMenu: PromptInputProps.MenuDefinition = {
159127
id: 'files',

src/prompt-input/core/dom-utils.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ function buildTokenSelector(options: TokenQueryOptions): string {
9191
return selector;
9292
}
9393

94-
/** Finds all elements matching the given token type and/or token ID within a container. */
95-
export function findElements(container: HTMLElement, options: TokenQueryOptions): HTMLElement[] {
96-
const selector = buildTokenSelector(options);
97-
return selector ? Array.from(container.querySelectorAll<HTMLElement>(selector)) : [];
98-
}
99-
10094
/** Finds the first element matching the given token type and/or token ID within a container. */
10195
export function findElement(container: HTMLElement, options: TokenQueryOptions): HTMLElement | null {
10296
const selector = buildTokenSelector(options);
@@ -137,11 +131,6 @@ export function isEmptyState(element: HTMLElement): boolean {
137131
return paragraphs.length === 0 || (paragraphs.length === 1 && hasOnlyTrailingBR(paragraphs[0]));
138132
}
139133

140-
/** Checks if a token type represents a caret spot element. */
141-
export function isCaretSpotType(tokenType: ElementType | string | null): boolean {
142-
return tokenType === ElementType.CaretSpotBefore || tokenType === ElementType.CaretSpotAfter;
143-
}
144-
145134
/** Resets the element to a single empty paragraph with a trailing BR. */
146135
export function setEmptyState(element: HTMLElement): void {
147136
const paragraphs = findAllParagraphs(element);
@@ -156,6 +145,11 @@ export function setEmptyState(element: HTMLElement): void {
156145
element.appendChild(p);
157146
}
158147

148+
/** Checks if a token type represents a caret spot element. */
149+
export function isCaretSpotType(tokenType: ElementType | string | null): boolean {
150+
return tokenType === ElementType.CaretSpotBefore || tokenType === ElementType.CaretSpotAfter;
151+
}
152+
159153
export type ArrowDirection = 'backward' | 'forward';
160154

161155
/** Resolves an arrow key to a logical reading direction, accounting for RTL. */

src/prompt-input/core/event-handlers.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
isCaretSpotType,
2020
isElementEffectivelyEmpty,
2121
isReferenceElementType,
22+
setEmptyState,
2223
stripZeroWidthCharacters,
2324
} from './dom-utils';
2425
import { MenuItemsHandlers, MenuItemsState } from './menu-state';
@@ -237,11 +238,14 @@ export function handleReferenceTokenDeletion(
237238

238239
// Clean up empty paragraphs left behind after deleting across paragraph boundaries
239240
const paragraphs = findAllParagraphs(editableElement);
240-
if (paragraphs.length > 1) {
241-
const firstNonEmpty = paragraphs.find(p => !isElementEffectivelyEmpty(p));
242-
const keepParagraph = firstNonEmpty || paragraphs[0];
241+
const allEmpty = paragraphs.every(p => isElementEffectivelyEmpty(p));
242+
243+
if (allEmpty) {
244+
setEmptyState(editableElement);
245+
} else if (paragraphs.length > 1) {
246+
const firstNonEmpty = paragraphs.find(p => !isElementEffectivelyEmpty(p))!;
243247
for (const p of paragraphs) {
244-
if (p !== keepParagraph) {
248+
if (p !== firstNonEmpty) {
245249
p.remove();
246250
}
247251
}

src/prompt-input/core/token-operations.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ import {
2727

2828
export type UpdateSource = 'user-input' | 'external' | 'menu-selection' | 'internal';
2929

30-
export interface TokenUpdate {
31-
tokens: PromptInputProps.InputToken[];
32-
source: UpdateSource;
33-
caretPosition?: number;
34-
}
35-
3630
export interface ShortcutsConfig {
3731
menus?: readonly PromptInputProps.MenuDefinition[];
3832
tokensToText?: (tokens: readonly PromptInputProps.InputToken[]) => string;

src/prompt-input/core/token-renderer.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ export interface PortalContainer {
5454
label: string;
5555
}
5656

57-
/** Props passed to the renderToken callback for rendering reference tokens. */
58-
export interface RenderTokenProps {
59-
id: string;
60-
label: string;
61-
disabled: boolean;
62-
readOnly: boolean;
63-
}
64-
6557
interface ParagraphGroup {
6658
tokens: PromptInputProps.InputToken[];
6759
}

src/prompt-input/core/token-utils.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ export function areAllTokensPinned(tokens: readonly PromptInputProps.InputToken[
5656
return tokens.every(isPinnedReferenceToken);
5757
}
5858

59-
export function validateTriggerWithPinnedTokens(
60-
menu: PromptInputProps.MenuDefinition,
61-
precedingTokens: readonly PromptInputProps.InputToken[]
62-
): boolean {
63-
if (menu.useAtStart) {
64-
return areAllTokensPinned(precedingTokens);
65-
}
66-
return true;
67-
}
68-
6959
/** Checks if a trigger is valid given the menu config, position, and preceding tokens. */
7060
export function validateTrigger(
7161
menu: PromptInputProps.MenuDefinition,

0 commit comments

Comments
 (0)