@perspective-dev/viewer 5.5.1 → 5.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -3
- package/dist/cdn/perspective-viewer.js +9 -9
- package/dist/cdn/perspective-viewer.js.map +4 -4
- package/dist/css/blueprint.css +1 -1
- package/dist/css/botanical.css +1 -1
- package/dist/css/dracula.css +1 -1
- package/dist/css/eggplant.css +1 -1
- package/dist/css/gruvbox-dark.css +1 -1
- package/dist/css/gruvbox.css +1 -1
- package/dist/css/icons.css +1 -1
- package/dist/css/intl/ar.css +1 -1
- package/dist/css/intl/de.css +1 -1
- package/dist/css/intl/es.css +1 -1
- package/dist/css/intl/fr.css +1 -1
- package/dist/css/intl/ja.css +1 -1
- package/dist/css/intl/pt.css +1 -1
- package/dist/css/intl/zh.css +1 -1
- package/dist/css/intl.css +1 -1
- package/dist/css/ledger.css +1 -1
- package/dist/css/monokai.css +1 -1
- package/dist/css/nord.css +1 -1
- package/dist/css/phosphor.css +1 -1
- package/dist/css/pro-dark.css +1 -1
- package/dist/css/pro.css +1 -1
- package/dist/css/solarized-dark.css +1 -1
- package/dist/css/solarized.css +1 -1
- package/dist/css/themes.css +1 -1
- package/dist/css/vaporwave.css +1 -1
- package/dist/css/velvet.css +1 -1
- package/dist/docs/perspective-docs.json +1 -1
- package/dist/esm/column-format.js +2 -0
- package/dist/esm/column-format.js.map +7 -0
- package/dist/esm/extensions.d.ts +3 -13
- package/dist/esm/perspective-viewer.d.ts +1 -1
- package/dist/esm/perspective-viewer.js +9 -9
- package/dist/esm/perspective-viewer.js.map +4 -4
- package/dist/esm/plugin.d.ts +4 -1
- package/dist/esm/select-detail.d.ts +15 -0
- package/dist/esm/select-detail.js +2 -0
- package/dist/esm/select-detail.js.map +7 -0
- package/dist/esm/ts-rs/DerivedTableConfig.d.ts +35 -0
- package/dist/esm/ts-rs/Layout.d.ts +2 -2
- package/dist/esm/ts-rs/Orientation.d.ts +2 -1
- package/dist/esm/ts-rs/PanelViewerConfig.d.ts +7 -6
- package/dist/esm/ts-rs/RestoreOptions.d.ts +3 -7
- package/dist/esm/ts-rs/SplitLayout.d.ts +13 -0
- package/dist/esm/ts-rs/TabLayout.d.ts +3 -0
- package/dist/esm/ts-rs/TableRef.d.ts +9 -0
- package/dist/esm/ts-rs/ViewerConfig.d.ts +7 -6
- package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +7 -5
- package/dist/esm/ts-rs/WorkspaceConfig.d.ts +9 -1
- package/dist/esm/ts-rs/WorkspaceConfigUpdate.d.ts +11 -1
- package/dist/wasm/perspective-viewer.d.ts +115 -35
- package/dist/wasm/perspective-viewer.js +312 -188
- package/dist/wasm/perspective-viewer.wasm +0 -0
- package/dist/wasm/perspective-viewer.wasm.d.ts +21 -17
- package/package.json +32 -19
- package/src/css/column-selector.css +205 -50
- package/src/css/ui/containers/context-menu.css +12 -1
- package/src/css/ui/containers/dropdown-menu-items.css +29 -0
- package/src/css/ui/containers/scroll-panel.css +4 -1
- package/src/rust/agent/client/protocol.rs +0 -89
- package/src/rust/agent/markdown/mod.rs +0 -238
- package/src/rust/agent/preamble.md +3 -0
- package/src/rust/agent/tools.rs +282 -17
- package/src/rust/components/column_selector/active_column.rs +15 -5
- package/src/rust/components/column_selector/add_expression_button.rs +9 -26
- package/src/rust/components/column_selector/config_selector.rs +35 -7
- package/src/rust/components/column_selector/derived_control.rs +229 -0
- package/src/rust/components/column_selector/expr_edit_button.rs +3 -2
- package/src/rust/components/column_selector/filter_column.rs +2 -4
- package/src/rust/components/column_selector/inactive_column.rs +4 -5
- package/src/rust/components/column_selector/pivot_column.rs +21 -1
- package/src/rust/components/column_selector/sort_column.rs +4 -3
- package/src/rust/components/column_selector.rs +21 -1
- package/src/rust/components/column_settings_sidebar/save_settings.rs +5 -3
- package/src/rust/components/column_settings_sidebar/style_tab/symbol/row_selector.rs +1 -1
- package/src/rust/components/column_settings_sidebar/style_tab.rs +1 -0
- package/src/rust/components/column_settings_sidebar.rs +25 -19
- package/src/rust/components/debug_panel.rs +38 -29
- package/src/rust/components/dragdrop_list.rs +8 -9
- package/src/rust/components/empty_row.rs +3 -3
- package/src/rust/components/filter_dropdown.rs +100 -101
- package/src/rust/components/main_panel/msg.rs +6 -4
- package/src/rust/components/main_panel/reconcile.rs +67 -25
- package/src/rust/components/main_panel/render.rs +70 -51
- package/src/rust/components/main_panel/update.rs +20 -21
- package/src/rust/components/main_panel.rs +87 -60
- package/src/rust/components/new_panel_menu.rs +69 -1
- package/src/rust/components/panel_menu.rs +63 -12
- package/src/rust/components/plugin_tab.rs +3 -2
- package/src/rust/components/render_warning.rs +2 -1
- package/src/rust/components/settings_panel.rs +4 -4
- package/src/rust/components/status_bar.rs +74 -24
- package/src/rust/components/status_indicator.rs +8 -1
- package/src/rust/components/viewer/filters.rs +13 -1
- package/src/rust/components/viewer/msg.rs +4 -0
- package/src/rust/components/viewer/panels.rs +41 -1
- package/src/rust/components/viewer/render.rs +1 -0
- package/src/rust/components/viewer/settings.rs +0 -22
- package/src/rust/components/viewer/snapshots.rs +2 -2
- package/src/rust/components/viewer/wiring.rs +14 -0
- package/src/rust/components/viewer.rs +45 -25
- package/src/rust/components/window_editor.rs +5 -4
- package/src/rust/config/column_config_schema.rs +38 -377
- package/src/rust/config/number_string_format.rs +0 -94
- package/src/rust/config/options.rs +3 -7
- package/src/rust/config/plugin_static_config.rs +0 -42
- package/src/rust/config/viewer_config.rs +47 -17
- package/src/rust/config/workspace_config.rs +160 -129
- package/src/rust/custom_elements/viewer.rs +187 -131
- package/src/rust/custom_events.rs +33 -18
- package/src/rust/derived.rs +266 -0
- package/src/rust/exprtk/tokenize.rs +0 -54
- package/src/rust/js/plugin.rs +1 -1
- package/src/rust/js/regular_layout.rs +225 -3
- package/src/rust/lib.rs +3 -0
- package/src/rust/presentation.rs +23 -4
- package/src/rust/queries/column_locator.rs +55 -48
- package/src/rust/queries/get_viewer_config.rs +1 -1
- package/src/rust/queries/plugin_column_styles.rs +22 -23
- package/src/rust/renderer/dispatch.rs +2 -0
- package/src/rust/renderer/plugin_config.rs +652 -487
- package/src/rust/renderer/props.rs +4 -0
- package/src/rust/renderer/registry.rs +2 -6
- package/src/rust/renderer/state.rs +205 -0
- package/src/rust/renderer.rs +201 -59
- package/src/rust/session/metadata.rs +30 -9
- package/src/rust/session/op_queue.rs +430 -0
- package/src/rust/session/panel_state.rs +327 -0
- package/src/rust/session/view_subscription.rs +42 -3
- package/src/rust/session.rs +900 -395
- package/src/rust/tasks/apply_global_filters.rs +49 -35
- package/src/rust/tasks/auto_pause.rs +22 -12
- package/src/rust/tasks/copy_export.rs +5 -0
- package/src/rust/tasks/create_panel.rs +34 -9
- package/src/rust/tasks/derive.rs +312 -0
- package/src/rust/tasks/mod.rs +6 -2
- package/src/rust/tasks/pipeline.rs +145 -89
- package/src/rust/tasks/reset_all.rs +31 -20
- package/src/rust/tasks/restore_derived.rs +200 -0
- package/src/rust/tasks/restore_panel.rs +153 -141
- package/src/rust/tasks/send_column_config.rs +56 -29
- package/src/rust/tasks/send_plugin_config.rs +52 -23
- package/src/rust/tasks/set_edit_mode.rs +33 -25
- package/src/rust/tasks/sync_update_panels.rs +30 -12
- package/src/rust/tasks/table_lifecycle.rs +70 -34
- package/src/rust/tasks/transactional_restore.rs +387 -0
- package/src/rust/tasks/update_theme.rs +45 -6
- package/src/rust/ui/containers/scroll_panel.rs +17 -10
- package/src/rust/ui/containers/split_panel.rs +0 -41
- package/src/rust/ui/context_menu.rs +157 -18
- package/src/rust/ui/font_loader.rs +23 -35
- package/src/rust/ui/form/mirrored_textarea.rs +0 -12
- package/src/rust/ui/form/multi_stop_gradient_selector.rs +0 -89
- package/src/rust/ui/form/palette_selector.rs +0 -51
- package/src/rust/ui/portal.rs +4 -10
- package/src/rust/utils/browser/mod.rs +2 -3
- package/src/{ts/perspective-viewer.inline.ts → rust/utils/browser/mouse.rs} +11 -10
- package/src/rust/utils/browser/request_animation_frame.rs +27 -8
- package/src/rust/utils/css.rs +0 -360
- package/src/rust/utils/local_fonts.rs +0 -36
- package/src/rust/utils/mod.rs +2 -3
- package/src/rust/utils/modal_position.rs +15 -21
- package/src/rust/utils/{browser/tests/mod.rs → plugin_host_state.rs} +31 -1
- package/src/rust/utils/pubsub.rs +0 -1
- package/src/rust/workspace.rs +187 -140
- package/src/svg/derived.svg +6 -0
- package/src/themes/icons.css +1 -0
- package/src/themes/intl/ar.css +11 -0
- package/src/themes/intl/de.css +11 -0
- package/src/themes/intl/es.css +11 -0
- package/src/themes/intl/fr.css +11 -0
- package/src/themes/intl/ja.css +11 -0
- package/src/themes/intl/pt.css +11 -0
- package/src/themes/intl/zh.css +11 -0
- package/src/themes/intl.css +11 -0
- package/src/ts/extensions.ts +3 -36
- package/src/ts/perspective-viewer.ts +1 -1
- package/src/ts/plugin.ts +4 -1
- package/src/{rust/utils/tests/request_animation_frame.rs → ts/select-detail.ts} +32 -26
- package/src/ts/ts-rs/DerivedTableConfig.ts +22 -0
- package/src/ts/ts-rs/Layout.ts +2 -2
- package/src/ts/ts-rs/Orientation.ts +2 -1
- package/src/ts/ts-rs/PanelViewerConfig.ts +7 -6
- package/src/ts/ts-rs/RestoreOptions.ts +3 -7
- package/src/ts/ts-rs/SplitLayout.ts +17 -1
- package/src/ts/ts-rs/TabLayout.ts +3 -0
- package/src/ts/ts-rs/TableRef.ts +9 -0
- package/src/ts/ts-rs/ViewerConfig.ts +7 -6
- package/src/ts/ts-rs/ViewerConfigUpdate.ts +7 -5
- package/src/ts/ts-rs/WorkspaceConfig.ts +7 -1
- package/src/ts/ts-rs/WorkspaceConfigUpdate.ts +9 -1
- package/dist/esm/perspective-viewer.inline.d.ts +0 -3
- package/dist/esm/perspective-viewer.inline.js +0 -21
- package/dist/esm/perspective-viewer.inline.js.map +0 -7
- package/src/rust/tasks/restore_and_render.rs +0 -107
- package/src/rust/utils/browser/tests/debounce.rs +0 -163
- package/src/rust/utils/tests/mod.rs +0 -14
- package/src/rust/utils/tests/pubsub.rs +0 -95
- /package/dist/wasm/snippets/{perspective-viewer-6813b568219c6763 → perspective-viewer-7fc45549159e01e4}/inline0.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-6813b568219c6763 → perspective-viewer-7fc45549159e01e4}/inline1.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-6813b568219c6763 → perspective-viewer-7fc45549159e01e4}/inline2.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-6813b568219c6763 → perspective-viewer-7fc45549159e01e4}/inline3.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-6813b568219c6763 → perspective-viewer-7fc45549159e01e4}/inline4.js +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-6813b568219c6763 → perspective-viewer-7fc45549159e01e4}/inline5.js +0 -0
|
@@ -162,7 +162,8 @@ impl RegularLayout {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
/// The
|
|
165
|
+
/// The direction a [`SplitLayout`] divides its space in: `horizontal` places
|
|
166
|
+
/// children side by side as columns, `vertical` stacks them as rows.
|
|
166
167
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, ts_rs::TS)]
|
|
167
168
|
#[serde(rename_all = "lowercase")]
|
|
168
169
|
pub enum Orientation {
|
|
@@ -170,8 +171,8 @@ pub enum Orientation {
|
|
|
170
171
|
Vertical,
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
/// A
|
|
174
|
-
///
|
|
174
|
+
/// A dashboard's panel arrangement: nested splits whose leaves are tab stacks
|
|
175
|
+
/// of panel ids, naming every panel exactly once.
|
|
175
176
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ts_rs::TS)]
|
|
176
177
|
#[serde(tag = "type")]
|
|
177
178
|
pub enum Layout {
|
|
@@ -184,13 +185,21 @@ pub enum Layout {
|
|
|
184
185
|
Tab(TabLayout),
|
|
185
186
|
}
|
|
186
187
|
|
|
188
|
+
/// A row or column of child layouts, nested to form a grid.
|
|
187
189
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ts_rs::TS)]
|
|
188
190
|
pub struct SplitLayout {
|
|
191
|
+
/// Child layouts, in left-to-right or top-to-bottom order.
|
|
189
192
|
pub children: Vec<Layout>,
|
|
193
|
+
|
|
194
|
+
/// Each child's fraction of the split, one per child, summing to 1.
|
|
190
195
|
pub sizes: Vec<f64>,
|
|
196
|
+
|
|
197
|
+
/// Whether children sit side by side (`horizontal`) or stacked
|
|
198
|
+
/// (`vertical`).
|
|
191
199
|
pub orientation: Orientation,
|
|
192
200
|
}
|
|
193
201
|
|
|
202
|
+
/// A stack of panels shown as tabs, one visible at a time.
|
|
194
203
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, ts_rs::TS)]
|
|
195
204
|
pub struct TabLayout {
|
|
196
205
|
/// Panel ids (slot names) in this stack.
|
|
@@ -202,7 +211,220 @@ pub struct TabLayout {
|
|
|
202
211
|
pub selected: Option<usize>,
|
|
203
212
|
}
|
|
204
213
|
|
|
214
|
+
/// A normalized `[0, 1]` rectangle of the layout box (regular-layout's
|
|
215
|
+
/// `ViewWindow`).
|
|
216
|
+
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
|
217
|
+
pub struct ViewWindow {
|
|
218
|
+
pub row_start: f64,
|
|
219
|
+
pub row_end: f64,
|
|
220
|
+
pub col_start: f64,
|
|
221
|
+
pub col_end: f64,
|
|
222
|
+
}
|
|
223
|
+
|
|
205
224
|
impl Layout {
|
|
225
|
+
/// Mirror of regular-layout's `insert_child(tree, name, [index],
|
|
226
|
+
/// orientation)`, the single-index split insert `MainPanel::reconcile`
|
|
227
|
+
/// issues.
|
|
228
|
+
pub fn insert_split(&self, index: usize, name: &str, orientation: Orientation) -> Layout {
|
|
229
|
+
let leaf = Layout::Tab(TabLayout {
|
|
230
|
+
tabs: vec![name.to_owned()],
|
|
231
|
+
selected: None,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
match self {
|
|
235
|
+
Layout::Split(split) if split.orientation == orientation => {
|
|
236
|
+
let index = index.min(split.children.len());
|
|
237
|
+
let mut children = split.children.clone();
|
|
238
|
+
let mut sizes = split.sizes.clone();
|
|
239
|
+
children.insert(index, leaf);
|
|
240
|
+
sizes.insert(index, 1.0 / (children.len() - 1).max(1) as f64);
|
|
241
|
+
let total: f64 = sizes.iter().sum();
|
|
242
|
+
let sizes = if total.is_finite() && total > 0.0 {
|
|
243
|
+
sizes.iter().map(|size| size / total).collect()
|
|
244
|
+
} else {
|
|
245
|
+
vec![1.0 / children.len() as f64; children.len()]
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
Layout::Split(SplitLayout {
|
|
249
|
+
children,
|
|
250
|
+
sizes,
|
|
251
|
+
orientation,
|
|
252
|
+
})
|
|
253
|
+
},
|
|
254
|
+
_ => Layout::Split(SplitLayout {
|
|
255
|
+
children: if index == 0 {
|
|
256
|
+
vec![leaf, self.clone()]
|
|
257
|
+
} else {
|
|
258
|
+
vec![self.clone(), leaf]
|
|
259
|
+
},
|
|
260
|
+
sizes: vec![0.5, 0.5],
|
|
261
|
+
orientation,
|
|
262
|
+
}),
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// The normalized box the visible panel `name` occupies (mirror of
|
|
267
|
+
/// regular-layout's `calculate_presize_paths`).
|
|
268
|
+
pub fn view_window(&self, name: &str) -> Option<ViewWindow> {
|
|
269
|
+
self.view_window_in(name, ViewWindow {
|
|
270
|
+
row_start: 0.0,
|
|
271
|
+
row_end: 1.0,
|
|
272
|
+
col_start: 0.0,
|
|
273
|
+
col_end: 1.0,
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
fn view_window_in(&self, name: &str, window: ViewWindow) -> Option<ViewWindow> {
|
|
278
|
+
match self {
|
|
279
|
+
Layout::Tab(tab) => {
|
|
280
|
+
let selected = tab.tabs.get(tab.selected.unwrap_or(0));
|
|
281
|
+
(selected.map(String::as_str) == Some(name)).then_some(window)
|
|
282
|
+
},
|
|
283
|
+
Layout::Split(split) => {
|
|
284
|
+
let vertical = split.orientation == Orientation::Vertical;
|
|
285
|
+
let (start, end) = if vertical {
|
|
286
|
+
(window.row_start, window.row_end)
|
|
287
|
+
} else {
|
|
288
|
+
(window.col_start, window.col_end)
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
let mut pos = start;
|
|
292
|
+
for (child, size) in split.children.iter().zip(&split.sizes) {
|
|
293
|
+
let next = pos + (end - start) * size;
|
|
294
|
+
let child_window = if vertical {
|
|
295
|
+
ViewWindow {
|
|
296
|
+
row_start: pos,
|
|
297
|
+
row_end: next,
|
|
298
|
+
..window
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
ViewWindow {
|
|
302
|
+
col_start: pos,
|
|
303
|
+
col_end: next,
|
|
304
|
+
..window
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
if let Some(found) = child.view_window_in(name, child_window) {
|
|
309
|
+
return Some(found);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
pos = next;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
None
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/// Check that this tree names each of `ids` exactly once and is
|
|
321
|
+
/// well-formed, describing the first violation found.
|
|
322
|
+
pub fn validate(&self, ids: &[String]) -> Result<(), String> {
|
|
323
|
+
if let Layout::Split(split) = self
|
|
324
|
+
&& split.children.is_empty()
|
|
325
|
+
&& split.sizes.is_empty()
|
|
326
|
+
&& ids.is_empty()
|
|
327
|
+
{
|
|
328
|
+
return Ok(());
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
let mut seen = Vec::new();
|
|
332
|
+
self.validate_node("layout", ids, &mut seen)?;
|
|
333
|
+
let missing = ids
|
|
334
|
+
.iter()
|
|
335
|
+
.filter(|id| !seen.contains(id))
|
|
336
|
+
.collect::<Vec<_>>();
|
|
337
|
+
|
|
338
|
+
if !missing.is_empty() {
|
|
339
|
+
return Err(format!(
|
|
340
|
+
"Invalid layout: panels {missing:?} are missing - a layout must name every panel \
|
|
341
|
+
exactly once (panels: {ids:?})"
|
|
342
|
+
));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
Ok(())
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
fn validate_node(
|
|
349
|
+
&self,
|
|
350
|
+
path: &str,
|
|
351
|
+
ids: &[String],
|
|
352
|
+
seen: &mut Vec<String>,
|
|
353
|
+
) -> Result<(), String> {
|
|
354
|
+
match self {
|
|
355
|
+
Layout::Split(split) => {
|
|
356
|
+
if split.children.is_empty() {
|
|
357
|
+
return Err(format!("Invalid layout: {path}.children is empty"));
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if split.sizes.len() != split.children.len() {
|
|
361
|
+
return Err(format!(
|
|
362
|
+
"Invalid layout: {path}.sizes has {} entries for {} children - give one \
|
|
363
|
+
size per child",
|
|
364
|
+
split.sizes.len(),
|
|
365
|
+
split.children.len()
|
|
366
|
+
));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if let Some(size) = split.sizes.iter().find(|x| !x.is_finite() || **x <= 0.0) {
|
|
370
|
+
return Err(format!(
|
|
371
|
+
"Invalid layout: {path}.sizes contains {size} - sizes must be positive \
|
|
372
|
+
fractions"
|
|
373
|
+
));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let total: f64 = split.sizes.iter().sum();
|
|
377
|
+
if (total - 1.0).abs() > 1e-6 {
|
|
378
|
+
return Err(format!(
|
|
379
|
+
"Invalid layout: {path}.sizes sum to {total} - sizes are fractions of the \
|
|
380
|
+
split and must sum to 1"
|
|
381
|
+
));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
for (index, child) in split.children.iter().enumerate() {
|
|
385
|
+
child.validate_node(&format!("{path}.children[{index}]"), ids, seen)?;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
Ok(())
|
|
389
|
+
},
|
|
390
|
+
Layout::Tab(tab) => {
|
|
391
|
+
if tab.tabs.is_empty() {
|
|
392
|
+
return Err(format!("Invalid layout: {path}.tabs is empty"));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
if let Some(selected) = tab.selected
|
|
396
|
+
&& selected >= tab.tabs.len()
|
|
397
|
+
{
|
|
398
|
+
return Err(format!(
|
|
399
|
+
"Invalid layout: {path}.selected is {selected} but {path}.tabs has {} \
|
|
400
|
+
entries",
|
|
401
|
+
tab.tabs.len()
|
|
402
|
+
));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
for name in &tab.tabs {
|
|
406
|
+
if !ids.contains(name) {
|
|
407
|
+
return Err(format!(
|
|
408
|
+
"Invalid layout: {path}.tabs names unknown panel \"{name}\" (panels: \
|
|
409
|
+
{ids:?})"
|
|
410
|
+
));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if seen.contains(name) {
|
|
414
|
+
return Err(format!(
|
|
415
|
+
"Invalid layout: panel \"{name}\" appears more than once - a layout \
|
|
416
|
+
must name every panel exactly once"
|
|
417
|
+
));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
seen.push(name.clone());
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
Ok(())
|
|
424
|
+
},
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
206
428
|
/// Collect every panel id (slot name) in the tree, depth-first.
|
|
207
429
|
pub fn slot_names(&self) -> Vec<String> {
|
|
208
430
|
match self {
|
package/src/rust/lib.rs
CHANGED
|
@@ -34,6 +34,7 @@ pub mod components;
|
|
|
34
34
|
pub mod config;
|
|
35
35
|
pub mod custom_elements;
|
|
36
36
|
mod custom_events;
|
|
37
|
+
mod derived;
|
|
37
38
|
pub mod exprtk;
|
|
38
39
|
mod js;
|
|
39
40
|
mod presentation;
|
|
@@ -89,6 +90,8 @@ export type * from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
|
|
|
89
90
|
export type * from "../../src/ts/ts-rs/ViewerConfigInitial.d.ts";
|
|
90
91
|
export type * from "../../src/ts/ts-rs/PluginStaticConfig.d.ts";
|
|
91
92
|
export type * from "../../src/ts/ts-rs/WorkspaceConfig.d.ts";
|
|
93
|
+
export type * from "../../src/ts/ts-rs/TableRef.d.ts";
|
|
94
|
+
export type * from "../../src/ts/ts-rs/DerivedTableConfig.d.ts";
|
|
92
95
|
export type * from "../../src/ts/ts-rs/WorkspaceConfigUpdate.d.ts";
|
|
93
96
|
export type * from "../../src/ts/ts-rs/ExportMethod.d.ts";
|
|
94
97
|
export type * from "../../src/ts/ts-rs/PanelOptions.d.ts";
|
package/src/rust/presentation.rs
CHANGED
|
@@ -233,6 +233,8 @@ impl Presentation {
|
|
|
233
233
|
self.viewer_elem
|
|
234
234
|
.toggle_attribute_with_force("settings", opt)
|
|
235
235
|
.unwrap();
|
|
236
|
+
|
|
237
|
+
crate::utils::stamp_plugin_host_state_all(&self.viewer_elem);
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
pub fn is_settings_open(&self) -> bool {
|
|
@@ -652,10 +654,12 @@ impl Presentation {
|
|
|
652
654
|
_ => None,
|
|
653
655
|
};
|
|
654
656
|
|
|
655
|
-
self.
|
|
657
|
+
self.reset_drag_state();
|
|
656
658
|
if let Some(action) = action {
|
|
657
659
|
self.drop_received.emit(action);
|
|
658
660
|
}
|
|
661
|
+
|
|
662
|
+
self.emit_drag_end();
|
|
659
663
|
}
|
|
660
664
|
|
|
661
665
|
/// Start the drag/drop action with the name of the column being dragged.
|
|
@@ -681,11 +685,26 @@ impl Presentation {
|
|
|
681
685
|
}
|
|
682
686
|
|
|
683
687
|
fn end_drag(&self) {
|
|
688
|
+
self.reset_drag_state();
|
|
689
|
+
self.emit_drag_end();
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
fn reset_drag_state(&self) {
|
|
684
693
|
self.drag_target.borrow_mut().take();
|
|
685
694
|
*self.drag_state.borrow_mut() = DragState::NoDrag;
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/// Notify the root one microtask late, so a drop's config edit (itself
|
|
698
|
+
/// notified through a microtask) lands in the same render batch.
|
|
699
|
+
fn emit_drag_end(&self) {
|
|
700
|
+
let emit = self.on_dragend.borrow().clone();
|
|
701
|
+
ApiFuture::spawn(async move {
|
|
702
|
+
if let Some(cb) = emit {
|
|
703
|
+
cb.emit(());
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
Ok(())
|
|
707
|
+
});
|
|
689
708
|
}
|
|
690
709
|
|
|
691
710
|
/// Register a `dragend` listener on the host `<perspective-viewer>`
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
|
|
11
11
|
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
|
|
12
12
|
|
|
13
|
-
use perspective_client::config::ViewConfig;
|
|
13
|
+
use perspective_client::config::{ColumnType, ViewConfig};
|
|
14
14
|
|
|
15
15
|
use crate::presentation::{ColumnLocator, ColumnSettingsTarget, OpenColumnSettings};
|
|
16
16
|
use crate::renderer::Renderer;
|
|
@@ -37,11 +37,62 @@ pub fn classify_column(
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
/// Whether `name` is one of `view_config`'s pivots, whose own raw values a
|
|
41
|
+
/// plugin draws as a header label or axis tick and therefore formats with its
|
|
42
|
+
/// TABLE type rather than an aggregate's view type.
|
|
43
|
+
pub fn is_pivot_column(name: &str, view_config: &ViewConfig) -> bool {
|
|
44
|
+
view_config.group_by.iter().any(|col| col == name)
|
|
45
|
+
|| view_config.split_by.iter().any(|col| col == name)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Whether `name` is configured AS a pivot: a pivot that is also in `columns`
|
|
49
|
+
/// is configured as that aggregate instead, so its pivot copy is not
|
|
50
|
+
/// separately configurable.
|
|
51
|
+
pub fn is_pivot_only_column(name: &str, view_config: &ViewConfig) -> bool {
|
|
52
|
+
is_pivot_column(name, view_config)
|
|
53
|
+
&& !view_config
|
|
54
|
+
.columns
|
|
55
|
+
.iter()
|
|
56
|
+
.any(|col| col.as_deref() == Some(name))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Whether the active plugin offers `name` any column config, gating every
|
|
60
|
+
/// affordance that opens the Style tab.
|
|
61
|
+
// TODO This hardcodes the set of types a plugin offers a pivot a format control
|
|
62
|
+
// for, instead of asking it. `get_column_config_schema` answers exactly
|
|
63
|
+
// (`!schema.leaf_fields().is_empty()`) but costs a plugin call per pivot pill
|
|
64
|
+
// per render; switch to it if pills ever outgrow a handful, or if a plugin's
|
|
65
|
+
// pivot controls stop being format-only.
|
|
66
|
+
pub fn has_column_config(
|
|
67
|
+
name: &str,
|
|
68
|
+
view_config: &ViewConfig,
|
|
69
|
+
metadata: &SessionMetadata,
|
|
70
|
+
renderer: &Renderer,
|
|
71
|
+
) -> bool {
|
|
72
|
+
if !renderer.can_render_column_styles() {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if view_config
|
|
77
|
+
.columns
|
|
78
|
+
.iter()
|
|
79
|
+
.any(|col| col.as_deref() == Some(name))
|
|
80
|
+
{
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
is_pivot_column(name, view_config)
|
|
85
|
+
&& matches!(
|
|
86
|
+
metadata.get_column_table_type(name),
|
|
87
|
+
Some(ColumnType::Integer | ColumnType::Float | ColumnType::Date | ColumnType::Datetime)
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
40
91
|
/// Gets a [`ColumnLocator`] for the current UI's column settings state,
|
|
41
92
|
/// or [`None`] if it is not currently active.
|
|
42
93
|
///
|
|
43
|
-
/// Table columns only have a useful sidebar (the Style tab)
|
|
44
|
-
///
|
|
94
|
+
/// Table columns only have a useful sidebar (the Style tab) when they're in
|
|
95
|
+
/// `view_config.columns` or are a pivot.
|
|
45
96
|
pub fn get_current_column_locator(
|
|
46
97
|
open_column_settings: &OpenColumnSettings,
|
|
47
98
|
renderer: &Renderer,
|
|
@@ -54,54 +105,10 @@ pub fn get_current_column_locator(
|
|
|
54
105
|
let locator = classify_column(name, view_config, metadata)?;
|
|
55
106
|
match locator {
|
|
56
107
|
ColumnLocator::Table(_) => {
|
|
57
|
-
|
|
58
|
-
maybe_col
|
|
59
|
-
.as_ref()
|
|
60
|
-
.map(|col| col == name)
|
|
61
|
-
.unwrap_or_default()
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
(in_columns && renderer.can_render_column_styles()).then_some(locator)
|
|
108
|
+
has_column_config(name, view_config, metadata, renderer).then_some(locator)
|
|
65
109
|
},
|
|
66
110
|
locator => Some(locator),
|
|
67
111
|
}
|
|
68
112
|
},
|
|
69
113
|
}
|
|
70
114
|
}
|
|
71
|
-
|
|
72
|
-
#[cfg(test)]
|
|
73
|
-
mod tests {
|
|
74
|
-
use std::collections::HashMap;
|
|
75
|
-
|
|
76
|
-
use perspective_client::config::Expressions;
|
|
77
|
-
|
|
78
|
-
use super::*;
|
|
79
|
-
|
|
80
|
-
fn config_with_expression(name: &str, expr: &str) -> ViewConfig {
|
|
81
|
-
ViewConfig {
|
|
82
|
-
expressions: Expressions(HashMap::from([(name.to_owned(), expr.to_owned())])),
|
|
83
|
-
..ViewConfig::default()
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
#[test]
|
|
88
|
-
fn classifies_from_the_config_before_metadata_catches_up() {
|
|
89
|
-
let config = config_with_expression("x", "1 + 1");
|
|
90
|
-
let metadata = SessionMetadata::default();
|
|
91
|
-
assert_eq!(
|
|
92
|
-
classify_column("x", &config, &metadata),
|
|
93
|
-
Some(ColumnLocator::Expression("x".to_owned()))
|
|
94
|
-
);
|
|
95
|
-
assert_eq!(classify_column("nope", &config, &metadata), None);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
#[test]
|
|
99
|
-
fn unnamed_expressions_are_keyed_by_their_text() {
|
|
100
|
-
let config = config_with_expression("\"Sales\" + 1", "\"Sales\" + 1");
|
|
101
|
-
let metadata = SessionMetadata::default();
|
|
102
|
-
assert_eq!(
|
|
103
|
-
classify_column("\"Sales\" + 1", &config, &metadata),
|
|
104
|
-
Some(ColumnLocator::Expression("\"Sales\" + 1".to_owned()))
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -26,7 +26,7 @@ pub async fn get_viewer_config(
|
|
|
26
26
|
session: &Session,
|
|
27
27
|
renderer: &Renderer,
|
|
28
28
|
presentation: &Presentation,
|
|
29
|
-
) -> ApiResult<ViewerConfig
|
|
29
|
+
) -> ApiResult<ViewerConfig<String, String>> {
|
|
30
30
|
let version = config::API_VERSION.to_string();
|
|
31
31
|
let mut view_config = if let Some(rendered) = session.get_rendered_view_config() {
|
|
32
32
|
(*rendered).clone()
|
|
@@ -13,22 +13,12 @@
|
|
|
13
13
|
use itertools::Itertools;
|
|
14
14
|
use perspective_client::config::ViewConfig;
|
|
15
15
|
use perspective_js::utils::{ApiResult, JsValueSerdeExt};
|
|
16
|
-
use serde::Serialize;
|
|
17
16
|
|
|
17
|
+
use super::column_locator::is_pivot_only_column;
|
|
18
18
|
use crate::config::ColumnConfigSchema;
|
|
19
|
-
use crate::renderer::Renderer;
|
|
19
|
+
use crate::renderer::{ColumnRole, Renderer};
|
|
20
20
|
use crate::session::SessionMetadata;
|
|
21
21
|
|
|
22
|
-
/// Stats payload passed to `plugin.column_config_schema` as the
|
|
23
|
-
/// `column_stats` arg. The caller (e.g. the StyleTab) owns the value —
|
|
24
|
-
/// typically populated by `fetch_column_abs_max` resolving into a
|
|
25
|
-
/// component-local `use_state`. Missing when no fetch has resolved yet.
|
|
26
|
-
#[derive(Default, Serialize)]
|
|
27
|
-
struct ColumnStats {
|
|
28
|
-
#[serde(skip_serializing_if = "Option::is_none")]
|
|
29
|
-
abs_max: Option<f64>,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
22
|
/// Queries the active plugin for its plugin-scoped [`ColumnConfigSchema`] as
|
|
33
23
|
/// it applies to `current_value`.
|
|
34
24
|
pub fn get_plugin_config_schema(
|
|
@@ -51,10 +41,6 @@ pub fn get_plugin_config_schema(
|
|
|
51
41
|
///
|
|
52
42
|
/// `current_value` is the column's existing flat JSON config (if any);
|
|
53
43
|
/// plugins use it to dynamically gate fields based on prior state.
|
|
54
|
-
/// `abs_max` is the caller-owned numeric stat (typically a Yew
|
|
55
|
-
/// `use_state` populated by an in-flight `fetch_column_abs_max` task);
|
|
56
|
-
/// `None` means the fetch has not yet resolved and gradient defaults
|
|
57
|
-
/// fall back to 0.
|
|
58
44
|
pub fn get_column_config_schema(
|
|
59
45
|
renderer: &Renderer,
|
|
60
46
|
view_config: &ViewConfig,
|
|
@@ -73,9 +59,22 @@ pub fn get_column_config_schema(
|
|
|
73
59
|
.and_then(|(idx, _)| names.get(idx))
|
|
74
60
|
.map(|s| s.as_str());
|
|
75
61
|
|
|
76
|
-
let
|
|
77
|
-
|
|
62
|
+
let role = if !is_pivot_only_column(column_name, view_config) {
|
|
63
|
+
ColumnRole::Column
|
|
64
|
+
} else if view_config.split_by.iter().any(|x| x == column_name) {
|
|
65
|
+
ColumnRole::SplitBy
|
|
78
66
|
} else {
|
|
67
|
+
ColumnRole::GroupBy
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let view_type = match role {
|
|
71
|
+
ColumnRole::Column => metadata.get_column_view_type(column_name),
|
|
72
|
+
_ => metadata
|
|
73
|
+
.get_column_table_type(column_name)
|
|
74
|
+
.or_else(|| metadata.get_column_view_type(column_name)),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let Some(view_type) = view_type else {
|
|
79
78
|
return Ok(ColumnConfigSchema { fields: vec![] });
|
|
80
79
|
};
|
|
81
80
|
|
|
@@ -87,9 +86,8 @@ pub fn get_column_config_schema(
|
|
|
87
86
|
let view_config_js =
|
|
88
87
|
wasm_bindgen::JsValue::from_serde_ext(view_config).unwrap_or(wasm_bindgen::JsValue::NULL);
|
|
89
88
|
|
|
90
|
-
let
|
|
91
|
-
|
|
92
|
-
wasm_bindgen::JsValue::from_serde_ext(&stats).unwrap_or(wasm_bindgen::JsValue::NULL);
|
|
89
|
+
let plugin_config_js = wasm_bindgen::JsValue::from_serde_ext(&renderer.get_plugin_config())
|
|
90
|
+
.unwrap_or(wasm_bindgen::JsValue::NULL);
|
|
93
91
|
|
|
94
92
|
let raw = plugin._column_config_schema(
|
|
95
93
|
&view_type.to_string(),
|
|
@@ -97,10 +95,11 @@ pub fn get_column_config_schema(
|
|
|
97
95
|
column_name,
|
|
98
96
|
¤t_js,
|
|
99
97
|
&view_config_js,
|
|
100
|
-
&
|
|
98
|
+
&plugin_config_js,
|
|
99
|
+
role.as_str(),
|
|
101
100
|
)?;
|
|
102
101
|
|
|
103
102
|
serde_wasm_bindgen::from_value::<ColumnConfigSchema>(raw)
|
|
104
|
-
.map(|schema| schema.canonicalize())
|
|
103
|
+
.map(|schema| schema.canonicalize().resolve_stat_defaults(abs_max))
|
|
105
104
|
.map_err(|e| e.into())
|
|
106
105
|
}
|
|
@@ -43,6 +43,8 @@ impl Renderer {
|
|
|
43
43
|
let is_solo = self.0.is_solo_panel.get();
|
|
44
44
|
let _ = el.class_list().toggle_with_force("single", is_solo);
|
|
45
45
|
let _ = el.class_list().toggle_with_force("multi", !is_solo);
|
|
46
|
+
let viewer = self.plugin_data.borrow().viewer_elem.clone();
|
|
47
|
+
stamp_plugin_host_state(&viewer, el);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
pub fn stamp_theme(&self, plugin: Option<&JsPerspectiveViewerPlugin>) {
|