baraqex 1.0.57 → 1.0.59
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/index.js +27 -3
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
- package/templates/basic-app/package-lock.json +6832 -4234
- package/templates/basic-app/package.json +29 -28
- package/templates/basic-app/src/main.tsx +189 -227
- package/templates/basic-app/vite.config.ts +14 -80
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "finall",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "tsc && vite build",
|
|
9
|
-
"preview": "vite preview",
|
|
10
|
-
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
11
|
-
"lint:fix": "eslint src --ext ts,tsx --fix"
|
|
12
|
-
},
|
|
13
|
-
"dependencies": {
|
|
14
|
-
"baraqex": "^1.0.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"@typescript-eslint/
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"eslint
|
|
22
|
-
"eslint-plugin-react-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "finall",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "tsc && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
11
|
+
"lint:fix": "eslint src --ext ts,tsx --fix"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"baraqex": "^1.0.58",
|
|
15
|
+
"frontend-hamroun": "^1.2.35"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
19
|
+
"@typescript-eslint/parser": "^6.0.0",
|
|
20
|
+
"autoprefixer": "^10.4.14",
|
|
21
|
+
"eslint": "^8.45.0",
|
|
22
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
23
|
+
"eslint-plugin-react-refresh": "^0.4.3",
|
|
24
|
+
"postcss": "^8.4.27",
|
|
25
|
+
"tailwindcss": "^3.3.3",
|
|
26
|
+
"typescript": "^5.0.0",
|
|
27
|
+
"vite": "^4.4.9"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { render, useState, useEffect, useMemo, useRef, useErrorBoundary, createContext, useContext } from 'baraqex';
|
|
2
2
|
import './main.css';
|
|
3
3
|
|
|
4
4
|
// JSX type declarations
|
|
@@ -10,224 +10,10 @@ declare global {
|
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
// Create a theme context
|
|
13
|
+
// Create a theme context with proper typing
|
|
14
14
|
const ThemeContext = createContext<'light' | 'dark'>('light');
|
|
15
15
|
|
|
16
|
-
//
|
|
17
|
-
function Counter() {
|
|
18
|
-
const [count, setCount] = useState(0);
|
|
19
|
-
const renderCount = useRef(0);
|
|
20
|
-
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
renderCount.current += 1;
|
|
23
|
-
}, [count]);
|
|
24
|
-
|
|
25
|
-
const doubled = useMemo(() => count * 2, [count]);
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<div className="card max-w-sm mx-auto">
|
|
29
|
-
<h2 className="text-2xl font-bold text-gray-800 mb-4 text-center">
|
|
30
|
-
Counter Example
|
|
31
|
-
</h2>
|
|
32
|
-
<div className="text-center">
|
|
33
|
-
<div className="text-4xl font-bold text-primary-600 mb-6">
|
|
34
|
-
{count}
|
|
35
|
-
</div>
|
|
36
|
-
<div className="mb-4">
|
|
37
|
-
<p className="text-sm text-gray-600 mb-2">Doubled: {doubled}</p>
|
|
38
|
-
<p className="text-sm text-gray-600">Renders: {renderCount.current}</p>
|
|
39
|
-
</div>
|
|
40
|
-
<div className="space-x-2">
|
|
41
|
-
<button
|
|
42
|
-
onClick={() => setCount(count + 1)}
|
|
43
|
-
className="btn btn-primary"
|
|
44
|
-
>
|
|
45
|
-
Increment
|
|
46
|
-
</button>
|
|
47
|
-
<button
|
|
48
|
-
onClick={() => setCount(count - 1)}
|
|
49
|
-
className="btn btn-secondary"
|
|
50
|
-
>
|
|
51
|
-
Decrement
|
|
52
|
-
</button>
|
|
53
|
-
<button
|
|
54
|
-
onClick={() => setCount(0)}
|
|
55
|
-
className="btn btn-danger"
|
|
56
|
-
>
|
|
57
|
-
Reset
|
|
58
|
-
</button>
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Todo Item Component
|
|
66
|
-
function TodoItem({ todo, onToggle, onDelete }: {
|
|
67
|
-
todo: { id: number; text: string; completed: boolean };
|
|
68
|
-
onToggle: (id: number) => void;
|
|
69
|
-
onDelete: (id: number) => void;
|
|
70
|
-
}) {
|
|
71
|
-
return (
|
|
72
|
-
<div className={`flex items-center justify-between p-3 rounded-md border transition-colors ${
|
|
73
|
-
todo.completed ? 'bg-green-50 border-green-200' : 'bg-gray-50 border-gray-200'
|
|
74
|
-
}`}>
|
|
75
|
-
<div className="flex items-center space-x-3">
|
|
76
|
-
<button
|
|
77
|
-
onClick={() => onToggle(todo.id)}
|
|
78
|
-
className={`w-5 h-5 rounded border-2 flex items-center justify-center transition-colors ${
|
|
79
|
-
todo.completed
|
|
80
|
-
? 'bg-green-500 border-green-500 text-white'
|
|
81
|
-
: 'border-gray-300 hover:border-green-500'
|
|
82
|
-
}`}
|
|
83
|
-
>
|
|
84
|
-
{todo.completed && '✓'}
|
|
85
|
-
</button>
|
|
86
|
-
<span className={`transition-colors ${todo.completed ? 'line-through text-gray-500' : 'text-gray-800'}`}>
|
|
87
|
-
{todo.text}
|
|
88
|
-
</span>
|
|
89
|
-
</div>
|
|
90
|
-
<button
|
|
91
|
-
onClick={() => onDelete(todo.id)}
|
|
92
|
-
className="text-red-500 hover:text-red-700 px-2 py-1 rounded transition-colors"
|
|
93
|
-
>
|
|
94
|
-
Delete
|
|
95
|
-
</button>
|
|
96
|
-
</div>
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Todo List Component
|
|
101
|
-
function TodoList() {
|
|
102
|
-
const [todos, setTodos] = useState<{ id: number; text: string; completed: boolean }[]>([
|
|
103
|
-
{ id: 1, text: 'Learn Baraqex Framework', completed: false },
|
|
104
|
-
{ id: 2, text: 'Build something awesome', completed: false },
|
|
105
|
-
{ id: 3, text: 'Deploy to production', completed: false }
|
|
106
|
-
]);
|
|
107
|
-
const [newTodo, setNewTodo] = useState('');
|
|
108
|
-
|
|
109
|
-
const addTodo = () => {
|
|
110
|
-
if (newTodo.trim()) {
|
|
111
|
-
setTodos([...todos, {
|
|
112
|
-
id: Date.now(),
|
|
113
|
-
text: newTodo.trim(),
|
|
114
|
-
completed: false
|
|
115
|
-
}]);
|
|
116
|
-
setNewTodo('');
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const toggleTodo = (id: number) => {
|
|
121
|
-
setTodos(todos.map((todo: { id: number; completed: any; }) =>
|
|
122
|
-
todo.id === id ? { ...todo, completed: !todo.completed } : todo
|
|
123
|
-
));
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const deleteTodo = (id: number) => {
|
|
127
|
-
setTodos(todos.filter((todo: { id: number; }) => todo.id !== id));
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
const completedCount = todos.filter((todo: { completed: any; }) => todo.completed).length;
|
|
131
|
-
const totalCount = todos.length;
|
|
132
|
-
|
|
133
|
-
return (
|
|
134
|
-
<div className="card max-w-md mx-auto">
|
|
135
|
-
<h2 className="text-2xl font-bold text-gray-800 mb-4 text-center">
|
|
136
|
-
Todo List
|
|
137
|
-
</h2>
|
|
138
|
-
|
|
139
|
-
<div className="mb-4">
|
|
140
|
-
<div className="flex space-x-2 mb-2">
|
|
141
|
-
<input
|
|
142
|
-
type="text"
|
|
143
|
-
value={newTodo}
|
|
144
|
-
onChange={(e: { target: { value: any; }; }) => setNewTodo(e.target.value)}
|
|
145
|
-
onKeyPress={(e: { key: string; }) => e.key === 'Enter' && addTodo()}
|
|
146
|
-
placeholder="Add a new todo..."
|
|
147
|
-
className="input flex-1"
|
|
148
|
-
/>
|
|
149
|
-
<button
|
|
150
|
-
onClick={addTodo}
|
|
151
|
-
className="btn btn-primary"
|
|
152
|
-
>
|
|
153
|
-
Add
|
|
154
|
-
</button>
|
|
155
|
-
</div>
|
|
156
|
-
<div className="text-sm text-gray-600 text-center">
|
|
157
|
-
{completedCount} of {totalCount} completed
|
|
158
|
-
</div>
|
|
159
|
-
</div>
|
|
160
|
-
|
|
161
|
-
<div className="space-y-2">
|
|
162
|
-
{todos.map((todo: { id: Number; text?: string; completed?: boolean; }) => (
|
|
163
|
-
<TodoItem
|
|
164
|
-
key={todo.id}
|
|
165
|
-
todo={todo}
|
|
166
|
-
onToggle={toggleTodo}
|
|
167
|
-
onDelete={deleteTodo}
|
|
168
|
-
/>
|
|
169
|
-
))}
|
|
170
|
-
</div>
|
|
171
|
-
|
|
172
|
-
{todos.length === 0 && (
|
|
173
|
-
<p className="text-gray-500 text-center py-4">
|
|
174
|
-
No todos yet. Add one above!
|
|
175
|
-
</p>
|
|
176
|
-
)}
|
|
177
|
-
</div>
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Error boundary test component
|
|
182
|
-
function BuggyComponent() {
|
|
183
|
-
const [shouldError, setShouldError] = useState(false);
|
|
184
|
-
|
|
185
|
-
if (shouldError) {
|
|
186
|
-
throw new Error("Test error from BuggyComponent");
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<div className="card max-w-sm mx-auto">
|
|
191
|
-
<h3 className="text-lg font-semibold text-gray-800 mb-4 text-center">
|
|
192
|
-
Error Boundary Test
|
|
193
|
-
</h3>
|
|
194
|
-
<p className="text-sm text-gray-600 mb-4 text-center">
|
|
195
|
-
Click the button below to test error handling
|
|
196
|
-
</p>
|
|
197
|
-
<div className="text-center">
|
|
198
|
-
<button
|
|
199
|
-
onClick={() => setShouldError(true)}
|
|
200
|
-
className="btn btn-danger"
|
|
201
|
-
>
|
|
202
|
-
Trigger Error
|
|
203
|
-
</button>
|
|
204
|
-
</div>
|
|
205
|
-
</div>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// Context test component
|
|
210
|
-
function ContextConsumer() {
|
|
211
|
-
const theme = useContext(ThemeContext);
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
<div className="card max-w-sm mx-auto">
|
|
215
|
-
<h3 className="text-lg font-semibold text-gray-800 mb-4 text-center">
|
|
216
|
-
Context API Test
|
|
217
|
-
</h3>
|
|
218
|
-
<div className={`p-4 rounded-md border text-center ${
|
|
219
|
-
theme === 'dark' ? 'border-gray-600 bg-gray-700 text-white' : 'border-gray-300 bg-gray-50'
|
|
220
|
-
}`}>
|
|
221
|
-
<p className="text-sm mb-2">Current theme: <strong>{theme}</strong></p>
|
|
222
|
-
<p className="text-xs text-gray-500">
|
|
223
|
-
Theme is provided by Context API
|
|
224
|
-
</p>
|
|
225
|
-
</div>
|
|
226
|
-
</div>
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Main App Component
|
|
16
|
+
// Main App Component - Fix the tab rendering logic
|
|
231
17
|
function App() {
|
|
232
18
|
const [activeTab, setActiveTab] = useState('counter');
|
|
233
19
|
const [theme, setTheme] = useState<'light' | 'dark'>('light');
|
|
@@ -237,6 +23,16 @@ function App() {
|
|
|
237
23
|
document.title = `Baraqex Demo - ${activeTab.charAt(0).toUpperCase() + activeTab.slice(1)}`;
|
|
238
24
|
}, [activeTab]);
|
|
239
25
|
|
|
26
|
+
// Add debug logging for theme changes
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
console.log('Theme changed to:', theme);
|
|
29
|
+
}, [theme]);
|
|
30
|
+
|
|
31
|
+
// Add debug logging for tab changes
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
console.log('Active tab changed to:', activeTab);
|
|
34
|
+
}, [activeTab]);
|
|
35
|
+
|
|
240
36
|
if (error) {
|
|
241
37
|
return (
|
|
242
38
|
<div className="min-h-screen bg-gradient-to-br from-red-50 to-red-100 flex items-center justify-center">
|
|
@@ -257,6 +53,26 @@ function App() {
|
|
|
257
53
|
);
|
|
258
54
|
}
|
|
259
55
|
|
|
56
|
+
// Function to render the current tab content
|
|
57
|
+
const renderTabContent = () => {
|
|
58
|
+
console.log('Rendering tab content for:', activeTab);
|
|
59
|
+
|
|
60
|
+
switch (activeTab) {
|
|
61
|
+
case 'counter':
|
|
62
|
+
console.log('Rendering Counter component');
|
|
63
|
+
return <Counter />;
|
|
64
|
+
case 'error':
|
|
65
|
+
console.log('Rendering BuggyComponent');
|
|
66
|
+
return <BuggyComponent />;
|
|
67
|
+
case 'context':
|
|
68
|
+
console.log('Rendering ContextConsumer component');
|
|
69
|
+
return <ContextConsumer />;
|
|
70
|
+
default:
|
|
71
|
+
console.log('Unknown tab, rendering Counter as fallback');
|
|
72
|
+
return <Counter />;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
260
76
|
return (
|
|
261
77
|
<ThemeContext.Provider value={theme}>
|
|
262
78
|
<div className={`min-h-screen transition-colors ${
|
|
@@ -340,7 +156,11 @@ function App() {
|
|
|
340
156
|
|
|
341
157
|
<div className="mt-8 text-center">
|
|
342
158
|
<button
|
|
343
|
-
onClick={() =>
|
|
159
|
+
onClick={() => {
|
|
160
|
+
const newTheme = theme === 'light' ? 'dark' : 'light';
|
|
161
|
+
console.log('Theme toggle clicked, changing from', theme, 'to', newTheme);
|
|
162
|
+
setTheme(newTheme);
|
|
163
|
+
}}
|
|
344
164
|
className={`btn ${theme === 'dark' ? 'bg-yellow-400 text-gray-900 hover:bg-yellow-300' : 'bg-gray-800 text-white hover:bg-gray-700'}`}
|
|
345
165
|
>
|
|
346
166
|
🌙 Toggle {theme === 'light' ? 'Dark' : 'Light'} Mode
|
|
@@ -354,13 +174,15 @@ function App() {
|
|
|
354
174
|
<div className="bg-white rounded-lg shadow-sm p-1 flex space-x-1 overflow-x-auto">
|
|
355
175
|
{[
|
|
356
176
|
{ id: 'counter', label: 'Counter', icon: '🔢' },
|
|
357
|
-
{ id: 'todos', label: 'Todo List', icon: '✅' },
|
|
358
177
|
{ id: 'error', label: 'Error Test', icon: '🚨' },
|
|
359
178
|
{ id: 'context', label: 'Context', icon: '🔄' }
|
|
360
179
|
].map(tab => (
|
|
361
180
|
<button
|
|
362
181
|
key={tab.id}
|
|
363
|
-
onClick={() =>
|
|
182
|
+
onClick={() => {
|
|
183
|
+
console.log('Tab clicked:', tab.id, 'current activeTab:', activeTab);
|
|
184
|
+
setActiveTab(tab.id);
|
|
185
|
+
}}
|
|
364
186
|
className={`px-4 py-2 rounded-md transition-colors whitespace-nowrap ${
|
|
365
187
|
activeTab === tab.id
|
|
366
188
|
? 'bg-primary-500 text-white'
|
|
@@ -374,12 +196,9 @@ function App() {
|
|
|
374
196
|
</div>
|
|
375
197
|
</div>
|
|
376
198
|
|
|
377
|
-
{/* Tab Content */}
|
|
199
|
+
{/* Tab Content - Use the function to render content */}
|
|
378
200
|
<div className="flex justify-center mb-12">
|
|
379
|
-
{
|
|
380
|
-
{activeTab === 'todos' && <TodoList />}
|
|
381
|
-
{activeTab === 'error' && <BuggyComponent />}
|
|
382
|
-
{activeTab === 'context' && <ContextConsumer />}
|
|
201
|
+
{renderTabContent()}
|
|
383
202
|
</div>
|
|
384
203
|
|
|
385
204
|
{/* Footer */}
|
|
@@ -461,5 +280,148 @@ function App() {
|
|
|
461
280
|
);
|
|
462
281
|
}
|
|
463
282
|
|
|
464
|
-
//
|
|
465
|
-
|
|
283
|
+
// Simple Counter Component with Tailwind styles - Fixed hooks
|
|
284
|
+
function Counter() {
|
|
285
|
+
// Initialize with proper values and ensure hooks work correctly
|
|
286
|
+
const [count, setCount] = useState(0);
|
|
287
|
+
const renderCount = useRef(0);
|
|
288
|
+
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
renderCount.current = (renderCount.current || 0) + 1;
|
|
291
|
+
console.log('Counter effect running, count:', count, 'renders:', renderCount.current);
|
|
292
|
+
}, [count]);
|
|
293
|
+
|
|
294
|
+
// Ensure count is a number before calculation
|
|
295
|
+
const doubled = useMemo(() => {
|
|
296
|
+
const numCount = typeof count === 'number' ? count : 0;
|
|
297
|
+
console.log('Calculating doubled for count:', numCount);
|
|
298
|
+
return numCount * 2;
|
|
299
|
+
}, [count]);
|
|
300
|
+
|
|
301
|
+
// Add debug logging
|
|
302
|
+
console.log('Counter render - count:', count, 'doubled:', doubled, 'renders:', renderCount.current);
|
|
303
|
+
|
|
304
|
+
return (
|
|
305
|
+
<div className="card max-w-sm mx-auto">
|
|
306
|
+
<h2 className="text-2xl font-bold text-gray-800 mb-4 text-center">
|
|
307
|
+
Counter Example
|
|
308
|
+
</h2>
|
|
309
|
+
<div className="text-center">
|
|
310
|
+
<div className="text-4xl font-bold text-primary-600 mb-6">
|
|
311
|
+
{typeof count === 'number' ? count : 0}
|
|
312
|
+
</div>
|
|
313
|
+
<div className="mb-4">
|
|
314
|
+
<p className="text-sm text-gray-600 mb-2">
|
|
315
|
+
Doubled: {typeof doubled === 'number' ? doubled : 'Error'}
|
|
316
|
+
</p>
|
|
317
|
+
<p className="text-sm text-gray-600">
|
|
318
|
+
Renders: {renderCount.current || 0}
|
|
319
|
+
</p>
|
|
320
|
+
</div>
|
|
321
|
+
<div className="space-x-2">
|
|
322
|
+
<button
|
|
323
|
+
onClick={() => {
|
|
324
|
+
console.log('Increment clicked, current count:', count);
|
|
325
|
+
const newCount = (typeof count === 'number' ? count : 0) + 1;
|
|
326
|
+
console.log('Setting new count:', newCount);
|
|
327
|
+
setCount(newCount);
|
|
328
|
+
}}
|
|
329
|
+
className="btn btn-primary"
|
|
330
|
+
>
|
|
331
|
+
Increment
|
|
332
|
+
</button>
|
|
333
|
+
<button
|
|
334
|
+
onClick={() => {
|
|
335
|
+
console.log('Decrement clicked, current count:', count);
|
|
336
|
+
const newCount = (typeof count === 'number' ? count : 0) - 1;
|
|
337
|
+
console.log('Setting new count:', newCount);
|
|
338
|
+
setCount(newCount);
|
|
339
|
+
}}
|
|
340
|
+
className="btn btn-secondary"
|
|
341
|
+
>
|
|
342
|
+
Decrement
|
|
343
|
+
</button>
|
|
344
|
+
<button
|
|
345
|
+
onClick={() => {
|
|
346
|
+
console.log('Reset clicked');
|
|
347
|
+
setCount(0);
|
|
348
|
+
}}
|
|
349
|
+
className="btn btn-danger"
|
|
350
|
+
>
|
|
351
|
+
Reset
|
|
352
|
+
</button>
|
|
353
|
+
</div>
|
|
354
|
+
</div>
|
|
355
|
+
</div>
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Error boundary test component with debugging
|
|
360
|
+
function BuggyComponent() {
|
|
361
|
+
console.log('BuggyComponent rendering...');
|
|
362
|
+
|
|
363
|
+
const [shouldError, setShouldError] = useState(false);
|
|
364
|
+
|
|
365
|
+
if (shouldError) {
|
|
366
|
+
throw new Error("Test error from BuggyComponent");
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<div className="card max-w-sm mx-auto">
|
|
371
|
+
<h3 className="text-lg font-semibold text-gray-800 mb-4 text-center">
|
|
372
|
+
Error Boundary Test
|
|
373
|
+
</h3>
|
|
374
|
+
<p className="text-sm text-gray-600 mb-4 text-center">
|
|
375
|
+
Click the button below to test error handling
|
|
376
|
+
</p>
|
|
377
|
+
<div className="text-center">
|
|
378
|
+
<button
|
|
379
|
+
onClick={() => {
|
|
380
|
+
console.log('Triggering error...');
|
|
381
|
+
setShouldError(true);
|
|
382
|
+
}}
|
|
383
|
+
className="btn btn-danger"
|
|
384
|
+
>
|
|
385
|
+
Trigger Error
|
|
386
|
+
</button>
|
|
387
|
+
</div>
|
|
388
|
+
</div>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Context test component - fixed to properly extract theme value
|
|
393
|
+
function ContextConsumer() {
|
|
394
|
+
const theme = useContext(ThemeContext);
|
|
395
|
+
|
|
396
|
+
// Extract the actual theme value - handle both direct values and wrapped objects
|
|
397
|
+
const actualTheme = typeof theme === 'object' && theme !== null
|
|
398
|
+
? (theme as any).value || 'light'
|
|
399
|
+
: (typeof theme === 'string' ? theme : 'light');
|
|
400
|
+
|
|
401
|
+
console.log('Context consumer - raw theme:', theme, 'actual theme:', actualTheme);
|
|
402
|
+
|
|
403
|
+
return (
|
|
404
|
+
<div className="card max-w-sm mx-auto">
|
|
405
|
+
<h3 className="text-lg font-semibold text-gray-800 mb-4 text-center">
|
|
406
|
+
Context API Test
|
|
407
|
+
</h3>
|
|
408
|
+
<div className={`p-4 rounded-md border text-center ${
|
|
409
|
+
actualTheme === 'dark' ? 'border-gray-600 bg-gray-700 text-white' : 'border-gray-300 bg-gray-50'
|
|
410
|
+
}`}>
|
|
411
|
+
<p className="text-sm mb-2">Current theme: <strong>{actualTheme}</strong></p>
|
|
412
|
+
<p className="text-xs text-gray-500">
|
|
413
|
+
Theme is provided by Context API
|
|
414
|
+
</p>
|
|
415
|
+
</div>
|
|
416
|
+
</div>
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// Mount the app with null check and debug logging
|
|
421
|
+
const rootElement = document.getElementById('root');
|
|
422
|
+
if (rootElement) {
|
|
423
|
+
console.log('Mounting app to root element');
|
|
424
|
+
render(<App />, rootElement);
|
|
425
|
+
} else {
|
|
426
|
+
console.error('Root element not found');
|
|
427
|
+
}
|
|
@@ -3,120 +3,54 @@ import { defineConfig } from 'vite';
|
|
|
3
3
|
export default defineConfig({
|
|
4
4
|
esbuild: {
|
|
5
5
|
jsxFactory: 'jsx',
|
|
6
|
-
jsxFragment: 'Fragment'
|
|
6
|
+
jsxFragment: 'Fragment',
|
|
7
|
+
jsxInject: `import { jsx } from 'baraqex'`
|
|
7
8
|
},
|
|
8
9
|
define: {
|
|
9
10
|
// Ensure we're in browser mode
|
|
10
11
|
'process.env.NODE_ENV': JSON.stringify('development'),
|
|
11
12
|
'typeof window': '"object"',
|
|
12
|
-
'typeof process': '"undefined"',
|
|
13
13
|
'global': 'globalThis'
|
|
14
14
|
},
|
|
15
15
|
optimizeDeps: {
|
|
16
16
|
// Exclude ALL server-only dependencies from browser bundle
|
|
17
17
|
exclude: [
|
|
18
|
+
// Only exclude actual server modules that would cause issues
|
|
18
19
|
'express',
|
|
19
20
|
'mysql2',
|
|
20
|
-
'mysql2/promise',
|
|
21
21
|
'mongodb',
|
|
22
22
|
'pg',
|
|
23
23
|
'bcryptjs',
|
|
24
24
|
'jsonwebtoken',
|
|
25
|
-
'cors'
|
|
26
|
-
'fs',
|
|
27
|
-
'path',
|
|
28
|
-
'crypto',
|
|
29
|
-
'http',
|
|
30
|
-
'url',
|
|
31
|
-
'fs/promises',
|
|
32
|
-
'child_process',
|
|
33
|
-
'os',
|
|
34
|
-
'stream',
|
|
35
|
-
'util',
|
|
36
|
-
'events',
|
|
37
|
-
'buffer',
|
|
38
|
-
'querystring',
|
|
39
|
-
'https',
|
|
40
|
-
'net',
|
|
41
|
-
'tls',
|
|
42
|
-
'zlib'
|
|
25
|
+
'cors'
|
|
43
26
|
],
|
|
44
27
|
// Force include browser-safe modules
|
|
45
28
|
include: [
|
|
46
|
-
'frontend-hamroun'
|
|
47
|
-
'crypto-browserify',
|
|
48
|
-
'path-browserify'
|
|
29
|
+
'frontend-hamroun'
|
|
49
30
|
]
|
|
50
31
|
},
|
|
51
|
-
build: {
|
|
52
|
-
rollupOptions: {
|
|
53
|
-
external: [
|
|
54
|
-
// Mark ALL server-only modules as external
|
|
55
|
-
'express',
|
|
56
|
-
'mysql2',
|
|
57
|
-
'mysql2/promise',
|
|
58
|
-
'mongodb',
|
|
59
|
-
'pg',
|
|
60
|
-
'bcryptjs',
|
|
61
|
-
'jsonwebtoken',
|
|
62
|
-
'cors',
|
|
63
|
-
'fs',
|
|
64
|
-
'path',
|
|
65
|
-
'crypto',
|
|
66
|
-
'http',
|
|
67
|
-
'url',
|
|
68
|
-
'fs/promises',
|
|
69
|
-
'child_process',
|
|
70
|
-
'os',
|
|
71
|
-
'stream',
|
|
72
|
-
'util',
|
|
73
|
-
'events',
|
|
74
|
-
'buffer',
|
|
75
|
-
'querystring',
|
|
76
|
-
'https',
|
|
77
|
-
'net',
|
|
78
|
-
'tls',
|
|
79
|
-
'zlib'
|
|
80
|
-
]
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
32
|
resolve: {
|
|
84
33
|
alias: {
|
|
85
|
-
//
|
|
86
|
-
'crypto': 'crypto-browserify',
|
|
87
|
-
'path': 'path-browserify',
|
|
34
|
+
// Only alias problematic Node.js built-ins, not everything
|
|
88
35
|
'fs': false,
|
|
36
|
+
'path': false,
|
|
89
37
|
'http': false,
|
|
90
38
|
'https': false,
|
|
91
39
|
'url': false,
|
|
92
|
-
'fs/promises': false,
|
|
93
|
-
'child_process': false,
|
|
94
40
|
'os': false,
|
|
95
|
-
'
|
|
96
|
-
'util': false,
|
|
97
|
-
'events': false,
|
|
98
|
-
'buffer': false,
|
|
99
|
-
'querystring': false,
|
|
100
|
-
'net': false,
|
|
101
|
-
'tls': false,
|
|
102
|
-
'zlib': false,
|
|
103
|
-
// Prevent any server modules from being loaded
|
|
104
|
-
'express': false,
|
|
105
|
-
'mysql2': false,
|
|
106
|
-
'mysql2/promise': false,
|
|
107
|
-
'mongodb': false,
|
|
108
|
-
'pg': false,
|
|
109
|
-
'bcryptjs': false,
|
|
110
|
-
'jsonwebtoken': false,
|
|
111
|
-
'cors': false
|
|
41
|
+
'crypto': false
|
|
112
42
|
},
|
|
113
43
|
// Only use browser-compatible fields
|
|
114
|
-
mainFields: ['browser', 'module', 'main']
|
|
115
|
-
conditions: ['browser']
|
|
44
|
+
mainFields: ['browser', 'module', 'main']
|
|
116
45
|
},
|
|
117
46
|
server: {
|
|
118
47
|
hmr: {
|
|
119
48
|
overlay: true
|
|
49
|
+
},
|
|
50
|
+
fs: {
|
|
51
|
+
// Allow serving files from the project root
|
|
52
|
+
allow: ['..']
|
|
120
53
|
}
|
|
121
54
|
}
|
|
55
|
+
|
|
122
56
|
});
|