@tristan2828/ui-foundation 4.125.0 → 4.127.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/conventions/docs/add-an-entity.md +140 -35
- package/conventions/docs/cell-patterns.md +144 -56
- package/conventions/docs/design-language.md +45 -13
- package/dist/api/contracts.d.ts +8 -1
- package/dist/api/gateway/errors.js +4 -0
- package/dist/api/schema.d.ts +9 -0
- package/dist/api/transport/index.js +10 -1
- package/dist/components/app/data-table-tools.d.ts +12 -0
- package/dist/components/app/data-table-tools.js +2 -2
- package/dist/components/app/data-table.d.ts +2 -1
- package/dist/components/app/data-table.js +1 -1
- package/dist/components/app/edit-caret.d.ts +25 -0
- package/dist/components/app/edit-caret.js +118 -0
- package/dist/components/app/edit-in-place-presets.d.ts +51 -1
- package/dist/components/app/edit-in-place-presets.js +30 -0
- package/dist/components/app/edit-in-place-store.d.ts +70 -4
- package/dist/components/app/edit-in-place-store.js +219 -21
- package/dist/components/app/edit-in-place.d.ts +11 -0
- package/dist/components/app/editable-value.js +202 -25
- package/dist/components/app/entity-form.js +4 -0
- package/dist/components/app/entity-view.js +5 -1
- package/dist/components/app/equal-items.d.ts +32 -6
- package/dist/components/app/equal-items.js +59 -8
- package/dist/components/app/error-state.js +1 -0
- package/dist/components/app/form-leave-guard.js +7 -1
- package/dist/components/app/milkdown-editor.d.ts +1 -0
- package/dist/components/app/milkdown-editor.js +226 -64
- package/dist/components/app/pill-filter.d.ts +16 -0
- package/dist/components/app/pill-filter.js +22 -1
- package/dist/components/app/prose-look.d.ts +1 -1
- package/dist/components/app/prose-look.js +3 -1
- package/dist/components/app/rating-input.d.ts +22 -0
- package/dist/components/app/rating-input.js +65 -0
- package/dist/components/app/rating-score.d.ts +2 -1
- package/dist/components/app/rating-score.js +2 -6
- package/dist/components/app/rich-text-autolink.d.ts +6 -0
- package/dist/components/app/rich-text-autolink.js +79 -0
- package/dist/components/app/rich-text-edges.d.ts +8 -0
- package/dist/components/app/rich-text-edges.js +144 -0
- package/dist/components/app/rich-text-editor.d.ts +19 -4
- package/dist/components/app/rich-text-editor.js +19 -6
- package/dist/components/app/rich-text-empty-paragraph.d.ts +14 -6
- package/dist/components/app/rich-text-empty-paragraph.js +19 -8
- package/dist/components/app/rich-text-formats.js +88 -15
- package/dist/components/app/rich-text-full-screen.d.ts +2 -0
- package/dist/components/app/rich-text-full-screen.js +78 -0
- package/dist/components/app/rich-text-highlight-menu.d.ts +3 -1
- package/dist/components/app/rich-text-highlight-menu.js +3 -2
- package/dist/components/app/rich-text-input-rules.d.ts +7 -0
- package/dist/components/app/rich-text-input-rules.js +83 -0
- package/dist/components/app/rich-text-keyboard-bar.d.ts +24 -0
- package/dist/components/app/rich-text-keyboard-bar.js +215 -0
- package/dist/components/app/rich-text-node-views.js +2 -1
- package/dist/components/app/rich-text-paste.d.ts +43 -0
- package/dist/components/app/rich-text-paste.js +355 -0
- package/dist/components/app/rich-text-shortcuts.d.ts +5 -1
- package/dist/components/app/rich-text-shortcuts.js +132 -2
- package/dist/components/app/rich-text-slash-menu.js +47 -9
- package/dist/components/app/rich-text-slash.d.ts +7 -0
- package/dist/components/app/rich-text-slash.js +27 -14
- package/dist/components/app/rich-text-table-grips.d.ts +8 -6
- package/dist/components/app/rich-text-table-grips.js +11 -12
- package/dist/components/app/rich-text-tasks.d.ts +8 -0
- package/dist/components/app/rich-text-tasks.js +20 -0
- package/dist/components/app/rich-text-toolbar.d.ts +5 -1
- package/dist/components/app/rich-text-toolbar.js +14 -6
- package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
- package/dist/components/app/rich-text-tools-bar.js +2 -2
- package/dist/components/app/rich-text-touch.d.ts +2 -0
- package/dist/components/app/rich-text-touch.js +18 -0
- package/dist/components/app/rich-text-widgets.js +1 -1
- package/dist/hooks/table-url-changes.d.ts +4 -0
- package/dist/hooks/table-url-changes.js +13 -0
- package/dist/hooks/use-record-update.d.ts +13 -1
- package/dist/hooks/use-record-update.js +17 -3
- package/dist/hooks/use-table-url-state.js +14 -8
- package/dist/index.d.ts +5 -2
- package/dist/index.js +8 -0
- package/dist/lib/markdown-merge.d.ts +38 -0
- package/dist/lib/markdown-merge.js +202 -17
- package/dist/lib/page-leaving.d.ts +8 -0
- package/dist/lib/page-leaving.js +30 -0
- package/dist/lib/pending-edits.d.ts +14 -0
- package/dist/lib/pending-edits.js +51 -0
- package/dist/lib/rating-glyphs.d.ts +3 -0
- package/dist/lib/rating-glyphs.js +7 -0
- package/dist/mocks/e2e-hooks.js +10 -0
- package/dist/mocks/override.d.ts +8 -0
- package/dist/testing/index.d.ts +40 -2
- package/dist/testing/index.js +101 -7
- package/openapi/foundation.yaml +12 -0
- package/package.json +1 -1
- package/styles/index.css +7 -0
package/dist/testing/index.js
CHANGED
|
@@ -57,8 +57,66 @@ async function boot(page, load, again) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
// A test that leaves a page right after a save: the save's answer comes
|
|
61
|
+
// from the mocks, but its follow-up refresh is sent by the page as it
|
|
62
|
+
// unloads, after MSW's client has said goodbye to the worker, so the
|
|
63
|
+
// worker passes it to the network and the bypass check fails the test
|
|
64
|
+
// (about 1 run in 20 in one app). So before the page navigates, wait
|
|
65
|
+
// until none of its own /api/ requests has been in flight for SETTLE_QUIET_MS,
|
|
66
|
+
// at most SETTLE_CAP_MS: the refresh then lands on the page that sent it.
|
|
67
|
+
// The cap only bounds the wait (a request that never ends, a stream);
|
|
68
|
+
// reaching it never fails the test.
|
|
69
|
+
const SETTLE_QUIET_MS = 150;
|
|
70
|
+
const SETTLE_CAP_MS = 3000;
|
|
71
|
+
const SETTLE_POLL_MS = 25;
|
|
72
|
+
const trackers = new WeakMap();
|
|
73
|
+
const isOwnApi = (page, request) => {
|
|
74
|
+
const url = new URL(request.url());
|
|
75
|
+
if (!url.pathname.startsWith('/api/'))
|
|
76
|
+
return false;
|
|
77
|
+
const pageUrl = page.url();
|
|
78
|
+
return !/^https?:/.test(pageUrl) || url.origin === new URL(pageUrl).origin;
|
|
79
|
+
};
|
|
80
|
+
// The page's own /api/ requests in flight, from `request` until
|
|
81
|
+
// `requestfinished` or `requestfailed`, and since when none has been.
|
|
82
|
+
function trackApi(page) {
|
|
83
|
+
const known = trackers.get(page);
|
|
84
|
+
if (known)
|
|
85
|
+
return known;
|
|
86
|
+
const inFlight = new Set();
|
|
87
|
+
let quietSince = -Infinity;
|
|
88
|
+
page.on('request', (request) => {
|
|
89
|
+
if (isOwnApi(page, request))
|
|
90
|
+
inFlight.add(request);
|
|
91
|
+
});
|
|
92
|
+
const done = (request) => {
|
|
93
|
+
if (inFlight.delete(request) && inFlight.size === 0)
|
|
94
|
+
quietSince = Date.now();
|
|
95
|
+
};
|
|
96
|
+
page.on('requestfinished', done);
|
|
97
|
+
page.on('requestfailed', done);
|
|
98
|
+
const settle = async () => {
|
|
99
|
+
const deadline = Date.now() + SETTLE_CAP_MS;
|
|
100
|
+
for (;;) {
|
|
101
|
+
const now = Date.now();
|
|
102
|
+
if (inFlight.size === 0 && now - quietSince >= SETTLE_QUIET_MS)
|
|
103
|
+
return;
|
|
104
|
+
if (now >= deadline)
|
|
105
|
+
return;
|
|
106
|
+
const wait = inFlight.size === 0 ? quietSince + SETTLE_QUIET_MS - now : SETTLE_POLL_MS;
|
|
107
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(1, Math.min(wait, deadline - now))));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const tracker = { settle };
|
|
111
|
+
trackers.set(page, tracker);
|
|
112
|
+
return tracker;
|
|
113
|
+
}
|
|
60
114
|
/**
|
|
61
|
-
* Makes the page's `goto()` and `reload()`
|
|
115
|
+
* Makes the page's `goto()` and `reload()` wait first until none of the
|
|
116
|
+
* page's own `/api/` requests has been in flight for 150 ms (at most 3 s,
|
|
117
|
+
* and reaching that never fails the test), so a save's follow-up refresh
|
|
118
|
+
* is answered by the page that sent it, on the mocks, not sent by the
|
|
119
|
+
* unloading page past them. They then return once the app has
|
|
62
120
|
* booted (its first render into `#root`), not at the load event, and load
|
|
63
121
|
* the page once more when one of the app's own files is refused before
|
|
64
122
|
* then; a second refusal fails naming the file. The wait is bounded by
|
|
@@ -69,8 +127,15 @@ async function boot(page, load, again) {
|
|
|
69
127
|
export function withBootWait(page) {
|
|
70
128
|
const goto = page.goto.bind(page);
|
|
71
129
|
const reload = page.reload.bind(page);
|
|
72
|
-
|
|
73
|
-
page.
|
|
130
|
+
const api = trackApi(page);
|
|
131
|
+
page.goto = async (url, options) => {
|
|
132
|
+
await api.settle();
|
|
133
|
+
return boot(page, () => goto(url, options), () => reload(options));
|
|
134
|
+
};
|
|
135
|
+
page.reload = async (options) => {
|
|
136
|
+
await api.settle();
|
|
137
|
+
return boot(page, () => reload(options), () => reload(options));
|
|
138
|
+
};
|
|
74
139
|
return page;
|
|
75
140
|
}
|
|
76
141
|
/**
|
|
@@ -160,19 +225,48 @@ export const test = base.extend({
|
|
|
160
225
|
* Forces a response for the page's *first* load: set before navigation, so
|
|
161
226
|
* it wins the race against the app's own first fetch. For states forced
|
|
162
227
|
* after load, use `waitForMswReady` and then `window.__msw.worker.use(...)`.
|
|
228
|
+
* The override applies to every page the test loads after, reloads included.
|
|
229
|
+
*
|
|
230
|
+
* `{ hold: true }` holds the requests until the test releases them, for a
|
|
231
|
+
* loading state (`tasksList` here is the list's `MswOverride`):
|
|
232
|
+
*
|
|
233
|
+
* const list = await forceMswOverride(page, tasksList, { hold: true })
|
|
234
|
+
* await page.goto('/tasks')
|
|
235
|
+
* await expect(page.locator('[data-state="loading"]')).toBeVisible()
|
|
236
|
+
* await list.release()
|
|
237
|
+
* await expect(page.getByText('Water the ferns')).toBeVisible()
|
|
238
|
+
*
|
|
239
|
+
* Release before the test navigates again: `goto()` and `reload()` first
|
|
240
|
+
* wait for the page's `/api/` requests to settle, and a held one doesn't.
|
|
163
241
|
*/
|
|
164
|
-
export async function forceMswOverride(page, override) {
|
|
242
|
+
export async function forceMswOverride(page, override, { hold = false } = {}) {
|
|
165
243
|
await page.addInitScript((spec) => {
|
|
166
244
|
window.__E2E_MSW_OVERRIDE__ = spec;
|
|
167
|
-
}, override);
|
|
245
|
+
}, hold ? { ...override, hold } : override);
|
|
246
|
+
return { release: () => releaseMswOverride(page) };
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Releases a held override (`forceMswOverride(page, ..., { hold: true })`):
|
|
250
|
+
* the requests held so far answer, and later ones answer at once, on this
|
|
251
|
+
* page and every page the test loads after. Releasing twice, or an
|
|
252
|
+
* override that wasn't held, does nothing.
|
|
253
|
+
*/
|
|
254
|
+
export async function releaseMswOverride(page) {
|
|
255
|
+
await page.addInitScript(() => {
|
|
256
|
+
window.__E2E_MSW_RELEASED__ = true;
|
|
257
|
+
});
|
|
258
|
+
await page.evaluate(() => {
|
|
259
|
+
window.__E2E_MSW_RELEASED__ = true;
|
|
260
|
+
window.__E2E_MSW_RELEASE__?.();
|
|
261
|
+
});
|
|
168
262
|
}
|
|
169
263
|
/** `window.__msw` is set only once the app's mocking has started — page.goto's load event doesn't wait for it. */
|
|
170
264
|
export async function waitForMswReady(page) {
|
|
171
265
|
await page.waitForFunction(() => window.__msw !== undefined);
|
|
172
266
|
}
|
|
173
267
|
/** Starts the page logged out: GET /auth/me answers 401 on first load. */
|
|
174
|
-
export function forceLoggedOut(page) {
|
|
175
|
-
|
|
268
|
+
export async function forceLoggedOut(page) {
|
|
269
|
+
await forceMswOverride(page, {
|
|
176
270
|
method: 'get',
|
|
177
271
|
path: '*/api/auth/me',
|
|
178
272
|
status: 401,
|
package/openapi/foundation.yaml
CHANGED
|
@@ -436,6 +436,18 @@ components:
|
|
|
436
436
|
content:
|
|
437
437
|
application/json:
|
|
438
438
|
schema: { $ref: "#/components/schemas/HTTPErrorBody" }
|
|
439
|
+
ConflictError:
|
|
440
|
+
# Optional: an app that checks no versions leaves it out, and
|
|
441
|
+
# check-contract doesn't ask for it.
|
|
442
|
+
x-optional: true
|
|
443
|
+
description: >
|
|
444
|
+
The record changed since the version the request was built on
|
|
445
|
+
(another tab, device or AI chat saved in between). Nothing was
|
|
446
|
+
written. The client fetches the record again and lets the person
|
|
447
|
+
choose; the gateway's toAppError makes it AppError kind "conflict".
|
|
448
|
+
content:
|
|
449
|
+
application/json:
|
|
450
|
+
schema: { $ref: "#/components/schemas/HTTPErrorBody" }
|
|
439
451
|
SignInExpiredError:
|
|
440
452
|
description: The pending sign-in is missing, expired or out of tries. Start again with POST /auth/login.
|
|
441
453
|
content:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.127.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": {
|
package/styles/index.css
CHANGED
|
@@ -401,6 +401,13 @@
|
|
|
401
401
|
.prose-table th {
|
|
402
402
|
text-align: start;
|
|
403
403
|
}
|
|
404
|
+
/* The rich-text editor on a touch screen (review F11): rows 40px tall, so
|
|
405
|
+
a row grip's 40px tap area stays in its own row. */
|
|
406
|
+
@media (pointer: coarse) {
|
|
407
|
+
[data-slot="rich-text-editor"] .prose-table :is(td, th) {
|
|
408
|
+
height: 2.5rem;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
404
411
|
.prose-table :is(td, th):is([style*="right"], [align="right"]) {
|
|
405
412
|
white-space: nowrap;
|
|
406
413
|
font-variant-numeric: tabular-nums;
|