@hypen-space/core 0.4.38 → 0.4.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/app.js +16 -1
- package/dist/app.js.map +3 -3
- package/dist/components/builtin.d.ts +17 -0
- package/dist/components/builtin.js +48 -30
- package/dist/components/builtin.js.map +4 -4
- package/dist/context.d.ts +11 -20
- package/dist/context.js +10 -38
- package/dist/context.js.map +3 -3
- package/dist/index.browser.js +25 -38
- package/dist/index.browser.js.map +4 -4
- package/dist/index.js +56 -67
- package/dist/index.js.map +5 -5
- package/dist/remote/client.js +16 -1
- package/dist/remote/client.js.map +3 -3
- package/dist/remote/index.js +16 -1
- package/dist/remote/index.js.map +3 -3
- package/dist/result.js +16 -1
- package/dist/result.js.map +3 -3
- package/dist/retry.js +16 -1
- package/dist/retry.js.map +3 -3
- package/package.json +1 -1
- package/src/components/builtin.ts +78 -56
- package/src/context.ts +22 -65
- package/src/result.ts +11 -0
package/dist/index.js
CHANGED
|
@@ -521,6 +521,21 @@ class RenderError extends HypenError {
|
|
|
521
521
|
}
|
|
522
522
|
}
|
|
523
523
|
function classifyEngineError(err) {
|
|
524
|
+
if (err && typeof err === "object" && "message" in err && "type" in err) {
|
|
525
|
+
const structured = err;
|
|
526
|
+
switch (structured.type) {
|
|
527
|
+
case "parseError":
|
|
528
|
+
return new ParseError(structured.message);
|
|
529
|
+
case "stateError":
|
|
530
|
+
return new StateError(structured.message);
|
|
531
|
+
case "renderError":
|
|
532
|
+
return new RenderError(structured.message);
|
|
533
|
+
case "actionError":
|
|
534
|
+
return new HypenError("ACTION_ERROR", structured.message);
|
|
535
|
+
default:
|
|
536
|
+
return new HypenError("UNKNOWN_ERROR", structured.message);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
524
539
|
const message = err instanceof Error ? err.message : String(err);
|
|
525
540
|
if (message.startsWith("Parse error:")) {
|
|
526
541
|
return new ParseError(message);
|
|
@@ -1890,7 +1905,6 @@ var log7 = frameworkLoggers.context;
|
|
|
1890
1905
|
class HypenGlobalContext {
|
|
1891
1906
|
modules = new Map;
|
|
1892
1907
|
typedEvents;
|
|
1893
|
-
legacyEventBus = new Map;
|
|
1894
1908
|
constructor() {
|
|
1895
1909
|
this.typedEvents = new TypedEventEmitter;
|
|
1896
1910
|
}
|
|
@@ -1933,57 +1947,30 @@ class HypenGlobalContext {
|
|
|
1933
1947
|
return state2;
|
|
1934
1948
|
}
|
|
1935
1949
|
emit(event, payload) {
|
|
1936
|
-
|
|
1937
|
-
if (!handlers || handlers.size === 0) {
|
|
1950
|
+
if (this.typedEvents.listenerCount(event) === 0) {
|
|
1938
1951
|
log7.debug(`Event "${event}" emitted but no listeners`);
|
|
1939
|
-
|
|
1940
|
-
log7.debug(`Emitting event: ${event}`, payload);
|
|
1941
|
-
handlers.forEach((handler) => {
|
|
1942
|
-
try {
|
|
1943
|
-
handler(payload);
|
|
1944
|
-
} catch (error) {
|
|
1945
|
-
log7.error(`Error in event handler for "${event}":`, error);
|
|
1946
|
-
}
|
|
1947
|
-
});
|
|
1948
|
-
}
|
|
1949
|
-
if (this.typedEvents.listenerCount(event) > 0) {
|
|
1950
|
-
this.typedEvents.emit(event, payload);
|
|
1952
|
+
return;
|
|
1951
1953
|
}
|
|
1954
|
+
log7.debug(`Emitting event: ${event}`, payload);
|
|
1955
|
+
this.typedEvents.emit(event, payload);
|
|
1952
1956
|
}
|
|
1953
1957
|
on(event, handler) {
|
|
1954
|
-
if (!this.legacyEventBus.has(event)) {
|
|
1955
|
-
this.legacyEventBus.set(event, new Set);
|
|
1956
|
-
}
|
|
1957
|
-
const handlers = this.legacyEventBus.get(event);
|
|
1958
|
-
handlers.add(handler);
|
|
1959
1958
|
log7.debug(`Listening to event: ${event}`);
|
|
1960
|
-
return ()
|
|
1961
|
-
handlers.delete(handler);
|
|
1962
|
-
if (handlers.size === 0) {
|
|
1963
|
-
this.legacyEventBus.delete(event);
|
|
1964
|
-
}
|
|
1965
|
-
};
|
|
1959
|
+
return this.typedEvents.on(event, handler);
|
|
1966
1960
|
}
|
|
1967
1961
|
off(event, handler) {
|
|
1968
|
-
|
|
1969
|
-
if (handlers) {
|
|
1970
|
-
handlers.delete(handler);
|
|
1971
|
-
if (handlers.size === 0) {
|
|
1972
|
-
this.legacyEventBus.delete(event);
|
|
1973
|
-
}
|
|
1974
|
-
}
|
|
1962
|
+
this.typedEvents.off(event, handler);
|
|
1975
1963
|
}
|
|
1976
1964
|
clearEvent(event) {
|
|
1977
|
-
this.
|
|
1965
|
+
this.typedEvents.removeAllListeners(event);
|
|
1978
1966
|
}
|
|
1979
1967
|
clearAllEvents() {
|
|
1980
|
-
this.
|
|
1968
|
+
this.typedEvents.clearAll();
|
|
1981
1969
|
}
|
|
1982
1970
|
debug() {
|
|
1983
1971
|
return {
|
|
1984
1972
|
modules: this.getModuleIds(),
|
|
1985
|
-
events:
|
|
1986
|
-
typedEvents: this.typedEvents.eventNames(),
|
|
1973
|
+
events: this.typedEvents.eventNames(),
|
|
1987
1974
|
state: this.getGlobalState()
|
|
1988
1975
|
};
|
|
1989
1976
|
}
|
|
@@ -2628,6 +2615,35 @@ class ComponentResolver {
|
|
|
2628
2615
|
|
|
2629
2616
|
// src/components/builtin.ts
|
|
2630
2617
|
var log9 = frameworkLoggers.router;
|
|
2618
|
+
async function updateRouteVisibility(currentPath, engine, doc) {
|
|
2619
|
+
const targetDoc = doc ?? document;
|
|
2620
|
+
const routeElements = targetDoc.querySelectorAll('[data-hypen-type="route"]');
|
|
2621
|
+
let matchFound = false;
|
|
2622
|
+
for (let index2 = 0;index2 < routeElements.length; index2++) {
|
|
2623
|
+
const routeEl = routeElements[index2];
|
|
2624
|
+
const htmlEl = routeEl;
|
|
2625
|
+
const routePath = htmlEl.dataset.routePath || "/";
|
|
2626
|
+
const isMatch = routePath === currentPath;
|
|
2627
|
+
htmlEl.style.display = isMatch ? "flex" : "none";
|
|
2628
|
+
if (isMatch) {
|
|
2629
|
+
matchFound = true;
|
|
2630
|
+
const componentName = htmlEl.dataset.routeComponent;
|
|
2631
|
+
const isLazy = htmlEl.dataset.routeLazy === "true";
|
|
2632
|
+
const hasContent = htmlEl.children.length > 0;
|
|
2633
|
+
const shouldRender = componentName && engine && (isLazy || !hasContent);
|
|
2634
|
+
if (shouldRender) {
|
|
2635
|
+
try {
|
|
2636
|
+
await engine.renderLazyRoute(routePath, componentName, htmlEl);
|
|
2637
|
+
} catch (err) {
|
|
2638
|
+
log9.error(`Failed to render route ${routePath}:`, err);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
if (!matchFound) {
|
|
2644
|
+
log9.warn(`No route matched path: ${currentPath}. Available routes:`, Array.from(routeElements).map((el) => el.dataset.routePath));
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2631
2647
|
var Router = app.defineState({
|
|
2632
2648
|
currentPath: "/",
|
|
2633
2649
|
matchedRoute: null,
|
|
@@ -2643,40 +2659,13 @@ var Router = app.defineState({
|
|
|
2643
2659
|
return;
|
|
2644
2660
|
}
|
|
2645
2661
|
const hypenEngine = context.__hypenEngine;
|
|
2646
|
-
const updateRouteVisibility = async (currentPath) => {
|
|
2647
|
-
const routeElements = document.querySelectorAll('[data-hypen-type="route"]');
|
|
2648
|
-
let matchFound = false;
|
|
2649
|
-
for (let index2 = 0;index2 < routeElements.length; index2++) {
|
|
2650
|
-
const routeEl = routeElements[index2];
|
|
2651
|
-
const htmlEl = routeEl;
|
|
2652
|
-
const routePath = htmlEl.dataset.routePath || "/";
|
|
2653
|
-
const isMatch = routePath === currentPath;
|
|
2654
|
-
htmlEl.style.display = isMatch ? "flex" : "none";
|
|
2655
|
-
if (isMatch) {
|
|
2656
|
-
matchFound = true;
|
|
2657
|
-
const componentName = htmlEl.dataset.routeComponent;
|
|
2658
|
-
const isLazy = htmlEl.dataset.routeLazy === "true";
|
|
2659
|
-
const hasContent = htmlEl.children.length > 0;
|
|
2660
|
-
if (componentName && !hasContent && hypenEngine) {
|
|
2661
|
-
try {
|
|
2662
|
-
await hypenEngine.renderLazyRoute(routePath, componentName, htmlEl);
|
|
2663
|
-
} catch (err) {
|
|
2664
|
-
log9.error(`Failed to render route ${routePath}:`, err);
|
|
2665
|
-
}
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
if (!matchFound) {
|
|
2670
|
-
log9.warn(`No route matched path: ${currentPath}. Available routes:`, Array.from(routeElements).map((el) => el.dataset.routePath));
|
|
2671
|
-
}
|
|
2672
|
-
};
|
|
2673
2662
|
setTimeout(() => {
|
|
2674
|
-
updateRouteVisibility(state2.currentPath);
|
|
2663
|
+
updateRouteVisibility(state2.currentPath, hypenEngine);
|
|
2675
2664
|
}, 100);
|
|
2676
2665
|
router.onNavigate((routeState) => {
|
|
2677
2666
|
state2.currentPath = routeState.currentPath;
|
|
2678
2667
|
state2.routeParams = routeState.params;
|
|
2679
|
-
updateRouteVisibility(routeState.currentPath);
|
|
2668
|
+
updateRouteVisibility(routeState.currentPath, hypenEngine);
|
|
2680
2669
|
});
|
|
2681
2670
|
}).build();
|
|
2682
2671
|
var Route = app.defineState({}, { name: "__Route" }).build();
|
|
@@ -2783,4 +2772,4 @@ export {
|
|
|
2783
2772
|
ActionError
|
|
2784
2773
|
};
|
|
2785
2774
|
|
|
2786
|
-
//# debugId=
|
|
2775
|
+
//# debugId=9FB52584D73FE77364756E2164756E21
|