hightjs 0.1.1
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/.idea/HightJS.iml +9 -0
- package/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +13 -0
- package/.idea/libraries/test_package.xml +9 -0
- package/.idea/libraries/ts_commonjs_default_export.xml +9 -0
- package/.idea/misc.xml +7 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +13 -0
- package/README.md +508 -0
- package/dist/adapters/express.d.ts +7 -0
- package/dist/adapters/express.js +63 -0
- package/dist/adapters/factory.d.ts +23 -0
- package/dist/adapters/factory.js +122 -0
- package/dist/adapters/fastify.d.ts +25 -0
- package/dist/adapters/fastify.js +61 -0
- package/dist/adapters/native.d.ts +8 -0
- package/dist/adapters/native.js +203 -0
- package/dist/adapters/starters/express.d.ts +0 -0
- package/dist/adapters/starters/express.js +1 -0
- package/dist/adapters/starters/factory.d.ts +0 -0
- package/dist/adapters/starters/factory.js +1 -0
- package/dist/adapters/starters/fastify.d.ts +0 -0
- package/dist/adapters/starters/fastify.js +1 -0
- package/dist/adapters/starters/index.d.ts +0 -0
- package/dist/adapters/starters/index.js +1 -0
- package/dist/adapters/starters/native.d.ts +0 -0
- package/dist/adapters/starters/native.js +1 -0
- package/dist/api/console.d.ts +92 -0
- package/dist/api/console.js +276 -0
- package/dist/api/http.d.ts +180 -0
- package/dist/api/http.js +467 -0
- package/dist/auth/client.d.ts +14 -0
- package/dist/auth/client.js +68 -0
- package/dist/auth/components.d.ts +29 -0
- package/dist/auth/components.js +84 -0
- package/dist/auth/core.d.ts +38 -0
- package/dist/auth/core.js +124 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.js +27 -0
- package/dist/auth/jwt.d.ts +41 -0
- package/dist/auth/jwt.js +169 -0
- package/dist/auth/providers.d.ts +5 -0
- package/dist/auth/providers.js +14 -0
- package/dist/auth/react/index.d.ts +6 -0
- package/dist/auth/react/index.js +32 -0
- package/dist/auth/react.d.ts +22 -0
- package/dist/auth/react.js +175 -0
- package/dist/auth/routes.d.ts +16 -0
- package/dist/auth/routes.js +104 -0
- package/dist/auth/types.d.ts +62 -0
- package/dist/auth/types.js +2 -0
- package/dist/bin/hightjs.d.ts +2 -0
- package/dist/bin/hightjs.js +35 -0
- package/dist/builder.d.ts +32 -0
- package/dist/builder.js +341 -0
- package/dist/client/DefaultNotFound.d.ts +1 -0
- package/dist/client/DefaultNotFound.js +53 -0
- package/dist/client/ErrorBoundary.d.ts +16 -0
- package/dist/client/ErrorBoundary.js +181 -0
- package/dist/client/clientRouter.d.ts +58 -0
- package/dist/client/clientRouter.js +116 -0
- package/dist/client/entry.client.d.ts +1 -0
- package/dist/client/entry.client.js +271 -0
- package/dist/client/routerContext.d.ts +26 -0
- package/dist/client/routerContext.js +62 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +8 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +13 -0
- package/dist/eslint/index.d.ts +32 -0
- package/dist/eslint/index.js +15 -0
- package/dist/eslint/use-client-rule.d.ts +19 -0
- package/dist/eslint/use-client-rule.js +99 -0
- package/dist/eslintSetup.d.ts +0 -0
- package/dist/eslintSetup.js +1 -0
- package/dist/example/src/web/routes/index.d.ts +3 -0
- package/dist/example/src/web/routes/index.js +15 -0
- package/dist/helpers.d.ts +18 -0
- package/dist/helpers.js +318 -0
- package/dist/hotReload.d.ts +23 -0
- package/dist/hotReload.js +292 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +480 -0
- package/dist/renderer.d.ts +14 -0
- package/dist/renderer.js +106 -0
- package/dist/router.d.ts +78 -0
- package/dist/router.js +359 -0
- package/dist/types/framework.d.ts +37 -0
- package/dist/types/framework.js +2 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.js +2 -0
- package/dist/typescript/use-client-plugin.d.ts +5 -0
- package/dist/typescript/use-client-plugin.js +113 -0
- package/dist/validation.d.ts +0 -0
- package/dist/validation.js +1 -0
- package/package.json +72 -0
- package/src/adapters/express.ts +70 -0
- package/src/adapters/factory.ts +96 -0
- package/src/adapters/fastify.ts +88 -0
- package/src/adapters/native.ts +223 -0
- package/src/api/console.ts +285 -0
- package/src/api/http.ts +515 -0
- package/src/auth/client.ts +74 -0
- package/src/auth/components.tsx +109 -0
- package/src/auth/core.ts +143 -0
- package/src/auth/index.ts +9 -0
- package/src/auth/jwt.ts +194 -0
- package/src/auth/providers.ts +13 -0
- package/src/auth/react/index.ts +9 -0
- package/src/auth/react.tsx +209 -0
- package/src/auth/routes.ts +133 -0
- package/src/auth/types.ts +73 -0
- package/src/bin/hightjs.js +40 -0
- package/src/builder.js +362 -0
- package/src/client/DefaultNotFound.tsx +68 -0
- package/src/client/clientRouter.ts +137 -0
- package/src/client/entry.client.tsx +302 -0
- package/src/client.ts +8 -0
- package/src/components/Link.tsx +22 -0
- package/src/helpers.ts +316 -0
- package/src/hotReload.ts +289 -0
- package/src/index.ts +514 -0
- package/src/renderer.tsx +122 -0
- package/src/router.ts +400 -0
- package/src/types/framework.ts +42 -0
- package/src/types.ts +54 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorBoundary = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
class ErrorBoundary extends react_1.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.state = { hasError: false };
|
|
10
|
+
}
|
|
11
|
+
static getDerivedStateFromError(error) {
|
|
12
|
+
// Atualiza o state para que a próxima renderização mostre a UI de erro
|
|
13
|
+
return { hasError: true, error };
|
|
14
|
+
}
|
|
15
|
+
componentDidCatch(error, errorInfo) {
|
|
16
|
+
console.error('ErrorBoundary capturou um erro:', error, errorInfo);
|
|
17
|
+
this.setState({
|
|
18
|
+
error,
|
|
19
|
+
errorInfo
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
render() {
|
|
23
|
+
if (this.state.hasError) {
|
|
24
|
+
return (0, jsx_runtime_1.jsx)(ErrorDisplay, { error: this.state.error, errorInfo: this.state.errorInfo });
|
|
25
|
+
}
|
|
26
|
+
return this.props.children;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
30
|
+
function ErrorDisplay({ error, errorInfo }) {
|
|
31
|
+
const isDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
32
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
33
|
+
fontFamily: 'system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
|
|
34
|
+
height: '100vh',
|
|
35
|
+
padding: '20px',
|
|
36
|
+
backgroundColor: isDark ? '#0a0a0a' : '#ffffff',
|
|
37
|
+
color: isDark ? '#fafafa' : '#171717',
|
|
38
|
+
overflow: 'auto'
|
|
39
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
40
|
+
maxWidth: '800px',
|
|
41
|
+
margin: '0 auto',
|
|
42
|
+
paddingTop: '40px'
|
|
43
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { style: {
|
|
44
|
+
borderBottom: `1px solid ${isDark ? '#262626' : '#e5e5e5'}`,
|
|
45
|
+
paddingBottom: '20px',
|
|
46
|
+
marginBottom: '30px'
|
|
47
|
+
}, children: [(0, jsx_runtime_1.jsx)("h1", { style: {
|
|
48
|
+
fontSize: '24px',
|
|
49
|
+
fontWeight: '600',
|
|
50
|
+
margin: '0 0 10px 0',
|
|
51
|
+
color: '#dc2626'
|
|
52
|
+
}, children: "\u274C Erro na Aplica\u00E7\u00E3o" }), (0, jsx_runtime_1.jsx)("p", { style: {
|
|
53
|
+
fontSize: '16px',
|
|
54
|
+
margin: '0',
|
|
55
|
+
color: isDark ? '#a3a3a3' : '#737373'
|
|
56
|
+
}, children: "Ocorreu um erro inesperado na aplica\u00E7\u00E3o. Veja os detalhes abaixo:" })] }), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
57
|
+
backgroundColor: isDark ? '#1c1917' : '#fef2f2',
|
|
58
|
+
border: `1px solid ${isDark ? '#451a03' : '#fecaca'}`,
|
|
59
|
+
borderRadius: '8px',
|
|
60
|
+
padding: '20px',
|
|
61
|
+
marginBottom: '20px'
|
|
62
|
+
}, children: [(0, jsx_runtime_1.jsx)("h2", { style: {
|
|
63
|
+
fontSize: '18px',
|
|
64
|
+
fontWeight: '600',
|
|
65
|
+
margin: '0 0 10px 0',
|
|
66
|
+
color: '#dc2626'
|
|
67
|
+
}, children: "Mensagem do Erro:" }), (0, jsx_runtime_1.jsx)("p", { style: {
|
|
68
|
+
fontSize: '14px',
|
|
69
|
+
fontFamily: 'Consolas, Monaco, "Courier New", monospace',
|
|
70
|
+
backgroundColor: isDark ? '#0c0a09' : '#ffffff',
|
|
71
|
+
padding: '15px',
|
|
72
|
+
borderRadius: '6px',
|
|
73
|
+
border: `1px solid ${isDark ? '#292524' : '#e5e5e5'}`,
|
|
74
|
+
margin: '0',
|
|
75
|
+
whiteSpace: 'pre-wrap',
|
|
76
|
+
overflow: 'auto'
|
|
77
|
+
}, children: error?.message || 'Erro desconhecido' })] }), error?.stack && ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
78
|
+
backgroundColor: isDark ? '#0c0a09' : '#fafafa',
|
|
79
|
+
border: `1px solid ${isDark ? '#292524' : '#e5e5e5'}`,
|
|
80
|
+
borderRadius: '8px',
|
|
81
|
+
padding: '20px',
|
|
82
|
+
marginBottom: '20px'
|
|
83
|
+
}, children: [(0, jsx_runtime_1.jsx)("h2", { style: {
|
|
84
|
+
fontSize: '18px',
|
|
85
|
+
fontWeight: '600',
|
|
86
|
+
margin: '0 0 10px 0',
|
|
87
|
+
color: isDark ? '#fafafa' : '#171717'
|
|
88
|
+
}, children: "Stack Trace:" }), (0, jsx_runtime_1.jsx)("pre", { style: {
|
|
89
|
+
fontSize: '12px',
|
|
90
|
+
fontFamily: 'Consolas, Monaco, "Courier New", monospace',
|
|
91
|
+
backgroundColor: isDark ? '#1c1917' : '#ffffff',
|
|
92
|
+
padding: '15px',
|
|
93
|
+
borderRadius: '6px',
|
|
94
|
+
border: `1px solid ${isDark ? '#44403c' : '#d4d4d4'}`,
|
|
95
|
+
margin: '0',
|
|
96
|
+
overflow: 'auto',
|
|
97
|
+
whiteSpace: 'pre-wrap',
|
|
98
|
+
color: isDark ? '#e5e5e5' : '#525252'
|
|
99
|
+
}, children: error.stack })] })), errorInfo?.componentStack && ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
100
|
+
backgroundColor: isDark ? '#0c0a09' : '#fafafa',
|
|
101
|
+
border: `1px solid ${isDark ? '#292524' : '#e5e5e5'}`,
|
|
102
|
+
borderRadius: '8px',
|
|
103
|
+
padding: '20px',
|
|
104
|
+
marginBottom: '20px'
|
|
105
|
+
}, children: [(0, jsx_runtime_1.jsx)("h2", { style: {
|
|
106
|
+
fontSize: '18px',
|
|
107
|
+
fontWeight: '600',
|
|
108
|
+
margin: '0 0 10px 0',
|
|
109
|
+
color: isDark ? '#fafafa' : '#171717'
|
|
110
|
+
}, children: "Component Stack:" }), (0, jsx_runtime_1.jsx)("pre", { style: {
|
|
111
|
+
fontSize: '12px',
|
|
112
|
+
fontFamily: 'Consolas, Monaco, "Courier New", monospace',
|
|
113
|
+
backgroundColor: isDark ? '#1c1917' : '#ffffff',
|
|
114
|
+
padding: '15px',
|
|
115
|
+
borderRadius: '6px',
|
|
116
|
+
border: `1px solid ${isDark ? '#44403c' : '#d4d4d4'}`,
|
|
117
|
+
margin: '0',
|
|
118
|
+
overflow: 'auto',
|
|
119
|
+
whiteSpace: 'pre-wrap',
|
|
120
|
+
color: isDark ? '#e5e5e5' : '#525252'
|
|
121
|
+
}, children: errorInfo.componentStack })] })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
122
|
+
display: 'flex',
|
|
123
|
+
gap: '10px',
|
|
124
|
+
marginTop: '30px'
|
|
125
|
+
}, children: [(0, jsx_runtime_1.jsx)("button", { onClick: () => window.location.reload(), style: {
|
|
126
|
+
backgroundColor: '#2563eb',
|
|
127
|
+
color: '#ffffff',
|
|
128
|
+
border: 'none',
|
|
129
|
+
padding: '12px 20px',
|
|
130
|
+
borderRadius: '6px',
|
|
131
|
+
fontSize: '14px',
|
|
132
|
+
fontWeight: '500',
|
|
133
|
+
cursor: 'pointer',
|
|
134
|
+
transition: 'background-color 0.2s'
|
|
135
|
+
}, onMouseEnter: (e) => {
|
|
136
|
+
e.currentTarget.style.backgroundColor = '#1d4ed8';
|
|
137
|
+
}, onMouseLeave: (e) => {
|
|
138
|
+
e.currentTarget.style.backgroundColor = '#2563eb';
|
|
139
|
+
}, children: "\uD83D\uDD04 Recarregar P\u00E1gina" }), (0, jsx_runtime_1.jsx)("button", { onClick: () => {
|
|
140
|
+
navigator.clipboard?.writeText(`
|
|
141
|
+
Erro: ${error?.message || 'Erro desconhecido'}
|
|
142
|
+
|
|
143
|
+
Stack Trace:
|
|
144
|
+
${error?.stack || 'N/A'}
|
|
145
|
+
|
|
146
|
+
Component Stack:
|
|
147
|
+
${errorInfo?.componentStack || 'N/A'}
|
|
148
|
+
`.trim());
|
|
149
|
+
alert('Detalhes do erro copiados para a área de transferência!');
|
|
150
|
+
}, style: {
|
|
151
|
+
backgroundColor: isDark ? '#374151' : '#f3f4f6',
|
|
152
|
+
color: isDark ? '#fafafa' : '#171717',
|
|
153
|
+
border: `1px solid ${isDark ? '#4b5563' : '#d1d5db'}`,
|
|
154
|
+
padding: '12px 20px',
|
|
155
|
+
borderRadius: '6px',
|
|
156
|
+
fontSize: '14px',
|
|
157
|
+
fontWeight: '500',
|
|
158
|
+
cursor: 'pointer',
|
|
159
|
+
transition: 'background-color 0.2s'
|
|
160
|
+
}, onMouseEnter: (e) => {
|
|
161
|
+
e.currentTarget.style.backgroundColor = isDark ? '#4b5563' : '#e5e7eb';
|
|
162
|
+
}, onMouseLeave: (e) => {
|
|
163
|
+
e.currentTarget.style.backgroundColor = isDark ? '#374151' : '#f3f4f6';
|
|
164
|
+
}, children: "\uD83D\uDCCB Copiar Detalhes" })] }), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
165
|
+
marginTop: '40px',
|
|
166
|
+
padding: '20px',
|
|
167
|
+
backgroundColor: isDark ? '#1e1b1a' : '#f8fafc',
|
|
168
|
+
border: `1px solid ${isDark ? '#3c2e2a' : '#e2e8f0'}`,
|
|
169
|
+
borderRadius: '8px'
|
|
170
|
+
}, children: [(0, jsx_runtime_1.jsx)("h3", { style: {
|
|
171
|
+
fontSize: '16px',
|
|
172
|
+
fontWeight: '600',
|
|
173
|
+
margin: '0 0 10px 0',
|
|
174
|
+
color: isDark ? '#fbbf24' : '#d97706'
|
|
175
|
+
}, children: "\uD83D\uDCA1 Para Desenvolvedores:" }), (0, jsx_runtime_1.jsxs)("ul", { style: {
|
|
176
|
+
fontSize: '14px',
|
|
177
|
+
margin: '0',
|
|
178
|
+
paddingLeft: '20px',
|
|
179
|
+
color: isDark ? '#d1d5db' : '#4b5563'
|
|
180
|
+
}, children: [(0, jsx_runtime_1.jsx)("li", { children: "Verifique o console do navegador para mais detalhes" }), (0, jsx_runtime_1.jsx)("li", { children: "Verifique se todos os arquivos foram buildados corretamente" }), (0, jsx_runtime_1.jsx)("li", { children: "Se for erro 404 em main.js, verifique se o servidor est\u00E1 rodando" }), (0, jsx_runtime_1.jsx)("li", { children: "Use as ferramentas de desenvolvimento do navegador para debugar" })] })] })] }) }));
|
|
181
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export interface RouterEvents {
|
|
2
|
+
beforeNavigate?: (url: string) => boolean | Promise<boolean>;
|
|
3
|
+
afterNavigate?: (url: string) => void;
|
|
4
|
+
}
|
|
5
|
+
declare class Router {
|
|
6
|
+
private events;
|
|
7
|
+
private listeners;
|
|
8
|
+
/**
|
|
9
|
+
* Navega para uma nova rota
|
|
10
|
+
*/
|
|
11
|
+
push(url: string): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Substitui a entrada atual do histórico
|
|
14
|
+
*/
|
|
15
|
+
replace(url: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Volta uma página no histórico
|
|
18
|
+
*/
|
|
19
|
+
back(): void;
|
|
20
|
+
/**
|
|
21
|
+
* Avança uma página no histórico
|
|
22
|
+
*/
|
|
23
|
+
forward(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Recarrega a página atual (re-renderiza o componente)
|
|
26
|
+
*/
|
|
27
|
+
refresh(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Obtém a URL atual
|
|
30
|
+
*/
|
|
31
|
+
get pathname(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Obtém os query parameters atuais
|
|
34
|
+
*/
|
|
35
|
+
get query(): URLSearchParams;
|
|
36
|
+
/**
|
|
37
|
+
* Obtém a URL completa atual
|
|
38
|
+
*/
|
|
39
|
+
get url(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Adiciona event listeners para eventos de roteamento
|
|
42
|
+
*/
|
|
43
|
+
on(events: RouterEvents): void;
|
|
44
|
+
/**
|
|
45
|
+
* Remove event listeners
|
|
46
|
+
*/
|
|
47
|
+
off(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Adiciona um listener para mudanças de rota
|
|
50
|
+
*/
|
|
51
|
+
subscribe(listener: () => void): () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Dispara evento de navegação para todos os listeners
|
|
54
|
+
*/
|
|
55
|
+
private triggerNavigation;
|
|
56
|
+
}
|
|
57
|
+
export declare const router: Router;
|
|
58
|
+
export default router;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Sistema de roteamento do lado do cliente para hweb-sdk
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.router = void 0;
|
|
5
|
+
class Router {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.events = {};
|
|
8
|
+
this.listeners = new Set();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Navega para uma nova rota
|
|
12
|
+
*/
|
|
13
|
+
async push(url) {
|
|
14
|
+
// Callback antes de navegar
|
|
15
|
+
if (this.events.beforeNavigate) {
|
|
16
|
+
const shouldProceed = await this.events.beforeNavigate(url);
|
|
17
|
+
if (shouldProceed === false)
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// Atualiza a URL na barra de endereço
|
|
21
|
+
window.history.pushState({ path: url }, '', url);
|
|
22
|
+
// Dispara evento para o roteador capturar de forma assíncrona
|
|
23
|
+
setTimeout(() => this.triggerNavigation(), 0);
|
|
24
|
+
// Callback após navegar
|
|
25
|
+
if (this.events.afterNavigate) {
|
|
26
|
+
this.events.afterNavigate(url);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Substitui a entrada atual do histórico
|
|
31
|
+
*/
|
|
32
|
+
async replace(url) {
|
|
33
|
+
// Callback antes de navegar
|
|
34
|
+
if (this.events.beforeNavigate) {
|
|
35
|
+
const shouldProceed = await this.events.beforeNavigate(url);
|
|
36
|
+
if (shouldProceed === false)
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Substitui a URL atual no histórico
|
|
40
|
+
window.history.replaceState({ path: url }, '', url);
|
|
41
|
+
// Dispara evento para o roteador capturar de forma assíncrona
|
|
42
|
+
setTimeout(() => this.triggerNavigation(), 0);
|
|
43
|
+
// Callback após navegar
|
|
44
|
+
if (this.events.afterNavigate) {
|
|
45
|
+
this.events.afterNavigate(url);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Volta uma página no histórico
|
|
50
|
+
*/
|
|
51
|
+
back() {
|
|
52
|
+
window.history.back();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Avança uma página no histórico
|
|
56
|
+
*/
|
|
57
|
+
forward() {
|
|
58
|
+
window.history.forward();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Recarrega a página atual (re-renderiza o componente)
|
|
62
|
+
*/
|
|
63
|
+
refresh() {
|
|
64
|
+
setTimeout(() => this.triggerNavigation(), 0);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Obtém a URL atual
|
|
68
|
+
*/
|
|
69
|
+
get pathname() {
|
|
70
|
+
return window.location.pathname;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Obtém os query parameters atuais
|
|
74
|
+
*/
|
|
75
|
+
get query() {
|
|
76
|
+
return new URLSearchParams(window.location.search);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Obtém a URL completa atual
|
|
80
|
+
*/
|
|
81
|
+
get url() {
|
|
82
|
+
return window.location.href;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Adiciona event listeners para eventos de roteamento
|
|
86
|
+
*/
|
|
87
|
+
on(events) {
|
|
88
|
+
this.events = { ...this.events, ...events };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Remove event listeners
|
|
92
|
+
*/
|
|
93
|
+
off() {
|
|
94
|
+
this.events = {};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Adiciona um listener para mudanças de rota
|
|
98
|
+
*/
|
|
99
|
+
subscribe(listener) {
|
|
100
|
+
this.listeners.add(listener);
|
|
101
|
+
return () => this.listeners.delete(listener);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Dispara evento de navegação para todos os listeners
|
|
105
|
+
*/
|
|
106
|
+
triggerNavigation() {
|
|
107
|
+
// Dispara o evento nativo para o roteador do hweb capturar
|
|
108
|
+
window.dispatchEvent(new PopStateEvent('popstate'));
|
|
109
|
+
// Notifica todos os listeners customizados
|
|
110
|
+
this.listeners.forEach(listener => listener());
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Instância singleton do router
|
|
114
|
+
exports.router = new Router();
|
|
115
|
+
// Para compatibilidade, também exporta como default
|
|
116
|
+
exports.default = exports.router;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const client_1 = require("react-dom/client");
|
|
39
|
+
const clientRouter_1 = require("./clientRouter");
|
|
40
|
+
function App({ componentMap, routes, initialComponentPath, initialParams, layoutComponent }) {
|
|
41
|
+
// Estado que guarda o componente a ser renderizado atualmente
|
|
42
|
+
const [CurrentPageComponent, setCurrentPageComponent] = (0, react_1.useState)(() => {
|
|
43
|
+
// Se for a rota especial __404__, não busca no componentMap
|
|
44
|
+
if (initialComponentPath === '__404__') {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return componentMap[initialComponentPath];
|
|
48
|
+
});
|
|
49
|
+
const [params, setParams] = (0, react_1.useState)(initialParams);
|
|
50
|
+
const findRouteForPath = (0, react_1.useCallback)((path) => {
|
|
51
|
+
for (const route of routes) {
|
|
52
|
+
const regexPattern = route.pattern.replace(/\[(\w+)\]/g, '(?<$1>[^/]+)');
|
|
53
|
+
const regex = new RegExp(`^${regexPattern}/?$`);
|
|
54
|
+
const match = path.match(regex);
|
|
55
|
+
if (match) {
|
|
56
|
+
return {
|
|
57
|
+
componentPath: route.componentPath,
|
|
58
|
+
params: match.groups || {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}, [routes]);
|
|
64
|
+
const updateRoute = (0, react_1.useCallback)(() => {
|
|
65
|
+
const currentPath = clientRouter_1.router.pathname;
|
|
66
|
+
const match = findRouteForPath(currentPath);
|
|
67
|
+
if (match) {
|
|
68
|
+
setCurrentPageComponent(() => componentMap[match.componentPath]);
|
|
69
|
+
setParams(match.params);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Se não encontrou rota, define como null para mostrar 404
|
|
73
|
+
setCurrentPageComponent(null);
|
|
74
|
+
setParams({});
|
|
75
|
+
}
|
|
76
|
+
}, [clientRouter_1.router.pathname, findRouteForPath, componentMap]);
|
|
77
|
+
// Ouve os eventos de "voltar" e "avançar" do navegador
|
|
78
|
+
(0, react_1.useEffect)(() => {
|
|
79
|
+
const handlePopState = () => {
|
|
80
|
+
updateRoute();
|
|
81
|
+
};
|
|
82
|
+
window.addEventListener('popstate', handlePopState);
|
|
83
|
+
// Também se inscreve no router para mudanças de rota
|
|
84
|
+
const unsubscribe = clientRouter_1.router.subscribe(updateRoute);
|
|
85
|
+
return () => {
|
|
86
|
+
window.removeEventListener('popstate', handlePopState);
|
|
87
|
+
unsubscribe();
|
|
88
|
+
};
|
|
89
|
+
}, [updateRoute]);
|
|
90
|
+
// Se não há componente ou é a rota __404__, mostra página 404
|
|
91
|
+
if (!CurrentPageComponent || initialComponentPath === '__404__') {
|
|
92
|
+
// Usa o componente 404 personalizado se existir, senão usa o padrão do hweb
|
|
93
|
+
const NotFoundComponent = window.__HWEB_NOT_FOUND__;
|
|
94
|
+
if (NotFoundComponent) {
|
|
95
|
+
// Usa o notFound.tsx personalizado do usuário
|
|
96
|
+
const NotFoundContent = (0, jsx_runtime_1.jsx)(NotFoundComponent, {});
|
|
97
|
+
// Aplica o layout se existir
|
|
98
|
+
if (layoutComponent) {
|
|
99
|
+
return react_1.default.createElement(layoutComponent, { children: NotFoundContent });
|
|
100
|
+
}
|
|
101
|
+
return NotFoundContent;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Usa o 404 padrão do hweb que foi incluído no build
|
|
105
|
+
const DefaultNotFound = window.__HWEB_DEFAULT_NOT_FOUND__;
|
|
106
|
+
const NotFoundContent = (0, jsx_runtime_1.jsx)(DefaultNotFound, {});
|
|
107
|
+
// Aplica o layout se existir
|
|
108
|
+
if (layoutComponent) {
|
|
109
|
+
return react_1.default.createElement(layoutComponent, { children: NotFoundContent });
|
|
110
|
+
}
|
|
111
|
+
return NotFoundContent;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Renderiza o componente atual (sem Context, usa o router diretamente)
|
|
115
|
+
const PageContent = (0, jsx_runtime_1.jsx)(CurrentPageComponent, { params: params });
|
|
116
|
+
// SEMPRE usa o layout - se não existir, cria um wrapper padrão
|
|
117
|
+
const content = layoutComponent
|
|
118
|
+
? react_1.default.createElement(layoutComponent, { children: PageContent })
|
|
119
|
+
: (0, jsx_runtime_1.jsx)("div", { children: PageContent });
|
|
120
|
+
// Adiciona o indicador de dev se não for produção
|
|
121
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [content, process.env.NODE_ENV !== 'production' && (0, jsx_runtime_1.jsx)(DevIndicator, {})] }));
|
|
122
|
+
}
|
|
123
|
+
// --- Constantes de Configuração ---
|
|
124
|
+
const DEV_INDICATOR_SIZE = 48;
|
|
125
|
+
const DEV_INDICATOR_CORNERS = [
|
|
126
|
+
{ top: 16, left: 16 }, // 0: topo-esquerda
|
|
127
|
+
{ top: 16, right: 16 }, // 1: topo-direita
|
|
128
|
+
{ bottom: 16, left: 16 }, // 2: baixo-esquerda
|
|
129
|
+
{ bottom: 16, right: 16 }, // 3: baixo-direita
|
|
130
|
+
];
|
|
131
|
+
function DevIndicator() {
|
|
132
|
+
const [corner, setCorner] = (0, react_1.useState)(3); // Canto atual (0-3)
|
|
133
|
+
const [isDragging, setIsDragging] = (0, react_1.useState)(false); // Estado de arrastar
|
|
134
|
+
// Posição visual do indicador durante o arraste
|
|
135
|
+
const [position, setPosition] = (0, react_1.useState)({ top: 0, left: 0 });
|
|
136
|
+
const indicatorRef = (0, react_1.useRef)(null);
|
|
137
|
+
const dragStartRef = (0, react_1.useRef)(null);
|
|
138
|
+
// --- Estilos Dinâmicos ---
|
|
139
|
+
const getIndicatorStyle = () => {
|
|
140
|
+
const baseStyle = {
|
|
141
|
+
position: 'fixed',
|
|
142
|
+
zIndex: 9999,
|
|
143
|
+
width: DEV_INDICATOR_SIZE,
|
|
144
|
+
height: DEV_INDICATOR_SIZE,
|
|
145
|
+
borderRadius: '50%',
|
|
146
|
+
background: 'linear-gradient(135deg, #8e2de2, #4a00e0)', // Gradiente Roxo
|
|
147
|
+
color: 'white',
|
|
148
|
+
fontWeight: 'bold',
|
|
149
|
+
fontSize: 28,
|
|
150
|
+
boxShadow: '0 4px 15px rgba(0,0,0,0.2)',
|
|
151
|
+
display: 'flex',
|
|
152
|
+
alignItems: 'center',
|
|
153
|
+
justifyContent: 'center',
|
|
154
|
+
cursor: isDragging ? 'grabbing' : 'grab',
|
|
155
|
+
userSelect: 'none',
|
|
156
|
+
transition: isDragging ? 'none' : 'all 0.3s ease-out', // Animação suave ao soltar
|
|
157
|
+
};
|
|
158
|
+
if (isDragging) {
|
|
159
|
+
return {
|
|
160
|
+
...baseStyle,
|
|
161
|
+
top: position.top,
|
|
162
|
+
left: position.left,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
return { ...baseStyle, ...DEV_INDICATOR_CORNERS[corner] };
|
|
166
|
+
};
|
|
167
|
+
const getMenuPositionStyle = () => {
|
|
168
|
+
// Posiciona o menu dependendo do canto
|
|
169
|
+
switch (corner) {
|
|
170
|
+
case 0: return { top: '110%', left: '0' }; // Top-Left
|
|
171
|
+
case 1: return { top: '110%', right: '0' }; // Top-Right
|
|
172
|
+
case 2: return { bottom: '110%', left: '0' }; // Bottom-Left
|
|
173
|
+
case 3: return { bottom: '110%', right: '0' }; // Bottom-Right
|
|
174
|
+
default: return {};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
// --- Lógica de Eventos ---
|
|
178
|
+
const handleMouseDown = (e) => {
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
dragStartRef.current = { x: e.clientX, y: e.clientY, moved: false };
|
|
181
|
+
if (indicatorRef.current) {
|
|
182
|
+
const rect = indicatorRef.current.getBoundingClientRect();
|
|
183
|
+
setPosition({ top: rect.top, left: rect.left });
|
|
184
|
+
}
|
|
185
|
+
setIsDragging(true);
|
|
186
|
+
};
|
|
187
|
+
const handleMouseMove = (0, react_1.useCallback)((e) => {
|
|
188
|
+
if (!isDragging || !dragStartRef.current)
|
|
189
|
+
return;
|
|
190
|
+
const deltaX = e.clientX - dragStartRef.current.x;
|
|
191
|
+
const deltaY = e.clientY - dragStartRef.current.y;
|
|
192
|
+
// Diferencia clique de arrastar (threshold de 5px)
|
|
193
|
+
if (!dragStartRef.current.moved && Math.hypot(deltaX, deltaY) > 5) {
|
|
194
|
+
dragStartRef.current.moved = true;
|
|
195
|
+
}
|
|
196
|
+
if (dragStartRef.current.moved) {
|
|
197
|
+
setPosition(prevPos => ({
|
|
198
|
+
top: prevPos.top + deltaY,
|
|
199
|
+
left: prevPos.left + deltaX,
|
|
200
|
+
}));
|
|
201
|
+
// Atualiza a referência para o próximo movimento
|
|
202
|
+
dragStartRef.current.x = e.clientX;
|
|
203
|
+
dragStartRef.current.y = e.clientY;
|
|
204
|
+
}
|
|
205
|
+
}, [isDragging]);
|
|
206
|
+
const handleMouseUp = (0, react_1.useCallback)((e) => {
|
|
207
|
+
if (!isDragging)
|
|
208
|
+
return;
|
|
209
|
+
setIsDragging(false);
|
|
210
|
+
// Se moveu, calcula o canto mais próximo
|
|
211
|
+
if (dragStartRef.current?.moved) {
|
|
212
|
+
const { clientX, clientY } = e;
|
|
213
|
+
const w = window.innerWidth;
|
|
214
|
+
const h = window.innerHeight;
|
|
215
|
+
const dists = [
|
|
216
|
+
Math.hypot(clientX, clientY), // TL
|
|
217
|
+
Math.hypot(w - clientX, clientY), // TR
|
|
218
|
+
Math.hypot(clientX, h - clientY), // BL
|
|
219
|
+
Math.hypot(w - clientX, h - clientY), // BR
|
|
220
|
+
];
|
|
221
|
+
setCorner(dists.indexOf(Math.min(...dists)));
|
|
222
|
+
}
|
|
223
|
+
dragStartRef.current = null;
|
|
224
|
+
}, [isDragging]);
|
|
225
|
+
// Adiciona e remove listeners globais
|
|
226
|
+
(0, react_1.useEffect)(() => {
|
|
227
|
+
if (isDragging) {
|
|
228
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
229
|
+
window.addEventListener('mouseup', handleMouseUp);
|
|
230
|
+
}
|
|
231
|
+
return () => {
|
|
232
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
233
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
234
|
+
};
|
|
235
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
236
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: indicatorRef, style: getIndicatorStyle(), onMouseDown: handleMouseDown, title: "Modo Dev HightJS", children: "H" }));
|
|
237
|
+
}
|
|
238
|
+
// --- Inicialização do Cliente (CSR - Client-Side Rendering) ---
|
|
239
|
+
function initializeClient() {
|
|
240
|
+
const initialData = window.__HWEB_INITIAL_DATA__;
|
|
241
|
+
if (!initialData) {
|
|
242
|
+
console.error('[hweb] Dados iniciais não encontrados na página.');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
// Cria o mapa de componentes dinamicamente a partir dos módulos carregados
|
|
246
|
+
const componentMap = {};
|
|
247
|
+
// Registra todos os componentes que foram importados
|
|
248
|
+
if (window.__HWEB_COMPONENTS__) {
|
|
249
|
+
Object.assign(componentMap, window.__HWEB_COMPONENTS__);
|
|
250
|
+
}
|
|
251
|
+
const container = document.getElementById('root');
|
|
252
|
+
if (!container) {
|
|
253
|
+
console.error('[hweb] Container #root não encontrado.');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
// Usar createRoot para render inicial (CSR)
|
|
258
|
+
const root = (0, client_1.createRoot)(container);
|
|
259
|
+
root.render((0, jsx_runtime_1.jsx)(App, { componentMap: componentMap, routes: initialData.routes, initialComponentPath: initialData.initialComponentPath, initialParams: initialData.initialParams, layoutComponent: window.__HWEB_LAYOUT__ }));
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
console.error('[hweb] Erro ao renderizar aplicação:', error);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
// Executa quando o DOM estiver pronto
|
|
266
|
+
if (document.readyState === 'loading') {
|
|
267
|
+
document.addEventListener('DOMContentLoaded', initializeClient);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
initializeClient();
|
|
271
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface RouterContextType {
|
|
3
|
+
pathname: string;
|
|
4
|
+
query: URLSearchParams;
|
|
5
|
+
push: (url: string) => Promise<void>;
|
|
6
|
+
replace: (url: string) => Promise<void>;
|
|
7
|
+
back: () => void;
|
|
8
|
+
forward: () => void;
|
|
9
|
+
refresh: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function RouterProvider({ children }: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* Hook para acessar o router dentro de componentes React
|
|
16
|
+
*/
|
|
17
|
+
export declare function useRouter(): RouterContextType;
|
|
18
|
+
/**
|
|
19
|
+
* Hook para acessar apenas o pathname atual
|
|
20
|
+
*/
|
|
21
|
+
export declare function usePathname(): string;
|
|
22
|
+
/**
|
|
23
|
+
* Hook para acessar apenas os query parameters
|
|
24
|
+
*/
|
|
25
|
+
export declare function useSearchParams(): URLSearchParams;
|
|
26
|
+
export {};
|