Skip to content

Commit 8a1dfb9

Browse files
authored
Refactor messages.ts by removing class-transformer and JS classes (#3858)
* Fix gamma correction with HTML-based editable Text tool text * Migrate simple, undecorated classes to types * Remove TupleToVec2 transformation * Remove @Transform from tooltips * Cleanup: replace value.toString() with String(value) everywhere * Convert documentId from string to bigint * Migrate the rest of the easy @Transform/@type decorations * Migrate FillChoice * Migrate WidgetDiffUpdate * Migrate WidgetInstance * Migrate away from classes that extend WidgetProps * Remove class-transformer and all classes in messages.ts * Migrate UI layout passing * Remove dead code * Remove unnecessary export and readonly prefixes * Remove HSVA type * Break out Color, Gradient, and FillChoice functions into a utility-functions file * Move widget helper functions from messages.ts into a new utility-functions file; restructure type imports * Reduce internal type defs * Rename JsMessage to FrontendMessage * Code review fixes * Fix other usages * Tidying up
1 parent f00a15a commit 8a1dfb9

Some content is hidden

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

64 files changed

+1443
-2100
lines changed

.github/workflows/comment-profiling-changes.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Profiling Changes
33
on:
44
pull_request:
55
paths:
6-
- 'node-graph/**'
7-
- 'Cargo.toml'
8-
- 'Cargo.lock'
6+
- "node-graph/**"
7+
- "Cargo.toml"
8+
- "Cargo.lock"
99

1010
env:
1111
CARGO_TERM_COLOR: always
@@ -200,7 +200,7 @@ jobs:
200200
let commentBody = "";
201201
202202
function formatNumber(num) {
203-
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
203+
return String(num).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
204204
}
205205
206206
function formatPercentage(pct) {

desktop/wrapper/src/intercept_frontend_message.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::path::PathBuf;
2-
1+
#[cfg(target_os = "macos")]
2+
use graphite_editor::messages::layout::utility_types::layout_widget::LayoutTarget;
33
use graphite_editor::messages::prelude::FrontendMessage;
4+
use std::path::PathBuf;
45

56
use super::DesktopWrapperMessageDispatcher;
67
use super::messages::{DesktopFrontendMessage, Document, FileFilter, OpenFileDialogContext, SaveFileDialogContext};
@@ -103,7 +104,10 @@ pub(super) fn intercept_frontend_message(dispatcher: &mut DesktopWrapperMessageD
103104
dispatcher.respond(DesktopFrontendMessage::PersistenceLoadPreferences);
104105
}
105106
#[cfg(target_os = "macos")]
106-
FrontendMessage::UpdateMenuBarLayout { diff } => {
107+
FrontendMessage::UpdateLayout {
108+
layout_target: LayoutTarget::MenuBar,
109+
diff,
110+
} => {
107111
use graphite_editor::messages::tool::tool_messages::tool_prelude::{DiffUpdate, WidgetDiff};
108112
match diff.as_slice() {
109113
[

editor/src/dispatcher.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,11 @@ mod test {
590590

591591
for response in responses {
592592
// Check for the existence of the file format incompatibility warning dialog after opening the test file
593-
if let FrontendMessage::UpdateDialogColumn1 { diff } = response {
593+
if let FrontendMessage::UpdateLayout {
594+
layout_target: LayoutTarget::DialogColumn1,
595+
diff,
596+
} = response
597+
{
594598
if let DiffUpdate::Layout(sub_layout) = &diff[0].new_value {
595599
if let LayoutGroup::Row { widgets } = &sub_layout.0[0] {
596600
if let Widget::TextLabel(TextLabel { value, .. }) = &*widgets[0].widget {

editor/src/messages/frontend/frontend_message.rs

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub enum FrontendMessage {
3939
line_height_ratio: f64,
4040
#[serde(rename = "fontSize")]
4141
font_size: f64,
42-
color: Color,
42+
color: String,
4343
#[serde(rename = "fontData")]
4444
font_data: Vec<u8>,
4545
transform: [f64; 6],
@@ -199,7 +199,9 @@ pub enum FrontendMessage {
199199
UpdateLayersPanelState {
200200
open: bool,
201201
},
202-
UpdateDataPanelLayout {
202+
UpdateLayout {
203+
#[serde(rename = "layoutTarget")]
204+
layout_target: LayoutTarget,
203205
diff: Vec<WidgetDiff>,
204206
},
205207
UpdateImportReorderIndex {
@@ -218,24 +220,12 @@ pub enum FrontendMessage {
218220
#[serde(rename = "hasLeftInputWire")]
219221
has_left_input_wire: HashMap<NodeId, bool>,
220222
},
221-
UpdateDialogButtons {
222-
diff: Vec<WidgetDiff>,
223-
},
224-
UpdateDialogColumn1 {
225-
diff: Vec<WidgetDiff>,
226-
},
227-
UpdateDialogColumn2 {
228-
diff: Vec<WidgetDiff>,
229-
},
230223
UpdateDocumentArtwork {
231224
svg: String,
232225
},
233226
UpdateImageData {
234227
image_data: Vec<(u64, Image<Color>)>,
235228
},
236-
UpdateDocumentBarLayout {
237-
diff: Vec<WidgetDiff>,
238-
},
239229
UpdateDocumentLayerDetails {
240230
data: LayerPanelEntry,
241231
},
@@ -268,18 +258,6 @@ pub enum FrontendMessage {
268258
UpdateGraphFadeArtwork {
269259
percentage: f64,
270260
},
271-
UpdateLayersPanelControlBarLeftLayout {
272-
diff: Vec<WidgetDiff>,
273-
},
274-
UpdateLayersPanelControlBarRightLayout {
275-
diff: Vec<WidgetDiff>,
276-
},
277-
UpdateLayersPanelBottomBarLayout {
278-
diff: Vec<WidgetDiff>,
279-
},
280-
UpdateMenuBarLayout {
281-
diff: Vec<WidgetDiff>,
282-
},
283261
UpdateMouseCursor {
284262
cursor: MouseCursorIcon,
285263
},
@@ -296,9 +274,6 @@ pub enum FrontendMessage {
296274
wires: Vec<WirePathUpdate>,
297275
},
298276
ClearAllNodeGraphWires,
299-
UpdateNodeGraphControlBarLayout {
300-
diff: Vec<WidgetDiff>,
301-
},
302277
UpdateNodeGraphSelection {
303278
selected: Vec<NodeId>,
304279
},
@@ -313,31 +288,10 @@ pub enum FrontendMessage {
313288
#[serde(rename = "openDocuments")]
314289
open_documents: Vec<OpenDocument>,
315290
},
316-
UpdatePropertiesPanelLayout {
317-
diff: Vec<WidgetDiff>,
318-
},
319-
UpdateToolOptionsLayout {
320-
diff: Vec<WidgetDiff>,
321-
},
322-
UpdateToolShelfLayout {
323-
diff: Vec<WidgetDiff>,
324-
},
325291
UpdateWirePathInProgress {
326292
#[serde(rename = "wirePath")]
327293
wire_path: Option<WirePath>,
328294
},
329-
UpdateWelcomeScreenButtonsLayout {
330-
diff: Vec<WidgetDiff>,
331-
},
332-
UpdateStatusBarHintsLayout {
333-
diff: Vec<WidgetDiff>,
334-
},
335-
UpdateStatusBarInfoLayout {
336-
diff: Vec<WidgetDiff>,
337-
},
338-
UpdateWorkingColorsLayout {
339-
diff: Vec<WidgetDiff>,
340-
},
341295
UpdatePlatform {
342296
platform: AppWindowPlatform,
343297
},

editor/src/messages/layout/layout_message_handler.rs

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -463,30 +463,11 @@ impl LayoutMessageHandler {
463463
fn send_diff(&self, mut diff: Vec<WidgetDiff>, layout_target: LayoutTarget, responses: &mut VecDeque<Message>, action_input_mapping: &impl Fn(&MessageDiscriminant) -> Option<KeysGroup>) {
464464
diff.iter_mut().for_each(|diff| diff.new_value.apply_keyboard_shortcut(action_input_mapping));
465465

466-
let message = match layout_target {
467-
LayoutTarget::DataPanel => FrontendMessage::UpdateDataPanelLayout { diff },
468-
LayoutTarget::DialogButtons => FrontendMessage::UpdateDialogButtons { diff },
469-
LayoutTarget::DialogColumn1 => FrontendMessage::UpdateDialogColumn1 { diff },
470-
LayoutTarget::DialogColumn2 => FrontendMessage::UpdateDialogColumn2 { diff },
471-
LayoutTarget::DocumentBar => FrontendMessage::UpdateDocumentBarLayout { diff },
472-
LayoutTarget::LayersPanelBottomBar => FrontendMessage::UpdateLayersPanelBottomBarLayout { diff },
473-
LayoutTarget::LayersPanelControlLeftBar => FrontendMessage::UpdateLayersPanelControlBarLeftLayout { diff },
474-
LayoutTarget::LayersPanelControlRightBar => FrontendMessage::UpdateLayersPanelControlBarRightLayout { diff },
475-
LayoutTarget::MenuBar => FrontendMessage::UpdateMenuBarLayout { diff },
476-
LayoutTarget::NodeGraphControlBar => FrontendMessage::UpdateNodeGraphControlBarLayout { diff },
477-
LayoutTarget::PropertiesPanel => FrontendMessage::UpdatePropertiesPanelLayout { diff },
478-
LayoutTarget::StatusBarHints => FrontendMessage::UpdateStatusBarHintsLayout { diff },
479-
LayoutTarget::StatusBarInfo => FrontendMessage::UpdateStatusBarInfoLayout { diff },
480-
LayoutTarget::ToolOptions => FrontendMessage::UpdateToolOptionsLayout { diff },
481-
LayoutTarget::ToolShelf => FrontendMessage::UpdateToolShelfLayout { diff },
482-
LayoutTarget::WelcomeScreenButtons => FrontendMessage::UpdateWelcomeScreenButtonsLayout { diff },
483-
LayoutTarget::WorkingColors => FrontendMessage::UpdateWorkingColorsLayout { diff },
484-
485-
// KEEP THIS ENUM LAST
486-
LayoutTarget::_LayoutTargetLength => panic!("`_LayoutTargetLength` is not a valid `LayoutTarget` and is used for array indexing"),
487-
};
466+
if matches!(layout_target, LayoutTarget::_LayoutTargetLength) {
467+
panic!("`_LayoutTargetLength` is not a valid `LayoutTarget` and is used for array indexing");
468+
}
488469

489-
responses.add(message);
470+
responses.add(FrontendMessage::UpdateLayout { layout_target, diff });
490471
}
491472
}
492473

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
847847
};
848848

849849
self.context_menu = Some(ContextMenuInformation {
850-
context_menu_coordinates: (node_graph_point + node_graph_shift).into(),
850+
context_menu_coordinates: (node_graph_point + node_graph_shift).as_ivec2(),
851851
context_menu_data,
852852
});
853853

@@ -1280,7 +1280,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
12801280
let compatible_type = network_interface.output_type(&output_connector, selection_network_path).add_node_string();
12811281

12821282
self.context_menu = Some(ContextMenuInformation {
1283-
context_menu_coordinates: (point + node_graph_shift).into(),
1283+
context_menu_coordinates: (point + node_graph_shift).as_ivec2(),
12841284
context_menu_data: ContextMenuData::CreateNode { compatible_type },
12851285
});
12861286

@@ -2696,7 +2696,7 @@ impl NodeGraphMessageHandler {
26962696
position += IVec2::new(12, -12)
26972697
}
26982698

2699-
Some(NodeGraphErrorDiagnostic { position: position.into(), error })
2699+
Some(NodeGraphErrorDiagnostic { position, error })
27002700
}
27012701

27022702
fn update_layer_panel(network_interface: &NodeNetworkInterface, selection_network_path: &[NodeId], collapsed: &CollapsedLayers, layers_panel_open: bool, responses: &mut VecDeque<Message>) {
@@ -2769,7 +2769,7 @@ impl NodeGraphMessageHandler {
27692769
children_allowed,
27702770
children_present: layer.has_children(network_interface.document_metadata()),
27712771
expanded: layer.has_children(network_interface.document_metadata()) && !collapsed.0.contains(&layer),
2772-
depth: layer.ancestors(network_interface.document_metadata()).count() - 1,
2772+
depth: layer.ancestors(network_interface.document_metadata()).count() as u32 - 1,
27732773
visible: network_interface.is_visible(&node_id, &[]),
27742774
parents_visible,
27752775
unlocked: !network_interface.is_locked(&node_id, &[]),

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use glam::{DVec2, IVec2};
1+
use glam::IVec2;
22
use graph_craft::document::NodeId;
33
use graph_craft::document::value::TaggedValue;
44
use graphene_std::Type;
@@ -162,14 +162,14 @@ pub enum ContextMenuData {
162162
pub struct ContextMenuInformation {
163163
// Stores whether the context menu is open and its position in graph coordinates
164164
#[serde(rename = "contextMenuCoordinates")]
165-
pub context_menu_coordinates: FrontendXY,
165+
pub context_menu_coordinates: IVec2,
166166
#[serde(rename = "contextMenuData")]
167167
pub context_menu_data: ContextMenuData,
168168
}
169169

170170
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize, specta::Type)]
171171
pub struct NodeGraphErrorDiagnostic {
172-
pub position: FrontendXY,
172+
pub position: IVec2,
173173
pub error: String,
174174
}
175175

@@ -196,22 +196,3 @@ pub enum Direction {
196196
Left,
197197
Right,
198198
}
199-
200-
/// Stores node graph coordinates which are then transformed in Svelte based on the node graph transform
201-
#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize, specta::Type)]
202-
pub struct FrontendXY {
203-
pub x: i32,
204-
pub y: i32,
205-
}
206-
207-
impl From<DVec2> for FrontendXY {
208-
fn from(v: DVec2) -> Self {
209-
FrontendXY { x: v.x as i32, y: v.y as i32 }
210-
}
211-
}
212-
213-
impl From<IVec2> for FrontendXY {
214-
fn from(v: IVec2) -> Self {
215-
FrontendXY { x: v.x, y: v.y }
216-
}
217-
}

editor/src/messages/portfolio/document/utility_types/nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct LayerPanelEntry {
2828
#[serde(rename = "childrenPresent")]
2929
pub children_present: bool,
3030
pub expanded: bool,
31-
pub depth: usize,
31+
pub depth: u32,
3232
pub visible: bool,
3333
#[serde(rename = "parentsVisible")]
3434
pub parents_visible: bool,

editor/src/messages/tool/tool_messages/text_tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl TextToolData {
412412
text: editing_text.text.clone(),
413413
line_height_ratio: editing_text.typesetting.line_height_ratio,
414414
font_size: editing_text.typesetting.font_size,
415-
color: editing_text.color.unwrap_or(Color::BLACK),
415+
color: editing_text.color.map_or("#000000".to_string(), |color| format!("#{}", color.to_rgba_hex_srgb())),
416416
font_data: font_cache.get(&editing_text.font).map(|(data, _)| data.clone()).unwrap_or_default(),
417417
transform: editing_text.transform.to_cols_array(),
418418
max_width: editing_text.typesetting.max_width,

frontend/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default defineConfig([
8787
"svelte/require-each-key": "off", // TODO: Remove this rule and fix the places where it's violated
8888

8989
// Import plugin config (for intelligently validating module import statements)
90+
"import/consistent-type-specifier-style": ["error", "prefer-top-level"],
9091
"import/no-unresolved": "error",
9192
// `no-duplicates` disabled due to <https://github.com/import-js/eslint-plugin-import/issues/1479#issuecomment-1789527447>. Reenable if that issue gets fixed.
9293
"import/no-duplicates": "off",

0 commit comments

Comments
 (0)