Skip to content

Commit b58f203

Browse files
authored
Merge pull request #24 from dev-five-git/maintain-properties
Add maintain properies
2 parents 2a8877e + 236882c commit b58f203

File tree

11 files changed

+381
-237
lines changed

11 files changed

+381
-237
lines changed

.changeset/long-beds-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Add maintain properies

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/devup-ui-wasm/src/lib.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use extractor::{extract, ExtractOption, ExtractStyleValue, StyleProperty};
1+
use extractor::extract_style::ExtractStyleValue;
2+
use extractor::{extract, ExtractOption, StyleProperty};
23
use js_sys::{Object, Reflect};
34
use once_cell::sync::Lazy;
45
use sheet::theme::{ColorTheme, Theme, Typography};
@@ -45,22 +46,22 @@ impl Output {
4546
match style {
4647
ExtractStyleValue::Static(st) => {
4748
if sheet.add_property(
48-
cls,
49-
st.property.clone(),
50-
st.level,
51-
st.value.clone(),
52-
st.selector.clone(),
49+
&cls,
50+
st.property(),
51+
st.level(),
52+
st.value(),
53+
st.selector(),
5354
) {
5455
collected = true;
5556
}
5657
}
5758
ExtractStyleValue::Dynamic(dy) => {
5859
if sheet.add_property(
59-
cls,
60-
dy.property.clone(),
61-
dy.level,
62-
format!("var({})", variable.unwrap()),
63-
dy.selector.clone(),
60+
&cls,
61+
dy.property(),
62+
dy.level(),
63+
&format!("var({})", variable.unwrap()),
64+
dy.selector(),
6465
) {
6566
collected = true;
6667
}

libs/extractor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ oxc_allocator = "0.46.0"
1111
oxc_ast = "0.46.0"
1212
oxc_codegen = "0.46.0"
1313
css = { path = "../css" }
14+
once_cell = "1.20.2"
1415

1516
[dev-dependencies]
1617
insta = "1.42.0"

libs/extractor/src/component.rs

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use crate::ExtractStyleValue::Static;
2-
use crate::{ExtractStaticStyle, ExtractStyleValue};
1+
use crate::extract_style::ExtractStaticStyle;
2+
use crate::extract_style::ExtractStyleValue::Static;
3+
use crate::ExtractStyleValue;
34

45
/// devup-ui export variable kind
56
#[derive(Debug, PartialEq, Clone)]
@@ -40,56 +41,56 @@ impl ExportVariableKind {
4041
| ExportVariableKind::Text
4142
| ExportVariableKind::Image
4243
| ExportVariableKind::Box => vec![],
43-
ExportVariableKind::Flex => vec![Static(ExtractStaticStyle {
44-
value: "flex".to_string(),
45-
property: "display".to_string(),
46-
level: 0,
47-
selector: None,
48-
})],
44+
ExportVariableKind::Flex => vec![Static(ExtractStaticStyle::new(
45+
"display".to_string(),
46+
"flex".to_string(),
47+
0,
48+
None,
49+
))],
4950
ExportVariableKind::VStack => {
5051
vec![
51-
Static(ExtractStaticStyle {
52-
value: "flex".to_string(),
53-
property: "display".to_string(),
54-
level: 0,
55-
selector: None,
56-
}),
57-
Static(ExtractStaticStyle {
58-
value: "column".to_string(),
59-
property: "flexDirection".to_string(),
60-
level: 0,
61-
selector: None,
62-
}),
52+
Static(ExtractStaticStyle::new(
53+
"display".to_string(),
54+
"flex".to_string(),
55+
0,
56+
None,
57+
)),
58+
Static(ExtractStaticStyle::new(
59+
"flexDirection".to_string(),
60+
"column".to_string(),
61+
0,
62+
None,
63+
)),
6364
]
6465
}
6566
ExportVariableKind::Center => {
6667
vec![
67-
Static(ExtractStaticStyle {
68-
value: "flex".to_string(),
69-
property: "display".to_string(),
70-
level: 0,
71-
selector: None,
72-
}),
73-
Static(ExtractStaticStyle {
74-
value: "center".to_string(),
75-
property: "justifyContent".to_string(),
76-
level: 0,
77-
selector: None,
78-
}),
79-
Static(ExtractStaticStyle {
80-
value: "center".to_string(),
81-
property: "alignItems".to_string(),
82-
level: 0,
83-
selector: None,
84-
}),
68+
Static(ExtractStaticStyle::new(
69+
"display".to_string(),
70+
"flex".to_string(),
71+
0,
72+
None,
73+
)),
74+
Static(ExtractStaticStyle::new(
75+
"justifyContent".to_string(),
76+
"center".to_string(),
77+
0,
78+
None,
79+
)),
80+
Static(ExtractStaticStyle::new(
81+
"alignItems".to_string(),
82+
"center".to_string(),
83+
0,
84+
None,
85+
)),
8586
]
8687
}
87-
ExportVariableKind::Grid => vec![Static(ExtractStaticStyle {
88-
value: "grid".to_string(),
89-
property: "display".to_string(),
90-
level: 0,
91-
selector: None,
92-
})],
88+
ExportVariableKind::Grid => vec![Static(ExtractStaticStyle::new(
89+
"display".to_string(),
90+
"grid".to_string(),
91+
0,
92+
None,
93+
))],
9394
}
9495
}
9596
}
@@ -181,61 +182,61 @@ mod tests {
181182
assert_eq!(ExportVariableKind::Input.extract(), vec![]);
182183
assert_eq!(
183184
ExportVariableKind::Flex.extract(),
184-
vec![Static(ExtractStaticStyle {
185-
value: "flex".to_string(),
186-
property: "display".to_string(),
187-
level: 0,
188-
selector: None,
189-
})]
185+
vec![Static(ExtractStaticStyle::new(
186+
"display".to_string(),
187+
"flex".to_string(),
188+
0,
189+
None,
190+
))]
190191
);
191192
assert_eq!(
192193
ExportVariableKind::VStack.extract(),
193194
vec![
194-
Static(ExtractStaticStyle {
195-
value: "flex".to_string(),
196-
property: "display".to_string(),
197-
level: 0,
198-
selector: None,
199-
}),
200-
Static(ExtractStaticStyle {
201-
value: "column".to_string(),
202-
property: "flexDirection".to_string(),
203-
level: 0,
204-
selector: None,
205-
})
195+
Static(ExtractStaticStyle::new(
196+
"display".to_string(),
197+
"flex".to_string(),
198+
0,
199+
None,
200+
)),
201+
Static(ExtractStaticStyle::new(
202+
"flexDirection".to_string(),
203+
"column".to_string(),
204+
0,
205+
None,
206+
))
206207
]
207208
);
208209
assert_eq!(
209210
ExportVariableKind::Center.extract(),
210211
vec![
211-
Static(ExtractStaticStyle {
212-
value: "flex".to_string(),
213-
property: "display".to_string(),
214-
level: 0,
215-
selector: None,
216-
}),
217-
Static(ExtractStaticStyle {
218-
value: "center".to_string(),
219-
property: "justifyContent".to_string(),
220-
level: 0,
221-
selector: None,
222-
}),
223-
Static(ExtractStaticStyle {
224-
value: "center".to_string(),
225-
property: "alignItems".to_string(),
226-
level: 0,
227-
selector: None,
228-
})
212+
Static(ExtractStaticStyle::new(
213+
"display".to_string(),
214+
"flex".to_string(),
215+
0,
216+
None,
217+
)),
218+
Static(ExtractStaticStyle::new(
219+
"justifyContent".to_string(),
220+
"center".to_string(),
221+
0,
222+
None,
223+
)),
224+
Static(ExtractStaticStyle::new(
225+
"alignItems".to_string(),
226+
"center".to_string(),
227+
0,
228+
None,
229+
))
229230
]
230231
);
231232
assert_eq!(
232233
ExportVariableKind::Grid.extract(),
233-
vec![Static(ExtractStaticStyle {
234-
value: "grid".to_string(),
235-
property: "display".to_string(),
236-
level: 0,
237-
selector: None,
238-
})]
234+
vec![Static(ExtractStaticStyle::new(
235+
"display".to_string(),
236+
"grid".to_string(),
237+
0,
238+
None,
239+
))]
239240
);
240241
}
241242
}

0 commit comments

Comments
 (0)