@lolyjs/core 0.2.0-alpha.3 → 0.2.0-alpha.31

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 (46) hide show
  1. package/README.md +1462 -761
  2. package/dist/{bootstrap-BiCQmSkx.d.mts → bootstrap-BfGTMUkj.d.mts} +19 -0
  3. package/dist/{bootstrap-BiCQmSkx.d.ts → bootstrap-BfGTMUkj.d.ts} +19 -0
  4. package/dist/cli.cjs +15909 -2468
  5. package/dist/cli.cjs.map +1 -1
  6. package/dist/cli.js +15932 -2481
  7. package/dist/cli.js.map +1 -1
  8. package/dist/index.cjs +18098 -4160
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.mts +323 -55
  11. package/dist/index.d.ts +323 -55
  12. package/dist/index.js +18216 -4271
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.types-JJ0KjvFU.d.mts +266 -0
  15. package/dist/index.types-JJ0KjvFU.d.ts +266 -0
  16. package/dist/react/cache.cjs +107 -32
  17. package/dist/react/cache.cjs.map +1 -1
  18. package/dist/react/cache.d.mts +29 -21
  19. package/dist/react/cache.d.ts +29 -21
  20. package/dist/react/cache.js +107 -32
  21. package/dist/react/cache.js.map +1 -1
  22. package/dist/react/components.cjs +11 -12
  23. package/dist/react/components.cjs.map +1 -1
  24. package/dist/react/components.js +11 -12
  25. package/dist/react/components.js.map +1 -1
  26. package/dist/react/hooks.cjs +124 -74
  27. package/dist/react/hooks.cjs.map +1 -1
  28. package/dist/react/hooks.d.mts +6 -24
  29. package/dist/react/hooks.d.ts +6 -24
  30. package/dist/react/hooks.js +122 -71
  31. package/dist/react/hooks.js.map +1 -1
  32. package/dist/react/sockets.cjs +5 -6
  33. package/dist/react/sockets.cjs.map +1 -1
  34. package/dist/react/sockets.js +5 -6
  35. package/dist/react/sockets.js.map +1 -1
  36. package/dist/react/themes.cjs +61 -18
  37. package/dist/react/themes.cjs.map +1 -1
  38. package/dist/react/themes.js +63 -20
  39. package/dist/react/themes.js.map +1 -1
  40. package/dist/runtime.cjs +531 -104
  41. package/dist/runtime.cjs.map +1 -1
  42. package/dist/runtime.d.mts +2 -2
  43. package/dist/runtime.d.ts +2 -2
  44. package/dist/runtime.js +531 -104
  45. package/dist/runtime.js.map +1 -1
  46. package/package.json +56 -14
@@ -21,7 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var hooks_exports = {};
22
22
  __export(hooks_exports, {
23
23
  useBroadcastChannel: () => useBroadcastChannel,
24
- usePageProps: () => usePageProps,
25
24
  useRouter: () => useRouter
26
25
  });
27
26
  module.exports = __toCommonJS(hooks_exports);
@@ -30,65 +29,43 @@ module.exports = __toCommonJS(hooks_exports);
30
29
  var import_react = require("react");
31
30
  var useBroadcastChannel = (channelName) => {
32
31
  const [message, setMessage] = (0, import_react.useState)(null);
33
- const channel = new BroadcastChannel(channelName);
32
+ const channelRef = (0, import_react.useRef)(null);
34
33
  (0, import_react.useEffect)(() => {
34
+ if (!channelRef.current && typeof window !== "undefined") {
35
+ channelRef.current = new BroadcastChannel(channelName);
36
+ }
37
+ const channel = channelRef.current;
38
+ if (!channel) return;
35
39
  const handleMessage = (event) => {
36
40
  setMessage(event.data);
37
41
  };
38
42
  channel.onmessage = handleMessage;
39
43
  return () => {
40
- channel.close();
41
- };
42
- }, [channel]);
43
- const sendMessage = (msg) => {
44
- channel.postMessage(msg);
45
- };
46
- return { message, sendMessage };
47
- };
48
-
49
- // modules/react/hooks/usePageProps/index.ts
50
- var import_react2 = require("react");
51
- function usePageProps() {
52
- const [state, setState] = (0, import_react2.useState)(() => {
53
- if (typeof window !== "undefined" && window?.__FW_DATA__) {
54
- const data = window.__FW_DATA__;
55
- return {
56
- params: data.params || {},
57
- props: data.props || {}
58
- };
59
- }
60
- return {
61
- params: {},
62
- props: {}
63
- };
64
- });
65
- (0, import_react2.useEffect)(() => {
66
- const handleDataRefresh = () => {
67
- if (window?.__FW_DATA__) {
68
- const data = window.__FW_DATA__;
69
- setState({
70
- params: data.params || {},
71
- props: data.props || {}
72
- });
44
+ if (channelRef.current) {
45
+ channelRef.current.close();
46
+ channelRef.current = null;
73
47
  }
74
48
  };
75
- window.addEventListener("fw-data-refresh", handleDataRefresh);
76
- return () => {
77
- window.removeEventListener("fw-data-refresh", handleDataRefresh);
78
- };
49
+ }, [channelName]);
50
+ const sendMessage = (0, import_react.useCallback)((msg) => {
51
+ if (channelRef.current) {
52
+ channelRef.current.postMessage(msg);
53
+ }
79
54
  }, []);
80
- return { params: state.params, props: state.props };
81
- }
55
+ return { message, sendMessage };
56
+ };
82
57
 
83
58
  // modules/react/hooks/useRouter/index.ts
84
- var import_react4 = require("react");
59
+ var import_react3 = require("react");
85
60
 
86
61
  // modules/runtime/client/RouterContext.tsx
87
- var import_react3 = require("react");
88
- var RouterContext = (0, import_react3.createContext)(null);
62
+ var import_react2 = require("react");
63
+ var RouterContext = (0, import_react2.createContext)(null);
89
64
 
90
65
  // modules/runtime/client/constants.ts
91
66
  var WINDOW_DATA_KEY = "__FW_DATA__";
67
+ var ROUTER_DATA_KEY = "__LOLY_ROUTER_DATA__";
68
+ var ROUTER_NAVIGATE_KEY = "__LOLY_ROUTER_NAVIGATE__";
92
69
 
93
70
  // modules/runtime/client/window-data.ts
94
71
  function getWindowData() {
@@ -97,94 +74,167 @@ function getWindowData() {
97
74
  }
98
75
  return window[WINDOW_DATA_KEY] ?? null;
99
76
  }
