Actualizar sigpro.ts

This commit is contained in:
2026-04-07 01:44:19 +02:00
parent 53f7b7980d
commit 8204fd7fd1

View File

@@ -407,7 +407,6 @@ export function Tag(tag: string, props: any = {}, children: any = []): HTMLEleme
return el; return el;
} }
// Componente If con soporte de transiciones
export function If( export function If(
condition: (() => boolean) | boolean, condition: (() => boolean) | boolean,
thenVal: any, thenVal: any,
@@ -448,7 +447,6 @@ export function If(
return container; return container;
} }
// Componente For con keyed rendering
export function For<T>( export function For<T>(
source: (() => T[]) | T[], source: (() => T[]) | T[],
renderFn: (item: T, index: number) => any, renderFn: (item: T, index: number) => any,
@@ -498,17 +496,12 @@ export function For<T>(
return container; return container;
} }
// Router con soporte mejorado export const Router = Object.assign(
export const Router = { (routes) => {
params: $({} as Record<string, string>),
to: (path: string) => { window.location.hash = path.replace(/^#?\/?/, "#/"); },
back: () => window.history.back(),
path: () => window.location.hash.replace(/^#/, "") || "/",
outlet: (routes: Array<{ path: string; component: Component }>) => {
const currentPath = $(Router.path()); const currentPath = $(Router.path());
window.addEventListener("hashchange", () => currentPath(Router.path())); window.addEventListener("hashchange", () => currentPath(Router.path()));
const outlet = Tag("div", { class: "router-outlet" }); const outlet = Tag("div", { class: "router-outlet" });
let currentView: Runtime | null = null; let currentView = null;
Watch(currentPath, async () => { Watch(currentPath, async () => {
const path = currentPath(); const path = currentPath();
@@ -521,9 +514,9 @@ export const Router = {
if (route) { if (route) {
let comp = route.component; let comp = route.component;
if (isFunc(comp) && comp.toString().includes('import')) { if (isFunc(comp) && comp.toString().includes('import')) {
comp = (await (comp as any)()).default || (await (comp as any)()); comp = (await comp()).default || (await comp());
} }
const params: Record<string, string> = {}; const params = {};
route.path.split("/").filter(Boolean).forEach((part, i) => { route.path.split("/").filter(Boolean).forEach((part, i) => {
if (part.startsWith(":")) params[part.slice(1)] = path.split("/").filter(Boolean)[i]; if (part.startsWith(":")) params[part.slice(1)] = path.split("/").filter(Boolean)[i];
}); });
@@ -535,7 +528,13 @@ export const Router = {
}); });
return outlet; return outlet;
}, },
}; {
params: $({}),
to: (path) => { window.location.hash = path.replace(/^#?\/?/, "#/"); },
back: () => window.history.back(),
path: () => window.location.hash.replace(/^#/, "") || "/",
}
);
export function Mount(component: Component | (() => any), target: string | HTMLElement): Runtime | undefined { export function Mount(component: Component | (() => any), target: string | HTMLElement): Runtime | undefined {
const targetEl = typeof target === "string" ? doc.querySelector(target) : target; const targetEl = typeof target === "string" ? doc.querySelector(target) : target;