what-framework 0.11.7 → 0.11.8

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 (3) hide show
  1. package/package.json +5 -5
  2. package/router.d.ts +144 -12
  3. package/server.d.ts +15 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "what-framework",
3
- "version": "0.11.7",
3
+ "version": "0.11.8",
4
4
  "description": "The web framework built for AI agents — signals, components, islands, SSR",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -84,9 +84,9 @@
84
84
  },
85
85
  "homepage": "https://whatfw.com",
86
86
  "dependencies": {
87
- "what-core": "^0.11.7",
88
- "what-router": "^0.11.7",
89
- "what-server": "^0.11.7",
90
- "what-compiler": "^0.11.7"
87
+ "what-core": "^0.11.8",
88
+ "what-router": "^0.11.8",
89
+ "what-server": "^0.11.8",
90
+ "what-compiler": "^0.11.8"
91
91
  }
92
92
  }
package/router.d.ts CHANGED
@@ -37,9 +37,6 @@ export interface NavigateOptions {
37
37
  /** Navigate to a new URL */
38
38
  export function navigate(to: string, options?: NavigateOptions): Promise<void>;
39
39
 
40
- /** Redirect (throws to navigate) */
41
- export function redirect(to: string, options?: NavigateOptions): never;
42
-
43
40
  // --- Route Configuration ---
44
41
 
45
42
  export interface RouteConfig {
@@ -81,6 +78,25 @@ export interface RouterProps {
81
78
 
82
79
  export function Router(props: RouterProps): VNode;
83
80
 
81
+ // --- File-Based Router ---
82
+
83
+ export interface FileRouteConfig {
84
+ path: string;
85
+ component: Component<RouteComponentProps>;
86
+ layout?: Component<LayoutProps>;
87
+ mode?: 'static' | 'server' | 'client' | 'hybrid';
88
+ }
89
+
90
+ export interface FileRouterProps {
91
+ routes: FileRouteConfig[];
92
+ layout?: Component<{ children?: VNodeChild }>;
93
+ fallback?: Component<{}>;
94
+ error?: Component<{ error: Error }>;
95
+ }
96
+
97
+ /** Router driven by what-compiler's generated route manifest (virtual:what-routes). */
98
+ export function FileRouter(props: FileRouterProps): VNode;
99
+
84
100
  // --- Link Component ---
85
101
 
86
102
  export interface LinkProps {
@@ -104,25 +120,141 @@ export function NavLink(props: LinkProps): VNode;
104
120
  /** Define routes from object config */
105
121
  export function defineRoutes(config: Record<string, Component | Partial<RouteConfig>>): RouteConfig[];
106
122
 
123
+ /** Create nested routes with shared options */
124
+ export function nestedRoutes(
125
+ basePath: string,
126
+ children: RouteConfig[],
127
+ options?: { layout?: Component; loading?: Component; error?: Component }
128
+ ): RouteConfig[];
129
+
130
+ /** Group routes without affecting URLs */
131
+ export function routeGroup(
132
+ name: string,
133
+ routes: RouteConfig[],
134
+ options?: { layout?: Component; middleware?: RouteMiddleware[] }
135
+ ): RouteConfig[];
136
+
137
+ // --- Redirect ---
138
+
139
+ export function Redirect(props: { to: string }): null;
140
+
141
+ // --- Guards ---
142
+
143
+ /** Create a route guard */
144
+ export function guard(
145
+ check: (props: RouteComponentProps) => boolean,
146
+ fallback: string | Component
147
+ ): <P>(component: Component<P>) => Component<P>;
148
+
149
+ /** Create an async route guard */
150
+ export function asyncGuard(
151
+ check: (props: RouteComponentProps) => Promise<boolean>,
152
+ options?: { fallback?: string | Component; loading?: Component }
153
+ ): <P>(component: Component<P>) => Component<P>;
154
+
107
155
  // --- Prefetch ---
108
156
 
109
- export function prefetchRoute(href: string): void;
157
+ export function prefetch(href: string): void;
110
158
 
111
- // --- Navigation Hooks ---
159
+ // --- Scroll Restoration ---
112
160
 
113
- export function beforeNavigate(fn: (to: string, from: string) => boolean | Promise<boolean>): () => void;
114
- export function afterNavigate(fn: (to: string, from: string) => void): () => void;
161
+ export function enableScrollRestoration(): void;
162
+
163
+ // --- View Transitions ---
164
+
165
+ export function viewTransitionName(name: string): { style: { viewTransitionName: string } };
166
+ export function setViewTransition(type: string): void;
115
167
 
116
- // --- useRoute Hooks ---
168
+ // --- useRoute Hook ---
117
169
 
118
- export function useRoute(): {
170
+ export interface UseRouteResult {
119
171
  path: Computed<string>;
120
172
  params: Computed<Record<string, string>>;
121
173
  query: Computed<Record<string, string>>;
122
174
  hash: Computed<string>;
123
175
  isNavigating: Computed<boolean>;
124
- };
176
+ navigate: typeof navigate;
177
+ prefetch: typeof prefetch;
178
+ }
179
+
180
+ export function useRoute(): UseRouteResult;
181
+
182
+ // --- Route Accessors ---
183
+
184
+ /** Current route params. Subscribes when read inside a tracking scope. */
185
+ export function useParams<T = Record<string, string>>(): T;
125
186
 
126
- export function useParams<T extends Record<string, string> = Record<string, string>>(): T;
127
- export function useSearch<T extends Record<string, string> = Record<string, string>>(): T;
187
+ /**
188
+ * Query string of the last successfully matched route, parsed. Subscribes when
189
+ * read inside a tracking scope. Only the Router's match branch writes it, so on
190
+ * an unmatched (404) route this is the previous route's query, not the current
191
+ * URL's. Same value and same caveat as `route.query`.
192
+ */
193
+ export function useSearch<T = Record<string, string>>(): T;
194
+
195
+ /** The navigate function, for symmetry with useParams/useSearch. */
128
196
  export function useNavigate(): typeof navigate;
197
+
198
+ /** Prefetch a route's assets. */
199
+ export function prefetchRoute(href: string): void;
200
+
201
+ // --- Redirect Signal ---
202
+
203
+ /**
204
+ * Abort the current render and navigate.
205
+ *
206
+ * Throws a navigation signal. Two places catch it: route middleware, caught by
207
+ * the Router's matching pass, and a component body, caught by the runtime where
208
+ * it instantiates components. Anywhere else (an event handler, a promise
209
+ * callback, a timer, or a reactive thunk such as `{() => cond() && redirect(to)}`)
210
+ * nothing catches it and the signal surfaces as an uncaught error carrying
211
+ * `ERR_REDIRECT_NOT_CAUGHT`; call `navigate(to)` there instead. In a thunk the
212
+ * first render reports the error, but on a later re-run the navigation simply
213
+ * does not happen and the stale DOM stays, so prefer `navigate(to)` there.
214
+ * A `try/catch` around the call also swallows it, so rethrow anything whose
215
+ * `name` is `RouterRedirect`. On the server the signal escapes `renderToString`
216
+ * to its caller: read `.to` and emit a 302.
217
+ */
218
+ export function redirect(to: string, options?: NavigateOptions): never;
219
+
220
+ // --- Navigation Hooks ---
221
+
222
+ /**
223
+ * Run before every route navigation; return false to cancel. Returns an
224
+ * unsubscribe. Not consulted for same-page hash navigation (`navigate('#x')`
225
+ * scrolls, it does not change the route). Cancelling a back/forward navigation
226
+ * restores the address bar by pushing the previous URL as a new history entry:
227
+ * the entry the browser moved to is not recovered and its `history.state` is
228
+ * not carried over.
229
+ */
230
+ export function beforeNavigate(fn: (to: string, from: string) => boolean | Promise<boolean>): () => void;
231
+
232
+ /** Run after every committed navigation. Returns an unsubscribe. */
233
+ export function afterNavigate(fn: (to: string, from: string) => void): () => void;
234
+
235
+ // --- Outlet ---
236
+
237
+ export function Outlet(props: { children?: VNodeChild }): VNode;
238
+
239
+ // --- Path Matching ---
240
+
241
+ export interface CompiledPath {
242
+ regex: RegExp;
243
+ paramNames: string[];
244
+ catchAll: string | null;
245
+ }
246
+
247
+ /** Compile a path pattern (`/users/:id`, `/posts/*`, `/[slug]`) to a matcher. */
248
+ export function compilePath(path: string): CompiledPath;
249
+
250
+ /** Match a pathname against routes, most specific first. */
251
+ export function matchRoute<T extends { path?: string }>(
252
+ path: string,
253
+ routes: T[],
254
+ ): { route: T; params: Record<string, string> } | null;
255
+
256
+ /** Parse a query string into a null-prototype object. */
257
+ export function parseQuery(search: string): Record<string, string>;
258
+
259
+ /** Reject javascript:, data:, vbscript: and protocol-relative URLs. */
260
+ export function isSafeUrl(url: string): boolean;
package/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // What Framework Server - TypeScript Definitions
2
2
 
3
- import { VNode, VNodeChild, Signal } from './index';
3
+ import { Component, VNode, VNodeChild, Signal } from './index';
4
4
 
5
5
  // --- SSR ---
6
6
 
@@ -10,14 +10,18 @@ export function renderToString(vnode: VNode): string;
10
10
  /** Render VNode tree as async iterator for streaming */
11
11
  export function renderToStream(vnode: VNode): AsyncGenerator<string>;
12
12
 
13
- /** Render a full page with document wrapper */
14
- export function renderPage(vnode: VNode, options?: {
15
- title?: string;
16
- meta?: Record<string, string>;
17
- scripts?: string[];
18
- styles?: string[];
19
- mode?: 'static' | 'server' | 'client' | 'hybrid';
20
- }): string;
13
+ export interface RenderRequestContext {
14
+ params?: Record<string, string>;
15
+ query?: Record<string, string>;
16
+ request?: any;
17
+ [key: string]: any;
18
+ }
19
+
20
+ /** Run a page module's loader, then render it. Returns the body, head and loader data. */
21
+ export function renderPage(
22
+ pageModule: { default: Component<any>; loader?: (ctx: RenderRequestContext) => any } | Component<any>,
23
+ reqCtx?: RenderRequestContext,
24
+ ): Promise<{ body: string; head: string; loaderData: any }>;
21
25
 
22
26
  // --- Page Configuration ---
23
27
 
@@ -44,15 +48,6 @@ export function definePage(config: Partial<PageConfig>): PageConfig;
44
48
 
45
49
  export type IslandMode = 'static' | 'idle' | 'visible' | 'load' | 'media' | 'action';
46
50
 
47
- export const IslandModes: {
48
- STATIC: 'static';
49
- IDLE: 'idle';
50
- VISIBLE: 'visible';
51
- LOAD: 'load';
52
- MEDIA: 'media';
53
- ACTION: 'action';
54
- };
55
-
56
51
  export interface IslandOptions {
57
52
  /** Hydration mode */
58
53
  mode?: IslandMode;
@@ -93,8 +88,8 @@ export interface ActionOptions {
93
88
  revalidate?: string[];
94
89
  }
95
90
 
96
- /** Create a server action */
97
- export function createAction<T extends any[], R>(
91
+ /** Define a server action */
92
+ export function action<T extends any[], R>(
98
93
  fn: (...args: T) => Promise<R>,
99
94
  options?: ActionOptions
100
95
  ): (...args: T) => Promise<R>;