@revojs/vue 0.1.23 → 0.1.24

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/index.js CHANGED
@@ -12,7 +12,11 @@ function vue() {
12
12
  } } },
13
13
  setup(app) {
14
14
  const { fromModule } = useKit(import.meta.url);
15
- app.config.client = fromModule("./module/index.html");
15
+ app.config.template.head.children.push({
16
+ tagName: "script",
17
+ attributes: { type: "module" },
18
+ children: [`import "${fromModule("./module/entry.ts")}"`]
19
+ });
16
20
  addRoutes(app, fromModule("./module/routes"));
17
21
  addAlias(app, "vue/app", fromModule("./module/app.ts"));
18
22
  addAlias(app, "vue/main", fromModule("./module/main.vue"));
@@ -1,8 +1,15 @@
1
- import { isServer, Radix, Scope, toRoutePath, useUrl, type Node } from "revojs";
2
- import { type Component, createSSRApp } from "vue";
3
- import { createMemoryHistory, createRouter, createWebHistory, RouterView, type RouteRecordRaw } from "vue-router";
4
1
  import Main from "#alias/vue/main";
5
2
  import pages from "#virtual/pages";
3
+ import { isServer, Radix, Scope, useUrl, type Node } from "revojs";
4
+ import { createSSRApp, type Component } from "vue";
5
+ import {
6
+ createMemoryHistory,
7
+ createRouter,
8
+ createWebHistory,
9
+ RouteRecordSingleView,
10
+ RouterView,
11
+ type RouteRecordRaw,
12
+ } from "vue-router";
6
13
 
7
14
  function toRoute(path: string, node: Node<Component>, index: number): RouteRecordRaw {
8
15
  const layout = node.children["+layout"];
@@ -17,8 +24,12 @@ function toRoute(path: string, node: Node<Component>, index: number): RouteRecor
17
24
  children.push({ path: "", component: node.value });
18
25
  }
19
26
 
27
+ if (node.type === "OPTIONAL-PARAMETER") {
28
+ path = ":" + node.parameter + "?";
29
+ }
30
+
20
31
  if (node.type === "PARAMETER") {
21
- path += node.parameter;
32
+ path = ":" + node.parameter;
22
33
  }
23
34
 
24
35
  const route = {
@@ -33,15 +44,30 @@ function toRoute(path: string, node: Node<Component>, index: number): RouteRecor
33
44
  export default async (scope: Scope) => {
34
45
  const radix = new Radix<Component>();
35
46
 
36
- for (const name in pages) {
37
- const [path] = toRoutePath(name);
47
+ for (const path in pages) {
48
+ const segments = path.toLowerCase().split("/");
49
+
50
+ for (const attribute of segments.pop()?.split(".") ?? []) {
51
+ if (attribute === "index" || attribute === "vue") {
52
+ continue;
53
+ }
54
+
55
+ segments.push(attribute);
56
+ }
57
+
58
+ radix.use(segments, pages[path]);
59
+ }
60
+
61
+ const rootNode = toRoute("/", radix.rootNode, 0);
38
62
 
39
- radix.use(path, pages[name]);
63
+ const optionalNode = rootNode.children?.find((route) => route.path.includes("?")) as RouteRecordSingleView;
64
+ if (optionalNode) {
65
+ rootNode.children?.push({ ...optionalNode, path: "" });
40
66
  }
41
67
 
42
68
  const router = createRouter({
43
69
  history: isServer ? createMemoryHistory() : createWebHistory(),
44
- routes: [toRoute("/", radix.rootNode, 0)],
70
+ routes: [rootNode],
45
71
  });
46
72
 
47
73
  const app = createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
@@ -0,0 +1,4 @@
1
+ import createApp from "#alias/vue/app";
2
+ import { Scope } from "revojs";
3
+
4
+ await createApp(new Scope()).then((app) => app.mount("#app"));
@@ -1,7 +1,7 @@
1
- import { defineRoute, sendHtml, useServer } from "revojs";
2
- import { renderToString } from "vue/server-renderer";
3
1
  import createApp from "#alias/vue/app";
4
2
  import client from "#virtual/client";
3
+ import { defineRoute, sendHtml, useServer } from "revojs";
4
+ import { renderToString } from "vue/server-renderer";
5
5
 
6
6
  export default defineRoute({
7
7
  async fetch(scope) {
@@ -13,9 +13,9 @@ export default defineRoute({
13
13
  app.config.errorHandler = (value) => (exception = value);
14
14
 
15
15
  const content = client
16
- .replace("<!-- MAIN -->", await renderToString(app))
16
+ .replace("<!-- BODY -->", await renderToString(app))
17
17
  .replace(
18
- "<!-- STATES -->",
18
+ "<!-- HEAD -->",
19
19
  "<script id='STATES' type='application/json'>" + JSON.stringify(states) + "</script>"
20
20
  );
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -1,18 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>Vue</title>
7
- <!-- STATES -->
8
- </head>
9
- <body>
10
- <div id="app"><!-- MAIN --></div>
11
- <script type="module">
12
- import { Scope } from "revojs";
13
- import createApp from "#alias/vue/app";
14
-
15
- await createApp(new Scope()).then((app) => app.mount("#app"));
16
- </script>
17
- </body>
18
- </html>