@perspective-dev/viewer 4.4.1 → 4.5.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.
Files changed (227) hide show
  1. package/dist/cdn/perspective-viewer.js +1 -2
  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/intl/de.css +1 -1
  9. package/dist/css/intl/es.css +1 -1
  10. package/dist/css/intl/fr.css +1 -1
  11. package/dist/css/intl/ja.css +1 -1
  12. package/dist/css/intl/pt.css +1 -1
  13. package/dist/css/intl/zh.css +1 -1
  14. package/dist/css/intl.css +1 -1
  15. package/dist/css/monokai.css +1 -1
  16. package/dist/css/phosphor.css +1 -1
  17. package/dist/css/pro-dark.css +1 -1
  18. package/dist/css/pro.css +1 -1
  19. package/dist/css/solarized-dark.css +1 -1
  20. package/dist/css/solarized.css +1 -1
  21. package/dist/css/themes.css +1 -1
  22. package/dist/css/vaporwave.css +1 -1
  23. package/dist/esm/bootstrap.d.ts +2 -1
  24. package/dist/esm/column-format.d.ts +51 -0
  25. package/dist/esm/extensions.d.ts +2 -0
  26. package/dist/esm/perspective-viewer.d.ts +3 -1
  27. package/dist/esm/perspective-viewer.inline.js +1 -2
  28. package/dist/esm/perspective-viewer.inline.js.map +4 -4
  29. package/dist/esm/perspective-viewer.js +1 -2
  30. package/dist/esm/perspective-viewer.js.map +4 -4
  31. package/dist/esm/perspective-viewer.worker.d.ts +2 -0
  32. package/dist/esm/plugin.d.ts +16 -72
  33. package/dist/esm/ts-rs/ColumnSelectMode.d.ts +1 -0
  34. package/dist/esm/ts-rs/PluginStaticConfig.d.ts +77 -0
  35. package/dist/esm/ts-rs/ViewerConfig.d.ts +6 -3
  36. package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +7 -4
  37. package/dist/wasm/perspective-viewer.d.ts +77 -18
  38. package/dist/wasm/perspective-viewer.js +302 -148
  39. package/dist/wasm/perspective-viewer.wasm +0 -0
  40. package/dist/wasm/perspective-viewer.wasm.d.ts +20 -15
  41. package/package.json +24 -2
  42. package/src/css/column-selector.css +3 -2
  43. package/src/css/column-settings-panel.css +44 -9
  44. package/src/css/column-style.css +35 -2
  45. package/src/css/containers/scroll-panel.css +2 -1
  46. package/src/css/containers/tabs.css +8 -52
  47. package/src/css/dom/checkbox.css +2 -6
  48. package/src/css/form/code-editor.css +1 -0
  49. package/src/css/form/debug.css +3 -10
  50. package/src/css/plugin-selector.css +33 -0
  51. package/src/css/plugin-settings-panel.css +99 -0
  52. package/src/css/viewer.css +143 -3
  53. package/src/rust/components/column_dropdown.rs +3 -1
  54. package/src/rust/components/column_selector/active_column.rs +16 -19
  55. package/src/rust/components/column_selector/config_selector.rs +20 -20
  56. package/src/rust/components/column_selector/filter_column.rs +14 -14
  57. package/src/rust/components/column_selector/inactive_column.rs +10 -15
  58. package/src/rust/components/column_selector/pivot_column.rs +7 -7
  59. package/src/rust/components/column_selector/sort_column.rs +7 -7
  60. package/src/rust/components/column_selector.rs +55 -37
  61. package/src/rust/components/column_settings_sidebar/style_tab/agg_depth_selector.rs +15 -7
  62. package/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs +395 -0
  63. package/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +15 -6
  64. package/src/rust/components/column_settings_sidebar/style_tab.rs +267 -136
  65. package/src/rust/components/column_settings_sidebar.rs +44 -49
  66. package/src/rust/components/containers/dragdrop_list.rs +32 -5
  67. package/src/rust/components/containers/mod.rs +0 -1
  68. package/src/rust/components/containers/scroll_panel.rs +21 -7
  69. package/src/rust/components/containers/sidebar.rs +8 -6
  70. package/src/rust/components/containers/split_panel.rs +3 -3
  71. package/src/rust/components/containers/tab_list.rs +3 -9
  72. package/src/rust/components/copy_dropdown.rs +2 -3
  73. package/src/rust/components/datetime_column_style.rs +19 -81
  74. package/src/rust/components/editable_header.rs +17 -3
  75. package/src/rust/components/export_dropdown.rs +2 -3
  76. package/src/rust/components/expression_editor.rs +29 -17
  77. package/src/rust/components/filter_dropdown.rs +2 -1
  78. package/src/rust/components/form/color_range_selector.rs +14 -7
  79. package/src/rust/components/form/debug.rs +47 -37
  80. package/src/rust/components/main_panel.rs +24 -65
  81. package/src/rust/components/mod.rs +2 -1
  82. package/src/rust/components/number_series_style.rs +161 -0
  83. package/src/rust/components/plugin_tab.rs +221 -0
  84. package/src/rust/components/settings_panel.rs +181 -59
  85. package/src/rust/components/status_bar.rs +141 -174
  86. package/src/rust/components/status_indicator.rs +15 -22
  87. package/src/rust/components/string_column_style.rs +20 -82
  88. package/src/rust/components/style_controls/number_string_format.rs +14 -30
  89. package/src/rust/components/viewer.rs +169 -132
  90. package/src/rust/config/column_config_schema.rs +195 -0
  91. package/src/rust/config/columns_config.rs +4 -97
  92. package/src/rust/config/datetime_column_style.rs +0 -5
  93. package/src/rust/config/mod.rs +8 -2
  94. package/src/rust/config/number_series_style.rs +79 -0
  95. package/src/rust/config/plugin_static_config.rs +144 -0
  96. package/src/rust/config/string_column_style.rs +0 -5
  97. package/src/rust/config/viewer_config.rs +5 -6
  98. package/src/rust/custom_elements/copy_dropdown.rs +30 -18
  99. package/src/rust/custom_elements/debug_plugin.rs +1 -3
  100. package/src/rust/custom_elements/export_dropdown.rs +26 -18
  101. package/src/rust/custom_elements/viewer.rs +62 -73
  102. package/src/rust/custom_events.rs +181 -224
  103. package/src/rust/js/plugin.rs +45 -117
  104. package/src/rust/lib.rs +34 -5
  105. package/src/rust/presentation/drag_helpers.rs +206 -0
  106. package/src/rust/presentation/props.rs +8 -0
  107. package/src/rust/presentation.rs +256 -41
  108. package/src/rust/{tasks → queries}/column_locator.rs +17 -73
  109. package/src/rust/queries/column_values.rs +59 -0
  110. package/src/rust/{tasks → queries}/columns_iter_set.rs +11 -18
  111. package/src/rust/queries/exports.rs +96 -0
  112. package/src/rust/queries/fetch_column_stats.rs +94 -0
  113. package/src/rust/queries/get_viewer_config.rs +54 -0
  114. package/src/rust/queries/mod.rs +44 -0
  115. package/src/rust/queries/plugin_column_styles.rs +101 -0
  116. package/src/rust/{engines.rs → queries/validate_expression.rs} +26 -15
  117. package/src/rust/renderer/activate.rs +1 -0
  118. package/src/rust/renderer/limits.rs +9 -4
  119. package/src/rust/renderer/plugin_store.rs +12 -0
  120. package/src/rust/renderer/props.rs +28 -3
  121. package/src/rust/renderer/registry.rs +40 -15
  122. package/src/rust/renderer.rs +703 -60
  123. package/src/rust/session/column_defaults_update.rs +20 -28
  124. package/src/rust/session/drag_drop_update.rs +10 -10
  125. package/src/rust/session/metadata.rs +31 -16
  126. package/src/rust/session/props.rs +15 -6
  127. package/src/rust/session/view_subscription.rs +10 -0
  128. package/src/rust/session.rs +109 -147
  129. package/src/rust/tasks/copy_export.rs +178 -158
  130. package/src/rust/tasks/{structural.rs → dismiss_render_warning.rs} +20 -40
  131. package/src/rust/tasks/edit_expression.rs +68 -88
  132. package/src/rust/tasks/eject.rs +25 -22
  133. package/src/rust/tasks/intersection_observer.rs +8 -21
  134. package/src/rust/tasks/mod.rs +19 -21
  135. package/src/rust/tasks/reset_all.rs +98 -0
  136. package/src/rust/tasks/resize_observer.rs +11 -33
  137. package/src/rust/tasks/restore_and_render.rs +128 -90
  138. package/src/rust/tasks/{get_viewer_config.rs → send_column_config.rs} +39 -35
  139. package/src/rust/tasks/send_plugin_config.rs +33 -33
  140. package/src/rust/tasks/update_and_render.rs +75 -49
  141. package/src/rust/{components/containers/trap_door_panel.rs → tasks/update_theme.rs} +34 -33
  142. package/src/rust/tasks/validate_expression.rs +61 -0
  143. package/src/rust/utils/browser/selection.rs +4 -4
  144. package/src/rust/utils/mod.rs +0 -63
  145. package/src/svg/checkbox-checked-icon.svg +1 -1
  146. package/src/svg/checkbox-unchecked-icon.svg +1 -1
  147. package/src/svg/mega-menu-icons-density.svg +23 -0
  148. package/src/svg/mega-menu-icons-map-density.svg +24 -0
  149. package/src/svg/mega-menu-icons-map-line.svg +19 -0
  150. package/src/themes/botanical.css +27 -53
  151. package/src/themes/defaults.css +24 -36
  152. package/src/themes/dracula.css +36 -54
  153. package/src/themes/gruvbox-dark.css +39 -59
  154. package/src/themes/gruvbox.css +16 -28
  155. package/src/themes/icons.css +5 -0
  156. package/src/themes/intl/de.css +43 -6
  157. package/src/themes/intl/es.css +43 -6
  158. package/src/themes/intl/fr.css +43 -6
  159. package/src/themes/intl/ja.css +43 -6
  160. package/src/themes/intl/pt.css +43 -6
  161. package/src/themes/intl/zh.css +43 -6
  162. package/src/themes/intl.css +38 -4
  163. package/src/themes/monokai.css +45 -61
  164. package/src/themes/phosphor.css +20 -29
  165. package/src/themes/pro-dark.css +25 -34
  166. package/src/themes/solarized-dark.css +21 -36
  167. package/src/themes/solarized.css +13 -23
  168. package/src/themes/vaporwave.css +40 -74
  169. package/src/ts/bootstrap.ts +14 -3
  170. package/src/ts/column-format.ts +162 -0
  171. package/src/ts/extensions.ts +4 -0
  172. package/src/ts/perspective-viewer.ts +9 -1
  173. package/src/{rust/components/column_settings_sidebar/style_tab/stub.rs → ts/perspective-viewer.worker.ts} +2 -22
  174. package/src/ts/plugin.ts +25 -101
  175. package/src/ts/ts-rs/{FormatUnit.ts → ColumnSelectMode.ts} +1 -1
  176. package/src/ts/ts-rs/PluginStaticConfig.ts +78 -0
  177. package/src/ts/ts-rs/ViewerConfig.ts +1 -2
  178. package/src/ts/ts-rs/ViewerConfigUpdate.ts +2 -3
  179. package/dist/esm/ts-rs/ColumnConfigValues.d.ts +0 -31
  180. package/dist/esm/ts-rs/CustomDatetimeFormat.d.ts +0 -1
  181. package/dist/esm/ts-rs/CustomDatetimeStyleConfig.d.ts +0 -15
  182. package/dist/esm/ts-rs/CustomNumberFormatConfig.d.ts +0 -18
  183. package/dist/esm/ts-rs/DatetimeColorMode.d.ts +0 -1
  184. package/dist/esm/ts-rs/DatetimeFormatType.d.ts +0 -6
  185. package/dist/esm/ts-rs/FormatMode.d.ts +0 -1
  186. package/dist/esm/ts-rs/FormatUnit.d.ts +0 -1
  187. package/dist/esm/ts-rs/NumberBackgroundMode.d.ts +0 -1
  188. package/dist/esm/ts-rs/NumberForegroundMode.d.ts +0 -1
  189. package/dist/esm/ts-rs/PluginConfig.d.ts +0 -2
  190. package/dist/esm/ts-rs/RoundingMode.d.ts +0 -1
  191. package/dist/esm/ts-rs/RoundingPriority.d.ts +0 -1
  192. package/dist/esm/ts-rs/SignDisplay.d.ts +0 -1
  193. package/dist/esm/ts-rs/SimpleDatetimeFormat.d.ts +0 -1
  194. package/dist/esm/ts-rs/SimpleDatetimeStyleConfig.d.ts +0 -6
  195. package/dist/esm/ts-rs/StringColorMode.d.ts +0 -1
  196. package/dist/esm/ts-rs/TrailingZeroDisplay.d.ts +0 -1
  197. package/dist/esm/ts-rs/UseGrouping.d.ts +0 -1
  198. package/src/rust/components/number_column_style.rs +0 -491
  199. package/src/rust/config/number_column_style.rs +0 -136
  200. package/src/rust/dragdrop.rs +0 -481
  201. package/src/rust/tasks/plugin_column_styles.rs +0 -98
  202. package/src/ts/ts-rs/ColumnConfigValues.ts +0 -14
  203. package/src/ts/ts-rs/CustomDatetimeFormat.ts +0 -3
  204. package/src/ts/ts-rs/CustomDatetimeStyleConfig.ts +0 -5
  205. package/src/ts/ts-rs/CustomNumberFormatConfig.ts +0 -8
  206. package/src/ts/ts-rs/DatetimeColorMode.ts +0 -3
  207. package/src/ts/ts-rs/DatetimeFormatType.ts +0 -8
  208. package/src/ts/ts-rs/FormatMode.ts +0 -3
  209. package/src/ts/ts-rs/NumberBackgroundMode.ts +0 -3
  210. package/src/ts/ts-rs/NumberForegroundMode.ts +0 -3
  211. package/src/ts/ts-rs/PluginConfig.ts +0 -4
  212. package/src/ts/ts-rs/RoundingMode.ts +0 -3
  213. package/src/ts/ts-rs/RoundingPriority.ts +0 -3
  214. package/src/ts/ts-rs/SignDisplay.ts +0 -3
  215. package/src/ts/ts-rs/SimpleDatetimeFormat.ts +0 -3
  216. package/src/ts/ts-rs/SimpleDatetimeStyleConfig.ts +0 -4
  217. package/src/ts/ts-rs/StringColorMode.ts +0 -3
  218. package/src/ts/ts-rs/TrailingZeroDisplay.ts +0 -3
  219. package/src/ts/ts-rs/UseGrouping.ts +0 -3
  220. /package/dist/wasm/snippets/{perspective-viewer-d924246f0b4a3dce → perspective-viewer-3cd58f0374935772}/inline0.js +0 -0
  221. /package/dist/wasm/snippets/{perspective-viewer-d924246f0b4a3dce → perspective-viewer-3cd58f0374935772}/inline1.js +0 -0
  222. /package/dist/wasm/snippets/{perspective-viewer-d924246f0b4a3dce → perspective-viewer-3cd58f0374935772}/inline2.js +0 -0
  223. /package/dist/wasm/snippets/{perspective-viewer-d924246f0b4a3dce → perspective-viewer-3cd58f0374935772}/inline3.js +0 -0
  224. /package/dist/wasm/snippets/{perspective-viewer-d924246f0b4a3dce → perspective-viewer-3cd58f0374935772}/inline4.js +0 -0
  225. /package/src/rust/{tasks → config}/export_method.rs +0 -0
  226. /package/src/rust/{tasks → queries}/export_app.rs +0 -0
  227. /package/src/rust/{tasks → queries}/is_invalid_drop.rs +0 -0
