frontend-hamroun 1.2.15 → 1.2.17

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 (158) hide show
  1. package/README.md +4 -0
  2. package/bin/cli.js +673 -0
  3. package/dist/component.d.ts +1 -1
  4. package/dist/context.d.ts +4 -3
  5. package/dist/index.client.d.ts +11 -0
  6. package/dist/index.d.ts +9 -89
  7. package/dist/index.js +396 -67
  8. package/dist/index.js.map +1 -0
  9. package/dist/index.mjs +392 -0
  10. package/dist/index.mjs.map +1 -0
  11. package/dist/jsx-runtime/jsx-runtime.d.ts +0 -1
  12. package/dist/jsx-runtime.d.ts +1 -1
  13. package/dist/renderer.d.ts +0 -10
  14. package/dist/server-renderer.d.ts +0 -3
  15. package/dist/server-types.d.ts +42 -0
  16. package/package.json +69 -50
  17. package/templates/basic-app/index.html +6 -6
  18. package/templates/basic-app/package.json +15 -11
  19. package/templates/basic-app/postcss.config.js +0 -1
  20. package/templates/basic-app/src/main.tsx +1 -10
  21. package/templates/basic-app/tailwind.config.js +2 -23
  22. package/templates/basic-app/tsconfig.json +4 -17
  23. package/templates/basic-app/vite.config.ts +3 -54
  24. package/templates/fullstack-app/api/hello.ts +18 -0
  25. package/templates/fullstack-app/api/users/[id].ts +73 -0
  26. package/templates/fullstack-app/api/users/index.ts +32 -0
  27. package/templates/fullstack-app/package.json +31 -0
  28. package/templates/fullstack-app/server.ts +46 -0
  29. package/templates/fullstack-app/src/pages/index.tsx +59 -0
  30. package/templates/ssr-template/vite.config.ts +1 -11
  31. package/bin/cli.cjs +0 -16
  32. package/bin/cli.mjs +0 -237
  33. package/dist/backend/api-utils.d.ts +0 -38
  34. package/dist/backend/api-utils.js +0 -135
  35. package/dist/backend/auth.d.ts +0 -134
  36. package/dist/backend/auth.js +0 -387
  37. package/dist/backend/database.d.ts +0 -27
  38. package/dist/backend/database.js +0 -91
  39. package/dist/backend/model.d.ts +0 -43
  40. package/dist/backend/model.js +0 -178
  41. package/dist/backend/router.d.ts +0 -27
  42. package/dist/backend/router.js +0 -137
  43. package/dist/backend/server.d.ts +0 -19
  44. package/dist/backend/server.js +0 -268
  45. package/dist/backend/types.d.ts +0 -217
  46. package/dist/backend/types.js +0 -1
  47. package/dist/batch.js +0 -22
  48. package/dist/cli/index.d.ts +0 -2
  49. package/dist/cli/index.js +0 -215
  50. package/dist/component.js +0 -84
  51. package/dist/components/Counter.js +0 -2
  52. package/dist/context.js +0 -18
  53. package/dist/frontend-hamroun.es.js +0 -1378
  54. package/dist/frontend-hamroun.umd.js +0 -66
  55. package/dist/hooks.js +0 -164
  56. package/dist/jsx-runtime/index.d.ts +0 -11
  57. package/dist/jsx-runtime/index.js +0 -19
  58. package/dist/jsx-runtime/jsx-dev-runtime.js +0 -1
  59. package/dist/jsx-runtime/jsx-runtime.js +0 -95
  60. package/dist/jsx-runtime.js +0 -192
  61. package/dist/renderer.js +0 -51
  62. package/dist/server-renderer.js +0 -102
  63. package/dist/types.js +0 -1
  64. package/dist/vdom.js +0 -27
  65. package/scripts/build-cli.js +0 -1107
  66. package/scripts/generate.js +0 -134
  67. package/src/backend/api-utils.ts +0 -178
  68. package/src/backend/auth.ts +0 -544
  69. package/src/backend/database.ts +0 -104
  70. package/src/backend/model.ts +0 -198
  71. package/src/backend/router.ts +0 -176
  72. package/src/backend/server.ts +0 -330
  73. package/src/backend/types.ts +0 -257
  74. package/src/batch.ts +0 -24
  75. package/src/cli/index.js +0 -554
  76. package/src/cli/index.ts +0 -257
  77. package/src/component.ts +0 -98
  78. package/src/components/Counter.tsx +0 -4
  79. package/src/context.ts +0 -29
  80. package/src/hooks.ts +0 -211
  81. package/src/index.ts +0 -144
  82. package/src/jsx-runtime/index.ts +0 -27
  83. package/src/jsx-runtime/jsx-dev-runtime.ts +0 -0
  84. package/src/jsx-runtime/jsx-runtime.ts +0 -104
  85. package/src/jsx-runtime.ts +0 -226
  86. package/src/renderer.ts +0 -55
  87. package/src/server-renderer.ts +0 -114
  88. package/src/shims.d.ts +0 -20
  89. package/src/types/bcrypt.d.ts +0 -30
  90. package/src/types/jsonwebtoken.d.ts +0 -55
  91. package/src/types.d.ts +0 -26
  92. package/src/types.ts +0 -21
  93. package/src/vdom.ts +0 -34
  94. package/templates/basic/.eslintignore +0 -5
  95. package/templates/basic/.eslintrc.json +0 -25
  96. package/templates/basic/docs/rapport_pfe.aux +0 -27
  97. package/templates/basic/docs/rapport_pfe.log +0 -399
  98. package/templates/basic/docs/rapport_pfe.out +0 -10
  99. package/templates/basic/docs/rapport_pfe.pdf +0 -0
  100. package/templates/basic/docs/rapport_pfe.tex +0 -68
  101. package/templates/basic/docs/rapport_pfe.toc +0 -14
  102. package/templates/basic/index.html +0 -12
  103. package/templates/basic/jsconfig.json +0 -14
  104. package/templates/basic/package.json +0 -20
  105. package/templates/basic/postcss.config.js +0 -7
  106. package/templates/basic/src/App.js +0 -105
  107. package/templates/basic/src/App.tsx +0 -65
  108. package/templates/basic/src/api.ts +0 -58
  109. package/templates/basic/src/components/Counter.tsx +0 -26
  110. package/templates/basic/src/components/Header.tsx +0 -9
  111. package/templates/basic/src/components/TodoList.tsx +0 -90
  112. package/templates/basic/src/main.css +0 -3
  113. package/templates/basic/src/main.js +0 -11
  114. package/templates/basic/src/main.ts +0 -20
  115. package/templates/basic/src/main.tsx +0 -144
  116. package/templates/basic/src/server.ts +0 -99
  117. package/templates/basic/tailwind.config.js +0 -32
  118. package/templates/basic/tsconfig.json +0 -20
  119. package/templates/basic/tsconfig.node.json +0 -10
  120. package/templates/basic/vite.config.js +0 -18
  121. package/templates/basic/vite.config.ts +0 -86
  122. package/templates/basic-app/src/App.js +0 -105
  123. package/templates/basic-app/src/App.tsx +0 -143
  124. package/templates/basic-app/src/api.ts +0 -58
  125. package/templates/basic-app/src/components/Counter.tsx +0 -26
  126. package/templates/basic-app/src/components/Header.tsx +0 -9
  127. package/templates/basic-app/src/components/TodoList.tsx +0 -90
  128. package/templates/basic-app/src/main.js +0 -10
  129. package/templates/basic-app/src/main.ts +0 -21
  130. package/templates/basic-app/src/react/index.ts +0 -35
  131. package/templates/basic-app/src/react/jsx-dev-runtime.ts +0 -13
  132. package/templates/basic-app/src/react/jsx-runtime.ts +0 -12
  133. package/templates/basic-app/src/server.ts +0 -99
  134. package/templates/basic-app/src/shims.ts +0 -9
  135. package/templates/basic-app/tsconfig.node.json +0 -10
  136. package/templates/basic-app/vite.config.js +0 -22
  137. package/templates/full-stack/.env.example +0 -11
  138. package/templates/full-stack/README.md +0 -51
  139. package/templates/full-stack/index.html +0 -12
  140. package/templates/full-stack/jsconfig.json +0 -14
  141. package/templates/full-stack/package.json +0 -20
  142. package/templates/full-stack/src/App.js +0 -105
  143. package/templates/full-stack/src/client/App.tsx +0 -50
  144. package/templates/full-stack/src/client/components/Header.tsx +0 -42
  145. package/templates/full-stack/src/client/components/UserList.tsx +0 -29
  146. package/templates/full-stack/src/client/main.tsx +0 -5
  147. package/templates/full-stack/src/main.css +0 -3
  148. package/templates/full-stack/src/main.js +0 -11
  149. package/templates/full-stack/src/main.ts +0 -20
  150. package/templates/full-stack/src/server/index.ts +0 -99
  151. package/templates/full-stack/src/server/routes/auth.ts +0 -39
  152. package/templates/full-stack/src/server/routes/users.ts +0 -48
  153. package/templates/full-stack/src/shims.ts +0 -9
  154. package/templates/full-stack/tsconfig.json +0 -20
  155. package/templates/full-stack/tsconfig.node.json +0 -10
  156. package/templates/full-stack/tsconfig.server.json +0 -15
  157. package/templates/full-stack/vite.config.js +0 -18
  158. package/templates/full-stack/vite.config.ts +0 -85
