@perspective-dev/viewer 4.5.1 → 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 (212) 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.cdn.d.ts +3 -0
  18. package/dist/esm/perspective-viewer.d.ts +9 -0
  19. package/dist/esm/perspective-viewer.inline.d.ts +3 -0
  20. package/dist/esm/perspective-viewer.inline.js +20 -1
  21. package/dist/esm/perspective-viewer.inline.js.map +4 -4
  22. package/dist/esm/perspective-viewer.js +20 -1
  23. package/dist/esm/perspective-viewer.js.map +4 -4
  24. package/dist/esm/plugin.d.ts +71 -5
  25. package/dist/esm/ts-rs/ClientOptions.d.ts +7 -0
  26. package/dist/esm/ts-rs/ExportMethod.d.ts +1 -0
  27. package/dist/esm/ts-rs/ExportOptions.d.ts +9 -0
  28. package/dist/esm/ts-rs/GetClientOptions.d.ts +8 -0
  29. package/dist/esm/ts-rs/GetTableOptions.d.ts +8 -0
  30. package/dist/esm/ts-rs/Layout.d.ts +11 -0
  31. package/dist/esm/ts-rs/OnUpdateData.d.ts +6 -0
  32. package/dist/esm/ts-rs/Orientation.d.ts +4 -0
  33. package/dist/esm/ts-rs/PanelOptions.d.ts +7 -0
  34. package/dist/esm/ts-rs/PanelViewerConfig.d.ts +39 -0
  35. package/dist/esm/ts-rs/SplitLayout.d.ts +7 -0
  36. package/dist/esm/ts-rs/TabLayout.d.ts +10 -0
  37. package/dist/esm/ts-rs/ViewOnUpdateResp.d.ts +4 -0
  38. package/dist/esm/ts-rs/ViewerConfig.d.ts +6 -2
  39. package/dist/esm/ts-rs/WorkspaceConfig.d.ts +40 -0
  40. package/dist/esm/ts-rs/WorkspaceConfigUpdate.d.ts +28 -0
  41. package/dist/wasm/perspective-viewer.d.ts +213 -79
  42. package/dist/wasm/perspective-viewer.js +537 -189
  43. package/dist/wasm/perspective-viewer.wasm +0 -0
  44. package/dist/wasm/perspective-viewer.wasm.d.ts +36 -28
  45. package/dist/wasm/snippets/perspective-viewer-daeef4ceb066e6c7/inline0.js +6 -0
  46. package/dist/wasm/snippets/{perspective-viewer-3cd58f0374935772/inline3.js → perspective-viewer-daeef4ceb066e6c7/inline4.js} +5 -0
  47. package/package.json +3 -2
  48. package/src/css/_column_dropdown.css +14 -0
  49. package/src/css/_context_menu.css +14 -0
  50. package/src/css/_dropdown_menu.css +14 -0
  51. package/src/css/_filter_dropdown.css +14 -0
  52. package/src/css/_function_dropdown.css +14 -0
  53. package/src/css/_viewer_bundle.css +41 -0
  54. package/src/css/column-settings-panel.css +1 -1
  55. package/src/css/containers/context-menu.css +101 -0
  56. package/src/css/panel-tab.css +193 -0
  57. package/src/css/plugin-selector.css +7 -10
  58. package/src/css/status-bar.css +75 -81
  59. package/src/css/viewer.css +181 -71
  60. package/src/rust/components/column_dropdown.rs +43 -33
  61. package/src/rust/components/column_selector/active_column.rs +7 -18
  62. package/src/rust/components/column_selector/aggregate_selector.rs +4 -10
  63. package/src/rust/components/column_selector/config_selector.rs +33 -84
  64. package/src/rust/components/column_selector/empty_column.rs +0 -3
  65. package/src/rust/components/column_selector/filter_column.rs +5 -18
  66. package/src/rust/components/column_selector/inactive_column.rs +3 -8
  67. package/src/rust/components/column_selector/invalid_column.rs +0 -4
  68. package/src/rust/components/column_selector/sort_column.rs +3 -6
  69. package/src/rust/components/column_selector.rs +5 -14
  70. package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs +0 -3
  71. package/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +0 -3
  72. package/src/rust/components/column_settings_sidebar.rs +0 -3
  73. package/src/rust/components/containers/dropdown_menu.rs +1 -3
  74. package/src/rust/components/containers/scroll_panel.rs +1 -3
  75. package/src/rust/components/containers/split_panel.rs +175 -66
  76. package/src/rust/components/containers/tab_list.rs +0 -3
  77. package/src/rust/components/context_menu.rs +130 -0
  78. package/src/rust/components/datetime_column_style.rs +0 -3
  79. package/src/rust/components/empty_row.rs +0 -3
  80. package/src/rust/components/expression_editor.rs +2 -3
  81. package/src/rust/components/filter_dropdown.rs +3 -3
  82. package/src/rust/components/font_loader.rs +2 -2
  83. package/src/rust/components/form/code_editor.rs +0 -3
  84. package/src/rust/components/form/debug.rs +3 -4
  85. package/src/rust/components/function_dropdown.rs +3 -3
  86. package/src/rust/components/global_filter_bar.rs +76 -0
  87. package/src/rust/components/main_panel/frame_theme.rs +186 -0
  88. package/src/rust/components/main_panel/msg.rs +62 -0
  89. package/src/rust/components/main_panel/presize.rs +220 -0
  90. package/src/rust/components/main_panel/reconcile.rs +224 -0
  91. package/src/rust/components/main_panel/render.rs +385 -0
  92. package/src/rust/components/main_panel/update.rs +184 -0
  93. package/src/rust/components/main_panel.rs +311 -71
  94. package/src/rust/components/mod.rs +4 -0
  95. package/src/rust/components/number_series_style.rs +0 -3
  96. package/src/rust/components/panel_menu.rs +486 -0
  97. package/src/rust/components/panel_tab.rs +505 -0
  98. package/src/rust/components/plugin_selector.rs +0 -3
  99. package/src/rust/components/plugin_tab.rs +1 -6
  100. package/src/rust/components/portal.rs +5 -2
  101. package/src/rust/components/render_warning.rs +0 -3
  102. package/src/rust/components/settings_panel.rs +13 -5
  103. package/src/rust/components/status_bar.rs +113 -180
  104. package/src/rust/components/status_indicator.rs +6 -9
  105. package/src/rust/components/string_column_style.rs +0 -3
  106. package/src/rust/components/style/mod.rs +65 -27
  107. package/src/rust/components/style/style_provider.rs +51 -16
  108. package/src/rust/components/style_controls/number_string_format.rs +1 -8
  109. package/src/rust/components/type_icon.rs +1 -4
  110. package/src/rust/components/viewer/filters.rs +133 -0
  111. package/src/rust/components/viewer/msg.rs +180 -0
  112. package/src/rust/components/viewer/panels.rs +326 -0
  113. package/src/rust/components/viewer/render.rs +243 -0
  114. package/src/rust/components/viewer/settings.rs +402 -0
  115. package/src/rust/components/viewer/snapshots.rs +134 -0
  116. package/src/rust/components/viewer/wiring.rs +505 -0
  117. package/src/rust/components/viewer.rs +243 -758
  118. package/src/rust/config/export_method.rs +1 -1
  119. package/src/rust/config/mod.rs +4 -0
  120. package/src/rust/config/options.rs +71 -0
  121. package/src/rust/config/viewer_config.rs +24 -2
  122. package/src/rust/config/workspace_config.rs +92 -0
  123. package/src/rust/custom_elements/copy_dropdown.rs +9 -3
  124. package/src/rust/custom_elements/debug_plugin.rs +20 -1
  125. package/src/rust/custom_elements/export_dropdown.rs +9 -3
  126. package/src/rust/custom_elements/viewer.rs +1015 -286
  127. package/src/rust/custom_events.rs +212 -61
  128. package/src/rust/js/mod.rs +2 -0
  129. package/src/rust/js/plugin.rs +297 -10
  130. package/src/rust/js/regular_layout.rs +258 -0
  131. package/src/rust/lib.rs +20 -2
  132. package/src/rust/presentation.rs +66 -33
  133. package/src/rust/queries/get_viewer_config.rs +29 -11
  134. package/src/rust/queries/plugin_column_styles.rs +2 -2
  135. package/src/rust/renderer/activate.rs +41 -14
  136. package/src/rust/renderer/dispatch.rs +436 -0
  137. package/src/rust/renderer/plugin_config.rs +495 -0
  138. package/src/rust/renderer/registry.rs +18 -6
  139. package/src/rust/renderer/render_timer.rs +29 -10
  140. package/src/rust/renderer.rs +350 -827
  141. package/src/rust/session/column_defaults_update.rs +26 -8
  142. package/src/rust/session/metadata.rs +11 -1
  143. package/src/rust/session/view_subscription.rs +30 -15
  144. package/src/rust/session.rs +753 -251
  145. package/src/rust/tasks/apply_global_filters.rs +89 -0
  146. package/src/rust/tasks/auto_pause.rs +171 -0
  147. package/src/rust/tasks/copy_export.rs +29 -19
  148. package/src/rust/tasks/create_panel.rs +243 -0
  149. package/src/rust/tasks/dismiss_render_warning.rs +3 -1
  150. package/src/rust/tasks/edit_expression.rs +4 -4
  151. package/src/rust/tasks/eject.rs +64 -23
  152. package/src/rust/tasks/mod.rs +28 -4
  153. package/src/rust/tasks/pipeline.rs +411 -0
  154. package/src/rust/tasks/presize_panels.rs +324 -0
  155. package/src/rust/tasks/reset_all.rs +22 -12
  156. package/src/rust/tasks/resize_observer.rs +124 -87
  157. package/src/rust/tasks/restore_and_render.rs +80 -86
  158. package/src/rust/tasks/restore_panel.rs +145 -0
  159. package/src/rust/tasks/send_column_config.rs +5 -2
  160. package/src/rust/tasks/send_plugin_config.rs +5 -2
  161. package/src/rust/tasks/set_edit_mode.rs +59 -0
  162. package/src/rust/tasks/sync_update_panels.rs +152 -0
  163. package/src/rust/tasks/table_lifecycle.rs +158 -0
  164. package/src/rust/tasks/update_theme.rs +56 -12
  165. package/src/rust/utils/completion.rs +56 -0
  166. package/src/rust/utils/custom_element.rs +5 -0
  167. package/src/rust/utils/debounce.rs +130 -7
  168. package/src/rust/utils/mod.rs +6 -0
  169. package/src/rust/utils/pending_effects.rs +62 -0
  170. package/src/rust/{components/style/local_style.rs → utils/spawn.rs} +17 -19
  171. package/src/rust/utils/weak_scope.rs +0 -10
  172. package/src/rust/workspace.rs +846 -0
  173. package/src/svg/active-indicator.svg +3 -0
  174. package/src/themes/botanical.css +7 -2
  175. package/src/themes/defaults.css +54 -2
  176. package/src/themes/dracula.css +8 -3
  177. package/src/themes/gruvbox-dark.css +7 -2
  178. package/src/themes/gruvbox.css +5 -2
  179. package/src/themes/icons.css +4 -2
  180. package/src/themes/monokai.css +7 -2
  181. package/src/themes/phosphor.css +7 -2
  182. package/src/themes/pro-dark.css +7 -2
  183. package/src/themes/pro.css +2 -1
  184. package/src/themes/solarized-dark.css +5 -2
  185. package/src/themes/solarized.css +5 -2
  186. package/src/themes/vaporwave.css +7 -2
  187. package/src/ts/bootstrap.ts +8 -7
  188. package/src/ts/extensions.ts +30 -2
  189. package/src/ts/perspective-viewer.ts +10 -0
  190. package/src/ts/plugin.ts +72 -5
  191. package/src/ts/ts-rs/ClientOptions.ts +7 -0
  192. package/src/ts/ts-rs/ExportMethod.ts +3 -0
  193. package/src/ts/ts-rs/ExportOptions.ts +8 -0
  194. package/src/ts/ts-rs/GetClientOptions.ts +7 -0
  195. package/src/ts/ts-rs/GetTableOptions.ts +7 -0
  196. package/src/ts/ts-rs/Layout.ts +9 -0
  197. package/src/ts/ts-rs/Orientation.ts +6 -0
  198. package/src/ts/ts-rs/PanelOptions.ts +7 -0
  199. package/src/ts/ts-rs/PanelViewerConfig.ts +15 -0
  200. package/src/ts/ts-rs/SplitLayout.ts +5 -0
  201. package/src/ts/ts-rs/TabLayout.ts +11 -0
  202. package/src/ts/ts-rs/ViewerConfig.ts +6 -2
  203. package/src/ts/ts-rs/WorkspaceConfig.ts +36 -0
  204. package/src/ts/ts-rs/WorkspaceConfigUpdate.ts +24 -0
  205. package/tsconfig.json +1 -1
  206. package/src/rust/components/style/style_cache.rs +0 -136
  207. package/src/rust/tasks/intersection_observer.rs +0 -98
  208. package/src/rust/tasks/update_and_render.rs +0 -110
  209. /package/dist/wasm/snippets/{perspective-viewer-3cd58f0374935772/inline0.js → perspective-viewer-daeef4ceb066e6c7/inline1.js} +0 -0
  210. /package/dist/wasm/snippets/{perspective-viewer-3cd58f0374935772/inline1.js → perspective-viewer-daeef4ceb066e6c7/inline2.js} +0 -0
  211. /package/dist/wasm/snippets/{perspective-viewer-3cd58f0374935772/inline2.js → perspective-viewer-daeef4ceb066e6c7/inline3.js} +0 -0
  212. /package/dist/wasm/snippets/{perspective-viewer-3cd58f0374935772/inline4.js → perspective-viewer-daeef4ceb066e6c7/inline5.js} +0 -0
