From c3a27f3ea90390d7c9d26c7dd8405918760dda59 Mon Sep 17 00:00:00 2001 From: heulitig Date: Mon, 30 Oct 2023 13:46:07 +0530 Subject: [PATCH] property dependency fixes for region -> text -> role --- fastn-js/js/dom.js | 10 +++++++++ ftd/src/js/element.rs | 51 +++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index d1f78713f9..50faa430c8 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -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)); @@ -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) { diff --git a/ftd/src/js/element.rs b/ftd/src/js/element.rs index fbd3b0d535..3d30d361f1 100644 --- a/ftd/src/js/element.rs +++ b/ftd/src/js/element.rs @@ -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(), @@ -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, @@ -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), @@ -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 { + // 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 { + 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 {