Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions crates/ocs_plugin_api/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,57 @@ pub trait HostApi {
) -> Result<crate::widget::WidgetRevision, crate::widget::WidgetReject> {
self.panel_surface_page(panel_id, page)
}

/// Publish (or replace) a panel's TABLE surface (API v29, additive):
/// stable row keys, typed scalar cells. The default is the
/// transport-era stub (Unattached; nothing stored); surface-aware
/// hosts override [`HostApi::panel_table_publish_for_plugin`].
fn panel_table_publish(
&mut self,
_panel_id: &str,
_surface: crate::tables::TableSurface,
) -> Result<crate::tables::TableRevision, crate::tables::TableReject> {
Err(crate::tables::TableReject {
code: crate::tables::TableRejectCode::Unattached,
current_revision: None,
})
}

/// [`Self::panel_table_publish`] for the transport's authenticated
/// `plugin_id`.
fn panel_table_publish_for_plugin(
&mut self,
_plugin_id: &str,
panel_id: &str,
surface: crate::tables::TableSurface,
) -> Result<crate::tables::TableRevision, crate::tables::TableReject> {
self.panel_table_publish(panel_id, surface)
}

/// Patch a panel's stored TABLE atomically (API v29, additive):
/// cell/row ops apply all-or-nothing against the stored head. The
/// default is the transport-era stub (Unattached; nothing stored).
fn panel_surface_table_patch(
&mut self,
_panel_id: &str,
_patch: crate::tables::TablePatch,
) -> Result<crate::tables::TableRevision, crate::tables::TableReject> {
Err(crate::tables::TableReject {
code: crate::tables::TableRejectCode::Unattached,
current_revision: None,
})
}

/// [`Self::panel_surface_table_patch`] for the transport's
/// authenticated `plugin_id`.
fn panel_surface_table_patch_for_plugin(
&mut self,
_plugin_id: &str,
panel_id: &str,
patch: crate::tables::TablePatch,
) -> Result<crate::tables::TableRevision, crate::tables::TableReject> {
self.panel_surface_table_patch(panel_id, patch)
}
}

/// The answer of a host without surface support: `InvalidSurface` for an
Expand Down
54 changes: 54 additions & 0 deletions crates/ocs_plugin_api/src/ipc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,60 @@ impl HostApi for PluginHostApi {
}
}

fn panel_table_publish(
&mut self,
panel_id: &str,
surface: crate::tables::TableSurface,
) -> Result<crate::tables::TableRevision, crate::tables::TableReject> {
match self.client.request(PluginRequest::PanelSurfacePublish {
panel_id: panel_id.to_string(),
surface: PanelSurface::Tables(surface),
}) {
Ok(PluginResponse::PanelTablePublished(result)) => result,
Ok(other) => {
eprintln!("[plugin] unexpected table publish response: {other:?}");
Err(crate::tables::TableReject {
code: crate::tables::TableRejectCode::Unattached,
current_revision: None,
})
}
Err(e) => {
eprintln!("[plugin] table publish request failed: {e}");
Err(crate::tables::TableReject {
code: crate::tables::TableRejectCode::Unattached,
current_revision: None,
})
}
}
}

fn panel_surface_table_patch(
&mut self,
panel_id: &str,
patch: crate::tables::TablePatch,
) -> Result<crate::tables::TableRevision, crate::tables::TableReject> {
match self.client.request(PluginRequest::PanelSurfaceTablePatch {
panel_id: panel_id.to_string(),
patch,
}) {
Ok(PluginResponse::PanelTablePatchResult(result)) => result,
Ok(other) => {
eprintln!("[plugin] unexpected table patch response: {other:?}");
Err(crate::tables::TableReject {
code: crate::tables::TableRejectCode::Unattached,
current_revision: None,
})
}
Err(e) => {
eprintln!("[plugin] table patch request failed: {e}");
Err(crate::tables::TableReject {
code: crate::tables::TableRejectCode::Unattached,
current_revision: None,
})
}
}
}