@@ -0,0 +1,486 @@
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 per-panel command menu: a cursor-anchored [`ContextMenu`] plus the
14
+ //! Export/Copy format-picker dropdowns it can spawn in place of itself. The
15
+ //! Export/Copy flows are handled end-to-end HERE (the target panel's engines
16
+ //! resolve from the `workspace` prop, like `StatusBar`'s own dropdowns);
17
+ //! every other command is emitted as a [`PanelCommand`] for the parent.
18
+ //!
19
+ //! Both stages are body-mounted [`PortalModal`]s positioned against a shared
20
+ //! session-long cursor anchor, so the menu is themed exactly like the pickers:
21
+ //! the host (`<perspective-context-menu theme="X">`) is matched by the
22
+ //! document theme rules' modal selector groups, with `X` = the TARGET panel's
23
+ //! effective theme (not the active/host theme).
24
+ //!
25
+ //! One menu "session" spans right-click → (menu | picker) → dismissal:
26
+ //! `on_close` fires exactly once, when the session ends (blur dismissal, a
27
+ //! command selection, or the picker closing).
28
+
29
+ use perspective_js::utils::*;
30
+ use wasm_bindgen::JsCast;
31
+ use web_sys::HtmlElement;
32
+ use yew::prelude::*;
33
+
34
+ use crate::components::context_menu::{ContextMenu, ContextMenuEntry, ContextMenuItem};
35
+ use crate::components::copy_dropdown::CopyDropDownMenu;
36
+ use crate::components::export_dropdown::ExportDropDownMenu;
37
+ use crate::components::portal::PortalModal;
38
+ use crate::components::style::StyleSurface;
39
+ use crate::config::*;
40
+ use crate::js::copy_to_clipboard;
41
+ use crate::presentation::Presentation;
42
+ use crate::tasks::export_method_to_blob;
43
+ use crate::utils::*;
44
+ use crate::workspace::{PanelId, Workspace};
45
+
46
+ /// A panel command the menu delegates to its parent. Export/Copy are absent —
47
+ /// they're handled internally by the picker flow.
48
+ #[derive(Clone, Debug, PartialEq, Eq)]
49
+ pub enum PanelCommand {
50
+ New,
51
+ NewFrom { client: String, table: String },
52
+ Duplicate,
53
+ Reset,
54
+ Maximize,
55
+ Restore,
56
+ ToggleMaster,
57
+ Close,
58
+ }
59
+
60
+ /// Which format-picker dropdown the context menu spawned in place of itself.
61
+ #[derive(Clone, Copy, PartialEq)]
62
+ pub enum PickerKind {
63
+ Export,
64
+ Copy,
65
+ }
66
+
67
+ #[derive(Properties)]
68
+ pub struct PanelMenuProps {
69
+ /// Viewport (client) coordinates the menu (and any spawned picker) anchors
70
+ /// at.
71
+ pub x: f64,
72
+ pub y: f64,
73
+
74
+ /// The right-clicked panel this menu targets — or `None` for the
75
+ /// EMPTY-stage menu (zero panels), which offers only the "New" sub-menu
76
+ /// (its `NewFrom` items resolve from the loaded-clients registry, no
77
+ /// panel required).
78
+ pub panel_id: Option<String>,
79
+
80
+ /// For per-panel command context (`is_master`, pivot state, panel count)
81
+ /// and resolving the target panel's engines for Export/Copy.
82
+ pub workspace: Workspace,
83
+
84
+ /// For `export_method_to_blob`.
85
+ pub presentation: Presentation,
86
+
87
+ /// The TARGET panel's effective theme (its own, else the registry
88
+ /// default), stamped on both stages' `PortalModal` hosts.
89
+ pub theme: Option<String>,
90
+
91
+ /// Whether the target panel is currently maximized (drives the
92
+ /// Maximize/Restore item).
93
+ pub maximized: bool,
94
+
95
+ /// A command was selected — the parent executes it (and ends the session
96
+ /// via the `on_close` that follows every selection).
97
+ pub on_command: Callback<PanelCommand>,
98
+
99
+ /// The menu session ended (backdrop dismissal, command selection, or
100
+ /// picker close); the parent unmounts this component.
101
+ pub on_close: Callback<()>,
102
+ }
103
+
104
+ impl PartialEq for PanelMenuProps {
105
+ fn eq(&self, rhs: &Self) -> bool {
106
+ self.x == rhs.x
107
+ && self.y == rhs.y
108
+ && self.panel_id == rhs.panel_id
109
+ && self.theme == rhs.theme
110
+ && self.maximized == rhs.maximized
111
+ }
112
+ }
113
+
114
+ pub enum PanelMenuMsg {
115
+ /// A parent-executed command was selected.
116
+ Command(PanelCommand),
117
+
118
+ /// Export/Copy was selected: swap the menu for the format picker.
119
+ OpenPicker(PickerKind),
120
+
121
+ /// The `ContextMenu` closed. Fired on backdrop dismissal AND after every
122
+ /// item selection — swallowed when a picker was just opened (the session
123
+ /// continues in the picker).
124
+ MenuClosed,
125
+
126
+ /// The picker closed (blur, or a completed export/copy).
127
+ ClosePicker,
128
+
129
+ /// The per-client hosted-table-name fetch (spawned at menu open, feeding
130
+ /// the "New" sub-menu) resolved: `(client name, its table names)` per
131
+ /// loaded client.
132
+ TablesLoaded(Vec<(String, Vec<String>)>),
133
+ }
134
+
135
+ pub struct PanelMenu {
136
+ /// The session-long 0×0 cursor anchor element (appended to `<body>`) both
137
+ /// stages' `PortalModal`s position against; removed on destroy.
138
+ anchor: HtmlElement,
139
+
140
+ /// The open format picker, if the session is in its picker stage.
141
+ picker: Option<PickerKind>,
142
+
143
+ /// The "New" sub-menu's data: `(client name, its hosted table names)` per
144
+ /// loaded client, in registration order. `None` while the fetch spawned at
145
+ /// menu open is still in flight.
146
+ tables: Option<Vec<(String, Vec<String>)>>,
147
+ }
148
+
149
+ impl Component for PanelMenu {
150
+ type Message = PanelMenuMsg;
151
+ type Properties = PanelMenuProps;
152
+
153
+ fn create(ctx: &Context<Self>) -> Self {
154
+ let clients = ctx.props().workspace.clients();
155
+ let link = ctx.link().clone();
156
+ ApiFuture::spawn(async move {
157
+ let mut tables = Vec::with_capacity(clients.len());
158
+ for client in clients {
159
+ // A failing client contributes an empty list rather than
160
+ // poisoning the whole menu.
161
+ let mut names = match client.get_hosted_table_names().await {
162
+ Ok(names) => names,
163
+ Err(err) => {
164
+ tracing::warn!(
165
+ "Failed to list tables for `Client` \"{}\": {err}",
166
+ client.get_name()
167
+ );
168
+
169
+ vec![]
170
+ },
171
+ };
172
+
173
+ // Server-side name order isn't meaningful (or stable) — list
174
+ // deterministically.
175
+ names.sort_unstable();
176
+ tables.push((client.get_name().to_owned(), names));
177
+ }
178
+
179
+ link.send_message(PanelMenuMsg::TablesLoaded(tables));
180
+ Ok(())
181
+ });
182
+
183
+ Self {
184
+ anchor: session_anchor(ctx.props().x, ctx.props().y),
185
+ picker: None,
186
+ tables: None,
187
+ }
188
+ }
189
+
190
+ fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
191
+ match msg {
192
+ PanelMenuMsg::Command(cmd) => {
193
+ ctx.props().on_command.emit(cmd);
194
+ false
195
+ },
196
+ PanelMenuMsg::OpenPicker(kind) => {
197
+ self.picker = Some(kind);
198
+ true
199
+ },
200
+ PanelMenuMsg::MenuClosed => {
201
+ // The menu's `PortalModal` closes (blur) after every item
202
+ // selection; when that selection just opened a picker, the
203
+ // session continues — only a plain dismissal/selection ends
204
+ // it.
205
+ if self.picker.is_none() {
206
+ ctx.props().on_close.emit(());
207
+ }
208
+
209
+ false
210
+ },
211
+ PanelMenuMsg::ClosePicker => {
212
+ ctx.props().on_close.emit(());
213
+ false
214
+ },
215
+ PanelMenuMsg::TablesLoaded(tables) => {
216
+ self.tables = Some(tables);
217
+ self.picker.is_none()
218
+ },
219
+ }
220
+ }
221
+
222
+ fn view(&self, ctx: &Context<Self>) -> Html {
223
+ match &self.picker {
224
+ Some(kind) => self.picker_html(ctx, *kind),
225
+ None => self.menu_html(ctx),
226
+ }
227
+ }
228
+
229
+ fn destroy(&mut self, _ctx: &Context<Self>) {
230
+ // The session ended (or the parent unmounted mid-session, e.g. the
231
+ // target panel closed); don't leak the cursor anchor.
232
+ let _ = global::body().remove_child(&self.anchor);
233
+ }
234
+ }
235
+
236
+ impl PanelMenu {
237
+ fn menu_html(&self, ctx: &Context<Self>) -> Html {
238
+ let on_close = ctx.link().callback(|_| PanelMenuMsg::MenuClosed);
239
+ let item = |label: &str, on_select: Callback<()>, disabled: bool| {
240
+ ContextMenuEntry::Item(ContextMenuItem {
241
+ label: label.to_owned(),
242
+ on_select,
243
+ disabled,
244
+ })
245
+ };
246
+ let cmd = |cmd: PanelCommand| {
247
+ ctx.link()
248
+ .callback(move |_| PanelMenuMsg::Command(cmd.clone()))
249
+ };
250
+ let entries = match ctx.props().panel_id.as_deref() {
251
+ // The empty-stage menu: no target panel, so only the "New"
252
+ // sub-menu. Hover-only (`on_select: None`) — plain "New" copies
253
+ // its source panel's table binding, which doesn't exist here.
254
+ None => vec![ContextMenuEntry::Submenu {
255
+ label: "New".to_owned(),
256
+ on_select: None,
257
+ entries: self.new_submenu_entries(ctx),
258
+ }],
259
+ Some(panel_id) => {
260
+ let can_close = ctx.props().workspace.len() > 1;
261
+ let is_master = ctx.props().workspace.is_master(&PanelId::from(panel_id));
262
+ vec![
263
+ ContextMenuEntry::Submenu {
264
+ label: "New".to_owned(),
265
+ on_select: Some(cmd(PanelCommand::New)),
266
+ entries: self.new_submenu_entries(ctx),
267
+ },
268
+ item("Duplicate", cmd(PanelCommand::Duplicate), false),
269
+ item("Reset", cmd(PanelCommand::Reset), false),
270
+ item(
271
+ "Export",
272
+ ctx.link()
273
+ .callback(|_| PanelMenuMsg::OpenPicker(PickerKind::Export)),
274
+ false,
275
+ ),
276
+ item(
277
+ "Copy",
278
+ ctx.link()
279
+ .callback(|_| PanelMenuMsg::OpenPicker(PickerKind::Copy)),
280
+ false,
281
+ ),
282
+ if ctx.props().maximized {
283
+ item("Restore", cmd(PanelCommand::Restore), false)
284
+ } else {
285
+ item("Maximize", cmd(PanelCommand::Maximize), false)
286
+ },
287
+ // Never gated: masters broadcast from ANY select/click event
288
+ // (flat grids fall back to the clicked cell's `==` clause), not
289
+ // just a grouped row tree.
290
+ item(
291
+ if is_master { "Detail" } else { "Master" },
292
+ cmd(PanelCommand::ToggleMaster),
293
+ false,
294
+ ),
295
+ item("Close", cmd(PanelCommand::Close), !can_close),
296
+ ]
297
+ },
298
+ };
299
+
300
+ html! {
301
+ <PortalModal
302
+ tag_name="perspective-context-menu"
303
+ surface={StyleSurface::ContextMenu}
304
+ target={Some(self.anchor.clone())}
305
+ own_focus=true
306
+ on_close={&on_close}
307
+ theme={ctx.props().theme.clone().unwrap_or_default()}
308
+ >
309
+ // Selection-end and blur-dismissal both route to `MenuClosed`;
310
+ // duplicates are harmless (the first ends the session or is
311
+ // swallowed by an open picker).
312
+ <ContextMenu {entries} {on_close} />
313
+ </PortalModal>
314
+ }
315
+ }
316
+
317
+ /// The "New" hover sub-menu's entries: every hosted `Table` name from
318
+ /// every loaded `Client`, flat for a single client, grouped under a
319
+ /// header row per client otherwise (client names are globally unique, so
320
+ /// the grouping also disambiguates table-name collisions).
321
+ fn new_submenu_entries(&self, ctx: &Context<Self>) -> Vec<ContextMenuEntry> {
322
+ let placeholder = |label: &str| {
323
+ vec![ContextMenuEntry::Item(ContextMenuItem {
324
+ label: label.to_owned(),
325
+ on_select: Callback::noop(),
326
+ disabled: true,
327
+ })]
328
+ };
329
+
330
+ let Some(clients) = &self.tables else {
331
+ return placeholder("Loading...");
332
+ };
333
+
334
+ if clients.iter().all(|(_, tables)| tables.is_empty()) {
335
+ return placeholder("No tables");
336
+ }
337
+
338
+ let multi = clients.len() > 1;
339
+ let mut entries = Vec::new();
340
+ for (client_name, tables) in clients {
341
+ if multi {
342
+ entries.push(ContextMenuEntry::Header(client_name.clone()));
343
+ }
344
+
345
+ for table in tables {
346
+ let on_select = {
347
+ clone!(client_name, table);
348
+ ctx.link().callback(move |_| {
349
+ PanelMenuMsg::Command(PanelCommand::NewFrom {
350
+ client: client_name.clone(),
351
+ table: table.clone(),
352
+ })
353
+ })
354
+ };
355
+
356
+ entries.push(ContextMenuEntry::Item(ContextMenuItem {
357
+ label: table.clone(),
358
+ on_select,
359
+ disabled: false,
360
+ }));
361
+ }
362
+ }
363
+
364
+ entries
365
+ }
366
+
367
+ /// Export/Copy format-picker spawned in place of the context menu, anchored
368
+ /// at the same cursor anchor and reusing the status bar's dropdown
369
+ /// components.
370
+ fn picker_html(&self, ctx: &Context<Self>, kind: PickerKind) -> Html {
371
+ // Export/Copy are absent from the target-less stage menu, so
372
+ // `panel_id` is always `Some` here in practice.
373
+ let Some(panel) = ctx
374
+ .props()
375
+ .panel_id
376
+ .as_deref()
377
+ .and_then(|id| ctx.props().workspace.panel(&PanelId::from(id)))
378
+ else {
379
+ return Html::default();
380
+ };
381
+
382
+ let on_close = ctx.link().callback(|_| PanelMenuMsg::ClosePicker);
383
+ let theme = ctx.props().theme.clone().unwrap_or_default();
384
+ let target = Some(self.anchor.clone());
385
+ let presentation = ctx.props().presentation.clone();
386
+
387
+ let inner = match kind {
388
+ PickerKind::Export => {
389
+ let callback = {
390
+ clone!(presentation);
391
+ let session = panel.session.clone();
392
+ let renderer = panel.renderer.clone();
393
+ let link = ctx.link().clone();
394
+ Callback::from(move |file: ExportFile| {
395
+ if file.name.is_empty() {
396
+ return;
397
+ }
398
+
399
+ clone!(session, renderer, presentation, link);
400
+ ApiFuture::spawn(async move {
401
+ let blob = export_method_to_blob(
402
+ &session,
403
+ &renderer,
404
+ &presentation,
405
+ file.method,
406
+ )
407
+ .await?;
408
+
409
+ download(&file.as_filename(renderer.is_chart()), &blob)?;
410
+ link.send_message(PanelMenuMsg::ClosePicker);
411
+ Ok(())
412
+ });
413
+ })
414
+ };
415
+
416
+ html! {
417
+ <ExportDropDownMenu
418
+ renderer={panel.renderer.clone()}
419
+ session={panel.session.clone()}
420
+ {callback}
421
+ />
422
+ }
423
+ },
424
+ PickerKind::Copy => {
425
+ let callback = {
426
+ clone!(presentation);
427
+ let session = panel.session.clone();
428
+ let renderer = panel.renderer.clone();
429
+ let link = ctx.link().clone();
430
+ Callback::from(move |file: ExportFile| {
431
+ clone!(session, renderer, presentation, link);
432
+ ApiFuture::spawn(async move {
433
+ let task = export_method_to_blob(
434
+ &session,
435
+ &renderer,
436
+ &presentation,
437
+ file.method,
438
+ );
439
+ copy_to_clipboard(task, file.method.mimetype(file.is_chart)).await?;
440
+ link.send_message(PanelMenuMsg::ClosePicker);
441
+ Ok(())
442
+ });
443
+ })
444
+ };
445
+
446
+ html! { <CopyDropDownMenu renderer={panel.renderer.clone()} {callback} /> }
447
+ },
448
+ };
449
+
450
+ let tag_name = match kind {
451
+ PickerKind::Export => "perspective-export-menu",
452
+ PickerKind::Copy => "perspective-copy-menu",
453
+ };
454
+
455
+ html! {
456
+ <PortalModal
457
+ {tag_name}
458
+ surface={StyleSurface::DropdownMenu}
459
+ {target}
460
+ own_focus=true
461
+ {on_close}
462
+ {theme}
463
+ >
464
+ { inner }
465
+ </PortalModal>
466
+ }
467
+ }
468
+ }
469
+
470
+ /// Create a session-long 0×0 anchor element at viewport `(x, y)`, appended to
471
+ /// `<body>`, for both stages' `PortalModal`s to position against.
472
+ fn session_anchor(x: f64, y: f64) -> HtmlElement {
473
+ let anchor: HtmlElement = global::document()
474
+ .create_element("div")
475
+ .unwrap()
476
+ .unchecked_into();
477
+
478
+ let style = anchor.style();
479
+ let _ = style.set_property("position", "fixed");
480
+ let _ = style.set_property("left", &format!("{x}px"));
481
+ let _ = style.set_property("top", &format!("{y}px"));
482
+ let _ = style.set_property("width", "0px");
483
+ let _ = style.set_property("height", "0px");
484
+ let _ = global::body().append_child(&anchor);
485
+ anchor
486
+ }