fix: Update asset metadata and enhance route handling in SUI

- Updated modification times for various asset files in bindata.go to reflect recent changes.
- Enhanced route handling in libsui/index.ts to support optional route parameters, improving flexibility in component rendering.
- Added initialization for sub-components within the rendering process, enhancing component lifecycle management and error handling.
This commit is contained in:
Max 2025-05-05 18:11:47 +08:00
parent d894f0a1e9
commit 01c524be54
2 changed files with 104 additions and 85 deletions

File diff suppressed because one or more lines are too long

View file

@ -357,7 +357,9 @@ async function __sui_render(
const elm = comp.root.closest("[s\\:route]");
const routeAttr = elm ? elm.getAttribute("s:route") : false;
const root = document.body.getAttribute("s:public") || "";
const route = routeAttr ? `${root}${routeAttr}` : window.location.pathname;
const route = routeAttr
? `${root}${routeAttr}`
: option.route || window.location.pathname;
option.component = (routeAttr && comp.root.getAttribute("s:cn")) || "";
const url = `/api/__yao/sui/v1/render${route}`;
@ -386,6 +388,22 @@ async function __sui_render(
// Set the response text to the elements
elms.forEach((elm) => {
elm.innerHTML = text;
// Find sub components and initialize them
const subElms = elm.querySelectorAll("[s\\:cn]");
subElms.forEach((subElm) => {
const method = subElm.getAttribute("s:ready");
const cn = subElm.getAttribute("s:cn");
if (method && cn && typeof window[cn] === "function") {
try {
new window[cn](subElm);
} catch (e) {
const message = e.message || e || "An error occurred";
console.error(`[SUI] ${cn} Error: ${message}`);
}
}
});
try {
__sui_event_init(elm);
} catch (e) {
@ -421,6 +439,7 @@ export type RenderOption = {
replace?: boolean; // default is true
withPageData?: boolean; // default is false
component?: string; // default is empty
route?: string; // default is empty
};
export type ComponentState = {