chore: Update __Query class to accept both string and Element types for selector

This commit is contained in:
Max 2024-08-06 09:31:36 +08:00
parent 197b155280
commit 2a19ef857b
3 changed files with 64 additions and 67 deletions

File diff suppressed because one or more lines are too long

View file

@ -115,8 +115,7 @@ const componentInitScriptTmpl = `
this.root = %s;
this.store = new __sui_store(this.root);
this.props = new __sui_props(this.root);
if (!this.root.getAttribute("initialized")) {
if (this.root.getAttribute("initialized") != 'true') {
this.root.setAttribute("initialized", 'true');
this.root.addEventListener("state:change", function (event) {
const name = this.getAttribute("s:cn");

View file

@ -42,13 +42,11 @@ function __sui_state(component) {
return;
}
let parent = component.root.parentElement;
while (parent && !parent.getAttribute("s:cn")) {
parent = parent.parentElement;
}
if (parent == document.body || parent == null) {
let parent = component.root.parentElement?.closest(`[s\\:cn]`);
if (parent == null) {
return;
}
// Dispatch the state change custom event to parent component
const event = new CustomEvent("state:change", {
detail: { key: key, value: value, target: component.root },