@tristan2828/ui-foundation 4.113.0 → 4.114.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/README.md +1 -1
- package/dist/mocks/index.d.ts +1 -0
- package/dist/mocks/index.js +1 -0
- package/dist/mocks/start-worker.d.ts +10 -0
- package/dist/mocks/start-worker.js +77 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ than installing this by hand:
|
|
|
21
21
|
| `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For the page standards (`docs/foundation/design-language.md` "Parts of the page standards"): `ValueList`, `ListHeader`, `Timeline`, `NeedsYou`, `Freshness`, `PartEmpty`. For a module's overview ("An overview page" there): `OverviewPage`, and `WidgetCard`'s `to`, `value`, `line` and `freshness`. For a list's tools (`docs/foundation/cell-patterns.md` 25 and 26): `FilterBar`, `FilterSelect`, `RelatedTable`, and DataTable's `views`, `columnsMenu`, `rowActions`, `phoneRow`, `limit` and `viewAll`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. For the dialogs and feedback standard (`docs/foundation/add-an-entity.md` "Toasts and feedback"): `DeleteAction`, `notify`, `useAction`, `ActionError`, `JobStatus`, `OfflineNotice`, `useOffline`; from `/ui/skeleton`, `Skeleton` takes `delay`. For the trail and search in `AppShell`'s bar (`docs/foundation/design-language.md` "The sidebar and the phone's bar"): `usePageTrail`, `useRecentRecord`, `PageTrail`; types `AppShellSearch`, `SearchRecord`, `RecentRecord`. For the form standard (`docs/foundation/add-an-entity.md` "Forms"): `FormSection`, `OptionSelect`, `ChoiceButtons`, `ReferenceCombobox`, `countFormErrors`, `fieldRows`, `parsePlainDate`, and for a record's rows edited in place `editRowClass`, `onEditRowClick` and `inPlace.choice`; from `/ui/field`, `Field` takes `size`, `solo` and `kind`, and `FieldLabel` takes `required`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
|
|
22
22
|
| `@tristan2828/ui-foundation/ui/<name>` | shadcn primitives: badge, button, calendar, card, checkbox, combobox, dialog, empty, field, input, input-group, label, popover, select, separator, sheet, sidebar, skeleton, sonner, spinner, switch, table, textarea, tooltip |
|
|
23
23
|
| `@tristan2828/ui-foundation/gateway` | `safeFetch`, `toAppError`, `networkError` — for an app's `src/api/gateway/` only |
|
|
24
|
-
| `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `environmentHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `exposeMswForE2E` |
|
|
24
|
+
| `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `environmentHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `startMockWorker` (mock mode's boot), `exposeMswForE2E` |
|
|
25
25
|
| `@tristan2828/ui-foundation/testing` | Playwright: `test` and `expect` (a page whose `goto()`/`reload()` wait for the app's boot; `withBootWait` for a page of your own), `defineA11ySuite`, `defineMockModeBannerSuite`, `defineDataEnvironmentBannerSuite`, `forceMswOverride`, `forceLoggedOut`, `waitForMswReady`, `expectDataViewsLoaded` |
|
|
26
26
|
| `@tristan2828/ui-foundation/eslint` | the lint rules, as a flat config: `export default [...uiFoundation()]` |
|
|
27
27
|
| `@tristan2828/ui-foundation/styles.css` | tokens and base styles, after `@import "tailwindcss";` |
|
package/dist/mocks/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export { clientErrorHandlers, getMockClientErrors, resetMockClientErrors } from
|
|
|
3
3
|
export { environmentHandlers } from './environment.js';
|
|
4
4
|
export { getMockPushSubscriptions, MOCK_PUSH_PUBLIC_KEY, pushHandlers, resetMockPush } from './push.js';
|
|
5
5
|
export { exposeMswForE2E } from './e2e-hooks.js';
|
|
6
|
+
export { MOCK_PROBE_PATH, startMockWorker } from './start-worker.js';
|
|
6
7
|
export type { MswHandle, MswOverride } from './override.js';
|
package/dist/mocks/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { clientErrorHandlers, getMockClientErrors, resetMockClientErrors } from
|
|
|
6
6
|
export { environmentHandlers } from './environment.js';
|
|
7
7
|
export { getMockPushSubscriptions, MOCK_PUSH_PUBLIC_KEY, pushHandlers, resetMockPush } from './push.js';
|
|
8
8
|
export { exposeMswForE2E } from './e2e-hooks.js';
|
|
9
|
+
export { MOCK_PROBE_PATH, startMockWorker } from './start-worker.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SetupWorker, StartOptions } from 'msw/browser';
|
|
2
|
+
/** Answered only by the handler startMockWorker adds for the probe. */
|
|
3
|
+
export declare const MOCK_PROBE_PATH = "/__ui-foundation-msw-probe";
|
|
4
|
+
/**
|
|
5
|
+
* Starts MSW for an app's mock mode. Resolves once requests are answered by
|
|
6
|
+
* the mocks, with the worker exposed for Playwright (`exposeMswForE2E`).
|
|
7
|
+
* Render the app only after it resolves. `options` go to `worker.start()`;
|
|
8
|
+
* unhandled requests are bypassed unless they say otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function startMockWorker(worker: SetupWorker, options?: StartOptions): Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Mock mode's boot, shared by every app: starts the MSW worker and returns
|
|
2
|
+
// only once the page's requests really reach the mocks, then exposes the
|
|
3
|
+
// worker for Playwright (./e2e-hooks.ts).
|
|
4
|
+
//
|
|
5
|
+
// Two waits after worker.start():
|
|
6
|
+
//
|
|
7
|
+
// 1. The controller. On a first visit start() can resolve before the new
|
|
8
|
+
// service worker controls the page, and a request made in that gap goes
|
|
9
|
+
// to the network.
|
|
10
|
+
// 2. A probe. Being controlled still isn't enough: MSW's worker mocks only
|
|
11
|
+
// for the clients in its in-memory list, which the page joins with a
|
|
12
|
+
// MOCK_ACTIVATE message during start(). A worker the browser stops and
|
|
13
|
+
// starts again (it may, under load, at any time) has forgotten that list
|
|
14
|
+
// and passes every request through, so the app's first queries came back
|
|
15
|
+
// from the network (no `main`, "data is undefined"). So one request that
|
|
16
|
+
// only a runtime handler answers is made first; until it comes back
|
|
17
|
+
// mocked, the page joins the list again.
|
|
18
|
+
import { http, HttpResponse } from 'msw';
|
|
19
|
+
import { exposeMswForE2E } from './e2e-hooks.js';
|
|
20
|
+
/** Answered only by the handler startMockWorker adds for the probe. */
|
|
21
|
+
export const MOCK_PROBE_PATH = '/__ui-foundation-msw-probe';
|
|
22
|
+
const PROBE_ANSWER = 'mocked';
|
|
23
|
+
const PROBE_TRIES = 20;
|
|
24
|
+
const PROBE_PAUSE_MS = 100;
|
|
25
|
+
/**
|
|
26
|
+
* Starts MSW for an app's mock mode. Resolves once requests are answered by
|
|
27
|
+
* the mocks, with the worker exposed for Playwright (`exposeMswForE2E`).
|
|
28
|
+
* Render the app only after it resolves. `options` go to `worker.start()`;
|
|
29
|
+
* unhandled requests are bypassed unless they say otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export async function startMockWorker(worker, options = {}) {
|
|
32
|
+
await worker.start({ onUnhandledRequest: 'bypass', ...options });
|
|
33
|
+
await untilControlled();
|
|
34
|
+
await untilMocked(worker);
|
|
35
|
+
// After the probe's resetHandlers(), so a spec's pre-navigation override
|
|
36
|
+
// (applied here) stays in place.
|
|
37
|
+
exposeMswForE2E(worker);
|
|
38
|
+
}
|
|
39
|
+
// Bounded: a hard reload leaves the page uncontrolled for its whole life,
|
|
40
|
+
// and then the probe below says so instead of the boot hanging.
|
|
41
|
+
const CONTROLLER_WAIT_MS = 3000;
|
|
42
|
+
function untilControlled() {
|
|
43
|
+
if (navigator.serviceWorker.controller)
|
|
44
|
+
return Promise.resolve();
|
|
45
|
+
return new Promise((resolve) => {
|
|
46
|
+
const timer = setTimeout(resolve, CONTROLLER_WAIT_MS);
|
|
47
|
+
navigator.serviceWorker.addEventListener('controllerchange', () => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
resolve();
|
|
50
|
+
}, { once: true });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function untilMocked(worker) {
|
|
54
|
+
worker.use(http.get(MOCK_PROBE_PATH, () => HttpResponse.text(PROBE_ANSWER)));
|
|
55
|
+
try {
|
|
56
|
+
for (let attempt = 0; attempt < PROBE_TRIES; attempt += 1) {
|
|
57
|
+
if ((await probe()) === PROBE_ANSWER)
|
|
58
|
+
return;
|
|
59
|
+
// The worker doesn't know this page: join its client list again.
|
|
60
|
+
navigator.serviceWorker.controller?.postMessage('MOCK_ACTIVATE');
|
|
61
|
+
await new Promise((resolve) => setTimeout(resolve, PROBE_PAUSE_MS));
|
|
62
|
+
}
|
|
63
|
+
console.error(`[ui-foundation] The mock service worker still passes this page's requests to the network after ${PROBE_TRIES} tries. ` +
|
|
64
|
+
'API calls may not be mocked; reload the page.');
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
// The probe's handler goes: the runtime handlers are the specs' alone.
|
|
68
|
+
worker.resetHandlers();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function probe() {
|
|
72
|
+
// The one bare fetch in mocks (eslint.config.js): it tests the worker
|
|
73
|
+
// itself, before any app code runs, and never reaches a server.
|
|
74
|
+
return fetch(MOCK_PROBE_PATH, { cache: 'no-store' })
|
|
75
|
+
.then((response) => (response.ok ? response.text() : ''))
|
|
76
|
+
.catch(() => '');
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.114.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|