evikit 2.9.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. package/README.md +11 -18
  2. package/db.d.ts +255 -255
  3. package/index.d.ts +18 -0
  4. package/index.js +41 -7
  5. package/package.json +1 -1
  6. package/sqlite.js +576 -576
package/index.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  Router as IsoRouter,
7
7
  LocationProvider,
8
8
  prerender,
9
+ Route,
9
10
  } from "preact-iso";
10
11
  import { locationStub } from "preact-iso/prerender";
11
12
  import { useState } from "preact/hooks";
@@ -63,6 +64,14 @@ export async function hydrate(App, renderTarget) {
63
64
  }
64
65
  }
65
66
 
67
+ /**
68
+ * @param {string | null} path
69
+ * @param {() => import("preact").VNode} component
70
+ */
71
+ export function route(path, component) {
72
+ return { component, default: !path, path };
73
+ }
74
+
66
75
  /** @param {{ children?: import("preact").ComponentChildren, dehydratedState?: ReturnType<import("./query.js").dehydrate> | undefined, i18n: ReturnType<import("./i18n.js").useI18n> }} props */
67
76
  export function Router({ children, dehydratedState, i18n }) {
68
77
  const [queryClient] = useState(
@@ -91,16 +100,41 @@ export function Router({ children, dehydratedState, i18n }) {
91
100
  );
92
101
  }
93
102
 
103
+ /** @param {(import("./index.d.ts").SsrApp | import("./index.d.ts").SsrProps | { ErrorPage: () => import("preact").VNode } | ReturnType<import("./index.d.ts").route>)[]} args */
104
+ export function ssr(...args) {
105
+ if (typeof args[0] == "function") {
106
+ const App = args[0];
107
+ /** @type {import("./index.d.ts").SsrProps | undefined} */
108
+ const props = /** @type {any} */ (args[1]);
109
+ if (props) {
110
+ return ssrInner(App, props);
111
+ }
112
+ /** @param {import("./index.d.ts").SsrProps} props */
113
+ return (props) => ssrInner(App, props);
114
+ }
115
+ /** @type {() => import("preact").VNode} */
116
+ const ErrorPage = /** @type {any} */ (args[0]).ErrorPage;
117
+ /** @type {ReturnType<import("./index.d.ts").route>[]} */
118
+ const routes = /** @type {any} */ (args.slice(1));
119
+ /** @type {import("./index.d.ts").SsrApp} */
120
+ function App(props) {
121
+ return h(
122
+ Router,
123
+ props,
124
+ ...routes.map((route) => h(Route, route)),
125
+ h(Route, { component: ErrorPage, default: true }),
126
+ );
127
+ }
128
+ hydrate(App, "#app");
129
+ /** @param {import("./index.d.ts").SsrProps} props */
130
+ return (props) => ssrInner(App, props);
131
+ }
132
+
94
133
  /**
95
134
  * @param {(props: { dehydratedState?: ReturnType<import("./query.js").dehydrate> | undefined, i18n: ReturnType<import("./i18n.js").useI18n> }) => import("preact").VNode} App
96
- * @param {{ cookie?: string | undefined, lang?: string, url: string }} [data]
135
+ * @param {{ cookie?: string | undefined, lang?: string, url: string }} data
97
136
  */
98
- export async function ssr(App, data) {
99
- if (!data) {
100
- /** @param {NonNullable<typeof data>} data */
101
- return (data) => ssr(App, data);
102
- }
103
-
137
+ async function ssrInner(App, data) {
104
138
  const i18n = await getI18n(...(data.lang ? [data.lang] : []));
105
139
 
106
140
  const queryClient = new QueryClient({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "evikit",
3
3
  "description": "Preact/SQLite SSR framework for small web apps",
4
- "version": "2.9.1",
4
+ "version": "2.10.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./index.js",