@tristan2828/ui-foundation 4.124.2 → 4.126.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 +42 -21
- package/conventions/docs/cell-patterns.md +80 -39
- package/dist/api/transport/index.js +10 -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-store.d.ts +43 -4
- package/dist/components/app/edit-in-place-store.js +169 -19
- package/dist/components/app/editable-value.js +164 -22
- package/dist/components/app/entity-form.js +4 -0
- package/dist/components/app/entity-view.js +1 -1
- 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 +224 -63
- package/dist/components/app/prose-look.d.ts +1 -1
- package/dist/components/app/prose-look.js +3 -1
- 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 +15 -2
- package/dist/components/app/rich-text-editor.js +16 -4
- 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 +214 -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 +13 -5
- 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-table-url-state.js +14 -8
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/lib/markdown-merge.d.ts +26 -0
- package/dist/lib/markdown-merge.js +112 -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/mocks/e2e-hooks.js +10 -0
- package/dist/mocks/override.d.ts +8 -0
- package/dist/mocks/start-worker.d.ts +24 -0
- package/dist/mocks/start-worker.js +120 -3
- package/dist/testing/index.d.ts +84 -5
- package/dist/testing/index.js +177 -10
- 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,37 +127,146 @@ 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
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Watches the page's own `/api/` responses for any that didn't come from
|
|
143
|
+
* the mock service worker (`response.fromServiceWorker()` false), which
|
|
144
|
+
* means the request went to the network: to the preview server's proxy,
|
|
145
|
+
* and from there to whatever listens on its port. A test that passed on
|
|
146
|
+
* data from there didn't test the mocks (#367).
|
|
147
|
+
*
|
|
148
|
+
* A bypass the app healed doesn't count: since the rejoin in
|
|
149
|
+
* `startMockWorker`, a page whose worker forgot it makes the request again
|
|
150
|
+
* once the worker knows it, so a later answer from the worker to the same
|
|
151
|
+
* method and URL settles it. A test that routes requests itself is left
|
|
152
|
+
* alone: its routed answers aren't the worker's either.
|
|
153
|
+
*
|
|
154
|
+
* The `test` exported here runs it on every test's `page`; this is for a
|
|
155
|
+
* page an app's own fixture opens. Call `check()` after the test.
|
|
156
|
+
*/
|
|
157
|
+
export function watchMswBypass(page, { mockMode = process.env.VITE_API !== 'real' } = {}) {
|
|
158
|
+
const pending = [];
|
|
159
|
+
let routed = false;
|
|
160
|
+
page.on('response', (response) => {
|
|
161
|
+
const url = new URL(response.url());
|
|
162
|
+
const pageUrl = page.url();
|
|
163
|
+
if (!url.pathname.startsWith('/api/'))
|
|
164
|
+
return;
|
|
165
|
+
if (/^https?:/.test(pageUrl) && url.origin !== new URL(pageUrl).origin)
|
|
166
|
+
return;
|
|
167
|
+
const method = response.request().method();
|
|
168
|
+
const key = `${method} ${url.href}`;
|
|
169
|
+
if (response.fromServiceWorker()) {
|
|
170
|
+
// The same request answered by the worker after it went past: healed.
|
|
171
|
+
const healed = pending.findIndex((entry) => entry.key === key);
|
|
172
|
+
if (healed !== -1)
|
|
173
|
+
pending.splice(healed, 1);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
pending.push({ key, line: `${method} ${url.pathname}${url.search} answered ${response.status()} without MSW` });
|
|
177
|
+
});
|
|
178
|
+
const flagRoutes = (target, names) => {
|
|
179
|
+
for (const name of names) {
|
|
180
|
+
const original = target[name];
|
|
181
|
+
if (typeof original !== 'function')
|
|
182
|
+
continue;
|
|
183
|
+
target[name] = ((...args) => {
|
|
184
|
+
routed = true;
|
|
185
|
+
return original.apply(target, args);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
flagRoutes(page, ['route', 'routeFromHAR']);
|
|
190
|
+
flagRoutes(page.context(), ['route', 'routeFromHAR']);
|
|
191
|
+
const bypassed = () => pending.map((entry) => entry.line);
|
|
192
|
+
return {
|
|
193
|
+
bypassed,
|
|
194
|
+
routed: () => routed,
|
|
195
|
+
check: () => {
|
|
196
|
+
if (!mockMode || routed || pending.length === 0)
|
|
197
|
+
return;
|
|
198
|
+
throw new Error(`${pending.length} API request(s) went past the mock service worker, so this test didn't run on the mocks:\n` +
|
|
199
|
+
bypassed().map((line) => ` ${line}`).join('\n') +
|
|
200
|
+
'\nSee docs/consuming.md "End-to-end tests on the mocks". A test that answers requests itself (page.route) is exempt; ' +
|
|
201
|
+
"one that expects this can opt out with test.use({ mswBypass: 'allow' }).");
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
76
205
|
/**
|
|
77
206
|
* Playwright's `test`, with a `page` whose `goto()` and `reload()` wait
|
|
78
|
-
* for the app's boot (`withBootWait`)
|
|
79
|
-
*
|
|
207
|
+
* for the app's boot (`withBootWait`), and which fails a test whose page
|
|
208
|
+
* got an `/api/` answer from anywhere but the mock service worker
|
|
209
|
+
* (`watchMswBypass`). Import `test` and `expect` from here instead of
|
|
210
|
+
* '@playwright/test'; the suites below use it too.
|
|
211
|
+
*
|
|
212
|
+
* `test.use({ mswBypass: 'allow' })` turns the check off for a file or a
|
|
213
|
+
* describe; a test that routes requests itself (`page.route`) and a run
|
|
214
|
+
* against the real API (`VITE_API=real`) are never checked.
|
|
80
215
|
*/
|
|
81
216
|
export const test = base.extend({
|
|
82
|
-
|
|
217
|
+
mswBypass: ['fail', { option: true }],
|
|
218
|
+
page: async ({ page, mswBypass }, provide) => {
|
|
219
|
+
const watch = mswBypass === 'fail' ? watchMswBypass(page) : null;
|
|
83
220
|
await provide(withBootWait(page));
|
|
221
|
+
watch?.check();
|
|
84
222
|
},
|
|
85
223
|
});
|
|
86
224
|
/**
|
|
87
225
|
* Forces a response for the page's *first* load: set before navigation, so
|
|
88
226
|
* it wins the race against the app's own first fetch. For states forced
|
|
89
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.
|
|
90
241
|
*/
|
|
91
|
-
export async function forceMswOverride(page, override) {
|
|
242
|
+
export async function forceMswOverride(page, override, { hold = false } = {}) {
|
|
92
243
|
await page.addInitScript((spec) => {
|
|
93
244
|
window.__E2E_MSW_OVERRIDE__ = spec;
|
|
94
|
-
}, 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
|
+
});
|
|
95
262
|
}
|
|
96
263
|
/** `window.__msw` is set only once the app's mocking has started — page.goto's load event doesn't wait for it. */
|
|
97
264
|
export async function waitForMswReady(page) {
|
|
98
265
|
await page.waitForFunction(() => window.__msw !== undefined);
|
|
99
266
|
}
|
|
100
267
|
/** Starts the page logged out: GET /auth/me answers 401 on first load. */
|
|
101
|
-
export function forceLoggedOut(page) {
|
|
102
|
-
|
|
268
|
+
export async function forceLoggedOut(page) {
|
|
269
|
+
await forceMswOverride(page, {
|
|
103
270
|
method: 'get',
|
|
104
271
|
path: '*/api/auth/me',
|
|
105
272
|
status: 401,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.126.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;
|