package/src/index.ts DELETED
@@ -1,144 +0,0 @@
1
- // Frontend exports
2
- import { jsx, jsxs, jsxDEV, createElement, Fragment } from './jsx-runtime/index';
3
- import { Component } from './component';
4
- import { useState, useEffect, useRef, useMemo, useErrorBoundary } from './hooks';
5
- import { render, hydrate } from './renderer';
6
- import { renderToString } from './server-renderer';
7
- import { prepareRender, finishRender } from './hooks';
8
- import { batchUpdates } from './batch';
9
- import { createContext, useContext } from './context';
10
-
11
- // Import backend functionality
12
- import { createServer } from './backend/server';
13
- import { createAuth } from './backend/auth';
14
- import { createModel, FieldTypes } from './backend/model';
15
- import { createModelRouter, createApiRouter as createCustomRouter } from './backend/router';
16
- import {
17
- sendSuccess,
18
- sendError,
19
- apiResponse,
20
- getPaginationParams,
21
- paginationMiddleware,
22
- validateRequest,
23
- asyncHandler,
24
- createRestEndpoints,
25
- createApiRouter
26
- } from './backend/api-utils';
27
- import { DatabaseConnector } from './backend/database';
28
-
29
- // Export JSX runtime
30
- export {
31
- jsx,
32
- jsxs,
33
- jsxDEV, // Add jsxDEV export
34
- createElement,
35
- Fragment
36
- };
37
-
38
- // Export hooks
39
- export {
40
- useState,
41
- useEffect,
42
- useRef,
43
- useMemo,
44
- useErrorBoundary,
45
- prepareRender,
46
- finishRender,
47
- batchUpdates,
48
- createContext,
49
- useContext
50
- };
51
-
52
- // Export component base class
53
- export { Component };
54
-
55
- // Export renderers
56
- export {
57
- render,
58
- hydrate,
59
- renderToString
60
- };
61
-
62
- // Export backend functionality
63
- export {
64
- createServer,
65
- createAuth,
66
- createModel,
67
- FieldTypes,
68
- createModelRouter,
69
- createCustomRouter,
70
- createApiRouter,
71
- sendSuccess,
72
- sendError,
73
- apiResponse,
74
- getPaginationParams,
75
- paginationMiddleware,
76
- validateRequest,
77
- asyncHandler,
78
- createRestEndpoints,
79
- DatabaseConnector
80
- };
81
-
82
- // Re-export types
83
- export type { Context } from './context';
84
- export type { VNode } from './types';
85
-
86
- // Backend types
87
- export type {
88
- HamrounServerOptions,
89
- RouterOptions,
90
- RouteContext,
91
- PaginationOptions,
92
- PaginatedResult,
93
- DatabaseOptions,
94
- Model,
95
- ApiResponse
96
- } from './backend/types';
97
-
98
- export type {
99
- AuthOptions,
100
- TokenPair
101
- } from './backend/auth';
102
-
103
- // Default export with all functionality
104
- export default {
105
- // Frontend
106
- jsx,
107
- jsxs,
108
- jsxDEV, // Add to default export
109
- createElement,
110
- Fragment,
111
- Component,
112
- useState,
113
- useEffect,
114
- useRef,
115
- useMemo,
116
- useErrorBoundary,
117
- render,
118
- hydrate,
119
- renderToString,
120
- prepareRender,
121
- finishRender,
122
- batchUpdates,
123
- createContext,
124
- useContext,
125
-
126
- // Backend
127
- createServer,
128
- createAuth,
129
- createModel,
130
- FieldTypes,
131
- createModelRouter,
132
- createCustomRouter,
133
- createApiRouter,
134
- sendSuccess,
135
- sendError,
136
- apiResponse,
137
- getPaginationParams,
138
- paginationMiddleware,
139
- validateRequest,
140
- asyncHandler,
141
- createRestEndpoints,
142
- DatabaseConnector
143
- };
144
-
@@ -1,27 +0,0 @@
1
- import { jsx, jsxs, createElement, Fragment, jsxDEV } from './jsx-runtime';
2
-
3
- export {
4
- jsx,
5
- jsxs,
6
- jsxDEV, // Add export for jsxDEV
7
- createElement,
8
- Fragment
9
- };
10
-
11
- // For global access in browsers
12
- if (typeof window !== 'undefined') {
13
- // TypeScript safe way to add properties to window
14
- (window as any).jsx = jsx;
15
- (window as any).jsxs = jsxs;
16
- (window as any).jsxDEV = jsxDEV; // Add jsxDEV
17
- (window as any).Fragment = Fragment;
18
- }
19
-
20
- // Default export for module usage
21
- export default {
22
- jsx,
23
- jsxs,
24
- jsxDEV,
25
- createElement,
26
- Fragment
27
- };
File without changes
@@ -1,104 +0,0 @@
1
- import { diff } from '../vdom';
2
-
3
- // Create a safe global object reference that works in both browser and Node
4
- const globalObj: any = typeof window !== 'undefined' ? window :
5
- typeof global !== 'undefined' ? global : {};
6
-
7
- export function jsx(type: string | Function, props: any, key?: string): any {
8
- return {
9
- type,
10
- props: props || {},
11
- key
12
- };
13
- }
14
-
15
- // Use the jsx function for jsxs as well
16
- export function jsxs(type: string | Function, props: any, key?: string): any {
17
- return jsx(type, props, key);
18
- }
19
-
20
- export function createElement(vnode: any): HTMLElement | Text {
21
- if (typeof vnode === 'string' || typeof vnode === 'number') {
22
- return document.createTextNode(String(vnode));
23
- }
24
-
25
- if (typeof vnode.type === 'function') {
26
- const result = vnode.type(vnode.props);
27
- return createElement(result);
28
- }
29
-
30
- const element = document.createElement(vnode.type);
31
-
32
- Object.entries(vnode.props || {}).forEach(([name, value]: [string, any]) => {
33
- if (name === 'children') {
34
- const children = Array.isArray(value) ? value : [value];
35
- children.forEach((child: any) => {
36
- if (child != null) {
37
- const childElement = createElement(child);
38
- // Generate stats for testing
39
- if (process.env.NODE_ENV === 'test' && typeof window !== 'undefined') {
40
- // Create stats tracking
41
- if (!globalObj.__renderStats) {
42
- globalObj.__renderStats = {
43
- elementsCreated: 0,
44
- textNodesCreated: 0,
45
- eventsAttached: 0,
46
- renderTime: 0
47
- };
48
-
49
- // Write stats to file when tests complete
50
- if (typeof afterAll === 'function') {
51
- afterAll(() => {
52
- try {
53
- const fs = require('fs');
54
- const path = require('path');
55
- const statsPath = path.resolve(process.cwd(), 'jsx-runtime-stats.json');
56
- fs.writeFileSync(statsPath, JSON.stringify(globalObj.__renderStats, null, 2));
57
- console.log(`JSX runtime stats written to ${statsPath}`);
58
- } catch (error) {
59
- console.error('Failed to write stats file:', error);
60
- }
61
- });
62
- }
63
- }
64
-
65
- // Increment stats based on element type
66
- if (childElement instanceof Text) {
67
- globalObj.__renderStats.textNodesCreated++;
68
- } else {
69
- globalObj.__renderStats.elementsCreated++;
70
- }
71
- }
72
-
73
- element.appendChild(childElement);
74
- }
75
- });
76
- } else if (name.startsWith('on')) {
77
- const eventName = name.toLowerCase().substring(2);
78
- element.addEventListener(eventName, value);
79
-
80
- // Track event attachment in stats
81
- if (process.env.NODE_ENV === 'test' && typeof window !== 'undefined' && globalObj.__renderStats) {
82
- globalObj.__renderStats.eventsAttached++;
83
- }
84
- } else if (name === 'className') {
85
- // Handle className specially by setting it as the class attribute
86
- element.setAttribute('class', value);
87
- } else if (name === 'style' && typeof value === 'object') {
88
- // Handle style objects by merging them into element.style
89
- Object.entries(value).forEach(([styleProp, styleValue]) => {
90
- element.style[styleProp as any] = String(styleValue);
91
- });
92
- } else {
93
- element.setAttribute(name, value);
94
- }
95
- });
96
-
97
- return element;
98
- }
99
-
100
- export const Fragment = Symbol('Fragment');
101
-
102
- // Add named exports for React JSX compatibility
103
- export const jsxDEV = jsx;
104
- // Don't export jsxs again - it's already exported above
@@ -1,226 +0,0 @@
1
- import type { Component } from './component';
2
-
3
- interface VNode {
4
- type: string | Function;
5
- props: Record<string, any>;
6
- }
7
-
8
- function jsx(type: string | Function, props: any, p0: string): VNode {
9
- console.log('JSX Transform:', { type, props });
10
- const processedProps = { ...props };
11
-
12
- // Handle children properly
13
- if (arguments.length > 2) {
14
- processedProps.children = Array.prototype.slice.call(arguments, 2);
15
- }
16
-
17
- return { type, props: processedProps };
18
- }
19
-
20
- const Fragment = ({ children }: { children: any }) => children;
21
-
22
- // Check if we're in a browser environment
23
- const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
24
-
25
- async function createElement(vnode: VNode | any): Promise<Node> {
26
- console.log('Creating element from:', vnode);
27
-
28
- // Create mock DOM elements when in Node environment
29
- if (!isBrowser) {
30
- // Return mock node objects in Node.js environment
31
- if (vnode == null) {
32
- return { nodeType: 3, textContent: '' } as any;
33
- }
34
-
35
- if (typeof vnode === 'boolean') {
36
- return { nodeType: 3, textContent: '' } as any;
37
- }
38
-
39
- if (typeof vnode === 'number' || typeof vnode === 'string') {
40
- return { nodeType: 3, textContent: String(vnode) } as any;
41
- }
42
-
43
- // Handle arrays
44
- if (Array.isArray(vnode)) {
45
- const fragment = { nodeType: 11, childNodes: [] } as any;
46
- for (const child of vnode) {
47
- const node = await createElement(child);
48
- fragment.childNodes.push(node);
49
- }
50
- return fragment;
51
- }
52
-
53
- // Handle VNode
54
- if ('type' in vnode && vnode.props !== undefined) {
55
- const { type, props } = vnode;
56
-
57
- // Handle function components
58
- if (typeof type === 'function') {
59
- try {
60
- const result = await type(props || {});
61
- const node = await createElement(result);
62
- return node;
63
- } catch (error) {
64
- console.error('Error rendering component:', error);
65
- return { nodeType: 3, textContent: '' } as any;
66
- }
67
- }
68
-
69
- // Mock element creation
70
- const element = {
71
- nodeType: 1,
72
- tagName: type,
73
- attributes: {},
74
- style: {},
75
- childNodes: [],
76
- setAttribute: function(key: string, value: string) {
77
- this.attributes[key] = value;
78
- },
79
- appendChild: function(child: any) {
80
- this.childNodes.push(child);
81
- }
82
- } as any;
83
-
84
- // Handle props
85
- for (const [key, value] of Object.entries(props || {})) {
86
- if (key === 'children') continue;
87
- if (key.startsWith('on') && typeof value === 'function') {
88
- // Mock event handlers
89
- const eventName = key.toLowerCase().slice(2);
90
- if (!element.__events) {
91
- element.__events = {};
92
- }
93
- element.__events[eventName] = value;
94
- } else if (key === 'style' && typeof value === 'object') {
95
- Object.assign(element.style, value);
96
- } else if (key === 'className') {
97
- element.setAttribute('class', String(value));
98
- } else if (key !== 'key' && key !== 'ref') {
99
- element.setAttribute(key, String(value));
100
- }
101
- }
102
-
103
- // Handle children
104
- const children = props?.children;
105
- if (children != null) {
106
- const childArray = Array.isArray(children) ? children.flat() : [children];
107
- for (const child of childArray) {
108
- const childNode = await createElement(child);
109
- element.appendChild(childNode);
110
- }
111
- }
112
-
113
- return element;
114
- }
115
-
116
- // Handle other objects by converting to string
117
- return { nodeType: 3, textContent: String(vnode) } as any;
118
- }
119
-
120
- // Browser environment implementation
121
- if (vnode == null) {
122
- return document.createTextNode('');
123
- }
124
-
125
- if (typeof vnode === 'boolean') {
126
- return document.createTextNode('');
127
- }
128
-
129
- if (typeof vnode === 'number' || typeof vnode === 'string') {
130
- return document.createTextNode(String(vnode));
131
- }
132
-
133
- // Handle arrays
134
- if (Array.isArray(vnode)) {
135
- const fragment = document.createDocumentFragment();
136
- for (const child of vnode) {
137
- const node = await createElement(child);
138
- fragment.appendChild(node);
139
- }
140
- return fragment;
141
- }
142
-
143
- // Handle VNode
144
- if ('type' in vnode && vnode.props !== undefined) {
145
- const { type, props } = vnode;
146
-
147
- // Handle function components
148
- if (typeof type === 'function') {
149
- try {
150
- const result = await type(props || {});
151
- const node = await createElement(result);
152
- if (node instanceof Element) {
153
- node.setAttribute('data-component-id', type.name || type.toString());
154
- }
155
- return node;
156
- } catch (error) {
157
- console.error('Error rendering component:', error);
158
- return document.createTextNode('');
159
- }
160
- }
161
-
162
- // Create DOM element
163
- const element = document.createElement(type as string);
164
-
165
- // Handle props
166
- for (const [key, value] of Object.entries(props || {})) {
167
- if (key === 'children') continue;
168
- if (key.startsWith('on') && typeof value === 'function') {
169
- const eventName = key.toLowerCase().slice(2);
170
- // Remove existing event listener if any
171
- const existingHandler = (element as any).__events?.[eventName];
172
- if (existingHandler) {
173
- element.removeEventListener(eventName, existingHandler);
174
- }
175
-
176
- // Add new event listener
177
- element.addEventListener(eventName, value as EventListener);
178
- if (!(element as any).__events) {
179
- (element as any).__events = {};
180
- }
181
- (element as any).__events[eventName] = value;
182
- } else if (key === 'style' && typeof value === 'object') {
183
- Object.assign(element.style, value);
184
- } else if (key === 'className') {
185
- element.setAttribute('class', String(value));
186
- } else if (key !== 'key' && key !== 'ref') {
187
- element.setAttribute(key, String(value));
188
- }
189
- }
190
-
191
- // Handle children
192
- const children = props?.children;
193
- if (children != null) {
194
- const childArray = Array.isArray(children) ? children.flat() : [children];
195
- for (const child of childArray) {
196
- const childNode = await createElement(child);
197
- element.appendChild(childNode);
198
- }
199
- }
200
-
201
- return element;
202
- }
203
-
204
- // Handle other objects by converting to string
205
- return document.createTextNode(String(vnode));
206
- }
207
-
208
- // Export named functions and aliases without duplicates
209
- export {
210
- jsx,
211
- jsx as jsxs,
212
- jsx as jsxDEV,
213
- Fragment,
214
- createElement
215
- };
216
-
217
- // Named exports object
218
- const jsxRuntime = {
219
- jsx,
220
- jsxs: jsx,
221
- jsxDEV: jsx,
222
- Fragment,
223
- createElement
224
- };
225
-
226
- export default jsxRuntime;
package/src/renderer.ts DELETED
@@ -1,55 +0,0 @@
1
- import { createElement } from './jsx-runtime';
2
- import { prepareRender, finishRender, setRenderCallback } from './hooks';
3
- import { batchUpdates } from './batch';
4
-
5
- // Track hydration state
6
- let isHydrating = false;
7
-
8
- /**
9
- * Hydrates a server-rendered component
10
- * @param element The element to hydrate
11
- * @param container The container element that contains server-rendered HTML
12
- */
13
- export async function hydrate(element: any, container: HTMLElement) {
14
- isHydrating = true;
15
- try {
16
- await render(element, container);
17
- } finally {
18
- isHydrating = false;
19
- }
20
- }
21
-
22
- /**
23
- * Renders a component to the DOM
24
- * @param element The element to render
25
- * @param container The container to render into
26
- */
27
- export async function render(element: any, container: HTMLElement) {
28
- console.log('Rendering to:', container.id || 'unnamed-container');
29
-
30
- batchUpdates(async () => {
31
- const rendererId = prepareRender();
32
- try {
33
- setRenderCallback(render, element, container);
34
- const domNode = await createElement(element);
35
-
36
- // Don't clear container if we're hydrating
37
- if (!isHydrating) {
38
- container.innerHTML = '';
39
- }
40
-
41
- // When hydrating, we should match and update existing nodes
42
- // rather than appending new ones
43
- if (isHydrating && container.firstChild) {
44
- // During hydration, we assume the structure matches
45
- // and just attach event handlers without replacing DOM
46
- console.log('Hydrating existing DOM');
47
- } else {
48
- container.appendChild(domNode);
49
- }
50
-
51
- } finally {
52
- finishRender();
53
- }
54
- });
55
- }
@@ -1,114 +0,0 @@
1
- import { prepareRender, finishRender, setRenderCallback } from './hooks';
2
-
3
- /**
4
- * Renders a component to a string
5
- */
6
- export async function renderToString(element: any): Promise<string> {
7
- // Setup render context
8
- const rendererId = prepareRender();
9
- setRenderCallback(() => {}, element, null as any);
10
-
11
- try {
12
- if (element == null) return '';
13
-
14
- if (typeof element === 'boolean') return '';
15
-
16
- if (typeof element === 'number' || typeof element === 'string') {
17
- return escapeHtml(String(element));
18
- }
19
-
20
- if (Array.isArray(element)) {
21
- const children = await Promise.all(element.map(renderToString));
22
- return children.join('');
23
- }
24
-
25
- if ('type' in element && element.props !== undefined) {
26
- const { type, props } = element;
27
-
28
- // Handle function components
29
- if (typeof type === 'function') {
30
- try {
31
- // Prepare new render context for the component
32
- prepareRender();
33
- const result = await type(props || {});
34
- const html = await renderToString(result);
35
- finishRender();
36
- return html;
37
- } catch (error) {
38
- console.error('Error rendering component:', error);
39
- return '';
40
- }
41
- }
42
-
43
- // Handle Fragment special case
44
- if (type === Symbol.for('react.fragment') || type.name === 'Fragment') {
45
- if (props.children) {
46
- const children = Array.isArray(props.children) ? props.children : [props.children];
47
- const renderedChildren = await Promise.all(children.map(renderToString));
48
- return renderedChildren.join('');
49
- }
50
- return '';
51
- }
52
-
53
- // Handle regular elements
54
- let html = `<${type}`;
55
-
56
- // Add attributes, skipping internal ones like 'key'
57
- for (const [key, value] of Object.entries(props || {})) {
58
- if (key === 'children' || key === 'key') continue;
59
- if (key === 'className') {
60
- html += ` class="${escapeHtml(String(value))}"`;
61
- } else if (key === 'style' && typeof value === 'object') {
62
- html += ` style="${stringifyStyle(value || {})}"`;
63
- } else if (!key.startsWith('on')) {
64
- html += ` ${key}="${escapeHtml(String(value))}"`;
65
- }
66
- }
67
-
68
- // Handle self-closing tags
69
- const voidElements = new Set([
70
- 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
71
- 'link', 'meta', 'param', 'source', 'track', 'wbr'
72
- ]);
73
-
74
- if (voidElements.has(type)) {
75
- return html + '/>';
76
- }
77
-
78
- html += '>';
79
-
80
- // Add children
81
- if (props?.children) {
82
- const children = Array.isArray(props.children) ? props.children : [props.children];
83
- for (const child of children) {
84
- html += await renderToString(child);
85
- }
86
- }
87
-
88
- return html + `</${type}>`;
89
- }
90
-
91
- return escapeHtml(String(element));
92
- } finally {
93
- finishRender();
94
- }
95
- }
96
-
97
- function escapeHtml(str: string): string {
98
- return str
99
- .replace(/&/g, '&amp;')
100
- .replace(/</g, '&lt;')
101
- .replace(/>/g, '&gt;')
102
- .replace(/"/g, '&quot;')
103
- .replace(/'/g, '&#39;');
104
- }
105
-
106
- function stringifyStyle(style: Record<string, any>): string {
107
- return Object.entries(style)
108
- .map(([key, value]) => `${hyphenate(key)}:${value}`)
109
- .join(';');
110
- }
111
-
112
- function hyphenate(str: string): string {
113
- return str.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
114
- }
package/src/shims.d.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * Module declaration shims for third-party libraries
3
- */
4
-
5
- // Handle bcrypt CommonJS module in ESM context
6
- declare module 'bcrypt' {
7
- export function genSalt(rounds?: number): Promise<string>;
8
- export function hash(data: string, saltOrRounds: string | number): Promise<string>;
9
- export function compare(data: string, encrypted: string): Promise<boolean>;
10
-
11
- // Allow either default or named imports to work
12
- const bcrypt: {
13
- genSalt: typeof genSalt;
14
- hash: typeof hash;
15
- compare: typeof compare;
16
- };
17
- export default bcrypt;
18
- }
19
-
20
- // Add similar declarations for other problematic Node.js modules if needed