Skip to main content

perspective_viewer/config/
options.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13//! Argument dictionaries for the public `PerspectiveViewerElement` methods.
14//! Each derives `ts_rs::TS` so its TypeScript type is generated (and
15//! re-exported from the crate's `typescript_custom_section`) alongside the
16//! config types, rather than hand-maintained.
17
18use serde::Deserialize;
19use ts_rs::TS;
20
21use crate::config::ExportMethod;
22
23/// Selects the target panel of a panel-scoped `<perspective-viewer>` method;
24/// the active panel when `panel` is omitted.
25#[derive(Deserialize, Default, TS)]
26pub struct PanelOptions {
27    #[ts(optional)]
28    pub panel: Option<String>,
29}
30
31/// Options for the `restore()` method.
32#[derive(Deserialize, Default, TS)]
33pub struct RestoreOptions {
34    /// The target panel; the active panel when omitted.
35    #[ts(optional)]
36    pub panel: Option<String>,
37
38    /// When `true`, a failed restore only REJECTS the returned `Promise` —
39    /// the error is not committed to the viewer's visible error state, and
40    /// the session remains usable for subsequent calls. For programmatic
41    /// callers (e.g. the LLM agent's `set_view_config` tool) for whom a
42    /// failed config patch is feedback rather than a user-facing fault.
43    /// The config may be partially applied on failure; restore a
44    /// known-good config to recover exactly.
45    #[ts(optional)]
46    pub suppress_errors: Option<bool>,
47
48    /// When `true`, a `table` no loaded client hosts yet leaves the panel
49    /// empty and pending until the table is created, instead of the default
50    /// error.
51    #[ts(optional)]
52    pub wait_for_table: Option<bool>,
53}
54
55/// Options for the `restoreWorkspace()` method.
56#[derive(Deserialize, Default, TS)]
57pub struct RestoreWorkspaceOptions {
58    /// As `RestoreOptions::wait_for_table`, applied to every panel entry.
59    #[ts(optional)]
60    pub wait_for_table: Option<bool>,
61}
62
63/// Options for the `addPanel()` method.
64#[derive(Deserialize, Default, TS)]
65pub struct AddPanelOptions {
66    /// As `RestoreOptions::wait_for_table`.
67    #[ts(optional)]
68    pub wait_for_table: Option<bool>,
69}
70
71/// The `eject` argument: the loaded client to remove by name; the active
72/// panel's client when omitted.
73#[derive(Deserialize, Default, TS)]
74pub struct ClientOptions {
75    #[ts(optional)]
76    pub client: Option<String>,
77}
78
79/// The `download` / `export` / `copy` argument: the `ExportMethod` and target
80/// panel.
81#[derive(Deserialize, Default, TS)]
82pub struct ExportOptions {
83    #[ts(as = "Option<ExportMethod>")]
84    #[ts(optional)]
85    pub method: Option<String>,
86
87    #[ts(optional)]
88    pub panel: Option<String>,
89}
90
91/// The `getTable` argument: whether to `wait` for a `Table`, and the target
92/// panel.
93#[derive(Deserialize, Default, TS)]
94pub struct GetTableOptions {
95    #[ts(optional)]
96    pub wait: Option<bool>,
97
98    #[ts(optional)]
99    pub panel: Option<String>,
100}
101
102/// How `getView` resolves the `View` it returns.
103#[derive(Clone, Copy, Default, Deserialize, PartialEq, Eq, TS)]
104#[serde(rename_all = "lowercase")]
105pub enum GetViewMode {
106    /// The panel's own bound `View`, which the viewer replaces on config
107    /// change and deletes on auto-pause or `delete()`; rejects when none is
108    /// bound.
109    #[default]
110    Live,
111
112    /// A caller-owned `View` built from the panel's effective config,
113    /// independent of the render lifecycle.
114    Clone,
115
116    /// `live` when the panel has a bound `View`, else `clone`.
117    Auto,
118}
119
120/// The `getView` argument: the `mode` and the target panel.
121#[derive(Deserialize, Default, TS)]
122pub struct GetViewOptions {
123    #[ts(optional)]
124    pub mode: Option<GetViewMode>,
125
126    #[ts(optional)]
127    pub panel: Option<String>,
128}
129
130/// The `getClient` argument: whether to `wait` for a `Client`, and the target
131/// panel.
132#[derive(Deserialize, Default, TS)]
133pub struct GetClientOptions {
134    #[ts(optional)]
135    pub wait: Option<bool>,
136
137    #[ts(optional)]
138    pub panel: Option<String>,
139}
140
141/// Options for the `saveWorkspace()` method.
142#[derive(Deserialize, Default, TS)]
143pub struct SaveWorkspaceOptions {
144    /// When `true`, the emitted `palette` is the full set the element
145    /// holds rather than only the values the panels reference.
146    #[serde(default)]
147    #[ts(optional)]
148    pub full_palette: Option<bool>,
149}