cursedbelt 6.29.0 → 6.30.0
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/canvas-hud/HudControls.d.ts +2 -0
- package/dist/react/canvas-hud/HudControls.d.ts.map +1 -1
- package/dist/react/canvas-hud/HudControls.js +3 -1
- package/dist/react/canvas-hud/HudControls.js.map +1 -1
- package/dist/react/components/ColorSwatches.d.ts.map +1 -1
- package/dist/react/components/ColorSwatches.js +1 -1
- package/dist/react/components/ColorSwatches.js.map +1 -1
- package/dist/react/components/DataTable/serverWindowWatch.d.ts +5 -4
- package/dist/react/components/DataTable/serverWindowWatch.d.ts.map +1 -1
- package/dist/react/components/DataTable/serverWindowWatch.js +7 -9
- package/dist/react/components/DataTable/serverWindowWatch.js.map +1 -1
- package/dist/react/components/ScrollArea.d.ts +9 -1
- package/dist/react/components/ScrollArea.d.ts.map +1 -1
- package/dist/react/components/ScrollArea.js +9 -3
- package/dist/react/components/ScrollArea.js.map +1 -1
- package/dist/react/components/TagsEditor.d.ts +12 -2
- package/dist/react/components/TagsEditor.d.ts.map +1 -1
- package/dist/react/components/TagsEditor.js +23 -8
- package/dist/react/components/TagsEditor.js.map +1 -1
- package/dist/react/lib/keepAsking.d.ts +30 -0
- package/dist/react/lib/keepAsking.d.ts.map +1 -0
- package/dist/react/lib/keepAsking.js +57 -0
- package/dist/react/lib/keepAsking.js.map +1 -0
- package/dist/react/lib/tagList.d.ts +15 -0
- package/dist/react/lib/tagList.d.ts.map +1 -1
- package/dist/react/lib/tagList.js +29 -0
- package/dist/react/lib/tagList.js.map +1 -1
- package/dist/react/map-frame/MapFrame.d.ts +11 -1
- package/dist/react/map-frame/MapFrame.d.ts.map +1 -1
- package/dist/react/map-frame/MapFrame.js +25 -2
- package/dist/react/map-frame/MapFrame.js.map +1 -1
- package/dist/react/map-frame/geo.d.ts +27 -0
- package/dist/react/map-frame/geo.d.ts.map +1 -1
- package/dist/react/map-frame/geo.js +38 -0
- package/dist/react/map-frame/geo.js.map +1 -1
- package/dist/react/map-frame/index.d.ts +4 -4
- package/dist/react/map-frame/index.d.ts.map +1 -1
- package/dist/react/map-frame/index.js +2 -2
- package/dist/react/map-frame/index.js.map +1 -1
- package/dist/styles-areas/core.css +8 -4
- package/dist/styles-utilities.css +18 -0
- package/package.json +9 -3
- package/scripts/build.spec.ts +39 -0
- package/scripts/build.ts +131 -0
- package/src/buildIsStaged.spec.ts +57 -47
- package/src/react/canvas-hud/HudControls.spec.tsx +13 -1
- package/src/react/canvas-hud/HudControls.tsx +3 -1
- package/src/react/components/ColorSwatches.tsx +5 -1
- package/src/react/components/DataTable/serverWindowWatch.ts +8 -9
- package/src/react/components/ScrollArea.spec.tsx +25 -0
- package/src/react/components/ScrollArea.tsx +18 -1
- package/src/react/components/TagsEditor.spec.tsx +66 -0
- package/src/react/components/TagsEditor.tsx +31 -7
- package/src/react/lib/keepAsking.spec.ts +89 -0
- package/src/react/lib/keepAsking.ts +63 -0
- package/src/react/lib/tagList.spec.ts +23 -1
- package/src/react/lib/tagList.ts +33 -0
- package/src/react/map-frame/MapFrame.tsx +33 -0
- package/src/react/map-frame/MapFrame.wheel.spec.tsx +69 -0
- package/src/react/map-frame/geo.spec.ts +32 -0
- package/src/react/map-frame/geo.ts +54 -0
- package/src/react/map-frame/index.ts +5 -2
- package/src/styles-areas/core.css +8 -4
- package/src/styles-utilities.css +18 -0
- package/src/stylesAreas.spec.ts +2 -1
- package/src/stylesStaticMatches.spec.ts +2 -3
- package/src/stylesUtilitiesMatches.spec.ts +2 -3
- package/src/verifyGraph.spec.ts +22 -6
package/scripts/build.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `bun run build` — cursedbelt's `dist`, compiled into a staging directory (`dist.next`) and
|
|
3
|
+
* swapped in whole, so a consumer reading `dist` never sees half a build.
|
|
4
|
+
*
|
|
5
|
+
* ## Builds in one checkout take turns (forge task 5806)
|
|
6
|
+
*
|
|
7
|
+
* The staging names are fixed, and the suite job, the publish job and `tools/lib-preview.ts` all build
|
|
8
|
+
* in the same checkout. Two at once read `rm: dist.prev: Directory not empty` (2026-11-23 ~10:40Z):
|
|
9
|
+
* build B's first `rm` ran while build A was writing into `dist.next`. Per-build staging names would
|
|
10
|
+
* not cure it — two swaps still race on `dist` itself, and every build rewrites the generated
|
|
11
|
+
* stylesheets under `src/` — so a second build WAITS for the first: `.build.lock`, a directory
|
|
12
|
+
* (`mkdir` is atomic) holding its owner's pid. A lock whose owner is dead, or one older than
|
|
13
|
+
* {@link STALE_MS} with no owner written, is taken over.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
|
|
18
|
+
export interface BuildStep {
|
|
19
|
+
readonly cmd: readonly string[];
|
|
20
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const STAGE = 'dist.next';
|
|
24
|
+
|
|
25
|
+
/** The real build's steps, in order. Each writes into `dist.next` (or the generated sources). */
|
|
26
|
+
export const BUILD_STEPS: readonly BuildStep[] = [
|
|
27
|
+
{ cmd: ['bun', 'run', 'scripts/generateStaticStyles.ts'] },
|
|
28
|
+
{ cmd: ['bun', 'run', 'scripts/generateUtilityStyles.ts'] },
|
|
29
|
+
{ cmd: ['bun', 'run', 'scripts/generateAreaStyles.ts'] },
|
|
30
|
+
{ cmd: ['tsc', '--project', 'tsconfig.build.json', '--outDir', STAGE] },
|
|
31
|
+
{ cmd: ['tsc', '--project', 'tsconfig.scripts.build.json', '--outDir', `${STAGE}/scripts`] },
|
|
32
|
+
{ cmd: ['bun', 'run', 'scripts/copyDistAssets.ts'], env: { CURSEDBELT_DIST_DIR: STAGE } },
|
|
33
|
+
{ cmd: ['bun', 'run', 'scripts/checkDistExports.ts'], env: { CURSEDBELT_DIST_DIR: STAGE } },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
async function run(cwd: string, step: BuildStep): Promise<number> {
|
|
37
|
+
const child = Bun.spawn([...step.cmd], {
|
|
38
|
+
cwd,
|
|
39
|
+
env: { ...process.env, ...step.env },
|
|
40
|
+
stdio: ['inherit', 'inherit', 'inherit'],
|
|
41
|
+
});
|
|
42
|
+
return await child.exited;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const LOCK = '.build.lock';
|
|
46
|
+
/** A lock with no owner file this old is a build that died between `mkdir` and writing its pid. */
|
|
47
|
+
const STALE_MS = 10 * 60_000;
|
|
48
|
+
/** Longer than any build has taken; past it the wait fails loudly instead of hanging a job. */
|
|
49
|
+
const WAIT_MS = 20 * 60_000;
|
|
50
|
+
|
|
51
|
+
function ownerAlive(lock: string): boolean {
|
|
52
|
+
let pid: number;
|
|
53
|
+
try {
|
|
54
|
+
pid = Number(readFileSync(join(lock, 'owner'), 'utf8'));
|
|
55
|
+
} catch {
|
|
56
|
+
try {
|
|
57
|
+
return Date.now() - statSync(lock).mtimeMs < STALE_MS;
|
|
58
|
+
} catch {
|
|
59
|
+
return false; // released while we looked
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
process.kill(pid, 0);
|
|
64
|
+
return true;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return (error as NodeJS.ErrnoException).code === 'EPERM';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Takes `<cwd>/.build.lock`, waiting while a live build holds it. Resolves to its release. */
|
|
71
|
+
export async function takeBuildLock(cwd: string): Promise<() => void> {
|
|
72
|
+
const lock = join(cwd, LOCK);
|
|
73
|
+
const until = Date.now() + WAIT_MS;
|
|
74
|
+
let said = false;
|
|
75
|
+
for (;;) {
|
|
76
|
+
try {
|
|
77
|
+
mkdirSync(lock);
|
|
78
|
+
writeFileSync(join(lock, 'owner'), String(process.pid));
|
|
79
|
+
return () => rmSync(lock, { recursive: true, force: true });
|
|
80
|
+
} catch (error) {
|
|
81
|
+
if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;
|
|
82
|
+
}
|
|
83
|
+
if (!ownerAlive(lock)) {
|
|
84
|
+
// Renamed aside first: of two waiters that both found it dead, one rename wins.
|
|
85
|
+
const aside = `${lock}.stale.${process.pid}`;
|
|
86
|
+
try {
|
|
87
|
+
renameSync(lock, aside);
|
|
88
|
+
rmSync(aside, { recursive: true, force: true });
|
|
89
|
+
} catch {}
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (Date.now() > until) throw new Error(`build: ${lock} is still held after ${WAIT_MS / 60_000} min`);
|
|
93
|
+
if (!said) console.error(`⏳ build: another build holds ${lock} — waiting for it`);
|
|
94
|
+
said = true;
|
|
95
|
+
await Bun.sleep(200);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Runs `steps` into `<cwd>/dist.next`, then swaps it in for `<cwd>/dist` — under the build lock.
|
|
101
|
+
* Resolves to the exit code.
|
|
102
|
+
*/
|
|
103
|
+
export async function build(cwd: string, steps: readonly BuildStep[] = BUILD_STEPS): Promise<number> {
|
|
104
|
+
const release = await takeBuildLock(cwd);
|
|
105
|
+
try {
|
|
106
|
+
return await buildUnlocked(cwd, steps);
|
|
107
|
+
} finally {
|
|
108
|
+
release();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function buildUnlocked(cwd: string, steps: readonly BuildStep[]): Promise<number> {
|
|
113
|
+
const next = join(cwd, STAGE);
|
|
114
|
+
const prev = join(cwd, 'dist.prev');
|
|
115
|
+
const dist = join(cwd, 'dist');
|
|
116
|
+
rmSync(next, { recursive: true, force: true });
|
|
117
|
+
rmSync(prev, { recursive: true, force: true });
|
|
118
|
+
for (const step of steps) {
|
|
119
|
+
const code = await run(cwd, step);
|
|
120
|
+
if (code !== 0) {
|
|
121
|
+
console.error(`✗ build: \`${step.cmd.join(' ')}\` exited ${code}`);
|
|
122
|
+
return code;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (existsSync(dist)) renameSync(dist, prev);
|
|
126
|
+
renameSync(next, dist);
|
|
127
|
+
rmSync(prev, { recursive: true, force: true });
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (import.meta.main) process.exit(await build(process.cwd()));
|
|
@@ -19,67 +19,77 @@
|
|
|
19
19
|
* no dist is a `mv` rather than a compile, and a build that fails on somebody's WIP
|
|
20
20
|
* leaves the previous `dist` untouched — which is the property that was missing.
|
|
21
21
|
*
|
|
22
|
-
* ──
|
|
23
|
-
* The
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
22
|
+
* ── What is checked, and how ──────────────────────────────────────────────────
|
|
23
|
+
* The build is `scripts/build.ts` (forge task 5806), so the property is checked as
|
|
24
|
+
* BEHAVIOR: `build()` run over stand-in steps in a temp directory — a failing step
|
|
25
|
+
* must leave the previous `dist` whole, and a passing one must swap the staged tree
|
|
26
|
+
* in. The real step list, `BUILD_STEPS`, is read for what the stand-ins cannot show:
|
|
27
|
+
* every compiler and the asset copy aim at the staging directory.
|
|
28
28
|
*/
|
|
29
29
|
import { describe, expect, test } from 'bun:test'
|
|
30
|
-
import { readFileSync } from 'node:fs'
|
|
30
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
31
|
+
import { tmpdir } from 'node:os'
|
|
32
|
+
import { join } from 'node:path'
|
|
33
|
+
import { BUILD_STEPS, build, type BuildStep } from '../scripts/build.js'
|
|
31
34
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const STAGE = 'dist.next'
|
|
36
|
+
|
|
37
|
+
/** A temp checkout holding a previous `dist` with one file in it. */
|
|
38
|
+
function checkout(): string {
|
|
39
|
+
const cwd = mkdtempSync(join(tmpdir(), 'cb-staged-'))
|
|
40
|
+
mkdirSync(join(cwd, 'dist'))
|
|
41
|
+
writeFileSync(join(cwd, 'dist', 'old.js'), 'old')
|
|
42
|
+
return cwd
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const writes = (file: string): BuildStep => ({
|
|
46
|
+
cmd: ['sh', '-c', `mkdir -p ${STAGE} && echo new > ${STAGE}/${file}`],
|
|
47
|
+
})
|
|
35
48
|
|
|
36
49
|
describe('the build is staged, not destructive-then-verify', () => {
|
|
37
|
-
|
|
50
|
+
test('a step that fails leaves the previous dist whole — nothing removes it before the compilers have run', async () => {
|
|
51
|
+
const cwd = checkout()
|
|
52
|
+
try {
|
|
53
|
+
const code = await build(cwd, [writes('half.js'), { cmd: ['sh', '-c', 'exit 3'] }])
|
|
54
|
+
expect(code).toBe(3)
|
|
55
|
+
expect(readFileSync(join(cwd, 'dist', 'old.js'), 'utf8')).toBe('old') // reads-other-dist: the temp checkout's
|
|
56
|
+
expect(existsSync(join(cwd, 'dist', 'half.js'))).toBe(false) // reads-other-dist: the temp checkout's
|
|
57
|
+
} finally {
|
|
58
|
+
rmSync(cwd, { recursive: true, force: true })
|
|
59
|
+
}
|
|
60
|
+
})
|
|
38
61
|
|
|
39
|
-
test('
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"in the reader's own diff. Stage into dist.next and swap.",
|
|
52
|
-
).toBe(false)
|
|
53
|
-
expect(firstRm === -1 || firstRm > firstTsc || build.startsWith('rm -rf dist.next')).toBe(
|
|
54
|
-
true,
|
|
55
|
-
)
|
|
62
|
+
test('the swap happens, and only after every step', async () => {
|
|
63
|
+
const cwd = checkout()
|
|
64
|
+
try {
|
|
65
|
+
expect(await build(cwd, [writes('a.js'), writes('b.js')])).toBe(0)
|
|
66
|
+
expect(existsSync(join(cwd, 'dist', 'a.js'))).toBe(true) // reads-other-dist: the temp checkout's
|
|
67
|
+
expect(existsSync(join(cwd, 'dist', 'b.js'))).toBe(true) // reads-other-dist: the temp checkout's
|
|
68
|
+
expect(existsSync(join(cwd, 'dist', 'old.js'))).toBe(false) // reads-other-dist: the temp checkout's
|
|
69
|
+
expect(existsSync(join(cwd, STAGE))).toBe(false)
|
|
70
|
+
expect(existsSync(join(cwd, 'dist.prev'))).toBe(false) // reads-other-dist: the temp checkout's
|
|
71
|
+
} finally {
|
|
72
|
+
rmSync(cwd, { recursive: true, force: true })
|
|
73
|
+
}
|
|
56
74
|
})
|
|
57
75
|
|
|
58
76
|
test('the compilers emit into the staging directory', () => {
|
|
59
77
|
// Every tsc project carries `"outDir": "dist"` in its tsconfig; the CLI override is
|
|
60
|
-
// what redirects them. If one loses `--outDir dist.next
|
|
61
|
-
// live tree and the staging is half-inert.
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const overrides = build.match(/--outDir dist\.next/g) ?? []
|
|
70
|
-
expect(tscRuns.length, 'the build must run at least one tsc project').toBeGreaterThan(0)
|
|
71
|
-
expect(overrides.length, 'every tsc project must emit into dist.next').toBe(tscRuns.length)
|
|
78
|
+
// what redirects them. If one loses `--outDir dist.next…` it writes straight into
|
|
79
|
+
// the live tree and the staging is half-inert. Counted against the tsc steps, never
|
|
80
|
+
// hard-coded (the split of 2026-09-15 took one project to cursedbelt-server).
|
|
81
|
+
const tsc = BUILD_STEPS.filter((step) => step.cmd[0] === 'tsc')
|
|
82
|
+
expect(tsc.length, 'the build must run at least one tsc project').toBeGreaterThan(0)
|
|
83
|
+
for (const step of tsc) {
|
|
84
|
+
const outDir = step.cmd[step.cmd.indexOf('--outDir') + 1] ?? ''
|
|
85
|
+
expect(outDir === STAGE || outDir.startsWith(`${STAGE}/`), `${step.cmd.join(' ')} must emit into ${STAGE}`).toBe(true)
|
|
86
|
+
}
|
|
72
87
|
})
|
|
73
88
|
|
|
74
89
|
test('the assets are copied into the staging directory too', () => {
|
|
75
90
|
// `copyDistAssets` defaults to `dist`, so without this the css and the verify
|
|
76
91
|
// fixtures land in the OLD tree and the swap throws them away.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
test('the swap happens, and only after everything else', () => {
|
|
81
|
-
const swap = build.indexOf('mv dist.next dist')
|
|
82
|
-
expect(swap, 'the staged build is never promoted').toBeGreaterThan(-1)
|
|
83
|
-
expect(swap).toBeGreaterThan(build.indexOf('copyDistAssets'))
|
|
92
|
+
const copy = BUILD_STEPS.find((step) => step.cmd.join(' ').includes('copyDistAssets'))
|
|
93
|
+
expect(copy?.env?.CURSEDBELT_DIST_DIR).toBe(STAGE)
|
|
84
94
|
})
|
|
85
95
|
})
|
|
@@ -2,7 +2,7 @@ import { afterEach, describe, expect, mock, test } from 'bun:test';
|
|
|
2
2
|
import { cleanup, fireEvent, render } from '@testing-library/react';
|
|
3
3
|
import { CanvasMinimap } from './CanvasMinimap.js';
|
|
4
4
|
import { CanvasSearchField } from './CanvasSearchField.js';
|
|
5
|
-
import { HudButton, HudZoomControls } from './HudControls.js';
|
|
5
|
+
import { CanvasZoomHint, HudButton, HudZoomControls } from './HudControls.js';
|
|
6
6
|
import { readWheel } from './useCanvasWheel.js';
|
|
7
7
|
|
|
8
8
|
afterEach(cleanup);
|
|
@@ -169,3 +169,15 @@ describe('readWheel (CNV-1: one gesture, one meaning)', () => {
|
|
|
169
169
|
expect(readWheel('embedded', wheel())).toBe('page');
|
|
170
170
|
});
|
|
171
171
|
});
|
|
172
|
+
|
|
173
|
+
describe('CanvasZoomHint (CNV-1)', () => {
|
|
174
|
+
test('neither the overlay nor its pill takes a pointer, so a hidden hint never covers what is under it', () => {
|
|
175
|
+
const { getByTestId } = render(<CanvasZoomHint show={false} />);
|
|
176
|
+
const hint = getByTestId('canvas-zoom-hint');
|
|
177
|
+
expect(hint.getAttribute('aria-hidden')).toBe('true');
|
|
178
|
+
expect(hint.className).toContain('pointer-events-none');
|
|
179
|
+
const pill = hint.firstElementChild as HTMLElement;
|
|
180
|
+
expect(pill.className).toContain('pointer-events-none');
|
|
181
|
+
expect(pill.className).not.toContain('pointer-events-auto');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -136,6 +136,8 @@ export interface CanvasZoomHintProps {
|
|
|
136
136
|
/**
|
|
137
137
|
* CNV-1's "Hold ⌘ to zoom" — what an embedded canvas says when a plain wheel scrolled the page
|
|
138
138
|
* instead of zooming it, the way an embedded Google Map does. Says Ctrl off a Mac.
|
|
139
|
+
* 🔴 The pill is `pointer-events-none` too: HudPill defaults to `pointer-events-auto`, and a hidden pill left so sat
|
|
140
|
+
* over the canvas's middle, taking every click and wheel aimed there (photos' pin at the map's center).
|
|
139
141
|
*/
|
|
140
142
|
export function CanvasZoomHint({ show, className, ...rest }: CanvasZoomHintProps) {
|
|
141
143
|
const kt = useKeyText();
|
|
@@ -150,7 +152,7 @@ export function CanvasZoomHint({ show, className, ...rest }: CanvasZoomHintProps
|
|
|
150
152
|
className,
|
|
151
153
|
)}
|
|
152
154
|
>
|
|
153
|
-
<HudPill className='px-3 py-1.5 text-sm'>Hold {kt('$mod')} to zoom</HudPill>
|
|
155
|
+
<HudPill className='pointer-events-none px-3 py-1.5 text-sm'>Hold {kt('$mod')} to zoom</HudPill>
|
|
154
156
|
</div>
|
|
155
157
|
);
|
|
156
158
|
}
|
|
@@ -64,8 +64,12 @@ export function ColorSwatches({
|
|
|
64
64
|
if (well.current && wellHex && well.current.value !== wellHex) well.current.value = wellHex;
|
|
65
65
|
}, [wellHex]);
|
|
66
66
|
return (
|
|
67
|
-
|
|
67
|
+
// No wrap on the outer row (task 5729): when the presets do not fit, THEY wrap among
|
|
68
|
+
// themselves (`min-w-0` lets the picker shrink below its one-row width) and the well stays at
|
|
69
|
+
// the end of the first row — a wrapping outer row dropped the well alone onto a row of its own.
|
|
70
|
+
<div {...rest} data-slot='color-swatches' className={cn('flex items-start gap-1.5', className)}>
|
|
68
71
|
<SwatchPicker
|
|
72
|
+
className='min-w-0'
|
|
69
73
|
aria-label={ariaLabel}
|
|
70
74
|
size={size}
|
|
71
75
|
options={presets.map((color) => ({ value: color.toLowerCase(), color, label: color }))}
|
|
@@ -20,6 +20,8 @@
|
|
|
20
20
|
* request answers it), which is the contract `onReachEnd` always had.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
+
import { RETRY_CEILING_MS, RETRY_FIRST_MS, retryDelayMs } from '../../lib/keepAsking.js';
|
|
24
|
+
|
|
23
25
|
/** What is on screen, as absolute row numbers over the whole result set; `last` is EXCLUSIVE. */
|
|
24
26
|
export interface ShownRows {
|
|
25
27
|
first: number;
|
|
@@ -48,17 +50,14 @@ export function windowAsk(shown: ShownRows, loaded: LoadedWindow): WindowAsk {
|
|
|
48
50
|
return null;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
/** The
|
|
52
|
-
* still on its way is not asked for
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export const WINDOW_RETRY_CEILING_MS =
|
|
53
|
+
/** The pacing is `cursedbelt/react/keep-asking`'s, so a table's rows and a page's first load re-ask alike:
|
|
54
|
+
* 2 s (longer than a healthy window takes to arrive, so a request still on its way is not asked for
|
|
55
|
+
* twice), doubling to 30 s and holding there for as long as the placeholders stay up. */
|
|
56
|
+
export const WINDOW_RETRY_FIRST_MS = RETRY_FIRST_MS;
|
|
57
|
+
export const WINDOW_RETRY_CEILING_MS = RETRY_CEILING_MS;
|
|
56
58
|
|
|
57
59
|
/** The pause before the `attempt`-th re-ask (1-based): 2 s, 4 s, 8 s, 16 s, then 30 s for good. */
|
|
58
|
-
export
|
|
59
|
-
const n = Number.isFinite(attempt) ? Math.max(1, Math.floor(attempt)) : 1;
|
|
60
|
-
return Math.min(WINDOW_RETRY_CEILING_MS, WINDOW_RETRY_FIRST_MS * 2 ** (n - 1));
|
|
61
|
-
}
|
|
60
|
+
export const windowRetryDelayMs = retryDelayMs;
|
|
62
61
|
|
|
63
62
|
/** The first and one-past-last rows inside `[top, bottom)` — what `onChange` and the watch both read. */
|
|
64
63
|
export function shownRows(items: readonly { index: number; start: number; end: number }[], top: number, bottom: number): ShownRows | null {
|
|
@@ -124,6 +124,31 @@ describe('ScrollArea height — a bounded region by token (LAY-8, task 2461)', (
|
|
|
124
124
|
expect(el?.className).not.toContain('flex-1');
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
test.each(['sm', 'md', 'lg'] as const)('%s with fit makes the token a ceiling, so a short list shrinks (task 5676)', (h) => {
|
|
128
|
+
const { container } = render(
|
|
129
|
+
<ScrollArea height={h} fit>
|
|
130
|
+
x
|
|
131
|
+
</ScrollArea>,
|
|
132
|
+
);
|
|
133
|
+
const el = scrollDiv(container);
|
|
134
|
+
expect(el?.dataset.cbRegionHeight).toBe(h);
|
|
135
|
+
expect(el?.dataset.cbRegionFit).toBe('');
|
|
136
|
+
expect(el?.className).toContain(`max-h-[min(var(--region-h-${h}),var(--region-h-phone))]`);
|
|
137
|
+
expect(el?.className).toContain(`sm:max-h-[var(--region-h-${h})]`);
|
|
138
|
+
// No fixed height: the box takes the list's own height under the ceiling.
|
|
139
|
+
expect(el?.className.split(/\s+/).some((c) => /^(sm:)?h-\[/.test(c))).toBe(false);
|
|
140
|
+
expect(el?.className).toContain('flex-none');
|
|
141
|
+
expect(el?.className).not.toContain('flex-1');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('fit without a height changes nothing', () => {
|
|
145
|
+
const { container } = render(<ScrollArea fit>x</ScrollArea>);
|
|
146
|
+
const el = scrollDiv(container);
|
|
147
|
+
expect(el?.dataset.cbRegionFit).toBeUndefined();
|
|
148
|
+
expect(el?.className).toContain('flex-1');
|
|
149
|
+
expect(el?.className).not.toContain('max-h-');
|
|
150
|
+
});
|
|
151
|
+
|
|
127
152
|
test('unset, the area fills its flex parent as before', () => {
|
|
128
153
|
const { container } = render(<ScrollArea>x</ScrollArea>);
|
|
129
154
|
const el = scrollDiv(container);
|
|
@@ -75,6 +75,14 @@ export interface ScrollAreaProps extends Omit<HTMLAttributes<HTMLDivElement>, 's
|
|
|
75
75
|
* `--region-h-phone` (60dvh) on a phone. Unset, the area fills its flex parent.
|
|
76
76
|
*/
|
|
77
77
|
height?: ScrollAreaHeight;
|
|
78
|
+
/**
|
|
79
|
+
* With `height`, make the token a CEILING instead of a fixed box: a short list takes
|
|
80
|
+
* its own height and a long one stops at the token and scrolls (task 5676). Use it for
|
|
81
|
+
* a list that is often short (a merge plan's few rows); leave it off for a feed or log
|
|
82
|
+
* that fills over time, where a steady box keeps the page from jumping as rows arrive.
|
|
83
|
+
* No effect without `height`.
|
|
84
|
+
*/
|
|
85
|
+
fit?: boolean;
|
|
78
86
|
className?: string;
|
|
79
87
|
}
|
|
80
88
|
|
|
@@ -87,6 +95,13 @@ const REGION_HEIGHT: Record<ScrollAreaHeight, string> = {
|
|
|
87
95
|
lg: 'flex-none h-[min(var(--region-h-lg),var(--region-h-phone))] sm:h-[var(--region-h-lg)]',
|
|
88
96
|
};
|
|
89
97
|
|
|
98
|
+
// The same tokens as a ceiling (`fit`): the box shrinks to a short list.
|
|
99
|
+
const REGION_MAX_HEIGHT: Record<ScrollAreaHeight, string> = {
|
|
100
|
+
sm: 'flex-none max-h-[min(var(--region-h-sm),var(--region-h-phone))] sm:max-h-[var(--region-h-sm)]',
|
|
101
|
+
md: 'flex-none max-h-[min(var(--region-h-md),var(--region-h-phone))] sm:max-h-[var(--region-h-md)]',
|
|
102
|
+
lg: 'flex-none max-h-[min(var(--region-h-lg),var(--region-h-phone))] sm:max-h-[var(--region-h-lg)]',
|
|
103
|
+
};
|
|
104
|
+
|
|
90
105
|
/**
|
|
91
106
|
* THE single keyboard-/safe-area-aware scroll container — the ONLY way to make a
|
|
92
107
|
* scroll region in cursedbelt.
|
|
@@ -120,6 +135,7 @@ export function ScrollArea({
|
|
|
120
135
|
scrollRef,
|
|
121
136
|
fade = false,
|
|
122
137
|
height,
|
|
138
|
+
fit = false,
|
|
123
139
|
className,
|
|
124
140
|
...rest
|
|
125
141
|
}: ScrollAreaProps) {
|
|
@@ -149,6 +165,7 @@ export function ScrollArea({
|
|
|
149
165
|
}}
|
|
150
166
|
data-cb-scrollarea=''
|
|
151
167
|
data-cb-region-height={height}
|
|
168
|
+
data-cb-region-fit={height && fit ? '' : undefined}
|
|
152
169
|
data-cb-scroll-fade={fade ? (mask ? 'on' : 'idle') : undefined}
|
|
153
170
|
onFocusCapture={onFocusCapture}
|
|
154
171
|
style={style}
|
|
@@ -170,7 +187,7 @@ export function ScrollArea({
|
|
|
170
187
|
axis === 'x' && 'overflow-x-auto',
|
|
171
188
|
// guardrails-ignore no-raw-overflow: this IS the ScrollArea primitive.
|
|
172
189
|
axis === 'both' && 'overflow-auto',
|
|
173
|
-
height && REGION_HEIGHT[height],
|
|
190
|
+
height && (fit ? REGION_MAX_HEIGHT[height] : REGION_HEIGHT[height]),
|
|
174
191
|
className,
|
|
175
192
|
)}
|
|
176
193
|
>
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A TYPED tag goes through the app's spelling rule and its refusal, exactly as a pasted one does
|
|
3
|
+
* (forge task 5798): photos' owner got a chip "007" the server then answered with a bare "bad tag",
|
|
4
|
+
* because only a paste was normalized.
|
|
5
|
+
*/
|
|
6
|
+
import { afterEach, describe, expect, jest, spyOn, test } from 'bun:test';
|
|
7
|
+
import { cleanup, fireEvent, render } from '@testing-library/react';
|
|
8
|
+
import { toast } from '../Toast.js';
|
|
9
|
+
import { TagsEditor } from './TagsEditor.js';
|
|
10
|
+
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
cleanup();
|
|
13
|
+
jest.restoreAllMocks();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const lower = (raw: string) => raw.trim().toLowerCase();
|
|
17
|
+
const whyNot = (raw: string) => (raw.trim().length < 2 ? `“${raw.trim()}” is one character — a tag needs at least two` : null);
|
|
18
|
+
|
|
19
|
+
function mount(value: string[], props: Partial<Parameters<typeof TagsEditor>[0]> = {}) {
|
|
20
|
+
const onChange = jest.fn();
|
|
21
|
+
const error = spyOn(toast, 'error').mockImplementation(() => '' as never);
|
|
22
|
+
const view = render(<TagsEditor value={value} onChange={onChange} aria-label='Tags' {...props} />);
|
|
23
|
+
const input = view.getByLabelText('Tags') as HTMLInputElement;
|
|
24
|
+
const type = (text: string) => {
|
|
25
|
+
fireEvent.change(input, { target: { value: text } });
|
|
26
|
+
fireEvent.keyDown(input, { key: 'Enter' });
|
|
27
|
+
};
|
|
28
|
+
return { onChange, error, input, type };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('TagsEditor — a typed tag is checked, not only a paste', () => {
|
|
32
|
+
test('a typed tag is respelled by normalize before it becomes a chip', () => {
|
|
33
|
+
const { onChange, error, type } = mount(['Kept'], { normalize: lower, whyNot });
|
|
34
|
+
type('Boats');
|
|
35
|
+
expect(onChange).toHaveBeenCalledWith(['Kept', 'boats']);
|
|
36
|
+
expect(error).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('a typed tag whyNot refuses never becomes a chip, and the toast says why', () => {
|
|
40
|
+
const { onChange, error, type } = mount(['kept'], { normalize: lower, whyNot });
|
|
41
|
+
type('x');
|
|
42
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
43
|
+
expect(error).toHaveBeenCalledWith('“x” is one character — a tag needs at least two');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('a typed tag normalize answers "" for is refused with the default reason', () => {
|
|
47
|
+
const { onChange, error, type } = mount([], { normalize: (raw) => raw.replace(/[^a-z]/gi, '') });
|
|
48
|
+
type('007');
|
|
49
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
50
|
+
expect(error).toHaveBeenCalledWith('“007” can\'t be a tag');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('a paste is refused the same way, in one toast', () => {
|
|
54
|
+
const { onChange, error, input } = mount(['kept'], { normalize: lower, whyNot });
|
|
55
|
+
fireEvent.paste(input, { clipboardData: { getData: () => 'Sea, x, y' } });
|
|
56
|
+
expect(onChange).toHaveBeenCalledWith(['kept', 'sea']);
|
|
57
|
+
expect(error).toHaveBeenCalledTimes(1);
|
|
58
|
+
expect(error.mock.calls[0]![0]).toStartWith('2 tags left out — ');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('removing a chip still reaches onChange', () => {
|
|
62
|
+
const { onChange } = mount(['a', 'bb'], { normalize: lower, whyNot });
|
|
63
|
+
fireEvent.click(document.querySelector('button[aria-label^="Remove"]') as HTMLButtonElement);
|
|
64
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -14,7 +14,7 @@ import { Copy } from 'lucide-react';
|
|
|
14
14
|
import { type ClipboardEvent, type ComponentPropsWithoutRef, type KeyboardEvent, useEffect, useState } from 'react';
|
|
15
15
|
import { toast } from '../Toast.js';
|
|
16
16
|
import { cn } from '../lib/cn.js';
|
|
17
|
-
import { mergeTagLists, parseTagList, tagListText } from '../lib/tagList.js';
|
|
17
|
+
import { acceptTagList, mergeTagLists, parseTagList, tagListText } from '../lib/tagList.js';
|
|
18
18
|
import { useKeyText } from '../workspace-shell/keyChoice.js';
|
|
19
19
|
import { IconButton } from './IconButton.js';
|
|
20
20
|
import { TagsInput } from './TagsInput.js';
|
|
@@ -27,8 +27,18 @@ export interface TagsEditorProps
|
|
|
27
27
|
placeholder?: string;
|
|
28
28
|
'aria-label'?: string;
|
|
29
29
|
className?: string;
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* The app's one spelling rule for a tag (photos lower-cases and folds synonyms). Default: trim.
|
|
32
|
+
* Every tag a commit ADDS — typed with Enter or a comma, or pasted — is spelled by it before it
|
|
33
|
+
* becomes a chip, so the chip reads what the app keeps; one it turns into "" is refused.
|
|
34
|
+
*/
|
|
31
35
|
normalize?: (raw: string) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Why a tag cannot be one, or null when it can — said in an error toast when a typed or pasted
|
|
38
|
+
* tag is refused. Asked before `normalize`. Default: “<raw>” can't be a tag (when `normalize`
|
|
39
|
+
* answers "").
|
|
40
|
+
*/
|
|
41
|
+
whyNot?: (raw: string) => string | null;
|
|
32
42
|
/** What the tags are on, for the copy toast and tooltip: "paste them onto another {item}". Default `item`. */
|
|
33
43
|
item?: string;
|
|
34
44
|
}
|
|
@@ -55,6 +65,7 @@ export function TagsEditor({
|
|
|
55
65
|
'aria-label': ariaLabel = 'Tags',
|
|
56
66
|
className,
|
|
57
67
|
normalize,
|
|
68
|
+
whyNot,
|
|
58
69
|
item = 'item',
|
|
59
70
|
...rest
|
|
60
71
|
}: TagsEditorProps) {
|
|
@@ -95,14 +106,27 @@ export function TagsEditor({
|
|
|
95
106
|
event.preventDefault();
|
|
96
107
|
copied(picked.length);
|
|
97
108
|
};
|
|
109
|
+
/** One toast for whatever a commit refused: the reason, or the first reason and how many more. */
|
|
110
|
+
const refuse = (refused: readonly string[]): void => {
|
|
111
|
+
if (!refused.length) return;
|
|
112
|
+
toast.error(refused.length === 1 ? refused[0]! : `${refused.length} tags left out — ${refused[0]}, and more`);
|
|
113
|
+
};
|
|
114
|
+
// Every commit TagsInput makes (Enter, a comma, a removed chip) is checked here, so a typed tag is
|
|
115
|
+
// spelled and refused exactly as a pasted one is (forge task 5798).
|
|
116
|
+
const change = (next: string[]): void => {
|
|
117
|
+
const { tags, refused } = acceptTagList(value, next, normalize, whyNot);
|
|
118
|
+
refuse(refused);
|
|
119
|
+
if (tags.length !== value.length || tags.some((tag, i) => tag !== value[i])) onChange(tags);
|
|
120
|
+
};
|
|
98
121
|
const onPaste = (event: ClipboardEvent<HTMLDivElement>): void => {
|
|
99
122
|
if ((event.target as HTMLElement).tagName !== 'INPUT') return;
|
|
100
|
-
const pasted = parseTagList(event.clipboardData.getData('text/plain')
|
|
123
|
+
const pasted = parseTagList(event.clipboardData.getData('text/plain'));
|
|
101
124
|
if (!pasted.length) return;
|
|
102
125
|
event.preventDefault();
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
const { tags, refused } = acceptTagList(value, mergeTagLists(value, pasted), normalize, whyNot);
|
|
127
|
+
refuse(refused);
|
|
128
|
+
if (tags.length !== value.length) onChange(tags);
|
|
129
|
+
else if (!refused.length) toast.success(`Every pasted tag is on it already`);
|
|
106
130
|
};
|
|
107
131
|
|
|
108
132
|
return (
|
|
@@ -118,7 +142,7 @@ export function TagsEditor({
|
|
|
118
142
|
>
|
|
119
143
|
<div className='flex items-start gap-1'>
|
|
120
144
|
<div className={cn('min-w-0 flex-1 rounded-field', all && 'ring-2 ring-accent ring-offset-2 ring-offset-background')}>
|
|
121
|
-
<TagsInput value={value} onChange={
|
|
145
|
+
<TagsInput value={value} onChange={change} placeholder={placeholder} aria-label={ariaLabel} suggestions={suggestions} />
|
|
122
146
|
</div>
|
|
123
147
|
<IconButton
|
|
124
148
|
label='Copy all tags'
|