77
+ function getRouterData() {
78
+ if (typeof window === "undefined") {
79
+ return null;
80
+ }
81
+ return window[ROUTER_DATA_KEY] ?? null;
82
+ }
100
83
 
101
84
  // modules/react/hooks/useRouter/index.ts
102
85
  function useRouter() {
103
- const context = (0, import_react4.useContext)(RouterContext);
86
+ const context = (0, import_react3.useContext)(RouterContext);
104
87
  const navigate = context?.navigate;
105
- const [routeData, setRouteData] = (0, import_react4.useState)(() => {
88
+ const navigateRef = (0, import_react3.useRef)(navigate);
89
+ (0, import_react3.useEffect)(() => {
90
+ navigateRef.current = navigate;
91
+ }, [navigate]);
92
+ const [routeData, setRouteData] = (0, import_react3.useState)(() => {
106
93
  if (typeof window === "undefined") {
107
94
  return {
108
95
  pathname: "",
109
96
  query: {},
97
+ searchParams: {},
110
98
  params: {}
111
99
  };
112
100
  }
113
101
  const data = getWindowData();
102
+ const routerData = getRouterData();
103
+ const searchParams = routerData?.searchParams || parseQueryString(window.location.search);
114
104
  return {
115
- pathname: data?.pathname || window.location.pathname,
116
- query: parseQueryString(window.location.search),
117
- params: data?.params || {}
105
+ pathname: routerData?.pathname || data?.pathname || window.location.pathname,
106
+ query: searchParams,
107
+ // For backward compatibility
108
+ searchParams,
109
+ params: routerData?.params || data?.params || {}
118
110
  };
119
111
  });
120
- (0, import_react4.useEffect)(() => {
112
+ (0, import_react3.useEffect)(() => {
121
113
  if (typeof window === "undefined") return;
122
114
  const handleDataRefresh = () => {
123
115
  const data = getWindowData();
116
+ const routerData = getRouterData();
124
117
  const currentPathname = window.location.pathname;
125
118
  const currentSearch = window.location.search;
119
+ const searchParams = routerData?.searchParams || parseQueryString(currentSearch);
126
120
  setRouteData({
127
- pathname: data?.pathname || currentPathname,
128
- query: parseQueryString(currentSearch),
129
- params: data?.params || {}
121
+ pathname: routerData?.pathname || data?.pathname || currentPathname,
122
+ query: searchParams,
123
+ // For backward compatibility
124
+ searchParams,
125
+ params: routerData?.params || data?.params || {}
130
126
  });
131
127
  };
132
128
  window.addEventListener("fw-data-refresh", handleDataRefresh);
129
+ window.addEventListener("fw-router-data-refresh", handleDataRefresh);
133
130
  const handlePopState = () => {
134
131
  handleDataRefresh();
135
132
  };
136
133
  window.addEventListener("popstate", handlePopState);
137
134
  return () => {
138
135
  window.removeEventListener("fw-data-refresh", handleDataRefresh);
136
+ window.removeEventListener("fw-router-data-refresh", handleDataRefresh);
139
137
  window.removeEventListener("popstate", handlePopState);
140
138
  };
141
139
  }, []);
142
- const push = (0, import_react4.useCallback)(
140
+ const push = (0, import_react3.useCallback)(
143
141
  async (url, options) => {
144
142
  const fullUrl = url.startsWith("/") ? url : `/${url}`;
145
- if (!navigate) {
146
- if (typeof window !== "undefined") {
147
- window.location.href = fullUrl;
143
+ const getCurrentNavigate = () => {
144
+ if (navigateRef.current) return navigateRef.current;
145
+ if (navigate) return navigate;
146
+ if (typeof window !== "undefined" && window[ROUTER_NAVIGATE_KEY]) {
147
+ return window[ROUTER_NAVIGATE_KEY];
148
148
  }
149
+ return null;
150
+ };
151
+ let currentNavigate = getCurrentNavigate();
152
+ if (typeof window === "undefined") {
153
+ return;
154
+ }
155
+ if (!currentNavigate) {
156
+ for (let i = 0; i < 10; i++) {
157
+ await new Promise((resolve) => setTimeout(resolve, 10));
158
+ currentNavigate = getCurrentNavigate();
159
+ if (currentNavigate) break;
160
+ }
161
+ }
162
+ if (!currentNavigate) {
163
+ window.location.href = fullUrl;
149
164
  return;
150
165
  }
151
- if (typeof window !== "undefined") {
152
- window.history.pushState({}, "", fullUrl);
166
+ const currentUrl = window.location.pathname + window.location.search;
167
+ if (fullUrl === currentUrl) {
168
+ return;
153
169
  }
154
- await navigate(fullUrl, options);
170
+ window.history.pushState({}, "", fullUrl);
171
+ await currentNavigate(fullUrl, options);
155
172
  },
156
173
  [navigate]
174
+ // Include navigate in dependencies so it updates when context becomes available
157
175
  );
158
- const replace = (0, import_react4.useCallback)(
176
+ const replace = (0, import_react3.useCallback)(
159
177
  async (url, options) => {
160
178
  const fullUrl = url.startsWith("/") ? url : `/${url}`;
161
- if (!navigate) {
162
- if (typeof window !== "undefined") {
163
- window.location.replace(fullUrl);
179
+ const getCurrentNavigate = () => {
180
+ if (navigateRef.current) return navigateRef.current;
181
+ if (navigate) return navigate;
182
+ if (typeof window !== "undefined" && window[ROUTER_NAVIGATE_KEY]) {
183
+ return window[ROUTER_NAVIGATE_KEY];
164
184
  }
185
+ return null;
186
+ };
187
+ let currentNavigate = getCurrentNavigate();
188
+ if (typeof window === "undefined") {
165
189
  return;
166
190
  }
167
- if (typeof window !== "undefined") {
168
- window.history.replaceState({}, "", fullUrl);
191
+ if (!currentNavigate) {
192
+ for (let i = 0; i < 10; i++) {
193
+ await new Promise((resolve) => setTimeout(resolve, 10));
194
+ currentNavigate = getCurrentNavigate();
195
+ if (currentNavigate) break;
196
+ }
197
+ }
198
+ if (!currentNavigate) {
199
+ window.location.replace(fullUrl);
200
+ return;
169
201
  }
170
- await navigate(fullUrl, options);
202
+ window.history.replaceState({}, "", fullUrl);
203
+ await currentNavigate(fullUrl, options);
171
204
  },
172
205
  [navigate]
173
206
  );
174
- const back = (0, import_react4.useCallback)(() => {
207
+ const back = (0, import_react3.useCallback)(() => {
175
208
  if (typeof window !== "undefined") {
176
209
  window.history.back();
177
210
  }
178
211
  }, []);
179
- const refresh = (0, import_react4.useCallback)(async () => {
212
+ const refresh = (0, import_react3.useCallback)(async () => {
180
213
  const currentUrl = typeof window !== "undefined" ? window.location.pathname + window.location.search : routeData.pathname;
181
- if (!navigate) {
182
- if (typeof window !== "undefined") {
183
- window.location.reload();
214
+ const getCurrentNavigate = () => {
215
+ if (navigateRef.current) return navigateRef.current;
216
+ if (navigate) return navigate;
217
+ if (typeof window !== "undefined" && window[ROUTER_NAVIGATE_KEY]) {
218
+ return window[ROUTER_NAVIGATE_KEY];
184
219
  }
220
+ return null;
221
+ };
222
+ let currentNavigate = getCurrentNavigate();
223
+ if (typeof window === "undefined") {
224
+ return;
225
+ }
226
+ if (!currentNavigate) {
227
+ for (let i = 0; i < 10; i++) {
228
+ await new Promise((resolve) => setTimeout(resolve, 10));
229
+ currentNavigate = getCurrentNavigate();
230
+ if (currentNavigate) break;
231
+ }
232
+ }
233
+ if (!currentNavigate) {
234
+ window.location.reload();
185
235
  return;
186
236
  }
187
- await navigate(currentUrl, { revalidate: true });
237
+ await currentNavigate(currentUrl, { revalidate: true });
188
238
  }, [navigate, routeData.pathname]);
189
239
  return {
190
240
  push,
@@ -193,6 +243,7 @@ function useRouter() {
193
243
  refresh,
194
244
  pathname: routeData.pathname,
195
245
  query: routeData.query,
246
+ searchParams: routeData.searchParams,
196
247
  params: routeData.params
197
248
  };
198
249
  }
@@ -212,7 +263,6 @@ function parseQueryString(search) {
212
263
  // Annotate the CommonJS export names for ESM import in node:
213
264
  0 && (module.exports = {
214
265
  useBroadcastChannel,
215
- usePageProps,
216
266
  useRouter
217
267
  });
218
268
  //# sourceMappingURL=hooks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../modules/react/hooks/index.ts","../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/usePageProps/index.ts","../../modules/react/hooks/useRouter/index.ts","../../modules/runtime/client/RouterContext.tsx","../../modules/runtime/client/constants.ts","../../modules/runtime/client/window-data.ts"],"sourcesContent":["export { useBroadcastChannel } from \"./useBroadcastChannel\";\r\nexport { usePageProps } from \"./usePageProps\";\r\nexport { useRouter } from \"./useRouter\";\r\nexport type { Router } from \"./useRouter\";\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channel = new BroadcastChannel(channelName);\r\n\r\n useEffect(() => {\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n channel.close();\r\n };\r\n }, [channel]);\r\n\r\n const sendMessage = (msg: unknown) => {\r\n channel.postMessage(msg);\r\n };\r\n\r\n return { message, sendMessage };\r\n};\r\n","import React, { useEffect, useState } from \"react\";\r\n\r\n/**\r\n * Hook to access page props and route parameters.\r\n *\r\n * Reads initial data from window.__FW_DATA__ set during SSR.\r\n * Automatically updates when `revalidate()` is called.\r\n *\r\n * @template P - Type for page props (default: any)\r\n * @template T - Type for route params (default: any)\r\n * @returns Object containing params and props\r\n *\r\n * @example\r\n * // With props type only\r\n * const { props } = usePageProps<{ title: string }>();\r\n *\r\n * @example\r\n * // With both props and params types\r\n * const { props, params } = usePageProps<{ title: string }, { id: string }>();\r\n */\r\nexport function usePageProps<P = any, T = any>(): { params: T, props: P } {\r\n const [state, setState] = useState<{ params: T, props: P }>(() => {\r\n // Initialize with current data if available\r\n if (typeof window !== \"undefined\" && (window as any)?.__FW_DATA__) {\r\n const data = (window as any).__FW_DATA__;\r\n return {\r\n params: data.params || {} as T,\r\n props: data.props || {} as P,\r\n };\r\n }\r\n return {\r\n params: {} as T,\r\n props: {} as P,\r\n };\r\n });\r\n\r\n useEffect(() => {\r\n // Listen for data refresh events (from revalidate() or navigation)\r\n const handleDataRefresh = () => {\r\n if ((window as any)?.__FW_DATA__) {\r\n const data = (window as any).__FW_DATA__;\r\n setState({\r\n params: data.params || {} as T,\r\n props: data.props || {} as P,\r\n });\r\n }\r\n };\r\n\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n };\r\n }, []);\r\n\r\n return { params: state.params as T, props: state.props as P };\r\n};\r\n","import { useState, useEffect, useCallback, useContext } from \"react\";\r\nimport { RouterContext } from \"../../../runtime/client/RouterContext\";\r\nimport { getWindowData } from \"../../../runtime/client/window-data\";\r\n\r\nexport interface Router {\r\n /**\r\n * Navigate to a new route.\r\n * @param url - The URL to navigate to (e.g., \"/about\" or \"/blog/[slug]\" with params)\r\n * @param options - Navigation options\r\n */\r\n push: (url: string, options?: { revalidate?: boolean }) => Promise<void>;\r\n \r\n /**\r\n * Replace the current route without adding to history.\r\n * @param url - The URL to navigate to\r\n * @param options - Navigation options\r\n */\r\n replace: (url: string, options?: { revalidate?: boolean }) => Promise<void>;\r\n \r\n /**\r\n * Go back in the browser history.\r\n */\r\n back: () => void;\r\n \r\n /**\r\n * Refresh the current route data by revalidating.\r\n */\r\n refresh: () => Promise<void>;\r\n \r\n /**\r\n * Current pathname (e.g., \"/blog/my-post\")\r\n */\r\n pathname: string;\r\n \r\n /**\r\n * Query parameters from the URL (e.g., ?id=123&name=test)\r\n */\r\n query: Record<string, string>;\r\n \r\n /**\r\n * Dynamic route parameters (e.g., { slug: \"my-post\" } for /blog/[slug])\r\n */\r\n params: Record<string, string>;\r\n}\r\n\r\n/**\r\n * Hook to access router functionality and current route information.\r\n * \r\n * Provides methods to navigate programmatically and access current route data.\r\n * \r\n * @returns Router object with navigation methods and route information\r\n * \r\n * @example\r\n * ```tsx\r\n * function MyComponent() {\r\n * const router = useRouter();\r\n * \r\n * const handleClick = () => {\r\n * router.push(\"/about\");\r\n * };\r\n * \r\n * return (\r\n * <div>\r\n * <p>Current path: {router.pathname}</p>\r\n * <p>Params: {JSON.stringify(router.params)}</p>\r\n * <button onClick={handleClick}>Go to About</button>\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n * \r\n * @example\r\n * ```tsx\r\n * // Navigate with dynamic params\r\n * router.push(\"/blog/my-post\");\r\n * \r\n * // Replace current route\r\n * router.replace(\"/login\");\r\n * \r\n * // Refresh current route data\r\n * await router.refresh();\r\n * ```\r\n */\r\nexport function useRouter(): Router {\r\n // Try to get context, but don't throw if it's not available (SSR)\r\n const context = useContext(RouterContext);\r\n const navigate = context?.navigate;\r\n \r\n const [routeData, setRouteData] = useState(() => {\r\n // During SSR, return empty/default values\r\n if (typeof window === \"undefined\") {\r\n return {\r\n pathname: \"\",\r\n query: {},\r\n params: {},\r\n };\r\n }\r\n \r\n // On client, get data from window\r\n const data = getWindowData();\r\n return {\r\n pathname: data?.pathname || window.location.pathname,\r\n query: parseQueryString(window.location.search),\r\n params: data?.params || {},\r\n };\r\n });\r\n\r\n // Listen for route changes (only on client)\r\n useEffect(() => {\r\n if (typeof window === \"undefined\") return;\r\n \r\n const handleDataRefresh = () => {\r\n const data = getWindowData();\r\n const currentPathname = window.location.pathname;\r\n const currentSearch = window.location.search;\r\n \r\n setRouteData({\r\n pathname: data?.pathname || currentPathname,\r\n query: parseQueryString(currentSearch),\r\n params: data?.params || {},\r\n });\r\n };\r\n\r\n // Listen for navigation events\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n \r\n // Also listen for popstate (browser back/forward)\r\n const handlePopState = () => {\r\n handleDataRefresh();\r\n };\r\n window.addEventListener(\"popstate\", handlePopState);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n window.removeEventListener(\"popstate\", handlePopState);\r\n };\r\n }, []);\r\n\r\n const push = useCallback(\r\n async (url: string, options?: { revalidate?: boolean }) => {\r\n const fullUrl = url.startsWith(\"/\") ? url : `/${url}`;\r\n \r\n // During SSR or if context is not available, use window.location\r\n if (!navigate) {\r\n if (typeof window !== \"undefined\") {\r\n window.location.href = fullUrl;\r\n }\r\n return;\r\n }\r\n \r\n if (typeof window !== \"undefined\") {\r\n window.history.pushState({}, \"\", fullUrl);\r\n }\r\n await navigate(fullUrl, options);\r\n },\r\n [navigate]\r\n );\r\n\r\n const replace = useCallback(\r\n async (url: string, options?: { revalidate?: boolean }) => {\r\n const fullUrl = url.startsWith(\"/\") ? url : `/${url}`;\r\n \r\n // During SSR or if context is not available, use window.location\r\n if (!navigate) {\r\n if (typeof window !== \"undefined\") {\r\n window.location.replace(fullUrl);\r\n }\r\n return;\r\n }\r\n \r\n if (typeof window !== \"undefined\") {\r\n window.history.replaceState({}, \"\", fullUrl);\r\n }\r\n await navigate(fullUrl, options);\r\n },\r\n [navigate]\r\n );\r\n\r\n const back = useCallback(() => {\r\n if (typeof window !== \"undefined\") {\r\n window.history.back();\r\n }\r\n }, []);\r\n\r\n const refresh = useCallback(async () => {\r\n const currentUrl = typeof window !== \"undefined\" \r\n ? window.location.pathname + window.location.search \r\n : routeData.pathname;\r\n \r\n // During SSR or if context is not available, reload the page\r\n if (!navigate) {\r\n if (typeof window !== \"undefined\") {\r\n window.location.reload();\r\n }\r\n return;\r\n }\r\n \r\n await navigate(currentUrl, { revalidate: true });\r\n }, [navigate, routeData.pathname]);\r\n\r\n return {\r\n push,\r\n replace,\r\n back,\r\n refresh,\r\n pathname: routeData.pathname,\r\n query: routeData.query,\r\n params: routeData.params,\r\n };\r\n}\r\n\r\n/**\r\n * Parse query string into an object.\r\n * @param search - Query string (e.g., \"?id=123&name=test\")\r\n * @returns Object with query parameters\r\n */\r\nfunction parseQueryString(search: string): Record<string, string> {\r\n const params: Record<string, string> = {};\r\n if (!search || search.length === 0) return params;\r\n \r\n const queryString = search.startsWith(\"?\") ? search.slice(1) : search;\r\n const pairs = queryString.split(\"&\");\r\n \r\n for (const pair of pairs) {\r\n const [key, value] = pair.split(\"=\");\r\n if (key) {\r\n params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : \"\";\r\n }\r\n }\r\n \r\n return params;\r\n}\r\n","import { createContext, useContext } from \"react\";\r\n\r\nexport type NavigateFunction = (\r\n url: string,\r\n options?: { revalidate?: boolean; replace?: boolean }\r\n) => Promise<void>;\r\n\r\nexport interface RouterContextValue {\r\n navigate: NavigateFunction;\r\n}\r\n\r\nexport const RouterContext = createContext<RouterContextValue | null>(null);\r\n\r\nexport function useRouterContext(): RouterContextValue {\r\n const context = useContext(RouterContext);\r\n if (!context) {\r\n throw new Error(\r\n \"useRouter must be used within a RouterProvider. Make sure you're using it inside a Loly app.\"\r\n );\r\n }\r\n return context;\r\n}\r\n","// Client-side constants (hardcoded to avoid alias resolution issues in Rspack)\r\nexport const WINDOW_DATA_KEY = \"__FW_DATA__\";\r\nexport const APP_CONTAINER_ID = \"__app\";\r\n\r\n","import { WINDOW_DATA_KEY } from \"./constants\";\r\nimport type { InitialData } from \"./types\";\r\n\r\nexport function getWindowData(): InitialData | null {\r\n if (typeof window === \"undefined\") {\r\n return null;\r\n }\r\n return ((window as any)[WINDOW_DATA_KEY] as InitialData | undefined) ?? null;\r\n}\r\n\r\nexport function setWindowData(data: InitialData): void {\r\n (window as any)[WINDOW_DATA_KEY] = data;\r\n \r\n // Dispatch event for components to listen to (e.g., usePageProps, ThemeProvider)\r\n // This ensures components update when navigating in SPA mode\r\n if (typeof window !== \"undefined\") {\r\n window.dispatchEvent(\r\n new CustomEvent(\"fw-data-refresh\", {\r\n detail: { data },\r\n })\r\n );\r\n }\r\n}\r\n\r\nexport function getCurrentTheme(): string | null {\r\n return getWindowData()?.theme ?? null;\r\n}\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA2C;AAEpC,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,IAAI;AAC3C,QAAM,UAAU,IAAI,iBAAiB,WAAW;AAEhD,8BAAU,MAAM;AACd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,cAAQ,MAAM;AAAA,IAChB;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,cAAc,CAAC,QAAiB;AACpC,YAAQ,YAAY,GAAG;AAAA,EACzB;AAEA,SAAO,EAAE,SAAS,YAAY;AAChC;;;ACxBA,IAAAA,gBAA2C;AAoBpC,SAAS,eAA0D;AACxE,QAAM,CAAC,OAAO,QAAQ,QAAI,wBAAkC,MAAM;AAEhE,QAAI,OAAO,WAAW,eAAgB,QAAgB,aAAa;AACjE,YAAM,OAAQ,OAAe;AAC7B,aAAO;AAAA,QACL,QAAQ,KAAK,UAAU,CAAC;AAAA,QACxB,OAAO,KAAK,SAAS,CAAC;AAAA,MACxB;AAAA,IACF;AACA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,OAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AAED,+BAAU,MAAM;AAEd,UAAM,oBAAoB,MAAM;AAC9B,UAAK,QAAgB,aAAa;AAChC,cAAM,OAAQ,OAAe;AAC7B,iBAAS;AAAA,UACP,QAAQ,KAAK,UAAU,CAAC;AAAA,UACxB,OAAO,KAAK,SAAS,CAAC;AAAA,QACxB,CAAC;AAAA,MACH;AAAA,I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CAAC,UAAU;AACb,UAAI,OAAO,WAAW,aAAa;AACjC,eAAO,SAAS,OAAO;AAAA,MACzB;AACA;AAAA,IACF;AAEA,UAAM,SAAS,YAAY,EAAE,YAAY,KAAK,CAAC;AAAA,EACjD,GAAG,CAAC,UAAU,UAAU,QAAQ,CAAC;AAEjC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,UAAU;AAAA,IACpB,OAAO,UAAU;AAAA,IACjB,QAAQ,UAAU;AAAA,EACpB;AACF;AAOA,SAAS,iBAAiB,QAAwC;AAChE,QAAM,SAAiC,CAAC;AACxC,MAAI,CAAC,UAAU,OAAO,WAAW,EAAG,QAAO;AAE3C,QAAM,cAAc,OAAO,WAAW,GAAG,IAAI,OAAO,MAAM,CAAC,IAAI;AAC/D,QAAM,QAAQ,YAAY,MAAM,GAAG;AAEnC,aAAW,QAAQ,OAAO;AACxB,UAAM,CAAC,KAAK,KAAK,IAAI,KAAK,MAAM,GAAG;AACnC,QAAI,KAAK;AACP,aAAO,mBAAmB,GAAG,CAAC,IAAI,QAAQ,mBAAmB,KAAK,IAAI;AAAA,IACxE;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_react","import_react","import_react"]}
1
+ {"version":3,"sources":["../../modules/react/hooks/index.ts","../../modules/react/hooks/useBroadcastChannel/index.tsx","../../modules/react/hooks/useRouter/index.ts","../../modules/runtime/client/RouterContext.tsx","../../modules/runtime/client/constants.ts","../../modules/runtime/client/window-data.ts"],"sourcesContent":["export { useBroadcastChannel } from \"./useBroadcastChannel\";\r\nexport { useRouter } from \"./useRouter\";\r\nexport type { Router } from \"./useRouter\";\r\n","import React, { useEffect, useState, useRef, useCallback } from \"react\";\r\n\r\nexport const useBroadcastChannel = (channelName: string) => {\r\n const [message, setMessage] = useState(null);\r\n const channelRef = useRef<BroadcastChannel | null>(null);\r\n\r\n useEffect(() => {\r\n // Create channel only once, inside useEffect\r\n if (!channelRef.current && typeof window !== \"undefined\") {\r\n channelRef.current = new BroadcastChannel(channelName);\r\n }\r\n\r\n const channel = channelRef.current;\r\n if (!channel) return;\r\n\r\n const handleMessage = (event: MessageEvent) => {\r\n setMessage(event.data);\r\n };\r\n\r\n channel.onmessage = handleMessage;\r\n\r\n // Clean up the channel when the component unmounts\r\n return () => {\r\n if (channelRef.current) {\r\n channelRef.current.close();\r\n channelRef.current = null;\r\n }\r\n };\r\n }, [channelName]);\r\n\r\n const sendMessage = useCallback((msg: unknown) => {\r\n if (channelRef.current) {\r\n channelRef.current.postMessage(msg);\r\n }\r\n }, []);\r\n\r\n return { message, sendMessage };\r\n};\r\n","import { useState, useEffect, useCallback, useContext, useRef } from \"react\";\r\nimport { RouterContext } from \"../../../runtime/client/RouterContext\";\r\nimport { getWindowData, getRouterData } from \"../../../runtime/client/window-data\";\r\nimport { ROUTER_NAVIGATE_KEY } from \"../../../runtime/client/constants\";\r\n\r\nexport interface Router {\r\n /**\r\n * Navigate to a new route.\r\n * @param url - The URL to navigate to (e.g., \"/about\" or \"/blog/[slug]\" with params)\r\n * @param options - Navigation options\r\n */\r\n push: (url: string, options?: { revalidate?: boolean }) => Promise<void>;\r\n \r\n /**\r\n * Replace the current route without adding to history.\r\n * @param url - The URL to navigate to\r\n * @param options - Navigation options\r\n */\r\n replace: (url: string, options?: { revalidate?: boolean }) => Promise<void>;\r\n \r\n /**\r\n * Go back in the browser history.\r\n */\r\n back: () => void;\r\n \r\n /**\r\n * Refresh the current route data by revalidating.\r\n */\r\n refresh: () => Promise<void>;\r\n \r\n /**\r\n * Current pathname (e.g., \"/blog/my-post\")\r\n */\r\n pathname: string;\r\n \r\n /**\r\n * Query parameters from the URL (e.g., ?id=123&name=test)\r\n * Alias for searchParams for backward compatibility\r\n */\r\n query: Record<string, string>;\r\n \r\n /**\r\n * Search parameters from the URL (e.g., ?id=123&name=test)\r\n */\r\n searchParams: Record<string, unknown>;\r\n \r\n /**\r\n * Dynamic route parameters (e.g., { slug: \"my-post\" } for /blog/[slug])\r\n */\r\n params: Record<string, string>;\r\n}\r\n\r\n/**\r\n * Hook to access router functionality and current route information.\r\n * \r\n * Provides methods to navigate programmatically and access current route data.\r\n * \r\n * @returns Router object with navigation methods and route information\r\n * \r\n * @example\r\n * ```tsx\r\n * function MyComponent() {\r\n * const router = useRouter();\r\n * \r\n * const handleClick = () => {\r\n * router.push(\"/about\");\r\n * };\r\n * \r\n * return (\r\n * <div>\r\n * <p>Current path: {router.pathname}</p>\r\n * <p>Params: {JSON.stringify(router.params)}</p>\r\n * <button onClick={handleClick}>Go to About</button>\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n * \r\n * @example\r\n * ```tsx\r\n * // Navigate with dynamic params\r\n * router.push(\"/blog/my-post\");\r\n * \r\n * // Replace current route\r\n * router.replace(\"/login\");\r\n * \r\n * // Refresh current route data\r\n * await router.refresh();\r\n * ```\r\n */\r\nexport function useRouter(): Router {\r\n // Try to get context, but don't throw if it's not available (SSR)\r\n const context = useContext(RouterContext);\r\n const navigate = context?.navigate;\r\n \r\n // Use a ref to store navigate so we can access it in callbacks even if context updates\r\n // Initialize with current navigate value\r\n const navigateRef = useRef(navigate);\r\n \r\n // Update ref when navigate changes (this ensures we always have the latest value)\r\n useEffect(() => {\r\n navigateRef.current = navigate;\r\n }, [navigate]);\r\n \r\n const [routeData, setRouteData] = useState(() => {\r\n // During SSR, return empty/default values\r\n if (typeof window === \"undefined\") {\r\n return {\r\n pathname: \"\",\r\n query: {},\r\n searchParams: {},\r\n params: {},\r\n };\r\n }\r\n \r\n // On client, get data from window\r\n const data = getWindowData();\r\n const routerData = getRouterData();\r\n \r\n // Parse search params from URL if routerData is not available\r\n const searchParams = routerData?.searchParams || parseQueryString(window.location.search);\r\n \r\n return {\r\n pathname: routerData?.pathname || data?.pathname || window.location.pathname,\r\n query: searchParams as Record<string, string>, // For backward compatibility\r\n searchParams: searchParams,\r\n params: routerData?.params || data?.params || {},\r\n };\r\n });\r\n\r\n // Listen for route changes (only on client)\r\n useEffect(() => {\r\n if (typeof window === \"undefined\") return;\r\n \r\n const handleDataRefresh = () => {\r\n const data = getWindowData();\r\n const routerData = getRouterData();\r\n const currentPathname = window.location.pathname;\r\n const currentSearch = window.location.search;\r\n \r\n const searchParams = routerData?.searchParams || parseQueryString(currentSearch);\r\n \r\n setRouteData({\r\n pathname: routerData?.pathname || data?.pathname || currentPathname,\r\n query: searchParams as Record<string, string>, // For backward compatibility\r\n searchParams: searchParams,\r\n params: routerData?.params || data?.params || {},\r\n });\r\n };\r\n\r\n // Listen for navigation events\r\n window.addEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n window.addEventListener(\"fw-router-data-refresh\", handleDataRefresh);\r\n \r\n // Also listen for popstate (browser back/forward)\r\n const handlePopState = () => {\r\n handleDataRefresh();\r\n };\r\n window.addEventListener(\"popstate\", handlePopState);\r\n\r\n return () => {\r\n window.removeEventListener(\"fw-data-refresh\", handleDataRefresh);\r\n window.removeEventListener(\"fw-router-data-refresh\", handleDataRefresh);\r\n window.removeEventListener(\"popstate\", handlePopState);\r\n };\r\n }, []);\r\n\r\n const push = useCallback(\r\n async (url: string, options?: { revalidate?: boolean }) => {\r\n const fullUrl = url.startsWith(\"/\") ? url : `/${url}`;\r\n \r\n /**\r\n * SOLUTION: Multi-source navigate function resolution\r\n * \r\n * During React hydration, RouterContext may not be available immediately.\r\n * We try three sources in order:\r\n * 1. navigateRef.current - Most up-to-date, updated via useEffect\r\n * 2. navigate from context - Direct context access\r\n * 3. window.__LOLY_ROUTER_NAVIGATE__ - Global fallback exposed by AppShell\r\n * \r\n * This ensures SPA navigation works even during hydration timing issues.\r\n */\r\n const getCurrentNavigate = () => {\r\n if (navigateRef.current) return navigateRef.current;\r\n if (navigate) return navigate;\r\n if (typeof window !== \"undefined\" && (window as any)[ROUTER_NAVIGATE_KEY]) {\r\n return (window as any)[ROUTER_NAVIGATE_KEY];\r\n }\r\n return null;\r\n };\r\n \r\n let currentNavigate = getCurrentNavigate();\r\n \r\n if (typeof window === \"undefined\") {\r\n return; // SSR\r\n }\r\n \r\n // Wait for context during hydration (up to 100ms)\r\n if (!currentNavigate) {\r\n for (let i = 0; i < 10; i++) {\r\n await new Promise(resolve => setTimeout(resolve, 10));\r\n currentNavigate = getCurrentNavigate();\r\n if (currentNavigate) break;\r\n }\r\n }\r\n \r\n // Final fallback: full page reload if navigate is still unavailable\r\n if (!currentNavigate) {\r\n window.location.href = fullUrl;\r\n return;\r\n }\r\n \r\n // Check if we're already on this URL (same as link handler)\r\n const currentUrl = window.location.pathname + window.location.search;\r\n if (fullUrl === currentUrl) {\r\n return; // Already on this route, no need to navigate\r\n }\r\n \r\n // Update URL in browser history (same as link handler does)\r\n // This is done BEFORE navigation to match link behavior\r\n window.history.pushState({}, \"\", fullUrl);\r\n \r\n // Navigate using SPA navigation (same as link handler)\r\n // If navigation fails, navigate() will handle the reload internally\r\n await currentNavigate(fullUrl, options);\r\n },\r\n [navigate] // Include navigate in dependencies so it updates when context becomes available\r\n );\r\n\r\n const replace = useCallback(\r\n async (url: string, options?: { revalidate?: boolean }) => {\r\n const fullUrl = url.startsWith(\"/\") ? url : `/${url}`;\r\n \r\n const getCurrentNavigate = () => {\r\n if (navigateRef.current) return navigateRef.current;\r\n if (navigate) return navigate;\r\n if (typeof window !== \"undefined\" && (window as any)[ROUTER_NAVIGATE_KEY]) {\r\n return (window as any)[ROUTER_NAVIGATE_KEY];\r\n }\r\n return null;\r\n };\r\n \r\n let currentNavigate = getCurrentNavigate();\r\n \r\n if (typeof window === \"undefined\") {\r\n return;\r\n }\r\n \r\n if (!currentNavigate) {\r\n for (let i = 0; i < 10; i++) {\r\n await new Promise(resolve => setTimeout(resolve, 10));\r\n currentNavigate = getCurrentNavigate();\r\n if (currentNavigate) break;\r\n }\r\n }\r\n \r\n if (!currentNavigate) {\r\n window.location.replace(fullUrl);\r\n return;\r\n }\r\n \r\n // Update URL in browser history using replace (doesn't add to history)\r\n window.history.replaceState({}, \"\", fullUrl);\r\n \r\n // Navigate using SPA navigation\r\n await currentNavigate(fullUrl, options);\r\n },\r\n [navigate]\r\n );\r\n\r\n const back = useCallback(() => {\r\n if (typeof window !== \"undefined\") {\r\n window.history.back();\r\n }\r\n }, []);\r\n\r\n const refresh = useCallback(async () => {\r\n const currentUrl = typeof window !== \"undefined\" \r\n ? window.location.pathname + window.location.search \r\n : routeData.pathname;\r\n \r\n const getCurrentNavigate = () => {\r\n if (navigateRef.current) return navigateRef.current;\r\n if (navigate) return navigate;\r\n if (typeof window !== \"undefined\" && (window as any)[ROUTER_NAVIGATE_KEY]) {\r\n return (window as any)[ROUTER_NAVIGATE_KEY];\r\n }\r\n return null;\r\n };\r\n \r\n let currentNavigate = getCurrentNavigate();\r\n \r\n if (typeof window === \"undefined\") {\r\n return;\r\n }\r\n \r\n if (!currentNavigate) {\r\n for (let i = 0; i < 10; i++) {\r\n await new Promise(resolve => setTimeout(resolve, 10));\r\n currentNavigate = getCurrentNavigate();\r\n if (currentNavigate) break;\r\n }\r\n }\r\n \r\n if (!currentNavigate) {\r\n window.location.reload();\r\n return;\r\n }\r\n \r\n await currentNavigate(currentUrl, { revalidate: true });\r\n }, [navigate, routeData.pathname]);\r\n\r\n return {\r\n push,\r\n replace,\r\n back,\r\n refresh,\r\n pathname: routeData.pathname,\r\n query: routeData.query,\r\n searchParams: routeData.searchParams,\r\n params: routeData.params,\r\n };\r\n}\r\n\r\n/**\r\n * Parse query string into an object.\r\n * @param search - Query string (e.g., \"?id=123&name=test\")\r\n * @returns Object with query parameters\r\n */\r\nfunction parseQueryString(search: string): Record<string, string> {\r\n const params: Record<string, string> = {};\r\n if (!search || search.length === 0) return params;\r\n \r\n const queryString = search.startsWith(\"?\") ? search.slice(1) : search;\r\n const pairs = queryString.split(\"&\");\r\n \r\n for (const pair of pairs) {\r\n const [key, value] = pair.split(\"=\");\r\n if (key) {\r\n params[decodeURIComponent(key)] = value ? decodeURIComponent(value) : \"\";\r\n }\r\n }\r\n \r\n return params;\r\n}\r\n","import { createContext, useContext } from \"react\";\r\n\r\nexport type NavigateFunction = (\r\n url: string,\r\n options?: { revalidate?: boolean; replace?: boolean }\r\n) => Promise<void>;\r\n\r\nexport interface RouterContextValue {\r\n navigate: NavigateFunction;\r\n}\r\n\r\nexport const RouterContext = createContext<RouterContextValue | null>(null);\r\n\r\nexport function useRouterContext(): RouterContextValue {\r\n const context = useContext(RouterContext);\r\n if (!context) {\r\n throw new Error(\r\n \"useRouter must be used within a RouterProvider. Make sure you're using it inside a Loly app.\"\r\n );\r\n }\r\n return context;\r\n}\r\n","// Client-side constants (hardcoded to avoid alias resolution issues in Rspack)\r\nexport const WINDOW_DATA_KEY = \"__FW_DATA__\";\r\nexport const ROUTER_DATA_KEY = \"__LOLY_ROUTER_DATA__\";\r\nexport const APP_CONTAINER_ID = \"__app\";\r\n// Global key for navigate function fallback (exposed by AppShell for hydration timing issues)\r\nexport const ROUTER_NAVIGATE_KEY = \"__LOLY_ROUTER_NAVIGATE__\";\r\n\r\n","import { WINDOW_DATA_KEY, ROUTER_DATA_KEY } from \"./constants\";\r\nimport type { InitialData, RouterData } from \"./types\";\r\n\r\nconst LAYOUT_PROPS_KEY = \"__FW_LAYOUT_PROPS__\";\r\n\r\nexport function getWindowData(): InitialData | null {\r\n if (typeof window === \"undefined\") {\r\n return null;\r\n }\r\n return (window[WINDOW_DATA_KEY] as InitialData | undefined) ?? null;\r\n}\r\n\r\n/**\r\n * Gets preserved layout props from window storage.\r\n * Layout props are preserved across SPA navigations when layout hooks are skipped.\r\n */\r\nexport function getPreservedLayoutProps(): Record<string, any> | null {\r\n if (typeof window === \"undefined\") {\r\n return null;\r\n }\r\n return ((window as any)[LAYOUT_PROPS_KEY] as Record<string, any> | undefined) ?? null;\r\n}\r\n\r\n/**\r\n * Sets preserved layout props in window storage.\r\n * These props are used when layout hooks are skipped in SPA navigation.\r\n */\r\nexport function setPreservedLayoutProps(props: Record<string, any> | null): void {\r\n if (typeof window === \"undefined\") {\r\n return;\r\n }\r\n if (props === null) {\r\n delete (window as any)[LAYOUT_PROPS_KEY];\r\n } else {\r\n (window as any)[LAYOUT_PROPS_KEY] = props;\r\n }\r\n}\r\n\r\nexport function getRouterData(): RouterData | null {\r\n if (typeof window === \"undefined\") {\r\n return null;\r\n }\r\n return (window[ROUTER_DATA_KEY] as RouterData | undefined) ?? null;\r\n}\r\n\r\nexport function setWindowData(data: InitialData): void {\r\n window[WINDOW_DATA_KEY] = data;\r\n \r\n // Dispatch event for components to listen to (e.g. ThemeProvider)\r\n // This ensures components update when navigating in SPA mode\r\n if (typeof window !== \"undefined\") {\r\n window.dispatchEvent(\r\n new CustomEvent(\"fw-data-refresh\", {\r\n detail: { data },\r\n })\r\n );\r\n }\r\n}\r\n\r\nexport function setRouterData(data: RouterData): void {\r\n window[ROUTER_DATA_KEY] = data;\r\n \r\n // Dispatch event for router data updates\r\n if (typeof window !== \"undefined\") {\r\n window.dispatchEvent(\r\n new CustomEvent(\"fw-router-data-refresh\", {\r\n detail: { data },\r\n })\r\n );\r\n }\r\n}\r\n\r\nexport function getCurrentTheme(): string | null {\r\n return getWindowData()?.theme ?? null;\r\n}\r\n\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAgE;AAEzD,IAAM,sBAAsB,CAAC,gBAAwB;AAC1D,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,IAAI;AAC3C,QAAM,iBAAa,qBAAgC,IAAI;AAEvD,8BAAU,MAAM;AAEd,QAAI,CAAC,WAAW,WAAW,OAAO,WAAW,aAAa;AACxD,iBAAW,UAAU,IAAI,iBAAiB,WAAW;AAAA,IACvD;AAEA,UAAM,UAAU,WAAW;AAC3B,QAAI,CAAC,QAAS;AAEd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,iBAAW,MAAM,IAAI;AAAA,IACvB;AAEA,YAAQ,YAAY;AAGpB,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,mBAAW,QAAQ,MAAM;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C/D,QAAM,QAAQ,YAAY,MAAM,GAAG;AAEnC,aAAW,QAAQ,OAAO;AACxB,UAAM,CAAC,KAAK,KAAK,IAAI,KAAK,MAAM,GAAG;AACnC,QAAI,KAAK;AACP,aAAO,mBAAmB,GAAG,CAAC,IAAI,QAAQ,mBAAmB,KAAK,IAAI;AAAA,IACxE;AAAA,EACF;AAEA,SAAO;AACT;","names":["import_react","import_react"]}
@@ -3,29 +3,6 @@ declare const useBroadcastChannel: (channelName: string) => {
3
3
  sendMessage: (msg: unknown) => void;
4
4
  };
5
5
 
6
- /**
7
- * Hook to access page props and route parameters.
8
- *
9
- * Reads initial data from window.__FW_DATA__ set during SSR.
10
- * Automatically updates when `revalidate()` is called.
11
- *
12
- * @template P - Type for page props (default: any)
13
- * @template T - Type for route params (default: any)
14
- * @returns Object containing params and props
15
- *
16
- * @example
17
- * // With props type only
18
- * const { props } = usePageProps<{ title: string }>();
19
- *
20
- * @example
21
- * // With both props and params types
22
- * const { props, params } = usePageProps<{ title: string }, { id: string }>();
23
- */
24
- declare function usePageProps<P = any, T = any>(): {
25
- params: T;
26
- props: P;
27
- };
28
-
29
6
  interface Router {
30
7
  /**
31
8
  * Navigate to a new route.
@@ -57,8 +34,13 @@ interface Router {
57
34
  pathname: string;
58
35
  /**
59
36
  * Query parameters from the URL (e.g., ?id=123&name=test)
37
+ * Alias for searchParams for backward compatibility
60
38
  */
61
39
  query: Record<string, string>;
40
+ /**
41
+ * Search parameters from the URL (e.g., ?id=123&name=test)
42
+ */
43
+ searchParams: Record<string, unknown>;
62
44
  /**
63
45
  * Dynamic route parameters (e.g., { slug: "my-post" } for /blog/[slug])
64
46
  */
@@ -104,4 +86,4 @@ interface Router {
104
86
  */
105
87
  declare function useRouter(): Router;
106
88
 
107
- export { type Router, useBroadcastChannel, usePageProps, useRouter };
89
+ export { type Router, useBroadcastChannel, useRouter };
@@ -3,29 +3,6 @@ declare const useBroadcastChannel: (channelName: string) => {
3
3
  sendMessage: (msg: unknown) => void;
4
4
  };
5
5
 
6
- /**
7
- * Hook to access page props and route parameters.
8
- *
9
- * Reads initial data from window.__FW_DATA__ set during SSR.
10
- * Automatically updates when `revalidate()` is called.
11
- *
12
- * @template P - Type for page props (default: any)
13
- * @template T - Type for route params (default: any)
14
- * @returns Object containing params and props
15
- *
16
- * @example
17
- * // With props type only
18
- * const { props } = usePageProps<{ title: string }>();
19
- *
20
- * @example
21
- * // With both props and params types
22
- * const { props, params } = usePageProps<{ title: string }, { id: string }>();
23
- */
24
- declare function usePageProps<P = any, T = any>(): {
25
- params: T;
26
- props: P;
27
- };
28
-
29
6
  interface Router {
30
7
  /**
31
8
  * Navigate to a new route.
@@ -57,8 +34,13 @@ interface Router {
57
34
  pathname: string;
58
35
  /**
59
36
  * Query parameters from the URL (e.g., ?id=123&name=test)
37
+ * Alias for searchParams for backward compatibility
60
38
  */
61
39
  query: Record<string, string>;
40
+ /**
41
+ * Search parameters from the URL (e.g., ?id=123&name=test)
42
+ */
43
+ searchParams: Record<string, unknown>;
62
44
  /**
63
45
  * Dynamic route parameters (e.g., { slug: "my-post" } for /blog/[slug])
64
46
  */
@@ -104,4 +86,4 @@ interface Router {
104
86
  */
105
87
  declare function useRouter(): Router;
106
88
 
107
- export { type Router, useBroadcastChannel, usePageProps, useRouter };
89
+ export { type Router, useBroadcastChannel, useRouter };