vatts 2.2.5 → 2.3.0-canary

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 (64) hide show
  1. package/README.md +3 -3
  2. package/dist/builder.js +54 -17
  3. package/dist/frameworks/FrontCore.d.ts +34 -0
  4. package/dist/frameworks/FrontCore.js +128 -0
  5. package/dist/{vue → frameworks/builds}/vue.build.js +1 -1
  6. package/dist/frameworks/react/client.d.ts +8 -0
  7. package/dist/{react → frameworks/react}/client.js +14 -14
  8. package/dist/{react → frameworks/react/components}/Link.js +2 -2
  9. package/dist/frameworks/react/entry.client.d.ts +14 -0
  10. package/dist/frameworks/react/entry.client.js +211 -0
  11. package/dist/frameworks/react/react-elements.d.ts +10 -0
  12. package/dist/{react → frameworks/renderers}/renderer-react.d.ts +2 -2
  13. package/dist/{react → frameworks/renderers}/renderer-react.js +34 -68
  14. package/dist/{vue → frameworks/renderers}/renderer.vue.d.ts +2 -2
  15. package/dist/frameworks/renderers/renderer.vue.js +193 -0
  16. package/dist/frameworks/themes/BuildingPage.d.ts +1 -0
  17. package/dist/frameworks/themes/BuildingPage.js +312 -0
  18. package/dist/frameworks/themes/DefaultNotFound.d.ts +1 -0
  19. package/dist/frameworks/themes/DefaultNotFound.js +330 -0
  20. package/dist/frameworks/themes/ErrorModal.d.ts +1 -0
  21. package/dist/frameworks/themes/ErrorModal.js +345 -0
  22. package/dist/frameworks/themes/ServerError.d.ts +1 -0
  23. package/dist/frameworks/themes/ServerError.js +401 -0
  24. package/dist/frameworks/themes/VattsDevBadge.d.ts +1 -0
  25. package/dist/frameworks/themes/VattsDevBadge.js +232 -0
  26. package/dist/frameworks/vue/App.vue +149 -0
  27. package/dist/frameworks/vue/client.d.ts +9 -0
  28. package/dist/{vue → frameworks/vue}/client.js +13 -11
  29. package/dist/{vue → frameworks/vue/components}/Link.vue +1 -1
  30. package/dist/frameworks/vue/entry.client.js +75 -0
  31. package/dist/global/global.d.ts +1 -2
  32. package/dist/index.js +12 -1
  33. package/dist/renderer.js +2 -2
  34. package/package.json +10 -26
  35. package/dist/react/BuildingPage.d.ts +0 -2
  36. package/dist/react/BuildingPage.js +0 -270
  37. package/dist/react/DefaultNotFound.d.ts +0 -2
  38. package/dist/react/DefaultNotFound.js +0 -248
  39. package/dist/react/DevIndicator.d.ts +0 -5
  40. package/dist/react/DevIndicator.js +0 -203
  41. package/dist/react/ErrorModal.d.ts +0 -20
  42. package/dist/react/ErrorModal.js +0 -266
  43. package/dist/react/client.d.ts +0 -8
  44. package/dist/react/entry.client.d.ts +0 -6
  45. package/dist/react/entry.client.js +0 -325
  46. package/dist/react/server-error.d.ts +0 -8
  47. package/dist/react/server-error.js +0 -346
  48. package/dist/vue/App.vue +0 -199
  49. package/dist/vue/BuildingPage.vue +0 -281
  50. package/dist/vue/DefaultNotFound.vue +0 -329
  51. package/dist/vue/DevIndicator.vue +0 -226
  52. package/dist/vue/ErrorModal.vue +0 -317
  53. package/dist/vue/client.d.ts +0 -9
  54. package/dist/vue/entry.client.js +0 -110
  55. package/dist/vue/renderer.vue.js +0 -387
  56. package/dist/vue/server-error.vue +0 -351
  57. /package/dist/{react → frameworks/builds}/react.build.d.ts +0 -0
  58. /package/dist/{react → frameworks/builds}/react.build.js +0 -0
  59. /package/dist/{vue → frameworks/builds}/vue.build.d.ts +0 -0
  60. /package/dist/{react → frameworks/react/components}/Link.d.ts +0 -0
  61. /package/dist/{react → frameworks/react/components}/image/Image.d.ts +0 -0
  62. /package/dist/{react → frameworks/react/components}/image/Image.js +0 -0
  63. /package/dist/{vue → frameworks/vue/components}/image/Image.vue +0 -0
  64. /package/dist/{vue → frameworks/vue}/entry.client.d.ts +0 -0
