@revojs/vue 0.1.18 → 0.1.20

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.
@@ -1,5 +1,5 @@
1
- import { Ref } from "vue";
2
1
  import { Scope } from "revojs";
2
+ import { Ref } from "vue";
3
3
 
4
4
  //#region src/client/index.d.ts
5
5
  type AsyncOptions<T> = {
@@ -1,4 +1,4 @@
1
- import { $fetch, getState, sendRedirect, setState } from "../dist-CID_dTbk.js";
1
+ import { $fetch, getState, sendRedirect, setState } from "revojs";
2
2
  import { customRef, inject, onServerPrefetch, ref } from "vue";
3
3
  import { useRouter } from "vue-router";
4
4
 
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import "./dist-CID_dTbk.js";
2
- import { addAssets, addRoutes, useKit } from "@revojs/kit";
1
+ import { addRoutes, useKit } from "revojs/kit";
2
+ import "revojs";
3
3
 
4
4
  //#region src/index.ts
5
5
  function addPages(app, path) {
@@ -8,13 +8,12 @@ function addPages(app, path) {
8
8
  function vue() {
9
9
  return {
10
10
  config: { sources: { pages: {
11
- match: "**/{page,layout}.vue",
11
+ match: "**/*.vue",
12
12
  entries: ["./routes"]
13
13
  } } },
14
14
  setup(app) {
15
15
  const { toPath, addAlias } = useKit(app, import.meta.url);
16
16
  app.config.client = toPath("./module/index.html");
17
- addAssets(app, "./dist/client");
18
17
  addRoutes(app, toPath("./module/routes"));
19
18
  addAlias("vue/app", "./module/app.ts");
20
19
  addAlias("vue/main", "./module/main.vue");
@@ -5,10 +5,10 @@ import Main from "#alias/vue/main";
5
5
  import pages from "#virtual/pages";
6
6
 
7
7
  function toRoute(path: string, node: Node<Component>, index: number): RouteRecordRaw {
8
- const layout = node.children["LAYOUT"];
8
+ const layout = node.children["+layout"];
9
9
 
10
10
  if (layout) {
11
- delete node.children["LAYOUT"];
11
+ delete node.children["+layout"];
12
12
  }
13
13
 
14
14
  const children = Object.entries(node.children).map(([path, node]) => toRoute(path, node, index + 1));
@@ -21,10 +21,6 @@ function toRoute(path: string, node: Node<Component>, index: number): RouteRecor
21
21
  path += node.parameter;
22
22
  }
23
23
 
24
- if (index === 0) {
25
- path = "/";
26
- }
27
-
28
24
  const route = {
29
25
  path,
30
26
  children,
@@ -38,17 +34,16 @@ export default async (scope: Scope) => {
38
34
  const radix = new Radix<Component>();
39
35
 
40
36
  for (const name in pages) {
41
- const [path, target] = toRoutePath(name);
42
-
43
37
  const Component = pages[name];
38
+
44
39
  if (Component) {
45
- radix.use(target === "PAGE" ? path : path + "/" + target, Component);
40
+ radix.use(toRoutePath(name), Component);
46
41
  }
47
42
  }
48
43
 
49
44
  const router = createRouter({
50
45
  history: import.meta.server ? createMemoryHistory() : createWebHistory(),
51
- routes: Object.entries(radix.rootNode.children).map(([path, node]) => toRoute(path, node, 0)),
46
+ routes: [toRoute("/", radix.rootNode, 0)],
52
47
  });
53
48
 
54
49
  const app = createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -29,9 +29,9 @@
29
29
  "watch": "tsdown -w"
30
30
  },
31
31
  "dependencies": {
32
- "@revojs/kit": "*",
33
32
  "vue": "^3.5.19",
34
- "vue-router": "^4.5.1"
33
+ "vue-router": "^4.5.1",
34
+ "revojs": "*"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@revojs/tsconfig": "*",
@@ -1,110 +0,0 @@
1
- //#region ../revojs/dist/index.js
2
- function useServer(scope) {
3
- return scope.getContext(SERVER_CONTEXT);
4
- }
5
- function getState(scope, name) {
6
- if (import.meta.server) {
7
- const { states } = useServer(scope);
8
- return states[name];
9
- } else {
10
- if (STATES === void 0) {
11
- const element = document.getElementById("STATES");
12
- STATES = element?.textContent ? JSON.parse(element.textContent) : {};
13
- }
14
- return STATES[name];
15
- }
16
- }
17
- function setState(scope, name, value) {
18
- if (import.meta.server) {
19
- const { states } = useServer(scope);
20
- states[name] = value;
21
- } else {
22
- if (STATES === void 0) {
23
- const element = document.getElementById("STATES");
24
- STATES = element?.textContent ? JSON.parse(element.textContent) : {};
25
- }
26
- STATES[name] = value;
27
- }
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
- }
35
- const ROUTER_CONTEXT = defineContext("ROUTER_CONTEXT");
36
- const SERVER_CONTEXT = defineContext("SERVER_CONTEXT");
37
- let STATES;
38
- var StopEvent = class extends Event {
39
- constructor() {
40
- super("stop");
41
- }
42
- };
43
- var Scope = class extends EventTarget {
44
- parentScope;
45
- context;
46
- constructor(parentScope) {
47
- super();
48
- this.parentScope = parentScope;
49
- this.parentScope?.onStop(() => this.stop());
50
- this.context = {};
51
- }
52
- getContext(input) {
53
- let scope = this;
54
- while (scope) {
55
- if (scope.context[input]) return scope.context[input];
56
- scope = scope.parentScope;
57
- }
58
- return {};
59
- }
60
- setContext(input, value) {
61
- this.context[input] = value;
62
- }
63
- onStop(input) {
64
- this.addEventListener("stop", input, { once: true });
65
- }
66
- stop() {
67
- return this.dispatchEvent(new StopEvent());
68
- }
69
- };
70
- function defineContext(name) {
71
- return name;
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
- }
86
- async function $fetch(scope, input, options) {
87
- let response;
88
- if (import.meta.server) {
89
- const { states, request, variables } = useServer(scope);
90
- const next = new Scope();
91
- const url = new URL(input.toString(), request.url);
92
- next.setContext(SERVER_CONTEXT, {
93
- states,
94
- request: new Request(url, options),
95
- response: { headers: new Headers() },
96
- variables
97
- });
98
- const previous = new URL(request.url);
99
- if (url.origin === previous.origin) response = await (await import("#virtual/server")).default.fetch(next);
100
- }
101
- response ??= await fetch(input, options);
102
- if (response.ok === false) throw response;
103
- switch (response.headers.get("Content-Type")?.split(";").shift() ?? "") {
104
- case "application/json": return response.json();
105
- default: return response;
106
- }
107
- }
108
-
109
- //#endregion
110
- export { $fetch, getState, sendRedirect, setState };