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 perspective_client::proto::ColumnType;
19use serde::Deserialize;
20use ts_rs::TS;
21
22use crate::config::ExportMethod;
23
24/// Selects the target panel of a panel-scoped `<perspective-viewer>` method;
25/// the active panel when `panel` is omitted.
26#[derive(Deserialize, Default, TS)]
27pub struct PanelOptions {
28 #[ts(optional)]
29 pub panel: Option<String>,
30}
31
32/// Options for the `restore()` method.
33#[derive(Deserialize, Default, TS)]
34pub struct RestoreOptions {
35 /// The target panel; the active panel when omitted.
36 #[ts(optional)]
37 pub panel: Option<String>,
38
39 /// When `true`, a config that was applied and then failed to render only
40 /// rejects the returned `Promise`, without raising the panel's visible
41 /// error state.
42 #[ts(optional)]
43 pub suppress_errors: Option<bool>,
44
45 /// When `true`, a `table` no loaded client hosts yet leaves the panel
46 /// empty and pending until the table is created, instead of the default
47 /// error.
48 #[ts(optional)]
49 pub wait_for_table: Option<bool>,
50}
51
52/// Options for the `restoreWorkspace()` method.
53#[derive(Deserialize, Default, TS)]
54pub struct RestoreWorkspaceOptions {
55 /// As `RestoreOptions::wait_for_table`, applied to every panel entry.
56 #[ts(optional)]
57 pub wait_for_table: Option<bool>,
58}
59
60/// Options for the `addPanel()` method.
61#[derive(Deserialize, Default, TS)]
62pub struct AddPanelOptions {
63 /// As `RestoreOptions::wait_for_table`.
64 #[ts(optional)]
65 pub wait_for_table: Option<bool>,
66}
67
68/// The `eject` argument: the loaded client to remove by name; the active
69/// panel's client when omitted.
70#[derive(Deserialize, Default, TS)]
71pub struct ClientOptions {
72 #[ts(optional)]
73 pub client: Option<String>,
74}
75
76/// The `download` / `export` / `copy` argument: the `ExportMethod` and target
77/// panel.
78#[derive(Deserialize, Default, TS)]
79pub struct ExportOptions {
80 #[ts(as = "Option<ExportMethod>")]
81 #[ts(optional)]
82 pub method: Option<String>,
83
84 #[ts(optional)]
85 pub panel: Option<String>,
86}
87
88/// The `getTable` argument: whether to `wait` for a `Table`, and the target
89/// panel.
90#[derive(Deserialize, Default, TS)]
91pub struct GetTableOptions {
92 #[ts(optional)]
93 pub wait: Option<bool>,
94
95 #[ts(optional)]
96 pub panel: Option<String>,
97}
98
99/// How `getView` resolves the `View` it returns.
100#[derive(Clone, Copy, Default, Deserialize, PartialEq, Eq, TS)]
101#[serde(rename_all = "lowercase")]
102pub enum GetViewMode {
103 /// The panel's own bound `View`, which the viewer replaces on config
104 /// change and deletes on auto-pause or `delete()`; rejects when none is
105 /// bound.
106 #[default]
107 Live,
108
109 /// A caller-owned `View` built from the panel's effective config,
110 /// independent of the render lifecycle.
111 Clone,
112
113 /// `live` when the panel has a bound `View`, else `clone`.
114 Auto,
115}
116
117/// The `getView` argument: the `mode` and the target panel.
118#[derive(Deserialize, Default, TS)]
119pub struct GetViewOptions {
120 #[ts(optional)]
121 pub mode: Option<GetViewMode>,
122
123 #[ts(optional)]
124 pub panel: Option<String>,
125}
126
127/// The `getClient` argument: whether to `wait` for a `Client`, and the target
128/// panel.
129#[derive(Deserialize, Default, TS)]
130pub struct GetClientOptions {
131 #[ts(optional)]
132 pub wait: Option<bool>,
133
134 #[ts(optional)]
135 pub panel: Option<String>,
136}
137
138/// Options for the `saveWorkspace()` method.
139#[derive(Deserialize, Default, TS)]
140pub struct SaveWorkspaceOptions {
141 /// When `true`, the emitted `palette` is the full set the element
142 /// holds rather than only the values the panels reference.
143 #[serde(default)]
144 #[ts(optional)]
145 pub full_palette: Option<bool>,
146}
147
148/// Options for the static `setPluginConfigDefaults()` method.
149#[derive(Deserialize, Default, TS)]
150pub struct ConfigDefaultsOptions {
151 /// Limits the defaults to the named plugin.
152 #[ts(optional)]
153 pub plugin: Option<String>,
154}
155
156/// Options for the static `setColumnConfigDefaults()` method.
157#[derive(Deserialize, Default, TS)]
158pub struct ColumnConfigDefaultsOptions {
159 /// Limits the defaults to the named plugin.
160 #[ts(optional)]
161 pub plugin: Option<String>,
162
163 /// Limits the defaults to columns of this view type.
164 #[serde(rename = "type")]
165 #[ts(optional, as = "Option<ColumnType>")]
166 pub ty: Option<String>,
167}