Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changepacks/changepack_log_0cJIQ-UBtwiXt8YhHyNj2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"changes": { "bindings/devup-ui-wasm/package.json": "Patch" },
"note": "Fix selector issue",
"date": "2025-11-19T07:56:23.681473700Z"
}
7 changes: 6 additions & 1 deletion libs/css/src/style_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ impl Ord for StyleSelector {
if c == Ordering::Equal { aa.cmp(bb) } else { c }
}
(StyleSelector::Selector(a), StyleSelector::Selector(b)) => {
get_selector_order(a).cmp(&get_selector_order(b))
let order_cmp = get_selector_order(a).cmp(&get_selector_order(b));
if order_cmp == Ordering::Equal {
a.cmp(b)
} else {
order_cmp
}
}
(
StyleSelector::Media {
Expand Down
78 changes: 37 additions & 41 deletions libs/extractor/src/extractor/extract_style_from_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,51 +197,47 @@ pub fn extract_style_from_expression<'a>(
}
}

let sel = part_of_selector
.iter()
.map(|name| {
if let Some(selector) = selector {
if name.starts_with("_") {
if name.starts_with("_theme") {
StyleSelector::from([
to_kebab_case(name.strip_prefix("_").unwrap_or(name))
.as_str(),
&selector.to_string(),
])
.to_string()
} else {
StyleSelector::from([
&selector.to_string(),
to_kebab_case(name.strip_prefix("_").unwrap_or(name))
.as_str(),
])
.to_string()
}
for sel in part_of_selector.iter().map(|name| {
if let Some(selector) = selector {
if name.starts_with("_") {
if name.starts_with("_theme") {
StyleSelector::from([
to_kebab_case(name.strip_prefix("_").unwrap_or(name))
.as_str(),
&selector.to_string(),
])
.to_string()
} else {
name.replace("&", &selector.to_string())
StyleSelector::from([
&selector.to_string(),
to_kebab_case(name.strip_prefix("_").unwrap_or(name))
.as_str(),
])
.to_string()
}
} else if name.starts_with("_") {
StyleSelector::from(
to_kebab_case(name.strip_prefix("_").unwrap_or(name)).as_str(),
)
.to_string()
} else {
StyleSelector::from(name.strip_prefix("_").unwrap_or(name))
.to_string()
name.replace("&", &selector.to_string())
}
})
.collect::<Vec<_>>()
.join(",");
props.extend(
extract_style_from_expression(
ast_builder,
None,
&mut o.value,
level,
&Some(StyleSelector::Selector(sel)),
)
.styles,
);
} else if name.starts_with("_") {
StyleSelector::from(
to_kebab_case(name.strip_prefix("_").unwrap_or(name)).as_str(),
)
.to_string()
} else {
StyleSelector::from(name.strip_prefix("_").unwrap_or(name)).to_string()
}
}) {
props.extend(
extract_style_from_expression(
ast_builder,
None,
&mut o.value,
level,
&Some(StyleSelector::Selector(sel)),
)
.styles,
);
}
}
}
return ExtractResult {
Expand Down
77 changes: 77 additions & 0 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,83 @@ import clsx from 'clsx'
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box selectors={{
"& .a, & .b": {
bg: "$primary"
}
}} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_dir: "@devup-ui/core".to_string(),
single_css: true,
import_main_css: false
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box selectors={{
".test-picker__day--keyboard-selected": {
_hover: {
bg: "$primary"
},
selectors: {
"&:active": {
bg: "$primary"
}
}
}
}} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_dir: "@devup-ui/core".to_string(),
single_css: true,
import_main_css: false
}
)
.unwrap()
));

reset_class_map();
assert_debug_snapshot!(ToBTreeSet::from(
extract(
"test.tsx",
r#"import {Box} from '@devup-ui/core'
<Box selectors={{
".a, .b": {
_hover: {
bg: "$primary"
},
selectors: {
"&:active": {
bg: "$secondary"
}
}
}
}} />
"#,
ExtractOption {
package: "@devup-ui/core".to_string(),
css_dir: "@devup-ui/core".to_string(),
single_css: true,
import_main_css: false
}
)
.unwrap()
));
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_active\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_active\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false\n}).unwrap())"
---
ToBTreeSet {
styles: {
Expand All @@ -11,12 +11,25 @@ ToBTreeSet {
level: 0,
selector: Some(
Selector(
":root[data-theme=dark] &:hover,&:hover:active",
":root[data-theme=dark] &:hover",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "color",
value: "red",
level: 0,
selector: Some(
Selector(
"&:hover:active",
),
),
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_placeholder\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"_themeDark,_placeholder\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false\n}).unwrap())"
---
ToBTreeSet {
styles: {
Expand All @@ -11,12 +11,25 @@ ToBTreeSet {
level: 0,
selector: Some(
Selector(
":root[data-theme=dark] &:hover,&:hover::placeholder",
":root[data-theme=dark] &:hover",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "color",
value: "red",
level: 0,
selector: Some(
Selector(
"&:hover::placeholder",
),
),
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box _hover={{\n selectors: {\n \"&::placeholder, &:active\": {\n color: \"blue\"\n }\n },\n }} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box _hover={{\n selectors: {\n \"&::placeholder, &:active\": {\n color: \"blue\"\n }\n },\n }} />\n \"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false\n}).unwrap())"
---
ToBTreeSet {
styles: {
Expand All @@ -11,12 +11,25 @@ ToBTreeSet {
level: 0,
selector: Some(
Selector(
"&:hover::placeholder,&:hover:active",
"&:hover::placeholder",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "color",
value: "blue",
level: 0,
selector: Some(
Selector(
"&:hover:active",
),
),
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box _hover={{\n selectors: {\n \"&::placeholder\": {\n color: \"red\"\n },\n \"&::placeholder, &:active\": {\n color: \"blue\"\n }\n },\n }} />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box _hover={{\n selectors: {\n \"&::placeholder\": {\n color: \"red\"\n },\n \"&::placeholder, &:active\": {\n color: \"blue\"\n }\n },\n }} />\n \"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false\n}).unwrap())"
---
ToBTreeSet {
styles: {
Expand All @@ -11,7 +11,20 @@ ToBTreeSet {
level: 0,
selector: Some(
Selector(
"&:hover::placeholder,&:hover:active",
"&:hover::placeholder",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "color",
value: "blue",
level: 0,
selector: Some(
Selector(
"&:hover:active",
),
),
style_order: None,
Expand All @@ -31,5 +44,5 @@ ToBTreeSet {
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b c\" />;\n",
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: libs/extractor/src/lib.rs
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"&:active, _hover\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap())"
expression: "ToBTreeSet::from(extract(\"test.tsx\",\nr#\"import {Box} from '@devup-ui/core'\n <Box \n selectors={{\n _hover: {\n selectors: {\n \"&:active, _hover\": {\n color: \"red\",\n }\n }\n }\n }}\n />\n \"#,\nExtractOption\n{\n package: \"@devup-ui/core\".to_string(), css_dir:\n \"@devup-ui/core\".to_string(), single_css: true, import_main_css: false\n}).unwrap())"
---
ToBTreeSet {
styles: {
Expand All @@ -11,12 +11,25 @@ ToBTreeSet {
level: 0,
selector: Some(
Selector(
"&:hover:active,&:hover:hover",
"&:hover:active",
),
),
style_order: None,
},
),
Static(
ExtractStaticStyle {
property: "color",
value: "red",
level: 0,
selector: Some(
Selector(
"&:hover:hover",
),
),
style_order: None,
},
),
},
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a\" />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className=\"a b\" />;\n",
}
Loading