@@ -1,481 +0,0 @@
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
- use std::cell::{Cell, RefCell};
14
- use std::ops::Deref;
15
- use std::rc::Rc;
16
-
17
- use perspective_client::clone;
18
- use wasm_bindgen::prelude::*;
19
- use web_sys::*;
20
- use yew::html::ImplicitClone;
21
- use yew::prelude::*;
22
-
23
- use crate::js::{IntersectionObserver, IntersectionObserverEntry};
24
- use crate::utils::*;
25
- use crate::*;
26
-
27
- /// Value-semantic snapshot of the drag/drop state threaded through the
28
- /// component tree for visual feedback (drag-highlight CSS classes).
29
- #[derive(Clone, Debug, PartialEq, Default)]
30
- pub struct DragDropProps {
31
- /// Column name currently being dragged, if a drag is in progress.
32
- pub column: Option<String>,
33
- }
34
-
35
- #[derive(Clone, Debug)]
36
- struct DragFrom {
37
- column: String,
38
- effect: DragEffect,
39
- }
40
-
41
- #[derive(Debug)]
42
- struct DragOver {
43
- target: DragTarget,
44
- index: usize,
45
- }
46
-
47
- #[derive(Debug, Default)]
48
- enum DragState {
49
- #[default]
50
- NoDrag,
51
- DragInProgress(DragFrom),
52
- DragOverInProgress(DragFrom, DragOver),
53
- }
54
-
55
- impl DragState {
56
- const fn is_drag_in_progress(&self) -> bool {
57
- !matches!(self, Self::NoDrag)
58
- }
59
- }
60
-
61
- pub type DragEndCallback = Closure<dyn FnMut(DragEvent)>;
62
-
63
- pub struct DragDropState {
64
- drag_state: RefCell<DragState>,
65
- pub drop_received: PubSub<(String, DragTarget, DragEffect, usize)>,
66
-
67
- /// Injected callback from the root component, replacing the former
68
- /// `dragstart_received: PubSub` field.
69
- pub on_dragstart: RefCell<Option<Callback<DragEffect>>>,
70
-
71
- /// Injected callback from the root component, replacing the former
72
- /// `dragend_received: PubSub` field.
73
- pub on_dragend: RefCell<Option<Callback<()>>>,
74
-
75
- /// The host `<perspective-viewer>` element, used to attach the fallback
76
- /// `dragend` listener on a stable DOM node outside the virtual DOM.
77
- elem: HtmlElement,
78
-
79
- /// Host-level `dragend` listener closure, stored so it can be removed
80
- /// when a new drag starts. Attached to `elem` rather than `document`
81
- /// to keep the listener scoped to this component instance.
82
- host_dragend: RefCell<Option<DragEndCallback>>,
83
-
84
- drag_target: RefCell<Option<DragTargetState>>,
85
- }
86
-
87
- /// The `<perspective-viewer>` drag/drop service, which manages drag/drop user
88
- /// interactions across components. It is a component-level service, since only
89
- /// one drag/drop action can be executed by the user at a time.
90
- #[derive(Clone)]
91
- pub struct DragDrop(Rc<DragDropState>);
92
-
93
- impl DragDrop {
94
- pub fn new(elem: &HtmlElement) -> Self {
95
- Self(Rc::new(DragDropState {
96
- drag_state: Default::default(),
97
- drop_received: Default::default(),
98
- on_dragstart: Default::default(),
99
- on_dragend: Default::default(),
100
- elem: elem.clone(),
101
- host_dragend: Default::default(),
102
- drag_target: Default::default(),
103
- }))
104
- }
105
- }
106
-
107
- impl Deref for DragDrop {
108
- type Target = Rc<DragDropState>;
109
-
110
- fn deref(&self) -> &Self::Target {
111
- &self.0
112
- }
113
- }
114
-
115
- impl PartialEq for DragDrop {
116
- fn eq(&self, other: &Self) -> bool {
117
- Rc::ptr_eq(&self.0, &other.0)
118
- }
119
- }
120
-
121
- impl ImplicitClone for DragDrop {}
122
-
123
- impl DragDrop {
124
- /// Snapshot the drag state as a [`DragDropProps`] value for threading
125
- /// through the component tree without PubSub subscriptions.
126
- pub fn to_props(&self) -> DragDropProps {
127
- DragDropProps {
128
- column: self.get_drag_column(),
129
- }
130
- }
131
-
132
- /// Get the column name currently being drag/dropped.
133
- pub fn get_drag_column(&self) -> Option<String> {
134
- match *self.drag_state.borrow() {
135
- DragState::DragInProgress(DragFrom { ref column, .. })
136
- | DragState::DragOverInProgress(DragFrom { ref column, .. }, _) => Some(column.clone()),
137
- _ => None,
138
- }
139
- }
140
-
141
- pub fn get_drag_target(&self) -> Option<DragTarget> {
142
- match *self.drag_state.borrow() {
143
- DragState::DragInProgress(DragFrom {
144
- effect: DragEffect::Move(target),
145
- ..
146
- })
147
- | DragState::DragOverInProgress(
148
- DragFrom {
149
- effect: DragEffect::Move(target),
150
- ..
151
- },
152
- _,
153
- ) => Some(target),
154
- _ => None,
155
- }
156
- }
157
-
158
- pub fn set_drag_image(&self, event: &DragEvent) -> ApiResult<()> {
159
- event.stop_propagation();
160
- if let Some(dt) = event.data_transfer() {
161
- dt.set_drop_effect("move");
162
- // dt.set_data("text/plain", "{}").unwrap();
163
- }
164
-
165
- let original: HtmlElement = event.target().into_apierror()?.unchecked_into();
166
- let elem: HtmlElement = original
167
- .children()
168
- .get_with_index(0)
169
- .unwrap()
170
- .clone_node_with_deep(true)?
171
- .unchecked_into();
172
-
173
- elem.class_list().toggle("snap-drag-image")?;
174
- original.append_child(&elem)?;
175
- event.data_transfer().into_apierror()?.set_drag_image(
176
- &elem,
177
- event.offset_x(),
178
- event.offset_y(),
179
- );
180
-
181
- *self.drag_target.borrow_mut() =
182
- Some(DragTargetState::new(self.elem.clone(), original.clone()));
183
-
184
- // Drag image does not register correctly unless we wait.
185
- ApiFuture::spawn(async move {
186
- request_animation_frame().await;
187
- original.remove_child(&elem)?;
188
- Ok(())
189
- });
190
-
191
- Ok(())
192
- }
193
-
194
- // Is the drag/drop state currently in `action`?
195
- pub fn is_dragover(&self, drag_target: DragTarget) -> Option<(usize, String)> {
196
- match *self.drag_state.borrow() {
197
- DragState::DragOverInProgress(
198
- DragFrom { ref column, .. },
199
- DragOver { target, index },
200
- ) if target == drag_target => Some((index, column.clone())),
201
- _ => None,
202
- }
203
- }
204
-
205
- pub fn notify_drop(&self, event: &DragEvent) {
206
- event.prevent_default();
207
- event.stop_propagation();
208
-
209
- let action = match &*self.drag_state.borrow() {
210
- DragState::DragOverInProgress(
211
- DragFrom { column, effect },
212
- DragOver { target, index },
213
- ) => Some((column.to_string(), *target, *effect, *index)),
214
- _ => None,
215
- };
216
-
217
- self.drag_target.borrow_mut().take();
218
- *self.drag_state.borrow_mut() = DragState::NoDrag;
219
- if let Some(action) = action {
220
- self.drop_received.emit(action);
221
- }
222
- }
223
-
224
- /// Start the drag/drop action with the name of the column being dragged.
225
- pub fn notify_drag_start(&self, column: String, effect: DragEffect) {
226
- *self.drag_state.borrow_mut() = DragState::DragInProgress(DragFrom { column, effect });
227
- self.register_host_dragend();
228
- let emit = self.on_dragstart.borrow().clone();
229
- ApiFuture::spawn(async move {
230
- request_animation_frame().await;
231
- if let Some(cb) = emit {
232
- cb.emit(effect);
233
- }
234
-
235
- Ok(())
236
- });
237
- }
238
-
239
- /// End the drag/drop action by resetting the state to default.
240
- pub fn notify_drag_end(&self) {
241
- if self.drag_state.borrow().is_drag_in_progress() {
242
- self.drag_target.borrow_mut().take();
243
- *self.drag_state.borrow_mut() = DragState::NoDrag;
244
- if let Some(cb) = self.on_dragend.borrow().as_ref() {
245
- cb.emit(());
246
- }
247
- }
248
- }
249
-
250
- /// Register a `dragend` listener on the host `<perspective-viewer>`
251
- /// element so that drag-end cleanup fires even when Yew re-renders
252
- /// remove the original dragged element from the shadow DOM. The host
253
- /// element is outside the virtual DOM and therefore stable.
254
- fn register_host_dragend(&self) {
255
- // Remove any previously registered listener.
256
- if let Some(prev) = self.host_dragend.borrow_mut().take() {
257
- let _ = self
258
- .elem
259
- .remove_event_listener_with_callback("dragend", prev.as_ref().unchecked_ref());
260
- }
261
-
262
- let this = self.clone();
263
- let closure = Closure::wrap(Box::new(move |_event: DragEvent| {
264
- this.notify_drag_end();
265
- }) as Box<dyn FnMut(DragEvent)>);
266
-
267
- self.elem
268
- .add_event_listener_with_callback("dragend", closure.as_ref().unchecked_ref())
269
- .unwrap();
270
-
271
- *self.host_dragend.borrow_mut() = Some(closure);
272
- }
273
-
274
- /// Leave the `action` zone.
275
- pub fn notify_drag_leave(&self, drag_target: DragTarget) {
276
- let reset = match *self.drag_state.borrow() {
277
- DragState::DragOverInProgress(
278
- DragFrom { ref column, effect },
279
- DragOver { target, .. },
280
- ) if target == drag_target => Some((column.clone(), effect)),
281
- _ => None,
282
- };
283
-
284
- if let Some((column, effect)) = reset {
285
- self.notify_drag_start(column, effect);
286
- }
287
- }
288
-
289
- // Enter the `action` zone at `index`, which must be <= the number of children
290
- // in the container.
291
- pub fn notify_drag_enter(&self, target: DragTarget, index: usize) -> bool {
292
- let mut drag_state = self.drag_state.borrow_mut();
293
- let should_render = match &*drag_state {
294
- DragState::DragOverInProgress(_, drag_to) => {
295
- drag_to.target != target || drag_to.index != index
296
- },
297
- _ => true,
298
- };
299
-
300
- *drag_state = match &*drag_state {
301
- DragState::DragOverInProgress(drag_from, _) | DragState::DragInProgress(drag_from) => {
302
- DragState::DragOverInProgress(drag_from.clone(), DragOver { target, index })
303
- },
304
- _ => DragState::NoDrag,
305
- };
306
-
307
- should_render
308
- }
309
- }
310
-
311
- /// Safari does not set `relatedTarget` on `"dragleave"`, which makes it
312
- /// impossible to determine whether a logical drag leave has happened with just
313
- /// this event, so use function on `"dragenter"` to capture the `relatedTarget`.
314
- pub fn dragenter_helper(callback: impl Fn() + 'static, target: NodeRef) -> Callback<DragEvent> {
315
- Callback::from({
316
- move |event: DragEvent| {
317
- maybe_log!({
318
- event.stop_propagation();
319
- event.prevent_default();
320
- if event.related_target().is_none() {
321
- target
322
- .cast::<HtmlElement>()
323
- .into_apierror()?
324
- .dataset()
325
- .set("safaridragleave", "true")?;
326
- }
327
- });
328
-
329
- callback();
330
- }
331
- })
332
- }
333
-
334
- /// HTML drag/drop will fire a bubbling `dragleave` event over all children of a
335
- /// `dragleave`-listened-to element, so we need to filter out the events from
336
- /// the children elements with this esoteric DOM arcana.
337
- pub fn dragleave_helper(callback: impl Fn() + 'static, drag_ref: NodeRef) -> Callback<DragEvent> {
338
- Callback::from({
339
- clone!(drag_ref);
340
- move |event: DragEvent| {
341
- maybe_log!({
342
- event.stop_propagation();
343
- event.prevent_default();
344
-
345
- let mut related_target = event
346
- .related_target()
347
- .or_else(|| Some(JsValue::UNDEFINED.unchecked_into::<EventTarget>()))
348
- .and_then(|x| x.dyn_into::<Element>().ok());
349
-
350
- // This is a wild chrome bug. `dragleave` can fire with the `relatedTarget`
351
- // property set to an element inside the closed `ShadowRoot` hosted by a
352
- // browser-native `<select>` tag, which fails the `.contains()` check
353
- // below. This mystery `ShadowRoot` has a structure that looks like this
354
- // (tested in Chrome 92), which we try to detect as best we can below.
355
- //
356
- // ```html
357
- // <div aria-hidden="true">Selected Text Here</siv>
358
- // <slot name="user-agent-custom-assign-slot"></slot>
359
- // ```
360
- //
361
- // This is pretty course though, since there is no guarantee this structure
362
- // will be maintained in future Chrome versions; the `.expect()` in this
363
- // method chain should at least warn us if this regresses.
364
- //
365
- // Wait - you don't believe me? Throw a debugger statement inside this
366
- // conditional and drag a column over a pivot-mode active columns list.
367
- if related_target
368
- .as_ref()
369
- .map(|x| x.has_attribute("aria-hidden"))
370
- .unwrap_or_default()
371
- {
372
- related_target = Some(
373
- related_target
374
- .into_apierror()?
375
- .parent_node()
376
- .into_apierror()?
377
- .dyn_ref::<ShadowRoot>()
378
- .ok_or_else(|| JsValue::from("Chrome drag/drop bug detection failed"))?
379
- .host()
380
- .unchecked_into::<Element>(),
381
- )
382
- }
383
-
384
- let current_target = drag_ref.cast::<HtmlElement>().unwrap();
385
- match related_target {
386
- Some(ref related) => {
387
- // Due to virtual dom these events sometimes fire after
388
- // the node is removed ...
389
- if !current_target.contains(Some(related))
390
- && related.parent_element().is_some()
391
- {
392
- callback();
393
- }
394
- },
395
- None => {
396
- // Safari (OSX and iOS) don't set `relatedTarget`, so we need to
397
- // read a memoized value from the `"dragenter"` event.
398
- let dataset = current_target.dataset();
399
- if dataset.get("safaridragleave").is_some() {
400
- dataset.delete("safaridragleave");
401
- } else {
402
- callback();
403
- }
404
- },
405
- };
406
- })
407
- }
408
- })
409
- }
410
-
411
- #[derive(Clone)]
412
- pub struct DragDropContainer {
413
- pub noderef: NodeRef,
414
- pub dragenter: Callback<DragEvent>,
415
- pub dragleave: Callback<DragEvent>,
416
- }
417
-
418
- impl DragDropContainer {
419
- pub fn new<F: Fn() + 'static, G: Fn() + 'static>(ondragenter: F, ondragleave: G) -> Self {
420
- let noderef = NodeRef::default();
421
- Self {
422
- dragenter: dragenter_helper(ondragenter, noderef.clone()),
423
- dragleave: dragleave_helper(ondragleave, noderef.clone()),
424
- noderef,
425
- }
426
- }
427
- }
428
-
429
- /// A really, really unfortunate hack that is needed to guarantee that `dragend`
430
- /// is called even under aggressive DOM mutation after `dragstart` is fired.
431
- struct DragTargetState {
432
- target: HtmlElement,
433
- shadow_root: ShadowRoot,
434
- alive: Rc<Cell<bool>>,
435
- observer: IntersectionObserver,
436
- }
437
-
438
- impl DragTargetState {
439
- fn new(host: HtmlElement, target: HtmlElement) -> Self {
440
- let shadow_root = host.shadow_root().unwrap();
441
- let alive = Rc::new(Cell::new(true));
442
- let observer = IntersectionObserver::new(
443
- &Closure::<dyn FnMut(js_sys::Array)>::new({
444
- clone!(target, shadow_root, alive);
445
- move |records: js_sys::Array| {
446
- if !alive.get() {
447
- return;
448
- }
449
-
450
- for record in records.iter() {
451
- let record: IntersectionObserverEntry = record.unchecked_into();
452
- if !record.is_intersecting() {
453
- shadow_root.append_child(&target).unwrap();
454
- return;
455
- }
456
- }
457
- }
458
- })
459
- .into_js_value()
460
- .unchecked_into(),
461
- );
462
-
463
- observer.observe(target.as_ref());
464
- Self {
465
- target,
466
- shadow_root,
467
- alive,
468
- observer,
469
- }
470
- }
471
- }
472
-
473
- impl Drop for DragTargetState {
474
- fn drop(&mut self) {
475
- self.alive.set(false);
476
- self.observer.unobserve(&self.target);
477
- if self.target.is_connected() {
478
- let _ = self.shadow_root.remove_child(&self.target);
479
- }
480
- }
481
- }
@@ -1,98 +0,0 @@
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
- use itertools::Itertools;
14
- use perspective_client::config::ViewConfig;
15
- use perspective_js::utils::ApiResult;
16
-
17
- use super::{HasRenderer, HasSession};
18
- use crate::config::ColumnStyleOpts;
19
- use crate::renderer::Renderer;
20
- use crate::session::SessionMetadata;
21
-
22
- /// Queries the plugin to see if a given column can render column styles.
23
- pub fn can_render_column_styles(
24
- renderer: &Renderer,
25
- view_config: &ViewConfig,
26
- metadata: &SessionMetadata,
27
- column_name: &str,
28
- ) -> ApiResult<bool> {
29
- let plugin = renderer.get_active_plugin()?;
30
- let names: Vec<String> = plugin
31
- .config_column_names()
32
- .and_then(|jsarr| serde_wasm_bindgen::from_value(jsarr.into()).ok())
33
- .unwrap_or_default();
34
-
35
- let group = view_config
36
- .columns
37
- .iter()
38
- .find_position(|maybe_s| maybe_s.as_deref() == Some(column_name))
39
- .and_then(|(idx, _)| names.get(idx))
40
- .map(|s| s.as_str());
41
-
42
- let view_type = metadata
43
- .get_column_view_type(column_name)
44
- .ok_or("Invalid column")?;
45
-
46
- plugin.can_render_column_styles(&view_type.to_string(), group)
47
- }
48
-
49
- /// Queries the plugin for the available style control options for a column.
50
- pub fn get_column_style_control_options(
51
- renderer: &Renderer,
52
- view_config: &ViewConfig,
53
- metadata: &SessionMetadata,
54
- column_name: &str,
55
- ) -> ApiResult<ColumnStyleOpts> {
56
- let plugin = renderer.get_active_plugin()?;
57
- let names: Vec<String> = plugin
58
- .config_column_names()
59
- .and_then(|jsarr| serde_wasm_bindgen::from_value(jsarr.into()).ok())
60
- .unwrap_or_default();
61
-
62
- let group = view_config
63
- .columns
64
- .iter()
65
- .find_position(|maybe_s| maybe_s.as_deref() == Some(column_name))
66
- .and_then(|(idx, _)| names.get(idx))
67
- .map(|s| s.as_str());
68
-
69
- let view_type = metadata
70
- .get_column_view_type(column_name)
71
- .ok_or("Invalid column")?;
72
-
73
- let controls = plugin.column_style_controls(&view_type.to_string(), group)?;
74
- serde_wasm_bindgen::from_value(controls).map_err(|e| e.into())
75
- }
76
-
77
- /// Trait facade — delegates to the standalone functions above.
78
- pub trait PluginColumnStyles: HasSession + HasRenderer {
79
- fn can_render_column_styles(&self, column_name: &str) -> ApiResult<bool> {
80
- can_render_column_styles(
81
- self.renderer(),
82
- &self.session().get_view_config(),
83
- &self.session().metadata(),
84
- column_name,
85
- )
86
- }
87
-
88
- fn get_column_style_control_options(&self, column_name: &str) -> ApiResult<ColumnStyleOpts> {
89
- get_column_style_control_options(
90
- self.renderer(),
91
- &self.session().get_view_config(),
92
- &self.session().metadata(),
93
- column_name,
94
- )
95
- }
96
- }
97
-
98
- impl<T: HasSession + HasRenderer> PluginColumnStyles for T {}
@@ -1,14 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { CustomNumberFormatConfig } from "./CustomNumberFormatConfig.js";
3
- import type { DatetimeColorMode } from "./DatetimeColorMode.js";
4
- import type { DatetimeFormatType } from "./DatetimeFormatType.js";
5
- import type { FormatMode } from "./FormatMode.js";
6
- import type { NumberBackgroundMode } from "./NumberBackgroundMode.js";
7
- import type { NumberForegroundMode } from "./NumberForegroundMode.js";
8
- import type { StringColorMode } from "./StringColorMode.js";
9
-
10
- /**
11
- * The value de/serialized and stored in the viewer config.
12
- * Also passed to the plugin via `plugin.save()`.
13
- */
14
- export type ColumnConfigValues = { symbols?: { [key in string]?: string }, number_format?: CustomNumberFormatConfig | null, aggregate_depth?: number, number_fg_mode?: NumberForegroundMode, number_bg_mode?: NumberBackgroundMode, pos_fg_color: string | null, neg_fg_color: string | null, pos_bg_color: string | null, neg_bg_color: string | null, fg_gradient: number | null, bg_gradient: number | null, format?: FormatMode, string_color_mode?: StringColorMode, color?: string | null, date_format?: DatetimeFormatType, datetime_color_mode?: DatetimeColorMode, };
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type CustomDatetimeFormat = "long" | "short" | "narrow" | "numeric" | "2-digit" | "disabled";
@@ -1,5 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { CustomDatetimeFormat } from "./CustomDatetimeFormat.js";
3
- import type { FormatUnit } from "./FormatUnit.js";
4
-
5
- export type CustomDatetimeStyleConfig = { format: FormatUnit, timeZone?: string | null, fractionalSecondDigits?: number, second?: CustomDatetimeFormat, minute?: CustomDatetimeFormat, hour?: CustomDatetimeFormat, day?: CustomDatetimeFormat, weekday?: CustomDatetimeFormat, month?: CustomDatetimeFormat, year?: CustomDatetimeFormat, hour12?: boolean, };
@@ -1,8 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { RoundingMode } from "./RoundingMode.js";
3
- import type { RoundingPriority } from "./RoundingPriority.js";
4
- import type { SignDisplay } from "./SignDisplay.js";
5
- import type { TrailingZeroDisplay } from "./TrailingZeroDisplay.js";
6
- import type { UseGrouping } from "./UseGrouping.js";
7
-
8
- export type CustomNumberFormatConfig = { minimumIntegerDigits: number | null, minimumFractionDigits: number | null, maximumFractionDigits: number | null, minimumSignificantDigits: number | null, maximumSignificantDigits: number | null, roundingPriority: RoundingPriority | null, roundingIncrement: number | null, roundingMode: RoundingMode | null, trailingZeroDisplay: TrailingZeroDisplay | null, useGrouping: UseGrouping | null, signDisplay: SignDisplay | null, };
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type DatetimeColorMode = "none" | "foreground" | "background";
@@ -1,8 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { CustomDatetimeStyleConfig } from "./CustomDatetimeStyleConfig.js";
3
- import type { SimpleDatetimeStyleConfig } from "./SimpleDatetimeStyleConfig.js";
4
-
5
- /**
6
- * `Simple` case has all default-able keys and must be last!
7
- */
8
- export type DatetimeFormatType = CustomDatetimeStyleConfig | SimpleDatetimeStyleConfig;
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type FormatMode = "none" | "link" | "bold" | "italics";
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type NumberBackgroundMode = "disabled" | "color" | "gradient" | "pulse";
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type NumberForegroundMode = "disabled" | "color" | "bar" | "label-bar";
@@ -1,4 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { JsonValue } from "./serde_json/JsonValue.js";
3
-
4
- export type PluginConfig = JsonValue;
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type RoundingMode = "ceil" | "floor" | "expand" | "trunc" | "halfCeil" | "halfFloor" | "halfExpand" | "halfTrunc" | "halfEven";
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type RoundingPriority = "auto" | "morePrecision" | "lessPrecision";
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type SignDisplay = "auto" | "always" | "exceptZero" | "negative" | "never";
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export type SimpleDatetimeFormat = "full" | "long" | "medium" | "short" | "disabled";