frontend-hamroun 1.2.84 → 1.2.88
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/dist/batch.d.ts +4 -0
- package/dist/batch.d.ts.map +1 -0
- package/dist/batch.js +22 -0
- package/dist/client-router.d.ts +61 -0
- package/dist/client-router.d.ts.map +1 -0
- package/dist/client-router.js +209 -0
- package/dist/component.d.ts +15 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +84 -0
- package/dist/components/Counter.d.ts +1 -0
- package/dist/components/Counter.d.ts.map +1 -0
- package/dist/components/Counter.js +2 -0
- package/dist/context.d.ts +5 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +23 -0
- package/dist/event-bus.d.ts +24 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +74 -0
- package/dist/forms.d.ts +41 -0
- package/dist/forms.d.ts.map +1 -0
- package/dist/forms.js +147 -0
- package/dist/hooks.d.ts +12 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +142 -0
- package/dist/index.cjs +1118 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.client.d.ts +13 -0
- package/dist/index.client.d.ts.map +1 -0
- package/dist/index.client.js +12 -25
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1040 -264
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.cjs +102 -0
- package/dist/jsx-dev-runtime.cjs.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +3 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +96 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts +5 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.js +40 -0
- package/dist/jsx-runtime.cjs +112 -1
- package/dist/jsx-runtime.cjs.map +1 -1
- package/dist/jsx-runtime.d.ts +18 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +90 -79
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/lifecycle-events.d.ts +109 -0
- package/dist/lifecycle-events.d.ts.map +1 -0
- package/dist/lifecycle-events.js +176 -0
- package/dist/renderComponent.d.ts +14 -0
- package/dist/renderComponent.d.ts.map +1 -0
- package/dist/renderComponent.js +29 -0
- package/dist/renderer.d.ts +4 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +49 -0
- package/dist/router.d.ts +56 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +165 -0
- package/dist/server-renderer.d.ts +2 -0
- package/dist/server-renderer.d.ts.map +1 -0
- package/dist/server-renderer.js +111 -5
- package/dist/server-types.d.ts +43 -0
- package/dist/server-types.d.ts.map +1 -0
- package/dist/server-types.js +5 -0
- package/dist/store.d.ts +42 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +98 -0
- package/dist/types.d.ts +272 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +47 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +143 -0
- package/dist/vdom.d.ts +9 -0
- package/dist/vdom.d.ts.map +1 -0
- package/dist/vdom.js +21 -0
- package/dist/wasm.d.ts +37 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +158 -0
- package/package.json +54 -83
- package/templates/basic-app/build.d.ts +2 -0
- package/templates/basic-app/build.d.ts.map +1 -0
- package/templates/basic-app/dev.d.ts +2 -0
- package/templates/basic-app/dev.d.ts.map +1 -0
- package/templates/basic-app/esbuild.config.d.ts +2 -0
- package/templates/basic-app/esbuild.config.d.ts.map +1 -0
- package/templates/basic-app/postcss.config.d.ts +8 -0
- package/templates/basic-app/postcss.config.d.ts.map +1 -0
- package/templates/basic-app/server.d.ts +2 -0
- package/templates/basic-app/server.d.ts.map +1 -0
- package/templates/basic-app/src/App.d.ts +2 -0
- package/templates/basic-app/src/App.d.ts.map +1 -0
- package/templates/basic-app/src/App.js +148 -0
- package/templates/basic-app/src/client.d.ts +2 -0
- package/templates/basic-app/src/client.d.ts.map +1 -0
- package/templates/basic-app/src/client.js +6 -0
- package/templates/basic-app/src/components/Counter.d.ts +4 -0
- package/templates/basic-app/src/components/Counter.d.ts.map +1 -0
- package/templates/basic-app/src/components/Counter.js +9 -0
- package/templates/basic-app/src/jsx-shim.d.ts +8 -0
- package/templates/basic-app/src/jsx-shim.d.ts.map +1 -0
- package/templates/basic-app/src/main.d.ts +2 -0
- package/templates/basic-app/src/main.d.ts.map +1 -0
- package/templates/basic-app/src/main.js +57 -0
- package/templates/basic-app/src/server.d.ts +2 -0
- package/templates/basic-app/src/server.d.ts.map +1 -0
- package/templates/basic-app/tailwind.config.d.ts +9 -0
- package/templates/basic-app/tailwind.config.d.ts.map +1 -0
- package/templates/basic-app/vite.config.d.ts +3 -0
- package/templates/basic-app/vite.config.d.ts.map +1 -0
- package/templates/basic-app/vite.config.js +7 -0
- package/templates/complete-app/api/hello.d.ts +1 -0
- package/templates/complete-app/api/hello.d.ts.map +1 -0
- package/templates/complete-app/client.d.ts +2 -0
- package/templates/complete-app/client.d.ts.map +1 -0
- package/templates/complete-app/lib/frontend-hamroun.d.ts +18 -0
- package/templates/complete-app/lib/frontend-hamroun.d.ts.map +1 -0
- package/templates/complete-app/pages/about.d.ts +7 -0
- package/templates/complete-app/pages/about.d.ts.map +1 -0
- package/templates/complete-app/pages/index.d.ts +7 -0
- package/templates/complete-app/pages/index.d.ts.map +1 -0
- package/templates/complete-app/pages/wasm-demo.d.ts +7 -0
- package/templates/complete-app/pages/wasm-demo.d.ts.map +1 -0
- package/templates/complete-app/public/client.d.ts +17 -0
- package/templates/complete-app/public/client.d.ts.map +1 -0
- package/templates/complete-app/server.d.ts +2 -0
- package/templates/complete-app/server.d.ts.map +1 -0
- package/templates/complete-app/server.js +236 -218
- package/templates/complete-app/src/App.d.ts +2 -0
- package/templates/complete-app/src/App.d.ts.map +1 -0
- package/templates/complete-app/src/App.js +27 -0
- package/templates/complete-app/src/client.d.ts +2 -0
- package/templates/complete-app/src/client.d.ts.map +1 -0
- package/templates/complete-app/src/client.js +52 -0
- package/templates/complete-app/src/pages/index.d.ts +2 -0
- package/templates/complete-app/src/pages/index.d.ts.map +1 -0
- package/templates/complete-app/src/pages/index.js +19 -0
- package/templates/complete-app/src/server.d.ts +2 -0
- package/templates/complete-app/src/server.d.ts.map +1 -0
- package/templates/complete-app/src/server.js +192 -0
- package/templates/complete-app/vite.config.d.ts +3 -0
- package/templates/complete-app/vite.config.d.ts.map +1 -0
- package/templates/complete-app/vite.config.js +29 -57
- package/templates/fullstack-app/api/hello.d.ts +4 -0
- package/templates/fullstack-app/api/hello.d.ts.map +1 -0
- package/templates/fullstack-app/api/hello.js +14 -11
- package/templates/fullstack-app/api/users/[id].d.ts +5 -0
- package/templates/fullstack-app/api/users/[id].d.ts.map +1 -0
- package/templates/fullstack-app/api/users/[id].js +52 -0
- package/templates/fullstack-app/api/users/index.d.ts +4 -0
- package/templates/fullstack-app/api/users/index.d.ts.map +1 -0
- package/templates/fullstack-app/api/users/index.js +25 -0
- package/templates/fullstack-app/build/main.d.ts +211 -0
- package/templates/fullstack-app/build/main.d.ts.map +1 -0
- package/templates/fullstack-app/build.d.ts +2 -0
- package/templates/fullstack-app/build.d.ts.map +1 -0
- package/templates/fullstack-app/build.js +190 -0
- package/templates/fullstack-app/postcss.config.d.ts +5 -0
- package/templates/fullstack-app/postcss.config.d.ts.map +1 -0
- package/templates/fullstack-app/process-tailwind.d.ts +2 -0
- package/templates/fullstack-app/process-tailwind.d.ts.map +1 -0
- package/templates/fullstack-app/public/route-handler.d.ts +1 -0
- package/templates/fullstack-app/public/route-handler.d.ts.map +1 -0
- package/templates/fullstack-app/server.d.ts +2 -0
- package/templates/fullstack-app/server.d.ts.map +1 -0
- package/templates/fullstack-app/server.js +428 -266
- package/templates/fullstack-app/src/client.d.ts +2 -0
- package/templates/fullstack-app/src/client.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/ClientHome.d.ts +1 -0
- package/templates/fullstack-app/src/components/ClientHome.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/ClientHome.js +1 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.d.ts +7 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.js +12 -0
- package/templates/fullstack-app/src/components/Layout.d.ts +7 -0
- package/templates/fullstack-app/src/components/Layout.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/Layout.js +4 -0
- package/templates/fullstack-app/src/components/StateDemo.d.ts +2 -0
- package/templates/fullstack-app/src/components/StateDemo.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/StateDemo.js +86 -0
- package/templates/fullstack-app/src/components/UserList.d.ts +11 -0
- package/templates/fullstack-app/src/components/UserList.d.ts.map +1 -0
- package/templates/fullstack-app/src/components/UserList.js +7 -0
- package/templates/fullstack-app/src/config.d.ts +29 -0
- package/templates/fullstack-app/src/config.d.ts.map +1 -0
- package/templates/fullstack-app/src/config.js +36 -0
- package/templates/fullstack-app/src/data/api.d.ts +35 -0
- package/templates/fullstack-app/src/data/api.d.ts.map +1 -0
- package/templates/fullstack-app/src/data/api.js +173 -0
- package/templates/fullstack-app/src/main.d.ts +7 -0
- package/templates/fullstack-app/src/main.d.ts.map +1 -0
- package/templates/fullstack-app/src/main.js +130 -0
- package/templates/fullstack-app/src/middleware.d.ts +10 -0
- package/templates/fullstack-app/src/middleware.d.ts.map +1 -0
- package/templates/fullstack-app/src/middleware.js +14 -0
- package/templates/fullstack-app/src/pages/404.d.ts +4 -0
- package/templates/fullstack-app/src/pages/404.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/404.js +4 -0
- package/templates/fullstack-app/src/pages/[id].d.ts +1 -0
- package/templates/fullstack-app/src/pages/[id].d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/[id].js +1 -0
- package/templates/fullstack-app/src/pages/_app.d.ts +6 -0
- package/templates/fullstack-app/src/pages/_app.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/_app.js +6 -0
- package/templates/fullstack-app/src/pages/_document.d.ts +7 -0
- package/templates/fullstack-app/src/pages/_document.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/_document.js +4 -0
- package/templates/fullstack-app/src/pages/_error.d.ts +4 -0
- package/templates/fullstack-app/src/pages/_error.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/_error.js +8 -0
- package/templates/fullstack-app/src/pages/about/index.d.ts +5 -0
- package/templates/fullstack-app/src/pages/about/index.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/about/index.js +6 -0
- package/templates/fullstack-app/src/pages/about.d.ts +10 -0
- package/templates/fullstack-app/src/pages/about.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/about.js +21 -0
- package/templates/fullstack-app/src/pages/api/users/[id].d.ts +6 -0
- package/templates/fullstack-app/src/pages/api/users/[id].d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/api/users/[id].js +51 -0
- package/templates/fullstack-app/src/pages/api/users/index.d.ts +4 -0
- package/templates/fullstack-app/src/pages/api/users/index.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/api/users/index.js +33 -0
- package/templates/fullstack-app/src/pages/index.d.ts +21 -0
- package/templates/fullstack-app/src/pages/index.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/index.js +66 -0
- package/templates/fullstack-app/src/pages/users/[id].d.ts +38 -0
- package/templates/fullstack-app/src/pages/users/[id].d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/users/[id].js +79 -0
- package/templates/fullstack-app/src/pages/users.d.ts +14 -0
- package/templates/fullstack-app/src/pages/users.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/users.js +14 -0
- package/templates/fullstack-app/src/pages/wasm-demo.d.ts +1 -0
- package/templates/fullstack-app/src/pages/wasm-demo.d.ts.map +1 -0
- package/templates/fullstack-app/src/pages/wasm-demo.js +2 -0
- package/templates/fullstack-app/src/router.d.ts +22 -0
- package/templates/fullstack-app/src/router.d.ts.map +1 -0
- package/templates/fullstack-app/src/router.js +210 -0
- package/templates/fullstack-app/tailwind.config.d.ts +3 -0
- package/templates/fullstack-app/tailwind.config.d.ts.map +1 -0
- package/templates/fullstack-app/vite.config.d.ts +3 -0
- package/templates/fullstack-app/vite.config.d.ts.map +1 -0
- package/templates/ssr-template/dist/client/assets/main-D-VH3xOb.d.ts +2 -0
- package/templates/ssr-template/dist/client/assets/main-D-VH3xOb.d.ts.map +1 -0
- package/templates/ssr-template/dist/client.d.ts +85 -0
- package/templates/ssr-template/dist/client.d.ts.map +1 -0
- package/templates/ssr-template/dist/server.d.ts +2 -0
- package/templates/ssr-template/dist/server.d.ts.map +1 -0
- package/templates/ssr-template/esbuild.config.d.ts +2 -0
- package/templates/ssr-template/esbuild.config.d.ts.map +1 -0
- package/templates/ssr-template/jsx-shim.d.ts +2 -0
- package/templates/ssr-template/jsx-shim.d.ts.map +1 -0
- package/templates/ssr-template/src/App.d.ts +2 -0
- package/templates/ssr-template/src/App.d.ts.map +1 -0
- package/templates/ssr-template/src/App.js +625 -0
- package/templates/ssr-template/src/client.d.ts +2 -0
- package/templates/ssr-template/src/client.d.ts.map +1 -0
- package/templates/ssr-template/src/client.js +3 -0
- package/templates/ssr-template/src/server.d.ts +2 -0
- package/templates/ssr-template/src/server.d.ts.map +1 -0
- package/templates/ssr-template/src/server.js +29 -0
- package/templates/ssr-template/vite.config.d.ts +3 -0
- package/templates/ssr-template/vite.config.d.ts.map +1 -0
- package/templates/ssr-template/vite.config.js +30 -0
- package/templates/wasm/build-wasm.d.ts +2 -0
- package/templates/wasm/build-wasm.d.ts.map +1 -0
- package/templates/wasm/dist/assets/index-BNqTDBdE.d.ts +30 -0
- package/templates/wasm/dist/assets/index-BNqTDBdE.d.ts.map +1 -0
- package/templates/wasm/dist/wasm_exec.d.ts +1 -0
- package/templates/wasm/dist/wasm_exec.d.ts.map +1 -0
- package/templates/wasm/esbuild.config.d.ts +2 -0
- package/templates/wasm/esbuild.config.d.ts.map +1 -0
- package/templates/wasm/go/wasm_exec.d.ts +1 -0
- package/templates/wasm/go/wasm_exec.d.ts.map +1 -0
- package/templates/wasm/jsx-shim.d.ts +5 -0
- package/templates/wasm/jsx-shim.d.ts.map +1 -0
- package/templates/wasm/public/wasm_exec.d.ts +1 -0
- package/templates/wasm/public/wasm_exec.d.ts.map +1 -0
- package/templates/wasm/src/App.d.ts +2 -0
- package/templates/wasm/src/App.d.ts.map +1 -0
- package/templates/wasm/src/App.js +381 -0
- package/templates/wasm/src/client.d.ts +2 -0
- package/templates/wasm/src/client.d.ts.map +1 -0
- package/templates/wasm/src/client.js +210 -0
- package/templates/wasm/src/index.d.ts +2 -0
- package/templates/wasm/src/index.d.ts.map +1 -0
- package/templates/wasm/src/index.js +20 -0
- package/templates/wasm/src/server.d.ts +2 -0
- package/templates/wasm/src/server.d.ts.map +1 -0
- package/templates/wasm/src/server.js +131 -0
- package/templates/wasm/vite.config.d.ts +3 -0
- package/templates/wasm/vite.config.d.ts.map +1 -0
- package/templates/wasm/vite.config.js +36 -0
- package/templates/wasm/wasm-loader.d.ts +6 -0
- package/templates/wasm/wasm-loader.d.ts.map +1 -0
- package/dist/index.client.cjs +0 -2
- package/dist/index.client.cjs.map +0 -1
- package/dist/index.client.js.map +0 -1
- package/dist/renderer-DaVfBeVi.cjs +0 -2
- package/dist/renderer-DaVfBeVi.cjs.map +0 -1
- package/dist/renderer-nfT7XSpo.js +0 -61
- package/dist/renderer-nfT7XSpo.js.map +0 -1
- package/dist/server-renderer-B5b0Q0ck.cjs +0 -2
- package/dist/server-renderer-B5b0Q0ck.cjs.map +0 -1
- package/dist/server-renderer-C4MB-jAp.js +0 -248
- package/dist/server-renderer-C4MB-jAp.js.map +0 -1
- package/dist/server-renderer.cjs +0 -2
- package/dist/server-renderer.cjs.map +0 -1
- package/dist/server-renderer.js.map +0 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["client.js"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
//# sourceMappingURL=ClientHome.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ClientHome.d.ts","sourceRoot":"","sources":["ClientHome.tsx"],"names":[],"mappings":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["ErrorBoundary.tsx"],"names":[],"mappings":"AAEA,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC;CACrD;AAED,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,kBAAkB,OA4BvE"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "frontend-hamroun/jsx-runtime";
|
2
|
+
import { useErrorBoundary } from 'frontend-hamroun';
|
3
|
+
export function ErrorBoundary({ children, fallback }) {
|
4
|
+
const [error, resetError] = useErrorBoundary();
|
5
|
+
if (error) {
|
6
|
+
if (fallback) {
|
7
|
+
return fallback(error, resetError);
|
8
|
+
}
|
9
|
+
return (_jsxs("div", { className: "error-boundary p-4 border border-red-500 rounded bg-red-50", children: [_jsx("h3", { className: "text-lg font-medium text-red-800 mb-2", children: "Something went wrong" }), _jsx("p", { className: "text-red-600 mb-2", children: error.message }), _jsx("button", { onClick: resetError, className: "px-3 py-1 bg-red-600 text-white rounded hover:bg-red-700", children: "Try again" }), process.env.NODE_ENV !== 'production' && (_jsx("pre", { className: "mt-3 text-xs overflow-auto p-2 bg-gray-100", children: error.stack }))] }));
|
10
|
+
}
|
11
|
+
return children;
|
12
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Layout.d.ts","sourceRoot":"","sources":["Layout.tsx"],"names":[],"mappings":"AAEA,UAAU,WAAW;IACnB,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,EAAE,QAAQ,EAAE,KAA8B,EAAE,EAAE,WAAW,eAkCvF"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "frontend-hamroun/jsx-runtime";
|
2
|
+
export default function Layout({ children, title = 'Frontend Hamroun App' }) {
|
3
|
+
return (_jsxs("div", { className: "min-h-screen flex flex-col bg-gray-50", children: [_jsx("header", { className: "bg-blue-600 text-white", children: _jsxs("div", { className: "container mx-auto px-4 py-4 flex justify-between items-center", children: [_jsx("h1", { className: "text-xl font-bold", children: _jsx("a", { href: "/", className: "hover:text-blue-100", children: title }) }), _jsx("nav", { children: _jsxs("ul", { className: "flex space-x-6", children: [_jsx("li", { children: _jsx("a", { href: "/", className: "hover:text-blue-100", children: "Home" }) }), _jsx("li", { children: _jsx("a", { href: "/about", className: "hover:text-blue-100", children: "About" }) })] }) })] }) }), _jsx("main", { className: "flex-grow container mx-auto px-4 py-8", children: children }), _jsx("footer", { className: "bg-gray-800 text-white", children: _jsx("div", { className: "container mx-auto px-4 py-6", children: _jsxs("p", { className: "text-center text-gray-400", children: ["\u00A9 ", new Date().getFullYear(), " Frontend Hamroun App. All rights reserved."] }) }) })] }));
|
4
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"StateDemo.d.ts","sourceRoot":"","sources":["StateDemo.tsx"],"names":[],"mappings":"AASA,MAAM,CAAC,OAAO,UAAU,SAAS,gBAqMhC"}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "frontend-hamroun/jsx-runtime";
|
2
|
+
import { useState, useMemo } from 'frontend-hamroun';
|
3
|
+
export default function StateDemo() {
|
4
|
+
// More comprehensive state with history tracking
|
5
|
+
const [state, setState] = useState({
|
6
|
+
count: 0,
|
7
|
+
lastUpdated: null,
|
8
|
+
history: []
|
9
|
+
});
|
10
|
+
// Track UI state separately
|
11
|
+
const [isLoading, setIsLoading] = useState(false);
|
12
|
+
const [showHistory, setShowHistory] = useState(false);
|
13
|
+
// Check for server-side rendering
|
14
|
+
const isSSR = typeof window === 'undefined';
|
15
|
+
// Calculate derived state with useMemo for performance
|
16
|
+
const stats = useMemo(() => {
|
17
|
+
// Ensure we have a valid history array
|
18
|
+
if (isSSR || !state || !state.history || state.history.length === 0) {
|
19
|
+
return { avg: 0, max: 0, min: 0 };
|
20
|
+
}
|
21
|
+
try {
|
22
|
+
const sum = state.history.reduce((a, b) => a + b, 0);
|
23
|
+
return {
|
24
|
+
avg: parseFloat((sum / state.history.length).toFixed(1)),
|
25
|
+
max: Math.max(...state.history),
|
26
|
+
min: Math.min(...state.history)
|
27
|
+
};
|
28
|
+
}
|
29
|
+
catch (error) {
|
30
|
+
console.error('Error calculating stats:', error);
|
31
|
+
return { avg: 0, max: 0, min: 0 };
|
32
|
+
}
|
33
|
+
}, [state?.history]);
|
34
|
+
// Handle increment with history tracking
|
35
|
+
const increment = () => {
|
36
|
+
if (isSSR)
|
37
|
+
return;
|
38
|
+
setIsLoading(true);
|
39
|
+
// Simulate async operation
|
40
|
+
setTimeout(() => {
|
41
|
+
setState(prevState => ({
|
42
|
+
count: prevState.count + 1,
|
43
|
+
lastUpdated: new Date().toLocaleTimeString(),
|
44
|
+
history: [...(prevState.history || []), prevState.count + 1]
|
45
|
+
}));
|
46
|
+
setIsLoading(false);
|
47
|
+
}, 300);
|
48
|
+
};
|
49
|
+
// Handle decrement with bounds checking
|
50
|
+
const decrement = () => {
|
51
|
+
if (isSSR)
|
52
|
+
return;
|
53
|
+
setIsLoading(true);
|
54
|
+
// Simulate async operation
|
55
|
+
setTimeout(() => {
|
56
|
+
setState(prevState => ({
|
57
|
+
count: Math.max(0, prevState.count - 1),
|
58
|
+
lastUpdated: new Date().toLocaleTimeString(),
|
59
|
+
history: prevState.count > 0 ? [...(prevState.history || []), prevState.count - 1] : (prevState.history || [])
|
60
|
+
}));
|
61
|
+
setIsLoading(false);
|
62
|
+
}, 300);
|
63
|
+
};
|
64
|
+
// Reset counter
|
65
|
+
const reset = () => {
|
66
|
+
if (isSSR)
|
67
|
+
return;
|
68
|
+
setState({
|
69
|
+
count: 0,
|
70
|
+
lastUpdated: new Date().toLocaleTimeString(),
|
71
|
+
history: []
|
72
|
+
});
|
73
|
+
};
|
74
|
+
// Toggle history visibility
|
75
|
+
const toggleHistory = () => {
|
76
|
+
if (isSSR)
|
77
|
+
return;
|
78
|
+
setShowHistory(prev => !prev);
|
79
|
+
};
|
80
|
+
// For SSR, return a simpler version of the component
|
81
|
+
if (isSSR) {
|
82
|
+
return (_jsxs("div", { className: "bg-white shadow-lg rounded-lg p-6 mb-8", children: [_jsx("h2", { className: "text-xl font-semibold text-gray-800 mb-4", children: "State Management Demo" }), _jsxs("div", { className: "flex items-center justify-between mb-4", children: [_jsx("button", { className: "px-4 py-2 bg-gray-200 text-gray-800 rounded-lg", children: "-" }), _jsx("span", { className: "text-2xl font-bold mx-4", children: "0" }), _jsx("button", { className: "px-4 py-2 bg-blue-600 text-white rounded-lg", children: "+" })] }), _jsx("p", { className: "text-sm text-gray-500", children: "Interactive counter (client-side only)" })] }));
|
83
|
+
}
|
84
|
+
// Regular client-side render
|
85
|
+
return (_jsxs("div", { className: "bg-white shadow-lg rounded-lg p-6 mb-8", children: [_jsx("h2", { className: "text-xl font-semibold text-gray-800 mb-4", children: "State Management Demo" }), _jsxs("div", { className: "mb-6", children: [_jsxs("div", { className: "flex items-center justify-between mb-4", children: [_jsx("button", { onClick: decrement, className: "px-4 py-2 bg-gray-200 text-gray-800 rounded-lg hover:bg-gray-300 disabled:opacity-50", disabled: state.count === 0 || isLoading, children: isLoading ? '...' : '-' }), _jsx("span", { className: "text-2xl font-bold mx-4", children: state.count }), _jsx("button", { onClick: increment, className: "px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50", disabled: isLoading, children: isLoading ? '...' : '+' })] }), _jsx("button", { onClick: reset, className: "text-sm text-gray-600 hover:text-red-600", disabled: state.count === 0 && (!state.history || state.history.length === 0), children: "Reset Counter" })] }), state.lastUpdated && (_jsx("div", { className: "mb-4", children: _jsxs("p", { className: "text-sm text-gray-500", children: ["Last updated: ", state.lastUpdated] }) })), state.history && state.history.length > 0 && (_jsxs("div", { className: "border-t pt-4 mt-4", children: [_jsxs("div", { className: "flex items-center justify-between mb-2", children: [_jsx("h3", { className: "text-md font-medium text-gray-700", children: "Statistics" }), _jsx("button", { onClick: toggleHistory, className: "text-sm text-blue-600 hover:underline", children: showHistory ? 'Hide History' : 'Show History' })] }), _jsxs("div", { className: "grid grid-cols-3 gap-2 mb-3", children: [_jsxs("div", { className: "bg-blue-50 p-2 rounded text-center", children: [_jsx("div", { className: "text-xs text-gray-500", children: "Average" }), _jsx("div", { className: "font-bold", children: stats.avg })] }), _jsxs("div", { className: "bg-green-50 p-2 rounded text-center", children: [_jsx("div", { className: "text-xs text-gray-500", children: "Maximum" }), _jsx("div", { className: "font-bold", children: stats.max })] }), _jsxs("div", { className: "bg-red-50 p-2 rounded text-center", children: [_jsx("div", { className: "text-xs text-gray-500", children: "Minimum" }), _jsx("div", { className: "font-bold", children: stats.min })] })] }), showHistory && (_jsxs("div", { className: "mt-3", children: [_jsxs("h4", { className: "text-sm font-medium text-gray-600 mb-1", children: ["History (", state.history.length, " events)"] }), _jsx("div", { className: "bg-gray-50 p-2 rounded max-h-24 overflow-y-auto text-xs", children: state.history.map((value, index) => (_jsx("span", { className: "inline-block bg-gray-200 rounded px-2 py-1 m-1", children: value }, index))) })] }))] }))] }));
|
86
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"UserList.d.ts","sourceRoot":"","sources":["UserList.tsx"],"names":[],"mappings":"AAEA,UAAU,IAAI;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,aAAa;IACrB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf;AAED,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,aAAa,eA+BxD"}
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "frontend-hamroun/jsx-runtime";
|
2
|
+
export default function UserList({ users }) {
|
3
|
+
if (!users || users.length === 0) {
|
4
|
+
return (_jsx("div", { className: "empty-state p-4 text-center bg-gray-50 rounded", children: _jsx("p", { className: "text-gray-500", children: "No users available" }) }));
|
5
|
+
}
|
6
|
+
return (_jsx("div", { className: "user-list", children: _jsx("ul", { className: "divide-y divide-gray-100", children: users.map(user => (_jsx("li", { className: "py-3", children: _jsxs("div", { className: "flex justify-between", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium text-gray-900", children: user.name }), _jsx("p", { className: "text-sm text-gray-500", children: user.email })] }), _jsx("a", { href: `/users/${user.id}`, className: "text-blue-600 hover:underline text-sm self-center", children: "View Profile" })] }) }, user.id))) }) }));
|
7
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
export declare const AppConfig: {
|
2
|
+
title: string;
|
3
|
+
description: string;
|
4
|
+
navigation: {
|
5
|
+
path: string;
|
6
|
+
label: string;
|
7
|
+
}[];
|
8
|
+
api: {
|
9
|
+
baseUrl: string;
|
10
|
+
endpoints: {
|
11
|
+
users: string;
|
12
|
+
posts: string;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
meta: {
|
16
|
+
viewport: string;
|
17
|
+
charset: string;
|
18
|
+
author: string;
|
19
|
+
keywords: string;
|
20
|
+
};
|
21
|
+
theme: {
|
22
|
+
primaryColor: string;
|
23
|
+
backgroundColor: string;
|
24
|
+
textColor: string;
|
25
|
+
fontFamily: string;
|
26
|
+
};
|
27
|
+
};
|
28
|
+
export default AppConfig;
|
29
|
+
//# sourceMappingURL=config.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCrB,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
// Application configuration
|
2
|
+
// Modify this file to customize your application without changing core files
|
3
|
+
export const AppConfig = {
|
4
|
+
// App information
|
5
|
+
title: 'Frontend Hamroun App',
|
6
|
+
description: 'A full-stack application built with Frontend Hamroun',
|
7
|
+
// Navigation
|
8
|
+
navigation: [
|
9
|
+
{ path: '/', label: 'Home' },
|
10
|
+
{ path: '/about', label: 'About' },
|
11
|
+
{ path: '/users', label: 'Users' }
|
12
|
+
],
|
13
|
+
// API endpoints
|
14
|
+
api: {
|
15
|
+
baseUrl: '/api',
|
16
|
+
endpoints: {
|
17
|
+
users: '/users',
|
18
|
+
posts: '/posts'
|
19
|
+
}
|
20
|
+
},
|
21
|
+
// Default meta tags
|
22
|
+
meta: {
|
23
|
+
viewport: 'width=device-width, initial-scale=1.0',
|
24
|
+
charset: 'UTF-8',
|
25
|
+
author: 'Your Name',
|
26
|
+
keywords: 'frontend-hamroun, fullstack, template'
|
27
|
+
},
|
28
|
+
// Style customization
|
29
|
+
theme: {
|
30
|
+
primaryColor: '#0066cc',
|
31
|
+
backgroundColor: '#ffffff',
|
32
|
+
textColor: '#333333',
|
33
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif'
|
34
|
+
}
|
35
|
+
};
|
36
|
+
export default AppConfig;
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/**
|
2
|
+
* Fetch data from the API with caching
|
3
|
+
*/
|
4
|
+
export declare function fetchApi(endpoint: string, options?: RequestInit & {
|
5
|
+
useCache?: boolean;
|
6
|
+
forceFresh?: boolean;
|
7
|
+
}): Promise<any>;
|
8
|
+
/**
|
9
|
+
* Clear the API cache
|
10
|
+
*/
|
11
|
+
export declare function clearApiCache(endpoint?: string): void;
|
12
|
+
export declare const UserApi: {
|
13
|
+
getAll(): Promise<{
|
14
|
+
id: number;
|
15
|
+
name: string;
|
16
|
+
email: string;
|
17
|
+
}[]>;
|
18
|
+
getById(id: number | string): Promise<{
|
19
|
+
id: number;
|
20
|
+
name: string;
|
21
|
+
email: string;
|
22
|
+
} | null>;
|
23
|
+
getPosts(authorId?: number | string): Promise<{
|
24
|
+
id: number;
|
25
|
+
title: string;
|
26
|
+
content: string;
|
27
|
+
authorId: number;
|
28
|
+
}[]>;
|
29
|
+
};
|
30
|
+
export declare const WasmApi: {
|
31
|
+
calculate: (operation: "add" | "multiply", a: number, b: number) => Promise<any>;
|
32
|
+
processJson: (data: any) => Promise<any>;
|
33
|
+
};
|
34
|
+
export declare const batchApiCalls: <T>(apiFunctions: Array<() => Promise<T>>) => Promise<T[]>;
|
35
|
+
//# sourceMappingURL=api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["api.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,WAAW,GAAG;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAA;CAChB,GACL,OAAO,CAAC,GAAG,CAAC,CAwCd;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAOrD;AAmBD,eAAO,MAAM,OAAO;;;;;;gBAmBA,MAAM,GAAG,MAAM;;;;;wBAyBP,MAAM,GAAG,MAAM;;;;;;CAyB1C,CAAC;AAGF,eAAO,MAAM,OAAO;2BACK,KAAK,GAAG,UAAU,KAAK,MAAM,KAAK,MAAM;wBAG3C,GAAG;CAKxB,CAAC;AAGF,eAAO,MAAM,aAAa,GAAU,CAAC,gBACrB,KAAK,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,KACpC,OAAO,CAAC,CAAC,EAAE,CA8Bb,CAAC"}
|
@@ -0,0 +1,173 @@
|
|
1
|
+
/**
|
2
|
+
* API utilities for making requests to the backend
|
3
|
+
*/
|
4
|
+
import { batchUpdates } from 'frontend-hamroun';
|
5
|
+
// Cache for API responses
|
6
|
+
const apiCache = new Map();
|
7
|
+
const CACHE_DURATION = 60000; // 1 minute cache
|
8
|
+
/**
|
9
|
+
* Fetch data from the API with caching
|
10
|
+
*/
|
11
|
+
export async function fetchApi(endpoint, options = {}) {
|
12
|
+
const url = endpoint.startsWith('/') ? `/api${endpoint}` : `/api/${endpoint}`;
|
13
|
+
const { useCache = true, forceFresh = false, ...fetchOptions } = options;
|
14
|
+
// Check cache first if enabled
|
15
|
+
if (useCache && !forceFresh) {
|
16
|
+
const cached = apiCache.get(url);
|
17
|
+
if (cached && Date.now() - cached.timestamp < CACHE_DURATION) {
|
18
|
+
console.log(`[API] Using cached data for: ${url}`);
|
19
|
+
return cached.data;
|
20
|
+
}
|
21
|
+
}
|
22
|
+
try {
|
23
|
+
console.log(`[API] Fetching data from: ${url}`);
|
24
|
+
const response = await fetch(url, {
|
25
|
+
headers: {
|
26
|
+
'Content-Type': 'application/json',
|
27
|
+
'Accept': 'application/json',
|
28
|
+
},
|
29
|
+
...fetchOptions
|
30
|
+
});
|
31
|
+
if (!response.ok) {
|
32
|
+
throw new Error(`API request failed: ${response.status} ${response.statusText}`);
|
33
|
+
}
|
34
|
+
const data = await response.json();
|
35
|
+
console.log(`[API] Successfully fetched data from: ${url}`);
|
36
|
+
// Cache the response if caching is enabled
|
37
|
+
if (useCache) {
|
38
|
+
apiCache.set(url, { data, timestamp: Date.now() });
|
39
|
+
}
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
console.error(`[API] Error fetching from ${url}:`, error);
|
44
|
+
throw error;
|
45
|
+
}
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Clear the API cache
|
49
|
+
*/
|
50
|
+
export function clearApiCache(endpoint) {
|
51
|
+
if (endpoint) {
|
52
|
+
const url = endpoint.startsWith('/') ? `/api${endpoint}` : `/api/${endpoint}`;
|
53
|
+
apiCache.delete(url);
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
apiCache.clear();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
// Sample data for development
|
60
|
+
const sampleUsers = [
|
61
|
+
{ id: 1, name: 'User 1', email: 'user1@example.com' },
|
62
|
+
{ id: 2, name: 'User 2', email: 'user2@example.com' },
|
63
|
+
{ id: 3, name: 'User 3', email: 'user3@example.com' }
|
64
|
+
];
|
65
|
+
const samplePosts = [
|
66
|
+
{ id: 1, title: 'Post 1', content: 'Content for post 1', authorId: 1 },
|
67
|
+
{ id: 2, title: 'Post 2', content: 'Content for post 2', authorId: 2 },
|
68
|
+
{ id: 3, title: 'Post 3', content: 'Content for post 3', authorId: 1 }
|
69
|
+
];
|
70
|
+
// Helper to simulate network delay
|
71
|
+
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
72
|
+
// User API client
|
73
|
+
export const UserApi = {
|
74
|
+
// Get all users
|
75
|
+
async getAll() {
|
76
|
+
try {
|
77
|
+
// In a real app, we'd fetch from API
|
78
|
+
// const response = await fetch('/api/users');
|
79
|
+
// if (!response.ok) throw new Error('Failed to fetch users');
|
80
|
+
// return await response.json();
|
81
|
+
// Simulate API delay
|
82
|
+
await delay(300);
|
83
|
+
return [...sampleUsers]; // Return a copy to avoid mutations
|
84
|
+
}
|
85
|
+
catch (error) {
|
86
|
+
console.error('Error fetching users:', error);
|
87
|
+
return [];
|
88
|
+
}
|
89
|
+
},
|
90
|
+
// Get user by ID
|
91
|
+
async getById(id) {
|
92
|
+
try {
|
93
|
+
// In a real app, we'd fetch from API
|
94
|
+
// const response = await fetch(`/api/users/${id}`);
|
95
|
+
// if (!response.ok) throw new Error('User not found');
|
96
|
+
// return await response.json();
|
97
|
+
// Convert ID to number if it's a string
|
98
|
+
const userId = typeof id === 'string' ? parseInt(id, 10) : id;
|
99
|
+
// Simulate API delay
|
100
|
+
await delay(200);
|
101
|
+
// Find user
|
102
|
+
const user = sampleUsers.find(u => u.id === userId);
|
103
|
+
if (!user)
|
104
|
+
throw new Error('User not found');
|
105
|
+
return { ...user }; // Return a copy to avoid mutations
|
106
|
+
}
|
107
|
+
catch (error) {
|
108
|
+
console.error(`Error fetching user ${id}:`, error);
|
109
|
+
return null;
|
110
|
+
}
|
111
|
+
},
|
112
|
+
// Get posts (all or by author)
|
113
|
+
async getPosts(authorId) {
|
114
|
+
try {
|
115
|
+
// In a real app, we'd fetch from API
|
116
|
+
// const url = authorId ? `/api/posts?authorId=${authorId}` : '/api/posts';
|
117
|
+
// const response = await fetch(url);
|
118
|
+
// if (!response.ok) throw new Error('Failed to fetch posts');
|
119
|
+
// return await response.json();
|
120
|
+
// Convert authorId to number if it's a string
|
121
|
+
const userId = authorId ? (typeof authorId === 'string' ? parseInt(authorId, 10) : authorId) : undefined;
|
122
|
+
// Simulate API delay
|
123
|
+
await delay(400);
|
124
|
+
// Filter posts if authorId is provided
|
125
|
+
const posts = userId
|
126
|
+
? samplePosts.filter(p => p.authorId === userId)
|
127
|
+
: samplePosts;
|
128
|
+
return [...posts]; // Return a copy to avoid mutations
|
129
|
+
}
|
130
|
+
catch (error) {
|
131
|
+
console.error('Error fetching posts:', error);
|
132
|
+
return [];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
};
|
136
|
+
// WASM API service
|
137
|
+
export const WasmApi = {
|
138
|
+
calculate: (operation, a, b) => fetchApi(`/wasm/calculate?op=${operation}&a=${a}&b=${b}`),
|
139
|
+
processJson: (data) => fetchApi('/wasm/process-json', {
|
140
|
+
method: 'POST',
|
141
|
+
body: JSON.stringify(data),
|
142
|
+
useCache: false
|
143
|
+
})
|
144
|
+
};
|
145
|
+
// Batch multiple API calls for efficiency
|
146
|
+
export const batchApiCalls = async (apiFunctions) => {
|
147
|
+
const results = [];
|
148
|
+
let errors = [];
|
149
|
+
// Execute all API calls in parallel
|
150
|
+
const promises = apiFunctions.map(fn => fn());
|
151
|
+
try {
|
152
|
+
const settledResults = await Promise.allSettled(promises);
|
153
|
+
// Process results
|
154
|
+
batchUpdates(() => {
|
155
|
+
settledResults.forEach(result => {
|
156
|
+
if (result.status === 'fulfilled') {
|
157
|
+
results.push(result.value);
|
158
|
+
}
|
159
|
+
else {
|
160
|
+
errors.push(result.reason);
|
161
|
+
}
|
162
|
+
});
|
163
|
+
});
|
164
|
+
if (errors.length) {
|
165
|
+
console.error('[API] Some batch API calls failed:', errors);
|
166
|
+
}
|
167
|
+
return results;
|
168
|
+
}
|
169
|
+
catch (error) {
|
170
|
+
console.error('[API] Batch API calls failed:', error);
|
171
|
+
throw error;
|
172
|
+
}
|
173
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["main.tsx"],"names":[],"mappings":"AAEA,OAAO,cAAc,CAAC;AAGtB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,iBAAiB,CAAC,EAAE,GAAG,CAAC;KACzB;CACF"}
|
@@ -0,0 +1,130 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "frontend-hamroun/jsx-runtime";
|
2
|
+
import { render, hydrate } from 'frontend-hamroun';
|
3
|
+
// Import Tailwind CSS
|
4
|
+
import './styles.css';
|
5
|
+
// Get initial state from server
|
6
|
+
const initialState = window.__INITIAL_STATE__ || {
|
7
|
+
route: window.location.pathname,
|
8
|
+
timestamp: new Date().toISOString(),
|
9
|
+
serverRendered: false,
|
10
|
+
data: {
|
11
|
+
users: null,
|
12
|
+
posts: null
|
13
|
+
}
|
14
|
+
};
|
15
|
+
console.log('[Client] Initial state:', initialState);
|
16
|
+
// Create a mutable variable for hydration state
|
17
|
+
let isHydrating = document.getElementById('root')?.innerHTML.trim() !== '';
|
18
|
+
// Function to handle navigation
|
19
|
+
async function handleRouteChange(path, isPushState = true) {
|
20
|
+
try {
|
21
|
+
console.log(`[Router] Navigating to: ${path}`);
|
22
|
+
// Update URL if needed
|
23
|
+
if (isPushState) {
|
24
|
+
window.history.pushState(null, '', path);
|
25
|
+
}
|
26
|
+
// Dynamically load the page component based on the path
|
27
|
+
const normalizedPath = path === '/' ? 'index' : path.replace(/^\//, '');
|
28
|
+
let Page;
|
29
|
+
try {
|
30
|
+
// Dynamic import for the page component
|
31
|
+
const module = await import(`./pages/${normalizedPath}.tsx`);
|
32
|
+
Page = module.default;
|
33
|
+
}
|
34
|
+
catch (error) {
|
35
|
+
console.warn(`[Router] Could not load page for ${path}, trying index file`);
|
36
|
+
try {
|
37
|
+
// Try loading index file in directory
|
38
|
+
const module = await import(`./pages/${normalizedPath}/index.tsx`);
|
39
|
+
Page = module.default;
|
40
|
+
}
|
41
|
+
catch (innerError) {
|
42
|
+
console.error(`[Router] Failed to load page component for ${path}`);
|
43
|
+
// Try to load 404 page
|
44
|
+
try {
|
45
|
+
const notFoundModule = await import(`./pages/404.tsx`);
|
46
|
+
Page = notFoundModule.default;
|
47
|
+
}
|
48
|
+
catch (notFoundError) {
|
49
|
+
// If all fails, render a simple not found message
|
50
|
+
const rootElement = document.getElementById('root');
|
51
|
+
if (rootElement) {
|
52
|
+
render(_jsxs("div", { style: { padding: '20px', maxWidth: '800px', margin: '0 auto' }, children: [_jsx("h1", { children: "Page Not Found" }), _jsx("p", { children: "The page you requested could not be found." }), _jsx("a", { href: "/", style: { color: '#0066cc' }, children: "Go to Home" })] }), rootElement);
|
53
|
+
}
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
// Get the current page props
|
59
|
+
let pageProps = initialState.pageProps || {};
|
60
|
+
// If the page defines getServerSideProps, fetch data
|
61
|
+
if (Page.getServerSideProps) {
|
62
|
+
try {
|
63
|
+
const response = await fetch(`/api/__props${path}`);
|
64
|
+
if (response.ok) {
|
65
|
+
const data = await response.json();
|
66
|
+
pageProps = data.props || {};
|
67
|
+
}
|
68
|
+
}
|
69
|
+
catch (error) {
|
70
|
+
console.error('[Router] Error fetching page props:', error);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
// Update the state with current route
|
74
|
+
const updatedState = {
|
75
|
+
...initialState,
|
76
|
+
route: path,
|
77
|
+
pageProps
|
78
|
+
};
|
79
|
+
// Render the page
|
80
|
+
const rootElement = document.getElementById('root');
|
81
|
+
if (!rootElement)
|
82
|
+
return;
|
83
|
+
if (isHydrating && path === initialState.route) {
|
84
|
+
console.log('[Client] Hydrating server-rendered content');
|
85
|
+
hydrate(_jsx(Page, { ...pageProps, initialState: updatedState }), rootElement);
|
86
|
+
isHydrating = false;
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
console.log('[Client] Rendering client-side');
|
90
|
+
render(_jsx(Page, { ...pageProps, initialState: updatedState }), rootElement);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
catch (error) {
|
94
|
+
console.error('[Router] Navigation error:', error);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
// Handle initial route
|
98
|
+
handleRouteChange(window.location.pathname, false);
|
99
|
+
// Handle client-side navigation
|
100
|
+
document.addEventListener('click', (e) => {
|
101
|
+
let target = e.target;
|
102
|
+
// Find closest anchor element
|
103
|
+
while (target && target.tagName !== 'A') {
|
104
|
+
target = target.parentElement;
|
105
|
+
if (!target)
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
if (target &&
|
109
|
+
target.tagName === 'A' &&
|
110
|
+
target.getAttribute('href') &&
|
111
|
+
target.getAttribute('href')?.startsWith('/') &&
|
112
|
+
!target.getAttribute('href')?.startsWith('//') &&
|
113
|
+
!target.getAttribute('target')) {
|
114
|
+
e.preventDefault();
|
115
|
+
const href = target.getAttribute('href') || '/';
|
116
|
+
handleRouteChange(href);
|
117
|
+
}
|
118
|
+
});
|
119
|
+
// Handle back/forward navigation
|
120
|
+
window.addEventListener('popstate', () => {
|
121
|
+
handleRouteChange(window.location.pathname, false);
|
122
|
+
});
|
123
|
+
// Set up socket.io for live reload in development
|
124
|
+
if (typeof io !== 'undefined') {
|
125
|
+
const socket = io();
|
126
|
+
socket.on('reload', () => {
|
127
|
+
console.log('[Dev] Reloading page due to file changes');
|
128
|
+
window.location.reload();
|
129
|
+
});
|
130
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Request, Response, NextFunction } from 'express';
|
2
|
+
declare global {
|
3
|
+
namespace Express {
|
4
|
+
interface Request {
|
5
|
+
timestamp: string;
|
6
|
+
}
|
7
|
+
}
|
8
|
+
}
|
9
|
+
export default function middleware(req: Request, res: Response, next?: NextFunction): Promise<void>;
|
10
|
+
//# sourceMappingURL=middleware.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,OAAO,CAAC;QAChB,UAAU,OAAO;YACf,SAAS,EAAE,MAAM,CAAC;SACnB;KACF;CACF;AAGD,wBAA8B,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,YAAY,iBAcxF"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
// This middleware will be applied to all routes (API and pages)
|
2
|
+
export default async function middleware(req, res, next) {
|
3
|
+
// Add request timestamp
|
4
|
+
req.timestamp = await new Date().toISOString();
|
5
|
+
// Log all requests in development mode
|
6
|
+
if (process.env.NODE_ENV !== 'production') {
|
7
|
+
console.log(`[${req.timestamp}] ${req.method} ${req.url}`);
|
8
|
+
}
|
9
|
+
// Example of response header modification
|
10
|
+
res.setHeader('X-Powered-By', 'Frontend Hamroun');
|
11
|
+
// Continue to next middleware
|
12
|
+
if (next)
|
13
|
+
next();
|
14
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"404.d.ts","sourceRoot":"","sources":["404.tsx"],"names":[],"mappings":"AAEA,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,YAAY,EAAE;;CAAA,eAyBhD"}
|