hightjs 0.4.0 → 0.5.0

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 (125) hide show
  1. package/README.md +48 -116
  2. package/dist/bin/hightjs.js +51 -23
  3. package/dist/builder.js +139 -4
  4. package/dist/client/DefaultNotFound.d.ts +1 -1
  5. package/dist/client/DefaultNotFound.js +72 -46
  6. package/dist/client/client.d.ts +3 -0
  7. package/dist/{client.js → client/client.js} +4 -4
  8. package/dist/client/entry.client.js +39 -29
  9. package/dist/global/global.d.ts +117 -0
  10. package/dist/{auth/types.js → global/global.js} +0 -1
  11. package/dist/helpers.js +80 -2
  12. package/dist/hotReload.js +2 -2
  13. package/dist/index.js +16 -16
  14. package/dist/loaders.d.ts +1 -0
  15. package/dist/loaders.js +46 -0
  16. package/dist/renderer.js +158 -4
  17. package/dist/types.d.ts +44 -0
  18. package/package.json +36 -31
  19. package/.idea/HightJS.iml +0 -9
  20. package/.idea/copilot.data.migration.agent.xml +0 -6
  21. package/.idea/copilot.data.migration.ask.xml +0 -6
  22. package/.idea/copilot.data.migration.ask2agent.xml +0 -6
  23. package/.idea/copilot.data.migration.edit.xml +0 -6
  24. package/.idea/copilotDiffState.xml +0 -67
  25. package/.idea/inspectionProfiles/Project_Default.xml +0 -13
  26. package/.idea/libraries/test_package.xml +0 -9
  27. package/.idea/libraries/ts_commonjs_default_export.xml +0 -9
  28. package/.idea/misc.xml +0 -7
  29. package/.idea/modules.xml +0 -8
  30. package/.idea/vcs.xml +0 -6
  31. package/dist/auth/client.d.ts +0 -24
  32. package/dist/auth/client.js +0 -146
  33. package/dist/auth/components.d.ts +0 -29
  34. package/dist/auth/components.js +0 -100
  35. package/dist/auth/core.d.ts +0 -55
  36. package/dist/auth/core.js +0 -189
  37. package/dist/auth/index.d.ts +0 -7
  38. package/dist/auth/index.js +0 -45
  39. package/dist/auth/jwt.d.ts +0 -41
  40. package/dist/auth/jwt.js +0 -185
  41. package/dist/auth/providers/credentials.d.ts +0 -60
  42. package/dist/auth/providers/credentials.js +0 -97
  43. package/dist/auth/providers/discord.d.ts +0 -63
  44. package/dist/auth/providers/discord.js +0 -190
  45. package/dist/auth/providers/google.d.ts +0 -63
  46. package/dist/auth/providers/google.js +0 -186
  47. package/dist/auth/providers/index.d.ts +0 -2
  48. package/dist/auth/providers/index.js +0 -35
  49. package/dist/auth/providers.d.ts +0 -3
  50. package/dist/auth/providers.js +0 -26
  51. package/dist/auth/react/index.d.ts +0 -6
  52. package/dist/auth/react/index.js +0 -48
  53. package/dist/auth/react.d.ts +0 -22
  54. package/dist/auth/react.js +0 -199
  55. package/dist/auth/routes.d.ts +0 -16
  56. package/dist/auth/routes.js +0 -152
  57. package/dist/auth/types.d.ts +0 -76
  58. package/dist/client.d.ts +0 -3
  59. package/docs/README.md +0 -58
  60. package/docs/arquivos-especiais.md +0 -10
  61. package/docs/autenticacao.md +0 -212
  62. package/docs/checklist.md +0 -9
  63. package/docs/cli.md +0 -72
  64. package/docs/config.md +0 -216
  65. package/docs/estrutura.md +0 -20
  66. package/docs/faq.md +0 -10
  67. package/docs/hot-reload.md +0 -5
  68. package/docs/integracoes.md +0 -240
  69. package/docs/middlewares.md +0 -73
  70. package/docs/rotas-backend.md +0 -45
  71. package/docs/rotas-frontend.md +0 -66
  72. package/docs/seguranca.md +0 -8
  73. package/docs/websocket.md +0 -45
  74. package/example/certs/cert.pem +0 -20
  75. package/example/certs/key.pem +0 -27
  76. package/example/hightjs.config.ts +0 -87
  77. package/example/package-lock.json +0 -1174
  78. package/example/package.json +0 -26
  79. package/example/postcss.config.js +0 -8
  80. package/example/src/backend/auth.ts +0 -42
  81. package/example/src/backend/routes/auth.ts +0 -3
  82. package/example/src/backend/routes/version.ts +0 -13
  83. package/example/src/web/components/Home.tsx +0 -140
  84. package/example/src/web/components/LoginPage.tsx +0 -149
  85. package/example/src/web/globals.css +0 -5
  86. package/example/src/web/layout.tsx +0 -100
  87. package/example/src/web/routes/index.tsx +0 -13
  88. package/example/src/web/routes/login.tsx +0 -30
  89. package/example/tailwind.config.js +0 -12
  90. package/example/tsconfig.json +0 -15
  91. package/src/adapters/express.ts +0 -87
  92. package/src/adapters/factory.ts +0 -112
  93. package/src/adapters/fastify.ts +0 -104
  94. package/src/adapters/native.ts +0 -234
  95. package/src/api/console.ts +0 -305
  96. package/src/api/http.ts +0 -535
  97. package/src/auth/client.ts +0 -171
  98. package/src/auth/components.tsx +0 -125
  99. package/src/auth/core.ts +0 -215
  100. package/src/auth/index.ts +0 -25
  101. package/src/auth/jwt.ts +0 -210
  102. package/src/auth/providers/credentials.ts +0 -139
  103. package/src/auth/providers/discord.ts +0 -239
  104. package/src/auth/providers/google.ts +0 -234
  105. package/src/auth/providers/index.ts +0 -20
  106. package/src/auth/providers.ts +0 -20
  107. package/src/auth/react/index.ts +0 -25
  108. package/src/auth/react.tsx +0 -234
  109. package/src/auth/routes.ts +0 -183
  110. package/src/auth/types.ts +0 -108
  111. package/src/bin/hightjs.js +0 -222
  112. package/src/builder.js +0 -472
  113. package/src/client/DefaultNotFound.tsx +0 -84
  114. package/src/client/clientRouter.ts +0 -153
  115. package/src/client/entry.client.tsx +0 -511
  116. package/src/client.ts +0 -24
  117. package/src/components/Link.tsx +0 -38
  118. package/src/helpers.ts +0 -542
  119. package/src/hotReload.ts +0 -569
  120. package/src/index.ts +0 -555
  121. package/src/renderer.tsx +0 -263
  122. package/src/router.ts +0 -730
  123. package/src/types/framework.ts +0 -58
  124. package/src/types.ts +0 -207
  125. package/tsconfig.json +0 -17
