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