cursedbelt 5.91.0 → 5.92.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/react/activity-bar/activityBar.css +5 -0
- package/dist/react/code-editor/markdownRules.d.ts +8 -2
- package/dist/react/code-editor/markdownRules.d.ts.map +1 -1
- package/dist/react/code-editor/markdownRules.js +7 -3
- package/dist/react/code-editor/markdownRules.js.map +1 -1
- package/dist/react/components/Autocomplete.d.ts +11 -2
- package/dist/react/components/Autocomplete.d.ts.map +1 -1
- package/dist/react/components/Autocomplete.js +7 -6
- package/dist/react/components/Autocomplete.js.map +1 -1
- package/dist/react/components/Button.d.ts.map +1 -1
- package/dist/react/components/Button.js +7 -1
- package/dist/react/components/Button.js.map +1 -1
- package/dist/react/components/FileDropZone.d.ts.map +1 -1
- package/dist/react/components/FileDropZone.js +12 -76
- package/dist/react/components/FileDropZone.js.map +1 -1
- package/dist/react/components/TagsInput.d.ts +46 -4
- package/dist/react/components/TagsInput.d.ts.map +1 -1
- package/dist/react/components/TagsInput.js +92 -39
- package/dist/react/components/TagsInput.js.map +1 -1
- package/dist/react/components/TagsInputSuggesting.d.ts +8 -0
- package/dist/react/components/TagsInputSuggesting.d.ts.map +1 -0
- package/dist/react/components/TagsInputSuggesting.js +48 -0
- package/dist/react/components/TagsInputSuggesting.js.map +1 -0
- package/dist/react/components/dropTransfer.d.ts +53 -0
- package/dist/react/components/dropTransfer.d.ts.map +1 -0
- package/dist/react/components/dropTransfer.js +116 -0
- package/dist/react/components/dropTransfer.js.map +1 -0
- package/dist/react/components/suggestionList.d.ts +13 -0
- package/dist/react/components/suggestionList.d.ts.map +1 -0
- package/dist/react/components/suggestionList.js +19 -0
- package/dist/react/components/suggestionList.js.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/media-gallery/MediaMetaEditor.d.ts +4 -4
- package/dist/react/optimistic/optimistic.d.ts +11 -2
- package/dist/react/optimistic/optimistic.d.ts.map +1 -1
- package/dist/react/optimistic/optimistic.js +4 -2
- package/dist/react/optimistic/optimistic.js.map +1 -1
- package/dist/scripts/guardrailsEnforce.d.ts.map +1 -1
- package/dist/styles-areas/analytics.css +14 -19
- package/dist/styles-areas/auth.css +3 -4
- package/dist/styles-areas/canvas-hud.css +3 -3
- package/dist/styles-areas/chat.css +10 -11
- package/dist/styles-areas/code-editor.css +2 -2
- package/dist/styles-areas/core.css +60 -54
- package/dist/styles-areas/data-table.css +13 -17
- package/dist/styles-areas/disk-usage.css +6 -7
- package/dist/styles-areas/emoji.css +2 -3
- package/dist/styles-areas/fields.css +15 -20
- package/dist/styles-areas/master-detail.css +3 -4
- package/dist/styles-areas/master-lock.css +1 -2
- package/dist/styles-areas/media-gallery.css +8 -10
- package/dist/styles-areas/rich-text.css +3 -3
- package/dist/styles-areas/stats.css +13 -17
- package/dist/styles-areas/wizard.css +6 -11
- package/package.json +7 -1
- package/scripts/guardrails-baseline.json +1 -1
- package/scripts/guardrailsEnforce.spec.ts +13 -0
- package/scripts/guardrailsEnforce.ts +5 -3
- package/scripts/styleAreas.ts +3 -0
- package/src/react/activity-bar/activityBar.css +5 -0
- package/src/react/code-editor/markdownRules.spec.ts +10 -2
- package/src/react/code-editor/markdownRules.ts +11 -3
- package/src/react/components/Autocomplete.spec.tsx +55 -1
- package/src/react/components/Autocomplete.tsx +18 -43
- package/src/react/components/Button.spec.tsx +17 -0
- package/src/react/components/Button.tsx +7 -1
- package/src/react/components/FileDropZone.tsx +12 -83
- package/src/react/components/TagsInput.spec.tsx +129 -14
- package/src/react/components/TagsInput.tsx +153 -85
- package/src/react/components/TagsInputSuggesting.tsx +94 -0
- package/src/react/components/dropTransfer.spec.ts +76 -0
- package/src/react/components/dropTransfer.ts +133 -0
- package/src/react/components/suggestionList.tsx +66 -0
- package/src/react/disk-usage/DiskUsage.spec.tsx +3 -0
- package/src/react/index.ts +1 -0
- package/src/react/lib/floatingStyles.spec.ts +2 -1
- package/src/react/media-gallery/MediaMetaEditor.tsx +4 -4
- package/src/react/optimistic/optimistic.spec.tsx +41 -0
- package/src/react/optimistic/optimistic.ts +13 -4
- package/src/styles-areas/analytics.css +14 -19
- package/src/styles-areas/auth.css +3 -4
- package/src/styles-areas/canvas-hud.css +3 -3
- package/src/styles-areas/chat.css +10 -11
- package/src/styles-areas/code-editor.css +2 -2
- package/src/styles-areas/core.css +60 -54
- package/src/styles-areas/data-table.css +13 -17
- package/src/styles-areas/disk-usage.css +6 -7
- package/src/styles-areas/emoji.css +2 -3
- package/src/styles-areas/fields.css +15 -20
- package/src/styles-areas/master-detail.css +3 -4
- package/src/styles-areas/master-lock.css +1 -2
- package/src/styles-areas/media-gallery.css +8 -10
- package/src/styles-areas/rich-text.css +3 -3
- package/src/styles-areas/stats.css +13 -17
- package/src/styles-areas/wizard.css +6 -11
|
@@ -33,6 +33,11 @@ import { PRESS } from '../lib/press.js';
|
|
|
33
33
|
export const buttonVariants = cva(
|
|
34
34
|
[
|
|
35
35
|
'relative inline-flex items-center justify-center gap-2 rounded-md font-medium',
|
|
36
|
+
// 🔴 ONE LINE, always (2026-10-23): the height is a fixed control token, so a label allowed to
|
|
37
|
+
// wrap draws two lines in a one-line box — station's Deploys column squeezed "Deploy now" onto
|
|
38
|
+
// two, its text touching the top and bottom edges. A tight container gets a wider button, or
|
|
39
|
+
// a shorter label; never a wrapped one.
|
|
40
|
+
'whitespace-nowrap',
|
|
36
41
|
// 🔴 TACTILE (forge task family-app-ux-overhaul, 2026-10-06): a press is answered — eased
|
|
37
42
|
// colors and a `--press-scale` dip while held. The contract and who is exempt: `lib/press.ts`.
|
|
38
43
|
PRESS,
|
|
@@ -133,7 +138,8 @@ export const buttonVariants = cva(
|
|
|
133
138
|
// button — sized or on the `md` default — drew a padded box: TotpEntry's "Use a recovery code
|
|
134
139
|
// instead" sat 12px in from the column every other row starts on.
|
|
135
140
|
compoundVariants: [
|
|
136
|
-
|
|
141
|
+
// …and it wraps with that text: one line is the fixed-height CONTROL's rule, and a link has no height.
|
|
142
|
+
{ variant: 'link', size: ['sm', 'md', 'lg'], class: 'h-auto px-0 py-0 whitespace-normal' },
|
|
137
143
|
// A link is text inside a sentence: it underlines on hover and does not dip on press.
|
|
138
144
|
{ variant: 'link', class: 'active:scale-100' },
|
|
139
145
|
],
|
|
@@ -2,6 +2,7 @@ import { Upload, X } from 'lucide-react';
|
|
|
2
2
|
import { type DragEvent, type ReactNode, useId, useRef, useState } from 'react';
|
|
3
3
|
import { cn } from '../lib/cn.js';
|
|
4
4
|
import { Button } from './Button.js';
|
|
5
|
+
import { isHiddenName, matchesAccept, walkDrop } from './dropTransfer.js';
|
|
5
6
|
import { Input } from './Input.js';
|
|
6
7
|
|
|
7
8
|
export interface FileDropZoneProps {
|
|
@@ -51,102 +52,30 @@ export interface FileDropZoneProps {
|
|
|
51
52
|
className?: string;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
/** The slice of the File and Directory Entries API a drop needs — every browser ships it. */
|
|
55
|
-
interface DropEntry {
|
|
56
|
-
isFile: boolean;
|
|
57
|
-
isDirectory: boolean;
|
|
58
|
-
name: string;
|
|
59
|
-
file?: (ok: (file: File) => void, fail: (error: unknown) => void) => void;
|
|
60
|
-
createReader?: () => {
|
|
61
|
-
readEntries: (ok: (entries: DropEntry[]) => void, fail: (error: unknown) => void) => void;
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** What a folder can hold before walking it stops — a drop, not a disk scan. */
|
|
66
|
-
const MAX_FOLDER_FILES = 5000;
|
|
67
|
-
|
|
68
|
-
const isHidden = (name: string) => name.startsWith('.');
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Every file under `entry`, depth-first. A directory's reader answers in batches until empty.
|
|
72
|
-
*
|
|
73
|
-
* Each file carries its path from the dropped folder in `webkitRelativePath` (`Album/CD1/01.mp3`),
|
|
74
|
-
* exactly as a folder PICKER's files do natively — so an app reading provenance (music defaults
|
|
75
|
-
* its "where these came from" field to the top folder) gets the same answer from both gestures.
|
|
76
|
-
* A drop leaves it `''` otherwise, and that difference is what kept music on its own walk.
|
|
77
|
-
*/
|
|
78
|
-
async function filesUnder(entry: DropEntry, out: File[], prefix = ''): Promise<void> {
|
|
79
|
-
if (out.length >= MAX_FOLDER_FILES || isHidden(entry.name)) return;
|
|
80
|
-
if (entry.isFile && entry.file) {
|
|
81
|
-
const read = entry.file.bind(entry);
|
|
82
|
-
const file = await new Promise<File>((ok, fail) => read(ok, fail));
|
|
83
|
-
Object.defineProperty(file, 'webkitRelativePath', { value: `${prefix}${file.name}`, configurable: true });
|
|
84
|
-
out.push(file);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (!entry.isDirectory || !entry.createReader) return;
|
|
88
|
-
const reader = entry.createReader();
|
|
89
|
-
while (out.length < MAX_FOLDER_FILES) {
|
|
90
|
-
const batch = await new Promise<DropEntry[]>((ok, fail) => reader.readEntries(ok, fail));
|
|
91
|
-
if (batch.length === 0) return;
|
|
92
|
-
for (const child of batch) await filesUnder(child, out, `${prefix}${entry.name}/`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
55
|
/**
|
|
97
56
|
* A drop's files, with every dropped FOLDER replaced by the accepted files inside it — see the
|
|
98
57
|
* FOLDER section above. `null` when nothing in the drop is a folder, so the ordinary path stays
|
|
99
|
-
* exactly `dataTransfer.files`.
|
|
100
|
-
*
|
|
101
|
-
* 🔴 The entries are taken SYNCHRONOUSLY, before the first `await`: a browser empties the
|
|
102
|
-
* `DataTransfer` once the drop event returns.
|
|
58
|
+
* exactly `dataTransfer.files`. The walk itself is {@link walkDrop}, shared with every app's own
|
|
59
|
+
* drop target through {@link filesFromDataTransfer}.
|
|
103
60
|
*/
|
|
104
61
|
function folderAwareDrop(
|
|
105
62
|
transfer: DataTransfer,
|
|
106
63
|
accept: string | undefined,
|
|
107
64
|
): Promise<{ loose: File[]; fromFolders: File[]; emptyFolders: File[] }> | null {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
? (item.webkitGetAsEntry() as DropEntry | null)
|
|
112
|
-
: null,
|
|
113
|
-
);
|
|
114
|
-
if (!entries.some((entry) => entry?.isDirectory)) return null;
|
|
115
|
-
const looseFiles = [...transfer.files];
|
|
116
|
-
return (async () => {
|
|
117
|
-
const loose: File[] = [];
|
|
65
|
+
const walking = walkDrop(transfer);
|
|
66
|
+
if (!walking) return null;
|
|
67
|
+
return walking.then(({ loose, folders }) => {
|
|
118
68
|
const fromFolders: File[] = [];
|
|
119
69
|
const emptyFolders: File[] = [];
|
|
120
|
-
for (const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (file) loose.push(file);
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
const inside: File[] = [];
|
|
127
|
-
try {
|
|
128
|
-
await filesUnder(entry, inside);
|
|
129
|
-
} catch {
|
|
130
|
-
// An unreadable folder yields what was read before the error — and, if that is nothing, a refusal below.
|
|
131
|
-
}
|
|
132
|
-
const kept = inside.filter((f) => matchesAccept(f, accept));
|
|
70
|
+
for (const folder of folders) {
|
|
71
|
+
// A folder that yields nothing acceptable is a refusal under its own name, never silence.
|
|
72
|
+
const kept = folder.files.filter((f) => matchesAccept(f, accept));
|
|
133
73
|
if (kept.length > 0) fromFolders.push(...kept);
|
|
134
|
-
else emptyFolders.push(new File([],
|
|
74
|
+
else emptyFolders.push(new File([], folder.name));
|
|
135
75
|
}
|
|
136
76
|
return { loose, fromFolders, emptyFolders };
|
|
137
|
-
})();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const matchesAccept = (file: File, accept?: string): boolean => {
|
|
141
|
-
if (!accept) return true;
|
|
142
|
-
return accept.split(',').some((raw) => {
|
|
143
|
-
const rule = raw.trim().toLowerCase();
|
|
144
|
-
if (!rule) return false;
|
|
145
|
-
if (rule.startsWith('.')) return file.name.toLowerCase().endsWith(rule);
|
|
146
|
-
if (rule.endsWith('/*')) return file.type.toLowerCase().startsWith(rule.slice(0, -1));
|
|
147
|
-
return file.type.toLowerCase() === rule;
|
|
148
77
|
});
|
|
149
|
-
}
|
|
78
|
+
}
|
|
150
79
|
|
|
151
80
|
/**
|
|
152
81
|
* A folder PICKER's files, judged the way a dropped folder's are: what `accept` turns away is
|
|
@@ -156,7 +85,7 @@ const matchesAccept = (file: File, accept?: string): boolean => {
|
|
|
156
85
|
*/
|
|
157
86
|
function folderPick(list: FileList | null, accept: string | undefined): { fromFolders: File[]; emptyFolders: File[] } {
|
|
158
87
|
const all = list ? [...list] : [];
|
|
159
|
-
const kept = all.filter((f) => !f.webkitRelativePath.split('/').some(
|
|
88
|
+
const kept = all.filter((f) => !f.webkitRelativePath.split('/').some(isHiddenName) && matchesAccept(f, accept));
|
|
160
89
|
if (kept.length > 0 || all.length === 0) return { fromFolders: kept, emptyFolders: [] };
|
|
161
90
|
const name = all[0]?.webkitRelativePath.split('/')[0] || 'That folder';
|
|
162
91
|
return { fromFolders: [], emptyFolders: [new File([], name)] };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
-
import {
|
|
1
|
+
import { afterEach, beforeAll, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { act, cleanup, fireEvent, render, waitFor } from '@testing-library/react';
|
|
3
5
|
import { useState } from 'react';
|
|
4
|
-
import { TagsInput } from './TagsInput.js';
|
|
6
|
+
import { preloadSuggestingTagsInput, TagsInput } from './TagsInput.js';
|
|
5
7
|
|
|
6
8
|
afterEach(cleanup);
|
|
7
9
|
|
|
@@ -80,17 +82,76 @@ describe('TagsInput', () => {
|
|
|
80
82
|
});
|
|
81
83
|
});
|
|
82
84
|
|
|
85
|
+
/**
|
|
86
|
+
* 🔴 Never a `<datalist>` (forge task 3602). The owner, 2026-10-23: *"the dropdown does not look
|
|
87
|
+
* styled … I was in dark mode and it popped up light"* — the browser draws a datalist outside the
|
|
88
|
+
* page. The list is the kit's own (Base UI Autocomplete, portaled), carrying the popover tokens.
|
|
89
|
+
*/
|
|
90
|
+
/**
|
|
91
|
+
* A BYTE contract as much as a behavioral one (forge task 3614): the suggesting field is Base UI's
|
|
92
|
+
* Autocomplete, ~38 kB gzip, and 5.92.0 rooted every TagsInput in it — station's FolderSizesView,
|
|
93
|
+
* whose rules fields suggest nothing, went 7.15 → 44.32 kB gzip. A field without `suggestions`
|
|
94
|
+
* must not carry that engine; one with them fetches it, and loses nothing typed meanwhile.
|
|
95
|
+
*
|
|
96
|
+
* 🔴 These run BEFORE the `suggestions` block preloads the engine, so the first render here is
|
|
97
|
+
* the plain field the hand-over starts from.
|
|
98
|
+
*/
|
|
99
|
+
describe('the suggesting field is loaded only when asked for', () => {
|
|
100
|
+
test('TagsInput.tsx imports no Base UI, and reaches the suggesting field dynamically', () => {
|
|
101
|
+
const src = readFileSync(join(import.meta.dir, 'TagsInput.tsx'), 'utf8');
|
|
102
|
+
expect(src).not.toMatch(/from\s*['"]@base-ui\//);
|
|
103
|
+
expect(src).not.toMatch(/from\s*['"]\.\/(TagsInputSuggesting|suggestionList)(\.js)?['"]/);
|
|
104
|
+
expect(src).toContain("import('./TagsInputSuggesting.js')");
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('a draft typed and the focus held before the engine arrives are still there after', async () => {
|
|
108
|
+
const { container } = render(
|
|
109
|
+
<TagsInput value={[]} onChange={() => undefined} suggestions={['banking', 'tax']} />,
|
|
110
|
+
);
|
|
111
|
+
const plain = container.querySelector('input') as HTMLInputElement;
|
|
112
|
+
expect(plain.getAttribute('role'), 'the engine was already loaded — this test must run first').toBeNull();
|
|
113
|
+
act(() => plain.focus());
|
|
114
|
+
fireEvent.change(plain, { target: { value: 'ba' } });
|
|
115
|
+
// Where the focus is in the commit that swaps the inputs, not some polls later: a mutation
|
|
116
|
+
// record is a microtask after that commit, before any passive effect (a later task), so a
|
|
117
|
+
// hand-over in `useEffect` reads <body> here every time, not only under a loaded gate.
|
|
118
|
+
let focusAtSwap: Element | null | undefined;
|
|
119
|
+
const swap = new MutationObserver(() => {
|
|
120
|
+
if (focusAtSwap === undefined && container.querySelector('input[role="combobox"]')) {
|
|
121
|
+
focusAtSwap = document.activeElement;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
swap.observe(container, { childList: true, subtree: true, attributes: true });
|
|
125
|
+
await waitFor(() => expect(container.querySelector('input')?.getAttribute('role')).toBe('combobox'));
|
|
126
|
+
swap.disconnect();
|
|
127
|
+
const suggesting = container.querySelector('input') as HTMLInputElement;
|
|
128
|
+
expect(suggesting.value).toBe('ba');
|
|
129
|
+
expect(focusAtSwap).toBe(suggesting);
|
|
130
|
+
expect(document.activeElement).toBe(suggesting);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
83
134
|
describe('suggestions', () => {
|
|
84
|
-
|
|
135
|
+
// Every case below draws the list, so the engine is in hand before the first render.
|
|
136
|
+
beforeAll(() => preloadSuggestingTagsInput());
|
|
137
|
+
|
|
138
|
+
const openList = (input: HTMLInputElement) =>
|
|
139
|
+
act(() => {
|
|
140
|
+
fireEvent.keyDown(input, { key: 'ArrowDown' });
|
|
141
|
+
});
|
|
142
|
+
const offeredNow = () => [...document.querySelectorAll('[role="option"]')].map((o) => o.textContent);
|
|
143
|
+
|
|
144
|
+
test('drawn in the page with the kit tokens, never a datalist — minus what is already committed', () => {
|
|
85
145
|
const { container } = render(
|
|
86
146
|
<TagsInput value={['work']} onChange={() => undefined} suggestions={['work', 'bank']} />,
|
|
87
147
|
);
|
|
88
148
|
const input = container.querySelector('input') as HTMLInputElement;
|
|
89
|
-
|
|
90
|
-
expect(list).
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
149
|
+
expect(document.querySelector('datalist')).toBeNull();
|
|
150
|
+
expect(input.getAttribute('list')).toBeNull();
|
|
151
|
+
openList(input);
|
|
152
|
+
expect(offeredNow()).toEqual(['bank']);
|
|
153
|
+
const popup = document.querySelector('[role="option"]')?.closest('.bg-popover');
|
|
154
|
+
expect(popup, 'the list does not carry the popover tokens').not.toBeNull();
|
|
94
155
|
});
|
|
95
156
|
|
|
96
157
|
test('🔴 suppression is case-insensitive — "Bank" committed hides the suggestion "bank"', () => {
|
|
@@ -100,16 +161,70 @@ describe('suggestions', () => {
|
|
|
100
161
|
const { container } = render(
|
|
101
162
|
<TagsInput value={['Bank']} onChange={() => undefined} suggestions={['bank', 'tax']} />,
|
|
102
163
|
);
|
|
103
|
-
|
|
104
|
-
|
|
164
|
+
openList(container.querySelector('input') as HTMLInputElement);
|
|
165
|
+
expect(offeredNow()).toEqual(['tax']);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('narrows to what is typed, in any case', () => {
|
|
169
|
+
const { container } = render(
|
|
170
|
+
<TagsInput value={[]} onChange={() => undefined} suggestions={['Banking', 'tax', 'bank']} />,
|
|
105
171
|
);
|
|
106
|
-
|
|
172
|
+
const input = container.querySelector('input') as HTMLInputElement;
|
|
173
|
+
fireEvent.change(input, { target: { value: 'BAN' } });
|
|
174
|
+
openList(input);
|
|
175
|
+
expect(offeredNow()).toEqual(['Banking', 'bank']);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('picking a suggestion commits it as a tag — not the half-typed draft', () => {
|
|
179
|
+
function WithSuggestions() {
|
|
180
|
+
const [value, setValue] = useState<string[]>([]);
|
|
181
|
+
return (
|
|
182
|
+
<div>
|
|
183
|
+
<TagsInput value={value} onChange={setValue} suggestions={['banking', 'tax']} />
|
|
184
|
+
<output data-json>{JSON.stringify(value)}</output>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
const { container } = render(<WithSuggestions />);
|
|
189
|
+
const input = container.querySelector('input') as HTMLInputElement;
|
|
190
|
+
fireEvent.change(input, { target: { value: 'ba' } });
|
|
191
|
+
openList(input);
|
|
192
|
+
act(() => {
|
|
193
|
+
fireEvent.click(document.querySelector('[role="option"]') as HTMLElement);
|
|
194
|
+
});
|
|
195
|
+
expect(json(container)).toEqual(['banking']);
|
|
196
|
+
expect(input.value).toBe('');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('Enter on a highlighted suggestion commits the suggestion', () => {
|
|
200
|
+
function WithSuggestions() {
|
|
201
|
+
const [value, setValue] = useState<string[]>([]);
|
|
202
|
+
return (
|
|
203
|
+
<div>
|
|
204
|
+
<TagsInput value={value} onChange={setValue} suggestions={['banking', 'tax']} />
|
|
205
|
+
<output data-json>{JSON.stringify(value)}</output>
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const { container } = render(<WithSuggestions />);
|
|
210
|
+
const input = container.querySelector('input') as HTMLInputElement;
|
|
211
|
+
fireEvent.change(input, { target: { value: 'ba' } });
|
|
212
|
+
openList(input);
|
|
213
|
+
act(() => {
|
|
214
|
+
fireEvent.keyDown(input, { key: 'ArrowDown' });
|
|
215
|
+
});
|
|
216
|
+
act(() => {
|
|
217
|
+
fireEvent.keyDown(input, { key: 'Enter' });
|
|
218
|
+
});
|
|
219
|
+
expect(json(container)).toEqual(['banking']);
|
|
107
220
|
});
|
|
108
221
|
|
|
109
|
-
test('no suggestions → no
|
|
222
|
+
test('no suggestions → no list and no dangling list attribute', () => {
|
|
110
223
|
const { container } = render(<TagsInput value={[]} onChange={() => undefined} />);
|
|
111
|
-
expect(
|
|
224
|
+
expect(document.querySelector('datalist')).toBeNull();
|
|
112
225
|
const input = container.querySelector('input') as HTMLInputElement;
|
|
113
226
|
expect(input.getAttribute('list')).toBeNull();
|
|
227
|
+
openList(input);
|
|
228
|
+
expect(offeredNow()).toEqual([]);
|
|
114
229
|
});
|
|
115
230
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { X } from 'lucide-react';
|
|
2
|
-
import { type KeyboardEvent,
|
|
2
|
+
import { type ComponentType, type KeyboardEvent, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { cn } from '../lib/cn.js';
|
|
4
4
|
import { CONTROL_MIN_HEIGHT_CLASS, type ControlSize } from '../lib/field.js';
|
|
5
5
|
import { IconButton } from './IconButton.js';
|
|
@@ -16,9 +16,14 @@ export interface TagsInputProps {
|
|
|
16
16
|
maxTags?: number;
|
|
17
17
|
/**
|
|
18
18
|
* Tags to offer as you type — the vocabulary already in use, so a re-tag matches
|
|
19
|
-
* the first spelling instead of minting "Bank"/"bank"/"banking" three ways.
|
|
20
|
-
*
|
|
21
|
-
* tags already committed on this value are not re-offered. Omit for none
|
|
19
|
+
* the first spelling instead of minting "Bank"/"bank"/"banking" three ways. Drawn
|
|
20
|
+
* in the page by the kit's own list (Base UI Autocomplete), narrowed to what is
|
|
21
|
+
* typed; tags already committed on this value are not re-offered. Omit for none —
|
|
22
|
+
* and a field that omits it never loads that list's engine (see {@link TagsInput}).
|
|
23
|
+
*
|
|
24
|
+
* 🔴 Never a `<datalist>`: the browser draws its list outside the page, where no
|
|
25
|
+
* stylesheet reaches it — it popped up light in dark mode (owner, 2026-10-23,
|
|
26
|
+
* forge task 3602).
|
|
22
27
|
*/
|
|
23
28
|
suggestions?: readonly string[];
|
|
24
29
|
id?: string;
|
|
@@ -45,14 +50,142 @@ function mergeTags(current: string[], additions: string[]): string[] {
|
|
|
45
50
|
return next;
|
|
46
51
|
}
|
|
47
52
|
|
|
53
|
+
/** What the suggesting field takes beyond the public props: the draft lives in {@link TagsInput},
|
|
54
|
+
* so a word typed before the list's engine arrived is still there after it does. */
|
|
55
|
+
export interface TagsFieldProps extends TagsInputProps {
|
|
56
|
+
draft: string;
|
|
57
|
+
setDraft: (draft: string) => void;
|
|
58
|
+
/** Focus the input on mount — the plain field had it when the engine arrived. */
|
|
59
|
+
initialFocus?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The editing both fields share: commit, remove, the comma/Enter/Backspace keys, a pasted list. */
|
|
63
|
+
export function useTagEditing({ value, onChange, draft, setDraft }: Pick<TagsFieldProps, 'value' | 'onChange' | 'draft' | 'setDraft'>) {
|
|
64
|
+
const commit = (raw: string) => {
|
|
65
|
+
const next = mergeTags(value, [raw]);
|
|
66
|
+
if (next.length !== value.length) onChange(next);
|
|
67
|
+
setDraft('');
|
|
68
|
+
};
|
|
69
|
+
const removeAt = (index: number) => onChange(value.filter((_, i) => i !== index));
|
|
70
|
+
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
71
|
+
if (e.key === 'Enter' || e.key === ',') {
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
if (draft.trim()) commit(draft);
|
|
74
|
+
} else if (e.key === 'Backspace' && draft === '' && value.length > 0) {
|
|
75
|
+
removeAt(value.length - 1);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
/** A typed or pasted value: every comma commits what is before it, the rest stays the draft. */
|
|
79
|
+
const type = (v: string) => {
|
|
80
|
+
if (!v.includes(',')) return setDraft(v);
|
|
81
|
+
const parts = v.split(',');
|
|
82
|
+
const last = parts.pop() ?? '';
|
|
83
|
+
const merged = mergeTags(value, parts);
|
|
84
|
+
if (merged.length !== value.length) onChange(merged);
|
|
85
|
+
setDraft(last);
|
|
86
|
+
};
|
|
87
|
+
return { commit, removeAt, onKeyDown, type };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The chip row's frame — an Input-shaped container reading the field tokens. */
|
|
91
|
+
export function tagsRowClass(size: ControlSize, disabled: boolean | undefined, className: string | undefined) {
|
|
92
|
+
return cn(
|
|
93
|
+
// `py-1`, not `py-1.5`: the empty row is a 20px line + 8px + 2px border, under the min-height, so it
|
|
94
|
+
// sits at exactly the control height beside an Input; `py-1.5` made it 38px next to a 36px one (FND-4).
|
|
95
|
+
// guardrails-ignore control-height-tokens: min-height chip-wrapping row (not fixed) — py- clears wrapped lines
|
|
96
|
+
'flex w-full flex-wrap items-center gap-1.5 rounded-field border border-field-border bg-field-bg px-2 py-1 transition focus-within:border-field-ring focus-within:ring-2 focus-within:ring-field-ring/30 aria-[invalid=true]:border-field-error',
|
|
97
|
+
CONTROL_MIN_HEIGHT_CLASS[size],
|
|
98
|
+
disabled && 'cursor-not-allowed opacity-50',
|
|
99
|
+
className,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const TAGS_INPUT_CLASS =
|
|
104
|
+
'min-w-24 flex-1 bg-transparent py-0.5 text-base text-field-fg outline-none placeholder:text-field-placeholder sm:pointer-fine:text-sm';
|
|
105
|
+
|
|
106
|
+
/** The committed tags as removable chips. */
|
|
107
|
+
// no-attribute-forward: a list of chips with no element of its own — the row it sits in takes the caller's attributes
|
|
108
|
+
export function TagChips({ value, disabled, onRemove }: { value: string[]; disabled?: boolean | undefined; onRemove: (index: number) => void }) {
|
|
109
|
+
return value.map((tag, i) => (
|
|
110
|
+
<span key={tag} className='inline-flex items-center gap-1 rounded bg-muted py-0.5 pl-2 pr-1 text-sm text-foreground'>
|
|
111
|
+
{tag}
|
|
112
|
+
<IconButton
|
|
113
|
+
label={`Remove ${tag}`}
|
|
114
|
+
disabled={disabled}
|
|
115
|
+
onClick={() => onRemove(i)}
|
|
116
|
+
className='h-auto min-h-0 w-auto size-4 rounded-sm p-0 text-muted-foreground hover:bg-border hover:text-foreground [&_svg]:size-3'
|
|
117
|
+
>
|
|
118
|
+
<X aria-hidden />
|
|
119
|
+
</IconButton>
|
|
120
|
+
</span>
|
|
121
|
+
));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type SuggestingField = ComponentType<TagsFieldProps>;
|
|
125
|
+
|
|
126
|
+
let loadedSuggesting: SuggestingField | null = null;
|
|
127
|
+
let pendingSuggesting: Promise<SuggestingField> | null = null;
|
|
128
|
+
|
|
129
|
+
/** Fetch the suggesting field (Base UI Autocomplete) once per page. */
|
|
130
|
+
export function preloadSuggestingTagsInput(): Promise<SuggestingField> {
|
|
131
|
+
if (!pendingSuggesting) {
|
|
132
|
+
pendingSuggesting = import('./TagsInputSuggesting.js').then((m) => {
|
|
133
|
+
loadedSuggesting = m.default;
|
|
134
|
+
return m.default;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return pendingSuggesting;
|
|
138
|
+
}
|
|
139
|
+
|
|
48
140
|
/**
|
|
49
141
|
* Comma / Enter-delimited tag input: pill chips inside an Input-shaped container that
|
|
50
142
|
* reads the same field-style tokens (border / ring / invalid). Controlled —
|
|
51
143
|
* `value: string[]`, `onChange(next)`. Type + Enter or comma to add (paste
|
|
52
144
|
* "a,b,c" splits into three); the ✕ on a chip or Backspace on an empty input removes
|
|
53
145
|
* one. Replaces the ad-hoc CommaTagsInput. The registry's `tags` control.
|
|
146
|
+
*
|
|
147
|
+
* ── Why the suggesting field is a dynamic `import()` ─────────────────────────
|
|
148
|
+
* 🔴 Suggestions are drawn by Base UI's Autocomplete, ~38 kB gzip. 5.92.0 rooted EVERY TagsInput
|
|
149
|
+
* in it, so a field that suggests nothing — station's disk-usage rules, every form's `tags`
|
|
150
|
+
* control — carried it: station's FolderSizesView chunk went 7.15 → 44.32 kB gzip (forge task
|
|
151
|
+
* 3614). A field given `suggestions` fetches it on mount (the same move as `InfoHint`); until it
|
|
152
|
+
* arrives — and for good, without `suggestions` — this file's plain input is the field, holding
|
|
153
|
+
* the draft and the focus it hands over.
|
|
54
154
|
*/
|
|
55
|
-
export function TagsInput({
|
|
155
|
+
export function TagsInput(props: TagsInputProps) {
|
|
156
|
+
const wantsList = props.suggestions !== undefined;
|
|
157
|
+
// `() => loadedSuggesting`: a component IS a function, and `useState(fn)` would call it.
|
|
158
|
+
const [Suggesting, setSuggesting] = useState<SuggestingField | null>(() => (wantsList ? loadedSuggesting : null));
|
|
159
|
+
const [draft, setDraft] = useState('');
|
|
160
|
+
const focused = useRef(false);
|
|
161
|
+
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (!wantsList || Suggesting) return;
|
|
164
|
+
let alive = true;
|
|
165
|
+
void preloadSuggestingTagsInput().then((c) => {
|
|
166
|
+
if (alive) setSuggesting(() => c);
|
|
167
|
+
});
|
|
168
|
+
return () => {
|
|
169
|
+
alive = false;
|
|
170
|
+
};
|
|
171
|
+
}, [wantsList, Suggesting]);
|
|
172
|
+
|
|
173
|
+
if (wantsList && Suggesting) {
|
|
174
|
+
return <Suggesting {...props} draft={draft} setDraft={setDraft} initialFocus={focused.current} />;
|
|
175
|
+
}
|
|
176
|
+
return (
|
|
177
|
+
<PlainTagsField
|
|
178
|
+
{...props}
|
|
179
|
+
draft={draft}
|
|
180
|
+
setDraft={setDraft}
|
|
181
|
+
onFocusChange={(on) => {
|
|
182
|
+
focused.current = on;
|
|
183
|
+
}}
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function PlainTagsField({
|
|
56
189
|
value,
|
|
57
190
|
onChange,
|
|
58
191
|
onBlur,
|
|
@@ -61,112 +194,47 @@ export function TagsInput({
|
|
|
61
194
|
maxTags,
|
|
62
195
|
id,
|
|
63
196
|
name,
|
|
64
|
-
suggestions,
|
|
197
|
+
suggestions: _suggestions,
|
|
65
198
|
'aria-invalid': ariaInvalid,
|
|
66
199
|
'aria-label': ariaLabel,
|
|
67
200
|
'aria-describedby': ariaDescribedBy,
|
|
68
201
|
className,
|
|
69
202
|
size = 'md',
|
|
203
|
+
draft,
|
|
204
|
+
setDraft,
|
|
205
|
+
onFocusChange,
|
|
70
206
|
...rest
|
|
71
|
-
}:
|
|
72
|
-
const
|
|
73
|
-
const listId = useId();
|
|
207
|
+
}: TagsFieldProps & { onFocusChange: (focused: boolean) => void }) {
|
|
208
|
+
const { commit, removeAt, onKeyDown, type } = useTagEditing({ value, onChange, draft, setDraft });
|
|
74
209
|
const atMax = maxTags != null && value.length >= maxTags;
|
|
75
|
-
// Case-insensitive: a committed "Bank" must suppress the suggestion "bank" —
|
|
76
|
-
// offering it back commits nothing (mergeTags dedupes case-sensitively, so it
|
|
77
|
-
// WOULD land as a second chip) and reads as the field suggesting a duplicate.
|
|
78
|
-
const committed = new Set(value.map((tag) => tag.toLowerCase()));
|
|
79
|
-
const offered = (suggestions ?? []).filter((tag) => !committed.has(tag.toLowerCase()));
|
|
80
|
-
|
|
81
|
-
const commit = (raw: string) => {
|
|
82
|
-
const next = mergeTags(value, [raw]);
|
|
83
|
-
if (next.length !== value.length) onChange(next);
|
|
84
|
-
setDraft('');
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const removeAt = (index: number) => onChange(value.filter((_, i) => i !== index));
|
|
88
|
-
|
|
89
|
-
const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
|
|
90
|
-
if (e.key === 'Enter' || e.key === ',') {
|
|
91
|
-
e.preventDefault();
|
|
92
|
-
if (draft.trim()) commit(draft);
|
|
93
|
-
} else if (e.key === 'Backspace' && draft === '' && value.length > 0) {
|
|
94
|
-
removeAt(value.length - 1);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
210
|
return (
|
|
99
|
-
<div
|
|
100
|
-
{
|
|
101
|
-
aria-invalid={ariaInvalid}
|
|
102
|
-
className={cn(
|
|
103
|
-
// `py-1`, not `py-1.5`: the empty row is a 20px line + 8px + 2px border, under the min-height, so it
|
|
104
|
-
// sits at exactly the control height beside an Input; `py-1.5` made it 38px next to a 36px one (FND-4).
|
|
105
|
-
// guardrails-ignore control-height-tokens: min-height chip-wrapping row (not fixed) — py- clears wrapped lines
|
|
106
|
-
'flex w-full flex-wrap items-center gap-1.5 rounded-field border border-field-border bg-field-bg px-2 py-1 transition focus-within:border-field-ring focus-within:ring-2 focus-within:ring-field-ring/30 aria-[invalid=true]:border-field-error',
|
|
107
|
-
CONTROL_MIN_HEIGHT_CLASS[size],
|
|
108
|
-
disabled && 'cursor-not-allowed opacity-50',
|
|
109
|
-
className,
|
|
110
|
-
)}
|
|
111
|
-
>
|
|
112
|
-
{value.map((tag, i) => (
|
|
113
|
-
<span
|
|
114
|
-
key={tag}
|
|
115
|
-
className='inline-flex items-center gap-1 rounded bg-muted py-0.5 pl-2 pr-1 text-sm text-foreground'
|
|
116
|
-
>
|
|
117
|
-
{tag}
|
|
118
|
-
<IconButton
|
|
119
|
-
label={`Remove ${tag}`}
|
|
120
|
-
disabled={disabled}
|
|
121
|
-
onClick={() => removeAt(i)}
|
|
122
|
-
className='h-auto min-h-0 w-auto size-4 rounded-sm p-0 text-muted-foreground hover:bg-border hover:text-foreground [&_svg]:size-3'
|
|
123
|
-
>
|
|
124
|
-
<X aria-hidden />
|
|
125
|
-
</IconButton>
|
|
126
|
-
</span>
|
|
127
|
-
))}
|
|
211
|
+
<div {...rest} aria-invalid={ariaInvalid} className={tagsRowClass(size, disabled, className)}>
|
|
212
|
+
<TagChips value={value} disabled={disabled} onRemove={removeAt} />
|
|
128
213
|
{!atMax ? (
|
|
129
214
|
<input
|
|
215
|
+
// guardrails-ignore no-raw-inputs: perf — the chip row is the field's frame, so its draft
|
|
216
|
+
// input is borderless; the Field-layer Input draws a second frame, and Base UI's (38 kB)
|
|
217
|
+
// is what this path exists to skip (forge task 3614).
|
|
130
218
|
id={id}
|
|
131
219
|
name={name}
|
|
132
|
-
// guardrails-ignore no-raw-inputs: this IS the TagsInput Field-family
|
|
133
|
-
// primitive — wraps the raw draft-tag text input it exposes.
|
|
134
|
-
type='text'
|
|
135
220
|
value={draft}
|
|
221
|
+
onChange={(e) => type(e.target.value)}
|
|
136
222
|
disabled={disabled}
|
|
137
223
|
placeholder={value.length === 0 ? placeholder : undefined}
|
|
138
224
|
aria-invalid={ariaInvalid}
|
|
139
225
|
aria-label={ariaLabel}
|
|
140
226
|
aria-describedby={ariaDescribedBy}
|
|
141
227
|
autoComplete='off'
|
|
142
|
-
list={offered.length > 0 ? listId : undefined}
|
|
143
|
-
onChange={(e) => {
|
|
144
|
-
const v = e.target.value;
|
|
145
|
-
if (v.includes(',')) {
|
|
146
|
-
const parts = v.split(',');
|
|
147
|
-
const last = parts.pop() ?? '';
|
|
148
|
-
const merged = mergeTags(value, parts);
|
|
149
|
-
if (merged.length !== value.length) onChange(merged);
|
|
150
|
-
setDraft(last);
|
|
151
|
-
} else {
|
|
152
|
-
setDraft(v);
|
|
153
|
-
}
|
|
154
|
-
}}
|
|
155
228
|
onKeyDown={onKeyDown}
|
|
229
|
+
onFocus={() => onFocusChange(true)}
|
|
156
230
|
onBlur={() => {
|
|
231
|
+
onFocusChange(false);
|
|
157
232
|
if (draft.trim()) commit(draft);
|
|
158
233
|
onBlur?.();
|
|
159
234
|
}}
|
|
160
|
-
className=
|
|
235
|
+
className={TAGS_INPUT_CLASS}
|
|
161
236
|
/>
|
|
162
237
|
) : null}
|
|
163
|
-
{offered.length > 0 ? (
|
|
164
|
-
<datalist id={listId}>
|
|
165
|
-
{offered.map((tag) => (
|
|
166
|
-
<option key={tag} value={tag} />
|
|
167
|
-
))}
|
|
168
|
-
</datalist>
|
|
169
|
-
) : null}
|
|
170
238
|
</div>
|
|
171
239
|
);
|
|
172
240
|
}
|