@@ -1,511 +0,0 @@
1
- /*
2
- * This file is part of the HightJS Project.
3
- * Copyright (c) 2025 itsmuzin
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import React, {useState, useEffect, useCallback, useRef} from 'react';
18
- import { createRoot } from 'react-dom/client';
19
- import { router } from './clientRouter';
20
-
21
- // --- O Componente Principal do Cliente (Roteador) ---
22
-
23
- interface AppProps {
24
- componentMap: Record<string, any>;
25
- routes: { pattern: string; componentPath: string }[];
26
- initialComponentPath: string;
27
- initialParams: any;
28
- layoutComponent?: any;
29
- }
30
-
31
- function App({ componentMap, routes, initialComponentPath, initialParams, layoutComponent }: AppProps) {
32
- // Estado que guarda o componente a ser renderizado atualmente
33
- const [hmrTimestamp, setHmrTimestamp] = useState(Date.now());
34
- const [CurrentPageComponent, setCurrentPageComponent] = useState(() => {
35
- // Se for a rota especial __404__, não busca no componentMap
36
- if (initialComponentPath === '__404__') {
37
- return null;
38
- }
39
- return componentMap[initialComponentPath];
40
- });
41
- const [params, setParams] = useState(initialParams);
42
-
43
- // HMR: Escuta eventos de hot reload
44
- useEffect(() => {
45
- // Ativa o sistema de HMR
46
- (window as any).__HWEB_HMR__ = true;
47
-
48
- const handleHMRUpdate = async (event: CustomEvent) => {
49
- const { file, timestamp } = event.detail;
50
- const fileName = file ? file.split('/').pop()?.split('\\').pop() : 'unknown';
51
- console.log('🔥 HMR: Hot reloading...', fileName);
52
-
53
- try {
54
- // Aguarda um pouco para o esbuild terminar de recompilar
55
- await new Promise(resolve => setTimeout(resolve, 300));
56
-
57
- // Re-importa o módulo principal com cache busting
58
- const mainScript = document.querySelector('script[src*="main.js"]') as HTMLScriptElement;
59
- if (mainScript) {
60
- const mainSrc = mainScript.src.split('?')[0];
61
- const cacheBustedSrc = `${mainSrc}?t=${timestamp}`;
62
-
63
- // Cria novo script
64
- const newScript = document.createElement('script');
65
- newScript.type = 'module';
66
- newScript.src = cacheBustedSrc;
67
-
68
- // Quando o novo script carregar, força re-render
69
- newScript.onload = () => {
70
- console.log('✅ HMR: Modules reloaded');
71
-
72
- // Força re-render do componente
73
- setHmrTimestamp(timestamp);
74
-
75
- // Marca sucesso
76
- (window as any).__HMR_SUCCESS__ = true;
77
- setTimeout(() => {
78
- (window as any).__HMR_SUCCESS__ = false;
79
- }, 3000);
80
- };
81
-
82
- newScript.onerror = () => {
83
- console.error('❌ HMR: Failed to reload modules');
84
- (window as any).__HMR_SUCCESS__ = false;
85
- };
86
-
87
- // Remove o script antigo e adiciona o novo
88
- // (não remove para não quebrar o app)
89
- document.head.appendChild(newScript);
90
- } else {
91
- // Se não encontrou o script, apenas força re-render
92
- console.log('⚡ HMR: Forcing re-render');
93
- setHmrTimestamp(timestamp);
94
- (window as any).__HMR_SUCCESS__ = true;
95
- }
96
- } catch (error) {
97
- console.error('❌ HMR Error:', error);
98
- (window as any).__HMR_SUCCESS__ = false;
99
- }
100
- };
101
-
102
- window.addEventListener('hmr:component-update' as any, handleHMRUpdate);
103
-
104
- return () => {
105
- window.removeEventListener('hmr:component-update' as any, handleHMRUpdate);
106
- };
107
- }, []);
108
-
109
- const findRouteForPath = useCallback((path: string) => {
110
- for (const route of routes) {
111
- const regexPattern = route.pattern
112
- // [[...param]] → opcional catch-all
113
- .replace(/\[\[\.\.\.(\w+)\]\]/g, '(?<$1>.+)?')
114
- // [...param] → obrigatório catch-all
115
- .replace(/\[\.\.\.(\w+)\]/g, '(?<$1>.+)')
116
- // /[[param]] → opcional com barra também opcional
117
- .replace(/\/\[\[(\w+)\]\]/g, '(?:/(?<$1>[^/]+))?')
118
- // [[param]] → segmento opcional (sem barra anterior)
119
- .replace(/\[\[(\w+)\]\]/g, '(?<$1>[^/]+)?')
120
- // [param] → segmento obrigatório
121
- .replace(/\[(\w+)\]/g, '(?<$1>[^/]+)');
122
- const regex = new RegExp(`^${regexPattern}/?$`);
123
- const match = path.match(regex);
124
- if (match) {
125
- return {
126
- componentPath: route.componentPath,
127
- params: match.groups || {}
128
- };
129
- }
130
- }
131
- return null;
132
- }, [routes]);
133
-
134
- const updateRoute = useCallback(() => {
135
- const currentPath = router.pathname;
136
- const match = findRouteForPath(currentPath);
137
- if (match) {
138
- setCurrentPageComponent(() => componentMap[match.componentPath]);
139
- setParams(match.params);
140
- } else {
141
- // Se não encontrou rota, define como null para mostrar 404
142
- setCurrentPageComponent(null);
143
- setParams({});
144
- }
145
- }, [router.pathname, findRouteForPath, componentMap]);
146
-
147
- // Ouve os eventos de "voltar" e "avançar" do navegador
148
- useEffect(() => {
149
- const handlePopState = () => {
150
- updateRoute();
151
- };
152
-
153
- window.addEventListener('popstate', handlePopState);
154
-
155
- // Também se inscreve no router para mudanças de rota
156
- const unsubscribe = router.subscribe(updateRoute);
157
-
158
- return () => {
159
- window.removeEventListener('popstate', handlePopState);
160
- unsubscribe();
161
- };
162
- }, [updateRoute]);
163
-
164
- // Se não há componente ou é a rota __404__, mostra página 404
165
- if (!CurrentPageComponent || initialComponentPath === '__404__') {
166
- // Usa o componente 404 personalizado se existir, senão usa o padrão do hweb
167
- const NotFoundComponent = (window as any).__HWEB_NOT_FOUND__;
168
-
169
- if (NotFoundComponent) {
170
- // Usa o notFound.tsx personalizado do usuário
171
- const NotFoundContent = <NotFoundComponent />;
172
-
173
- // Aplica o layout se existir
174
- if (layoutComponent) {
175
- return React.createElement(layoutComponent, { children: NotFoundContent });
176
- }
177
- return NotFoundContent;
178
- } else {
179
- // Usa o 404 padrão do hweb que foi incluído no build
180
- const DefaultNotFound = (window as any).__HWEB_DEFAULT_NOT_FOUND__;
181
- const NotFoundContent = <DefaultNotFound />;
182
-
183
- // Aplica o layout se existir
184
- if (layoutComponent) {
185
- return React.createElement(layoutComponent, { children: NotFoundContent });
186
- }
187
- return NotFoundContent;
188
- }
189
- }
190
-
191
- // Renderiza o componente atual (sem Context, usa o router diretamente)
192
- // Usa key com timestamp para forçar re-mount durante HMR
193
- const PageContent = <CurrentPageComponent key={`page-${hmrTimestamp}`} params={params} />;
194
-
195
- // SEMPRE usa o layout - se não existir, cria um wrapper padrão
196
- const content = layoutComponent
197
- ? React.createElement(layoutComponent, { children: PageContent })
198
- : <div>{PageContent}</div>;
199
-
200
- // Adiciona o indicador de dev se não for produção
201
- return (
202
- <>
203
- {content}
204
- {process.env.NODE_ENV !== 'production' && <DevIndicator />}
205
- </>
206
- );
207
- }
208
-
209
-
210
-
211
- // --- Constantes de Configuração ---
212
- const DEV_INDICATOR_SIZE = 48;
213
- const DEV_INDICATOR_CORNERS = [
214
- { top: 16, left: 16 }, // 0: topo-esquerda
215
- { top: 16, right: 16 }, // 1: topo-direita
216
- { bottom: 16, left: 16 }, // 2: baixo-esquerda
217
- { bottom: 16, right: 16 },// 3: baixo-direita
218
- ];
219
-
220
- function DevIndicator() {
221
- const [corner, setCorner] = useState(3); // Canto atual (0-3)
222
- const [isDragging, setIsDragging] = useState(false); // Estado de arrastar
223
- const [isBuilding, setIsBuilding] = useState(false); // Estado de build
224
-
225
- // Posição visual do indicador durante o arraste
226
- const [position, setPosition] = useState<{ top: number; left: number }>({ top: 0, left: 0 });
227
-
228
- const indicatorRef = useRef<HTMLDivElement>(null);
229
- const dragStartRef = useRef<{ x: number; y: number; moved: boolean } | null>(null);
230
-
231
- // Escuta eventos de hot reload para mostrar estado de build
232
- useEffect(() => {
233
- if (typeof window === 'undefined') return;
234
-
235
- const handleHotReloadMessage = (event: MessageEvent) => {
236
- try {
237
- const message = JSON.parse(event.data);
238
-
239
- // Quando detecta mudança em arquivo, ativa loading
240
- if (message.type === 'frontend-reload' ||
241
- message.type === 'backend-api-reload' ||
242
- message.type === 'src-reload') {
243
- setIsBuilding(true);
244
- }
245
-
246
- // Quando o build termina ou servidor fica pronto, desativa loading
247
- if (message.type === 'server-ready' || message.type === 'build-complete') {
248
- setIsBuilding(false);
249
- }
250
- } catch (e) {
251
- // Ignora mensagens que não são JSON
252
- }
253
- };
254
-
255
- // Intercepta mensagens WebSocket
256
- const originalWebSocket = window.WebSocket;
257
- window.WebSocket = class extends originalWebSocket {
258
- constructor(url: string | URL, protocols?: string | string[]) {
259
- super(url, protocols);
260
-
261
- this.addEventListener('message', (event) => {
262
- if (url.toString().includes('hweb-hotreload')) {
263
- handleHotReloadMessage(event);
264
- }
265
- });
266
- }
267
- } as any;
268
-
269
- return () => {
270
- window.WebSocket = originalWebSocket;
271
- };
272
- }, []);
273
-
274
- // --- Estilos Dinâmicos ---
275
- const getIndicatorStyle = (): React.CSSProperties => {
276
- const baseStyle: React.CSSProperties = {
277
- position: 'fixed',
278
- zIndex: 9999,
279
- width: DEV_INDICATOR_SIZE,
280
- height: DEV_INDICATOR_SIZE,
281
- borderRadius: '50%',
282
- background: isBuilding
283
- ? 'linear-gradient(135deg, #f093fb, #f5576c)' // Gradiente Rosa/Vermelho quando building
284
- : 'linear-gradient(135deg, #8e2de2, #4a00e0)', // Gradiente Roxo normal
285
- color: 'white',
286
- fontWeight: 'bold',
287
- fontSize: 28,
288
- boxShadow: isBuilding
289
- ? '0 4px 25px rgba(245, 87, 108, 0.6)' // Shadow mais forte quando building
290
- : '0 4px 15px rgba(0,0,0,0.2)',
291
- display: 'flex',
292
- alignItems: 'center',
293
- justifyContent: 'center',
294
- cursor: isDragging ? 'grabbing' : 'grab',
295
- userSelect: 'none',
296
- transition: isDragging ? 'none' : 'all 0.3s ease-out',
297
- animation: isBuilding ? 'hweb-pulse 1.5s ease-in-out infinite' : 'none',
298
- };
299
-
300
- if (isDragging) {
301
- return {
302
- ...baseStyle,
303
- top: position.top,
304
- left: position.left,
305
- };
306
- }
307
-
308
- return { ...baseStyle, ...DEV_INDICATOR_CORNERS[corner] };
309
- };
310
-
311
- const getMenuPositionStyle = (): React.CSSProperties => {
312
- // Posiciona o menu dependendo do canto
313
- switch (corner) {
314
- case 0: return { top: '110%', left: '0' }; // Top-Left
315
- case 1: return { top: '110%', right: '0' }; // Top-Right
316
- case 2: return { bottom: '110%', left: '0' }; // Bottom-Left
317
- case 3: return { bottom: '110%', right: '0' }; // Bottom-Right
318
- default: return {};
319
- }
320
- };
321
-
322
- // --- Lógica de Eventos ---
323
- const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
324
- e.preventDefault();
325
- dragStartRef.current = { x: e.clientX, y: e.clientY, moved: false };
326
- if (indicatorRef.current) {
327
- const rect = indicatorRef.current.getBoundingClientRect();
328
- setPosition({ top: rect.top, left: rect.left });
329
- }
330
- setIsDragging(true);
331
- };
332
-
333
- const handleMouseMove = useCallback((e: MouseEvent) => {
334
- if (!isDragging || !dragStartRef.current) return;
335
-
336
- const deltaX = e.clientX - dragStartRef.current.x;
337
- const deltaY = e.clientY - dragStartRef.current.y;
338
-
339
- // Diferencia clique de arrastar (threshold de 5px)
340
- if (!dragStartRef.current.moved && Math.hypot(deltaX, deltaY) > 5) {
341
- dragStartRef.current.moved = true;
342
- }
343
-
344
- if (dragStartRef.current.moved) {
345
- setPosition(prevPos => ({
346
- top: prevPos.top + deltaY,
347
- left: prevPos.left + deltaX,
348
- }));
349
- // Atualiza a referência para o próximo movimento
350
- dragStartRef.current.x = e.clientX;
351
- dragStartRef.current.y = e.clientY;
352
- }
353
- }, [isDragging]);
354
-
355
- const handleMouseUp = useCallback((e: MouseEvent) => {
356
- if (!isDragging) return;
357
- setIsDragging(false);
358
-
359
- // Se moveu, calcula o canto mais próximo
360
- if (dragStartRef.current?.moved) {
361
- const { clientX, clientY } = e;
362
- const w = window.innerWidth;
363
- const h = window.innerHeight;
364
-
365
- const dists = [
366
- Math.hypot(clientX, clientY), // TL
367
- Math.hypot(w - clientX, clientY), // TR
368
- Math.hypot(clientX, h - clientY), // BL
369
- Math.hypot(w - clientX, h - clientY), // BR
370
- ];
371
- setCorner(dists.indexOf(Math.min(...dists)));
372
- }
373
-
374
- dragStartRef.current = null;
375
- }, [isDragging]);
376
-
377
- // Adiciona e remove listeners globais
378
- useEffect(() => {
379
- if (isDragging) {
380
- window.addEventListener('mousemove', handleMouseMove);
381
- window.addEventListener('mouseup', handleMouseUp);
382
- }
383
- return () => {
384
- window.removeEventListener('mousemove', handleMouseMove);
385
- window.removeEventListener('mouseup', handleMouseUp);
386
- };
387
- }, [isDragging, handleMouseMove, handleMouseUp]);
388
-
389
-
390
- return (
391
- <>
392
- <style>
393
- {`
394
- @keyframes hweb-pulse {
395
- 0%, 100% {
396
- transform: scale(1);
397
- opacity: 1;
398
- }
399
- 50% {
400
- transform: scale(1.1);
401
- opacity: 0.8;
402
- }
403
- }
404
-
405
- @keyframes hweb-spin {
406
- from {
407
- transform: rotate(0deg);
408
- }
409
- to {
410
- transform: rotate(360deg);
411
- }
412
- }
413
- `}
414
- </style>
415
- <div
416
- ref={indicatorRef}
417
- style={getIndicatorStyle()}
418
- onMouseDown={handleMouseDown}
419
- title={isBuilding ? "Building..." : "Modo Dev HightJS"}
420
- >
421
- {isBuilding ? (
422
- <span style={{ animation: 'hweb-spin 1s linear infinite' }}>⟳</span>
423
- ) : (
424
- 'H'
425
- )}
426
- </div>
427
- </>
428
- );
429
- }
430
-
431
- // --- Inicialização do Cliente (CSR - Client-Side Rendering) ---
432
-
433
- function deobfuscateData(obfuscated: string): any {
434
- try {
435
- // Remove o hash fake
436
- const parts = obfuscated.split('.');
437
- const base64 = parts.length > 1 ? parts[1] : parts[0];
438
-
439
- // Decodifica base64
440
- const jsonStr = atob(base64);
441
-
442
- // Parse JSON
443
- return JSON.parse(jsonStr);
444
- } catch (error) {
445
- console.error('[hweb] Failed to decode data:', error);
446
- return null;
447
- }
448
- }
449
-
450
- function initializeClient() {
451
- // Lê os dados do atributo data-h
452
- const dataElement = document.getElementById('__hight_data__');
453
-
454
- if (!dataElement) {
455
- console.error('[hweb] Initial data script not found.');
456
- return;
457
- }
458
-
459
- const obfuscated = dataElement.getAttribute('data-h');
460
-
461
- if (!obfuscated) {
462
- console.error('[hweb] Data attribute not found.');
463
- return;
464
- }
465
-
466
- const initialData = deobfuscateData(obfuscated);
467
-
468
- if (!initialData) {
469
- console.error('[hweb] Failed to parse initial data.');
470
- return;
471
- }
472
-
473
- // Cria o mapa de componentes dinamicamente a partir dos módulos carregados
474
- const componentMap: Record<string, any> = {};
475
-
476
- // Registra todos os componentes que foram importados
477
- if ((window as any).__HWEB_COMPONENTS__) {
478
- Object.assign(componentMap, (window as any).__HWEB_COMPONENTS__);
479
- }
480
-
481
- const container = document.getElementById('root');
482
- if (!container) {
483
- console.error('[hweb] Container #root not found.');
484
- return;
485
- }
486
-
487
- try {
488
- // Usar createRoot para render inicial (CSR)
489
- const root = createRoot(container);
490
-
491
- root.render(
492
- <App
493
- componentMap={componentMap}
494
- routes={initialData.routes}
495
- initialComponentPath={initialData.initialComponentPath}
496
- initialParams={initialData.initialParams}
497
- layoutComponent={(window as any).__HWEB_LAYOUT__}
498
- />
499
- );
500
- } catch (error) {
501
- console.error('[hweb] Error rendering application:', error);
502
- }
503
- }
504
-
505
- // Executa quando o DOM estiver pronto
506
- if (document.readyState === 'loading') {
507
- document.addEventListener('DOMContentLoaded', initializeClient);
508
- } else {
509
- initializeClient();
510
- }
511
-
package/src/client.ts DELETED
@@ -1,24 +0,0 @@
1
- /*
2
- * This file is part of the HightJS Project.
3
- * Copyright (c) 2025 itsmuzin
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- // Este arquivo exporta apenas código seguro para o cliente (navegador)
18
- export { Link } from './components/Link';
19
- export { RouteConfig, Metadata } from "./types";
20
- export { router } from './client/clientRouter';
21
-
22
-
23
-
24
-
@@ -1,38 +0,0 @@
1
- /*
2
- * This file is part of the HightJS Project.
3
- * Copyright (c) 2025 itsmuzin
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- import React, { type AnchorHTMLAttributes, type ReactNode } from 'react';
18
- import { router } from '../client/clientRouter';
19
-
20
- interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
21
- href: string;
22
- children: ReactNode;
23
- }
24
-
25
- export function Link({ href, children, ...props }: LinkProps) {
26
- const handleClick = async (e: React.MouseEvent<HTMLAnchorElement>) => {
27
- e.preventDefault();
28
-
29
- // Usa o novo sistema de router
30
- await router.push(href);
31
- };
32
-
33
- return (
34
- <a href={href} {...props} onClick={handleClick}>
35
- {children}
36
- </a>
37
- );
38
- }