@revojs/vue 0.1.3 → 0.1.5

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.
@@ -0,0 +1,6 @@
1
+ import { Scope } from "revojs";
2
+
3
+ //#region src/client/index.d.ts
4
+ declare function useScope(): Scope;
5
+ //#endregion
6
+ export { useScope };
@@ -0,0 +1,11 @@
1
+ import { inject } from "vue";
2
+
3
+ //#region src/client/index.ts
4
+ function useScope() {
5
+ const scope = inject("REVOJS_SCOPE");
6
+ if (scope) return scope;
7
+ throw new Error();
8
+ }
9
+
10
+ //#endregion
11
+ export { useScope };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import "revojs";
1
2
  import { addAssets, addRoutes, useKit } from "revojs/vite";
2
3
 
3
4
  //#region src/index.ts
@@ -1,4 +1,4 @@
1
- import { isServer, Radix, toRoutePath, type Node, type Route } from "revojs";
1
+ import { Radix, Scope, toRoutePath, useUrl, type Node } from "revojs";
2
2
  import { type Component, createSSRApp } from "vue";
3
3
  import { createMemoryHistory, createRouter, createWebHistory, RouterView, type RouteRecordRaw } from "vue-router";
4
4
  import Main from "#alias/vue/main";
@@ -30,7 +30,7 @@ function toRoute(path: string, node: Node<Component>): RouteRecordRaw {
30
30
  return route;
31
31
  }
32
32
 
33
- export default () => {
33
+ export default async (scope: Scope) => {
34
34
  const radix = new Radix<Component>();
35
35
 
36
36
  for (const name in pages) {
@@ -43,9 +43,17 @@ export default () => {
43
43
  }
44
44
 
45
45
  const router = createRouter({
46
- history: isServer() ? createMemoryHistory() : createWebHistory(),
46
+ history: import.meta.server ? createMemoryHistory() : createWebHistory(),
47
47
  routes: Object.entries(radix.rootNode.children).map(([path, node]) => toRoute(path, node)),
48
48
  });
49
49
 
50
- return createSSRApp(Main).use(router);
50
+ if (import.meta.server) {
51
+ const { pathname } = useUrl(scope);
52
+
53
+ await router.push(pathname);
54
+ }
55
+
56
+ await router.isReady();
57
+
58
+ return createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
51
59
  };
@@ -8,9 +8,10 @@
8
8
  <body>
9
9
  <div id="app"><!-- MAIN --></div>
10
10
  <script type="module">
11
+ import { Scope } from "revojs";
11
12
  import createApp from "#alias/vue/app";
12
13
 
13
- createApp().mount("#app");
14
+ await createApp(new Scope()).then((app) => app.mount("#app"));
14
15
  </script>
15
16
  </body>
16
17
  </html>
@@ -1,3 +1,10 @@
1
1
  <template>
2
- <RouterView />
2
+ <Suspense>
3
+ <RouterView />
4
+ </Suspense>
3
5
  </template>
6
+
7
+ <script setup lang="ts">
8
+ import { Suspense } from "vue";
9
+ import { RouterView } from "vue-router";
10
+ </script>
@@ -5,6 +5,6 @@ import client from "#virtual/client";
5
5
 
6
6
  export default defineRoute({
7
7
  async fetch(scope) {
8
- return sendHtml(scope, client.replace("<!-- MAIN -->", await renderToString(createApp())));
8
+ return sendHtml(scope, client.replace("<!-- MAIN -->", await renderToString(await createApp(scope))));
9
9
  },
10
10
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -9,6 +9,10 @@
9
9
  "types": "./dist/index.d.ts",
10
10
  "import": "./dist/index.js"
11
11
  },
12
+ "./client": {
13
+ "types": "./dist/client/index.d.ts",
14
+ "import": "./dist/client/index.js"
15
+ },
12
16
  "./types": {
13
17
  "types": "./src/types/index.d.ts"
14
18
  }
@@ -1,7 +1,7 @@
1
1
  declare module "#alias/vue/app" {
2
2
  import type { App } from "vue";
3
3
 
4
- export default function createApp(): App;
4
+ export default function createApp(scope: Scope): Promise<App>;
5
5
  }
6
6
 
7
7
  declare module "#alias/vue/main" {