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