baraqex 1.0.38 → 1.0.40
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/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +786 -141
- package/dist/browser.js.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +893 -223
- package/dist/index.js.map +4 -4
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +221 -85
- package/dist/server/index.js.map +4 -4
- package/package.json +14 -10
- package/templates/ssr-template/package-lock.json +160 -1395
- package/templates/ssr-template/package.json +1 -1
- package/templates/ssr-template/src/App.tsx +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,57 +103,65 @@ 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, isServerSideRender = false) {
|
|
41
138
|
currentRender++;
|
|
139
|
+
isSSR = isServerSideRender;
|
|
42
140
|
stateIndices.set(currentRender, 0);
|
|
141
|
+
if (!states.has(currentRender)) {
|
|
142
|
+
states.set(currentRender, []);
|
|
143
|
+
}
|
|
43
144
|
return currentRender;
|
|
44
145
|
}
|
|
45
146
|
function finishRender() {
|
|
46
|
-
if (isServer) {
|
|
47
|
-
serverStates.delete(currentRender);
|
|
48
|
-
}
|
|
49
|
-
currentRender = 0;
|
|
50
147
|
}
|
|
51
148
|
function useState(initial) {
|
|
52
149
|
if (!currentRender) {
|
|
53
150
|
throw new Error("useState must be called within a render");
|
|
54
151
|
}
|
|
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
152
|
if (!states.has(currentRender)) {
|
|
71
153
|
states.set(currentRender, []);
|
|
72
154
|
}
|
|
73
155
|
const componentStates = states.get(currentRender);
|
|
74
|
-
const index = stateIndices.get(currentRender);
|
|
156
|
+
const index = stateIndices.get(currentRender) || 0;
|
|
75
157
|
if (index >= componentStates.length) {
|
|
76
158
|
componentStates.push(initial);
|
|
77
159
|
}
|
|
78
160
|
const state = componentStates[index];
|
|
79
161
|
const setState = (newValue) => {
|
|
162
|
+
if (isSSR) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
80
165
|
const nextValue = typeof newValue === "function" ? newValue(componentStates[index]) : newValue;
|
|
81
166
|
if (componentStates[index] === nextValue)
|
|
82
167
|
return;
|
|
@@ -93,19 +178,24 @@ function useState(initial) {
|
|
|
93
178
|
function useEffect(callback, deps) {
|
|
94
179
|
if (!currentRender)
|
|
95
180
|
throw new Error("useEffect must be called within a render");
|
|
96
|
-
|
|
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;
|
|
97
187
|
if (!effects.has(currentRender)) {
|
|
98
188
|
effects.set(currentRender, []);
|
|
99
189
|
}
|
|
100
190
|
const componentEffects = effects.get(currentRender);
|
|
101
191
|
const prevEffect = componentEffects[effectIndex];
|
|
102
192
|
if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
|
|
103
|
-
if (prevEffect
|
|
193
|
+
if (prevEffect?.cleanup) {
|
|
104
194
|
prevEffect.cleanup();
|
|
105
195
|
}
|
|
106
196
|
queueMicrotask(() => {
|
|
107
197
|
const cleanup = callback() || void 0;
|
|
108
|
-
componentEffects[effectIndex] = { cleanup, deps };
|
|
198
|
+
componentEffects[effectIndex] = { cleanup, deps: deps || [] };
|
|
109
199
|
});
|
|
110
200
|
}
|
|
111
201
|
stateIndices.set(currentRender, effectIndex + 1);
|
|
@@ -113,7 +203,7 @@ function useEffect(callback, deps) {
|
|
|
113
203
|
function useMemo(factory, deps) {
|
|
114
204
|
if (!currentRender)
|
|
115
205
|
throw new Error("useMemo must be called within a render");
|
|
116
|
-
const memoIndex = stateIndices.get(currentRender);
|
|
206
|
+
const memoIndex = stateIndices.get(currentRender) || 0;
|
|
117
207
|
if (!memos.has(currentRender)) {
|
|
118
208
|
memos.set(currentRender, []);
|
|
119
209
|
}
|
|
@@ -121,7 +211,7 @@ function useMemo(factory, deps) {
|
|
|
121
211
|
const prevMemo = componentMemos[memoIndex];
|
|
122
212
|
if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
|
|
123
213
|
const value = factory();
|
|
124
|
-
componentMemos[memoIndex] = { value, deps };
|
|
214
|
+
componentMemos[memoIndex] = { value, deps: deps || [] };
|
|
125
215
|
stateIndices.set(currentRender, memoIndex + 1);
|
|
126
216
|
return value;
|
|
127
217
|
}
|
|
@@ -131,7 +221,7 @@ function useMemo(factory, deps) {
|
|
|
131
221
|
function useRef(initial) {
|
|
132
222
|
if (!currentRender)
|
|
133
223
|
throw new Error("useRef must be called within a render");
|
|
134
|
-
const refIndex = stateIndices.get(currentRender);
|
|
224
|
+
const refIndex = stateIndices.get(currentRender) || 0;
|
|
135
225
|
if (!refs.has(currentRender)) {
|
|
136
226
|
refs.set(currentRender, []);
|
|
137
227
|
}
|
|
@@ -148,6 +238,9 @@ function useRef(initial) {
|
|
|
148
238
|
}
|
|
149
239
|
async function rerender(rendererId) {
|
|
150
240
|
try {
|
|
241
|
+
if (isSSR) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
151
244
|
const componentEffects = effects.get(rendererId);
|
|
152
245
|
if (componentEffects) {
|
|
153
246
|
componentEffects.forEach((effect) => {
|
|
@@ -167,211 +260,619 @@ function useErrorBoundary() {
|
|
|
167
260
|
const [error, setError] = useState(null);
|
|
168
261
|
return [error, () => setError(null)];
|
|
169
262
|
}
|
|
170
|
-
function
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
+
}
|
|
181
274
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
+
}
|
|
187
282
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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;
|
|
193
291
|
}
|
|
194
|
-
return { type, props: processedProps };
|
|
195
292
|
}
|
|
196
|
-
async function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return
|
|
293
|
+
async function renderToString(element) {
|
|
294
|
+
prepareRender(element);
|
|
295
|
+
try {
|
|
296
|
+
const html = await renderNodeToString(element);
|
|
297
|
+
return html;
|
|
298
|
+
} finally {
|
|
201
299
|
}
|
|
202
|
-
|
|
203
|
-
|
|
300
|
+
}
|
|
301
|
+
async function renderNodeToString(node) {
|
|
302
|
+
if (node == null || typeof node === "boolean") {
|
|
303
|
+
return "";
|
|
204
304
|
}
|
|
205
|
-
if (typeof
|
|
206
|
-
return
|
|
305
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
306
|
+
return escapeHtml(String(node));
|
|
207
307
|
}
|
|
208
|
-
if (Array.isArray(
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
const node = await createElement(child);
|
|
212
|
-
fragment.appendChild(node);
|
|
213
|
-
}
|
|
214
|
-
return fragment;
|
|
308
|
+
if (Array.isArray(node)) {
|
|
309
|
+
const results = await Promise.all(node.map((child) => renderNodeToString(child)));
|
|
310
|
+
return results.join("");
|
|
215
311
|
}
|
|
216
|
-
if ("
|
|
217
|
-
const { type, props } =
|
|
312
|
+
if (node && typeof node === "object" && "type" in node) {
|
|
313
|
+
const { type, props = {} } = node;
|
|
218
314
|
if (typeof type === "function") {
|
|
219
315
|
try {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
316
|
+
const componentRenderId = prepareRender(type);
|
|
317
|
+
try {
|
|
318
|
+
const result = await type(props);
|
|
319
|
+
return await renderNodeToString(result);
|
|
320
|
+
} finally {
|
|
321
|
+
finishRender();
|
|
224
322
|
}
|
|
225
|
-
return node;
|
|
226
323
|
} catch (error) {
|
|
227
324
|
console.error("Error rendering component:", error);
|
|
228
|
-
return
|
|
325
|
+
return `<!-- Error rendering component: ${error.message} -->`;
|
|
229
326
|
}
|
|
230
327
|
}
|
|
231
|
-
|
|
232
|
-
|
|
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));
|
|
252
|
-
}
|
|
328
|
+
if (typeof type === "string") {
|
|
329
|
+
return await renderDOMElement(type, props);
|
|
253
330
|
}
|
|
254
|
-
const children = props == null ? void 0 : props.children;
|
|
255
|
-
if (children != null) {
|
|
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
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return element;
|
|
263
331
|
}
|
|
264
|
-
|
|
332
|
+
if (typeof node === "object") {
|
|
333
|
+
return escapeHtml(JSON.stringify(node));
|
|
334
|
+
}
|
|
335
|
+
return escapeHtml(String(node));
|
|
265
336
|
}
|
|
266
|
-
async function
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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) + "/>";
|
|
272
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;
|
|
273
382
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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;
|
|
283
459
|
}
|
|
284
|
-
container.appendChild(domNode);
|
|
285
|
-
} finally {
|
|
286
|
-
finishRender();
|
|
287
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
|
|
288
551
|
});
|
|
289
552
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
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;
|
|
295
560
|
}
|
|
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
|
-
|
|
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);
|
|
328
678
|
}
|
|
329
679
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
"wbr"
|
|
349
|
-
];
|
|
350
|
-
if (selfClosing.includes(tag)) {
|
|
351
|
-
return `<${tag}${attrs}/>`;
|
|
352
|
-
}
|
|
353
|
-
return `<${tag}${attrs}>${children}</${tag}>`;
|
|
354
|
-
}
|
|
355
|
-
if (vnode.type === Symbol.for("react.fragment")) {
|
|
356
|
-
let fragmentOutput = "";
|
|
357
|
-
const children = Array.isArray((_b = vnode.props) == null ? void 0 : _b.children) ? vnode.props.children : ((_c = vnode.props) == null ? void 0 : _c.children) ? [vnode.props.children] : [];
|
|
358
|
-
for (const child of children) {
|
|
359
|
-
fragmentOutput += renderNodeToString(child);
|
|
360
|
-
}
|
|
361
|
-
return fragmentOutput;
|
|
362
|
-
}
|
|
363
|
-
console.warn("Unknown vnode type:", vnode.type);
|
|
364
|
-
return "";
|
|
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
|
+
};
|
|
365
698
|
}
|
|
366
|
-
function
|
|
367
|
-
|
|
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);
|
|
368
818
|
}
|
|
369
|
-
|
|
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;
|
|
370
868
|
var init_dist = __esm({
|
|
371
|
-
"node_modules/frontend-hamroun/dist/index.
|
|
869
|
+
"node_modules/frontend-hamroun/dist/index.js"() {
|
|
870
|
+
Fragment = ({ children }) => children;
|
|
372
871
|
isBatching = false;
|
|
373
872
|
queue = [];
|
|
873
|
+
contexts = /* @__PURE__ */ new Map();
|
|
374
874
|
currentRender = 0;
|
|
875
|
+
isSSR = false;
|
|
375
876
|
states = /* @__PURE__ */ new Map();
|
|
376
877
|
stateIndices = /* @__PURE__ */ new Map();
|
|
377
878
|
effects = /* @__PURE__ */ new Map();
|
|
@@ -380,15 +881,139 @@ var init_dist = __esm({
|
|
|
380
881
|
globalRenderCallback = null;
|
|
381
882
|
globalContainer = null;
|
|
382
883
|
currentElement = null;
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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);
|
|
390
995
|
}
|
|
996
|
+
return next(action);
|
|
391
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 = {}));
|
|
392
1017
|
}
|
|
393
1018
|
});
|
|
394
1019
|
|
|
@@ -1342,13 +1967,13 @@ function createDevServer(options = {}) {
|
|
|
1342
1967
|
});
|
|
1343
1968
|
}
|
|
1344
1969
|
function createProductionServer(config) {
|
|
1345
|
-
const
|
|
1970
|
+
const server = new Server({
|
|
1346
1971
|
...config,
|
|
1347
1972
|
// Fix the PORT parsing
|
|
1348
1973
|
port: config.port || (process.env.PORT ? parseInt(process.env.PORT) : 8080)
|
|
1349
1974
|
});
|
|
1350
|
-
|
|
1351
|
-
return
|
|
1975
|
+
server.addShutdownHandler();
|
|
1976
|
+
return server;
|
|
1352
1977
|
}
|
|
1353
1978
|
function getRequestIp(req) {
|
|
1354
1979
|
return req.ip || req.headers["x-forwarded-for"]?.split(",")[0].trim() || req.socket.remoteAddress || "";
|
|
@@ -1559,13 +2184,14 @@ var init_server = __esm({
|
|
|
1559
2184
|
// Could be parsed from URL
|
|
1560
2185
|
api: { serverTime: (/* @__PURE__ */ new Date()).toISOString() }
|
|
1561
2186
|
};
|
|
1562
|
-
const
|
|
1563
|
-
if (!success) {
|
|
2187
|
+
const renderResult = await renderComponent(PageComponent, initialProps);
|
|
2188
|
+
if (!renderResult.success) {
|
|
1564
2189
|
return {
|
|
1565
|
-
html: generateErrorPage(500, "Failed to render page", error instanceof Error ? error : new Error("Unknown error")),
|
|
2190
|
+
html: generateErrorPage(500, "Failed to render page", renderResult.error instanceof Error ? renderResult.error : new Error("Unknown error")),
|
|
1566
2191
|
statusCode: 500
|
|
1567
2192
|
};
|
|
1568
2193
|
}
|
|
2194
|
+
const htmlContent = renderResult.html;
|
|
1569
2195
|
let pageTitle = "My App";
|
|
1570
2196
|
try {
|
|
1571
2197
|
if (typeof PageComponent.getTitle === "function") {
|
|
@@ -1576,7 +2202,7 @@ var init_server = __esm({
|
|
|
1576
2202
|
} catch (e) {
|
|
1577
2203
|
}
|
|
1578
2204
|
const componentName = getComponentName(pagePath, pagesDir);
|
|
1579
|
-
const fullHtml = generateDocument(
|
|
2205
|
+
const fullHtml = generateDocument(htmlContent, {
|
|
1580
2206
|
title: pageTitle,
|
|
1581
2207
|
// Get description from component if available
|
|
1582
2208
|
description: typeof PageComponent.getDescription === "function" ? PageComponent.getDescription(initialProps) : PageComponent.description || "",
|
|
@@ -1694,11 +2320,11 @@ var init_server = __esm({
|
|
|
1694
2320
|
process.on("SIGINT", gracefulShutdown);
|
|
1695
2321
|
}
|
|
1696
2322
|
};
|
|
1697
|
-
renderComponent =
|
|
2323
|
+
renderComponent = (Component2, props = {}) => {
|
|
1698
2324
|
try {
|
|
1699
|
-
const html = renderToString(
|
|
2325
|
+
const html = renderToString(Component2(props));
|
|
1700
2326
|
return {
|
|
1701
|
-
html,
|
|
2327
|
+
html: typeof html === "string" ? html : String(html),
|
|
1702
2328
|
success: true
|
|
1703
2329
|
};
|
|
1704
2330
|
} catch (error) {
|
|
@@ -1955,34 +2581,57 @@ if (isNode && !isBrowser) {
|
|
|
1955
2581
|
}
|
|
1956
2582
|
function renderToString3(content) {
|
|
1957
2583
|
if (typeof content === "string") {
|
|
1958
|
-
return
|
|
2584
|
+
return content;
|
|
1959
2585
|
}
|
|
1960
2586
|
if (typeof content === "function") {
|
|
1961
2587
|
try {
|
|
1962
2588
|
const result = content();
|
|
1963
|
-
return
|
|
2589
|
+
return String(result);
|
|
1964
2590
|
} catch (error) {
|
|
1965
|
-
return
|
|
2591
|
+
return `<!-- Error rendering: ${error} -->`;
|
|
1966
2592
|
}
|
|
1967
2593
|
}
|
|
1968
|
-
return
|
|
2594
|
+
return String(content);
|
|
1969
2595
|
}
|
|
1970
2596
|
console.log("Baraqex - powered by Frontend Hamroun Framework with additional utilities");
|
|
1971
2597
|
export {
|
|
1972
2598
|
ApiRouter2 as ApiRouter,
|
|
1973
2599
|
AuthService2 as AuthService,
|
|
1974
2600
|
BaraqexServer,
|
|
2601
|
+
Component,
|
|
1975
2602
|
Database2 as Database,
|
|
1976
2603
|
Fragment,
|
|
2604
|
+
LifecycleEvents,
|
|
2605
|
+
Link,
|
|
2606
|
+
Redirect,
|
|
2607
|
+
Route,
|
|
2608
|
+
RouterProvider,
|
|
2609
|
+
StoreProvider,
|
|
2610
|
+
Switch,
|
|
1977
2611
|
baraqexRenderToString,
|
|
1978
2612
|
batchUpdates,
|
|
1979
2613
|
callWasmFunction,
|
|
1980
2614
|
createContext,
|
|
1981
2615
|
createDevServer2 as createDevServer,
|
|
2616
|
+
createElement,
|
|
2617
|
+
createEventBus,
|
|
1982
2618
|
createProductionServer2 as createProductionServer,
|
|
1983
2619
|
createServer2 as createServer,
|
|
2620
|
+
createStore,
|
|
2621
|
+
diff,
|
|
2622
|
+
emitAppDestroyed,
|
|
2623
|
+
emitAppError,
|
|
2624
|
+
emitAppInit,
|
|
2625
|
+
emitAppMounted,
|
|
2626
|
+
emitAppUpdated,
|
|
2627
|
+
emitComponentCreated,
|
|
2628
|
+
emitComponentError,
|
|
2629
|
+
emitComponentMounted,
|
|
2630
|
+
emitComponentUnmounted,
|
|
2631
|
+
emitComponentUpdated,
|
|
1984
2632
|
ensureDirectory2 as ensureDirectory,
|
|
1985
2633
|
errorHandler2 as errorHandler,
|
|
2634
|
+
globalEventBus as eventBus,
|
|
1986
2635
|
generateDocument,
|
|
1987
2636
|
generateErrorPage,
|
|
1988
2637
|
generateLoadingPage,
|
|
@@ -1996,10 +2645,22 @@ export {
|
|
|
1996
2645
|
isDirectoryEmpty2 as isDirectoryEmpty,
|
|
1997
2646
|
isWasmReady,
|
|
1998
2647
|
jsx,
|
|
2648
|
+
jsx as jsxDEV,
|
|
1999
2649
|
jsx as jsxs,
|
|
2000
2650
|
loadGoWasm,
|
|
2001
2651
|
loadGoWasmFromFile2 as loadGoWasmFromFile,
|
|
2652
|
+
logger,
|
|
2002
2653
|
notFoundHandler2 as notFoundHandler,
|
|
2654
|
+
onAppDestroyed,
|
|
2655
|
+
onAppError,
|
|
2656
|
+
onAppInit,
|
|
2657
|
+
onAppMounted,
|
|
2658
|
+
onAppUpdated,
|
|
2659
|
+
onComponentCreated,
|
|
2660
|
+
onComponentError,
|
|
2661
|
+
onComponentMounted,
|
|
2662
|
+
onComponentUnmounted,
|
|
2663
|
+
onComponentUpdated,
|
|
2003
2664
|
rateLimit2 as rateLimit,
|
|
2004
2665
|
readJsonFile2 as readJsonFile,
|
|
2005
2666
|
render,
|
|
@@ -2009,14 +2670,23 @@ export {
|
|
|
2009
2670
|
safeJsonParse2 as safeJsonParse,
|
|
2010
2671
|
sendError2 as sendError,
|
|
2011
2672
|
sendSuccess2 as sendSuccess,
|
|
2012
|
-
|
|
2673
|
+
shouldComponentUpdate,
|
|
2674
|
+
thunk,
|
|
2013
2675
|
useContext,
|
|
2676
|
+
useDispatch,
|
|
2014
2677
|
useEffect,
|
|
2015
2678
|
useErrorBoundary,
|
|
2679
|
+
useEvent,
|
|
2680
|
+
useForm,
|
|
2016
2681
|
useGoWasm,
|
|
2682
|
+
useLocation,
|
|
2017
2683
|
useMemo,
|
|
2684
|
+
useNavigate,
|
|
2685
|
+
useParams,
|
|
2018
2686
|
useRef,
|
|
2687
|
+
useSelector,
|
|
2019
2688
|
useState,
|
|
2689
|
+
useStore,
|
|
2020
2690
|
validateFields2 as validateFields,
|
|
2021
2691
|
validateFileUpload2 as validateFileUpload,
|
|
2022
2692
|
writeJsonFile2 as writeJsonFile
|