Skip to content

Commit 40a9fb0

Browse files
authored
Refactor the TypeScript data flow for full type safety and auto-generation of Rust types (#3865)
* Migrate Specta to Tsify to auto-generate messages.ts, working except colors and widgets * Adopt the generated FillColor/Color/GradientStops * Fix widget typing * Separate WidgetGroup enum variants into wrapper structs * Small rename * Simplify widgets further * Clean up message type references * Switch type imports to the auto-generated file * Remove lowercase serde rename * Fix FillChoice deserialization * Fix small regression from #3837 * Improve type safety * Make WidgetSpan type-safe * More cleanup and type safety * More type safety * More type safety * Get the rest to type-check without errors; improve widget builder macro to have optional icons; improve Svelte 5 configs * Cargo fmt * Fix imports * Update outdated readme info * Fix lint command rename references * Fix typos * One more typos fix * Remove unnecessary dep: prefix from the edited Cargo.toml files * Remove excess parts from Cargo.toml * Fix compiling on desktop * Revert "Remove excess parts from Cargo.toml" This reverts commit 6b71111. * Update dev docs with simpler, more accurate instructions
1 parent fbd2658 commit 40a9fb0

File tree

199 files changed

+2253
-2799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+2253
-2799
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ jobs:
117117
NODE_ENV: production
118118
run: |
119119
cd frontend
120-
npm run lint
120+
npm run check
121121
122122
# Run the Rust tests on the self-hosted native runner
123123
test:

.github/workflows/website.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
run: |
9595
cd website
9696
npm ci
97-
npm run lint
97+
npm run check
9898
zola --config config.toml build --minify
9999
100100
- name: 📤 Publish to Cloudflare Pages

.vscode/settings.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,12 @@
3939
"rust-analyzer.check.command": "clippy",
4040
"rust-analyzer.cargo.allTargets": false,
4141
"rust-analyzer.procMacro.ignored": {
42-
"serde_derive": ["Serialize", "Deserialize"],
43-
"specta_macros": ["Type"] // Disabled because of: https://github.com/specta-rs/specta/issues/387
42+
"serde_derive": ["Serialize", "Deserialize"]
4443
},
4544
// ESLint config
4645
"eslint.format.enable": true,
4746
"eslint.workingDirectories": ["./frontend", "./website"],
4847
"eslint.validate": ["javascript", "typescript", "svelte"],
49-
// Svelte config
50-
"svelte.plugin.svelte.compilerWarnings": {
51-
"css-unused-selector": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
52-
"vite-plugin-svelte-css-no-scopable-elements": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
53-
"a11y-no-static-element-interactions": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
54-
"a11y-no-noninteractive-element-interactions": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
55-
"a11y-click-events-have-key-events": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
56-
"a11y_consider_explicit_label": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
57-
"a11y_click_events_have_key_events": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
58-
"a11y_no_noninteractive_element_interactions": "ignore", // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
59-
"a11y_no_static_element_interactions": "ignore" // NOTICE: Keep this list in sync with the list in `frontend/vite.config.ts`
60-
},
6148
// Git Graph config
6249
"git-graph.repository.fetchAndPrune": true,
6350
"git-graph.repository.showRemoteHeads": false,

Cargo.lock

Lines changed: 67 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ rustc-hash = "2.0"
9898
bytemuck = { version = "1.13", features = ["derive", "min_const_generics"] }
9999
serde = { version = "1.0", features = ["derive", "rc"] }
100100
serde_json = "1.0"
101+
serde_bytes = "0.11"
101102
serde-wasm-bindgen = "0.6"
102103
reqwest = { version = "0.13", features = ["blocking", "json"] }
103104
futures = "0.3"
@@ -176,11 +177,7 @@ fern = { version = "0.7", features = ["colored"] }
176177
num_enum = { version = "0.7", default-features = false }
177178
num-derive = "0.4"
178179
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
179-
specta = { version = "2.0.0-rc.22", features = [
180-
"glam",
181-
"derive",
182-
# "typescript",
183-
] }
180+
tsify = { version = "0.5", default-features = false, features = ["js"] }
184181
syn = { version = "2.0", default-features = false, features = [
185182
"full",
186183
"derive",
@@ -230,7 +227,6 @@ graphite-proc-macros = { opt-level = 1 }
230227
image = { opt-level = 2 }
231228
rustc-hash = { opt-level = 3 }
232229
serde_derive = { opt-level = 1 }
233-
specta-macros = { opt-level = 1 }
234230
syn = { opt-level = 1 }
235231
node-macro = { opt-level = 2 }
236232

deny.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ allow-git = []
183183

184184
[sources.allow-org]
185185
# 1 or more github.com organizations to allow git sources for
186-
github = ["linebender", "Rust-GPU", "specta-rs"]
186+
github = ["linebender", "Rust-GPU"]
187187
# 1 or more gitlab.com organizations to allow git sources for
188188
#gitlab = [""]
189189
# 1 or more bitbucket.org organizations to allow git sources for

desktop/wrapper/src/intercept_frontend_message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
2626
});
2727
}
2828
FrontendMessage::TriggerSaveDocument { document_id, name, path, content } => {
29+
let content = content.into_vec();
2930
if let Some(path) = path {
3031
dispatcher.respond(DesktopFrontendMessage::WriteFile { path, content });
3132
} else {
@@ -42,6 +43,7 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
4243
}
4344
}
4445
FrontendMessage::TriggerSaveFile { name, content } => {
46+
let content = content.into_vec();
4547
dispatcher.respond(DesktopFrontendMessage::SaveFileDialog {
4648
title: "Save File".to_string(),
4749
default_filename: name,

desktop/wrapper/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) mod menu {
1515
[layout_group] => layout_group,
1616
_ => panic!("Menu bar layout is supposed to have exactly one layout group"),
1717
};
18-
let LayoutGroup::Row { widgets } = layout_group else {
18+
let LayoutGroup::Row(WidgetRow { widgets }) = layout_group else {
1919
panic!("Menu bar layout group is supposed to be a row");
2020
};
2121
widgets

editor/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ log = { workspace = true }
2929
bitflags = { workspace = true }
3030
thiserror = { workspace = true }
3131
serde = { workspace = true }
32+
serde_bytes = { workspace = true }
3233
serde_json = { workspace = true }
3334
kurbo = { workspace = true }
3435
futures = { workspace = true }
3536
glam = { workspace = true }
3637
derivative = { workspace = true }
37-
specta = { workspace = true }
38+
tsify = { workspace = true }
3839
dyn-any = { workspace = true }
3940
num_enum = { workspace = true }
4041
usvg = { workspace = true }

editor/src/dispatcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ mod test {
596596
} = response
597597
{
598598
if let DiffUpdate::Layout(sub_layout) = &diff[0].new_value {
599-
if let LayoutGroup::Row { widgets } = &sub_layout.0[0] {
599+
if let LayoutGroup::Row(WidgetRow { widgets }) = &sub_layout.0[0] {
600600
if let Widget::TextLabel(TextLabel { value, .. }) = &*widgets[0].widget {
601601
print_problem_to_terminal_on_failure(value);
602602
}

0 commit comments

Comments
 (0)