From f4ecbc51696a635e841dcb66abfb26f6773d7182 Mon Sep 17 00:00:00 2001 From: heulitig Date: Thu, 2 Nov 2023 16:57:31 +0530 Subject: [PATCH] fixed breakpoint-width for ftd.document --- fastn-js/js/dom.js | 5 +++++ fastn-js/src/property.rs | 2 ++ ftd/src/js/element.rs | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index d1f78713f9..d1d8c3c725 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -1566,6 +1566,11 @@ class Node2 { } } else if (kind === fastn_dom.PropertyKind.Id) { this.#node.id = staticValue; + } else if (kind === fastn_dom.PropertyKind.BreakpointWidth) { + if (fastn_utils.isNull(staticValue)) { + return; + } + ftd.breakpoint_width.set("mobile", fastn_utils.getStaticValue(staticValue)); } else if (kind === fastn_dom.PropertyKind.Css) { let css_list = staticValue.map(obj => fastn_utils.getStaticValue(obj.item)); css_list.forEach((css) => { diff --git a/fastn-js/src/property.rs b/fastn-js/src/property.rs index 4018fb2613..d7c76361d5 100644 --- a/fastn-js/src/property.rs +++ b/fastn-js/src/property.rs @@ -307,6 +307,7 @@ impl Value { #[derive(Debug)] pub enum PropertyKind { + BreakpointWidth, Children, StringValue, IntegerValue, @@ -433,6 +434,7 @@ pub enum PropertyKind { impl PropertyKind { pub(crate) fn to_js(&self) -> &'static str { match self { + PropertyKind::BreakpointWidth => "fastn_dom.PropertyKind.BreakpointWidth", PropertyKind::Children => "fastn_dom.PropertyKind.Children", PropertyKind::Id => "fastn_dom.PropertyKind.Id", PropertyKind::Css => "fastn_dom.PropertyKind.Css", diff --git a/ftd/src/js/element.rs b/ftd/src/js/element.rs index 3d30d361f1..4e57e705bf 100644 --- a/ftd/src/js/element.rs +++ b/ftd/src/js/element.rs @@ -1420,6 +1420,16 @@ impl Document { let kernel = create_element(fastn_js::ElementKind::Document, parent, index, rdata); component_statements.push(fastn_js::ComponentStatement::CreateKernel(kernel.clone())); + if let Some(ref breakpoint_width) = self.breakpoint_width { + component_statements.push(fastn_js::ComponentStatement::SetProperty( + breakpoint_width.to_set_property( + fastn_js::PropertyKind::BreakpointWidth, + doc, + kernel.name.as_str(), + rdata, + ), + )); + } component_statements.extend(self.container.to_component_statements( doc, rdata,