Add node introspection API

Closes #1110

Test Plan: query the introspectNode Endpoint from js

Reviewers: 

Pull Request: https://github.com/GraphiteEditor/Graphite/pull/1183
This commit is contained in:
Dennis Kobert 2023-04-28 00:20:39 +02:00 committed by Keavon Chambers
parent 0af42ee6f9
commit bea7cc8dd0
6 changed files with 48 additions and 5 deletions

View file

@ -697,6 +697,25 @@ impl JsEditorHandle {
let message = DocumentMessage::ToggleLayerExpansion { layer_path };
self.dispatch(message);
}
/// Returns the string representation of the nodes contents
#[wasm_bindgen(js_name = introspectNode)]
pub fn introspect_node(&self, node_path: Vec<NodeId>) -> Option<String> {
let frontend_messages = EDITOR_INSTANCES.with(|instances| {
// Mutably borrow the editors, and if successful, we can access them in the closure
instances.try_borrow_mut().map(|mut editors| {
// Get the editor instance for this editor ID, then dispatch the message to the backend, and return its response `FrontendMessage` queue
editors
.get_mut(&self.editor_id)
.expect("EDITOR_INSTANCES does not contain the current editor_id")
.dispatcher
.message_handlers
.portfolio_message_handler
.introspect_node(&node_path)
})
});
frontend_messages.unwrap()
}
}
// Needed to make JsEditorHandle functions pub to Rust.