@perspective-dev/viewer 4.5.2 → 5.1.0
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/dist/cdn/perspective-viewer.js +20 -1
- package/dist/cdn/perspective-viewer.js.map +4 -4
- package/dist/css/botanical.css +1 -1
- package/dist/css/dracula.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/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/monokai.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/esm/extensions.d.ts +22 -3
- package/dist/esm/perspective-viewer.d.ts +9 -0
- package/dist/esm/perspective-viewer.inline.js +20 -1
- package/dist/esm/perspective-viewer.inline.js.map +4 -4
- package/dist/esm/perspective-viewer.js +20 -1
- package/dist/esm/perspective-viewer.js.map +4 -4
- package/dist/esm/plugin.d.ts +71 -5
- package/dist/esm/ts-rs/ClientOptions.d.ts +7 -0
- package/dist/esm/ts-rs/ExportMethod.d.ts +1 -0
- package/dist/esm/ts-rs/ExportOptions.d.ts +9 -0
- package/dist/esm/ts-rs/GetClientOptions.d.ts +8 -0
- package/dist/esm/ts-rs/GetTableOptions.d.ts +8 -0
- package/dist/esm/ts-rs/Layout.d.ts +11 -0
- package/dist/esm/ts-rs/Orientation.d.ts +4 -0
- package/dist/esm/ts-rs/PanelOptions.d.ts +7 -0
- package/dist/esm/ts-rs/PanelViewerConfig.d.ts +41 -0
- package/dist/esm/ts-rs/SplitLayout.d.ts +7 -0
- package/dist/esm/ts-rs/TabLayout.d.ts +10 -0
- package/dist/esm/ts-rs/ViewerConfig.d.ts +8 -2
- package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +9 -0
- package/dist/esm/ts-rs/WindowAggregate.d.ts +1 -0
- package/dist/esm/ts-rs/WindowSort.d.ts +7 -0
- package/dist/esm/ts-rs/WindowSortDir.d.ts +6 -0
- package/dist/esm/ts-rs/WindowSpec.d.ts +46 -0
- package/dist/esm/ts-rs/Windows.d.ts +10 -0
- package/dist/esm/ts-rs/WorkspaceConfig.d.ts +40 -0
- package/dist/esm/ts-rs/WorkspaceConfigUpdate.d.ts +28 -0
- package/dist/wasm/perspective-viewer.d.ts +299 -78
- package/dist/wasm/perspective-viewer.js +544 -186
- package/dist/wasm/perspective-viewer.wasm +0 -0
- package/dist/wasm/perspective-viewer.wasm.d.ts +34 -26
- package/dist/wasm/snippets/perspective-viewer-8a8c7d5d696b43ae/inline0.js +6 -0
- package/dist/wasm/snippets/{perspective-viewer-93064d0d79855d97/inline3.js → perspective-viewer-8a8c7d5d696b43ae/inline4.js} +5 -0
- package/package.json +3 -2
- package/src/css/_context_menu.css +14 -0
- package/src/css/column-selector.css +1 -0
- package/src/css/column-settings-panel.css +68 -3
- package/src/css/column-style.css +4 -3
- package/src/css/config-selector.css +22 -1
- package/src/css/containers/context-menu.css +107 -0
- package/src/css/containers/tabs.css +2 -2
- package/src/css/panel-tab.css +193 -0
- package/src/css/plugin-selector.css +7 -10
- package/src/css/status-bar.css +75 -81
- package/src/css/viewer.css +188 -70
- package/src/rust/components/column_dropdown.rs +40 -30
- package/src/rust/components/column_selector/active_column.rs +28 -45
- package/src/rust/components/column_selector/aggregate_selector.rs +4 -7
- package/src/rust/components/column_selector/column_selector_column_row.rs +73 -0
- package/src/rust/components/column_selector/config_selector.rs +40 -82
- package/src/rust/components/column_selector/expr_edit_button.rs +7 -1
- package/src/rust/components/column_selector/filter_column.rs +5 -15
- package/src/rust/components/column_selector/inactive_column.rs +11 -9
- package/src/rust/components/column_selector/sort_column.rs +3 -6
- package/src/rust/components/column_selector.rs +25 -14
- package/src/rust/components/column_settings_sidebar/style_tab.rs +2 -1
- package/src/rust/components/column_settings_sidebar/window_tab.rs +34 -0
- package/src/rust/components/column_settings_sidebar.rs +163 -16
- package/src/rust/components/containers/dragdrop_list.rs +73 -3
- package/src/rust/components/containers/sidebar.rs +99 -22
- package/src/rust/components/containers/split_panel.rs +181 -62
- package/src/rust/components/context_menu.rs +130 -0
- package/src/rust/components/editable_header.rs +2 -0
- package/src/rust/components/form/debug.rs +3 -0
- package/src/rust/components/global_filter_bar.rs +76 -0
- package/src/rust/components/main_panel/frame_theme.rs +186 -0
- package/src/rust/components/main_panel/msg.rs +62 -0
- package/src/rust/components/main_panel/presize.rs +220 -0
- package/src/rust/components/main_panel/reconcile.rs +224 -0
- package/src/rust/components/main_panel/render.rs +385 -0
- package/src/rust/components/main_panel/update.rs +184 -0
- package/src/rust/components/main_panel.rs +316 -71
- package/src/rust/components/mod.rs +5 -0
- package/src/rust/components/panel_menu.rs +493 -0
- package/src/rust/components/panel_tab.rs +510 -0
- package/src/rust/components/plugin_tab.rs +1 -1
- package/src/rust/components/portal.rs +7 -0
- package/src/rust/components/settings_panel.rs +13 -5
- package/src/rust/components/status_bar.rs +110 -178
- package/src/rust/components/status_indicator.rs +6 -9
- package/src/rust/components/style/mod.rs +5 -0
- package/src/rust/components/style/style_provider.rs +2 -0
- package/src/rust/components/viewer/filters.rs +133 -0
- package/src/rust/components/viewer/msg.rs +182 -0
- package/src/rust/components/viewer/panels.rs +326 -0
- package/src/rust/components/viewer/render.rs +255 -0
- package/src/rust/components/viewer/settings.rs +434 -0
- package/src/rust/components/viewer/snapshots.rs +134 -0
- package/src/rust/components/viewer/wiring.rs +505 -0
- package/src/rust/components/viewer.rs +245 -756
- package/src/rust/components/window_editor.rs +1013 -0
- package/src/rust/config/export_method.rs +1 -1
- package/src/rust/config/mod.rs +4 -0
- package/src/rust/config/options.rs +71 -0
- package/src/rust/config/viewer_config.rs +24 -2
- package/src/rust/config/workspace_config.rs +92 -0
- package/src/rust/custom_elements/copy_dropdown.rs +3 -1
- package/src/rust/custom_elements/debug_plugin.rs +20 -1
- package/src/rust/custom_elements/export_dropdown.rs +3 -1
- package/src/rust/custom_elements/viewer.rs +1015 -286
- package/src/rust/custom_events.rs +212 -61
- package/src/rust/js/mod.rs +2 -0
- package/src/rust/js/plugin.rs +297 -10
- package/src/rust/js/regular_layout.rs +258 -0
- package/src/rust/lib.rs +24 -2
- package/src/rust/presentation/column_locator.rs +16 -1
- package/src/rust/presentation.rs +66 -33
- package/src/rust/queries/columns_iter_set.rs +7 -1
- package/src/rust/queries/get_viewer_config.rs +29 -11
- package/src/rust/queries/plugin_column_styles.rs +2 -2
- package/src/rust/renderer/activate.rs +41 -14
- package/src/rust/renderer/dispatch.rs +463 -0
- package/src/rust/renderer/plugin_config.rs +495 -0
- package/src/rust/renderer/registry.rs +18 -6
- package/src/rust/renderer/render_timer.rs +29 -10
- package/src/rust/renderer.rs +384 -838
- package/src/rust/session/column_defaults_update.rs +26 -8
- package/src/rust/session/drag_drop_update.rs +18 -0
- package/src/rust/session/metadata.rs +66 -9
- package/src/rust/session/replace_expression_update.rs +1 -0
- package/src/rust/session/view_subscription.rs +30 -15
- package/src/rust/session.rs +755 -264
- package/src/rust/tasks/apply_global_filters.rs +89 -0
- package/src/rust/tasks/auto_pause.rs +171 -0
- package/src/rust/tasks/copy_export.rs +29 -19
- package/src/rust/tasks/create_panel.rs +243 -0
- package/src/rust/tasks/dismiss_render_warning.rs +3 -1
- package/src/rust/tasks/edit_expression.rs +4 -4
- package/src/rust/tasks/edit_window.rs +155 -0
- package/src/rust/tasks/eject.rs +64 -23
- package/src/rust/tasks/mod.rs +30 -4
- package/src/rust/tasks/pipeline.rs +411 -0
- package/src/rust/tasks/presize_panels.rs +324 -0
- package/src/rust/tasks/reset_all.rs +22 -12
- package/src/rust/tasks/resize_observer.rs +124 -87
- package/src/rust/tasks/restore_and_render.rs +80 -86
- package/src/rust/tasks/restore_panel.rs +145 -0
- package/src/rust/tasks/send_column_config.rs +5 -2
- package/src/rust/tasks/send_plugin_config.rs +5 -2
- package/src/rust/tasks/set_edit_mode.rs +59 -0
- package/src/rust/tasks/sync_update_panels.rs +152 -0
- package/src/rust/tasks/table_lifecycle.rs +158 -0
- package/src/rust/tasks/update_theme.rs +56 -12
- package/src/rust/utils/browser/dragdrop.rs +12 -0
- package/src/rust/utils/browser/tests/debounce.rs +49 -0
- package/src/rust/utils/completion.rs +56 -0
- package/src/rust/utils/custom_element.rs +5 -0
- package/src/rust/utils/debounce.rs +189 -17
- package/src/rust/utils/mod.rs +6 -0
- package/src/rust/utils/pending_effects.rs +62 -0
- package/src/rust/utils/spawn.rs +33 -0
- package/src/rust/utils/weak_scope.rs +0 -10
- package/src/rust/workspace.rs +846 -0
- package/src/svg/active-indicator.svg +3 -0
- package/src/svg/pin-icon.svg +5 -0
- package/src/themes/botanical.css +5 -2
- package/src/themes/defaults.css +54 -2
- package/src/themes/dracula.css +6 -3
- package/src/themes/gruvbox-dark.css +5 -2
- package/src/themes/gruvbox.css +5 -2
- package/src/themes/icons.css +5 -2
- package/src/themes/intl/de.css +7 -0
- package/src/themes/intl/es.css +7 -0
- package/src/themes/intl/fr.css +7 -0
- package/src/themes/intl/ja.css +7 -0
- package/src/themes/intl/pt.css +7 -0
- package/src/themes/intl/zh.css +7 -0
- package/src/themes/intl.css +10 -1
- package/src/themes/monokai.css +5 -2
- package/src/themes/phosphor.css +5 -2
- package/src/themes/pro-dark.css +5 -2
- package/src/themes/pro.css +2 -1
- package/src/themes/solarized-dark.css +5 -2
- package/src/themes/solarized.css +5 -2
- package/src/themes/vaporwave.css +5 -2
- package/src/ts/bootstrap.ts +8 -7
- package/src/ts/extensions.ts +30 -2
- package/src/ts/perspective-viewer.ts +10 -0
- package/src/ts/plugin.ts +72 -5
- package/src/ts/ts-rs/ClientOptions.ts +7 -0
- package/src/ts/ts-rs/ExportMethod.ts +3 -0
- package/src/ts/ts-rs/ExportOptions.ts +8 -0
- package/src/ts/ts-rs/GetClientOptions.ts +7 -0
- package/src/ts/ts-rs/GetTableOptions.ts +7 -0
- package/src/ts/ts-rs/Layout.ts +9 -0
- package/src/ts/ts-rs/Orientation.ts +6 -0
- package/src/ts/ts-rs/PanelOptions.ts +7 -0
- package/src/ts/ts-rs/PanelViewerConfig.ts +16 -0
- package/src/ts/ts-rs/SplitLayout.ts +5 -0
- package/src/ts/ts-rs/TabLayout.ts +11 -0
- package/src/ts/ts-rs/ViewerConfig.ts +7 -2
- package/src/ts/ts-rs/ViewerConfigUpdate.ts +9 -0
- package/src/ts/ts-rs/WindowAggregate.ts +3 -0
- package/src/ts/ts-rs/WindowSort.ts +9 -0
- package/src/ts/ts-rs/WindowSortDir.ts +8 -0
- package/src/ts/ts-rs/WindowSpec.ts +46 -0
- package/src/ts/ts-rs/Windows.ts +10 -0
- package/src/ts/ts-rs/WorkspaceConfig.ts +36 -0
- package/src/ts/ts-rs/WorkspaceConfigUpdate.ts +24 -0
- package/src/rust/tasks/intersection_observer.rs +0 -98
- package/src/rust/tasks/update_and_render.rs +0 -110
- /package/dist/wasm/snippets/{perspective-viewer-93064d0d79855d97/inline0.js → perspective-viewer-8a8c7d5d696b43ae/inline1.js} +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-93064d0d79855d97/inline1.js → perspective-viewer-8a8c7d5d696b43ae/inline2.js} +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-93064d0d79855d97/inline2.js → perspective-viewer-8a8c7d5d696b43ae/inline3.js} +0 -0
- /package/dist/wasm/snippets/{perspective-viewer-93064d0d79855d97/inline4.js → perspective-viewer-8a8c7d5d696b43ae/inline5.js} +0 -0
|
@@ -0,0 +1,463 @@
|
|
|
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
|
+
//! The [`Renderer`]'s LOCKED dispatch tier: everything that touches the
|
|
14
|
+
//! active plugin element under the per-renderer draw lock — the
|
|
15
|
+
//! `render_task` pipeline entry, the `draw_fresh`/`update_bound` dispatches,
|
|
16
|
+
//! restyle, resize and the presize protocol.
|
|
17
|
+
|
|
18
|
+
use std::future::Future;
|
|
19
|
+
use std::rc::Rc;
|
|
20
|
+
|
|
21
|
+
use perspective_client::View;
|
|
22
|
+
use perspective_js::utils::{ApiResult, ResultTApiErrorExt};
|
|
23
|
+
use wasm_bindgen::prelude::*;
|
|
24
|
+
use web_sys::*;
|
|
25
|
+
|
|
26
|
+
use super::activate::*;
|
|
27
|
+
use super::limits::*;
|
|
28
|
+
use super::{ContextPin, GeometryCmd, RenderContext, Renderer, SUBPIXEL_EPSILON};
|
|
29
|
+
use crate::js::plugin::*;
|
|
30
|
+
use crate::session::FreshView;
|
|
31
|
+
use crate::utils::*;
|
|
32
|
+
|
|
33
|
+
impl Renderer {
|
|
34
|
+
/// Toggle the `active` and panel-count (`single`/`multi`) classes on
|
|
35
|
+
/// `plugin`.
|
|
36
|
+
fn stamp_active(&self, plugin: &JsPerspectiveViewerPlugin) {
|
|
37
|
+
let el = plugin.unchecked_ref::<HtmlElement>();
|
|
38
|
+
let _ = el
|
|
39
|
+
.class_list()
|
|
40
|
+
.toggle_with_force("active", self.0.is_active_panel.get());
|
|
41
|
+
|
|
42
|
+
let is_solo = self.0.is_solo_panel.get();
|
|
43
|
+
let _ = el.class_list().toggle_with_force("single", is_solo);
|
|
44
|
+
let _ = el.class_list().toggle_with_force("multi", !is_solo);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Stamp this panel's effective `theme` attribute.
|
|
48
|
+
pub fn stamp_theme(&self, plugin: Option<&JsPerspectiveViewerPlugin>) {
|
|
49
|
+
let active_plugin = self.active_plugin();
|
|
50
|
+
if let Some(plugin) = plugin.or(active_plugin.as_ref()) {
|
|
51
|
+
let theme_elem = plugin.unchecked_ref::<HtmlElement>();
|
|
52
|
+
match self.effective_theme() {
|
|
53
|
+
Some(theme)
|
|
54
|
+
if theme_elem.get_attribute("theme").as_deref() != Some(theme.as_str()) =>
|
|
55
|
+
{
|
|
56
|
+
let _ = theme_elem.set_attribute("theme", &theme);
|
|
57
|
+
},
|
|
58
|
+
Some(_) => {},
|
|
59
|
+
None => {
|
|
60
|
+
let _ = theme_elem.remove_attribute("theme");
|
|
61
|
+
},
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Restyle the active plugin and re-draw.
|
|
67
|
+
pub async fn restyle_all(&self) -> ApiResult<JsValue> {
|
|
68
|
+
self.render_task(|guard| async move {
|
|
69
|
+
let Some(ctx) = self.cached_context() else {
|
|
70
|
+
return Ok(JsValue::UNDEFINED);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
let _pin = self.pin_context(&guard, ctx.clone());
|
|
74
|
+
let plugin = self.ensure_plugin_selected()?;
|
|
75
|
+
let meta = self.metadata();
|
|
76
|
+
let stamped_theme = self.effective_theme();
|
|
77
|
+
self.stamp_theme(Some(&plugin));
|
|
78
|
+
self.stamp_active(&plugin);
|
|
79
|
+
plugin.restyle();
|
|
80
|
+
*self.0.captured_theme.borrow_mut() = Some(stamped_theme);
|
|
81
|
+
let mut limits =
|
|
82
|
+
get_row_and_col_limits(&ctx.view, &meta, self.is_render_warning_enabled()).await?;
|
|
83
|
+
|
|
84
|
+
limits.is_update = true;
|
|
85
|
+
plugin
|
|
86
|
+
.update(
|
|
87
|
+
ctx.view.clone().into(),
|
|
88
|
+
limits.max_cols,
|
|
89
|
+
limits.max_rows,
|
|
90
|
+
false,
|
|
91
|
+
)
|
|
92
|
+
.await?;
|
|
93
|
+
|
|
94
|
+
Ok(JsValue::UNDEFINED)
|
|
95
|
+
})
|
|
96
|
+
.await
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
pub async fn with_lock<T>(self, task: impl Future<Output = ApiResult<T>>) -> ApiResult<T> {
|
|
100
|
+
let draw_mutex = self.draw_lock();
|
|
101
|
+
draw_mutex.lock(task).await
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// The [`RenderContext`] pinned by the run currently holding this
|
|
105
|
+
/// renderer's draw lock, if any. The per-panel element getters answer
|
|
106
|
+
/// from this when present (invariant I5).
|
|
107
|
+
pub fn render_context(&self) -> Option<Rc<RenderContext>> {
|
|
108
|
+
self.0.active_context.borrow().clone()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// The cached [`RenderContext`] of the currently-bound `View` (set by
|
|
112
|
+
/// the pipeline at bind time).
|
|
113
|
+
pub fn cached_context(&self) -> Option<Rc<RenderContext>> {
|
|
114
|
+
self.0.cached_context.borrow().clone()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// Cache `ctx` as the bound view's context (pipeline, at bind time).
|
|
118
|
+
pub fn set_cached_context(&self, ctx: Rc<RenderContext>) {
|
|
119
|
+
*self.0.cached_context.borrow_mut() = Some(ctx);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Pin `ctx` as the active [`RenderContext`] for the duration of the
|
|
123
|
+
/// returned RAII guard. Requires the lock witness — a context can only
|
|
124
|
+
/// be pinned by a locked run.
|
|
125
|
+
pub fn pin_context(&self, _guard: &RenderGuard, ctx: Rc<RenderContext>) -> ContextPin {
|
|
126
|
+
*self.0.active_context.borrow_mut() = Some(ctx);
|
|
127
|
+
ContextPin(self.clone())
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// `true` while a run is executing on this renderer's draw lock.
|
|
131
|
+
pub fn is_locked(&self) -> bool {
|
|
132
|
+
self.draw_lock.is_held()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
pub async fn resize(&self) -> ApiResult<()> {
|
|
136
|
+
self.0.geometry_cmd.set(Some(GeometryCmd::Measure));
|
|
137
|
+
self.geometry_task().await.map(|_| ())
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Public one-shot resize to explicit dimensions (`viewer.resize({
|
|
141
|
+
/// dimensions })`).
|
|
142
|
+
pub async fn resize_with_dimensions(&self, width: f64, height: f64) -> ApiResult<()> {
|
|
143
|
+
if let Some(present) = self.presize_with_dimensions(width, height).await? {
|
|
144
|
+
present.call0(&JsValue::NULL)?;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
Ok(())
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/// Render every changed pixel of a pending `(width, height)` box.
|
|
151
|
+
pub async fn presize_with_dimensions(
|
|
152
|
+
&self,
|
|
153
|
+
width: f64,
|
|
154
|
+
height: f64,
|
|
155
|
+
) -> ApiResult<Option<js_sys::Function>> {
|
|
156
|
+
self.0.presize_pending.set(self.0.presize_pending.get() + 1);
|
|
157
|
+
let result = self.presize_inner(None, width, height).await;
|
|
158
|
+
self.0.presize_pending.set(self.0.presize_pending.get() - 1);
|
|
159
|
+
result
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Pre-size AND pre-position the plugin to its target layout bo.
|
|
163
|
+
pub async fn presize_with_box(
|
|
164
|
+
&self,
|
|
165
|
+
dx: f64,
|
|
166
|
+
dy: f64,
|
|
167
|
+
width: f64,
|
|
168
|
+
height: f64,
|
|
169
|
+
) -> ApiResult<Option<js_sys::Function>> {
|
|
170
|
+
self.0.presize_pending.set(self.0.presize_pending.get() + 1);
|
|
171
|
+
let result = self.presize_inner(Some((dx, dy)), width, height).await;
|
|
172
|
+
self.0.presize_pending.set(self.0.presize_pending.get() - 1);
|
|
173
|
+
result
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async fn presize_inner(
|
|
177
|
+
&self,
|
|
178
|
+
translate: Option<(f64, f64)>,
|
|
179
|
+
width: f64,
|
|
180
|
+
height: f64,
|
|
181
|
+
) -> ApiResult<Option<js_sys::Function>> {
|
|
182
|
+
self.0.geometry_cmd.set(Some(GeometryCmd::Presize {
|
|
183
|
+
translate,
|
|
184
|
+
width,
|
|
185
|
+
height,
|
|
186
|
+
}));
|
|
187
|
+
|
|
188
|
+
self.geometry_task().await
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/// Run the LATEST queued [`GeometryCmd`] on the geometry debounce slot.
|
|
192
|
+
async fn geometry_task(&self) -> ApiResult<Option<js_sys::Function>> {
|
|
193
|
+
let timer = self.render_timer();
|
|
194
|
+
self.0
|
|
195
|
+
.geometry_slot
|
|
196
|
+
.clone()
|
|
197
|
+
.debounce_with(|_guard| async move {
|
|
198
|
+
let Some(cmd) = self.0.geometry_cmd.take() else {
|
|
199
|
+
return Ok(None);
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
match cmd {
|
|
203
|
+
GeometryCmd::Measure => {
|
|
204
|
+
set_timeout(timer.get_throttle()).await?;
|
|
205
|
+
let Some(jsplugin) = self.active_plugin() else {
|
|
206
|
+
return Ok(None);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
self.stamp_active(&jsplugin);
|
|
210
|
+
jsplugin.resize().await?;
|
|
211
|
+
Ok(None)
|
|
212
|
+
},
|
|
213
|
+
GeometryCmd::Presize {
|
|
214
|
+
translate,
|
|
215
|
+
width,
|
|
216
|
+
height,
|
|
217
|
+
} => self.run_presize(translate, width, height).await,
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
.await
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async fn run_presize(
|
|
224
|
+
&self,
|
|
225
|
+
translate: Option<(f64, f64)>,
|
|
226
|
+
width: f64,
|
|
227
|
+
height: f64,
|
|
228
|
+
) -> ApiResult<Option<js_sys::Function>> {
|
|
229
|
+
let Some(plugin) = self.active_plugin() else {
|
|
230
|
+
return Ok(None);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
self.stamp_active(&plugin);
|
|
234
|
+
self.clear_presize()?;
|
|
235
|
+
if plugin.capabilities().presize {
|
|
236
|
+
return plugin.presize(width, height).await;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let main_panel: &web_sys::HtmlElement = plugin.unchecked_ref();
|
|
240
|
+
let rect = main_panel.get_bounding_client_rect();
|
|
241
|
+
let size_changed = (height - rect.height()).abs() > SUBPIXEL_EPSILON
|
|
242
|
+
|| (width - rect.width()).abs() > SUBPIXEL_EPSILON;
|
|
243
|
+
|
|
244
|
+
let (dx, dy) = translate.unwrap_or((0.0, 0.0));
|
|
245
|
+
let moved = dx.abs() > SUBPIXEL_EPSILON || dy.abs() > SUBPIXEL_EPSILON;
|
|
246
|
+
if !size_changed && !moved {
|
|
247
|
+
return Ok(None);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if size_changed {
|
|
251
|
+
main_panel
|
|
252
|
+
.style()
|
|
253
|
+
.set_property("width", &format!("{width}px"))?;
|
|
254
|
+
main_panel
|
|
255
|
+
.style()
|
|
256
|
+
.set_property("height", &format!("{height}px"))?;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if moved {
|
|
260
|
+
main_panel
|
|
261
|
+
.style()
|
|
262
|
+
.set_property("transform", &format!("translate({dx}px, {dy}px)"))?;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if size_changed {
|
|
266
|
+
let result = plugin.resize().await;
|
|
267
|
+
if translate.is_none() {
|
|
268
|
+
main_panel.style().set_property("width", "")?;
|
|
269
|
+
main_panel.style().set_property("height", "")?;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
result?;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
Ok(None)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/// Remove the inline presize styles applied by [`Self::presize_with_box`].
|
|
279
|
+
pub fn clear_presize(&self) -> ApiResult<()> {
|
|
280
|
+
if let Some(plugin) = self.active_plugin() {
|
|
281
|
+
let el = plugin.unchecked_ref::<web_sys::HtmlElement>();
|
|
282
|
+
el.style().set_property("width", "")?;
|
|
283
|
+
el.style().set_property("height", "")?;
|
|
284
|
+
el.style().set_property("transform", "")?;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
Ok(())
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
pub async fn render_task<T, F, Fut>(&self, f: F) -> ApiResult<T>
|
|
291
|
+
where
|
|
292
|
+
F: FnOnce(RenderGuard) -> Fut,
|
|
293
|
+
Fut: Future<Output = ApiResult<T>>,
|
|
294
|
+
{
|
|
295
|
+
self.draw_lock().lock_with(f).await
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/// FULL-draw a NEW `View` on the active plugin (`plugin.draw`).
|
|
299
|
+
pub async fn draw_fresh(&self, guard: &RenderGuard, view: FreshView) -> ApiResult<()> {
|
|
300
|
+
let timer = self.render_timer();
|
|
301
|
+
timer
|
|
302
|
+
.capture_time(self.draw_view(guard, view.view(), false))
|
|
303
|
+
.await
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/// Repaint the ALREADY-BOUND `view` on the active plugin.
|
|
307
|
+
pub async fn update_bound(&self, guard: &RenderGuard, view: &View) -> ApiResult<()> {
|
|
308
|
+
let timer = self.render_timer();
|
|
309
|
+
timer.capture_time(self.draw_view(guard, view, true)).await
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/// Mint the [`FreshView`] full-draw witness for a plugin that has never
|
|
313
|
+
/// painted the bound `View`.
|
|
314
|
+
pub fn promote_first_paint(&self, view: &View) -> Option<FreshView> {
|
|
315
|
+
if !self.0.has_drawn.get() {
|
|
316
|
+
Some(FreshView::assert_fresh(view.clone()))
|
|
317
|
+
} else {
|
|
318
|
+
None
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/// Whether the active plugin's element is currently hidden.
|
|
323
|
+
pub fn is_plugin_hidden(&self) -> bool {
|
|
324
|
+
match self.active_plugin() {
|
|
325
|
+
Some(plugin) => plugin
|
|
326
|
+
.unchecked_ref::<web_sys::HtmlElement>()
|
|
327
|
+
.offset_parent()
|
|
328
|
+
.is_none(),
|
|
329
|
+
None => false,
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/// Record a `table_updated` redraw dropped while hidden (see
|
|
334
|
+
/// [`RendererData::data_stale`]).
|
|
335
|
+
pub fn set_data_stale(&self) {
|
|
336
|
+
self.0.data_stale.set(true);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/// Consume the dropped-update marker; the caller owes a full
|
|
340
|
+
/// `plugin.update` dispatch when `true`.
|
|
341
|
+
pub fn take_data_stale(&self) -> bool {
|
|
342
|
+
self.0.data_stale.replace(false)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
pub async fn activation_repaint(&self, _guard: &RenderGuard) -> ApiResult<()> {
|
|
346
|
+
if let Some(plugin) = self.active_plugin() {
|
|
347
|
+
self.stamp_active(&plugin);
|
|
348
|
+
self.stamp_theme(Some(&plugin));
|
|
349
|
+
let _ = plugin.resize().await?;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
Ok(())
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/// Redraw an already-bound view, debounced.
|
|
356
|
+
pub async fn update_lazy(
|
|
357
|
+
&self,
|
|
358
|
+
view: impl Future<Output = ApiResult<Option<View>>>,
|
|
359
|
+
) -> ApiResult<()> {
|
|
360
|
+
let timer = self.render_timer();
|
|
361
|
+
self.draw_lock()
|
|
362
|
+
.debounce_with(|guard| async move {
|
|
363
|
+
set_timeout(timer.get_throttle()).await?;
|
|
364
|
+
if self.0.presize_pending.get() > 0 {
|
|
365
|
+
tracing::debug!("Update skipped, presize pending");
|
|
366
|
+
return Ok(());
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
self.mount_active_plugin()?;
|
|
370
|
+
if let Some(view) = view.await? {
|
|
371
|
+
let _pin = self
|
|
372
|
+
.cached_context()
|
|
373
|
+
.map(|ctx| self.pin_context(&guard, ctx));
|
|
374
|
+
|
|
375
|
+
let timer = self.render_timer();
|
|
376
|
+
timer
|
|
377
|
+
.capture_time(self.draw_view(&guard, &view, true))
|
|
378
|
+
.await
|
|
379
|
+
} else {
|
|
380
|
+
tracing::debug!("Render skipped, no `View` attached");
|
|
381
|
+
Ok(())
|
|
382
|
+
}
|
|
383
|
+
})
|
|
384
|
+
.await
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
async fn draw_view(
|
|
388
|
+
&self,
|
|
389
|
+
_guard: &RenderGuard,
|
|
390
|
+
view: &perspective_client::View,
|
|
391
|
+
is_update: bool,
|
|
392
|
+
) -> ApiResult<()> {
|
|
393
|
+
debug_assert!(
|
|
394
|
+
!is_update || self.cached_context().is_none() || self.render_context().is_some(),
|
|
395
|
+
"I5: RenderContext not pinned at plugin dispatch"
|
|
396
|
+
);
|
|
397
|
+
|
|
398
|
+
let plugin = if is_update {
|
|
399
|
+
match self.active_plugin() {
|
|
400
|
+
Some(plugin) => plugin,
|
|
401
|
+
None => return Ok(()),
|
|
402
|
+
}
|
|
403
|
+
} else {
|
|
404
|
+
self.ensure_plugin_selected()?
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
let meta = self.metadata();
|
|
408
|
+
let mut limits =
|
|
409
|
+
get_row_and_col_limits(view, &meta, self.is_render_warning_enabled()).await?;
|
|
410
|
+
|
|
411
|
+
limits.is_update = is_update;
|
|
412
|
+
if let Some(cb) = self.0.on_render_limits_changed.borrow().as_ref() {
|
|
413
|
+
cb.emit(limits);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
let viewer_elem = self.0.borrow().viewer_elem.clone();
|
|
417
|
+
let slot = self.slot_name();
|
|
418
|
+
let first_paint = !self.0.has_drawn.get();
|
|
419
|
+
let stamped_theme = self.effective_theme();
|
|
420
|
+
self.stamp_active(&plugin);
|
|
421
|
+
self.stamp_theme(Some(&plugin));
|
|
422
|
+
if self.needs_restyle() {
|
|
423
|
+
plugin.restyle();
|
|
424
|
+
*self.0.captured_theme.borrow_mut() = Some(stamped_theme.clone());
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
self.0.data_stale.set(false);
|
|
428
|
+
let result = if is_update {
|
|
429
|
+
let task = plugin.update(view.clone().into(), limits.max_cols, limits.max_rows, false);
|
|
430
|
+
activate_plugin(_guard, &viewer_elem, &plugin, slot.as_deref(), task).await
|
|
431
|
+
} else {
|
|
432
|
+
let task = plugin.draw(view.clone().into(), limits.max_cols, limits.max_rows, false);
|
|
433
|
+
activate_plugin(_guard, &viewer_elem, &plugin, slot.as_deref(), task).await
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
if result.is_ok() {
|
|
437
|
+
self.0.has_drawn.set(true);
|
|
438
|
+
if first_paint {
|
|
439
|
+
*self.0.captured_theme.borrow_mut() = Some(stamped_theme);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
let cleanup = remove_inactive_plugin(
|
|
444
|
+
&viewer_elem,
|
|
445
|
+
&plugin,
|
|
446
|
+
slot.as_deref(),
|
|
447
|
+
self.plugin_data.borrow_mut().plugin_store.plugins(),
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
match result.ignore_view_delete() {
|
|
451
|
+
Err(error) if !self.0.has_drawn.get() => Err(error),
|
|
452
|
+
Err(error) => {
|
|
453
|
+
tracing::warn!("{}", error);
|
|
454
|
+
cleanup
|
|
455
|
+
},
|
|
456
|
+
Ok(_) => cleanup,
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
fn draw_lock(&self) -> DebounceMutex {
|
|
461
|
+
self.draw_lock.clone()
|
|
462
|
+
}
|
|
463
|
+
}
|