baraqex 1.0.37 → 1.0.39
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/api/hello.d.ts +3 -0
- package/dist/api/hello.d.ts.map +1 -0
- package/dist/api/users/[id].d.ts +5 -0
- package/dist/api/users/[id].d.ts.map +1 -0
- package/dist/browser.d.ts +14 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +771 -140
- package/dist/browser.js.map +4 -4
- package/dist/frontend/components/WasmLoader.d.ts +2 -0
- package/dist/frontend/components/WasmLoader.d.ts.map +1 -0
- package/dist/frontend/hooks/useWasm.d.ts +2 -0
- package/dist/frontend/hooks/useWasm.d.ts.map +1 -0
- package/dist/frontend/index.d.ts +2 -0
- package/dist/frontend/index.d.ts.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +872 -220
- package/dist/index.js.map +4 -4
- package/dist/renderComponent.d.ts +9 -0
- package/dist/renderComponent.d.ts.map +1 -0
- package/dist/server/api-router.d.ts +16 -0
- package/dist/server/api-router.d.ts.map +1 -0
- package/dist/server/auth.d.ts +25 -0
- package/dist/server/auth.d.ts.map +1 -0
- package/dist/server/database.d.ts +22 -0
- package/dist/server/database.d.ts.map +1 -0
- package/dist/server/index.d.ts +115 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +212 -85
- package/dist/server/index.js.map +4 -4
- package/dist/server/middleware.d.ts +11 -0
- package/dist/server/middleware.d.ts.map +1 -0
- package/dist/server/templates.d.ts +31 -0
- package/dist/server/templates.d.ts.map +1 -0
- package/dist/server/types.d.ts +69 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/utils.d.ts +70 -0
- package/dist/server/utils.d.ts.map +1 -0
- package/dist/server/wasm.d.ts +29 -0
- package/dist/server/wasm.d.ts.map +1 -0
- package/dist/server-renderer.d.ts +5 -0
- package/dist/server-renderer.d.ts.map +1 -0
- package/dist/wasm.d.ts +51 -0
- package/dist/wasm.d.ts.map +1 -0
- package/package.json +3 -4
- package/templates/ssr-template/package-lock.json +4 -4
- package/templates/ssr-template/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,7 +15,84 @@ 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.
|
|
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
|
+
}
|
|
19
96
|
function batchUpdates(fn) {
|
|
20
97
|
if (isBatching) {
|
|
21
98
|
queue.push(fn);
|
|
@@ -26,52 +103,54 @@ function batchUpdates(fn) {
|
|
|
26
103
|
fn();
|
|
27
104
|
while (queue.length > 0) {
|
|
28
105
|
const nextFn = queue.shift();
|
|
29
|
-
nextFn
|
|
106
|
+
nextFn?.();
|
|
30
107
|
}
|
|
31
108
|
} finally {
|
|
32
109
|
isBatching = false;
|
|
33
110
|
}
|
|
34
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
|
+
}
|
|
35
132
|
function setRenderCallback(callback, element, container) {
|
|
36
133
|
globalRenderCallback = callback;
|
|
37
134
|
globalContainer = container;
|
|
38
135
|
currentElement = element;
|
|
39
136
|
}
|
|
40
|
-
function prepareRender() {
|
|
137
|
+
function prepareRender(component = null) {
|
|
41
138
|
currentRender++;
|
|
42
139
|
stateIndices.set(currentRender, 0);
|
|
43
140
|
return currentRender;
|
|
44
141
|
}
|
|
45
142
|
function finishRender() {
|
|
46
|
-
if (isServer) {
|
|
47
|
-
serverStates.delete(currentRender);
|
|
48
|
-
}
|
|
49
143
|
currentRender = 0;
|
|
50
144
|
}
|
|
51
145
|
function useState(initial) {
|
|
52
146
|
if (!currentRender) {
|
|
53
147
|
throw new Error("useState must be called within a render");
|
|
54
148
|
}
|
|
55
|
-
if (isServer) {
|
|
56
|
-
if (!serverStates.has(currentRender)) {
|
|
57
|
-
serverStates.set(currentRender, /* @__PURE__ */ new Map());
|
|
58
|
-
}
|
|
59
|
-
const componentState = serverStates.get(currentRender);
|
|
60
|
-
const index2 = stateIndices.get(currentRender) || 0;
|
|
61
|
-
if (!componentState.has(index2)) {
|
|
62
|
-
componentState.set(index2, initial);
|
|
63
|
-
}
|
|
64
|
-
const state2 = componentState.get(index2);
|
|
65
|
-
const setState2 = (newValue) => {
|
|
66
|
-
};
|
|
67
|
-
stateIndices.set(currentRender, index2 + 1);
|
|
68
|
-
return [state2, setState2];
|
|
69
|
-
}
|
|
70
149
|
if (!states.has(currentRender)) {
|
|
71
150
|
states.set(currentRender, []);
|
|
72
151
|
}
|
|
73
152
|
const componentStates = states.get(currentRender);
|
|
74
|
-
const index = stateIndices.get(currentRender);
|
|
153
|
+
const index = stateIndices.get(currentRender) || 0;
|
|
75
154
|
if (index >= componentStates.length) {
|
|
76
155
|
componentStates.push(initial);
|
|
77
156
|
}
|
|
@@ -93,19 +172,19 @@ function useState(initial) {
|
|
|
93
172
|
function useEffect(callback, deps) {
|
|
94
173
|
if (!currentRender)
|
|
95
174
|
throw new Error("useEffect must be called within a render");
|
|
96
|
-
const effectIndex = stateIndices.get(currentRender);
|
|
175
|
+
const effectIndex = stateIndices.get(currentRender) || 0;
|
|
97
176
|
if (!effects.has(currentRender)) {
|
|
98
177
|
effects.set(currentRender, []);
|
|
99
178
|
}
|
|
100
179
|
const componentEffects = effects.get(currentRender);
|
|
101
180
|
const prevEffect = componentEffects[effectIndex];
|
|
102
181
|
if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
|
|
103
|
-
if (prevEffect
|
|
182
|
+
if (prevEffect?.cleanup) {
|
|
104
183
|
prevEffect.cleanup();
|
|
105
184
|
}
|
|
106
185
|
queueMicrotask(() => {
|
|
107
186
|
const cleanup = callback() || void 0;
|
|
108
|
-
componentEffects[effectIndex] = { cleanup, deps };
|
|
187
|
+
componentEffects[effectIndex] = { cleanup, deps: deps || [] };
|
|
109
188
|
});
|
|
110
189
|
}
|
|
111
190
|
stateIndices.set(currentRender, effectIndex + 1);
|
|
@@ -113,7 +192,7 @@ function useEffect(callback, deps) {
|
|
|
113
192
|
function useMemo(factory, deps) {
|
|
114
193
|
if (!currentRender)
|
|
115
194
|
throw new Error("useMemo must be called within a render");
|
|
116
|
-
const memoIndex = stateIndices.get(currentRender);
|
|
195
|
+
const memoIndex = stateIndices.get(currentRender) || 0;
|
|
117
196
|
if (!memos.has(currentRender)) {
|
|
118
197
|
memos.set(currentRender, []);
|
|
119
198
|
}
|
|
@@ -121,7 +200,7 @@ function useMemo(factory, deps) {
|
|
|
121
200
|
const prevMemo = componentMemos[memoIndex];
|
|
122
201
|
if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
|
|
123
202
|
const value = factory();
|
|
124
|
-
componentMemos[memoIndex] = { value, deps };
|
|
203
|
+
componentMemos[memoIndex] = { value, deps: deps || [] };
|
|
125
204
|
stateIndices.set(currentRender, memoIndex + 1);
|
|
126
205
|
return value;
|
|
127
206
|
}
|
|
@@ -131,7 +210,7 @@ function useMemo(factory, deps) {
|
|
|
131
210
|
function useRef(initial) {
|
|
132
211
|
if (!currentRender)
|
|
133
212
|
throw new Error("useRef must be called within a render");
|
|
134
|
-
const refIndex = stateIndices.get(currentRender);
|
|
213
|
+
const refIndex = stateIndices.get(currentRender) || 0;
|
|
135
214
|
if (!refs.has(currentRender)) {
|
|
136
215
|
refs.set(currentRender, []);
|
|
137
216
|
}
|
|
@@ -167,210 +246,614 @@ function useErrorBoundary() {
|
|
|
167
246
|
const [error, setError] = useState(null);
|
|
168
247
|
return [error, () => setError(null)];
|
|
169
248
|
}
|
|
170
|
-
function
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
249
|
+
async function render(element, container) {
|
|
250
|
+
try {
|
|
251
|
+
setRenderCallback(render, element, container);
|
|
252
|
+
const renderId = prepareRender(element);
|
|
253
|
+
const domNode = await createElement(element);
|
|
254
|
+
if (container instanceof Element) {
|
|
255
|
+
container.innerHTML = "";
|
|
256
|
+
} else {
|
|
257
|
+
while (container.firstChild) {
|
|
258
|
+
container.removeChild(container.firstChild);
|
|
259
|
+
}
|
|
181
260
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
261
|
+
container.appendChild(domNode);
|
|
262
|
+
finishRender();
|
|
263
|
+
console.log("Render completed successfully");
|
|
264
|
+
} catch (error) {
|
|
265
|
+
console.error("Error during render:", error);
|
|
266
|
+
finishRender();
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
187
269
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
270
|
+
async function hydrate(element, container) {
|
|
271
|
+
try {
|
|
272
|
+
console.log("Starting hydration...");
|
|
273
|
+
await render(element, container);
|
|
274
|
+
console.log("Hydration completed successfully");
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.error("Error during hydration:", error);
|
|
277
|
+
throw error;
|
|
193
278
|
}
|
|
194
|
-
return { type, props: processedProps };
|
|
195
279
|
}
|
|
196
|
-
async function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return
|
|
280
|
+
async function renderToString(element) {
|
|
281
|
+
prepareRender(true);
|
|
282
|
+
try {
|
|
283
|
+
const html = await renderNodeToString(element);
|
|
284
|
+
return html;
|
|
285
|
+
} finally {
|
|
286
|
+
finishRender();
|
|
201
287
|
}
|
|
202
|
-
|
|
203
|
-
|
|
288
|
+
}
|
|
289
|
+
async function renderNodeToString(node) {
|
|
290
|
+
if (node == null || typeof node === "boolean") {
|
|
291
|
+
return "";
|
|
204
292
|
}
|
|
205
|
-
if (typeof
|
|
206
|
-
return
|
|
293
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
294
|
+
return escapeHtml(String(node));
|
|
207
295
|
}
|
|
208
|
-
if (Array.isArray(
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
const node = await createElement(child);
|
|
212
|
-
fragment.appendChild(node);
|
|
213
|
-
}
|
|
214
|
-
return fragment;
|
|
296
|
+
if (Array.isArray(node)) {
|
|
297
|
+
const results = await Promise.all(node.map((child) => renderNodeToString(child)));
|
|
298
|
+
return results.join("");
|
|
215
299
|
}
|
|
216
|
-
if ("
|
|
217
|
-
const { type, props } =
|
|
300
|
+
if (node && typeof node === "object" && "type" in node) {
|
|
301
|
+
const { type, props = {} } = node;
|
|
218
302
|
if (typeof type === "function") {
|
|
219
303
|
try {
|
|
220
|
-
const result = await type(props
|
|
221
|
-
|
|
222
|
-
if (node instanceof Element) {
|
|
223
|
-
node.setAttribute("data-component-id", type.name || type.toString());
|
|
224
|
-
}
|
|
225
|
-
return node;
|
|
304
|
+
const result = await type(props);
|
|
305
|
+
return await renderNodeToString(result);
|
|
226
306
|
} catch (error) {
|
|
227
307
|
console.error("Error rendering component:", error);
|
|
228
|
-
return
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
const element = document.createElement(type);
|
|
232
|
-
for (const [key, value] of Object.entries(props || {})) {
|
|
233
|
-
if (key === "children")
|
|
234
|
-
continue;
|
|
235
|
-
if (key.startsWith("on") && typeof value === "function") {
|
|
236
|
-
const eventName = key.toLowerCase().slice(2);
|
|
237
|
-
const existingHandler = (_a = element.__events) == null ? void 0 : _a[eventName];
|
|
238
|
-
if (existingHandler) {
|
|
239
|
-
element.removeEventListener(eventName, existingHandler);
|
|
240
|
-
}
|
|
241
|
-
element.addEventListener(eventName, value);
|
|
242
|
-
if (!element.__events) {
|
|
243
|
-
element.__events = {};
|
|
244
|
-
}
|
|
245
|
-
element.__events[eventName] = value;
|
|
246
|
-
} else if (key === "style" && typeof value === "object") {
|
|
247
|
-
Object.assign(element.style, value);
|
|
248
|
-
} else if (key === "className") {
|
|
249
|
-
element.setAttribute("class", String(value));
|
|
250
|
-
} else if (key !== "key" && key !== "ref") {
|
|
251
|
-
element.setAttribute(key, String(value));
|
|
308
|
+
return `<!-- Error rendering component: ${error.message} -->`;
|
|
252
309
|
}
|
|
253
310
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const childArray = Array.isArray(children) ? children.flat() : [children];
|
|
257
|
-
for (const child of childArray) {
|
|
258
|
-
const childNode = await createElement(child);
|
|
259
|
-
element.appendChild(childNode);
|
|
260
|
-
}
|
|
311
|
+
if (typeof type === "string") {
|
|
312
|
+
return await renderDOMElement(type, props);
|
|
261
313
|
}
|
|
262
|
-
return element;
|
|
263
314
|
}
|
|
264
|
-
|
|
315
|
+
if (typeof node === "object") {
|
|
316
|
+
return escapeHtml(JSON.stringify(node));
|
|
317
|
+
}
|
|
318
|
+
return escapeHtml(String(node));
|
|
265
319
|
}
|
|
266
|
-
async function
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
320
|
+
async function renderDOMElement(tagName, props) {
|
|
321
|
+
const { children, ...attrs } = props;
|
|
322
|
+
const voidElements = /* @__PURE__ */ new Set([
|
|
323
|
+
"area",
|
|
324
|
+
"base",
|
|
325
|
+
"br",
|
|
326
|
+
"col",
|
|
327
|
+
"embed",
|
|
328
|
+
"hr",
|
|
329
|
+
"img",
|
|
330
|
+
"input",
|
|
331
|
+
"link",
|
|
332
|
+
"meta",
|
|
333
|
+
"param",
|
|
334
|
+
"source",
|
|
335
|
+
"track",
|
|
336
|
+
"wbr"
|
|
337
|
+
]);
|
|
338
|
+
const attributeString = Object.entries(attrs).filter(([key, value]) => {
|
|
339
|
+
if (key.startsWith("on") || key === "key" || key === "ref")
|
|
340
|
+
return false;
|
|
341
|
+
if (value == null || value === false)
|
|
342
|
+
return false;
|
|
343
|
+
return true;
|
|
344
|
+
}).map(([key, value]) => {
|
|
345
|
+
if (key === "className")
|
|
346
|
+
key = "class";
|
|
347
|
+
if (value === true)
|
|
348
|
+
return key;
|
|
349
|
+
if (key === "style" && typeof value === "object" && value !== null) {
|
|
350
|
+
const styleString = Object.entries(value).map(([prop, val]) => `${kebabCase(prop)}:${val}`).join(";");
|
|
351
|
+
return `style="${escapeHtml(styleString)}"`;
|
|
352
|
+
}
|
|
353
|
+
return `${key}="${escapeHtml(String(value))}"`;
|
|
354
|
+
}).join(" ");
|
|
355
|
+
const openTag = `<${tagName}${attributeString ? " " + attributeString : ""}>`;
|
|
356
|
+
if (voidElements.has(tagName)) {
|
|
357
|
+
return openTag.slice(0, -1) + "/>";
|
|
358
|
+
}
|
|
359
|
+
const closeTag = `</${tagName}>`;
|
|
360
|
+
if (children != null) {
|
|
361
|
+
const childrenString = await renderNodeToString(children);
|
|
362
|
+
return openTag + childrenString + closeTag;
|
|
272
363
|
}
|
|
364
|
+
return openTag + closeTag;
|
|
273
365
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
366
|
+
function escapeHtml(text) {
|
|
367
|
+
const htmlEscapes = {
|
|
368
|
+
"&": "&",
|
|
369
|
+
"<": "<",
|
|
370
|
+
">": ">",
|
|
371
|
+
'"': """,
|
|
372
|
+
"'": "'",
|
|
373
|
+
"/": "/"
|
|
374
|
+
};
|
|
375
|
+
return text.replace(/[&<>"'/]/g, (match) => htmlEscapes[match]);
|
|
376
|
+
}
|
|
377
|
+
function kebabCase(str) {
|
|
378
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
379
|
+
}
|
|
380
|
+
function arePropsEqual(oldProps, newProps) {
|
|
381
|
+
const oldKeys = Object.keys(oldProps).filter((k) => k !== "children");
|
|
382
|
+
const newKeys = Object.keys(newProps).filter((k) => k !== "children");
|
|
383
|
+
if (oldKeys.length !== newKeys.length)
|
|
384
|
+
return false;
|
|
385
|
+
return oldKeys.every((key) => oldProps[key] === newProps[key]);
|
|
386
|
+
}
|
|
387
|
+
function diff(oldNode, newNode) {
|
|
388
|
+
if (oldNode == null || newNode == null)
|
|
389
|
+
return oldNode !== newNode;
|
|
390
|
+
if (typeof oldNode !== typeof newNode)
|
|
391
|
+
return true;
|
|
392
|
+
if (typeof newNode === "string" || typeof newNode === "number")
|
|
393
|
+
return oldNode !== newNode;
|
|
394
|
+
if (newNode.type !== oldNode.type)
|
|
395
|
+
return true;
|
|
396
|
+
return !arePropsEqual(oldNode.props, newNode.props);
|
|
397
|
+
}
|
|
398
|
+
function shouldComponentUpdate(oldProps, newProps) {
|
|
399
|
+
return !arePropsEqual(oldProps, newProps);
|
|
400
|
+
}
|
|
401
|
+
function parsePath(path5) {
|
|
402
|
+
const pattern = path5.replace(/\/+$/, "").replace(/^\/+/, "/").replace(/\/:([^/]+)/g, "/([^/]+)");
|
|
403
|
+
const paramNames = [];
|
|
404
|
+
path5.replace(/\/:([^/]+)/g, (_, paramName) => {
|
|
405
|
+
paramNames.push(paramName);
|
|
406
|
+
return "";
|
|
407
|
+
});
|
|
408
|
+
return { pattern, paramNames };
|
|
409
|
+
}
|
|
410
|
+
function matchPath(pathname, route) {
|
|
411
|
+
const { path: path5, exact = false } = route;
|
|
412
|
+
const { pattern, paramNames } = parsePath(path5);
|
|
413
|
+
const regex = new RegExp(`^${pattern}${exact ? "$" : ""}`);
|
|
414
|
+
const match = pathname.match(regex);
|
|
415
|
+
if (!match)
|
|
416
|
+
return null;
|
|
417
|
+
const params = {};
|
|
418
|
+
paramNames.forEach((name, index) => {
|
|
419
|
+
params[name] = match[index + 1];
|
|
420
|
+
});
|
|
421
|
+
return params;
|
|
422
|
+
}
|
|
423
|
+
function RouterProvider({ routes, children }) {
|
|
424
|
+
const getInitialLocation = () => {
|
|
425
|
+
if (typeof window === "undefined") {
|
|
426
|
+
return { pathname: "/", search: "", hash: "" };
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
pathname: window.location.pathname,
|
|
430
|
+
search: window.location.search,
|
|
431
|
+
hash: window.location.hash
|
|
432
|
+
};
|
|
433
|
+
};
|
|
434
|
+
const [location, setLocation] = useState(getInitialLocation());
|
|
435
|
+
const [params, setParams] = useState({});
|
|
436
|
+
useEffect(() => {
|
|
437
|
+
for (const route of routes) {
|
|
438
|
+
const matchedParams = matchPath(location.pathname, route);
|
|
439
|
+
if (matchedParams) {
|
|
440
|
+
setParams(matchedParams);
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}, [location, routes]);
|
|
445
|
+
useEffect(() => {
|
|
446
|
+
if (typeof window === "undefined")
|
|
447
|
+
return;
|
|
448
|
+
const handlePopState = () => {
|
|
449
|
+
setLocation({
|
|
450
|
+
pathname: window.location.pathname,
|
|
451
|
+
search: window.location.search,
|
|
452
|
+
hash: window.location.hash
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
window.addEventListener("popstate", handlePopState);
|
|
456
|
+
return () => window.removeEventListener("popstate", handlePopState);
|
|
457
|
+
}, []);
|
|
458
|
+
const navigate = (to, options = {}) => {
|
|
459
|
+
if (typeof window === "undefined")
|
|
460
|
+
return;
|
|
461
|
+
const { replace = false, state = null } = options;
|
|
462
|
+
if (replace) {
|
|
463
|
+
window.history.replaceState(state, "", to);
|
|
464
|
+
} else {
|
|
465
|
+
window.history.pushState(state, "", to);
|
|
287
466
|
}
|
|
467
|
+
setLocation({
|
|
468
|
+
pathname: window.location.pathname,
|
|
469
|
+
search: window.location.search,
|
|
470
|
+
hash: window.location.hash
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
const match = (path5) => {
|
|
474
|
+
const { pattern } = parsePath(path5);
|
|
475
|
+
const regex = new RegExp(`^${pattern}`);
|
|
476
|
+
return regex.test(location.pathname);
|
|
477
|
+
};
|
|
478
|
+
const routerValue = {
|
|
479
|
+
location: {
|
|
480
|
+
pathname: location.pathname,
|
|
481
|
+
search: location.search,
|
|
482
|
+
hash: location.hash
|
|
483
|
+
},
|
|
484
|
+
params,
|
|
485
|
+
navigate,
|
|
486
|
+
match
|
|
487
|
+
};
|
|
488
|
+
return jsx(RouterContext.Provider, { value: routerValue, children });
|
|
489
|
+
}
|
|
490
|
+
function Route({ path: path5, component: Component2, props = {} }) {
|
|
491
|
+
const context = useContext();
|
|
492
|
+
const params = context.params;
|
|
493
|
+
const locationPathname = context.location.pathname;
|
|
494
|
+
const routeToMatch = { path: path5, component: Component2 };
|
|
495
|
+
const match = matchPath(locationPathname, routeToMatch);
|
|
496
|
+
if (!match)
|
|
497
|
+
return null;
|
|
498
|
+
return jsx(Component2, { ...props, params });
|
|
499
|
+
}
|
|
500
|
+
function Switch({ children }) {
|
|
501
|
+
const context = useContext();
|
|
502
|
+
const locationPathname = context.location.pathname;
|
|
503
|
+
const child = Array.isArray(children) ? children.find((child2) => {
|
|
504
|
+
if (!child2 || typeof child2.type !== "function" || !child2.props.path)
|
|
505
|
+
return false;
|
|
506
|
+
const routeObj = {
|
|
507
|
+
path: child2.props.path,
|
|
508
|
+
component: child2.type,
|
|
509
|
+
exact: child2.props.exact || false
|
|
510
|
+
};
|
|
511
|
+
return matchPath(locationPathname, routeObj);
|
|
512
|
+
}) : children;
|
|
513
|
+
return child || null;
|
|
514
|
+
}
|
|
515
|
+
function Link({ to, replace = false, state = null, className = "", activeClassName = "", children, ...rest }) {
|
|
516
|
+
const context = useContext();
|
|
517
|
+
const navigate = context.navigate;
|
|
518
|
+
const match = context.match;
|
|
519
|
+
const handleClick = (e) => {
|
|
520
|
+
e.preventDefault();
|
|
521
|
+
navigate(to, { replace, state });
|
|
522
|
+
};
|
|
523
|
+
const isActive = match(to);
|
|
524
|
+
const classes = [
|
|
525
|
+
className,
|
|
526
|
+
isActive ? activeClassName : ""
|
|
527
|
+
].filter(Boolean).join(" ");
|
|
528
|
+
return jsx("a", {
|
|
529
|
+
href: to,
|
|
530
|
+
className: classes || void 0,
|
|
531
|
+
onClick: handleClick,
|
|
532
|
+
...rest,
|
|
533
|
+
children
|
|
288
534
|
});
|
|
289
535
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
536
|
+
function Redirect({ to, replace = true }) {
|
|
537
|
+
const context = useContext();
|
|
538
|
+
const navigate = context.navigate;
|
|
539
|
+
useEffect(() => {
|
|
540
|
+
navigate(to, { replace });
|
|
541
|
+
}, [to]);
|
|
542
|
+
return null;
|
|
295
543
|
}
|
|
296
|
-
function
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
544
|
+
function useLocation() {
|
|
545
|
+
const context = useContext();
|
|
546
|
+
return context.location;
|
|
547
|
+
}
|
|
548
|
+
function useParams() {
|
|
549
|
+
const context = useContext();
|
|
550
|
+
return context.params;
|
|
551
|
+
}
|
|
552
|
+
function useNavigate() {
|
|
553
|
+
const context = useContext();
|
|
554
|
+
return context.navigate;
|
|
555
|
+
}
|
|
556
|
+
function useForm(options) {
|
|
557
|
+
const { initialValues, validate, onSubmit } = options;
|
|
558
|
+
const [values, setValues] = useState(initialValues);
|
|
559
|
+
const [errors, setErrors] = useState({});
|
|
560
|
+
const [touched, setTouched] = useState({});
|
|
561
|
+
const [dirty, setDirty] = useState({});
|
|
562
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
563
|
+
const [submitCount, setSubmitCount] = useState(0);
|
|
564
|
+
const isValid = Object.keys(errors).length === 0;
|
|
565
|
+
const isDirty = Object.values(dirty).some(Boolean);
|
|
566
|
+
useEffect(() => {
|
|
567
|
+
if (validate) {
|
|
568
|
+
const validationErrors = validate(values);
|
|
569
|
+
setErrors(validationErrors || {});
|
|
570
|
+
}
|
|
571
|
+
}, [values, validate]);
|
|
572
|
+
const handleChange = (e) => {
|
|
573
|
+
const { name, value, type, checked } = e.target;
|
|
574
|
+
const fieldValue = type === "checkbox" ? checked : value;
|
|
575
|
+
setValues((prev) => ({
|
|
576
|
+
...prev,
|
|
577
|
+
[name]: fieldValue
|
|
578
|
+
}));
|
|
579
|
+
setDirty((prev) => ({
|
|
580
|
+
...prev,
|
|
581
|
+
[name]: true
|
|
582
|
+
}));
|
|
583
|
+
};
|
|
584
|
+
const handleBlur = (e) => {
|
|
585
|
+
const { name } = e.target;
|
|
586
|
+
setTouched((prev) => ({
|
|
587
|
+
...prev,
|
|
588
|
+
[name]: true
|
|
589
|
+
}));
|
|
590
|
+
};
|
|
591
|
+
const setFieldValue = (field, value) => {
|
|
592
|
+
setValues((prev) => ({
|
|
593
|
+
...prev,
|
|
594
|
+
[field]: value
|
|
595
|
+
}));
|
|
596
|
+
setDirty((prev) => ({
|
|
597
|
+
...prev,
|
|
598
|
+
[field]: true
|
|
599
|
+
}));
|
|
600
|
+
};
|
|
601
|
+
const setFieldError = (field, error) => {
|
|
602
|
+
setErrors((prev) => ({
|
|
603
|
+
...prev,
|
|
604
|
+
[field]: error
|
|
605
|
+
}));
|
|
606
|
+
};
|
|
607
|
+
const updateValues = (newValues) => {
|
|
608
|
+
setValues((prev) => ({
|
|
609
|
+
...prev,
|
|
610
|
+
...newValues
|
|
611
|
+
}));
|
|
612
|
+
const dirtyFields = {};
|
|
613
|
+
Object.keys(newValues).forEach((key) => {
|
|
614
|
+
dirtyFields[key] = true;
|
|
615
|
+
});
|
|
616
|
+
setDirty((prev) => ({
|
|
617
|
+
...prev,
|
|
618
|
+
...dirtyFields
|
|
619
|
+
}));
|
|
620
|
+
};
|
|
621
|
+
const resetForm = () => {
|
|
622
|
+
setValues(initialValues);
|
|
623
|
+
setErrors({});
|
|
624
|
+
setTouched({});
|
|
625
|
+
setDirty({});
|
|
626
|
+
setIsSubmitting(false);
|
|
627
|
+
};
|
|
628
|
+
const handleSubmit = async (e) => {
|
|
629
|
+
e.preventDefault();
|
|
630
|
+
const allTouched = {};
|
|
631
|
+
Object.keys(values).forEach((key) => {
|
|
632
|
+
allTouched[key] = true;
|
|
633
|
+
});
|
|
634
|
+
setTouched(allTouched);
|
|
635
|
+
let validationErrors = {};
|
|
636
|
+
if (validate) {
|
|
637
|
+
validationErrors = validate(values);
|
|
638
|
+
setErrors(validationErrors || {});
|
|
639
|
+
}
|
|
640
|
+
if (Object.keys(validationErrors).length === 0 && onSubmit) {
|
|
641
|
+
setIsSubmitting(true);
|
|
642
|
+
setSubmitCount((count) => count + 1);
|
|
643
|
+
try {
|
|
644
|
+
await onSubmit(values, {
|
|
645
|
+
fields: Object.keys(values).reduce((acc, key) => {
|
|
646
|
+
acc[key] = {
|
|
647
|
+
value: values[key],
|
|
648
|
+
error: errors[key],
|
|
649
|
+
touched: touched[key] || false,
|
|
650
|
+
dirty: dirty[key] || false
|
|
651
|
+
};
|
|
652
|
+
return acc;
|
|
653
|
+
}, {}),
|
|
654
|
+
isValid,
|
|
655
|
+
isDirty,
|
|
656
|
+
isSubmitting: true,
|
|
657
|
+
submitCount: submitCount + 1
|
|
658
|
+
});
|
|
659
|
+
} finally {
|
|
660
|
+
setIsSubmitting(false);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
return {
|
|
665
|
+
values,
|
|
666
|
+
errors,
|
|
667
|
+
touched,
|
|
668
|
+
dirty,
|
|
669
|
+
isValid,
|
|
670
|
+
isDirty,
|
|
671
|
+
isSubmitting,
|
|
672
|
+
submitCount,
|
|
673
|
+
handleChange,
|
|
674
|
+
handleBlur,
|
|
675
|
+
handleSubmit,
|
|
676
|
+
setFieldValue,
|
|
677
|
+
setFieldError,
|
|
678
|
+
setValues: updateValues,
|
|
679
|
+
resetForm
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
function createEventBus() {
|
|
683
|
+
const events = /* @__PURE__ */ new Map();
|
|
684
|
+
const onceHandlers = /* @__PURE__ */ new WeakMap();
|
|
685
|
+
const on = (event, handler) => {
|
|
686
|
+
if (!events.has(event)) {
|
|
687
|
+
events.set(event, /* @__PURE__ */ new Set());
|
|
688
|
+
}
|
|
689
|
+
events.get(event).add(handler);
|
|
690
|
+
return () => off(event, handler);
|
|
691
|
+
};
|
|
692
|
+
const once = (event, handler) => {
|
|
693
|
+
const onceWrapper = (...args) => {
|
|
694
|
+
off(event, onceWrapper);
|
|
695
|
+
handler(...args);
|
|
696
|
+
};
|
|
697
|
+
onceHandlers.set(handler, onceWrapper);
|
|
698
|
+
return on(event, onceWrapper);
|
|
699
|
+
};
|
|
700
|
+
const off = (event, handler) => {
|
|
701
|
+
if (!handler) {
|
|
702
|
+
events.delete(event);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
const wrappedHandler = onceHandlers.get(handler);
|
|
706
|
+
const handlerToRemove = wrappedHandler || handler;
|
|
707
|
+
if (events.has(event)) {
|
|
708
|
+
events.get(event).delete(handlerToRemove);
|
|
709
|
+
if (events.get(event).size === 0) {
|
|
710
|
+
events.delete(event);
|
|
328
711
|
}
|
|
329
712
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
713
|
+
};
|
|
714
|
+
const emit = (event, ...args) => {
|
|
715
|
+
if (!events.has(event)) {
|
|
716
|
+
return;
|
|
333
717
|
}
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
"br",
|
|
338
|
-
"col",
|
|
339
|
-
"embed",
|
|
340
|
-
"hr",
|
|
341
|
-
"img",
|
|
342
|
-
"input",
|
|
343
|
-
"link",
|
|
344
|
-
"meta",
|
|
345
|
-
"param",
|
|
346
|
-
"source",
|
|
347
|
-
"track",
|
|
348
|
-
"wbr"
|
|
349
|
-
];
|
|
350
|
-
if (selfClosing.includes(tag)) {
|
|
351
|
-
return `<${tag}${attrs}/>`;
|
|
718
|
+
const handlers = Array.from(events.get(event));
|
|
719
|
+
for (const handler of handlers) {
|
|
720
|
+
handler(...args);
|
|
352
721
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
fragmentOutput += renderNodeToString(child);
|
|
722
|
+
};
|
|
723
|
+
const clear = (event) => {
|
|
724
|
+
if (event) {
|
|
725
|
+
events.delete(event);
|
|
726
|
+
} else {
|
|
727
|
+
events.clear();
|
|
360
728
|
}
|
|
361
|
-
|
|
729
|
+
};
|
|
730
|
+
return { on, once, off, emit, clear };
|
|
731
|
+
}
|
|
732
|
+
function useEvent(event, handler, options = {}) {
|
|
733
|
+
return options.once ? globalEventBus.once(event, handler) : globalEventBus.on(event, handler);
|
|
734
|
+
}
|
|
735
|
+
function createStore(reducer, initialState, middlewares = []) {
|
|
736
|
+
let state = initialState;
|
|
737
|
+
let listeners = [];
|
|
738
|
+
let dispatch = (action) => {
|
|
739
|
+
state = reducer(state, action);
|
|
740
|
+
listeners.forEach((listener) => listener());
|
|
741
|
+
return action;
|
|
742
|
+
};
|
|
743
|
+
if (middlewares.length > 0) {
|
|
744
|
+
const middlewareAPI = {
|
|
745
|
+
getState: () => state,
|
|
746
|
+
dispatch: (action) => dispatch(action),
|
|
747
|
+
subscribe: (listener) => subscribe(listener)
|
|
748
|
+
};
|
|
749
|
+
const chain = middlewares.map((middleware) => middleware(middlewareAPI));
|
|
750
|
+
dispatch = chain.reduce((a, b) => (next) => a(b(next)))(dispatch);
|
|
362
751
|
}
|
|
363
|
-
|
|
364
|
-
|
|
752
|
+
function subscribe(listener) {
|
|
753
|
+
listeners.push(listener);
|
|
754
|
+
return function unsubscribe() {
|
|
755
|
+
listeners = listeners.filter((l) => l !== listener);
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
dispatch({ type: "@@INIT" });
|
|
759
|
+
return {
|
|
760
|
+
getState: () => state,
|
|
761
|
+
dispatch,
|
|
762
|
+
subscribe
|
|
763
|
+
};
|
|
365
764
|
}
|
|
366
|
-
function
|
|
367
|
-
|
|
765
|
+
function StoreProvider({ store, children }) {
|
|
766
|
+
const [state, setState] = useState(store.getState());
|
|
767
|
+
useEffect(() => {
|
|
768
|
+
const unsubscribe = store.subscribe(() => {
|
|
769
|
+
setState(store.getState());
|
|
770
|
+
});
|
|
771
|
+
return unsubscribe;
|
|
772
|
+
}, [store]);
|
|
773
|
+
return jsx(StoreContext.Provider, {
|
|
774
|
+
value: { store, state },
|
|
775
|
+
children
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
function useSelector(selector) {
|
|
779
|
+
const context = useContext();
|
|
780
|
+
return selector(context.state);
|
|
781
|
+
}
|
|
782
|
+
function useDispatch() {
|
|
783
|
+
const context = useContext();
|
|
784
|
+
return context.store.dispatch;
|
|
785
|
+
}
|
|
786
|
+
function useStore() {
|
|
787
|
+
const context = useContext();
|
|
788
|
+
return context.store;
|
|
789
|
+
}
|
|
790
|
+
function emitAppInit(data) {
|
|
791
|
+
globalEventBus.emit(LifecycleEvents.APP_INIT, data);
|
|
792
|
+
}
|
|
793
|
+
function emitAppMounted(rootElement) {
|
|
794
|
+
globalEventBus.emit(LifecycleEvents.APP_MOUNTED, rootElement);
|
|
795
|
+
}
|
|
796
|
+
function emitAppUpdated() {
|
|
797
|
+
globalEventBus.emit(LifecycleEvents.APP_UPDATED);
|
|
798
|
+
}
|
|
799
|
+
function emitAppError(error) {
|
|
800
|
+
globalEventBus.emit(LifecycleEvents.APP_ERROR, error);
|
|
801
|
+
}
|
|
802
|
+
function emitAppDestroyed() {
|
|
803
|
+
globalEventBus.emit(LifecycleEvents.APP_DESTROYED);
|
|
368
804
|
}
|
|
369
|
-
|
|
805
|
+
function emitComponentCreated(info) {
|
|
806
|
+
globalEventBus.emit(LifecycleEvents.COMPONENT_CREATED, info);
|
|
807
|
+
}
|
|
808
|
+
function emitComponentMounted(info, element) {
|
|
809
|
+
globalEventBus.emit(LifecycleEvents.COMPONENT_MOUNTED, info, element);
|
|
810
|
+
}
|
|
811
|
+
function emitComponentUpdated(info, prevProps, newProps) {
|
|
812
|
+
globalEventBus.emit(LifecycleEvents.COMPONENT_UPDATED, info, prevProps, newProps);
|
|
813
|
+
}
|
|
814
|
+
function emitComponentError(info, error) {
|
|
815
|
+
globalEventBus.emit(LifecycleEvents.COMPONENT_ERROR, info, error);
|
|
816
|
+
}
|
|
817
|
+
function emitComponentUnmounted(info) {
|
|
818
|
+
globalEventBus.emit(LifecycleEvents.COMPONENT_UNMOUNTED, info);
|
|
819
|
+
}
|
|
820
|
+
function onAppInit(handler) {
|
|
821
|
+
return globalEventBus.on(LifecycleEvents.APP_INIT, handler);
|
|
822
|
+
}
|
|
823
|
+
function onAppMounted(handler) {
|
|
824
|
+
return globalEventBus.on(LifecycleEvents.APP_MOUNTED, handler);
|
|
825
|
+
}
|
|
826
|
+
function onAppUpdated(handler) {
|
|
827
|
+
return globalEventBus.on(LifecycleEvents.APP_UPDATED, handler);
|
|
828
|
+
}
|
|
829
|
+
function onAppError(handler) {
|
|
830
|
+
return globalEventBus.on(LifecycleEvents.APP_ERROR, handler);
|
|
831
|
+
}
|
|
832
|
+
function onAppDestroyed(handler) {
|
|
833
|
+
return globalEventBus.on(LifecycleEvents.APP_DESTROYED, handler);
|
|
834
|
+
}
|
|
835
|
+
function onComponentCreated(handler) {
|
|
836
|
+
return globalEventBus.on(LifecycleEvents.COMPONENT_CREATED, handler);
|
|
837
|
+
}
|
|
838
|
+
function onComponentMounted(handler) {
|
|
839
|
+
return globalEventBus.on(LifecycleEvents.COMPONENT_MOUNTED, handler);
|
|
840
|
+
}
|
|
841
|
+
function onComponentUpdated(handler) {
|
|
842
|
+
return globalEventBus.on(LifecycleEvents.COMPONENT_UPDATED, handler);
|
|
843
|
+
}
|
|
844
|
+
function onComponentError(handler) {
|
|
845
|
+
return globalEventBus.on(LifecycleEvents.COMPONENT_ERROR, handler);
|
|
846
|
+
}
|
|
847
|
+
function onComponentUnmounted(handler) {
|
|
848
|
+
return globalEventBus.on(LifecycleEvents.COMPONENT_UNMOUNTED, handler);
|
|
849
|
+
}
|
|
850
|
+
var Fragment, isBatching, queue, contexts, currentRender, states, stateIndices, effects, memos, refs, globalRenderCallback, globalContainer, currentElement, Component, RouterContext, globalEventBus, StoreContext, logger, thunk, LifecycleEvents;
|
|
370
851
|
var init_dist = __esm({
|
|
371
|
-
"node_modules/frontend-hamroun/dist/index.
|
|
852
|
+
"node_modules/frontend-hamroun/dist/index.js"() {
|
|
853
|
+
Fragment = ({ children }) => children;
|
|
372
854
|
isBatching = false;
|
|
373
855
|
queue = [];
|
|
856
|
+
contexts = /* @__PURE__ */ new Map();
|
|
374
857
|
currentRender = 0;
|
|
375
858
|
states = /* @__PURE__ */ new Map();
|
|
376
859
|
stateIndices = /* @__PURE__ */ new Map();
|
|
@@ -380,15 +863,139 @@ var init_dist = __esm({
|
|
|
380
863
|
globalRenderCallback = null;
|
|
381
864
|
globalContainer = null;
|
|
382
865
|
currentElement = null;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
866
|
+
Component = class {
|
|
867
|
+
constructor(props = {}) {
|
|
868
|
+
this.state = {};
|
|
869
|
+
this.element = null;
|
|
870
|
+
this._mounted = false;
|
|
871
|
+
this.props = props;
|
|
872
|
+
}
|
|
873
|
+
componentDidMount() {
|
|
874
|
+
}
|
|
875
|
+
async setState(newState) {
|
|
876
|
+
const prevState = { ...this.state };
|
|
877
|
+
this.state = { ...prevState, ...newState };
|
|
878
|
+
console.log(`${this.constructor.name} state updated:`, {
|
|
879
|
+
prev: prevState,
|
|
880
|
+
next: this.state
|
|
881
|
+
});
|
|
882
|
+
await Promise.resolve();
|
|
883
|
+
if (this._mounted) {
|
|
884
|
+
await this.update();
|
|
885
|
+
} else {
|
|
886
|
+
await this.update();
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
_replayEvents(oldElement, newElement) {
|
|
890
|
+
const oldEvents = oldElement.__events || {};
|
|
891
|
+
Object.entries(oldEvents).forEach(([event, handler]) => {
|
|
892
|
+
newElement.addEventListener(event, handler);
|
|
893
|
+
});
|
|
894
|
+
newElement.__events = oldEvents;
|
|
895
|
+
}
|
|
896
|
+
_deepCloneWithEvents(node) {
|
|
897
|
+
const clone = node.cloneNode(false);
|
|
898
|
+
const events = node.__events || {};
|
|
899
|
+
clone.__events = events;
|
|
900
|
+
Object.entries(events).forEach(([event, handler]) => {
|
|
901
|
+
clone.addEventListener(event, handler);
|
|
902
|
+
});
|
|
903
|
+
Array.from(node.childNodes).forEach((child) => {
|
|
904
|
+
if (child instanceof HTMLElement) {
|
|
905
|
+
clone.appendChild(this._deepCloneWithEvents(child));
|
|
906
|
+
} else {
|
|
907
|
+
clone.appendChild(child.cloneNode(true));
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
return clone;
|
|
911
|
+
}
|
|
912
|
+
async update() {
|
|
913
|
+
const vdom = this.render();
|
|
914
|
+
if (!vdom)
|
|
915
|
+
return document.createTextNode("");
|
|
916
|
+
const rendered = await createElement(vdom);
|
|
917
|
+
if (rendered instanceof HTMLElement) {
|
|
918
|
+
return this._updateElement(rendered);
|
|
919
|
+
}
|
|
920
|
+
const wrapper = document.createElement("div");
|
|
921
|
+
wrapper.appendChild(rendered);
|
|
922
|
+
return this._updateElement(wrapper);
|
|
923
|
+
}
|
|
924
|
+
async _updateElement(rendered) {
|
|
925
|
+
const newElement = this._deepCloneWithEvents(rendered);
|
|
926
|
+
newElement.__instance = this;
|
|
927
|
+
if (!this.element) {
|
|
928
|
+
this.element = newElement;
|
|
929
|
+
if (!this._mounted) {
|
|
930
|
+
this._mounted = true;
|
|
931
|
+
queueMicrotask(() => this.componentDidMount());
|
|
932
|
+
}
|
|
933
|
+
} else if (this.element.parentNode) {
|
|
934
|
+
this.element.parentNode.replaceChild(newElement, this.element);
|
|
935
|
+
this.element = newElement;
|
|
936
|
+
}
|
|
937
|
+
return this.element;
|
|
938
|
+
}
|
|
939
|
+
render() {
|
|
940
|
+
throw new Error("Component must implement render() method");
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
RouterContext = createContext({
|
|
944
|
+
location: {
|
|
945
|
+
pathname: "/",
|
|
946
|
+
search: "",
|
|
947
|
+
hash: ""
|
|
948
|
+
},
|
|
949
|
+
params: {},
|
|
950
|
+
navigate: () => {
|
|
951
|
+
},
|
|
952
|
+
match: () => false
|
|
953
|
+
});
|
|
954
|
+
globalEventBus = createEventBus();
|
|
955
|
+
StoreContext = createContext({
|
|
956
|
+
store: {
|
|
957
|
+
getState: () => ({}),
|
|
958
|
+
dispatch: () => {
|
|
959
|
+
},
|
|
960
|
+
subscribe: () => () => {
|
|
961
|
+
}
|
|
962
|
+
},
|
|
963
|
+
state: {}
|
|
964
|
+
});
|
|
965
|
+
logger = (store) => (next) => (action) => {
|
|
966
|
+
console.group(action.type);
|
|
967
|
+
console.log("Previous state:", store.getState());
|
|
968
|
+
console.log("Action:", action);
|
|
969
|
+
const result = next(action);
|
|
970
|
+
console.log("Next state:", store.getState());
|
|
971
|
+
console.groupEnd();
|
|
972
|
+
return result;
|
|
973
|
+
};
|
|
974
|
+
thunk = (store) => (next) => (action) => {
|
|
975
|
+
if (typeof action === "function") {
|
|
976
|
+
return action(store.dispatch, store.getState);
|
|
390
977
|
}
|
|
978
|
+
return next(action);
|
|
391
979
|
};
|
|
980
|
+
(function(LifecycleEvents2) {
|
|
981
|
+
LifecycleEvents2["APP_INIT"] = "app:init";
|
|
982
|
+
LifecycleEvents2["APP_MOUNTED"] = "app:mounted";
|
|
983
|
+
LifecycleEvents2["APP_UPDATED"] = "app:updated";
|
|
984
|
+
LifecycleEvents2["APP_ERROR"] = "app:error";
|
|
985
|
+
LifecycleEvents2["APP_DESTROYED"] = "app:destroyed";
|
|
986
|
+
LifecycleEvents2["COMPONENT_CREATED"] = "component:created";
|
|
987
|
+
LifecycleEvents2["COMPONENT_MOUNTED"] = "component:mounted";
|
|
988
|
+
LifecycleEvents2["COMPONENT_UPDATED"] = "component:updated";
|
|
989
|
+
LifecycleEvents2["COMPONENT_ERROR"] = "component:error";
|
|
990
|
+
LifecycleEvents2["COMPONENT_UNMOUNTED"] = "component:unmounted";
|
|
991
|
+
LifecycleEvents2["ROUTER_BEFORE_CHANGE"] = "router:before-change";
|
|
992
|
+
LifecycleEvents2["ROUTER_AFTER_CHANGE"] = "router:after-change";
|
|
993
|
+
LifecycleEvents2["ROUTER_ERROR"] = "router:error";
|
|
994
|
+
LifecycleEvents2["STORE_INITIALIZED"] = "store:initialized";
|
|
995
|
+
LifecycleEvents2["STORE_BEFORE_ACTION"] = "store:before-action";
|
|
996
|
+
LifecycleEvents2["STORE_AFTER_ACTION"] = "store:after-action";
|
|
997
|
+
LifecycleEvents2["STORE_ERROR"] = "store:error";
|
|
998
|
+
})(LifecycleEvents || (LifecycleEvents = {}));
|
|
392
999
|
}
|
|
393
1000
|
});
|
|
394
1001
|
|
|
@@ -1342,13 +1949,13 @@ function createDevServer(options = {}) {
|
|
|
1342
1949
|
});
|
|
1343
1950
|
}
|
|
1344
1951
|
function createProductionServer(config) {
|
|
1345
|
-
const
|
|
1952
|
+
const server = new Server({
|
|
1346
1953
|
...config,
|
|
1347
1954
|
// Fix the PORT parsing
|
|
1348
1955
|
port: config.port || (process.env.PORT ? parseInt(process.env.PORT) : 8080)
|
|
1349
1956
|
});
|
|
1350
|
-
|
|
1351
|
-
return
|
|
1957
|
+
server.addShutdownHandler();
|
|
1958
|
+
return server;
|
|
1352
1959
|
}
|
|
1353
1960
|
function getRequestIp(req) {
|
|
1354
1961
|
return req.ip || req.headers["x-forwarded-for"]?.split(",")[0].trim() || req.socket.remoteAddress || "";
|
|
@@ -1559,13 +2166,14 @@ var init_server = __esm({
|
|
|
1559
2166
|
// Could be parsed from URL
|
|
1560
2167
|
api: { serverTime: (/* @__PURE__ */ new Date()).toISOString() }
|
|
1561
2168
|
};
|
|
1562
|
-
const
|
|
1563
|
-
if (!success) {
|
|
2169
|
+
const renderResult = await renderComponent(PageComponent, initialProps);
|
|
2170
|
+
if (!renderResult.success) {
|
|
1564
2171
|
return {
|
|
1565
|
-
html: generateErrorPage(500, "Failed to render page", error instanceof Error ? error : new Error("Unknown error")),
|
|
2172
|
+
html: generateErrorPage(500, "Failed to render page", renderResult.error instanceof Error ? renderResult.error : new Error("Unknown error")),
|
|
1566
2173
|
statusCode: 500
|
|
1567
2174
|
};
|
|
1568
2175
|
}
|
|
2176
|
+
const htmlContent = renderResult.html;
|
|
1569
2177
|
let pageTitle = "My App";
|
|
1570
2178
|
try {
|
|
1571
2179
|
if (typeof PageComponent.getTitle === "function") {
|
|
@@ -1576,7 +2184,7 @@ var init_server = __esm({
|
|
|
1576
2184
|
} catch (e) {
|
|
1577
2185
|
}
|
|
1578
2186
|
const componentName = getComponentName(pagePath, pagesDir);
|
|
1579
|
-
const fullHtml = generateDocument(
|
|
2187
|
+
const fullHtml = generateDocument(htmlContent, {
|
|
1580
2188
|
title: pageTitle,
|
|
1581
2189
|
// Get description from component if available
|
|
1582
2190
|
description: typeof PageComponent.getDescription === "function" ? PageComponent.getDescription(initialProps) : PageComponent.description || "",
|
|
@@ -1694,11 +2302,11 @@ var init_server = __esm({
|
|
|
1694
2302
|
process.on("SIGINT", gracefulShutdown);
|
|
1695
2303
|
}
|
|
1696
2304
|
};
|
|
1697
|
-
renderComponent =
|
|
2305
|
+
renderComponent = (Component2, props = {}) => {
|
|
1698
2306
|
try {
|
|
1699
|
-
const html = renderToString(
|
|
2307
|
+
const html = renderToString(Component2(props));
|
|
1700
2308
|
return {
|
|
1701
|
-
html,
|
|
2309
|
+
html: typeof html === "string" ? html : String(html),
|
|
1702
2310
|
success: true
|
|
1703
2311
|
};
|
|
1704
2312
|
} catch (error) {
|
|
@@ -1955,34 +2563,57 @@ if (isNode && !isBrowser) {
|
|
|
1955
2563
|
}
|
|
1956
2564
|
function renderToString3(content) {
|
|
1957
2565
|
if (typeof content === "string") {
|
|
1958
|
-
return
|
|
2566
|
+
return content;
|
|
1959
2567
|
}
|
|
1960
2568
|
if (typeof content === "function") {
|
|
1961
2569
|
try {
|
|
1962
2570
|
const result = content();
|
|
1963
|
-
return
|
|
2571
|
+
return String(result);
|
|
1964
2572
|
} catch (error) {
|
|
1965
|
-
return
|
|
2573
|
+
return `<!-- Error rendering: ${error} -->`;
|
|
1966
2574
|
}
|
|
1967
2575
|
}
|
|
1968
|
-
return
|
|
2576
|
+
return String(content);
|
|
1969
2577
|
}
|
|
1970
2578
|
console.log("Baraqex - powered by Frontend Hamroun Framework with additional utilities");
|
|
1971
2579
|
export {
|
|
1972
2580
|
ApiRouter2 as ApiRouter,
|
|
1973
2581
|
AuthService2 as AuthService,
|
|
1974
2582
|
BaraqexServer,
|
|
2583
|
+
Component,
|
|
1975
2584
|
Database2 as Database,
|
|
1976
2585
|
Fragment,
|
|
2586
|
+
LifecycleEvents,
|
|
2587
|
+
Link,
|
|
2588
|
+
Redirect,
|
|
2589
|
+
Route,
|
|
2590
|
+
RouterProvider,
|
|
2591
|
+
StoreProvider,
|
|
2592
|
+
Switch,
|
|
1977
2593
|
baraqexRenderToString,
|
|
1978
2594
|
batchUpdates,
|
|
1979
2595
|
callWasmFunction,
|
|
1980
2596
|
createContext,
|
|
1981
2597
|
createDevServer2 as createDevServer,
|
|
2598
|
+
createElement,
|
|
2599
|
+
createEventBus,
|
|
1982
2600
|
createProductionServer2 as createProductionServer,
|
|
1983
2601
|
createServer2 as createServer,
|
|
2602
|
+
createStore,
|
|
2603
|
+
diff,
|
|
2604
|
+
emitAppDestroyed,
|
|
2605
|
+
emitAppError,
|
|
2606
|
+
emitAppInit,
|
|
2607
|
+
emitAppMounted,
|
|
2608
|
+
emitAppUpdated,
|
|
2609
|
+
emitComponentCreated,
|
|
2610
|
+
emitComponentError,
|
|
2611
|
+
emitComponentMounted,
|
|
2612
|
+
emitComponentUnmounted,
|
|
2613
|
+
emitComponentUpdated,
|
|
1984
2614
|
ensureDirectory2 as ensureDirectory,
|
|
1985
2615
|
errorHandler2 as errorHandler,
|
|
2616
|
+
globalEventBus as eventBus,
|
|
1986
2617
|
generateDocument,
|
|
1987
2618
|
generateErrorPage,
|
|
1988
2619
|
generateLoadingPage,
|
|
@@ -1996,10 +2627,22 @@ export {
|
|
|
1996
2627
|
isDirectoryEmpty2 as isDirectoryEmpty,
|
|
1997
2628
|
isWasmReady,
|
|
1998
2629
|
jsx,
|
|
2630
|
+
jsx as jsxDEV,
|
|
1999
2631
|
jsx as jsxs,
|
|
2000
2632
|
loadGoWasm,
|
|
2001
2633
|
loadGoWasmFromFile2 as loadGoWasmFromFile,
|
|
2634
|
+
logger,
|
|
2002
2635
|
notFoundHandler2 as notFoundHandler,
|
|
2636
|
+
onAppDestroyed,
|
|
2637
|
+
onAppError,
|
|
2638
|
+
onAppInit,
|
|
2639
|
+
onAppMounted,
|
|
2640
|
+
onAppUpdated,
|
|
2641
|
+
onComponentCreated,
|
|
2642
|
+
onComponentError,
|
|
2643
|
+
onComponentMounted,
|
|
2644
|
+
onComponentUnmounted,
|
|
2645
|
+
onComponentUpdated,
|
|
2003
2646
|
rateLimit2 as rateLimit,
|
|
2004
2647
|
readJsonFile2 as readJsonFile,
|
|
2005
2648
|
render,
|
|
@@ -2009,14 +2652,23 @@ export {
|
|
|
2009
2652
|
safeJsonParse2 as safeJsonParse,
|
|
2010
2653
|
sendError2 as sendError,
|
|
2011
2654
|
sendSuccess2 as sendSuccess,
|
|
2012
|
-
|
|
2655
|
+
shouldComponentUpdate,
|
|
2656
|
+
thunk,
|
|
2013
2657
|
useContext,
|
|
2658
|
+
useDispatch,
|
|
2014
2659
|
useEffect,
|
|
2015
2660
|
useErrorBoundary,
|
|
2661
|
+
useEvent,
|
|
2662
|
+
useForm,
|
|
2016
2663
|
useGoWasm,
|
|
2664
|
+
useLocation,
|
|
2017
2665
|
useMemo,
|
|
2666
|
+
useNavigate,
|
|
2667
|
+
useParams,
|
|
2018
2668
|
useRef,
|
|
2669
|
+
useSelector,
|
|
2019
2670
|
useState,
|
|
2671
|
+
useStore,
|
|
2020
2672
|
validateFields2 as validateFields,
|
|
2021
2673
|
validateFileUpload2 as validateFileUpload,
|
|
2022
2674
|
writeJsonFile2 as writeJsonFile
|