Skip to content

Commit

Permalink
property dependency fixes for region -> text -> role
Browse files Browse the repository at this point in the history
  • Loading branch information
Heulitig committed Oct 30, 2023
1 parent fcf243c commit c3a27f3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
10 changes: 10 additions & 0 deletions fastn-js/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,12 @@ class Node2 {
}
}
} else if (kind === fastn_dom.PropertyKind.Id) {
console.log(staticValue);
if (fastn_utils.isNull(staticValue)) {
this.#node.id = null;
return;
}

this.#node.id = staticValue;
} else if (kind === fastn_dom.PropertyKind.Css) {
let css_list = staticValue.map(obj => fastn_utils.getStaticValue(obj.item));
Expand Down Expand Up @@ -1950,8 +1956,12 @@ class Node2 {
let styles = staticValue?.map(obj => fastn_utils.getStaticValue(obj.item));
this.attachTextStyles(styles);
} else if (kind === fastn_dom.PropertyKind.Region) {
console.log(staticValue);
console.log(fastn_utils.slugify(this.#rawInnerValue));
console.log(this.#node.innerHTML);
this.updateTagName(staticValue);
if (this.#node.innerHTML) {
console.log("Setting new node id");
this.#node.id = fastn_utils.slugify(this.#rawInnerValue);
}
} else if (kind === fastn_dom.PropertyKind.AlignContent) {
Expand Down
51 changes: 40 additions & 11 deletions ftd/src/js/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,18 +1160,16 @@ impl Text {
let mut component_statements = vec![];
let kernel = create_element(fastn_js::ElementKind::Text, parent, index, rdata);
component_statements.push(fastn_js::ComponentStatement::CreateKernel(kernel.clone()));
component_statements.extend(self.common.to_set_properties(
component_statements.extend(self.common.to_set_properties_with_text(
kernel.name.as_str(),
doc,
rdata,
));
component_statements.push(fastn_js::ComponentStatement::SetProperty(
fastn_js::SetProperty {
fastn_js::ComponentStatement::SetProperty(fastn_js::SetProperty {
kind: fastn_js::PropertyKind::StringValue,
value: self.text.to_set_property_value(doc, rdata),
element_name: kernel.name.to_string(),
inherited: rdata.inherited_variable_name.to_string(),
},
}),
));
component_statements.extend(self.text_common.to_set_properties(
kernel.name.as_str(),
Expand Down Expand Up @@ -2446,7 +2444,7 @@ impl Common {
}
}

pub fn to_set_properties(
pub fn to_set_properties_without_role(
&self,
element_name: &str,
doc: &ftd::interpreter::TDoc,
Expand Down Expand Up @@ -2934,11 +2932,6 @@ impl Common {
),
));
}
if let Some(ref role) = self.role {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
role.to_set_property(fastn_js::PropertyKind::Role, doc, element_name, rdata),
));
}
if let Some(ref opacity) = self.opacity {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
opacity.to_set_property(fastn_js::PropertyKind::Opacity, doc, element_name, rdata),
Expand Down Expand Up @@ -3046,6 +3039,42 @@ impl Common {
}
component_statements
}

pub fn to_set_properties_with_text(
&self,
element_name: &str,
doc: &ftd::interpreter::TDoc,
rdata: &ftd::js::ResolverData,
text_component_statement: fastn_js::ComponentStatement,
) -> Vec<fastn_js::ComponentStatement> {
// Property dependencies
// Role <- Text (Role for post_markdown_process) <- Region(Headings need text for auto ids)
let mut component_statements = vec![];
if let Some(ref role) = self.role {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
role.to_set_property(fastn_js::PropertyKind::Role, doc, element_name, rdata),
));
}
component_statements.push(text_component_statement);
component_statements.extend(self.to_set_properties_without_role(element_name, doc, rdata));
component_statements
}

pub fn to_set_properties(
&self,
element_name: &str,
doc: &ftd::interpreter::TDoc,
rdata: &ftd::js::ResolverData,
) -> Vec<fastn_js::ComponentStatement> {
let mut component_statements = vec![];
component_statements.extend(self.to_set_properties_without_role(element_name, doc, rdata));
if let Some(ref role) = self.role {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
role.to_set_property(fastn_js::PropertyKind::Role, doc, element_name, rdata),
));
}
component_statements
}
}

impl ftd::interpreter::Event {
Expand Down

0 comments on commit c3a27f3

Please sign in to comment.