@tristan2828/ui-foundation 4.27.0 → 4.29.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.
Files changed (37) hide show
  1. package/conventions/AGENTS.md +3 -1
  2. package/conventions/docs/add-an-entity.md +29 -0
  3. package/conventions/docs/cell-patterns.md +5 -1
  4. package/conventions/docs/design-language.md +44 -0
  5. package/conventions/docs/timed-screens.md +114 -8
  6. package/dist/components/app/app-shell.d.ts +10 -1
  7. package/dist/components/app/app-shell.js +2 -2
  8. package/dist/components/app/foundation-providers.js +5 -1
  9. package/dist/components/app/icon-component.d.ts +12 -0
  10. package/dist/components/app/icon-component.js +1 -0
  11. package/dist/components/app/image-field.d.ts +37 -0
  12. package/dist/components/app/image-field.js +103 -0
  13. package/dist/components/app/markdown.js +1 -1
  14. package/dist/components/app/milkdown-editor.d.ts +1 -1
  15. package/dist/components/app/milkdown-editor.js +84 -5
  16. package/dist/components/app/rich-text-editor.d.ts +16 -0
  17. package/dist/components/app/rich-text-editor.js +5 -0
  18. package/dist/components/app/rich-text-image-upload.d.ts +42 -0
  19. package/dist/components/app/rich-text-image-upload.js +174 -0
  20. package/dist/components/app/rich-text-toolbar.d.ts +6 -2
  21. package/dist/components/app/rich-text-toolbar.js +36 -28
  22. package/dist/components/app/widget-card.d.ts +7 -3
  23. package/dist/error-reporting/error-reporting-provider.js +7 -1
  24. package/dist/error-reporting/reporter.d.ts +20 -1
  25. package/dist/error-reporting/reporter.js +60 -6
  26. package/dist/hooks/use-session-clock.d.ts +19 -4
  27. package/dist/hooks/use-session-clock.js +35 -6
  28. package/dist/index.d.ts +4 -1
  29. package/dist/index.js +3 -1
  30. package/dist/lib/audio-cues.d.ts +28 -6
  31. package/dist/lib/audio-cues.js +57 -8
  32. package/dist/lib/image-file.d.ts +37 -0
  33. package/dist/lib/image-file.js +82 -0
  34. package/dist/lib/markdown-merge.js +1 -1
  35. package/dist/lib/stale-chunk-reload.d.ts +14 -0
  36. package/dist/lib/stale-chunk-reload.js +64 -0
  37. package/package.json +1 -1
@@ -0,0 +1,64 @@
1
+ // After a deploy, a tab opened on the build before it still runs that
2
+ // build, and its content-hashed chunks are gone from the server: the next
3
+ // lazy import (the rich-text editor's, say) fails with "Failed to fetch
4
+ // dynamically imported module" (#206). Vite's preload helper announces it
5
+ // first as a cancelable `vite:preloadError` on `window`, for the package's
6
+ // own lazy chunks too once the app's build bundles them. On it, the page
7
+ // reloads once onto the new build, and the failure is not reported.
8
+ //
9
+ // Once, because a file missing from the new build too would reload
10
+ // forever: the reload is remembered in sessionStorage, and a second
11
+ // failure within `windowMs` of it is let through to the error boundary
12
+ // (and reported, since that one is a real missing file). Where nothing
13
+ // can be remembered, nothing reloads.
14
+ //
15
+ // createStaleChunkReload takes its storage, reload and clock, so the rules
16
+ // are unit tested in node (tests/stale-chunk-reload.test.ts);
17
+ // FoundationProviders installs the shared instance over the real ones.
18
+ const KEY = 'ui-foundation:stale-chunk-reload';
19
+ const WINDOW_MS = 60_000;
20
+ export function createStaleChunkReload({ storage, reload, now = Date.now, windowMs = WINDOW_MS, }) {
21
+ let reloading = false;
22
+ const remember = () => {
23
+ try {
24
+ const store = storage();
25
+ if (!store)
26
+ return false;
27
+ const last = Number(store.getItem(KEY));
28
+ if (Number.isFinite(last) && last > 0 && now() - last < windowMs)
29
+ return false;
30
+ store.setItem(KEY, String(now()));
31
+ return true;
32
+ }
33
+ catch {
34
+ return false;
35
+ }
36
+ };
37
+ const onPreloadError = (event) => {
38
+ if (reloading) {
39
+ event.preventDefault();
40
+ return;
41
+ }
42
+ if (!remember())
43
+ return;
44
+ reloading = true;
45
+ event.preventDefault();
46
+ reload();
47
+ };
48
+ return {
49
+ isReloading: () => reloading,
50
+ install(target) {
51
+ target.addEventListener('vite:preloadError', onPreloadError);
52
+ return () => target.removeEventListener('vite:preloadError', onPreloadError);
53
+ },
54
+ };
55
+ }
56
+ let shared = null;
57
+ /** The one instance over the real window, sessionStorage and reload. */
58
+ export function browserStaleChunkReload() {
59
+ shared ??= createStaleChunkReload({
60
+ storage: () => (typeof sessionStorage === 'undefined' ? undefined : sessionStorage),
61
+ reload: () => window.location.reload(),
62
+ });
63
+ return shared;
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.27.0",
3
+ "version": "4.29.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": {