@@ -0,0 +1,149 @@
1
+ <template>
2
+ <component :is="resolvedLayout" v-if="resolvedLayout">
3
+ <component
4
+ :is="resolvedContent"
5
+ v-bind="contentProps"
6
+ :key="`page-${hmrTimestamp}-${currentPathKey}`"
7
+ />
8
+ </component>
9
+
10
+ <component
11
+ v-else
12
+ :is="resolvedContent"
13
+ v-bind="contentProps"
14
+ :key="`page-${hmrTimestamp}-${currentPathKey}`"
15
+ />
16
+
17
+ <vatts-dev-badge
18
+ v-if="isDev"
19
+ :has-build-error="!!buildError"
20
+ @click-build-error="isErrorOpen = true"
21
+ ></vatts-dev-badge>
22
+
23
+ <vatts-error-modal
24
+ .error="buildError"
25
+ .isOpen="isErrorOpen"
26
+ @close-modal="isErrorOpen = false"
27
+ @copy-log="handleCopyLog"
28
+ ></vatts-error-modal>
29
+ </template>
30
+
31
+ <script setup>
32
+ import { ref, computed, onMounted, onUnmounted, shallowRef, watch, nextTick, defineComponent, h } from 'vue';
33
+ import { router } from '../../client/clientRouter';
34
+
35
+ // Importa a lógica centralizada
36
+ import {
37
+ findRouteForPath, updateDocumentTitle, copyBuildError,
38
+ setupBuildErrorEvents, setupHMREvents, dispatchHmrReady
39
+ } from '../FrontCore';
40
+
41
+ import '../themes/VattsDevBadge';
42
+ import '../themes/ErrorModal';
43
+
44
+ // --- Props ---
45
+ const props = defineProps({
46
+ componentMap: Object,
47
+ routes: Array,
48
+ initialComponentPath: String,
49
+ initialParams: null,
50
+ layoutComponent: null
51
+ });
52
+
53
+ // --- Estado ---
54
+ const hmrTimestamp = ref(Date.now());
55
+ const currentPathKey = ref(window.location.pathname);
56
+ const pendingHmrReady = ref(null);
57
+
58
+ const buildError = ref(window.__VATTS_BUILD_ERROR__ || null);
59
+ const isErrorOpen = ref(!!window.__VATTS_BUILD_ERROR__);
60
+ const isDev = process.env.NODE_ENV !== 'production';
61
+
62
+ // Cleanup references for events
63
+ let cleanupErrorEvents;
64
+ let cleanupHmrEvents;
65
+ let unsubscribeRouter;
66
+
67
+ const handleCopyLog = () => copyBuildError(buildError.value);
68
+
69
+ watch(hmrTimestamp, async (timestamp) => {
70
+ if (!pendingHmrReady.value || pendingHmrReady.value.timestamp !== timestamp) return;
71
+ await nextTick();
72
+ dispatchHmrReady(pendingHmrReady.value);
73
+ pendingHmrReady.value = null;
74
+ });
75
+
76
+ // --- Roteamento ---
77
+ const CurrentPageComponent = shallowRef(null);
78
+ const params = ref({});
79
+
80
+ const updateRoute = () => {
81
+ const currentPath = window.location.pathname.replace("index.html", '');
82
+ currentPathKey.value = currentPath;
83
+
84
+ const match = findRouteForPath(currentPath, props.routes);
85
+ if (match) {
86
+ CurrentPageComponent.value = props.componentMap[match.componentPath];
87
+ params.value = match.params;
88
+ updateDocumentTitle(match.metadata?.title);
89
+ } else {
90
+ CurrentPageComponent.value = null;
91
+ params.value = {};
92
+ }
93
+ };
94
+
95
+ // --- Computed ---
96
+ const resolvedContent = computed(() => {
97
+ if (!CurrentPageComponent.value) {
98
+ const NotFoundComponent = window.__VATTS_NOT_FOUND__;
99
+ if (NotFoundComponent) return NotFoundComponent;
100
+
101
+ const { getDefaultNotFound } = window.__VATTS_DEFAULT_NOT_FOUND__;
102
+ return getDefaultNotFound
103
+ ? defineComponent({
104
+ render() {
105
+ return h('div', {
106
+ innerHTML: getDefaultNotFound()
107
+ });
108
+ }
109
+ })
110
+ : 'div';
111
+ }
112
+ return CurrentPageComponent.value;
113
+ });
114
+
115
+ const contentProps = computed(() => {
116
+ if (!CurrentPageComponent.value) return {};
117
+ return { params: params.value };
118
+ });
119
+
120
+ const resolvedLayout = computed(() => props.layoutComponent || null);
121
+
122
+ // --- Lifecycle ---
123
+ onMounted(() => {
124
+ updateRoute();
125
+
126
+ // Usa as funções de eventos do Core
127
+ cleanupErrorEvents = setupBuildErrorEvents(
128
+ (err) => { buildError.value = err; isErrorOpen.value = true; },
129
+ () => { buildError.value = null; isErrorOpen.value = false; }
130
+ );
131
+
132
+ cleanupHmrEvents = setupHMREvents((file, timestamp) => {
133
+ pendingHmrReady.value = { file, timestamp };
134
+ hmrTimestamp.value = timestamp;
135
+ updateRoute();
136
+ });
137
+
138
+ window.addEventListener('popstate', updateRoute);
139
+ unsubscribeRouter = router.subscribe(updateRoute);
140
+ });
141
+
142
+ onUnmounted(() => {
143
+ if (cleanupErrorEvents) cleanupErrorEvents();
144
+ if (cleanupHmrEvents) cleanupHmrEvents();
145
+
146
+ window.removeEventListener('popstate', updateRoute);
147
+ if (unsubscribeRouter) unsubscribeRouter();
148
+ });
149
+ </script>
@@ -0,0 +1,9 @@
1
+ import Link from "./components/Link.vue";
2
+ export { Link };
3
+ export { RouteConfig, Metadata } from "../../types.ts";
4
+ export { router } from '../../client/clientRouter.ts';
5
+ export { requireDynamic } from '../../client/requireDynamic.ts';
6
+ export { importServer } from '../../client/rpc.ts';
7
+ export { importPhpServer } from '../../client/rpcPhp.ts';
8
+ export { default as Image } from "./components/image/Image.vue";
9
+ export { default as VattsImage } from "./components/image/Image.vue";
@@ -21,18 +21,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.VattsImage = exports.Image = exports.importPhpServer = exports.importServer = exports.requireDynamic = exports.router = exports.Link = void 0;
23
23
  // Este arquivo exporta apenas código seguro para o cliente (navegador)
