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:
parent
d894f0a1e9
commit
01c524be54
2 changed files with 104 additions and 85 deletions
168
data/bindata.go
168
data/bindata.go
File diff suppressed because one or more lines are too long
|
|
@ -357,7 +357,9 @@ async function __sui_render(
|
||||||
const elm = comp.root.closest("[s\\:route]");
|
const elm = comp.root.closest("[s\\:route]");
|
||||||
const routeAttr = elm ? elm.getAttribute("s:route") : false;
|
const routeAttr = elm ? elm.getAttribute("s:route") : false;
|
||||||
const root = document.body.getAttribute("s:public") || "";
|
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")) || "";
|
option.component = (routeAttr && comp.root.getAttribute("s:cn")) || "";
|
||||||
|
|
||||||
const url = `/api/__yao/sui/v1/render${route}`;
|
const url = `/api/__yao/sui/v1/render${route}`;
|
||||||
|
|
@ -386,6 +388,22 @@ async function __sui_render(
|
||||||
// Set the response text to the elements
|
// Set the response text to the elements
|
||||||
elms.forEach((elm) => {
|
elms.forEach((elm) => {
|
||||||
elm.innerHTML = text;
|
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 {
|
try {
|
||||||
__sui_event_init(elm);
|
__sui_event_init(elm);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -421,6 +439,7 @@ export type RenderOption = {
|
||||||
replace?: boolean; // default is true
|
replace?: boolean; // default is true
|
||||||
withPageData?: boolean; // default is false
|
withPageData?: boolean; // default is false
|
||||||
component?: string; // default is empty
|
component?: string; // default is empty
|
||||||
|
route?: string; // default is empty
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ComponentState = {
|
export type ComponentState = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue