create-tigra 4.0.1 → 4.1.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/CHANGELOG.md +27 -0
- package/README.md +17 -2
- package/bin/create-tigra.js +72 -1
- package/lib/patchers/diagnostics.patcher.js +149 -0
- package/lib/patchers/metrics.patcher.js +145 -0
- package/modules/diagnostics/diagnostics.md +65 -0
- package/modules/diagnostics/prisma/diagnostic-bucket.prisma +22 -0
- package/modules/diagnostics/prisma/migration.sql +43 -0
- package/modules/diagnostics/server/__tests__/diagnostics.collector.test.ts +72 -0
- package/modules/diagnostics/server/__tests__/diagnostics.context.test.ts +51 -0
- package/modules/diagnostics/server/__tests__/diagnostics.integration.test.ts +107 -0
- package/modules/diagnostics/server/__tests__/diagnostics.service.test.ts +31 -0
- package/modules/diagnostics/server/diagnostics.collector.ts +95 -0
- package/modules/diagnostics/server/diagnostics.context.ts +73 -0
- package/modules/diagnostics/server/diagnostics.repo.ts +69 -0
- package/modules/diagnostics/server/diagnostics.routes.ts +17 -0
- package/modules/diagnostics/server/diagnostics.sample.ts +92 -0
- package/modules/diagnostics/server/diagnostics.schemas.ts +33 -0
- package/modules/diagnostics/server/diagnostics.service.ts +44 -0
- package/modules/metrics/client/WebVitalsReporter.tsx +35 -0
- package/modules/metrics/client/__tests__/WebVitalsReporter.test.ts +65 -0
- package/modules/metrics/client/metrics.pages.ts +5 -0
- package/modules/metrics/performance.md +56 -0
- package/modules/metrics/prisma/metric-bucket.prisma +18 -0
- package/modules/metrics/prisma/migration.sql +17 -0
- package/modules/metrics/server/__tests__/metrics.collector.test.ts +75 -0
- package/modules/metrics/server/__tests__/metrics.integration.test.ts +88 -0
- package/modules/metrics/server/__tests__/metrics.schemas.test.ts +36 -0
- package/modules/metrics/server/__tests__/metrics.service.test.ts +84 -0
- package/modules/metrics/server/metrics.collector.ts +130 -0
- package/modules/metrics/server/metrics.pages.ts +3 -0
- package/modules/metrics/server/metrics.repo.ts +45 -0
- package/modules/metrics/server/metrics.routes.ts +46 -0
- package/modules/metrics/server/metrics.schemas.ts +57 -0
- package/modules/metrics/server/metrics.service.ts +100 -0
- package/package.json +1 -1
- package/template/AGENTS.md +17 -10
- package/template/client/src/app/focus-rings.policy.test.ts +88 -0
- package/template/client/src/app/globals.css +46 -0
- package/template/client/src/app/layout.tsx +5 -0
- package/template/client/src/app/page.tsx +2 -2
- package/template/client/src/components/common/InputModalityTracker.tsx +12 -0
- package/template/client/src/components/ui/input.tsx +3 -2
- package/template/client/src/lib/input-modality.test.ts +79 -0
- package/template/client/src/lib/input-modality.ts +52 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the visitor last interacted with the page, kept on `<html data-input="pointer" | "keyboard">`, so focus rings
|
|
3
|
+
* show only for keyboard users (globals.css "Focus rings").
|
|
4
|
+
*
|
|
5
|
+
* Why the browser's own `:focus-visible` is not enough: Radix menus and selects cancel the default of the mouse press
|
|
6
|
+
* on their trigger and then move focus by script (into the menu, then to the item under the pointer). Chrome then has
|
|
7
|
+
* no record of mouse use and reports `:focus-visible`, so every keyboard ring appeared for mouse users until their
|
|
8
|
+
* first ordinary click on the page (reproduced in Chrome, also on a blank page without Radix).
|
|
9
|
+
*
|
|
10
|
+
* Rules:
|
|
11
|
+
* - Any pointer press (mouse, touch, pen) means "pointer".
|
|
12
|
+
* - Tab means "keyboard" everywhere; arrows, Home/End, PageUp/PageDown and Escape mean "keyboard" outside text fields,
|
|
13
|
+
* where they navigate focus (menus, tabs, radio groups). Typing, Enter and caret keys in a text field do not: the
|
|
14
|
+
* owner is writing, not navigating. Shortcuts with Ctrl/Alt/Meta and lone modifier keys change nothing.
|
|
15
|
+
* - The server renders "pointer" (app/layout.tsx), so nothing shows a ring before the first key press; a keyboard
|
|
16
|
+
* user's first Tab switches the mode before focus moves (keydown precedes the focus change).
|
|
17
|
+
*/
|
|
18
|
+
export type InputModality = 'pointer' | 'keyboard';
|
|
19
|
+
|
|
20
|
+
const NAVIGATION_KEYS = new Set(['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown', 'Escape']);
|
|
21
|
+
/** Input types that are not text fields: arrows there move focus or a value, like any other control. */
|
|
22
|
+
const NON_TEXT_INPUTS = new Set(['button', 'submit', 'reset', 'checkbox', 'radio', 'range', 'file', 'color', 'image']);
|
|
23
|
+
|
|
24
|
+
/** True for elements where keys type or move a caret (they keep their focus look in every mode). */
|
|
25
|
+
function isTextField(target: EventTarget | null): boolean {
|
|
26
|
+
if (!(target instanceof Element)) return false;
|
|
27
|
+
if (target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return true;
|
|
28
|
+
if (target instanceof HTMLInputElement) return !NON_TEXT_INPUTS.has(target.type);
|
|
29
|
+
// The attribute, not `isContentEditable` (missing in jsdom); `closest` also covers keys from inside an editor.
|
|
30
|
+
return target.closest('[contenteditable]:not([contenteditable="false"])') !== null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Starts tracking on `doc` (capture phase, so a component that stops propagation cannot hide the interaction) and
|
|
34
|
+
* returns a function that stops it. Sets "pointer" at once. */
|
|
35
|
+
export function installInputModality(doc: Document): () => void {
|
|
36
|
+
const root = doc.documentElement;
|
|
37
|
+
const set = (mode: InputModality): void => {
|
|
38
|
+
if (root.getAttribute('data-input') !== mode) root.setAttribute('data-input', mode);
|
|
39
|
+
};
|
|
40
|
+
const onPointerDown = (): void => set('pointer');
|
|
41
|
+
const onKeyDown = (event: KeyboardEvent): void => {
|
|
42
|
+
if (event.ctrlKey || event.altKey || event.metaKey) return;
|
|
43
|
+
if (event.key === 'Tab' || (NAVIGATION_KEYS.has(event.key) && !isTextField(event.target))) set('keyboard');
|
|
44
|
+
};
|
|
45
|
+
set('pointer');
|
|
46
|
+
doc.addEventListener('pointerdown', onPointerDown, true);
|
|
47
|
+
doc.addEventListener('keydown', onKeyDown, true);
|
|
48
|
+
return () => {
|
|
49
|
+
doc.removeEventListener('pointerdown', onPointerDown, true);
|
|
50
|
+
doc.removeEventListener('keydown', onKeyDown, true);
|
|
51
|
+
};
|
|
52
|
+
}
|