24
- const Link_vue_1 = __importDefault(require("./Link.vue"));
24
+ const Link_vue_1 = __importDefault(require("./components/Link.vue"));
25
25
  exports.Link = Link_vue_1.default;
26
- var clientRouter_1 = require("../client/clientRouter");
27
- Object.defineProperty(exports, "router", { enumerable: true, get: function () { return clientRouter_1.router; } });
28
- var requireDynamic_1 = require("../client/requireDynamic");
29
- Object.defineProperty(exports, "requireDynamic", { enumerable: true, get: function () { return requireDynamic_1.requireDynamic; } });
26
+ const framework_ts_1 = require("../../api/framework.js");
27
+ var clientRouter_ts_1 = require("../../client/clientRouter.js");
28
+ Object.defineProperty(exports, "router", { enumerable: true, get: function () { return clientRouter_ts_1.router; } });
29
+ var requireDynamic_ts_1 = require("../../client/requireDynamic.js");
30
+ Object.defineProperty(exports, "requireDynamic", { enumerable: true, get: function () { return requireDynamic_ts_1.requireDynamic; } });
31
+ framework_ts_1.cachedFramework == 'react';
30
32
  // RPC (client-side)
31
- var rpc_1 = require("../client/rpc");
32
- Object.defineProperty(exports, "importServer", { enumerable: true, get: function () { return rpc_1.importServer; } });
33
- var rpcPhp_1 = require("../client/rpcPhp");
34
- Object.defineProperty(exports, "importPhpServer", { enumerable: true, get: function () { return rpcPhp_1.importPhpServer; } });
35
- var Image_vue_1 = require("./image/Image.vue");
33
+ var rpc_ts_1 = require("../../client/rpc.js");
34
+ Object.defineProperty(exports, "importServer", { enumerable: true, get: function () { return rpc_ts_1.importServer; } });
35
+ var rpcPhp_ts_1 = require("../../client/rpcPhp.js");
36
+ Object.defineProperty(exports, "importPhpServer", { enumerable: true, get: function () { return rpcPhp_ts_1.importPhpServer; } });
37
+ var Image_vue_1 = require("./components/image/Image.vue");
36
38
  Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return __importDefault(Image_vue_1).default; } });
37
- var Image_vue_2 = require("./image/Image.vue");
39
+ var Image_vue_2 = require("./components/image/Image.vue");
38
40
  Object.defineProperty(exports, "VattsImage", { enumerable: true, get: function () { return __importDefault(Image_vue_2).default; } });