fn panel_snapshot(&self, panel_id: &str) -> Result<crate::dialog::PanelSnapshot, String> {
match self.client.request(PluginRequest::PanelSnapshot {
panel_id: panel_id.to_string(),
Expand Down
15 changes: 15 additions & 0 deletions crates/ocs_plugin_api/src/ipc/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,13 @@ pub enum PluginRequest {
panel_id: String,
page: crate::widget::WidgetPage,
},
/// V29 (additive): apply a bounded, revision-checked table patch
/// (cell/row ops) to the panel's stored table atomically
/// (all-or-nothing) — the cell-edit and row-update primitive.
PanelSurfaceTablePatch {
panel_id: String,
patch: crate::tables::TablePatch,
},
}

/// Responses the host sends back for `PluginRequest`.
Expand Down Expand Up @@ -570,6 +577,14 @@ pub enum PluginResponse {
/// widget revision (the widget tier's independent revision space), or
/// the typed refusal.
PanelWidgetPublished(Result<crate::widget::WidgetRevision, crate::widget::WidgetReject>),
/// V29 (additive): outcome of a TABLE surface publish — the stored
/// table revision (the table tier's independent revision space), or
/// the typed refusal.
PanelTablePublished(Result<crate::tables::TableRevision, crate::tables::TableReject>),
/// V29 (additive): outcome of a table patch — the stored revision
/// after the atomic apply, or the typed refusal; the stored table
/// never ends up partially patched.
PanelTablePatchResult(Result<crate::tables::TableRevision, crate::tables::TableReject>),
}

/// Messages sent from the host to the plugin runner.
Expand Down
6 changes: 6 additions & 0 deletions crates/ocs_plugin_api/src/ipc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,19 @@ pub fn handle_plugin_request(
crate::scene::PanelSurface::Widgets(widgets) => PluginResponse::PanelWidgetPublished(
host.panel_widget_publish_for_plugin(plugin_id, &panel_id, widgets),
),
crate::scene::PanelSurface::Tables(tables) => PluginResponse::PanelTablePublished(
host.panel_table_publish_for_plugin(plugin_id, &panel_id, tables),
),
},
PanelSurfacePatch { panel_id, patch } => PluginResponse::PanelSurfacePatchResult(
host.panel_surface_patch_for_plugin(plugin_id, &panel_id, patch),
),
PanelSurfacePage { panel_id, page } => PluginResponse::PanelSurfacePageResult(
host.panel_surface_page_for_plugin(plugin_id, &panel_id, page),
),
PanelSurfaceTablePatch { panel_id, patch } => PluginResponse::PanelTablePatchResult(
host.panel_surface_table_patch_for_plugin(plugin_id, &panel_id, patch),
),
SetGeoLocation { location } => {
PluginResponse::GeoLocationSet(host.set_geo_location(&location))
}
Expand Down
5 changes: 5 additions & 0 deletions crates/ocs_plugin_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub mod entity_coverage_types;
pub mod manifest;
pub mod ribbon;
pub mod scene;
pub mod tables;
pub mod type_registry;
pub mod type_registry_types;
pub mod version_info;
Expand Down Expand Up @@ -83,6 +84,10 @@ pub use scene::{
PanelScene, PanelSurface, Rect2D, Rgba8, SceneBuilder, SceneColor, SceneElement, SceneError,
SceneRevision, StableId, Stroke, SurfaceReject, SurfaceRejectCode, ThemeColor, Vec2,
};
pub use tables::{
CellValue, MAX_TABLE_OPS, MAX_TABLE_ROWS, TableColumn, TableError, TableOp, TablePatch,
TableRevision, TableSurface,
};
pub use type_registry::{
EnumVariantInfo, FieldInfo, MethodInfo, ParameterInfo, TypeId, TypeInfo, TypeKind,
TypeRegistry, get_embedded_type_registry_json,
Expand Down
15 changes: 15 additions & 0 deletions crates/ocs_plugin_api/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,11 @@ pub enum PanelSurface {
/// host-local, and children a plugin has not pushed yet page in via
/// `WidgetPage` installs.
Widgets(crate::widget::WidgetSurface),
/// The panel's typed-table surface (api v29, S07): stable row keys,
/// typed scalar cells, atomic cell/row patches — rendered and edited
/// with NATIVE host widgets (edits are host-local drafts until the
/// plugin canonicalizes them with its own patch).
Tables(crate::tables::TableSurface),
}

/// Why a panel surface publish was refused; a refusal changes nothing.
Expand Down Expand Up @@ -878,6 +883,16 @@ pub enum SurfaceEvent {
/// one expansion case that is NOT host-local — the plugin is the
/// data source).
NodeExpanded { node: StableId },
/// A committed cell edit on a table surface (api v29, S07): the
/// host-local editing session committed a draft under the
/// typed-commit rule; the plugin remains the data authority and
/// canonicalizes by pushing its own table patch. Best-effort like
/// every surface event.
CellEdited {
row: StableId,
column: StableId,
value: crate::tables::CellValue,
},
}

/// Maximum patch ops accepted in one patch frame, bounding allocation and
Expand Down
Loading
Loading