@nifrajs/web 0.1.0-alpha.1

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 (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/css-modules.d.ts +34 -0
  4. package/dist/build.d.ts +110 -0
  5. package/dist/build.d.ts.map +1 -0
  6. package/dist/build.js +238 -0
  7. package/dist/build.js.map +1 -0
  8. package/dist/client.d.ts +32 -0
  9. package/dist/client.d.ts.map +1 -0
  10. package/dist/client.js +204 -0
  11. package/dist/client.js.map +1 -0
  12. package/dist/deferred.d.ts +90 -0
  13. package/dist/deferred.d.ts.map +1 -0
  14. package/dist/deferred.js +310 -0
  15. package/dist/deferred.js.map +1 -0
  16. package/dist/dev-error.d.ts +17 -0
  17. package/dist/dev-error.d.ts.map +1 -0
  18. package/dist/dev-error.js +59 -0
  19. package/dist/dev-error.js.map +1 -0
  20. package/dist/dev.d.ts +25 -0
  21. package/dist/dev.d.ts.map +1 -0
  22. package/dist/dev.js +83 -0
  23. package/dist/dev.js.map +1 -0
  24. package/dist/draft.d.ts +58 -0
  25. package/dist/draft.d.ts.map +1 -0
  26. package/dist/draft.js +55 -0
  27. package/dist/draft.js.map +1 -0
  28. package/dist/fonts-google.d.ts +109 -0
  29. package/dist/fonts-google.d.ts.map +1 -0
  30. package/dist/fonts-google.js +291 -0
  31. package/dist/fonts-google.js.map +1 -0
  32. package/dist/fonts.d.ts +67 -0
  33. package/dist/fonts.d.ts.map +1 -0
  34. package/dist/fonts.js +103 -0
  35. package/dist/fonts.js.map +1 -0
  36. package/dist/fs.d.ts +10 -0
  37. package/dist/fs.d.ts.map +1 -0
  38. package/dist/fs.js +24 -0
  39. package/dist/fs.js.map +1 -0
  40. package/dist/index.d.ts +280 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +784 -0
  43. package/dist/index.js.map +1 -0
  44. package/dist/islands.d.ts +37 -0
  45. package/dist/islands.d.ts.map +1 -0
  46. package/dist/islands.js +107 -0
  47. package/dist/islands.js.map +1 -0
  48. package/dist/isr.d.ts +154 -0
  49. package/dist/isr.d.ts.map +1 -0
  50. package/dist/isr.js +331 -0
  51. package/dist/isr.js.map +1 -0
  52. package/dist/manifest.d.ts +178 -0
  53. package/dist/manifest.d.ts.map +1 -0
  54. package/dist/manifest.js +213 -0
  55. package/dist/manifest.js.map +1 -0
  56. package/dist/plugins/css-modules.d.ts +40 -0
  57. package/dist/plugins/css-modules.d.ts.map +1 -0
  58. package/dist/plugins/css-modules.js +0 -0
  59. package/dist/plugins/css-modules.js.map +1 -0
  60. package/dist/plugins/kit.d.ts +44 -0
  61. package/dist/plugins/kit.d.ts.map +1 -0
  62. package/dist/plugins/kit.js +105 -0
  63. package/dist/plugins/kit.js.map +1 -0
  64. package/dist/plugins/scss.d.ts +27 -0
  65. package/dist/plugins/scss.d.ts.map +1 -0
  66. package/dist/plugins/scss.js +78 -0
  67. package/dist/plugins/scss.js.map +1 -0
  68. package/dist/prerender.d.ts +77 -0
  69. package/dist/prerender.d.ts.map +1 -0
  70. package/dist/prerender.js +139 -0
  71. package/dist/prerender.js.map +1 -0
  72. package/dist/query.d.ts +62 -0
  73. package/dist/query.d.ts.map +1 -0
  74. package/dist/query.js +184 -0
  75. package/dist/query.js.map +1 -0
  76. package/dist/router.d.ts +169 -0
  77. package/dist/router.d.ts.map +1 -0
  78. package/dist/router.js +531 -0
  79. package/dist/router.js.map +1 -0
  80. package/dist/vite.d.ts +49 -0
  81. package/dist/vite.d.ts.map +1 -0
  82. package/dist/vite.js +144 -0
  83. package/dist/vite.js.map +1 -0
  84. package/package.json +127 -0
  85. package/src/build.ts +375 -0
  86. package/src/client.ts +218 -0
  87. package/src/deferred.ts +339 -0
  88. package/src/dev-error.ts +62 -0
  89. package/src/dev.ts +108 -0
  90. package/src/draft.ts +82 -0
  91. package/src/fonts-google.ts +397 -0
  92. package/src/fonts.ts +147 -0
  93. package/src/fs.ts +26 -0
  94. package/src/index.ts +1202 -0
  95. package/src/islands.ts +121 -0
  96. package/src/isr.ts +461 -0
  97. package/src/manifest.ts +366 -0
  98. package/src/plugins/css-modules.ts +0 -0
  99. package/src/plugins/kit.ts +123 -0
  100. package/src/plugins/scss.ts +108 -0
  101. package/src/prerender.ts +209 -0
  102. package/src/query.ts +250 -0
  103. package/src/router.ts +676 -0
  104. package/src/vite.ts +212 -0
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Request header that asks a nifra route's GET to return just the loader data as JSON (instead of
3
+ * the full HTML document). Set by client-side navigation; read by `createWebApp`'s GET handler.
4
+ */
5
+ export declare const DATA_HEADER = "x-nifra-data";
6
+ /**
7
+ * Global the server injects (`createWebApp({ prerenderedPaths })`) listing the SSG-prerendered paths.
8
+ * The client's default data fetch reads it: a soft-nav INTO a prerendered route fetches its static
9
+ * `<path>/_data.json` (a CDN file — no worker round-trip) instead of the dynamic header-GET.
10
+ */
11
+ export declare const PRERENDERED_GLOBAL = "__NIFRA_PRERENDERED__";
12
+ /**
13
+ * Response header a data-mode action POST uses to convey a redirect (`redirect(...)`) to the
14
+ * client — fetch would otherwise silently follow a 3xx to its HTML, losing the target. The
15
+ * client reads this and performs a client-side navigation instead.
16
+ */
17
+ export declare const REDIRECT_HEADER = "x-nifra-redirect";
18
+ /**
19
+ * Response header an action sets (via the `revalidate(paths, data)` helper) to tell the client which
20
+ * routes the mutation changed — a comma-separated list of paths. After the submit, the client marks
21
+ * those cached routes stale (refetching any that are mounted) so a mutation can refresh views beyond
22
+ * the active one. The client validates each path against the manifest matcher before acting on it.
23
+ */
24
+ export declare const REVALIDATE_HEADER = "x-nifra-revalidate";
25
+ /** A URL matched against the manifest patterns: which route + its extracted params. */
26
+ export interface RouteMatch {
27
+ readonly routeId: string;
28
+ readonly params: Record<string, string>;
29
+ }
30
+ /** An in-flight client submit — the action it targets + the `FormData` being sent. Set while the
31
+ * submit is pending, cleared when it settles. A component reads `submission.formData` to render an
32
+ * **optimistic** view (the expected result) before the server responds. */
33
+ export interface Submission {
34
+ readonly action: string;
35
+ readonly formData: FormData;
36
+ }
37
+ /** The router's observable state. A new object is published on every transition. */
38
+ export interface RouterState {
39
+ readonly routeId: string;
40
+ readonly params: Record<string, string>;
41
+ /** The current URL path (used to revalidate the active loader after an action). */
42
+ readonly path: string;
43
+ readonly data: unknown;
44
+ /** An action's data return after a client-side submit (cleared on navigation). */
45
+ readonly actionData?: unknown;
46
+ /** True while a navigation or submit is in flight (drives loading UI). */
47
+ readonly pending: boolean;
48
+ /** The in-flight submit (set during a `submit`, cleared when it settles) — for optimistic UI. */
49
+ readonly submission?: Submission;
50
+ }
51
+ /** A route id paired with its nifra pattern (e.g. `":id"` segments) — the matcher input. */
52
+ export interface RoutePattern {
53
+ readonly routeId: string;
54
+ readonly pattern: string;
55
+ }
56
+ /**
57
+ * Build a matcher from route patterns (built from the SAME manifest the server routes from, so
58
+ * client and server agree). Returns the first matching route + decoded params, or null. The
59
+ * query string is ignored for matching (it is not part of the route pattern).
60
+ */
61
+ export declare function createMatcher(patterns: readonly RoutePattern[]): (path: string) => RouteMatch | null;
62
+ /** How a router fetches a route's loader data on navigation. `signal` aborts a superseded fetch
63
+ * (and its deferred stream). */
64
+ export type FetchRouteData = (path: string, match: RouteMatch, signal?: AbortSignal) => Promise<unknown>;
65
+ /** Per-submit options. `revalidate: false` opts out of the post-action loader re-fetch. */
66
+ export interface SubmitOptions {
67
+ /** Re-run the active route's loader after the action settles (default `true`). Set `false` to
68
+ * keep the current `data` and rely on the action's `actionData` alone. */
69
+ readonly revalidate?: boolean;
70
+ }
71
+ /** A fetcher's observable state — independent of the main router. `pending` covers its in-flight
72
+ * load/submit; `data` is its last `load()` result; `actionData` its last `submit()` result;
73
+ * `submission` the in-flight submit (for optimistic UI). Client-only (never SSR'd). */
74
+ export interface FetcherState {
75
+ readonly pending: boolean;
76
+ readonly data: unknown;
77
+ readonly actionData?: unknown;
78
+ readonly submission?: Submission;
79
+ }
80
+ /**
81
+ * An independent load/submit state machine, retrieved by `router.fetcher(key)`. Runs **concurrently**
82
+ * with the main router and with other fetchers — each is single-flight against *itself* (its own
83
+ * monotonic token), so N row-level mutations / side-channel loads can be in flight at once without
84
+ * disturbing the active view. Loads/submits write the shared cache and honor `X-Nifra-Revalidate`.
85
+ */
86
+ export interface Fetcher {
87
+ /** Current state; stable reference between transitions. */
88
+ snapshot: () => FetcherState;
89
+ /** Subscribe to this fetcher's transitions; returns an unsubscribe fn. */
90
+ subscribe: (listener: () => void) => () => void;
91
+ /** Load a route path's loader data into this fetcher's own `data` (also writes the shared cache).
92
+ * A no-op for an unmatched path. */
93
+ load: (path: string) => Promise<void>;
94
+ /** Submit an action into this fetcher's own state; honors `X-Nifra-Revalidate` by refreshing the
95
+ * active route + any mounted fetcher showing a changed path. Rejects on failure (caller falls back).
96
+ * (No `revalidate` opt-out — a fetcher has no active loader of its own to skip.) */
97
+ submit: (action: string, body: NonNullable<RequestInit["body"]>) => Promise<void>;
98
+ }
99
+ /** The agnostic router store consumed by per-adapter Router bindings. */
100
+ export interface ClientRouter {
101
+ /** Current state; stable reference between transitions (so `useSyncExternalStore` can bail). */
102
+ snapshot: () => RouterState;
103
+ /** Subscribe to transitions; returns an unsubscribe fn. */
104
+ subscribe: (listener: () => void) => () => void;
105
+ /** Navigate to a path: match → fetch loader data → publish. No-op for an unmatched path. */
106
+ navigate: (path: string) => Promise<void>;
107
+ /**
108
+ * Submit an action (POST `body` to `action` in data mode): a redirect becomes a client
109
+ * navigation; otherwise the data return is published as `actionData` and the active route's
110
+ * loader is revalidated so the mutation is reflected. Pass `{ revalidate: false }` to SKIP that
111
+ * revalidation — keep the current `data` and just publish the action's `actionData` (useful when
112
+ * the action already returned everything that changed, saving the extra round-trip). A redirect
113
+ * always loads its target regardless. Rejects on failure (caller falls back).
114
+ */
115
+ submit: (action: string, body: NonNullable<RequestInit["body"]>, opts?: SubmitOptions) => Promise<void>;
116
+ /**
117
+ * Mark cached route data stale and refresh the active view. With `paths`, target exactly those
118
+ * (e.g. the routes a mutation changed); without, invalidate the whole cache. The active route
119
+ * refreshes immediately — refetched + republished — whenever it's in scope (an explicit list that
120
+ * includes it, or an invalidate-all); other stale entries refetch lazily when next read (a
121
+ * fetcher, or the next navigation/access). Rejects if the active refetch fails (like `navigate`).
122
+ * The keyed substrate for targeted revalidation (the `X-Nifra-Revalidate` header) and fetchers.
123
+ */
124
+ invalidate: (paths?: readonly string[]) => Promise<void>;
125
+ /**
126
+ * Warm a path's chunk + loader data into a bounded one-shot cache without publishing state —
127
+ * a later `navigate` to it transitions with no network round-trip. Best-effort: failures and
128
+ * unmatched paths are no-ops. Wired to link hover/focus by `installHistory`.
129
+ */
130
+ prefetch: (path: string) => Promise<void>;
131
+ /**
132
+ * Get (lazily creating) the stable {@link Fetcher} for `key` — an independent, concurrent
133
+ * load/submit state machine for row-level mutations or side-channel loads that must not disturb
134
+ * the active view. The same `key` always returns the same fetcher (so a binding can subscribe to a
135
+ * stable store). Keys are app-chosen and typically stable (e.g. a row id).
136
+ */
137
+ fetcher: (key: string) => Fetcher;
138
+ /** All live fetchers — for a global busy view (e.g. a `useFetchers` binding). */
139
+ fetchers: () => readonly Fetcher[];
140
+ /** Subscribe to any-fetcher-changed (a transition on any fetcher, or a new one created) — backs a
141
+ * `useFetchers` binding; returns an unsubscribe fn. */
142
+ subscribeFetchers: (listener: () => void) => () => void;
143
+ /** Match a path against the manifest patterns (exposed for history/link wiring). */
144
+ match: (path: string) => RouteMatch | null;
145
+ }
146
+ export interface ClientRouterOptions {
147
+ readonly patterns: readonly RoutePattern[];
148
+ readonly initial: RouterState;
149
+ /** Override the loader-data fetch (tests inject a stub; defaults to a same-origin JSON GET). */
150
+ readonly fetchData?: FetchRouteData;
151
+ /** Ensure a route's code chunk is loaded before rendering (code-splitting). Awaited in parallel
152
+ * with the loader data, so `pending` covers both. Omit when the bundle isn't split. */
153
+ readonly loadModule?: (routeId: string) => Promise<void>;
154
+ }
155
+ /** Options for a per-adapter `mountRouter` (the Router binding that hydrates + re-renders). */
156
+ export interface MountRouterOptions {
157
+ readonly router: ClientRouter;
158
+ /** routeId → layout chain (outermost layout → page); built by `generateClientEntry`. */
159
+ readonly routes: Record<string, readonly unknown[]>;
160
+ /** Hydration container (opaque — the adapter casts it to its DOM element type). */
161
+ readonly container: unknown;
162
+ }
163
+ /**
164
+ * Create the agnostic router store. `navigate` is guarded by a monotonic token so that when
165
+ * navigations overlap, only the latest result is applied (rapid clicks don't flash stale data).
166
+ * A failed fetch clears `pending` and rethrows so the caller can fall back to a full-page load.
167
+ */
168
+ export declare function createClientRouter(options: ClientRouterOptions): ClientRouter;
169
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,eAAO,MAAM,WAAW,iBAAiB,CAAA;AAEzC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,0BAA0B,CAAA;AAEzD;;;;GAIG;AACH,eAAO,MAAM,eAAe,qBAAqB,CAAA;AAEjD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,uBAAuB,CAAA;AAErD,uFAAuF;AACvF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACxC;AAED;;2EAE2E;AAC3E,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAC5B;AAED,oFAAoF;AACpF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACvC,mFAAmF;IACnF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACr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