baraqex 1.0.43 → 1.0.45
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/README_WASM.md +472 -0
- package/bin/baraqex.js +1 -1
- package/dist/browser.js +1 -1067
- package/dist/browser.js.map +4 -4
- package/dist/index.js +28 -1087
- package/dist/index.js.map +4 -4
- package/dist/{server/index.js → server.js} +21 -249
- package/dist/server.js.map +7 -0
- package/package.json +49 -58
- package/templates/ssr-template/index.html +35 -0
- package/templates/ssr-template/package-lock.json +2665 -446
- package/templates/ssr-template/package.json +20 -14
- package/templates/ssr-template/src/App.tsx +65 -42
- package/templates/ssr-template/src/client.tsx +2 -10
- package/templates/wasm/package-lock.json +3169 -2710
- package/templates/wasm/package.json +9 -12
- package/templates/wasm/src/App.tsx +50 -19
- package/templates/wasm/vite.config.ts +24 -59
- package/dist/api/hello.d.ts +0 -3
- package/dist/api/hello.d.ts.map +0 -1
- package/dist/api/users/[id].d.ts +0 -5
- package/dist/api/users/[id].d.ts.map +0 -1
- package/dist/browser.d.ts +0 -29
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.package.json +0 -4
- package/dist/frontend/components/WasmLoader.d.ts +0 -2
- package/dist/frontend/components/WasmLoader.d.ts.map +0 -1
- package/dist/frontend/hooks/useWasm.d.ts +0 -2
- package/dist/frontend/hooks/useWasm.d.ts.map +0 -1
- package/dist/frontend/index.d.ts +0 -2
- package/dist/frontend/index.d.ts.map +0 -1
- package/dist/index.d.ts +0 -34
- package/dist/index.d.ts.map +0 -1
- package/dist/renderComponent.d.ts +0 -9
- package/dist/renderComponent.d.ts.map +0 -1
- package/dist/server/api-router.d.ts +0 -16
- package/dist/server/api-router.d.ts.map +0 -1
- package/dist/server/auth.d.ts +0 -25
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/database.d.ts +0 -22
- package/dist/server/database.d.ts.map +0 -1
- package/dist/server/index.d.ts +0 -115
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -7
- package/dist/server/middleware.d.ts +0 -11
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/package.json +0 -4
- package/dist/server/templates.d.ts +0 -31
- package/dist/server/templates.d.ts.map +0 -1
- package/dist/server/types.d.ts +0 -69
- package/dist/server/types.d.ts.map +0 -1
- package/dist/server/utils.d.ts +0 -70
- package/dist/server/utils.d.ts.map +0 -1
- package/dist/server/wasm.d.ts +0 -29
- package/dist/server/wasm.d.ts.map +0 -1
- package/dist/server-renderer.d.ts +0 -5
- package/dist/server-renderer.d.ts.map +0 -1
- package/dist/wasm.d.ts +0 -51
- package/dist/wasm.d.ts.map +0 -1
- package/templates/wasm/src/index.html +0 -14
- package/templates/wasm/src/main.tsx +0 -5
- package/templates/wasm/src/wasm-loader.ts +0 -119
package/dist/index.js
CHANGED
|
@@ -15,1008 +15,6 @@ var __export = (target, all) => {
|
|
|
15
15
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
// node_modules/frontend-hamroun/dist/index.js
|
|
19
|
-
function jsx(type, props) {
|
|
20
|
-
console.log("JSX Transform:", { type, props });
|
|
21
|
-
const processedProps = { ...props };
|
|
22
|
-
if (arguments.length > 2) {
|
|
23
|
-
processedProps.children = Array.prototype.slice.call(arguments, 2);
|
|
24
|
-
}
|
|
25
|
-
return { type, props: processedProps };
|
|
26
|
-
}
|
|
27
|
-
async function createElement(vnode) {
|
|
28
|
-
console.log("Creating element from:", vnode);
|
|
29
|
-
if (vnode == null) {
|
|
30
|
-
return document.createTextNode("");
|
|
31
|
-
}
|
|
32
|
-
if (typeof vnode === "boolean") {
|
|
33
|
-
return document.createTextNode("");
|
|
34
|
-
}
|
|
35
|
-
if (typeof vnode === "number" || typeof vnode === "string") {
|
|
36
|
-
return document.createTextNode(String(vnode));
|
|
37
|
-
}
|
|
38
|
-
if (Array.isArray(vnode)) {
|
|
39
|
-
const fragment = document.createDocumentFragment();
|
|
40
|
-
for (const child of vnode) {
|
|
41
|
-
const node = await createElement(child);
|
|
42
|
-
fragment.appendChild(node);
|
|
43
|
-
}
|
|
44
|
-
return fragment;
|
|
45
|
-
}
|
|
46
|
-
if ("type" in vnode && vnode.props !== void 0) {
|
|
47
|
-
const { type, props } = vnode;
|
|
48
|
-
if (typeof type === "function") {
|
|
49
|
-
try {
|
|
50
|
-
const result = await type(props || {});
|
|
51
|
-
const node = await createElement(result);
|
|
52
|
-
if (node instanceof Element) {
|
|
53
|
-
node.setAttribute("data-component-id", type.name || type.toString());
|
|
54
|
-
}
|
|
55
|
-
return node;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error("Error rendering component:", error);
|
|
58
|
-
return document.createTextNode("");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const element = document.createElement(type);
|
|
62
|
-
for (const [key, value] of Object.entries(props || {})) {
|
|
63
|
-
if (key === "children")
|
|
64
|
-
continue;
|
|
65
|
-
if (key.startsWith("on") && typeof value === "function") {
|
|
66
|
-
const eventName = key.toLowerCase().slice(2);
|
|
67
|
-
const existingHandler = element.__events?.[eventName];
|
|
68
|
-
if (existingHandler) {
|
|
69
|
-
element.removeEventListener(eventName, existingHandler);
|
|
70
|
-
}
|
|
71
|
-
element.addEventListener(eventName, value);
|
|
72
|
-
if (!element.__events) {
|
|
73
|
-
element.__events = {};
|
|
74
|
-
}
|
|
75
|
-
element.__events[eventName] = value;
|
|
76
|
-
} else if (key === "style" && typeof value === "object") {
|
|
77
|
-
Object.assign(element.style, value);
|
|
78
|
-
} else if (key === "className") {
|
|
79
|
-
element.setAttribute("class", String(value));
|
|
80
|
-
} else if (key !== "key" && key !== "ref") {
|
|
81
|
-
element.setAttribute(key, String(value));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const children = props?.children;
|
|
85
|
-
if (children != null) {
|
|
86
|
-
const childArray = Array.isArray(children) ? children.flat() : [children];
|
|
87
|
-
for (const child of childArray) {
|
|
88
|
-
const childNode = await createElement(child);
|
|
89
|
-
element.appendChild(childNode);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return element;
|
|
93
|
-
}
|
|
94
|
-
return document.createTextNode(String(vnode));
|
|
95
|
-
}
|
|
96
|
-
function batchUpdates(fn) {
|
|
97
|
-
if (isBatching) {
|
|
98
|
-
queue.push(fn);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
isBatching = true;
|
|
102
|
-
try {
|
|
103
|
-
fn();
|
|
104
|
-
while (queue.length > 0) {
|
|
105
|
-
const nextFn = queue.shift();
|
|
106
|
-
nextFn?.();
|
|
107
|
-
}
|
|
108
|
-
} finally {
|
|
109
|
-
isBatching = false;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function createContext(defaultValue) {
|
|
113
|
-
const contextId = Symbol("context");
|
|
114
|
-
const Provider = ({ value, children }) => {
|
|
115
|
-
contexts.set(contextId, value);
|
|
116
|
-
return children;
|
|
117
|
-
};
|
|
118
|
-
const Consumer = ({ children }) => {
|
|
119
|
-
const value = contexts.get(contextId) ?? defaultValue;
|
|
120
|
-
return children(value);
|
|
121
|
-
};
|
|
122
|
-
const context = {
|
|
123
|
-
Provider,
|
|
124
|
-
Consumer,
|
|
125
|
-
displayName: "Context"
|
|
126
|
-
};
|
|
127
|
-
return context;
|
|
128
|
-
}
|
|
129
|
-
function useContext(context) {
|
|
130
|
-
return {};
|
|
131
|
-
}
|
|
132
|
-
function setRenderCallback(callback, element, container) {
|
|
133
|
-
globalRenderCallback = callback;
|
|
134
|
-
globalContainer = container;
|
|
135
|
-
currentElement = element;
|
|
136
|
-
}
|
|
137
|
-
function prepareRender(component = null, isServerSideRender = false) {
|
|
138
|
-
currentRender++;
|
|
139
|
-
isSSR = isServerSideRender;
|
|
140
|
-
stateIndices.set(currentRender, 0);
|
|
141
|
-
if (!states.has(currentRender)) {
|
|
142
|
-
states.set(currentRender, []);
|
|
143
|
-
}
|
|
144
|
-
return currentRender;
|
|
145
|
-
}
|
|
146
|
-
function finishRender() {
|
|
147
|
-
}
|
|
148
|
-
function useState(initial) {
|
|
149
|
-
if (!currentRender) {
|
|
150
|
-
throw new Error("useState must be called within a render");
|
|
151
|
-
}
|
|
152
|
-
if (!states.has(currentRender)) {
|
|
153
|
-
states.set(currentRender, []);
|
|
154
|
-
}
|
|
155
|
-
const componentStates = states.get(currentRender);
|
|
156
|
-
const index = stateIndices.get(currentRender) || 0;
|
|
157
|
-
if (index >= componentStates.length) {
|
|
158
|
-
componentStates.push(initial);
|
|
159
|
-
}
|
|
160
|
-
const state = componentStates[index];
|
|
161
|
-
const setState = (newValue) => {
|
|
162
|
-
if (isSSR) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
const nextValue = typeof newValue === "function" ? newValue(componentStates[index]) : newValue;
|
|
166
|
-
if (componentStates[index] === nextValue)
|
|
167
|
-
return;
|
|
168
|
-
componentStates[index] = nextValue;
|
|
169
|
-
if (isBatching) {
|
|
170
|
-
batchUpdates(() => rerender(currentRender));
|
|
171
|
-
} else {
|
|
172
|
-
rerender(currentRender);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
stateIndices.set(currentRender, index + 1);
|
|
176
|
-
return [state, setState];
|
|
177
|
-
}
|
|
178
|
-
function useEffect(callback, deps) {
|
|
179
|
-
if (!currentRender)
|
|
180
|
-
throw new Error("useEffect must be called within a render");
|
|
181
|
-
if (isSSR) {
|
|
182
|
-
const effectIndex2 = stateIndices.get(currentRender) || 0;
|
|
183
|
-
stateIndices.set(currentRender, effectIndex2 + 1);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const effectIndex = stateIndices.get(currentRender) || 0;
|
|
187
|
-
if (!effects.has(currentRender)) {
|
|
188
|
-
effects.set(currentRender, []);
|
|
189
|
-
}
|
|
190
|
-
const componentEffects = effects.get(currentRender);
|
|
191
|
-
const prevEffect = componentEffects[effectIndex];
|
|
192
|
-
if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
|
|
193
|
-
if (prevEffect?.cleanup) {
|
|
194
|
-
prevEffect.cleanup();
|
|
195
|
-
}
|
|
196
|
-
queueMicrotask(() => {
|
|
197
|
-
const cleanup = callback() || void 0;
|
|
198
|
-
componentEffects[effectIndex] = { cleanup, deps: deps || [] };
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
stateIndices.set(currentRender, effectIndex + 1);
|
|
202
|
-
}
|
|
203
|
-
function useMemo(factory, deps) {
|
|
204
|
-
if (!currentRender)
|
|
205
|
-
throw new Error("useMemo must be called within a render");
|
|
206
|
-
const memoIndex = stateIndices.get(currentRender) || 0;
|
|
207
|
-
if (!memos.has(currentRender)) {
|
|
208
|
-
memos.set(currentRender, []);
|
|
209
|
-
}
|
|
210
|
-
const componentMemos = memos.get(currentRender);
|
|
211
|
-
const prevMemo = componentMemos[memoIndex];
|
|
212
|
-
if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
|
|
213
|
-
const value = factory();
|
|
214
|
-
componentMemos[memoIndex] = { value, deps: deps || [] };
|
|
215
|
-
stateIndices.set(currentRender, memoIndex + 1);
|
|
216
|
-
return value;
|
|
217
|
-
}
|
|
218
|
-
stateIndices.set(currentRender, memoIndex + 1);
|
|
219
|
-
return prevMemo.value;
|
|
220
|
-
}
|
|
221
|
-
function useRef(initial) {
|
|
222
|
-
if (!currentRender)
|
|
223
|
-
throw new Error("useRef must be called within a render");
|
|
224
|
-
const refIndex = stateIndices.get(currentRender) || 0;
|
|
225
|
-
if (!refs.has(currentRender)) {
|
|
226
|
-
refs.set(currentRender, []);
|
|
227
|
-
}
|
|
228
|
-
const componentRefs = refs.get(currentRender);
|
|
229
|
-
if (refIndex >= componentRefs.length) {
|
|
230
|
-
const ref2 = { current: initial };
|
|
231
|
-
componentRefs.push(ref2);
|
|
232
|
-
stateIndices.set(currentRender, refIndex + 1);
|
|
233
|
-
return ref2;
|
|
234
|
-
}
|
|
235
|
-
const ref = componentRefs[refIndex];
|
|
236
|
-
stateIndices.set(currentRender, refIndex + 1);
|
|
237
|
-
return ref;
|
|
238
|
-
}
|
|
239
|
-
async function rerender(rendererId) {
|
|
240
|
-
try {
|
|
241
|
-
if (isSSR) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
const componentEffects = effects.get(rendererId);
|
|
245
|
-
if (componentEffects) {
|
|
246
|
-
componentEffects.forEach((effect) => {
|
|
247
|
-
if (effect.cleanup)
|
|
248
|
-
effect.cleanup();
|
|
249
|
-
});
|
|
250
|
-
effects.set(rendererId, []);
|
|
251
|
-
}
|
|
252
|
-
if (globalRenderCallback && globalContainer && currentElement) {
|
|
253
|
-
await globalRenderCallback(currentElement, globalContainer);
|
|
254
|
-
}
|
|
255
|
-
} catch (error) {
|
|
256
|
-
console.error("Error during rerender:", error);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function useErrorBoundary() {
|
|
260
|
-
const [error, setError] = useState(null);
|
|
261
|
-
return [error, () => setError(null)];
|
|
262
|
-
}
|
|
263
|
-
async function render(element, container) {
|
|
264
|
-
try {
|
|
265
|
-
setRenderCallback(render, element, container);
|
|
266
|
-
const renderId = prepareRender(element);
|
|
267
|
-
const domNode = await createElement(element);
|
|
268
|
-
if (container instanceof Element) {
|
|
269
|
-
container.innerHTML = "";
|
|
270
|
-
} else {
|
|
271
|
-
while (container.firstChild) {
|
|
272
|
-
container.removeChild(container.firstChild);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
container.appendChild(domNode);
|
|
276
|
-
finishRender();
|
|
277
|
-
console.log("Render completed successfully");
|
|
278
|
-
} catch (error) {
|
|
279
|
-
console.error("Error during render:", error);
|
|
280
|
-
throw error;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
async function hydrate(element, container) {
|
|
284
|
-
try {
|
|
285
|
-
console.log("Starting hydration...");
|
|
286
|
-
await render(element, container);
|
|
287
|
-
console.log("Hydration completed successfully");
|
|
288
|
-
} catch (error) {
|
|
289
|
-
console.error("Error during hydration:", error);
|
|
290
|
-
throw error;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async function renderToString(element) {
|
|
294
|
-
prepareRender(element);
|
|
295
|
-
try {
|
|
296
|
-
const html = await renderNodeToString(element);
|
|
297
|
-
return html;
|
|
298
|
-
} finally {
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
async function renderNodeToString(node) {
|
|
302
|
-
if (node == null || typeof node === "boolean") {
|
|
303
|
-
return "";
|
|
304
|
-
}
|
|
305
|
-
if (typeof node === "string" || typeof node === "number") {
|
|
306
|
-
return escapeHtml(String(node));
|
|
307
|
-
}
|
|
308
|
-
if (Array.isArray(node)) {
|
|
309
|
-
const results = await Promise.all(node.map((child) => renderNodeToString(child)));
|
|
310
|
-
return results.join("");
|
|
311
|
-
}
|
|
312
|
-
if (node && typeof node === "object" && "type" in node) {
|
|
313
|
-
const { type, props = {} } = node;
|
|
314
|
-
if (typeof type === "function") {
|
|
315
|
-
try {
|
|
316
|
-
const componentRenderId = prepareRender(type);
|
|
317
|
-
try {
|
|
318
|
-
const result = await type(props);
|
|
319
|
-
return await renderNodeToString(result);
|
|
320
|
-
} finally {
|
|
321
|
-
finishRender();
|
|
322
|
-
}
|
|
323
|
-
} catch (error) {
|
|
324
|
-
console.error("Error rendering component:", error);
|
|
325
|
-
return `<!-- Error rendering component: ${error.message} -->`;
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (typeof type === "string") {
|
|
329
|
-
return await renderDOMElement(type, props);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (typeof node === "object") {
|
|
333
|
-
return escapeHtml(JSON.stringify(node));
|
|
334
|
-
}
|
|
335
|
-
return escapeHtml(String(node));
|
|
336
|
-
}
|
|
337
|
-
async function renderDOMElement(tagName, props) {
|
|
338
|
-
const { children, ...attrs } = props;
|
|
339
|
-
const voidElements = /* @__PURE__ */ new Set([
|
|
340
|
-
"area",
|
|
341
|
-
"base",
|
|
342
|
-
"br",
|
|
343
|
-
"col",
|
|
344
|
-
"embed",
|
|
345
|
-
"hr",
|
|
346
|
-
"img",
|
|
347
|
-
"input",
|
|
348
|
-
"link",
|
|
349
|
-
"meta",
|
|
350
|
-
"param",
|
|
351
|
-
"source",
|
|
352
|
-
"track",
|
|
353
|
-
"wbr"
|
|
354
|
-
]);
|
|
355
|
-
const attributeString = Object.entries(attrs).filter(([key, value]) => {
|
|
356
|
-
if (key.startsWith("on") || key === "key" || key === "ref")
|
|
357
|
-
return false;
|
|
358
|
-
if (value == null || value === false)
|
|
359
|
-
return false;
|
|
360
|
-
return true;
|
|
361
|
-
}).map(([key, value]) => {
|
|
362
|
-
if (key === "className")
|
|
363
|
-
key = "class";
|
|
364
|
-
if (value === true)
|
|
365
|
-
return key;
|
|
366
|
-
if (key === "style" && typeof value === "object" && value !== null) {
|
|
367
|
-
const styleString = Object.entries(value).map(([prop, val]) => `${kebabCase(prop)}:${val}`).join(";");
|
|
368
|
-
return `style="${escapeHtml(styleString)}"`;
|
|
369
|
-
}
|
|
370
|
-
return `${key}="${escapeHtml(String(value))}"`;
|
|
371
|
-
}).join(" ");
|
|
372
|
-
const openTag = `<${tagName}${attributeString ? " " + attributeString : ""}>`;
|
|
373
|
-
if (voidElements.has(tagName)) {
|
|
374
|
-
return openTag.slice(0, -1) + "/>";
|
|
375
|
-
}
|
|
376
|
-
const closeTag = `</${tagName}>`;
|
|
377
|
-
if (children != null) {
|
|
378
|
-
const childrenString = await renderNodeToString(children);
|
|
379
|
-
return openTag + childrenString + closeTag;
|
|
380
|
-
}
|
|
381
|
-
return openTag + closeTag;
|
|
382
|
-
}
|
|
383
|
-
function escapeHtml(text) {
|
|
384
|
-
const htmlEscapes = {
|
|
385
|
-
"&": "&",
|
|
386
|
-
"<": "<",
|
|
387
|
-
">": ">",
|
|
388
|
-
'"': """,
|
|
389
|
-
"'": "'",
|
|
390
|
-
"/": "/"
|
|
391
|
-
};
|
|
392
|
-
return text.replace(/[&<>"'/]/g, (match) => htmlEscapes[match]);
|
|
393
|
-
}
|
|
394
|
-
function kebabCase(str) {
|
|
395
|
-
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
396
|
-
}
|
|
397
|
-
function arePropsEqual(oldProps, newProps) {
|
|
398
|
-
const oldKeys = Object.keys(oldProps).filter((k) => k !== "children");
|
|
399
|
-
const newKeys = Object.keys(newProps).filter((k) => k !== "children");
|
|
400
|
-
if (oldKeys.length !== newKeys.length)
|
|
401
|
-
return false;
|
|
402
|
-
return oldKeys.every((key) => oldProps[key] === newProps[key]);
|
|
403
|
-
}
|
|
404
|
-
function diff(oldNode, newNode) {
|
|
405
|
-
if (oldNode == null || newNode == null)
|
|
406
|
-
return oldNode !== newNode;
|
|
407
|
-
if (typeof oldNode !== typeof newNode)
|
|
408
|
-
return true;
|
|
409
|
-
if (typeof newNode === "string" || typeof newNode === "number")
|
|
410
|
-
return oldNode !== newNode;
|
|
411
|
-
if (newNode.type !== oldNode.type)
|
|
412
|
-
return true;
|
|
413
|
-
return !arePropsEqual(oldNode.props, newNode.props);
|
|
414
|
-
}
|
|
415
|
-
function shouldComponentUpdate(oldProps, newProps) {
|
|
416
|
-
return !arePropsEqual(oldProps, newProps);
|
|
417
|
-
}
|
|
418
|
-
function parsePath(path5) {
|
|
419
|
-
const pattern = path5.replace(/\/+$/, "").replace(/^\/+/, "/").replace(/\/:([^/]+)/g, "/([^/]+)");
|
|
420
|
-
const paramNames = [];
|
|
421
|
-
path5.replace(/\/:([^/]+)/g, (_, paramName) => {
|
|
422
|
-
paramNames.push(paramName);
|
|
423
|
-
return "";
|
|
424
|
-
});
|
|
425
|
-
return { pattern, paramNames };
|
|
426
|
-
}
|
|
427
|
-
function matchPath(pathname, route) {
|
|
428
|
-
const { path: path5, exact = false } = route;
|
|
429
|
-
const { pattern, paramNames } = parsePath(path5);
|
|
430
|
-
const regex = new RegExp(`^${pattern}${exact ? "$" : ""}`);
|
|
431
|
-
const match = pathname.match(regex);
|
|
432
|
-
if (!match)
|
|
433
|
-
return null;
|
|
434
|
-
const params = {};
|
|
435
|
-
paramNames.forEach((name, index) => {
|
|
436
|
-
params[name] = match[index + 1];
|
|
437
|
-
});
|
|
438
|
-
return params;
|
|
439
|
-
}
|
|
440
|
-
function RouterProvider({ routes, children }) {
|
|
441
|
-
const getInitialLocation = () => {
|
|
442
|
-
if (typeof window === "undefined") {
|
|
443
|
-
return { pathname: "/", search: "", hash: "" };
|
|
444
|
-
}
|
|
445
|
-
return {
|
|
446
|
-
pathname: window.location.pathname,
|
|
447
|
-
search: window.location.search,
|
|
448
|
-
hash: window.location.hash
|
|
449
|
-
};
|
|
450
|
-
};
|
|
451
|
-
const [location, setLocation] = useState(getInitialLocation());
|
|
452
|
-
const [params, setParams] = useState({});
|
|
453
|
-
useEffect(() => {
|
|
454
|
-
for (const route of routes) {
|
|
455
|
-
const matchedParams = matchPath(location.pathname, route);
|
|
456
|
-
if (matchedParams) {
|
|
457
|
-
setParams(matchedParams);
|
|
458
|
-
break;
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}, [location, routes]);
|
|
462
|
-
useEffect(() => {
|
|
463
|
-
if (typeof window === "undefined")
|
|
464
|
-
return;
|
|
465
|
-
const handlePopState = () => {
|
|
466
|
-
setLocation({
|
|
467
|
-
pathname: window.location.pathname,
|
|
468
|
-
search: window.location.search,
|
|
469
|
-
hash: window.location.hash
|
|
470
|
-
});
|
|
471
|
-
};
|
|
472
|
-
window.addEventListener("popstate", handlePopState);
|
|
473
|
-
return () => window.removeEventListener("popstate", handlePopState);
|
|
474
|
-
}, []);
|
|
475
|
-
const navigate = (to, options = {}) => {
|
|
476
|
-
if (typeof window === "undefined")
|
|
477
|
-
return;
|
|
478
|
-
const { replace = false, state = null } = options;
|
|
479
|
-
if (replace) {
|
|
480
|
-
window.history.replaceState(state, "", to);
|
|
481
|
-
} else {
|
|
482
|
-
window.history.pushState(state, "", to);
|
|
483
|
-
}
|
|
484
|
-
setLocation({
|
|
485
|
-
pathname: window.location.pathname,
|
|
486
|
-
search: window.location.search,
|
|
487
|
-
hash: window.location.hash
|
|
488
|
-
});
|
|
489
|
-
};
|
|
490
|
-
const match = (path5) => {
|
|
491
|
-
const { pattern } = parsePath(path5);
|
|
492
|
-
const regex = new RegExp(`^${pattern}`);
|
|
493
|
-
return regex.test(location.pathname);
|
|
494
|
-
};
|
|
495
|
-
const routerValue = {
|
|
496
|
-
location: {
|
|
497
|
-
pathname: location.pathname,
|
|
498
|
-
search: location.search,
|
|
499
|
-
hash: location.hash
|
|
500
|
-
},
|
|
501
|
-
params,
|
|
502
|
-
navigate,
|
|
503
|
-
match
|
|
504
|
-
};
|
|
505
|
-
return jsx(RouterContext.Provider, { value: routerValue, children });
|
|
506
|
-
}
|
|
507
|
-
function Route({ path: path5, component: Component2, props = {} }) {
|
|
508
|
-
const context = useContext();
|
|
509
|
-
const params = context.params;
|
|
510
|
-
const locationPathname = context.location.pathname;
|
|
511
|
-
const routeToMatch = { path: path5, component: Component2 };
|
|
512
|
-
const match = matchPath(locationPathname, routeToMatch);
|
|
513
|
-
if (!match)
|
|
514
|
-
return null;
|
|
515
|
-
return jsx(Component2, { ...props, params });
|
|
516
|
-
}
|
|
517
|
-
function Switch({ children }) {
|
|
518
|
-
const context = useContext();
|
|
519
|
-
const locationPathname = context.location.pathname;
|
|
520
|
-
const child = Array.isArray(children) ? children.find((child2) => {
|
|
521
|
-
if (!child2 || typeof child2.type !== "function" || !child2.props.path)
|
|
522
|
-
return false;
|
|
523
|
-
const routeObj = {
|
|
524
|
-
path: child2.props.path,
|
|
525
|
-
component: child2.type,
|
|
526
|
-
exact: child2.props.exact || false
|
|
527
|
-
};
|
|
528
|
-
return matchPath(locationPathname, routeObj);
|
|
529
|
-
}) : children;
|
|
530
|
-
return child || null;
|
|
531
|
-
}
|
|
532
|
-
function Link({ to, replace = false, state = null, className = "", activeClassName = "", children, ...rest }) {
|
|
533
|
-
const context = useContext();
|
|
534
|
-
const navigate = context.navigate;
|
|
535
|
-
const match = context.match;
|
|
536
|
-
const handleClick = (e) => {
|
|
537
|
-
e.preventDefault();
|
|
538
|
-
navigate(to, { replace, state });
|
|
539
|
-
};
|
|
540
|
-
const isActive = match(to);
|
|
541
|
-
const classes = [
|
|
542
|
-
className,
|
|
543
|
-
isActive ? activeClassName : ""
|
|
544
|
-
].filter(Boolean).join(" ");
|
|
545
|
-
return jsx("a", {
|
|
546
|
-
href: to,
|
|
547
|
-
className: classes || void 0,
|
|
548
|
-
onClick: handleClick,
|
|
549
|
-
...rest,
|
|
550
|
-
children
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
function Redirect({ to, replace = true }) {
|
|
554
|
-
const context = useContext();
|
|
555
|
-
const navigate = context.navigate;
|
|
556
|
-
useEffect(() => {
|
|
557
|
-
navigate(to, { replace });
|
|
558
|
-
}, [to]);
|
|
559
|
-
return null;
|
|
560
|
-
}
|
|
561
|
-
function useLocation() {
|
|
562
|
-
const context = useContext();
|
|
563
|
-
return context.location;
|
|
564
|
-
}
|
|
565
|
-
function useParams() {
|
|
566
|
-
const context = useContext();
|
|
567
|
-
return context.params;
|
|
568
|
-
}
|
|
569
|
-
function useNavigate() {
|
|
570
|
-
const context = useContext();
|
|
571
|
-
return context.navigate;
|
|
572
|
-
}
|
|
573
|
-
function useForm(options) {
|
|
574
|
-
const { initialValues, validate, onSubmit } = options;
|
|
575
|
-
const [values, setValues] = useState(initialValues);
|
|
576
|
-
const [errors, setErrors] = useState({});
|
|
577
|
-
const [touched, setTouched] = useState({});
|
|
578
|
-
const [dirty, setDirty] = useState({});
|
|
579
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
580
|
-
const [submitCount, setSubmitCount] = useState(0);
|
|
581
|
-
const isValid = Object.keys(errors).length === 0;
|
|
582
|
-
const isDirty = Object.values(dirty).some(Boolean);
|
|
583
|
-
useEffect(() => {
|
|
584
|
-
if (validate) {
|
|
585
|
-
const validationErrors = validate(values);
|
|
586
|
-
setErrors(validationErrors || {});
|
|
587
|
-
}
|
|
588
|
-
}, [values, validate]);
|
|
589
|
-
const handleChange = (e) => {
|
|
590
|
-
const { name, value, type, checked } = e.target;
|
|
591
|
-
const fieldValue = type === "checkbox" ? checked : value;
|
|
592
|
-
setValues((prev) => ({
|
|
593
|
-
...prev,
|
|
594
|
-
[name]: fieldValue
|
|
595
|
-
}));
|
|
596
|
-
setDirty((prev) => ({
|
|
597
|
-
...prev,
|
|
598
|
-
[name]: true
|
|
599
|
-
}));
|
|
600
|
-
};
|
|
601
|
-
const handleBlur = (e) => {
|
|
602
|
-
const { name } = e.target;
|
|
603
|
-
setTouched((prev) => ({
|
|
604
|
-
...prev,
|
|
605
|
-
[name]: true
|
|
606
|
-
}));
|
|
607
|
-
};
|
|
608
|
-
const setFieldValue = (field, value) => {
|
|
609
|
-
setValues((prev) => ({
|
|
610
|
-
...prev,
|
|
611
|
-
[field]: value
|
|
612
|
-
}));
|
|
613
|
-
setDirty((prev) => ({
|
|
614
|
-
...prev,
|
|
615
|
-
[field]: true
|
|
616
|
-
}));
|
|
617
|
-
};
|
|
618
|
-
const setFieldError = (field, error) => {
|
|
619
|
-
setErrors((prev) => ({
|
|
620
|
-
...prev,
|
|
621
|
-
[field]: error
|
|
622
|
-
}));
|
|
623
|
-
};
|
|
624
|
-
const updateValues = (newValues) => {
|
|
625
|
-
setValues((prev) => ({
|
|
626
|
-
...prev,
|
|
627
|
-
...newValues
|
|
628
|
-
}));
|
|
629
|
-
const dirtyFields = {};
|
|
630
|
-
Object.keys(newValues).forEach((key) => {
|
|
631
|
-
dirtyFields[key] = true;
|
|
632
|
-
});
|
|
633
|
-
setDirty((prev) => ({
|
|
634
|
-
...prev,
|
|
635
|
-
...dirtyFields
|
|
636
|
-
}));
|
|
637
|
-
};
|
|
638
|
-
const resetForm = () => {
|
|
639
|
-
setValues(initialValues);
|
|
640
|
-
setErrors({});
|
|
641
|
-
setTouched({});
|
|
642
|
-
setDirty({});
|
|
643
|
-
setIsSubmitting(false);
|
|
644
|
-
};
|
|
645
|
-
const handleSubmit = async (e) => {
|
|
646
|
-
e.preventDefault();
|
|
647
|
-
const allTouched = {};
|
|
648
|
-
Object.keys(values).forEach((key) => {
|
|
649
|
-
allTouched[key] = true;
|
|
650
|
-
});
|
|
651
|
-
setTouched(allTouched);
|
|
652
|
-
let validationErrors = {};
|
|
653
|
-
if (validate) {
|
|
654
|
-
validationErrors = validate(values);
|
|
655
|
-
setErrors(validationErrors || {});
|
|
656
|
-
}
|
|
657
|
-
if (Object.keys(validationErrors).length === 0 && onSubmit) {
|
|
658
|
-
setIsSubmitting(true);
|
|
659
|
-
setSubmitCount((count) => count + 1);
|
|
660
|
-
try {
|
|
661
|
-
await onSubmit(values, {
|
|
662
|
-
fields: Object.keys(values).reduce((acc, key) => {
|
|
663
|
-
acc[key] = {
|
|
664
|
-
value: values[key],
|
|
665
|
-
error: errors[key],
|
|
666
|
-
touched: touched[key] || false,
|
|
667
|
-
dirty: dirty[key] || false
|
|
668
|
-
};
|
|
669
|
-
return acc;
|
|
670
|
-
}, {}),
|
|
671
|
-
isValid,
|
|
672
|
-
isDirty,
|
|
673
|
-
isSubmitting: true,
|
|
674
|
-
submitCount: submitCount + 1
|
|
675
|
-
});
|
|
676
|
-
} finally {
|
|
677
|
-
setIsSubmitting(false);
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
return {
|
|
682
|
-
values,
|
|
683
|
-
errors,
|
|
684
|
-
touched,
|
|
685
|
-
dirty,
|
|
686
|
-
isValid,
|
|
687
|
-
isDirty,
|
|
688
|
-
isSubmitting,
|
|
689
|
-
submitCount,
|
|
690
|
-
handleChange,
|
|
691
|
-
handleBlur,
|
|
692
|
-
handleSubmit,
|
|
693
|
-
setFieldValue,
|
|
694
|
-
setFieldError,
|
|
695
|
-
setValues: updateValues,
|
|
696
|
-
resetForm
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
function createEventBus() {
|
|
700
|
-
const events = /* @__PURE__ */ new Map();
|
|
701
|
-
const onceHandlers = /* @__PURE__ */ new WeakMap();
|
|
702
|
-
const on = (event, handler) => {
|
|
703
|
-
if (!events.has(event)) {
|
|
704
|
-
events.set(event, /* @__PURE__ */ new Set());
|
|
705
|
-
}
|
|
706
|
-
events.get(event).add(handler);
|
|
707
|
-
return () => off(event, handler);
|
|
708
|
-
};
|
|
709
|
-
const once = (event, handler) => {
|
|
710
|
-
const onceWrapper = (...args) => {
|
|
711
|
-
off(event, onceWrapper);
|
|
712
|
-
handler(...args);
|
|
713
|
-
};
|
|
714
|
-
onceHandlers.set(handler, onceWrapper);
|
|
715
|
-
return on(event, onceWrapper);
|
|
716
|
-
};
|
|
717
|
-
const off = (event, handler) => {
|
|
718
|
-
if (!handler) {
|
|
719
|
-
events.delete(event);
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
const wrappedHandler = onceHandlers.get(handler);
|
|
723
|
-
const handlerToRemove = wrappedHandler || handler;
|
|
724
|
-
if (events.has(event)) {
|
|
725
|
-
events.get(event).delete(handlerToRemove);
|
|
726
|
-
if (events.get(event).size === 0) {
|
|
727
|
-
events.delete(event);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
const emit = (event, ...args) => {
|
|
732
|
-
if (!events.has(event)) {
|
|
733
|
-
return;
|
|
734
|
-
}
|
|
735
|
-
const handlers = Array.from(events.get(event));
|
|
736
|
-
for (const handler of handlers) {
|
|
737
|
-
handler(...args);
|
|
738
|
-
}
|
|
739
|
-
};
|
|
740
|
-
const clear = (event) => {
|
|
741
|
-
if (event) {
|
|
742
|
-
events.delete(event);
|
|
743
|
-
} else {
|
|
744
|
-
events.clear();
|
|
745
|
-
}
|
|
746
|
-
};
|
|
747
|
-
return { on, once, off, emit, clear };
|
|
748
|
-
}
|
|
749
|
-
function useEvent(event, handler, options = {}) {
|
|
750
|
-
return options.once ? globalEventBus.once(event, handler) : globalEventBus.on(event, handler);
|
|
751
|
-
}
|
|
752
|
-
function createStore(reducer, initialState, middlewares = []) {
|
|
753
|
-
let state = initialState;
|
|
754
|
-
let listeners = [];
|
|
755
|
-
let dispatch = (action) => {
|
|
756
|
-
state = reducer(state, action);
|
|
757
|
-
listeners.forEach((listener) => listener());
|
|
758
|
-
return action;
|
|
759
|
-
};
|
|
760
|
-
if (middlewares.length > 0) {
|
|
761
|
-
const middlewareAPI = {
|
|
762
|
-
getState: () => state,
|
|
763
|
-
dispatch: (action) => dispatch(action),
|
|
764
|
-
subscribe: (listener) => subscribe(listener)
|
|
765
|
-
};
|
|
766
|
-
const chain = middlewares.map((middleware) => middleware(middlewareAPI));
|
|
767
|
-
dispatch = chain.reduce((a, b) => (next) => a(b(next)))(dispatch);
|
|
768
|
-
}
|
|
769
|
-
function subscribe(listener) {
|
|
770
|
-
listeners.push(listener);
|
|
771
|
-
return function unsubscribe() {
|
|
772
|
-
listeners = listeners.filter((l) => l !== listener);
|
|
773
|
-
};
|
|
774
|
-
}
|
|
775
|
-
dispatch({ type: "@@INIT" });
|
|
776
|
-
return {
|
|
777
|
-
getState: () => state,
|
|
778
|
-
dispatch,
|
|
779
|
-
subscribe
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
function StoreProvider({ store, children }) {
|
|
783
|
-
const [state, setState] = useState(store.getState());
|
|
784
|
-
useEffect(() => {
|
|
785
|
-
const unsubscribe = store.subscribe(() => {
|
|
786
|
-
setState(store.getState());
|
|
787
|
-
});
|
|
788
|
-
return unsubscribe;
|
|
789
|
-
}, [store]);
|
|
790
|
-
return jsx(StoreContext.Provider, {
|
|
791
|
-
value: { store, state },
|
|
792
|
-
children
|
|
793
|
-
});
|
|
794
|
-
}
|
|
795
|
-
function useSelector(selector) {
|
|
796
|
-
const context = useContext();
|
|
797
|
-
return selector(context.state);
|
|
798
|
-
}
|
|
799
|
-
function useDispatch() {
|
|
800
|
-
const context = useContext();
|
|
801
|
-
return context.store.dispatch;
|
|
802
|
-
}
|
|
803
|
-
function useStore() {
|
|
804
|
-
const context = useContext();
|
|
805
|
-
return context.store;
|
|
806
|
-
}
|
|
807
|
-
function emitAppInit(data) {
|
|
808
|
-
globalEventBus.emit(LifecycleEvents.APP_INIT, data);
|
|
809
|
-
}
|
|
810
|
-
function emitAppMounted(rootElement) {
|
|
811
|
-
globalEventBus.emit(LifecycleEvents.APP_MOUNTED, rootElement);
|
|
812
|
-
}
|
|
813
|
-
function emitAppUpdated() {
|
|
814
|
-
globalEventBus.emit(LifecycleEvents.APP_UPDATED);
|
|
815
|
-
}
|
|
816
|
-
function emitAppError(error) {
|
|
817
|
-
globalEventBus.emit(LifecycleEvents.APP_ERROR, error);
|
|
818
|
-
}
|
|
819
|
-
function emitAppDestroyed() {
|
|
820
|
-
globalEventBus.emit(LifecycleEvents.APP_DESTROYED);
|
|
821
|
-
}
|
|
822
|
-
function emitComponentCreated(info) {
|
|
823
|
-
globalEventBus.emit(LifecycleEvents.COMPONENT_CREATED, info);
|
|
824
|
-
}
|
|
825
|
-
function emitComponentMounted(info, element) {
|
|
826
|
-
globalEventBus.emit(LifecycleEvents.COMPONENT_MOUNTED, info, element);
|
|
827
|
-
}
|
|
828
|
-
function emitComponentUpdated(info, prevProps, newProps) {
|
|
829
|
-
globalEventBus.emit(LifecycleEvents.COMPONENT_UPDATED, info, prevProps, newProps);
|
|
830
|
-
}
|
|
831
|
-
function emitComponentError(info, error) {
|
|
832
|
-
globalEventBus.emit(LifecycleEvents.COMPONENT_ERROR, info, error);
|
|
833
|
-
}
|
|
834
|
-
function emitComponentUnmounted(info) {
|
|
835
|
-
globalEventBus.emit(LifecycleEvents.COMPONENT_UNMOUNTED, info);
|
|
836
|
-
}
|
|
837
|
-
function onAppInit(handler) {
|
|
838
|
-
return globalEventBus.on(LifecycleEvents.APP_INIT, handler);
|
|
839
|
-
}
|
|
840
|
-
function onAppMounted(handler) {
|
|
841
|
-
return globalEventBus.on(LifecycleEvents.APP_MOUNTED, handler);
|
|
842
|
-
}
|
|
843
|
-
function onAppUpdated(handler) {
|
|
844
|
-
return globalEventBus.on(LifecycleEvents.APP_UPDATED, handler);
|
|
845
|
-
}
|
|
846
|
-
function onAppError(handler) {
|
|
847
|
-
return globalEventBus.on(LifecycleEvents.APP_ERROR, handler);
|
|
848
|
-
}
|
|
849
|
-
function onAppDestroyed(handler) {
|
|
850
|
-
return globalEventBus.on(LifecycleEvents.APP_DESTROYED, handler);
|
|
851
|
-
}
|
|
852
|
-
function onComponentCreated(handler) {
|
|
853
|
-
return globalEventBus.on(LifecycleEvents.COMPONENT_CREATED, handler);
|
|
854
|
-
}
|
|
855
|
-
function onComponentMounted(handler) {
|
|
856
|
-
return globalEventBus.on(LifecycleEvents.COMPONENT_MOUNTED, handler);
|
|
857
|
-
}
|
|
858
|
-
function onComponentUpdated(handler) {
|
|
859
|
-
return globalEventBus.on(LifecycleEvents.COMPONENT_UPDATED, handler);
|
|
860
|
-
}
|
|
861
|
-
function onComponentError(handler) {
|
|
862
|
-
return globalEventBus.on(LifecycleEvents.COMPONENT_ERROR, handler);
|
|
863
|
-
}
|
|
864
|
-
function onComponentUnmounted(handler) {
|
|
865
|
-
return globalEventBus.on(LifecycleEvents.COMPONENT_UNMOUNTED, handler);
|
|
866
|
-
}
|
|
867
|
-
var Fragment, isBatching, queue, contexts, currentRender, isSSR, states, stateIndices, effects, memos, refs, globalRenderCallback, globalContainer, currentElement, Component, RouterContext, globalEventBus, StoreContext, logger, thunk, LifecycleEvents;
|
|
868
|
-
var init_dist = __esm({
|
|
869
|
-
"node_modules/frontend-hamroun/dist/index.js"() {
|
|
870
|
-
Fragment = ({ children }) => children;
|
|
871
|
-
isBatching = false;
|
|
872
|
-
queue = [];
|
|
873
|
-
contexts = /* @__PURE__ */ new Map();
|
|
874
|
-
currentRender = 0;
|
|
875
|
-
isSSR = false;
|
|
876
|
-
states = /* @__PURE__ */ new Map();
|
|
877
|
-
stateIndices = /* @__PURE__ */ new Map();
|
|
878
|
-
effects = /* @__PURE__ */ new Map();
|
|
879
|
-
memos = /* @__PURE__ */ new Map();
|
|
880
|
-
refs = /* @__PURE__ */ new Map();
|
|
881
|
-
globalRenderCallback = null;
|
|
882
|
-
globalContainer = null;
|
|
883
|
-
currentElement = null;
|
|
884
|
-
Component = class {
|
|
885
|
-
constructor(props = {}) {
|
|
886
|
-
this.state = {};
|
|
887
|
-
this.element = null;
|
|
888
|
-
this._mounted = false;
|
|
889
|
-
this.props = props;
|
|
890
|
-
}
|
|
891
|
-
componentDidMount() {
|
|
892
|
-
}
|
|
893
|
-
async setState(newState) {
|
|
894
|
-
const prevState = { ...this.state };
|
|
895
|
-
this.state = { ...prevState, ...newState };
|
|
896
|
-
console.log(`${this.constructor.name} state updated:`, {
|
|
897
|
-
prev: prevState,
|
|
898
|
-
next: this.state
|
|
899
|
-
});
|
|
900
|
-
await Promise.resolve();
|
|
901
|
-
if (this._mounted) {
|
|
902
|
-
await this.update();
|
|
903
|
-
} else {
|
|
904
|
-
await this.update();
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
_replayEvents(oldElement, newElement) {
|
|
908
|
-
const oldEvents = oldElement.__events || {};
|
|
909
|
-
Object.entries(oldEvents).forEach(([event, handler]) => {
|
|
910
|
-
newElement.addEventListener(event, handler);
|
|
911
|
-
});
|
|
912
|
-
newElement.__events = oldEvents;
|
|
913
|
-
}
|
|
914
|
-
_deepCloneWithEvents(node) {
|
|
915
|
-
const clone = node.cloneNode(false);
|
|
916
|
-
const events = node.__events || {};
|
|
917
|
-
clone.__events = events;
|
|
918
|
-
Object.entries(events).forEach(([event, handler]) => {
|
|
919
|
-
clone.addEventListener(event, handler);
|
|
920
|
-
});
|
|
921
|
-
Array.from(node.childNodes).forEach((child) => {
|
|
922
|
-
if (child instanceof HTMLElement) {
|
|
923
|
-
clone.appendChild(this._deepCloneWithEvents(child));
|
|
924
|
-
} else {
|
|
925
|
-
clone.appendChild(child.cloneNode(true));
|
|
926
|
-
}
|
|
927
|
-
});
|
|
928
|
-
return clone;
|
|
929
|
-
}
|
|
930
|
-
async update() {
|
|
931
|
-
const vdom = this.render();
|
|
932
|
-
if (!vdom)
|
|
933
|
-
return document.createTextNode("");
|
|
934
|
-
const rendered = await createElement(vdom);
|
|
935
|
-
if (rendered instanceof HTMLElement) {
|
|
936
|
-
return this._updateElement(rendered);
|
|
937
|
-
}
|
|
938
|
-
const wrapper = document.createElement("div");
|
|
939
|
-
wrapper.appendChild(rendered);
|
|
940
|
-
return this._updateElement(wrapper);
|
|
941
|
-
}
|
|
942
|
-
async _updateElement(rendered) {
|
|
943
|
-
const newElement = this._deepCloneWithEvents(rendered);
|
|
944
|
-
newElement.__instance = this;
|
|
945
|
-
if (!this.element) {
|
|
946
|
-
this.element = newElement;
|
|
947
|
-
if (!this._mounted) {
|
|
948
|
-
this._mounted = true;
|
|
949
|
-
queueMicrotask(() => this.componentDidMount());
|
|
950
|
-
}
|
|
951
|
-
} else if (this.element.parentNode) {
|
|
952
|
-
this.element.parentNode.replaceChild(newElement, this.element);
|
|
953
|
-
this.element = newElement;
|
|
954
|
-
}
|
|
955
|
-
return this.element;
|
|
956
|
-
}
|
|
957
|
-
render() {
|
|
958
|
-
throw new Error("Component must implement render() method");
|
|
959
|
-
}
|
|
960
|
-
};
|
|
961
|
-
RouterContext = createContext({
|
|
962
|
-
location: {
|
|
963
|
-
pathname: "/",
|
|
964
|
-
search: "",
|
|
965
|
-
hash: ""
|
|
966
|
-
},
|
|
967
|
-
params: {},
|
|
968
|
-
navigate: () => {
|
|
969
|
-
},
|
|
970
|
-
match: () => false
|
|
971
|
-
});
|
|
972
|
-
globalEventBus = createEventBus();
|
|
973
|
-
StoreContext = createContext({
|
|
974
|
-
store: {
|
|
975
|
-
getState: () => ({}),
|
|
976
|
-
dispatch: () => {
|
|
977
|
-
},
|
|
978
|
-
subscribe: () => () => {
|
|
979
|
-
}
|
|
980
|
-
},
|
|
981
|
-
state: {}
|
|
982
|
-
});
|
|
983
|
-
logger = (store) => (next) => (action) => {
|
|
984
|
-
console.group(action.type);
|
|
985
|
-
console.log("Previous state:", store.getState());
|
|
986
|
-
console.log("Action:", action);
|
|
987
|
-
const result = next(action);
|
|
988
|
-
console.log("Next state:", store.getState());
|
|
989
|
-
console.groupEnd();
|
|
990
|
-
return result;
|
|
991
|
-
};
|
|
992
|
-
thunk = (store) => (next) => (action) => {
|
|
993
|
-
if (typeof action === "function") {
|
|
994
|
-
return action(store.dispatch, store.getState);
|
|
995
|
-
}
|
|
996
|
-
return next(action);
|
|
997
|
-
};
|
|
998
|
-
(function(LifecycleEvents2) {
|
|
999
|
-
LifecycleEvents2["APP_INIT"] = "app:init";
|
|
1000
|
-
LifecycleEvents2["APP_MOUNTED"] = "app:mounted";
|
|
1001
|
-
LifecycleEvents2["APP_UPDATED"] = "app:updated";
|
|
1002
|
-
LifecycleEvents2["APP_ERROR"] = "app:error";
|
|
1003
|
-
LifecycleEvents2["APP_DESTROYED"] = "app:destroyed";
|
|
1004
|
-
LifecycleEvents2["COMPONENT_CREATED"] = "component:created";
|
|
1005
|
-
LifecycleEvents2["COMPONENT_MOUNTED"] = "component:mounted";
|
|
1006
|
-
LifecycleEvents2["COMPONENT_UPDATED"] = "component:updated";
|
|
1007
|
-
LifecycleEvents2["COMPONENT_ERROR"] = "component:error";
|
|
1008
|
-
LifecycleEvents2["COMPONENT_UNMOUNTED"] = "component:unmounted";
|
|
1009
|
-
LifecycleEvents2["ROUTER_BEFORE_CHANGE"] = "router:before-change";
|
|
1010
|
-
LifecycleEvents2["ROUTER_AFTER_CHANGE"] = "router:after-change";
|
|
1011
|
-
LifecycleEvents2["ROUTER_ERROR"] = "router:error";
|
|
1012
|
-
LifecycleEvents2["STORE_INITIALIZED"] = "store:initialized";
|
|
1013
|
-
LifecycleEvents2["STORE_BEFORE_ACTION"] = "store:before-action";
|
|
1014
|
-
LifecycleEvents2["STORE_AFTER_ACTION"] = "store:after-action";
|
|
1015
|
-
LifecycleEvents2["STORE_ERROR"] = "store:error";
|
|
1016
|
-
})(LifecycleEvents || (LifecycleEvents = {}));
|
|
1017
|
-
}
|
|
1018
|
-
});
|
|
1019
|
-
|
|
1020
18
|
// src/server/templates.ts
|
|
1021
19
|
var templates_exports = {};
|
|
1022
20
|
__export(templates_exports, {
|
|
@@ -1040,38 +38,38 @@ function generateDocument(content, options = {}) {
|
|
|
1040
38
|
initialData = {},
|
|
1041
39
|
componentName = ""
|
|
1042
40
|
} = options;
|
|
1043
|
-
const htmlAttributes = Object.entries(htmlAttrs).map(([key, value]) => `${key}="${
|
|
1044
|
-
const bodyAttributes = Object.entries(bodyAttrs).map(([key, value]) => `${key}="${
|
|
41
|
+
const htmlAttributes = Object.entries(htmlAttrs).map(([key, value]) => `${key}="${escapeHtml(value)}"`).join(" ");
|
|
42
|
+
const bodyAttributes = Object.entries(bodyAttrs).map(([key, value]) => `${key}="${escapeHtml(value)}"`).join(" ");
|
|
1045
43
|
const metaTags = [
|
|
1046
44
|
`<meta charset="${charset}">`,
|
|
1047
45
|
`<meta name="viewport" content="${viewport}">`,
|
|
1048
|
-
description ? `<meta name="description" content="${
|
|
46
|
+
description ? `<meta name="description" content="${escapeHtml(description)}">` : ""
|
|
1049
47
|
];
|
|
1050
48
|
Object.entries(meta).forEach(([name, content2]) => {
|
|
1051
|
-
metaTags.push(`<meta name="${
|
|
49
|
+
metaTags.push(`<meta name="${escapeHtml(name)}" content="${escapeHtml(content2)}">`);
|
|
1052
50
|
});
|
|
1053
51
|
const scriptTags = scripts.map((src) => {
|
|
1054
52
|
if (src.startsWith("<script")) {
|
|
1055
53
|
return src;
|
|
1056
54
|
}
|
|
1057
|
-
return `<script src="${
|
|
55
|
+
return `<script src="${escapeHtml(src)}" ${src.endsWith(".js") ? 'type="module"' : ""} defer></script>`;
|
|
1058
56
|
});
|
|
1059
57
|
const styleTags = styles.map((href) => {
|
|
1060
58
|
if (href.startsWith("<style")) {
|
|
1061
59
|
return href;
|
|
1062
60
|
}
|
|
1063
|
-
return `<link rel="stylesheet" href="${
|
|
61
|
+
return `<link rel="stylesheet" href="${escapeHtml(href)}">`;
|
|
1064
62
|
});
|
|
1065
|
-
const initialDataScript = Object.keys(initialData).length > 0 ? `<script id="__APP_DATA__" type="application/json">${
|
|
63
|
+
const initialDataScript = Object.keys(initialData).length > 0 ? `<script id="__APP_DATA__" type="application/json">${escapeHtml(JSON.stringify(initialData))}</script>` : "";
|
|
1066
64
|
return `<!DOCTYPE html>
|
|
1067
65
|
<html lang="${lang}" ${htmlAttributes}>
|
|
1068
66
|
<head>
|
|
1069
67
|
${metaTags.filter(Boolean).join("\n ")}
|
|
1070
|
-
<title>${
|
|
68
|
+
<title>${escapeHtml(title)}</title>
|
|
1071
69
|
${styleTags.join("\n ")}
|
|
1072
70
|
</head>
|
|
1073
71
|
<body class="${bodyClasses}" ${bodyAttributes}>
|
|
1074
|
-
<div id="app-root" data-ssr-root${componentName ? ` data-component="${
|
|
72
|
+
<div id="app-root" data-ssr-root${componentName ? ` data-component="${escapeHtml(componentName)}"` : ""}>${content}</div>
|
|
1075
73
|
${initialDataScript}
|
|
1076
74
|
${scriptTags.join("\n ")}
|
|
1077
75
|
</body>
|
|
@@ -1089,14 +87,14 @@ function generateErrorPage(statusCode, message, error) {
|
|
|
1089
87
|
const isDev = process.env.NODE_ENV !== "production";
|
|
1090
88
|
const errorDetails = isDev && error ? `
|
|
1091
89
|
<div class="error-details">
|
|
1092
|
-
<pre>${
|
|
90
|
+
<pre>${escapeHtml(error.stack || error.message)}</pre>
|
|
1093
91
|
</div>
|
|
1094
92
|
` : "";
|
|
1095
93
|
const content = `
|
|
1096
94
|
<div class="error-container">
|
|
1097
95
|
<h1>${statusCode}</h1>
|
|
1098
|
-
<h2>${
|
|
1099
|
-
<p>${
|
|
96
|
+
<h2>${escapeHtml(errorMessages[statusCode] || "Error")}</h2>
|
|
97
|
+
<p>${escapeHtml(message)}</p>
|
|
1100
98
|
${errorDetails}
|
|
1101
99
|
<a href="/" class="home-link">Back to Home</a>
|
|
1102
100
|
</div>
|
|
@@ -1170,7 +168,7 @@ function generateLoadingPage(message = "Loading...") {
|
|
|
1170
168
|
const content = `
|
|
1171
169
|
<div class="loading-container">
|
|
1172
170
|
<div class="spinner"></div>
|
|
1173
|
-
<p>${
|
|
171
|
+
<p>${escapeHtml(message)}</p>
|
|
1174
172
|
</div>
|
|
1175
173
|
`;
|
|
1176
174
|
const styles = [`<style>
|
|
@@ -1206,7 +204,7 @@ function generateLoadingPage(message = "Loading...") {
|
|
|
1206
204
|
styles
|
|
1207
205
|
});
|
|
1208
206
|
}
|
|
1209
|
-
function
|
|
207
|
+
function escapeHtml(text) {
|
|
1210
208
|
return String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1211
209
|
}
|
|
1212
210
|
var init_templates = __esm({
|
|
@@ -1770,8 +768,8 @@ async function initNodeWasm() {
|
|
|
1770
768
|
}
|
|
1771
769
|
}
|
|
1772
770
|
async function loadGoRuntime(goWasmPath) {
|
|
1773
|
-
if (typeof
|
|
1774
|
-
return
|
|
771
|
+
if (typeof global.Go === "function") {
|
|
772
|
+
return global.Go;
|
|
1775
773
|
}
|
|
1776
774
|
const possiblePaths = [
|
|
1777
775
|
goWasmPath,
|
|
@@ -1800,13 +798,13 @@ async function loadGoRuntime(goWasmPath) {
|
|
|
1800
798
|
continue;
|
|
1801
799
|
}
|
|
1802
800
|
const wasmExecUrl = pathToFileURL2(resolvedPath).href;
|
|
1803
|
-
if (
|
|
1804
|
-
delete
|
|
801
|
+
if (global.Go) {
|
|
802
|
+
delete global.Go;
|
|
1805
803
|
}
|
|
1806
804
|
await import(wasmExecUrl);
|
|
1807
|
-
if (typeof
|
|
805
|
+
if (typeof global.Go === "function") {
|
|
1808
806
|
console.log(`[WASM] Loaded Go runtime from: ${resolvedPath}`);
|
|
1809
|
-
return
|
|
807
|
+
return global.Go;
|
|
1810
808
|
} else {
|
|
1811
809
|
console.warn(`[WASM] File found but Go class not exported: ${resolvedPath}`);
|
|
1812
810
|
}
|
|
@@ -1858,7 +856,7 @@ async function loadGoWasmFromFile(wasmFilePath, options = {}) {
|
|
|
1858
856
|
console.log("[WASM] Scanning global object for Go functions...");
|
|
1859
857
|
}
|
|
1860
858
|
const functions = {};
|
|
1861
|
-
const globalObj =
|
|
859
|
+
const globalObj = global;
|
|
1862
860
|
const allKeys = Object.getOwnPropertyNames(globalObj);
|
|
1863
861
|
const goKeys = allKeys.filter((key) => key.startsWith("go"));
|
|
1864
862
|
if (options.debug) {
|
|
@@ -1944,6 +942,7 @@ __export(server_exports, {
|
|
|
1944
942
|
});
|
|
1945
943
|
import path4 from "path";
|
|
1946
944
|
import fs4 from "fs";
|
|
945
|
+
import { renderToString } from "frontend-hamroun";
|
|
1947
946
|
function getComponentName(filePath, pagesDir) {
|
|
1948
947
|
try {
|
|
1949
948
|
const relativePath = path4.relative(pagesDir, filePath);
|
|
@@ -1993,7 +992,6 @@ var Server, renderComponent, server_default;
|
|
|
1993
992
|
var init_server = __esm({
|
|
1994
993
|
"src/server/index.ts"() {
|
|
1995
994
|
"use strict";
|
|
1996
|
-
init_dist();
|
|
1997
995
|
init_database();
|
|
1998
996
|
init_auth();
|
|
1999
997
|
init_api_router();
|
|
@@ -2320,9 +1318,11 @@ var init_server = __esm({
|
|
|
2320
1318
|
process.on("SIGINT", gracefulShutdown);
|
|
2321
1319
|
}
|
|
2322
1320
|
};
|
|
2323
|
-
renderComponent = (
|
|
1321
|
+
renderComponent = async (Component, props = {}) => {
|
|
2324
1322
|
try {
|
|
2325
|
-
const
|
|
1323
|
+
const { jsx, renderToString: renderToString3 } = await import("frontend-hamroun");
|
|
1324
|
+
const element = jsx(Component, props);
|
|
1325
|
+
const html = renderToString3(element);
|
|
2326
1326
|
return {
|
|
2327
1327
|
html: typeof html === "string" ? html : String(html),
|
|
2328
1328
|
success: true
|
|
@@ -2330,7 +1330,7 @@ var init_server = __esm({
|
|
|
2330
1330
|
} catch (error) {
|
|
2331
1331
|
console.error("Error rendering component:", error);
|
|
2332
1332
|
return {
|
|
2333
|
-
html: `<div class="error">Error rendering component</div>`,
|
|
1333
|
+
html: `<div class="error">Error rendering component: ${error instanceof Error ? error.message : "Unknown error"}</div>`,
|
|
2334
1334
|
success: false,
|
|
2335
1335
|
error
|
|
2336
1336
|
};
|
|
@@ -2395,7 +1395,7 @@ var init_server_renderer = __esm({
|
|
|
2395
1395
|
});
|
|
2396
1396
|
|
|
2397
1397
|
// src/index.ts
|
|
2398
|
-
|
|
1398
|
+
export * from "frontend-hamroun";
|
|
2399
1399
|
|
|
2400
1400
|
// src/wasm.ts
|
|
2401
1401
|
async function loadGoWasm(wasmUrl, options = {}) {
|
|
@@ -2584,40 +1584,14 @@ export {
|
|
|
2584
1584
|
ApiRouter2 as ApiRouter,
|
|
2585
1585
|
AuthService2 as AuthService,
|
|
2586
1586
|
BaraqexServer,
|
|
2587
|
-
Component,
|
|
2588
1587
|
Database2 as Database,
|
|
2589
|
-
Fragment,
|
|
2590
|
-
LifecycleEvents,
|
|
2591
|
-
Link,
|
|
2592
|
-
Redirect,
|
|
2593
|
-
Route,
|
|
2594
|
-
RouterProvider,
|
|
2595
|
-
StoreProvider,
|
|
2596
|
-
Switch,
|
|
2597
1588
|
baraqexRenderToString,
|
|
2598
|
-
batchUpdates,
|
|
2599
1589
|
callWasmFunction,
|
|
2600
|
-
createContext,
|
|
2601
1590
|
createDevServer2 as createDevServer,
|
|
2602
|
-
createElement,
|
|
2603
|
-
createEventBus,
|
|
2604
1591
|
createProductionServer2 as createProductionServer,
|
|
2605
1592
|
createServer2 as createServer,
|
|
2606
|
-
createStore,
|
|
2607
|
-
diff,
|
|
2608
|
-
emitAppDestroyed,
|
|
2609
|
-
emitAppError,
|
|
2610
|
-
emitAppInit,
|
|
2611
|
-
emitAppMounted,
|
|
2612
|
-
emitAppUpdated,
|
|
2613
|
-
emitComponentCreated,
|
|
2614
|
-
emitComponentError,
|
|
2615
|
-
emitComponentMounted,
|
|
2616
|
-
emitComponentUnmounted,
|
|
2617
|
-
emitComponentUpdated,
|
|
2618
1593
|
ensureDirectory2 as ensureDirectory,
|
|
2619
1594
|
errorHandler2 as errorHandler,
|
|
2620
|
-
globalEventBus as eventBus,
|
|
2621
1595
|
generateDocument,
|
|
2622
1596
|
generateErrorPage,
|
|
2623
1597
|
generateLoadingPage,
|
|
@@ -2626,53 +1600,20 @@ export {
|
|
|
2626
1600
|
getPagination2 as getPagination,
|
|
2627
1601
|
getWasmFunctions,
|
|
2628
1602
|
hashString2 as hashString,
|
|
2629
|
-
hydrate,
|
|
2630
1603
|
initNodeWasm3 as initNodeWasm,
|
|
2631
1604
|
isDirectoryEmpty2 as isDirectoryEmpty,
|
|
2632
1605
|
isWasmReady,
|
|
2633
|
-
jsx,
|
|
2634
|
-
jsx as jsxDEV,
|
|
2635
|
-
jsx as jsxs,
|
|
2636
1606
|
loadGoWasm,
|
|
2637
1607
|
loadGoWasmFromFile2 as loadGoWasmFromFile,
|
|
2638
|
-
logger,
|
|
2639
1608
|
notFoundHandler2 as notFoundHandler,
|
|
2640
|
-
onAppDestroyed,
|
|
2641
|
-
onAppError,
|
|
2642
|
-
onAppInit,
|
|
2643
|
-
onAppMounted,
|
|
2644
|
-
onAppUpdated,
|
|
2645
|
-
onComponentCreated,
|
|
2646
|
-
onComponentError,
|
|
2647
|
-
onComponentMounted,
|
|
2648
|
-
onComponentUnmounted,
|
|
2649
|
-
onComponentUpdated,
|
|
2650
1609
|
rateLimit2 as rateLimit,
|
|
2651
1610
|
readJsonFile2 as readJsonFile,
|
|
2652
|
-
render,
|
|
2653
1611
|
renderComponent2 as renderComponent,
|
|
2654
|
-
renderToString,
|
|
2655
1612
|
requestLogger2 as requestLogger,
|
|
2656
1613
|
safeJsonParse2 as safeJsonParse,
|
|
2657
1614
|
sendError2 as sendError,
|
|
2658
1615
|
sendSuccess2 as sendSuccess,
|
|
2659
|
-
shouldComponentUpdate,
|
|
2660
|
-
thunk,
|
|
2661
|
-
useContext,
|
|
2662
|
-
useDispatch,
|
|
2663
|
-
useEffect,
|
|
2664
|
-
useErrorBoundary,
|
|
2665
|
-
useEvent,
|
|
2666
|
-
useForm,
|
|
2667
1616
|
useGoWasm,
|
|
2668
|
-
useLocation,
|
|
2669
|
-
useMemo,
|
|
2670
|
-
useNavigate,
|
|
2671
|
-
useParams,
|
|
2672
|
-
useRef,
|
|
2673
|
-
useSelector,
|
|
2674
|
-
useState,
|
|
2675
|
-
useStore,
|
|
2676
1617
|
validateFields2 as validateFields,
|
|
2677
1618
|
validateFileUpload2 as validateFileUpload,
|
|
2678
1619
|
writeJsonFile2 as writeJsonFile
|