Skip to content

Commit

Permalink
selectable property added (#1380)
Browse files Browse the repository at this point in the history
* selectable property added

* minor fix

* formatting
  • Loading branch information
harshdoesdev authored Oct 13, 2023
1 parent bf7f72b commit a1777ff
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fastn-js/js/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ fastn_dom.PropertyKind = {
Muted: 115,
LinkColor: 116,
TextShadow: 117,
Selectable: 118,
};


Expand Down Expand Up @@ -1560,6 +1561,12 @@ class Node2 {
// overflow: auto, resize: staticValue
this.attachCss("resize", staticValue);
this.attachCss("overflow", "auto");
} else if (kind === fastn_dom.PropertyKind.Selectable) {
if(staticValue === false) {
this.attachCss("user-select", "none");
} else {
this.attachCss("user-select", null);
}
} else if (kind === fastn_dom.PropertyKind.MinHeight) {
this.attachCss("min-height", staticValue);
} else if (kind === fastn_dom.PropertyKind.MaxHeight) {
Expand Down
2 changes: 2 additions & 0 deletions fastn-js/src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ pub enum PropertyKind {
MetaTwitterImage,
MetaThemeColor,
Favicon,
Selectable,
}

impl PropertyKind {
Expand Down Expand Up @@ -562,6 +563,7 @@ impl PropertyKind {
"fastn_dom.PropertyKind.DocumentProperties.MetaThemeColor"
}
PropertyKind::Favicon => "fastn_dom.PropertyKind.Favicon",
PropertyKind::Selectable => "fastn_dom.PropertyKind.Selectable",
}
}
}
6 changes: 6 additions & 0 deletions ftd/src/interpreter/things/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10725,6 +10725,12 @@ fn common_arguments() -> Vec<ftd::interpreter::Argument> {
.into_optional()
.into_kind_data(),
),
ftd::interpreter::Argument::default(
"selectable",
ftd::interpreter::Kind::boolean()
.into_optional()
.into_kind_data(),
),
]
}

Expand Down
12 changes: 12 additions & 0 deletions ftd/src/js/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,7 @@ pub struct Common {
pub css: Option<ftd::js::Value>,
pub js: Option<ftd::js::Value>,
pub events: Vec<ftd::interpreter::Event>,
pub selectable: Option<ftd::js::Value>,
}

impl Common {
Expand Down Expand Up @@ -2423,6 +2424,7 @@ impl Common {
whitespace: ftd::js::value::get_optional_js_value("white-space", properties, arguments),
shadow: ftd::js::value::get_optional_js_value("shadow", properties, arguments),
events: events.to_vec(),
selectable: ftd::js::value::get_optional_js_value("selectable", properties, arguments),
}
}

Expand Down Expand Up @@ -3009,6 +3011,16 @@ impl Common {
),
));
}
if let Some(ref selectable) = self.selectable {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
selectable.to_set_property(
fastn_js::PropertyKind::Selectable,
doc,
element_name,
rdata,
),
));
}
component_statements
}
}
Expand Down
4 changes: 4 additions & 0 deletions ftd/t/js/64-selectable.ftd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- ftd.text: You can select this value

-- ftd.text: You cannot select this value
selectable: false
83 changes: 83 additions & 0 deletions ftd/t/js/64-selectable.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a1777ff

Please sign in to comment.