@revojs/vue 0.1.8 → 0.1.10

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.
@@ -18,5 +18,6 @@ declare function useFetch<T, TError = Error>(scope: Scope, input: string | URL,
18
18
  isLoading: Ref<boolean, boolean>;
19
19
  execute: (options?: AsyncOptions<TError> | undefined) => Promise<T | undefined>;
20
20
  };
21
+ declare function navigate(scope: Scope, path: string): void;
21
22
  //#endregion
22
- export { AsyncOptions, useAsync, useFetch, useScope, useState };
23
+ export { AsyncOptions, navigate, useAsync, useFetch, useScope, useState };
@@ -1,5 +1,6 @@
1
- import { $fetch, getState, setState } from "../dist-DM3hv3cX.js";
1
+ import { $fetch, getState, sendRedirect, setState } from "../dist-iR83EkEu.js";
2
2
  import { inject, onServerPrefetch, ref, watch } from "vue";
3
+ import { useRouter } from "vue-router";
3
4
 
4
5
  //#region src/client/index.ts
5
6
  function useScope() {
@@ -38,6 +39,10 @@ function useAsync(scope, name, invoke, defaultOptions) {
38
39
  function useFetch(scope, input, options) {
39
40
  return useAsync(scope, input.toString(), () => $fetch(scope, input, options), options);
40
41
  }
42
+ function navigate(scope, path) {
43
+ if (import.meta.server) throw sendRedirect(scope, path);
44
+ else useRouter().push(path);
45
+ }
41
46
 
42
47
  //#endregion
43
- export { useAsync, useFetch, useScope, useState };
48
+ export { navigate, useAsync, useFetch, useScope, useState };
@@ -26,6 +26,12 @@ function setState(scope, name, value) {
26
26
  STATES[name] = value;
27
27
  }
28
28
  }
29
+ function sendRedirect(scope, path, config) {
30
+ const { response } = useServer(scope);
31
+ response.status = 302;
32
+ response.headers.set("Location", path);
33
+ return new Response(null, mergeObjects(response, config));
34
+ }
29
35
  const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
30
36
  const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
31
37
  let STATES;
@@ -64,6 +70,19 @@ var Scope = class extends EventTarget {
64
70
  function defineContext(name) {
65
71
  return name;
66
72
  }
73
+ function mergeObjects(base, input) {
74
+ if (input === null || input === void 0) return mergeObjects(base, {});
75
+ const object = Object.assign({}, input);
76
+ for (const key in base) {
77
+ if (key === "__proto__" || key === "constructor") continue;
78
+ const value = base[key];
79
+ if (value === null || value === void 0) continue;
80
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
81
+ else if (typeof value === "object" && typeof object[key] === "object") object[key] = mergeObjects(value, object[key]);
82
+ else object[key] = value;
83
+ }
84
+ return object;
85
+ }
67
86
  async function $fetch(scope, input, options) {
68
87
  let response;
69
88
  if (import.meta.server) {
@@ -86,4 +105,4 @@ async function $fetch(scope, input, options) {
86
105
  }
87
106
 
88
107
  //#endregion
89
- export { $fetch, getState, setState };
108
+ export { $fetch, getState, sendRedirect, setState };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./dist-DM3hv3cX.js";
1
+ import "./dist-iR83EkEu.js";
2
2
  import { addAssets, addRoutes, useKit } from "@revojs/kit";
3
3
 
4
4
  //#region src/index.ts
@@ -53,6 +53,8 @@ export default async (scope: Scope) => {
53
53
 
54
54
  const app = createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
55
55
 
56
+ app.config.throwUnhandledErrorInProduction = true;
57
+
56
58
  if (import.meta.server) {
57
59
  const { pathname } = useUrl(scope);
58
60
 
@@ -1,10 +1,7 @@
1
1
  <template>
2
- <Suspense>
3
- <RouterView />
4
- </Suspense>
2
+ <RouterView />
5
3
  </template>
6
4
 
7
5
  <script setup lang="ts">
8
- import { Suspense } from "vue";
9
6
  import { RouterView } from "vue-router";
10
7
  </script>
@@ -7,13 +7,22 @@ export default defineRoute({
7
7
  async fetch(scope) {
8
8
  const { states } = useServer(scope);
9
9
 
10
+ const app = await createApp(scope);
11
+
12
+ let exception;
13
+ app.config.errorHandler = (value) => (exception = value);
14
+
10
15
  const content = client
11
- .replace("<!-- MAIN -->", await renderToString(await createApp(scope)))
16
+ .replace("<!-- MAIN -->", await renderToString(app))
12
17
  .replace(
13
18
  "<!-- STATES -->",
14
19
  "<script id='STATES' type='application/json'>" + JSON.stringify(states) + "</script>"
15
20
  );
16
21
 
22
+ if (exception) {
23
+ throw exception;
24
+ }
25
+
17
26
  return sendHtml(scope, content);
18
27
  },
19
28
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",