From bfcda9c3eae564544619ecb3540c2aa0d43f2d76 Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 08:57:00 +0530 Subject: [PATCH 01/19] : and -> both supported in fastn.redirects syntax --- fastn-core/src/package/redirects.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fastn-core/src/package/redirects.rs b/fastn-core/src/package/redirects.rs index 040f5284d3..85245aab10 100644 --- a/fastn-core/src/package/redirects.rs +++ b/fastn-core/src/package/redirects.rs @@ -9,13 +9,20 @@ impl RedirectsTemp { let body = self.body.as_str(); let mut redirects: ftd::Map = ftd::Map::new(); for line in body.lines() { - if line.trim_start().starts_with(';') { + if line.is_empty() || line.trim_start().starts_with(';') { continue; } + // Supported Redirects Syntax under fastn.redirects + // : + // -> if let Some((key, value)) = line.split_once(':') { redirects.insert(key.trim().to_owned(), value.trim().to_owned()); } + + if let Some((key, value)) = line.split_once("->") { + redirects.insert(key.trim().to_owned(), value.trim().to_owned()); + } } redirects } From d8184d4fa17e5c306ba3f979468cc83e47b0c11c Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 10:53:26 +0530 Subject: [PATCH 02/19] assert checks on redirect values --- Cargo.lock | 2 +- fastn-core/src/package/mod.rs | 9 ++++++- fastn-core/src/package/redirects.rs | 39 ++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc94b19520..cd6cd3782f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "fastn" -version = "0.3.44" +version = "0.3.45" dependencies = [ "clap", "colored", diff --git a/fastn-core/src/package/mod.rs b/fastn-core/src/package/mod.rs index f8e2e75781..b1da0f15bf 100644 --- a/fastn-core/src/package/mod.rs +++ b/fastn-core/src/package/mod.rs @@ -597,7 +597,14 @@ impl Package { package.redirects = { let redirects_temp: Option = fastn_doc.get("fastn#redirects")?; - redirects_temp.map(|r| r.redirects_from_body()) + if let Some(redirects) = redirects_temp { + let result = redirects + .redirects_from_body() + .map_err(|e| fastn_core::Error::GenericError(e.to_string()))?; + Some(result) + } else { + None + } }; package.auto_import = fastn_doc diff --git a/fastn-core/src/package/redirects.rs b/fastn-core/src/package/redirects.rs index 85245aab10..e2e24c5cef 100644 --- a/fastn-core/src/package/redirects.rs +++ b/fastn-core/src/package/redirects.rs @@ -5,7 +5,7 @@ pub struct RedirectsTemp { } impl RedirectsTemp { - pub(crate) fn redirects_from_body(&self) -> ftd::Map { + pub(crate) fn redirects_from_body(&self) -> fastn_core::Result> { let body = self.body.as_str(); let mut redirects: ftd::Map = ftd::Map::new(); for line in body.lines() { @@ -17,14 +17,45 @@ impl RedirectsTemp { // -> if let Some((key, value)) = line.split_once(':') { - redirects.insert(key.trim().to_owned(), value.trim().to_owned()); + Self::assert_and_insert_redirect(key, value, &mut redirects)?; } if let Some((key, value)) = line.split_once("->") { - redirects.insert(key.trim().to_owned(), value.trim().to_owned()); + Self::assert_and_insert_redirect(key, value, &mut redirects)?; } } - redirects + Ok(redirects) + } + + // Assert checks on redirects + // - All redirects should be A -> B where A != B (Self loop) + // - If A -> B exists then there can’t be A -> C where B != C + // (No duplicated values starting with the same A) + fn assert_and_insert_redirect( + from: &str, + to: &str, + redirects: &mut ftd::Map, + ) -> fastn_core::Result<()> { + let from = from.trim().to_owned(); + let to = to.trim().to_owned(); + + assert!( + !from.eq(to.as_str()), + "Redirect {} -> {} is invalid", + from, + to + ); + assert!( + !redirects.contains_key(from.as_str()), + "Redirect {} -> {} is invalid, since {} -> {} already exists", + from.as_str(), + to.as_str(), + from.as_str(), + redirects.get(from.as_str()).unwrap(), + ); + + redirects.insert(from, to); + Ok(()) } } From 75a27582f01b32f4c822b5fbd1bbc9e34033da2a Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 12:03:51 +0530 Subject: [PATCH 03/19] included warning for deprecated syntax --- fastn-core/src/package/redirects.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fastn-core/src/package/redirects.rs b/fastn-core/src/package/redirects.rs index e2e24c5cef..655d44b12c 100644 --- a/fastn-core/src/package/redirects.rs +++ b/fastn-core/src/package/redirects.rs @@ -17,6 +17,10 @@ impl RedirectsTemp { // -> if let Some((key, value)) = line.split_once(':') { + fastn_core::warning!( + "Redirect syntax: '{key}: {value}' will be deprecated\nPlease use the '{key} \ + -> {value}' redirect syntax instead." + ); Self::assert_and_insert_redirect(key, value, &mut redirects)?; } From d9c412c5c9450d48a35f08497aab76482c582c05 Mon Sep 17 00:00:00 2001 From: Arpita-Jaiswal Date: Fri, 8 Sep 2023 12:20:25 +0530 Subject: [PATCH 04/19] Fix: set functions for mutable type --- fastn-js/js/fastn.js | 2 +- fastn-js/src/to_js.rs | 3 ++ ftd/t/js/52-events.ftd | 96 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 ftd/t/js/52-events.ftd diff --git a/fastn-js/js/fastn.js b/fastn-js/js/fastn.js index 07dbe6d19a..fdb07bc50f 100644 --- a/fastn-js/js/fastn.js +++ b/fastn-js/js/fastn.js @@ -266,7 +266,7 @@ class MutableList { let current_list = this.#list; let new_list = []; for (let idx in current_list) { - new_list.push( { item: fastn_utils.clone(current_list[idx].item), index: new Mutable(parseInt(idx)) }); + new_list.push(fastn_utils.clone(current_list[idx].item)); } return new MutableList(new_list); } diff --git a/fastn-js/src/to_js.rs b/fastn-js/src/to_js.rs index 4c48967c35..1d58968bba 100644 --- a/fastn-js/src/to_js.rs +++ b/fastn-js/src/to_js.rs @@ -943,6 +943,9 @@ impl ExpressionGenerator { return format!( indoc::indoc! { "let fastn_utils_val_{refined_var} = fastn_utils.clone({val}); + if (fastn_utils_val_{refined_var} instanceof fastn.mutableClass) {{ + fastn_utils_val_{refined_var} = fastn_utils_val_{refined_var}.get(); + }} if (!fastn_utils.setter({var}, fastn_utils_val_{refined_var})) {{ {var} = fastn_utils_val_{refined_var}; }}" diff --git a/ftd/t/js/52-events.ftd b/ftd/t/js/52-events.ftd new file mode 100644 index 0000000000..5b5ba365ee --- /dev/null +++ b/ftd/t/js/52-events.ftd @@ -0,0 +1,96 @@ +-- string list names: + +-- string: Rithik +-- string: Ritesh +-- string: Heulitig + +-- end: names + + + + + +-- display-names: +names: $names + + + + + + + + + +-- component display-names: +string list names: +integer $selected: 0 +integer len: $length(a = $display-names.names) + +-- ftd.column: +$on-global-key[down]$: $increment($a=$display-names.selected, n=$display-names.len) +$on-global-key[up]$: $decrement($a=$display-names.selected, n=$display-names.len) + +-- display-name: $obj +idx: $idx +$selected: $display-names.selected +for: obj, idx in $display-names.names + +-- end: ftd.column + + +-- end: display-names + + + + + + + + + +-- component display-name: +caption name: +integer idx: +integer $selected: + + +-- ftd.text: $display-name.name +background.solid if { display-name.selected == display-name.idx }: yellow +$on-mouse-enter$: $ftd.set-integer($a = $display-name.selected, v = $display-name.idx) + +-- end: display-name + + + + + +-- integer length(a): +string list a: + +len(a) + + + + + + + + + + + + +-- void increment(a,n): +integer $a: +integer n: + +a = (a + 1) % n + + + + +-- void decrement(a,n): +integer $a: +integer n: + +a = (a - 1) % n From da33fc22980543de671d2f39fe79c26fbc7f039f Mon Sep 17 00:00:00 2001 From: Arpita-Jaiswal Date: Fri, 8 Sep 2023 12:23:03 +0530 Subject: [PATCH 05/19] Fix tests --- ftd/t/js/03-common-properties.html | 3 + ftd/t/js/04-variable.html | 3 + ftd/t/js/05-dynamic-dom-list.html | 6 + ftd/t/js/06-dynamic-dom-list-2.html | 3 + ftd/t/js/10-color-test.html | 3 + ftd/t/js/15-function-call-in-property.html | 3 + ftd/t/js/17-clone.html | 3 + ftd/t/js/29-dom-list.html | 3 + ftd/t/js/52-events.html | 229 +++++++++++++++++++++ 9 files changed, 256 insertions(+) create mode 100644 ftd/t/js/52-events.html diff --git a/ftd/t/js/03-common-properties.html b/ftd/t/js/03-common-properties.html index 8ff8eee95a..60ce70c3ec 100644 --- a/ftd/t/js/03-common-properties.html +++ b/ftd/t/js/03-common-properties.html @@ -1406,6 +1406,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + 1); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/04-variable.html b/ftd/t/js/04-variable.html index 4b0a482b81..1bacd9226b 100644 --- a/ftd/t/js/04-variable.html +++ b/ftd/t/js/04-variable.html @@ -100,6 +100,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + 1); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/05-dynamic-dom-list.html b/ftd/t/js/05-dynamic-dom-list.html index 42168fcc26..bdbbd4f4ca 100644 --- a/ftd/t/js/05-dynamic-dom-list.html +++ b/ftd/t/js/05-dynamic-dom-list.html @@ -72,6 +72,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone((fastn_utils.getter(__args__.a) + 1) % 2); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; } @@ -102,6 +105,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + 1); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/06-dynamic-dom-list-2.html b/ftd/t/js/06-dynamic-dom-list-2.html index 242e6a2b29..9bdd3e8e2c 100644 --- a/ftd/t/js/06-dynamic-dom-list-2.html +++ b/ftd/t/js/06-dynamic-dom-list-2.html @@ -81,6 +81,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(__args__.v); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/10-color-test.html b/ftd/t/js/10-color-test.html index 0e0e35b6a2..502d62d5ca 100644 --- a/ftd/t/js/10-color-test.html +++ b/ftd/t/js/10-color-test.html @@ -120,6 +120,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + 1); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/15-function-call-in-property.html b/ftd/t/js/15-function-call-in-property.html index a43f0ea798..2d19ff18f8 100644 --- a/ftd/t/js/15-function-call-in-property.html +++ b/ftd/t/js/15-function-call-in-property.html @@ -53,6 +53,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + 1); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/17-clone.html b/ftd/t/js/17-clone.html index b9de171331..edf3376828 100644 --- a/ftd/t/js/17-clone.html +++ b/ftd/t/js/17-clone.html @@ -81,6 +81,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + " yo "); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; } diff --git a/ftd/t/js/29-dom-list.html b/ftd/t/js/29-dom-list.html index aa1923e5c2..78c0ebed5a 100644 --- a/ftd/t/js/29-dom-list.html +++ b/ftd/t/js/29-dom-list.html @@ -186,6 +186,9 @@ try { let __args__ = args; let fastn_utils_val___args___a = fastn_utils.clone(fastn_utils.getter(__args__.a) + 1); + if (fastn_utils_val___args___a instanceof fastn.mutableClass) { + fastn_utils_val___args___a = fastn_utils_val___args___a.get(); + } if (!fastn_utils.setter(__args__.a, fastn_utils_val___args___a)) { __args__.a = fastn_utils_val___args___a; }; diff --git a/ftd/t/js/52-events.html b/ftd/t/js/52-events.html new file mode 100644 index 0000000000..89a388ddc9 --- /dev/null +++ b/ftd/t/js/52-events.html @@ -0,0 +1,229 @@ + + + + + + + + + + + + + + +
Rithik
Ritesh
Heulitig
+ + From ce77af4a2e3119c82f35ebe1d58ad2a9242744f0 Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 12:42:24 +0530 Subject: [PATCH 06/19] bump version -> 0.3.46 --- Cargo.lock | 2 +- fastn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cd6cd3782f..abe6a30ce0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "fastn" -version = "0.3.45" +version = "0.3.46" dependencies = [ "clap", "colored", diff --git a/fastn/Cargo.toml b/fastn/Cargo.toml index 58af6efee1..e072058889 100644 --- a/fastn/Cargo.toml +++ b/fastn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastn" -version = "0.3.45" +version = "0.3.46" authors.workspace = true edition.workspace = true license.workspace = true From 40eaeb0040b31d6406b20fa480faa5ecb7cd7f5f Mon Sep 17 00:00:00 2001 From: Harsh Singh <64768386+harshdoesdev@users.noreply.github.com> Date: Fri, 8 Sep 2023 13:39:18 +0530 Subject: [PATCH 07/19] `link-color` property implemented for `ftd.text` (#1284) * added link-color attribute on ftd.text * formatted code * fixed issue with ssr * Fixed tests * Refactored code * moved to TextCommon * use isNull function * Removed unneccessary statements --- fastn-js/js/dom.js | 56 +++++++++++++++++ fastn-js/src/property.rs | 2 + ftd/src/interpreter/things/default.rs | 6 ++ ftd/src/js/element.rs | 12 ++++ ftd/t/js/53-link-color.ftd | 14 +++++ ftd/t/js/53-link-color.html | 90 +++++++++++++++++++++++++++ 6 files changed, 180 insertions(+) create mode 100644 ftd/t/js/53-link-color.ftd create mode 100644 ftd/t/js/53-link-color.html diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index 3e1c0374ed..38242faf23 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -60,6 +60,7 @@ fastn_dom.propertyMap = { "justify-content": "jc", "left": "l", "link": "lk", + "link-color": "lkc", "margin": "m", "margin-bottom": "mb", "margin-horizontal": "mh", @@ -273,6 +274,7 @@ fastn_dom.PropertyKind = { LoopVideo: 113, Controls: 114, Muted: 115, + LinkColor: 116, }; @@ -1244,6 +1246,58 @@ class Node2 { } } } + attachLinkColor(value) { + ftd.dark_mode.addClosure(fastn.closure(() => { + if (!ssr) { + const anchors = this.#node.tagName.toLowerCase() === 'a' + ? [this.#node] + : Array.from(this.#node.querySelectorAll("a")); + let propertyShort = `__${fastn_dom.propertyMap["link-color"]}`; + + if(fastn_utils.isNull(value)) { + anchors.forEach(a => { + a.classList.values().forEach(className => { + if(className.startsWith(`${propertyShort}-`)) { + a.classList.remove(className); + } + }); + }); + } else { + const lightValue = fastn_utils.getStaticValue(value.get("light")); + const darkValue = fastn_utils.getStaticValue(value.get("dark")); + let cls = `${propertyShort}-${JSON.stringify(lightValue)}`; + + if (!fastn_dom.unsanitised_classes[cls]) { + fastn_dom.unsanitised_classes[cls] = ++fastn_dom.class_count; + } + + cls = `${propertyShort}-${fastn_dom.unsanitised_classes[cls]}`; + + const cssClass = `.${cls}`; + + if (!fastn_dom.classes[cssClass]) { + const obj = { property: "color", value: lightValue }; + fastn_dom.classes[cssClass] = fastn_dom.classes[cssClass] || obj; + let styles = document.getElementById('styles'); + styles.innerHTML = `${styles.innerHTML}${getClassAsString(cssClass, obj)}\n`; + } + + if(lightValue !== darkValue) { + const obj = { property: "color", value: darkValue }; + let darkCls = `body.dark ${cssClass}`; + if (!fastn_dom.classes[darkCls]) { + fastn_dom.classes[darkCls] = fastn_dom.classes[darkCls] || obj; + let styles = document.getElementById('styles'); + styles.innerHTML = `${styles.innerHTML}${getClassAsString(darkCls, obj)}\n`; + } + } + + anchors.forEach(a => a.classList.add(cls)); + } + } + }).addNodeProperty(this, null, inherited)); + this.#mutables.push(ftd.dark_mode); + } setStaticProperty(kind, value, inherited) { // value can be either static or mutable let staticValue = fastn_utils.getStaticValue(value); @@ -1494,6 +1548,8 @@ class Node2 { this.attachColorCss("border-top-color", staticValue); } else if (kind === fastn_dom.PropertyKind.BorderBottomColor) { this.attachColorCss("border-bottom-color", staticValue); + } else if (kind === fastn_dom.PropertyKind.LinkColor) { + this.attachLinkColor(staticValue); } else if (kind === fastn_dom.PropertyKind.Color) { this.attachColorCss("color", staticValue, true); } else if (kind === fastn_dom.PropertyKind.Background) { diff --git a/fastn-js/src/property.rs b/fastn-js/src/property.rs index 78d1d940b5..0ce8c31966 100644 --- a/fastn-js/src/property.rs +++ b/fastn-js/src/property.rs @@ -318,6 +318,7 @@ pub enum PropertyKind { Region, OpenInNewTab, Link, + LinkColor, LinkRel, Anchor, Classes, @@ -432,6 +433,7 @@ impl PropertyKind { PropertyKind::Id => "fastn_dom.PropertyKind.Id", PropertyKind::Css => "fastn_dom.PropertyKind.Css", PropertyKind::Js => "fastn_dom.PropertyKind.Js", + PropertyKind::LinkColor => "fastn_dom.PropertyKind.LinkColor", PropertyKind::LinkRel => "fastn_dom.PropertyKind.LinkRel", PropertyKind::AlignSelf => "fastn_dom.PropertyKind.AlignSelf", PropertyKind::Anchor => "fastn_dom.PropertyKind.Anchor", diff --git a/ftd/src/interpreter/things/default.rs b/ftd/src/interpreter/things/default.rs index fa3ad63ed3..f46de6eac2 100644 --- a/ftd/src/interpreter/things/default.rs +++ b/ftd/src/interpreter/things/default.rs @@ -10761,6 +10761,12 @@ fn text_arguments() -> Vec { .into_optional() .into_kind_data(), ), + ftd::interpreter::Argument::default( + "link-color", + ftd::interpreter::Kind::record(ftd::interpreter::FTD_COLOR) + .into_optional() + .into_kind_data(), + ), ] } diff --git a/ftd/src/js/element.rs b/ftd/src/js/element.rs index 9448ec1d87..af6987c1ce 100644 --- a/ftd/src/js/element.rs +++ b/ftd/src/js/element.rs @@ -1888,6 +1888,7 @@ pub struct TextCommon { pub line_clamp: Option, pub style: Option, pub display: Option, + pub link_color: Option, } impl TextCommon { @@ -1910,6 +1911,7 @@ impl TextCommon { line_clamp: ftd::js::value::get_optional_js_value("line-clamp", properties, arguments), style: ftd::js::value::get_optional_js_value("style", properties, arguments), display: ftd::js::value::get_optional_js_value("display", properties, arguments), + link_color: ftd::js::value::get_optional_js_value("link-color", properties, arguments), } } @@ -1960,6 +1962,16 @@ impl TextCommon { display.to_set_property(fastn_js::PropertyKind::Display, doc, element_name, rdata), )); } + if let Some(ref link_color) = self.link_color { + component_statements.push(fastn_js::ComponentStatement::SetProperty( + link_color.to_set_property( + fastn_js::PropertyKind::LinkColor, + doc, + element_name, + rdata, + ), + )); + } component_statements } } diff --git a/ftd/t/js/53-link-color.ftd b/ftd/t/js/53-link-color.ftd new file mode 100644 index 0000000000..e944c47d31 --- /dev/null +++ b/ftd/t/js/53-link-color.ftd @@ -0,0 +1,14 @@ +-- ftd.color link-color: +dark: red +light: blue + +-- ftd.text: Click me +link: https://google.com +link-color: $link-color + +-- ftd.text: +link-color: $link-color + +Hello world [Test](https://google.com) + +This is awesome [Test](https://google.com) diff --git a/ftd/t/js/53-link-color.html b/ftd/t/js/53-link-color.html new file mode 100644 index 0000000000..a2126a6d6f --- /dev/null +++ b/ftd/t/js/53-link-color.html @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + +
Click me
Hello world [Test](https://google.com) + +This is awesome [Test](https://google.com)
+ + From 5c28b9726931993d9beda995bf2323ee6413edb7 Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 13:44:47 +0530 Subject: [PATCH 08/19] bump version -> 0.3.47 --- Cargo.lock | 2 +- fastn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index abe6a30ce0..9eaa11997e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "fastn" -version = "0.3.46" +version = "0.3.47" dependencies = [ "clap", "colored", diff --git a/fastn/Cargo.toml b/fastn/Cargo.toml index e072058889..2fa7e1e640 100644 --- a/fastn/Cargo.toml +++ b/fastn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastn" -version = "0.3.46" +version = "0.3.47" authors.workspace = true edition.workspace = true license.workspace = true From 9dc5f39ec22d45d102460d6d08657191803600bc Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 15:13:09 +0530 Subject: [PATCH 09/19] redirect warning fix for old syntax --- fastn-core/src/package/redirects.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fastn-core/src/package/redirects.rs b/fastn-core/src/package/redirects.rs index 655d44b12c..4978bd4b80 100644 --- a/fastn-core/src/package/redirects.rs +++ b/fastn-core/src/package/redirects.rs @@ -16,6 +16,11 @@ impl RedirectsTemp { // : // -> + if let Some((key, value)) = line.split_once("->") { + Self::assert_and_insert_redirect(key, value, &mut redirects)?; + continue; + } + if let Some((key, value)) = line.split_once(':') { fastn_core::warning!( "Redirect syntax: '{key}: {value}' will be deprecated\nPlease use the '{key} \ @@ -23,10 +28,6 @@ impl RedirectsTemp { ); Self::assert_and_insert_redirect(key, value, &mut redirects)?; } - - if let Some((key, value)) = line.split_once("->") { - Self::assert_and_insert_redirect(key, value, &mut redirects)?; - } } Ok(redirects) } From 1a66728fd420b156c69912402721d9f2df657330 Mon Sep 17 00:00:00 2001 From: heulitig Date: Fri, 8 Sep 2023 15:29:33 +0530 Subject: [PATCH 10/19] bump version -> 0.3.48 --- Cargo.lock | 2 +- fastn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9eaa11997e..f257a94d82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "fastn" -version = "0.3.47" +version = "0.3.48" dependencies = [ "clap", "colored", diff --git a/fastn/Cargo.toml b/fastn/Cargo.toml index 2fa7e1e640..d9a638e5a8 100644 --- a/fastn/Cargo.toml +++ b/fastn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastn" -version = "0.3.47" +version = "0.3.48" authors.workspace = true edition.workspace = true license.workspace = true From 236e76e17ca08dda44a35b2a171245efa4fe9a1e Mon Sep 17 00:00:00 2001 From: heulitig Date: Mon, 11 Sep 2023 10:42:29 +0530 Subject: [PATCH 11/19] class name fix + other minor fixes --- fastn-js/js/dom.js | 4 +- ftd/t/js/54-class-fix.ftd | 10 ++++ ftd/t/js/54-class-fix.html | 93 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 ftd/t/js/54-class-fix.ftd create mode 100644 ftd/t/js/54-class-fix.html diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index 38242faf23..9f205471bb 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -872,7 +872,7 @@ class Node2 { attachCss(property, value, createClass, className) { let propertyShort = fastn_dom.propertyMap[property] || property; propertyShort = `__${propertyShort}`; - let cls = `${propertyShort}-${JSON.stringify(value)}`; + let cls = `${propertyShort}-${JSON.stringify(fastn_dom.class_count)}`; if (!!className) { cls = className; } else { @@ -1236,7 +1236,7 @@ class Node2 { this.attachCss("align-items", "end"); break; case 'bottom-center': - this.attachCss("justify-content", "start"); + this.attachCss("justify-content", "center"); this.attachCss("align-items", "end"); break; case 'bottom-right': diff --git a/ftd/t/js/54-class-fix.ftd b/ftd/t/js/54-class-fix.ftd new file mode 100644 index 0000000000..c86a68bba9 --- /dev/null +++ b/ftd/t/js/54-class-fix.ftd @@ -0,0 +1,10 @@ +-- ftd.text: Hello +background.solid: $bg-yg + +-- ftd.text: hello +background.solid: yellow + + +-- ftd.color bg-yg: +light: yellow +dark: green diff --git a/ftd/t/js/54-class-fix.html b/ftd/t/js/54-class-fix.html new file mode 100644 index 0000000000..36b2d923e1 --- /dev/null +++ b/ftd/t/js/54-class-fix.html @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + +
Hello
hello
+ + From 821eea9af66f055c75cd165cbfeea7717644be66 Mon Sep 17 00:00:00 2001 From: heulitig Date: Mon, 11 Sep 2023 11:12:56 +0530 Subject: [PATCH 12/19] js tests fixed --- ftd/t/js/01-basic-module.html | 22 +- ftd/t/js/02-property.html | 10 +- ftd/t/js/03-common-properties.html | 732 ++++++++++++++----- ftd/t/js/04-variable.html | 4 +- ftd/t/js/05-dynamic-dom-list.html | 3 +- ftd/t/js/06-dynamic-dom-list-2.html | 3 +- ftd/t/js/08-inherited.html | 37 +- ftd/t/js/09-text-properties.html | 88 ++- ftd/t/js/10-color-test.html | 23 +- ftd/t/js/12-children.html | 5 +- ftd/t/js/13-non-style-properties.html | 24 +- ftd/t/js/14-code.html | 9 +- ftd/t/js/17-clone.html | 10 +- ftd/t/js/18-rive.html | 9 +- ftd/t/js/20-background-properties.html | 43 +- ftd/t/js/23-record-list.html | 8 +- ftd/t/js/24-device.html | 3 +- ftd/t/js/29-dom-list.html | 7 +- ftd/t/js/30-web-component.html | 89 ++- ftd/t/js/31-advance-list.html | 34 +- ftd/t/js/31-ftd-len.html | 5 +- ftd/t/js/32-ftd-len.html | 32 +- ftd/t/js/33-list-indexing.html | 6 +- ftd/t/js/36-single-ui.html | 3 +- ftd/t/js/37-expander.html | 42 +- ftd/t/js/38-background-image-properties.html | 11 +- ftd/t/js/40-code-themes.html | 13 +- ftd/t/js/43-image-object-fit.html | 31 +- ftd/t/js/44-local-storage.html | 3 +- ftd/t/js/44-module.html | 7 +- ftd/t/js/45-re-module.html | 7 +- ftd/t/js/47-ftd-code-syntax.html | 9 +- ftd/t/js/49-align-content.html | 251 ++++++- ftd/t/js/50-iframe-fullscreen.html | 15 +- ftd/t/js/51-markdown-table.html | 13 +- 35 files changed, 1181 insertions(+), 430 deletions(-) diff --git a/ftd/t/js/01-basic-module.html b/ftd/t/js/01-basic-module.html index c2f051f5af..9501b33469 100644 --- a/ftd/t/js/01-basic-module.html +++ b/ftd/t/js/01-basic-module.html @@ -16,20 +16,20 @@ -
fastn
Hello
Hello
+ + + + + + +
this is a `<title>`
+ + From 8e8ee9a2c08c4149ccb0e2678092e0bc2be44ee5 Mon Sep 17 00:00:00 2001 From: Rithik Seth <106665190+Heulitig@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:10:06 +0530 Subject: [PATCH 16/19] rive script fixes (#1297) * rive script fixes * debugs removed * removed other debugs --- ftd/src/js/mod.rs | 16 +++++++++++++--- ftd/src/js/utils.rs | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/ftd/src/js/mod.rs b/ftd/src/js/mod.rs index 473acebb8c..19b2b2711b 100644 --- a/ftd/src/js/mod.rs +++ b/ftd/src/js/mod.rs @@ -417,8 +417,15 @@ impl ftd::interpreter::Component { has_rive_components, ) { kernel_component_statements - } else if let Some(defined_component_statements) = - self.defined_component_to_component_statements(parent, index, doc, rdata, should_return) + } else if let Some(defined_component_statements) = self + .defined_component_to_component_statements( + parent, + index, + doc, + rdata, + should_return, + has_rive_components, + ) { defined_component_statements } else if let Some(header_defined_component_statements) = self @@ -459,7 +466,7 @@ impl ftd::interpreter::Component { ) -> Option> { if ftd::js::element::is_kernel(self.name.as_str()) { if !*has_rive_components { - *has_rive_components = ftd::js::element::is_rive_component(self.name.as_str()) + *has_rive_components = ftd::js::element::is_rive_component(self.name.as_str()); } Some( ftd::js::Element::from_interpreter_component(self, doc).to_component_statements( @@ -483,6 +490,7 @@ impl ftd::interpreter::Component { doc: &ftd::interpreter::TDoc, rdata: &ftd::js::ResolverData, should_return: bool, + has_rive_components: &mut bool, ) -> Option> { if let Some(arguments) = ftd::js::utils::get_set_property_values_for_provided_component_properties( @@ -491,6 +499,7 @@ impl ftd::interpreter::Component { self.name.as_str(), self.properties.as_slice(), self.line_number, + has_rive_components, ) { let mut component_statements = vec![]; @@ -563,6 +572,7 @@ impl ftd::interpreter::Component { component_name.as_str(), self.properties.as_slice(), self.line_number, + has_rive_components, )?; } else if !ftd::js::utils::is_ui_argument( component.arguments.as_slice(), diff --git a/ftd/src/js/utils.rs b/ftd/src/js/utils.rs index 150aa75fce..8ce8d7eb6f 100644 --- a/ftd/src/js/utils.rs +++ b/ftd/src/js/utils.rs @@ -256,6 +256,7 @@ pub(crate) fn get_set_property_values_for_provided_component_properties( component_name: &str, component_properties: &[ftd::interpreter::Property], line_number: usize, + has_rive_components: &mut bool, ) -> Option> { use itertools::Itertools; @@ -270,8 +271,17 @@ pub(crate) fn get_set_property_values_for_provided_component_properties( arguments .iter() .filter_map(|v| { - v.get_optional_value(component_properties) - .map(|val| (v.name.to_string(), val.to_set_property_value(doc, rdata))) + v.get_optional_value(component_properties).map(|val| { + ( + v.name.to_string(), + val.to_set_property_value_with_ui( + doc, + rdata, + has_rive_components, + false, + ), + ) + }) }) .collect_vec() }) From 6be9e6b44db8af2fc97b0602c1eb4f2217f1e607 Mon Sep 17 00:00:00 2001 From: Rithik Seth <106665190+Heulitig@users.noreply.github.com> Date: Mon, 11 Sep 2023 19:18:30 +0530 Subject: [PATCH 17/19] bump version -> 0.3.50 (#1298) --- Cargo.lock | 2 +- fastn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c933a53b1..c28e4704a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "fastn" -version = "0.3.49" +version = "0.3.50" dependencies = [ "clap", "colored", diff --git a/fastn/Cargo.toml b/fastn/Cargo.toml index 3f2ba5399f..a2986d8e16 100644 --- a/fastn/Cargo.toml +++ b/fastn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastn" -version = "0.3.49" +version = "0.3.50" authors.workspace = true edition.workspace = true license.workspace = true From 3adcbb43c9f884acb8c10c1d9d84c63bb732d3bc Mon Sep 17 00:00:00 2001 From: Harsh Singh <64768386+harshdoesdev@users.noreply.github.com> Date: Tue, 12 Sep 2023 14:22:58 +0530 Subject: [PATCH 18/19] `ftd.code` theme change fixed (#1299) * code theme change fix * get static value if mutable * check if theme is not null * minor fix --- fastn-js/js/dom.js | 24 +++++--- ftd/t/js/57-code-dark-mode.ftd | 15 +++++ ftd/t/js/57-code-dark-mode.html | 103 ++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 8 deletions(-) create mode 100644 ftd/t/js/57-code-dark-mode.ftd create mode 100644 ftd/t/js/57-code-dark-mode.html diff --git a/fastn-js/js/dom.js b/fastn-js/js/dom.js index 8b211f8970..f4cd033ef8 100644 --- a/fastn-js/js/dom.js +++ b/fastn-js/js/dom.js @@ -1768,19 +1768,27 @@ class Node2 { this.#node.classList.remove("line-numbers"); } } else if (kind === fastn_dom.PropertyKind.CodeTheme) { + this.#extraData.code = this.#extraData.code ? this.#extraData.code : {}; + if(fastn_utils.isNull(staticValue)) { + if(!fastn_utils.isNull(this.#extraData.code.theme)) { + this.#node.classList.remove(this.#extraData.code.theme); + } + return; + } if (!ssr) { fastn_utils.addCodeTheme(staticValue); } + staticValue = fastn_utils.getStaticValue(staticValue); let theme = staticValue.replace("\.", "-"); - this.#extraData.code = this.#extraData.code ? this.#extraData.code : {}; - if (this.#extraData.code.theme) { - this.#node.classList.remove(theme); + if (this.#extraData.code.theme !== theme) { + let codeNode = this.#children[0].getNode(); + this.#node.classList.remove(this.#extraData.code.theme); + codeNode.classList.remove(this.#extraData.code.theme); + this.#extraData.code.theme = theme; + this.#node.classList.add(theme); + codeNode.classList.add(theme); + fastn_utils.highlightCode(codeNode, this.#extraData.code); } - this.#extraData.code.theme = theme; - this.#node.classList.add(theme); - let codeNode = this.#children[0].getNode(); - codeNode.classList.add(theme); - fastn_utils.highlightCode(codeNode, this.#extraData.code); } else if (kind === fastn_dom.PropertyKind.CodeLanguage) { let language = `language-${staticValue}`; this.#extraData.code = this.#extraData.code ? this.#extraData.code : {}; diff --git a/ftd/t/js/57-code-dark-mode.ftd b/ftd/t/js/57-code-dark-mode.ftd new file mode 100644 index 0000000000..b0025b8672 --- /dev/null +++ b/ftd/t/js/57-code-dark-mode.ftd @@ -0,0 +1,15 @@ +-- ftd.code: +lang: ftd +role: $inherited.types.copy-small +theme: fastn-theme.light +theme if { ftd.dark-mode }: fastn-theme.dark + +\-- ftd.column: +padding.px: 10 ;; +spacing.fixed.px: "50" +height.fixed.px: 200 +width.fixed.px: 300 ;; +overflow-y: scroll +border-color: $red-yellow +border-style: solid +border-width.px: 2 diff --git a/ftd/t/js/57-code-dark-mode.html b/ftd/t/js/57-code-dark-mode.html new file mode 100644 index 0000000000..e4a62abc00 --- /dev/null +++ b/ftd/t/js/57-code-dark-mode.html @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + +
-- ftd.column:
+padding.px: 10 
+spacing.fixed.px: "50"
+height.fixed.px: 200
+width.fixed.px: 300 
+overflow-y: scroll
+border-color: $red-yellow
+border-style: solid
+border-width.px: 2
+
+ + From b0e4392e891efd6362d6d275575dcac4aef3d291 Mon Sep 17 00:00:00 2001 From: heulitig Date: Tue, 12 Sep 2023 14:24:27 +0530 Subject: [PATCH 19/19] bump version -> 0.3.51 --- Cargo.lock | 2 +- fastn/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c28e4704a7..309607ea08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "fastn" -version = "0.3.50" +version = "0.3.51" dependencies = [ "clap", "colored", diff --git a/fastn/Cargo.toml b/fastn/Cargo.toml index a2986d8e16..b2486b0765 100644 --- a/fastn/Cargo.toml +++ b/fastn/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fastn" -version = "0.3.50" +version = "0.3.51" authors.workspace = true edition.workspace = true license.workspace = true