@@ -15,7 +15,7 @@
15
15
  limitations under the License.
16
16
  -->
17
17
  <script setup>
18
- import { router } from '../client/clientRouter';
18
+ import { router } from '../../../client/clientRouter';
19
19
 
20
20
  const props = defineProps({
21
21
  href: {
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /*
7
+ * This file is part of the Vatts.js Project.
8
+ * Copyright (c) 2026 mfraz
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const vue_1 = require("vue");
23
+ const App_vue_1 = __importDefault(require("./App.vue"));
24
+ // Importa a lógica centralizada (agora usando findRouteForPath ao invés de getInitialClientData)
25
+ const FrontCore_1 = require("../FrontCore");
26
+ function initializeClient() {
27
+ try {
28
+ // Resolve a rota e params inicial calculando diretamente no lado do cliente
29
+ // a partir da injeção global do esbuild
30
+ const routes = window.__VATTS_ROUTES__ || [];
31
+ const currentPath = window.location.pathname.replace("index.html", '');
32
+ const match = (0, FrontCore_1.findRouteForPath)(currentPath, routes);
33
+ const initialComponentPath = match ? match.componentPath : '__404__';
34
+ const initialParams = match ? match.params : {};
35
+ const componentMap = {};
36
+ if (window.__VATTS_COMPONENTS__) {
37
+ Object.assign(componentMap, window.__VATTS_COMPONENTS__);
38
+ }
39
+ else {
40
+ console.warn('[Vatts Vue] No components found in window.__VATTS_COMPONENTS__');
41
+ }
42
+ const container = document.getElementById('root');
43
+ if (!container)
44
+ throw new Error('Container #root not found.');
45
+ if (window.__VATTS_APP__) {
46
+ try {
47
+ window.__VATTS_APP__.unmount();
48
+ container.innerHTML = '';
49
+ }
50
+ catch (e) {
51
+ console.warn('[Vatts Vue] Warning during unmount:', e);
52
+ }
53
+ }
54
+ const app = (0, vue_1.createApp)(App_vue_1.default, {
55
+ componentMap,
56
+ routes, // Passamos as rotas globais
57
+ initialComponentPath, // Passamos o path resolvido
58
+ initialParams, // Passamos os parâmetros da URL
59
+ layoutComponent: window.__VATTS_LAYOUT__
60
+ });
61
+ // Configuração para suportar os Web Components de desenvolvimento do Vatts
62
+ app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('vatts-');
63
+ window.__VATTS_APP__ = app;
64
+ app.mount(container);
65
+ }
66
+ catch (error) {
67
+ (0, FrontCore_1.renderCriticalError)(error, 'Vue');
68
+ }
69
+ }
70
+ if (document.readyState === 'loading') {
71
+ document.addEventListener('DOMContentLoaded', initializeClient);
72
+ }
73
+ else {
74
+ setTimeout(initializeClient, 0);
75
+ }
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
-
18
17
  /**
19
18
  * Type declarations for asset imports
20
19
  * This allows TypeScript to understand imports of various file types
@@ -177,4 +176,4 @@ declare module '*.vue' {
177
176
  }
178
177
  declare module '*.css';
179
178
  declare module '*.scss';
180
- declare module '*.sass';
179
+ declare module '*.sass';
package/dist/index.js CHANGED
@@ -723,7 +723,18 @@ function vatts(options) {
723
723
  // Se o stream já começou, não dá pra enviar erro 500 limpo.
724
724
  // O renderAsStream tenta lidar com isso no onError.
725
725
  if (!rawRes.headersSent) {
726
- genericRes.status(500).text('Internal server error');
726
+ const { getServerErrorHtml } = require("./frameworks/themes/ServerError");
727
+ // Gera o HTML bonitão passando o erro real
728
+ const errorHtml = getServerErrorHtml({
729
+ title: 'Critical SSR Error',
730
+ error: error,
731
+ requestUrl: pathname,
732
+ hint: 'The page crashed before or during the rendering process on the server.'
733
+ });
734
+ // Configura a resposta como HTML e envia a tela de erro
735
+ rawRes.statusCode = 500;
736
+ rawRes.setHeader('Content-Type', 'text/html; charset=utf-8');
737
+ rawRes.end(errorHtml);
727
738
  }
728
739
  }
729
740
  };
package/dist/renderer.js CHANGED
@@ -9,11 +9,11 @@ const framework_1 = require("./api/framework");
9
9
  async function renderAsStream(params) {
10
10
  if (framework_1.cachedFramework === 'react') {
11
11
  // Import dinâmico garante que o código do React só seja avaliado se necessário
12
- const { render } = await import("./react/renderer-react.js");
12
+ const { render } = await import("./frameworks/renderers/renderer-react.js");
13
13
  return await render(params);
14
14
  }
15
15
  else {
16
- const { renderVue } = await import("./vue/renderer.vue.js");
16
+ const { renderVue } = await import("./frameworks/renderers/renderer.vue.js");
17
17
  return await renderVue(params);
18
18
  }
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vatts",
3
- "version": "2.2.5",
3
+ "version": "2.3.0-canary",
4
4
  "description": "Vatts.js is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "mfraz",
@@ -46,14 +46,14 @@
46
46
  "require": "./dist/api/console.js"
47
47
  },
48
48
  "./react": {
49
- "types": "./dist/react/client.d.ts",
50
- "import": "./dist/react/client.js",
51
- "require": "./dist/react/client.js"
49
+ "types": "./dist/frameworks/react/client.d.ts",
50
+ "import": "./dist/frameworks/react/client.js",
51
+ "require": "./dist/frameworks/react/client.js"
52
52
  },
53
53
  "./vue": {
54
- "types": "./dist/vue/client.d.ts",
55
- "import": "./dist/vue/client.js",
56
- "require": "./dist/vue/client.js"
54
+ "types": "./dist/frameworks/vue/client.d.ts",
55
+ "import": "./dist/frameworks/vue/client.js",
56
+ "require": "./dist/frameworks/vue/client.js"
57
57
  },
58
58
  "./helpers": {
59
59
  "types": "./dist/helpers.d.ts",
@@ -102,41 +102,28 @@
102
102
  "pg": {
103
103
  "optional": true
104
104
  },
105
- "better-sqlite3": {
106
- "optional": true
107
- },
108
- "sqlite3": {
105
+ "@libsql/client": {
109
106
  "optional": true
110
107
  }
111
108
  },
112
109
  "peerDependencies": {
113
110
  "@libsql/client": "^0.17.0",
114
- "better-sqlite3": "^12.6.2",
115
111
  "express": "^4.0.0",
116
112
  "fastify": "^5.6.1",
117
113
  "mysql2": "^3.17.4",
118
114
  "pg": "^8.18.0",
119
115
  "react": "^19.2.3",
120
116
  "react-dom": "^19.2.3",
121
- "sqlite3": "^5.1.6",
122
117
  "vue": "^3.5.27"
123
118
  },
124
119
  "dependencies": {
125
- "@rollup/plugin-alias": "^6.0.0",
126
- "@rollup/plugin-commonjs": "^29.0.2",
127
- "@rollup/plugin-json": "^6.1.0",
128
- "@rollup/plugin-node-resolve": "^16.0.3",
129
- "@rollup/plugin-replace": "^6.0.3",
130
- "@rollup/plugin-terser": "^0.4.4",
131
120
  "@vue/server-renderer": "^3.5.34",
132
121
  "chokidar": "^3.6.0",
133
122
  "commander": "^14.0.3",
123
+ "cpx2": "^9.0.0",
134
124
  "esbuild": "^0.27.7",
135
125
  "esbuild-plugin-vue3": "^0.5.1",
136
126
  "koffi": "^2.16.2",
137
- "rollup": "^4.60.3",
138
- "rollup-plugin-esbuild": "^6.2.1",
139
- "rollup-plugin-vue": "^6.0.0",
140
127
  "sharp": "^0.34.5",
141
128
  "ts-loader": "9.5.4",
142
129
  "ts-node": "^10.9.2",
@@ -156,16 +143,13 @@
156
143
  "@types/react-dom": "^19.2.3",
157
144
  "@types/ws": "^8.18.1",
158
145
  "@vue/tsconfig": "^0.8.1",
159
- "better-sqlite3": "^12.9.0",
160
- "copyfiles": "^2.4.1",
161
146
  "image-size": "^2.0.2",
162
147
  "mysql2": "^3.22.3",
163
148
  "pg": "^8.20.0",
164
- "sqlite3": "^5.1.7",
165
149
  "vue": "^3.5.34",
166
150
  "vue-tsc": "^3.2.8"
167
151
  },
168
152
  "scripts": {
169
- "build": "tsc && copyfiles -u 1 \"src/**/*.{vue,d.ts}\" dist"
153
+ "build": "tsc && npx cpx2 \"src/**/**/**/*.{vue,d.ts}\" dist"
170
154
  }
171
155
  }
@@ -1,2 +0,0 @@
1
- import React from "react";
2
- export default function BuildingScreen(): React.JSX.Element;