frontend-hamroun 1.1.90 → 1.2.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.
- package/dist/{src/backend → backend}/api-utils.d.ts +2 -2
- package/dist/backend/api-utils.js +135 -0
- package/dist/backend/auth.js +387 -0
- package/dist/{src/backend → backend}/database.d.ts +1 -1
- package/dist/backend/database.js +91 -0
- package/dist/{src/backend → backend}/model.d.ts +2 -2
- package/dist/backend/model.js +176 -0
- package/dist/{src/backend → backend}/router.d.ts +1 -1
- package/dist/backend/router.js +137 -0
- package/dist/backend/server.js +268 -0
- package/dist/batch.js +22 -0
- package/dist/cli/index.js +1 -0
- package/dist/{src/component.d.ts → component.d.ts} +1 -1
- package/dist/component.js +84 -0
- package/dist/components/Counter.js +2 -0
- package/dist/context.js +20 -0
- package/dist/frontend-hamroun.es.js +1680 -0
- package/dist/frontend-hamroun.es.js.map +1 -0
- package/dist/frontend-hamroun.umd.js +2 -0
- package/dist/frontend-hamroun.umd.js.map +1 -0
- package/dist/hooks.js +164 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +52 -355
- package/dist/jsx-runtime/index.d.ts +9 -0
- package/dist/jsx-runtime/index.js +16 -0
- package/dist/jsx-runtime/jsx-dev-runtime.js +1 -0
- package/dist/jsx-runtime/jsx-runtime.js +91 -0
- package/dist/{src/jsx-runtime.d.ts → jsx-runtime.d.ts} +1 -1
- package/dist/jsx-runtime.js +192 -0
- package/dist/renderer.js +51 -0
- package/dist/{src/server-renderer.d.ts → server-renderer.d.ts} +3 -0
- package/dist/server-renderer.js +102 -0
- package/dist/vdom.js +27 -0
- package/package.json +38 -52
- package/scripts/generate.js +134 -0
- package/src/backend/api-utils.ts +178 -0
- package/src/backend/auth.ts +543 -0
- package/src/backend/database.ts +104 -0
- package/src/backend/model.ts +196 -0
- package/src/backend/router.ts +176 -0
- package/src/backend/server.ts +330 -0
- package/src/backend/types.ts +257 -0
- package/src/batch.ts +24 -0
- package/src/cli/index.js +22 -40
- package/src/component.ts +98 -0
- package/src/components/Counter.tsx +4 -0
- package/src/context.ts +32 -0
- package/src/hooks.ts +211 -0
- package/src/index.ts +113 -0
- package/src/jsx-runtime/index.ts +24 -0
- package/src/jsx-runtime/jsx-dev-runtime.ts +0 -0
- package/src/jsx-runtime/jsx-runtime.ts +99 -0
- package/src/jsx-runtime.ts +226 -0
- package/src/renderer.ts +55 -0
- package/src/server-renderer.ts +114 -0
- package/src/types/bcrypt.d.ts +30 -0
- package/src/types/jsonwebtoken.d.ts +55 -0
- package/src/types.d.ts +26 -0
- package/src/types.ts +21 -0
- package/src/vdom.ts +34 -0
- package/templates/basic-app/package.json +17 -15
- package/templates/basic-app/postcss.config.js +1 -0
- package/templates/basic-app/src/App.tsx +65 -0
- package/templates/basic-app/src/api.ts +58 -0
- package/templates/basic-app/src/components/Counter.tsx +26 -0
- package/templates/basic-app/src/components/Header.tsx +9 -0
- package/templates/basic-app/src/components/TodoList.tsx +90 -0
- package/templates/basic-app/src/main.ts +20 -0
- package/templates/basic-app/src/server.ts +99 -0
- package/templates/basic-app/tailwind.config.js +23 -2
- package/bin/cli.js +0 -371
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -139269
- package/dist/index.mjs.map +0 -1
- package/dist/src/index.d.ts +0 -16
- package/dist/test/setupTests.d.ts +0 -4
- /package/dist/{src/backend → backend}/auth.d.ts +0 -0
- /package/dist/{src/backend → backend}/server.d.ts +0 -0
- /package/dist/{src/backend → backend}/types.d.ts +0 -0
- /package/dist/{test/backend.test.d.ts → backend/types.js} +0 -0
- /package/dist/{src/batch.d.ts → batch.d.ts} +0 -0
- /package/dist/{src/cli → cli}/index.d.ts +0 -0
- /package/dist/{src/components → components}/Counter.d.ts +0 -0
- /package/dist/{src/context.d.ts → context.d.ts} +0 -0
- /package/dist/{src/hooks.d.ts → hooks.d.ts} +0 -0
- /package/dist/{src/jsx-runtime → jsx-runtime}/jsx-dev-runtime.d.ts +0 -0
- /package/dist/{src/jsx-runtime → jsx-runtime}/jsx-runtime.d.ts +0 -0
- /package/dist/{src/renderer.d.ts → renderer.d.ts} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{test/mockTest.d.ts → types.js} +0 -0
- /package/dist/{src/vdom.d.ts → vdom.d.ts} +0 -0
- /package/{dist/test/mongooseSetup.d.ts → src/cli/index.ts} +0 -0
@@ -0,0 +1,9 @@
|
|
1
|
+
import { jsx, jsxs, createElement, Fragment } from './jsx-runtime';
|
2
|
+
export { jsx, jsxs, createElement, Fragment };
|
3
|
+
declare const _default: {
|
4
|
+
jsx: typeof jsx;
|
5
|
+
jsxs: typeof jsxs;
|
6
|
+
createElement: typeof createElement;
|
7
|
+
Fragment: symbol;
|
8
|
+
};
|
9
|
+
export default _default;
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { jsx, jsxs, createElement, Fragment } from './jsx-runtime';
|
2
|
+
export { jsx, jsxs, createElement, Fragment };
|
3
|
+
// For global access in browsers
|
4
|
+
if (typeof window !== 'undefined') {
|
5
|
+
// TypeScript safe way to add properties to window
|
6
|
+
window.jsx = jsx;
|
7
|
+
window.jsxs = jsxs;
|
8
|
+
window.Fragment = Fragment;
|
9
|
+
}
|
10
|
+
// Default export for module usage
|
11
|
+
export default {
|
12
|
+
jsx,
|
13
|
+
jsxs,
|
14
|
+
createElement,
|
15
|
+
Fragment
|
16
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";
|
@@ -0,0 +1,91 @@
|
|
1
|
+
// Create a safe global object reference that works in both browser and Node
|
2
|
+
const globalObj = typeof window !== 'undefined' ? window :
|
3
|
+
typeof global !== 'undefined' ? global : {};
|
4
|
+
export function jsx(type, props, key) {
|
5
|
+
return {
|
6
|
+
type,
|
7
|
+
props: props || {},
|
8
|
+
key
|
9
|
+
};
|
10
|
+
}
|
11
|
+
export function jsxs(type, props, key) {
|
12
|
+
return jsx(type, props, key);
|
13
|
+
}
|
14
|
+
export function createElement(vnode) {
|
15
|
+
if (typeof vnode === 'string' || typeof vnode === 'number') {
|
16
|
+
return document.createTextNode(String(vnode));
|
17
|
+
}
|
18
|
+
if (typeof vnode.type === 'function') {
|
19
|
+
const result = vnode.type(vnode.props);
|
20
|
+
return createElement(result);
|
21
|
+
}
|
22
|
+
const element = document.createElement(vnode.type);
|
23
|
+
Object.entries(vnode.props || {}).forEach(([name, value]) => {
|
24
|
+
if (name === 'children') {
|
25
|
+
const children = Array.isArray(value) ? value : [value];
|
26
|
+
children.forEach((child) => {
|
27
|
+
if (child != null) {
|
28
|
+
const childElement = createElement(child);
|
29
|
+
// Generate stats for testing
|
30
|
+
if (process.env.NODE_ENV === 'test' && typeof window !== 'undefined') {
|
31
|
+
// Create stats tracking
|
32
|
+
if (!globalObj.__renderStats) {
|
33
|
+
globalObj.__renderStats = {
|
34
|
+
elementsCreated: 0,
|
35
|
+
textNodesCreated: 0,
|
36
|
+
eventsAttached: 0,
|
37
|
+
renderTime: 0
|
38
|
+
};
|
39
|
+
// Write stats to file when tests complete
|
40
|
+
if (typeof afterAll === 'function') {
|
41
|
+
afterAll(() => {
|
42
|
+
try {
|
43
|
+
const fs = require('fs');
|
44
|
+
const path = require('path');
|
45
|
+
const statsPath = path.resolve(process.cwd(), 'jsx-runtime-stats.json');
|
46
|
+
fs.writeFileSync(statsPath, JSON.stringify(globalObj.__renderStats, null, 2));
|
47
|
+
console.log(`JSX runtime stats written to ${statsPath}`);
|
48
|
+
}
|
49
|
+
catch (error) {
|
50
|
+
console.error('Failed to write stats file:', error);
|
51
|
+
}
|
52
|
+
});
|
53
|
+
}
|
54
|
+
}
|
55
|
+
// Increment stats based on element type
|
56
|
+
if (childElement instanceof Text) {
|
57
|
+
globalObj.__renderStats.textNodesCreated++;
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
globalObj.__renderStats.elementsCreated++;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
element.appendChild(childElement);
|
64
|
+
}
|
65
|
+
});
|
66
|
+
}
|
67
|
+
else if (name.startsWith('on')) {
|
68
|
+
const eventName = name.toLowerCase().substring(2);
|
69
|
+
element.addEventListener(eventName, value);
|
70
|
+
// Track event attachment in stats
|
71
|
+
if (process.env.NODE_ENV === 'test' && typeof window !== 'undefined' && globalObj.__renderStats) {
|
72
|
+
globalObj.__renderStats.eventsAttached++;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
else if (name === 'className') {
|
76
|
+
// Handle className specially by setting it as the class attribute
|
77
|
+
element.setAttribute('class', value);
|
78
|
+
}
|
79
|
+
else if (name === 'style' && typeof value === 'object') {
|
80
|
+
// Handle style objects by merging them into element.style
|
81
|
+
Object.entries(value).forEach(([styleProp, styleValue]) => {
|
82
|
+
element.style[styleProp] = String(styleValue);
|
83
|
+
});
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
element.setAttribute(name, value);
|
87
|
+
}
|
88
|
+
});
|
89
|
+
return element;
|
90
|
+
}
|
91
|
+
export const Fragment = Symbol('Fragment');
|
@@ -2,7 +2,7 @@ interface VNode {
|
|
2
2
|
type: string | Function;
|
3
3
|
props: Record<string, any>;
|
4
4
|
}
|
5
|
-
declare function jsx(type: string | Function, props: any): VNode;
|
5
|
+
declare function jsx(type: string | Function, props: any, p0: string): VNode;
|
6
6
|
declare const Fragment: ({ children }: {
|
7
7
|
children: any;
|
8
8
|
}) => any;
|
@@ -0,0 +1,192 @@
|
|
1
|
+
function jsx(type, props, p0) {
|
2
|
+
console.log('JSX Transform:', { type, props });
|
3
|
+
const processedProps = { ...props };
|
4
|
+
// Handle children properly
|
5
|
+
if (arguments.length > 2) {
|
6
|
+
processedProps.children = Array.prototype.slice.call(arguments, 2);
|
7
|
+
}
|
8
|
+
return { type, props: processedProps };
|
9
|
+
}
|
10
|
+
const Fragment = ({ children }) => children;
|
11
|
+
// Check if we're in a browser environment
|
12
|
+
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
13
|
+
async function createElement(vnode) {
|
14
|
+
console.log('Creating element from:', vnode);
|
15
|
+
// Create mock DOM elements when in Node environment
|
16
|
+
if (!isBrowser) {
|
17
|
+
// Return mock node objects in Node.js environment
|
18
|
+
if (vnode == null) {
|
19
|
+
return { nodeType: 3, textContent: '' };
|
20
|
+
}
|
21
|
+
if (typeof vnode === 'boolean') {
|
22
|
+
return { nodeType: 3, textContent: '' };
|
23
|
+
}
|
24
|
+
if (typeof vnode === 'number' || typeof vnode === 'string') {
|
25
|
+
return { nodeType: 3, textContent: String(vnode) };
|
26
|
+
}
|
27
|
+
// Handle arrays
|
28
|
+
if (Array.isArray(vnode)) {
|
29
|
+
const fragment = { nodeType: 11, childNodes: [] };
|
30
|
+
for (const child of vnode) {
|
31
|
+
const node = await createElement(child);
|
32
|
+
fragment.childNodes.push(node);
|
33
|
+
}
|
34
|
+
return fragment;
|
35
|
+
}
|
36
|
+
// Handle VNode
|
37
|
+
if ('type' in vnode && vnode.props !== undefined) {
|
38
|
+
const { type, props } = vnode;
|
39
|
+
// Handle function components
|
40
|
+
if (typeof type === 'function') {
|
41
|
+
try {
|
42
|
+
const result = await type(props || {});
|
43
|
+
const node = await createElement(result);
|
44
|
+
return node;
|
45
|
+
}
|
46
|
+
catch (error) {
|
47
|
+
console.error('Error rendering component:', error);
|
48
|
+
return { nodeType: 3, textContent: '' };
|
49
|
+
}
|
50
|
+
}
|
51
|
+
// Mock element creation
|
52
|
+
const element = {
|
53
|
+
nodeType: 1,
|
54
|
+
tagName: type,
|
55
|
+
attributes: {},
|
56
|
+
style: {},
|
57
|
+
childNodes: [],
|
58
|
+
setAttribute: function (key, value) {
|
59
|
+
this.attributes[key] = value;
|
60
|
+
},
|
61
|
+
appendChild: function (child) {
|
62
|
+
this.childNodes.push(child);
|
63
|
+
}
|
64
|
+
};
|
65
|
+
// Handle props
|
66
|
+
for (const [key, value] of Object.entries(props || {})) {
|
67
|
+
if (key === 'children')
|
68
|
+
continue;
|
69
|
+
if (key.startsWith('on') && typeof value === 'function') {
|
70
|
+
// Mock event handlers
|
71
|
+
const eventName = key.toLowerCase().slice(2);
|
72
|
+
if (!element.__events) {
|
73
|
+
element.__events = {};
|
74
|
+
}
|
75
|
+
element.__events[eventName] = value;
|
76
|
+
}
|
77
|
+
else if (key === 'style' && typeof value === 'object') {
|
78
|
+
Object.assign(element.style, value);
|
79
|
+
}
|
80
|
+
else if (key === 'className') {
|
81
|
+
element.setAttribute('class', String(value));
|
82
|
+
}
|
83
|
+
else if (key !== 'key' && key !== 'ref') {
|
84
|
+
element.setAttribute(key, String(value));
|
85
|
+
}
|
86
|
+
}
|
87
|
+
// Handle children
|
88
|
+
const children = props?.children;
|
89
|
+
if (children != null) {
|
90
|
+
const childArray = Array.isArray(children) ? children.flat() : [children];
|
91
|
+
for (const child of childArray) {
|
92
|
+
const childNode = await createElement(child);
|
93
|
+
element.appendChild(childNode);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return element;
|
97
|
+
}
|
98
|
+
// Handle other objects by converting to string
|
99
|
+
return { nodeType: 3, textContent: String(vnode) };
|
100
|
+
}
|
101
|
+
// Browser environment implementation
|
102
|
+
if (vnode == null) {
|
103
|
+
return document.createTextNode('');
|
104
|
+
}
|
105
|
+
if (typeof vnode === 'boolean') {
|
106
|
+
return document.createTextNode('');
|
107
|
+
}
|
108
|
+
if (typeof vnode === 'number' || typeof vnode === 'string') {
|
109
|
+
return document.createTextNode(String(vnode));
|
110
|
+
}
|
111
|
+
// Handle arrays
|
112
|
+
if (Array.isArray(vnode)) {
|
113
|
+
const fragment = document.createDocumentFragment();
|
114
|
+
for (const child of vnode) {
|
115
|
+
const node = await createElement(child);
|
116
|
+
fragment.appendChild(node);
|
117
|
+
}
|
118
|
+
return fragment;
|
119
|
+
}
|
120
|
+
// Handle VNode
|
121
|
+
if ('type' in vnode && vnode.props !== undefined) {
|
122
|
+
const { type, props } = vnode;
|
123
|
+
// Handle function components
|
124
|
+
if (typeof type === 'function') {
|
125
|
+
try {
|
126
|
+
const result = await type(props || {});
|
127
|
+
const node = await createElement(result);
|
128
|
+
if (node instanceof Element) {
|
129
|
+
node.setAttribute('data-component-id', type.name || type.toString());
|
130
|
+
}
|
131
|
+
return node;
|
132
|
+
}
|
133
|
+
catch (error) {
|
134
|
+
console.error('Error rendering component:', error);
|
135
|
+
return document.createTextNode('');
|
136
|
+
}
|
137
|
+
}
|
138
|
+
// Create DOM element
|
139
|
+
const element = document.createElement(type);
|
140
|
+
// Handle props
|
141
|
+
for (const [key, value] of Object.entries(props || {})) {
|
142
|
+
if (key === 'children')
|
143
|
+
continue;
|
144
|
+
if (key.startsWith('on') && typeof value === 'function') {
|
145
|
+
const eventName = key.toLowerCase().slice(2);
|
146
|
+
// Remove existing event listener if any
|
147
|
+
const existingHandler = element.__events?.[eventName];
|
148
|
+
if (existingHandler) {
|
149
|
+
element.removeEventListener(eventName, existingHandler);
|
150
|
+
}
|
151
|
+
// Add new event listener
|
152
|
+
element.addEventListener(eventName, value);
|
153
|
+
if (!element.__events) {
|
154
|
+
element.__events = {};
|
155
|
+
}
|
156
|
+
element.__events[eventName] = value;
|
157
|
+
}
|
158
|
+
else if (key === 'style' && typeof value === 'object') {
|
159
|
+
Object.assign(element.style, value);
|
160
|
+
}
|
161
|
+
else if (key === 'className') {
|
162
|
+
element.setAttribute('class', String(value));
|
163
|
+
}
|
164
|
+
else if (key !== 'key' && key !== 'ref') {
|
165
|
+
element.setAttribute(key, String(value));
|
166
|
+
}
|
167
|
+
}
|
168
|
+
// Handle children
|
169
|
+
const children = props?.children;
|
170
|
+
if (children != null) {
|
171
|
+
const childArray = Array.isArray(children) ? children.flat() : [children];
|
172
|
+
for (const child of childArray) {
|
173
|
+
const childNode = await createElement(child);
|
174
|
+
element.appendChild(childNode);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
return element;
|
178
|
+
}
|
179
|
+
// Handle other objects by converting to string
|
180
|
+
return document.createTextNode(String(vnode));
|
181
|
+
}
|
182
|
+
// Export named functions and aliases without duplicates
|
183
|
+
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment, createElement };
|
184
|
+
// Named exports object
|
185
|
+
const jsxRuntime = {
|
186
|
+
jsx,
|
187
|
+
jsxs: jsx,
|
188
|
+
jsxDEV: jsx,
|
189
|
+
Fragment,
|
190
|
+
createElement
|
191
|
+
};
|
192
|
+
export default jsxRuntime;
|
package/dist/renderer.js
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
import { createElement } from './jsx-runtime';
|
2
|
+
import { prepareRender, finishRender, setRenderCallback } from './hooks';
|
3
|
+
import { batchUpdates } from './batch';
|
4
|
+
// Track hydration state
|
5
|
+
let isHydrating = false;
|
6
|
+
/**
|
7
|
+
* Hydrates a server-rendered component
|
8
|
+
* @param element The element to hydrate
|
9
|
+
* @param container The container element that contains server-rendered HTML
|
10
|
+
*/
|
11
|
+
export async function hydrate(element, container) {
|
12
|
+
isHydrating = true;
|
13
|
+
try {
|
14
|
+
await render(element, container);
|
15
|
+
}
|
16
|
+
finally {
|
17
|
+
isHydrating = false;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
/**
|
21
|
+
* Renders a component to the DOM
|
22
|
+
* @param element The element to render
|
23
|
+
* @param container The container to render into
|
24
|
+
*/
|
25
|
+
export async function render(element, container) {
|
26
|
+
console.log('Rendering to:', container.id || 'unnamed-container');
|
27
|
+
batchUpdates(async () => {
|
28
|
+
const rendererId = prepareRender();
|
29
|
+
try {
|
30
|
+
setRenderCallback(render, element, container);
|
31
|
+
const domNode = await createElement(element);
|
32
|
+
// Don't clear container if we're hydrating
|
33
|
+
if (!isHydrating) {
|
34
|
+
container.innerHTML = '';
|
35
|
+
}
|
36
|
+
// When hydrating, we should match and update existing nodes
|
37
|
+
// rather than appending new ones
|
38
|
+
if (isHydrating && container.firstChild) {
|
39
|
+
// During hydration, we assume the structure matches
|
40
|
+
// and just attach event handlers without replacing DOM
|
41
|
+
console.log('Hydrating existing DOM');
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
container.appendChild(domNode);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
finally {
|
48
|
+
finishRender();
|
49
|
+
}
|
50
|
+
});
|
51
|
+
}
|
@@ -0,0 +1,102 @@
|
|
1
|
+
import { prepareRender, finishRender, setRenderCallback } from './hooks';
|
2
|
+
/**
|
3
|
+
* Renders a component to a string
|
4
|
+
*/
|
5
|
+
export async function renderToString(element) {
|
6
|
+
// Setup render context
|
7
|
+
const rendererId = prepareRender();
|
8
|
+
setRenderCallback(() => { }, element, null);
|
9
|
+
try {
|
10
|
+
if (element == null)
|
11
|
+
return '';
|
12
|
+
if (typeof element === 'boolean')
|
13
|
+
return '';
|
14
|
+
if (typeof element === 'number' || typeof element === 'string') {
|
15
|
+
return escapeHtml(String(element));
|
16
|
+
}
|
17
|
+
if (Array.isArray(element)) {
|
18
|
+
const children = await Promise.all(element.map(renderToString));
|
19
|
+
return children.join('');
|
20
|
+
}
|
21
|
+
if ('type' in element && element.props !== undefined) {
|
22
|
+
const { type, props } = element;
|
23
|
+
// Handle function components
|
24
|
+
if (typeof type === 'function') {
|
25
|
+
try {
|
26
|
+
// Prepare new render context for the component
|
27
|
+
prepareRender();
|
28
|
+
const result = await type(props || {});
|
29
|
+
const html = await renderToString(result);
|
30
|
+
finishRender();
|
31
|
+
return html;
|
32
|
+
}
|
33
|
+
catch (error) {
|
34
|
+
console.error('Error rendering component:', error);
|
35
|
+
return '';
|
36
|
+
}
|
37
|
+
}
|
38
|
+
// Handle Fragment special case
|
39
|
+
if (type === Symbol.for('react.fragment') || type.name === 'Fragment') {
|
40
|
+
if (props.children) {
|
41
|
+
const children = Array.isArray(props.children) ? props.children : [props.children];
|
42
|
+
const renderedChildren = await Promise.all(children.map(renderToString));
|
43
|
+
return renderedChildren.join('');
|
44
|
+
}
|
45
|
+
return '';
|
46
|
+
}
|
47
|
+
// Handle regular elements
|
48
|
+
let html = `<${type}`;
|
49
|
+
// Add attributes, skipping internal ones like 'key'
|
50
|
+
for (const [key, value] of Object.entries(props || {})) {
|
51
|
+
if (key === 'children' || key === 'key')
|
52
|
+
continue;
|
53
|
+
if (key === 'className') {
|
54
|
+
html += ` class="${escapeHtml(String(value))}"`;
|
55
|
+
}
|
56
|
+
else if (key === 'style' && typeof value === 'object') {
|
57
|
+
html += ` style="${stringifyStyle(value || {})}"`;
|
58
|
+
}
|
59
|
+
else if (!key.startsWith('on')) {
|
60
|
+
html += ` ${key}="${escapeHtml(String(value))}"`;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
// Handle self-closing tags
|
64
|
+
const voidElements = new Set([
|
65
|
+
'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',
|
66
|
+
'link', 'meta', 'param', 'source', 'track', 'wbr'
|
67
|
+
]);
|
68
|
+
if (voidElements.has(type)) {
|
69
|
+
return html + '/>';
|
70
|
+
}
|
71
|
+
html += '>';
|
72
|
+
// Add children
|
73
|
+
if (props?.children) {
|
74
|
+
const children = Array.isArray(props.children) ? props.children : [props.children];
|
75
|
+
for (const child of children) {
|
76
|
+
html += await renderToString(child);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
return html + `</${type}>`;
|
80
|
+
}
|
81
|
+
return escapeHtml(String(element));
|
82
|
+
}
|
83
|
+
finally {
|
84
|
+
finishRender();
|
85
|
+
}
|
86
|
+
}
|
87
|
+
function escapeHtml(str) {
|
88
|
+
return str
|
89
|
+
.replace(/&/g, '&')
|
90
|
+
.replace(/</g, '<')
|
91
|
+
.replace(/>/g, '>')
|
92
|
+
.replace(/"/g, '"')
|
93
|
+
.replace(/'/g, ''');
|
94
|
+
}
|
95
|
+
function stringifyStyle(style) {
|
96
|
+
return Object.entries(style)
|
97
|
+
.map(([key, value]) => `${hyphenate(key)}:${value}`)
|
98
|
+
.join(';');
|
99
|
+
}
|
100
|
+
function hyphenate(str) {
|
101
|
+
return str.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
|
102
|
+
}
|
package/dist/vdom.js
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
function arePropsEqual(oldProps, newProps) {
|
2
|
+
// Handle null/undefined props
|
3
|
+
oldProps = oldProps || {};
|
4
|
+
newProps = newProps || {};
|
5
|
+
const oldKeys = Object.keys(oldProps).filter(k => k !== 'children');
|
6
|
+
const newKeys = Object.keys(newProps).filter(k => k !== 'children');
|
7
|
+
if (oldKeys.length !== newKeys.length)
|
8
|
+
return false;
|
9
|
+
return oldKeys.every(key => oldProps[key] === newProps[key]);
|
10
|
+
}
|
11
|
+
export function diff(oldNode, newNode) {
|
12
|
+
if (oldNode == null || newNode == null)
|
13
|
+
return oldNode !== newNode;
|
14
|
+
if (typeof oldNode !== typeof newNode)
|
15
|
+
return true;
|
16
|
+
if (typeof newNode === 'string' || typeof newNode === 'number')
|
17
|
+
return oldNode !== newNode;
|
18
|
+
// Handle primitive values that are not objects
|
19
|
+
if (!oldNode.type || !newNode.type)
|
20
|
+
return oldNode !== newNode;
|
21
|
+
if (newNode.type !== oldNode.type)
|
22
|
+
return true;
|
23
|
+
return !arePropsEqual(oldNode.props, newNode.props);
|
24
|
+
}
|
25
|
+
export function shouldComponentUpdate(oldProps, newProps) {
|
26
|
+
return !arePropsEqual(oldProps, newProps);
|
27
|
+
}
|
package/package.json
CHANGED
@@ -1,93 +1,79 @@
|
|
1
1
|
{
|
2
2
|
"name": "frontend-hamroun",
|
3
|
-
"version": "1.
|
4
|
-
"description": "A lightweight frontend framework
|
3
|
+
"version": "1.2.0",
|
4
|
+
"description": "A lightweight frontend and backend framework for building modern web applications",
|
5
5
|
"type": "module",
|
6
|
-
"main": "
|
7
|
-
"module": "
|
8
|
-
"types": "
|
6
|
+
"main": "dist/frontend-hamroun.umd.js",
|
7
|
+
"module": "dist/frontend-hamroun.es.js",
|
8
|
+
"types": "dist/index.d.ts",
|
9
9
|
"files": [
|
10
10
|
"dist",
|
11
|
-
"
|
11
|
+
"src",
|
12
|
+
"templates",
|
13
|
+
"scripts",
|
12
14
|
"LICENSE",
|
13
|
-
"
|
14
|
-
"templates"
|
15
|
+
"README.md"
|
15
16
|
],
|
16
17
|
"exports": {
|
17
18
|
".": {
|
18
19
|
"types": "./dist/index.d.ts",
|
19
|
-
"import": "./dist/
|
20
|
-
"require": "./dist/
|
21
|
-
"default": "./dist/index.js"
|
20
|
+
"import": "./dist/frontend-hamroun.es.js",
|
21
|
+
"require": "./dist/frontend-hamroun.umd.js"
|
22
22
|
}
|
23
23
|
},
|
24
24
|
"bin": {
|
25
|
-
"frontend-hamroun": "bin/cli.js",
|
26
|
-
"create-frontend-app": "bin/cli.js",
|
27
25
|
"hamroun": "src/cli/index.js"
|
28
26
|
},
|
29
27
|
"scripts": {
|
30
|
-
"build": "vite build && tsc --emitDeclarationOnly",
|
31
|
-
"clean": "node -e \"if(require('fs').existsSync('dist')) require('fs').rmSync('dist',{recursive:true})\"",
|
32
|
-
"prepublishOnly": "npm run clean && npm run build",
|
33
28
|
"dev": "vite",
|
29
|
+
"build": "vite build && tsc",
|
34
30
|
"test": "jest",
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"
|
31
|
+
"clean": "rimraf dist",
|
32
|
+
"prebuild": "npm run clean",
|
33
|
+
"prepublish": "npm run build",
|
34
|
+
"generate": "node scripts/generate.js"
|
38
35
|
},
|
39
36
|
"keywords": [
|
40
37
|
"frontend",
|
41
38
|
"framework",
|
39
|
+
"react-like",
|
42
40
|
"jsx",
|
43
|
-
"
|
44
|
-
"
|
41
|
+
"ssr",
|
42
|
+
"server-side-rendering",
|
43
|
+
"backend",
|
44
|
+
"api",
|
45
|
+
"express"
|
45
46
|
],
|
46
47
|
"author": "Hamroun",
|
47
48
|
"license": "MIT",
|
48
49
|
"repository": {
|
49
50
|
"type": "git",
|
50
|
-
"url": "
|
51
|
+
"url": "https://github.com/hamroun/frontend-hamroun.git"
|
51
52
|
},
|
52
53
|
"devDependencies": {
|
53
|
-
"@types/
|
54
|
+
"@types/bcrypt": "^5.0.2",
|
54
55
|
"@types/compression": "^1.7.5",
|
55
|
-
"@types/express": "^4.17.
|
56
|
-
"@types/jest": "^29.5.
|
56
|
+
"@types/express": "^4.17.21",
|
57
|
+
"@types/jest": "^29.5.11",
|
58
|
+
"@types/jsonwebtoken": "^9.0.5",
|
57
59
|
"@types/morgan": "^1.9.9",
|
58
|
-
"@types/
|
59
|
-
"@types/supertest": "^2.0.12",
|
60
|
-
"@vitejs/plugin-react": "^4.0.4",
|
61
|
-
"aws-sdk": "^2.1692.0",
|
60
|
+
"@types/node": "^20.10.5",
|
62
61
|
"jest": "^29.7.0",
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
69
|
-
"typescript": "^5.0.0",
|
70
|
-
"vite": "^4.4.9",
|
71
|
-
"vite-plugin-dts": "^4.5.0",
|
72
|
-
"vitest": "^0.34.0"
|
73
|
-
},
|
74
|
-
"publishConfig": {
|
75
|
-
"access": "public",
|
76
|
-
"registry": "https://registry.npmjs.org/"
|
62
|
+
"rimraf": "^5.0.5",
|
63
|
+
"terser": "^5.25.0",
|
64
|
+
"ts-jest": "^29.1.1",
|
65
|
+
"typescript": "^5.3.3",
|
66
|
+
"vite": "^5.0.10",
|
67
|
+
"vite-plugin-dts": "^3.6.4"
|
77
68
|
},
|
78
69
|
"dependencies": {
|
79
70
|
"bcrypt": "^5.1.1",
|
80
|
-
"
|
81
|
-
"
|
82
|
-
"
|
83
|
-
"express": "^5.1.0",
|
84
|
-
"fs-extra": "^11.1.1",
|
85
|
-
"helmet": "^8.1.0",
|
86
|
-
"inquirer": "^9.2.10",
|
71
|
+
"compression": "^1.7.4",
|
72
|
+
"express": "^4.18.2",
|
73
|
+
"helmet": "^7.1.0",
|
87
74
|
"jsonwebtoken": "^9.0.2",
|
88
|
-
"mongoose": "^8.
|
75
|
+
"mongoose": "^8.0.3",
|
89
76
|
"morgan": "^1.10.0",
|
90
|
-
"nanospinner": "^1.1.0",
|
91
77
|
"ts-node": "^10.9.2"
|
92
78
|
}
|
93
79
|
}
|