Renderer-agnostic dispatcher for editor↔processor JSON messages.
More...
#include <editor_bridge.hpp>
|
| using | Handler = std::function<std::string(const choc::value::ValueView& payload)> |
| | Handler signature.
|
|
| static float | get_float (const choc::value::ValueView &v, const char *key, float dflt) noexcept |
| static std::size_t | get_uint (const choc::value::ValueView &v, const char *key, std::size_t dflt) noexcept |
| static std::string | get_string (const choc::value::ValueView &v, const char *key) noexcept |
| static std::string | ok_response () noexcept |
| | {"ok":true}.
|
| static std::string | ok_response (const choc::value::ValueView &extras) noexcept |
| | {"ok":true, ...members of extras merged in}.
|
| static std::string | err_response (std::string_view msg) noexcept |
| | {"ok":false,"error":"<msg>"}.
|
Renderer-agnostic dispatcher for editor↔processor JSON messages.
Typical usage from a plugin editor:
pulp::view::EditorBridge bridge; bridge.add_handler("paint_start", [this](const auto&) { drag_snap_ = BandSnapshot::capture(field_); return pulp::view::EditorBridge::ok_response(); }); bridge.add_handler("morph", [this](const auto& payload) { const auto t = std::clamp( pulp::view::EditorBridge::get_float(payload, "t", 0.0f), 0.0f, 1.0f); apply_morph_to_live(t); return pulp::view::EditorBridge::ok_response(); }); bridge.attach_webview(*panel_);
◆ Handler
Handler signature.
Receives the parsed payload (or an empty object if the envelope had no payload). Returns the full JSON response envelope to send back to the editor. Use the static ok_response / err_response helpers to build it.
◆ EditorBridge() [1/3]
| pulp::view::EditorBridge::EditorBridge |
( |
| ) |
|
◆ ~EditorBridge()
| pulp::view::EditorBridge::~EditorBridge |
( |
| ) |
|
◆ EditorBridge() [2/3]
| pulp::view::EditorBridge::EditorBridge |
( |
const EditorBridge & | | ) |
|
|
delete |
◆ EditorBridge() [3/3]
| pulp::view::EditorBridge::EditorBridge |
( |
EditorBridge && | | ) |
|
|
delete |
◆ add_handler()
| void pulp::view::EditorBridge::add_handler |
( |
std::string_view | type, |
|
|
Handler | fn ) |
Register a handler for the given message type.
Replacing an existing handler for the same type is allowed and silent.
◆ attach_native_runtime() [1/3]
| void pulp::view::EditorBridge::attach_native_runtime |
( |
JsRuntime & | runtime, |
|
|
std::string_view | handler_name ) |
Hook this bridge up to a native JS runtime's postMessage source.
handler_name is the symbol the runtime exposes that calls back into C++ (the equivalent of __pulpPostMessage in WebView).
NOTE: This is the integration seam for pulp #468 (Claude Design import lane). The full wiring lands when the import lane's JsRuntime postMessage shape is concrete; until then the body is a stub that records the binding so the call site doesn't have to feature-flag itself out.
◆ attach_native_runtime() [2/3]
| void pulp::view::EditorBridge::attach_native_runtime |
( |
ScriptedUiSession & | session, |
|
|
std::string_view | handler_name ) |
Attach to a ScriptedUiSession without borrowing its replaceable engine.
The endpoint is preserved across scripted-UI reloads. This bridge must outlive the attachment; call detach_native_runtime() before teardown.
◆ attach_native_runtime() [3/3]
| void pulp::view::EditorBridge::attach_native_runtime |
( |
ScriptEngine & | engine, |
|
|
std::string_view | handler_name ) |
Register a global function on a native ScriptEngine that accepts one JSON envelope string and returns the bridge's JSON response string.
The EditorBridge must outlive calls through the registered symbol.
◆ attach_webview()
| void pulp::view::EditorBridge::attach_webview |
( |
WebViewPanel & | panel | ) |
|
Hook this bridge up to a WebViewPanel's structured message channel.
Equivalent to: panel.set_message_handler([this](const WebViewMessage& m) { return dispatch_webview_message(m.type, m.payload_json); });
◆ detach_native_runtime()
| void pulp::view::EditorBridge::detach_native_runtime |
( |
ScriptedUiSession & | session, |
|
|
std::string_view | handler_name ) |
◆ detach_webview()
| void pulp::view::EditorBridge::detach_webview |
( |
WebViewPanel & | panel | ) |
|
Clear the message handler installed by attach_webview().
Safe to call even when no WebView handler is currently installed. Consumers that own both the bridge and panel can use this to make teardown order explicit before the panel or native child view is detached.
◆ dispatch()
| std::string pulp::view::EditorBridge::dispatch |
( |
std::string_view | type, |
|
|
const choc::value::ValueView & | payload ) const |
|
noexcept |
Dispatch an already-parsed envelope.
The caller has already extracted type and payload from the JSON envelope. Returns the JSON response envelope. Always well-formed.
◆ dispatch_json()
| std::string pulp::view::EditorBridge::dispatch_json |
( |
std::string_view | json | ) |
const |
|
noexcept |
Parse a JSON envelope and dispatch.
Returns the same well-formed JSON response envelope as dispatch. Malformed JSON, missing type, or any handler exception all return a {ok: false} response with a descriptive error string.
◆ dispatch_webview_message()
| std::string pulp::view::EditorBridge::dispatch_webview_message |
( |
std::string_view | type, |
|
|
std::string_view | payload_json ) const |
|
noexcept |
Convenience: dispatch a WebViewPanel message that has already been split into type + payload_json by the platform layer.
Used internally by attach_webview but also useful directly when a plugin wraps WebViewPanel itself.
◆ err_response()
| std::string pulp::view::EditorBridge::err_response |
( |
std::string_view | msg | ) |
|
|
staticnoexcept |
{"ok":false,"error":"<msg>"}.
◆ get_float()
| float pulp::view::EditorBridge::get_float |
( |
const choc::value::ValueView & | v, |
|
|
const char * | key, |
|
|
float | dflt ) |
|
staticnoexcept |
◆ get_string()
| std::string pulp::view::EditorBridge::get_string |
( |
const choc::value::ValueView & | v, |
|
|
const char * | key ) |
|
staticnoexcept |
◆ get_uint()
| std::size_t pulp::view::EditorBridge::get_uint |
( |
const choc::value::ValueView & | v, |
|
|
const char * | key, |
|
|
std::size_t | dflt ) |
|
staticnoexcept |
◆ handler_count()
| std::size_t pulp::view::EditorBridge::handler_count |
( |
| ) |
const |
|
noexcept |
Number of registered handlers.
◆ handlers()
| std::vector< std::string > pulp::view::EditorBridge::handlers |
( |
| ) |
const |
Return the registered message types in canonical lexicographic order.
This snapshot is intended for contract/parity checks and diagnostics; callers may retain it across bridge mutations without observing dangling views or a partially updated table.
◆ has_handler()
| bool pulp::view::EditorBridge::has_handler |
( |
std::string_view | type | ) |
const |
|
noexcept |
True if a handler is registered for type.
◆ ok_response() [1/2]
| std::string pulp::view::EditorBridge::ok_response |
( |
| ) |
|
|
staticnoexcept |
◆ ok_response() [2/2]
| std::string pulp::view::EditorBridge::ok_response |
( |
const choc::value::ValueView & | extras | ) |
|
|
staticnoexcept |
{"ok":true, ...members of extras merged in}.
extras must be an object value or the call returns ok_response().
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ remove_handler()
| void pulp::view::EditorBridge::remove_handler |
( |
std::string_view | type | ) |
|
Remove a handler. No-op if no handler was registered.
The documentation for this class was generated from the following file: