@perspective-dev/viewer 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/dist/cdn/perspective-viewer.js +2 -2
  2. package/dist/cdn/perspective-viewer.js.map +4 -4
  3. package/dist/css/dracula.css +1 -1
  4. package/dist/css/gruvbox-dark.css +1 -1
  5. package/dist/css/gruvbox.css +1 -1
  6. package/dist/css/icons.css +1 -1
  7. package/dist/css/monokai.css +1 -1
  8. package/dist/css/pro-dark.css +1 -1
  9. package/dist/css/pro.css +1 -1
  10. package/dist/css/solarized-dark.css +1 -1
  11. package/dist/css/solarized.css +1 -1
  12. package/dist/css/themes.css +1 -1
  13. package/dist/css/vaporwave.css +1 -1
  14. package/dist/esm/extensions.d.ts +23 -2
  15. package/dist/esm/perspective-viewer.d.ts +2 -7
  16. package/dist/esm/perspective-viewer.inline.js +2 -2
  17. package/dist/esm/perspective-viewer.inline.js.map +4 -4
  18. package/dist/esm/perspective-viewer.js +2 -2
  19. package/dist/esm/perspective-viewer.js.map +4 -4
  20. package/dist/esm/plugin.d.ts +1 -1
  21. package/dist/esm/ts-rs/ViewerConfigUpdate.d.ts +1 -0
  22. package/dist/wasm/perspective-viewer.d.ts +218 -46
  23. package/dist/wasm/perspective-viewer.js +1250 -761
  24. package/dist/wasm/perspective-viewer.wasm +0 -0
  25. package/dist/wasm/perspective-viewer.wasm.d.ts +38 -19
  26. package/package.json +1 -1
  27. package/src/less/containers/scroll-panel.less +0 -1
  28. package/src/less/plugin-selector.less +15 -5
  29. package/src/less/status-bar.less +75 -27
  30. package/src/less/viewer.less +140 -58
  31. package/src/rust/components/column_dropdown.rs +21 -21
  32. package/src/rust/components/column_selector/active_column.rs +131 -120
  33. package/src/rust/components/column_selector/add_expression_button.rs +5 -0
  34. package/src/rust/components/column_selector/aggregate_selector.rs +8 -4
  35. package/src/rust/components/column_selector/config_selector.rs +170 -161
  36. package/src/rust/components/column_selector/empty_column.rs +16 -11
  37. package/src/rust/components/column_selector/{expression_toolbar.rs → expr_edit_button.rs} +7 -0
  38. package/src/rust/components/column_selector/filter_column.rs +195 -194
  39. package/src/rust/components/column_selector/inactive_column.rs +82 -67
  40. package/src/rust/components/column_selector/pivot_column.rs +16 -11
  41. package/src/rust/components/column_selector/sort_column.rs +9 -7
  42. package/src/rust/components/column_selector.rs +42 -37
  43. package/src/rust/components/column_settings_sidebar/save_settings.rs +3 -1
  44. package/src/rust/components/column_settings_sidebar/style_tab/agg_depth_selector.rs +58 -0
  45. package/src/rust/components/column_settings_sidebar/style_tab/symbol/row_selector.rs +6 -6
  46. package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs.rs +2 -94
  47. package/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs_item.rs +111 -0
  48. package/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +3 -3
  49. package/src/rust/components/column_settings_sidebar/style_tab.rs +23 -83
  50. package/src/rust/components/{column_settings_sidebar/sidebar.rs → column_settings_sidebar.rs} +198 -171
  51. package/src/rust/components/containers/dragdrop_list.rs +20 -20
  52. package/src/rust/components/containers/dropdown_menu.rs +4 -6
  53. package/src/rust/components/containers/mod.rs +1 -4
  54. package/src/rust/components/containers/scroll_panel.rs +80 -80
  55. package/src/rust/components/containers/scroll_panel_item.rs +36 -36
  56. package/src/rust/components/containers/select.rs +46 -44
  57. package/src/rust/components/containers/sidebar.rs +3 -19
  58. package/src/rust/components/{column_settings_sidebar/style_tab/symbol/symbol_config.rs → containers/sidebar_close_button.rs} +15 -9
  59. package/src/rust/components/containers/split_panel.rs +212 -200
  60. package/src/rust/components/containers/tab_list.rs +11 -11
  61. package/src/rust/components/copy_dropdown.rs +22 -25
  62. package/src/rust/components/datetime_column_style/custom.rs +19 -19
  63. package/src/rust/components/datetime_column_style/simple.rs +13 -14
  64. package/src/rust/components/datetime_column_style.rs +75 -76
  65. package/src/rust/components/editable_header.rs +18 -14
  66. package/src/rust/components/empty_row.rs +5 -5
  67. package/src/rust/components/export_dropdown.rs +42 -42
  68. package/src/rust/components/expression_editor.rs +25 -19
  69. package/src/rust/components/filter_dropdown.rs +22 -22
  70. package/src/rust/components/font_loader.rs +11 -9
  71. package/src/rust/components/form/code_editor.rs +106 -105
  72. package/src/rust/components/form/color_range_selector.rs +14 -12
  73. package/src/rust/components/form/color_selector.rs +3 -1
  74. package/src/rust/components/form/debug.rs +95 -94
  75. package/src/rust/components/form/highlight.rs +5 -3
  76. package/src/rust/components/form/mod.rs +3 -2
  77. package/src/rust/components/form/optional_field.rs +2 -2
  78. package/src/rust/components/form/{select_field.rs → select_enum_field.rs} +1 -46
  79. package/src/rust/components/form/select_value_field.rs +64 -0
  80. package/src/rust/components/function_dropdown.rs +21 -21
  81. package/src/rust/components/main_panel.rs +219 -0
  82. package/src/rust/components/mod.rs +6 -6
  83. package/src/rust/components/modal.rs +42 -42
  84. package/src/rust/components/number_column_style.rs +34 -88
  85. package/src/rust/components/plugin_selector.rs +22 -25
  86. package/src/rust/components/render_warning.rs +9 -6
  87. package/src/rust/components/settings_panel.rs +82 -0
  88. package/src/rust/components/status_bar.rs +250 -146
  89. package/src/rust/components/status_bar_counter.rs +26 -119
  90. package/src/rust/components/status_indicator.rs +95 -79
  91. package/src/rust/components/string_column_style.rs +45 -45
  92. package/src/rust/components/style/style_provider.rs +1 -15
  93. package/src/rust/components/style_controls/number_string_format/digits_section.rs +1 -1
  94. package/src/rust/components/style_controls/number_string_format/misc_section.rs +1 -1
  95. package/src/rust/components/style_controls/number_string_format/style_section.rs +1 -1
  96. package/src/rust/components/style_controls/number_string_format.rs +45 -46
  97. package/src/rust/components/type_icon.rs +14 -11
  98. package/src/rust/components/viewer.rs +241 -384
  99. package/src/rust/config/columns_config.rs +2 -2
  100. package/src/rust/config/datetime_column_style.rs +1 -6
  101. package/src/rust/config/mod.rs +1 -0
  102. package/src/rust/config/number_column_style.rs +0 -6
  103. package/src/rust/config/number_string_format.rs +27 -4
  104. package/src/rust/config/viewer_config.rs +27 -167
  105. package/src/rust/custom_elements/copy_dropdown.rs +14 -6
  106. package/src/rust/custom_elements/export_dropdown.rs +15 -7
  107. package/src/rust/custom_elements/filter_dropdown.rs +4 -4
  108. package/src/rust/custom_elements/mod.rs +3 -0
  109. package/src/rust/custom_elements/viewer.rs +353 -161
  110. package/src/rust/custom_events.rs +55 -32
  111. package/src/rust/dragdrop.rs +4 -24
  112. package/src/rust/exprtk/cursor.rs +10 -1
  113. package/src/rust/exprtk/mod.rs +2 -0
  114. package/src/rust/exprtk/tokenize.rs +20 -3
  115. package/src/rust/js/clipboard.rs +2 -2
  116. package/src/rust/js/mimetype.rs +2 -7
  117. package/src/rust/js/mod.rs +0 -1
  118. package/src/rust/js/plugin.rs +7 -0
  119. package/src/rust/lib.rs +18 -5
  120. package/src/rust/model/column_locator.rs +82 -0
  121. package/src/rust/model/columns_iter_set.rs +1 -0
  122. package/src/rust/model/copy_export.rs +50 -14
  123. package/src/rust/model/edit_expression.rs +2 -5
  124. package/src/rust/model/eject.rs +41 -0
  125. package/src/rust/model/get_viewer_config.rs +4 -28
  126. package/src/rust/model/intersection_observer.rs +20 -8
  127. package/src/rust/model/mod.rs +11 -4
  128. package/src/rust/model/plugin_column_styles.rs +0 -31
  129. package/src/rust/model/reset_all.rs +38 -0
  130. package/src/rust/model/resize_observer.rs +34 -7
  131. package/src/rust/model/restore_and_render.rs +12 -7
  132. package/src/rust/{utils/scope.rs → model/send_plugin_config.rs} +32 -35
  133. package/src/rust/model/structural.rs +194 -23
  134. package/src/rust/model/update_and_render.rs +14 -4
  135. package/src/rust/{model/create_col.rs → presentation/column_locator.rs} +73 -42
  136. package/src/rust/{utils/wasm_abi.rs → presentation/sheets.rs} +54 -40
  137. package/src/rust/presentation.rs +60 -119
  138. package/src/rust/renderer/activate.rs +20 -5
  139. package/src/rust/renderer/limits.rs +0 -149
  140. package/src/rust/renderer/render_timer.rs +1 -1
  141. package/src/rust/renderer.rs +34 -18
  142. package/src/rust/root.rs +50 -0
  143. package/src/rust/session/column_defaults_update.rs +4 -4
  144. package/src/rust/session/drag_drop_update.rs +1 -1
  145. package/src/rust/session/metadata.rs +3 -17
  146. package/src/rust/session/replace_expression_update.rs +1 -2
  147. package/src/rust/session.rs +162 -82
  148. package/src/rust/utils/browser/blob.rs +16 -2
  149. package/src/rust/utils/browser/download.rs +1 -0
  150. package/src/rust/{components/column_settings_sidebar/mod.rs → utils/browser/dragdrop.rs} +14 -5
  151. package/src/rust/utils/browser/mod.rs +8 -4
  152. package/src/rust/utils/browser/selection.rs +5 -0
  153. package/src/rust/utils/custom_element.rs +28 -13
  154. package/src/rust/utils/datetime.rs +5 -0
  155. package/src/rust/utils/debounce.rs +7 -1
  156. package/src/rust/utils/hooks/use_async_callback.rs +7 -17
  157. package/src/rust/utils/mod.rs +28 -40
  158. package/src/rust/utils/number_format.rs +6 -5
  159. package/src/rust/utils/pubsub.rs +15 -10
  160. package/src/rust/utils/weak_scope.rs +11 -1
  161. package/src/svg/bookmark-icon.svg +4 -0
  162. package/src/svg/drag-handle copy.svg +10 -0
  163. package/src/svg/drawer-tab-hover.svg +5 -7
  164. package/src/svg/drawer-tab-invert-hover.svg +4 -8
  165. package/src/svg/drawer-tab-invert.svg +4 -7
  166. package/src/svg/drawer-tab.svg +4 -6
  167. package/src/svg/status_ok.svg +24 -24
  168. package/src/ts/extensions.ts +51 -3
  169. package/src/ts/perspective-viewer.ts +2 -14
  170. package/src/ts/plugin.ts +1 -1
  171. package/src/ts/ts-rs/ViewerConfigUpdate.ts +1 -1
  172. package/src/rust/components/column_settings_sidebar/style_tab/column_style.rs +0 -177
  173. package/src/rust/components/containers/tests/mod.rs +0 -11
  174. package/src/rust/components/containers/tests/split_panel.rs +0 -91
  175. package/src/rust/js/testing.rs +0 -149
  176. package/src/rust/utils/tee.rs +0 -88
  177. /package/dist/wasm/snippets/{perspective-viewer-9a89352df1552d2b → perspective-viewer-0d326a25c1022412}/inline0.js +0 -0
  178. /package/dist/wasm/snippets/{perspective-viewer-9a89352df1552d2b → perspective-viewer-0d326a25c1022412}/inline1.js +0 -0
  179. /package/dist/wasm/snippets/{perspective-viewer-9a89352df1552d2b → perspective-viewer-0d326a25c1022412}/inline2.js +0 -0
  180. /package/dist/wasm/snippets/{perspective-viewer-9a89352df1552d2b → perspective-viewer-0d326a25c1022412}/inline3.js +0 -0
  181. /package/dist/wasm/snippets/{perspective-viewer-9a89352df1552d2b → perspective-viewer-0d326a25c1022412}/inline4.js +0 -0
  182. /package/src/rust/components/{style_controls.rs → style_controls/mod.rs} +0 -0
  183. /package/src/rust/{components/containers → config}/kvpair.rs +0 -0
@@ -1,177 +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 perspective_client::config::*;
14
- use perspective_client::{clone, ColumnType};
15
- use serde::de::DeserializeOwned;
16
- use yew::{function_component, html, Callback, Html, Properties};
17
-
18
- use crate::components::column_settings_sidebar::style_tab::stub::Stub;
19
- use crate::components::datetime_column_style::DatetimeColumnStyle;
20
- use crate::components::number_column_style::NumberColumnStyle;
21
- use crate::components::string_column_style::StringColumnStyle;
22
- use crate::components::style::LocalStyle;
23
- use crate::config::*;
24
- use crate::custom_events::CustomEvents;
25
- use crate::model::*;
26
- use crate::renderer::Renderer;
27
- use crate::session::Session;
28
- use crate::{css, derive_model};
29
-
30
- /// This function retrieves the plugin's config using its `save` method.
31
- /// It also introduces the `default_config` field for the plugin.
32
- /// If this field does not exist, the plugin is considered to be un-style-able.
33
- fn get_column_style<T, U>(
34
- mut config: PluginConfig,
35
- attrs: PluginAttributes,
36
- column_name: &str,
37
- ty: ColumnType,
38
- ) -> Result<(Option<T>, U), String>
39
- where
40
- T: DeserializeOwned + std::fmt::Debug,
41
- U: DeserializeOwned + std::fmt::Debug,
42
- {
43
- let current_config = if let Some(config) = config.columns.remove(column_name) {
44
- serde_json::from_value(config)
45
- .map_err(|e| format!("Could not deserialize config with error {e:?}"))?
46
- } else {
47
- None
48
- };
49
-
50
- let style = attrs
51
- .style
52
- .ok_or_else(|| "Styles not implemented".to_string())?;
53
- let val = match ty {
54
- ColumnType::String => style.string,
55
- ColumnType::Datetime => style.datetime,
56
- ColumnType::Date => style.date,
57
- ColumnType::Integer => style.integer,
58
- ColumnType::Float => style.float,
59
- ColumnType::Boolean => style.bool,
60
- };
61
- serde_json::from_value(val)
62
- .map_err(|e| format!("Could not deserialize default_config with error {e:?}"))
63
- .map(|default_config| (current_config, default_config))
64
- }
65
-
66
- #[derive(Clone, PartialEq, Properties)]
67
- pub struct ColumnStyleProps {
68
- pub custom_events: CustomEvents,
69
- pub session: Session,
70
- pub renderer: Renderer,
71
- pub column_name: String,
72
- pub view_type: ColumnType,
73
- }
74
- derive_model!(CustomEvents, Session, Renderer for ColumnStyleProps);
75
- #[function_component]
76
- pub fn ColumnStyle(props: &ColumnStyleProps) -> Html {
77
- let props = props.clone();
78
- let (config, attrs) = (props.get_plugin_config(), props.get_plugin_attrs());
79
- let (config, attrs) = (config.unwrap(), attrs.unwrap());
80
- let view_type = props.view_type;
81
-
82
- let opt_html = match view_type {
83
- ColumnType::String => get_column_style::<_, StringColumnStyleDefaultConfig>(
84
- config.clone(),
85
- attrs.clone(),
86
- &props.column_name,
87
- view_type,
88
- )
89
- .map(|(config, default_config)| {
90
- let on_change = Callback::from(move |config| {
91
- props.send_plugin_config(
92
- props.column_name.clone(),
93
- serde_json::to_value(config).ok(),
94
- )
95
- });
96
-
97
- html! {
98
- <>
99
- <div
100
- class="style_contents"
101
- >
102
- <StringColumnStyle {config} {default_config} {on_change} />
103
- </div>
104
- </>
105
- }
106
- }),
107
- ColumnType::Datetime | ColumnType::Date => {
108
- get_column_style::<_, DatetimeColumnStyleDefaultConfig>(
109
- config.clone(),
110
- attrs.clone(),
111
- &props.column_name,
112
- view_type,
113
- )
114
- .map(|(config, default_config)| {
115
- let enable_time_config = matches!(view_type, ColumnType::Datetime);
116
- let on_change = Callback::from(move |config| {
117
- props.send_plugin_config(
118
- props.column_name.clone(),
119
- serde_json::to_value(config).unwrap(),
120
- )
121
- });
122
-
123
- html! {
124
- <div
125
- class="style_contents"
126
- >
127
- <DatetimeColumnStyle
128
- {enable_time_config}
129
- {config}
130
- {default_config}
131
- {on_change}
132
- />
133
- </div>
134
- }
135
- })
136
- },
137
- ColumnType::Integer | ColumnType::Float => {
138
- get_column_style::<_, NumberColumnStyleDefaultConfig>(
139
- config.clone(),
140
- attrs.clone(),
141
- &props.column_name,
142
- view_type,
143
- )
144
- .map(|(config, default_config)| {
145
- let on_change = {
146
- clone!(props);
147
- Callback::from(move |config| {
148
- props.send_plugin_config(
149
- props.column_name.clone(),
150
- serde_json::to_value(config).unwrap(),
151
- )
152
- })
153
- };
154
- html! {
155
- <div
156
- class="style_contents"
157
- >
158
- <NumberColumnStyle
159
- session={props.session.clone()}
160
- column_name={props.column_name.clone()}
161
- {config}
162
- {default_config}
163
- {on_change}
164
- />
165
- </div>
166
- }
167
- })
168
- },
169
- _ => Err("Booleans aren't styled yet.".into()),
170
- };
171
-
172
- let contents = opt_html.unwrap_or_else(|e| {
173
- html! { <Stub message="No styles available" error={e} /> }
174
- });
175
-
176
- html! { <><LocalStyle href={css!("column-style")} />{ contents }</> }
177
- }
@@ -1,11 +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
- // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
@@ -1,91 +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 wasm_bindgen_test::*;
14
- use web_sys::HtmlElement;
15
- use yew::prelude::*;
16
-
17
- use super::super::split_panel::{SplitPanel, SplitPanelMsg};
18
- use crate::utils::{await_animation_frame, WeakScope};
19
- use crate::*;
20
-
21
- wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
22
-
23
- #[wasm_bindgen_test]
24
- pub async fn test_resizes_larger() {
25
- let link: WeakScope<SplitPanel> = WeakScope::default();
26
- let panel_div = NodeRef::default();
27
- test_html! {
28
- <SplitPanel id="test" weak_link={ link.clone() }>
29
- <div ref={ panel_div.clone() } style="background-color: red"></div>
30
- <div style="background-color: green"></div>
31
- </SplitPanel>
32
- };
33
-
34
- await_animation_frame().await.unwrap();
35
- let split_panel = link.borrow().clone().unwrap();
36
- split_panel.send_message(SplitPanelMsg::StartResizing(0, 10));
37
- split_panel.send_message(SplitPanelMsg::MoveResizing(100));
38
- split_panel.send_message(SplitPanelMsg::StopResizing);
39
- await_animation_frame().await.unwrap();
40
-
41
- let width = panel_div.cast::<HtmlElement>().unwrap().offset_width();
42
- assert_eq!(width, 90);
43
- }
44
-
45
- #[wasm_bindgen_test]
46
- pub async fn test_resizes_narrower() {
47
- let link: WeakScope<SplitPanel> = WeakScope::default();
48
- let panel_div = NodeRef::default();
49
- test_html! {
50
- <SplitPanel id="test" weak_link={ link.clone() }>
51
- <div ref={ panel_div.clone() } style="background-color: red"></div>
52
- <div style="background-color: green"></div>
53
- </SplitPanel>
54
- };
55
-
56
- await_animation_frame().await.unwrap();
57
- let split_panel = link.borrow().clone().unwrap();
58
- split_panel.send_message(SplitPanelMsg::StartResizing(0, 10));
59
- split_panel.send_message(SplitPanelMsg::MoveResizing(100));
60
- split_panel.send_message(SplitPanelMsg::StopResizing);
61
- await_animation_frame().await.unwrap();
62
- split_panel.send_message(SplitPanelMsg::StartResizing(0, 100));
63
- split_panel.send_message(SplitPanelMsg::MoveResizing(50));
64
- split_panel.send_message(SplitPanelMsg::StopResizing);
65
- await_animation_frame().await.unwrap();
66
-
67
- let width = panel_div.cast::<HtmlElement>().unwrap().offset_width();
68
- assert_eq!(width, 40);
69
- }
70
-
71
- #[wasm_bindgen_test]
72
- pub async fn test_double_click_reset() {
73
- let link: WeakScope<SplitPanel> = WeakScope::default();
74
- let panel_div = NodeRef::default();
75
- test_html! {
76
- <SplitPanel id="test" weak_link={ link.clone() }>
77
- <div ref={ panel_div.clone() } style="background-color: red"></div>
78
- <div style="background-color: green"></div>
79
- </SplitPanel>
80
- };
81
-
82
- await_animation_frame().await.unwrap();
83
- let split_panel = link.borrow().clone().unwrap();
84
- split_panel.send_message(SplitPanelMsg::StartResizing(0, 10));
85
- split_panel.send_message(SplitPanelMsg::MoveResizing(100));
86
- split_panel.send_message(SplitPanelMsg::StopResizing);
87
- split_panel.send_message(SplitPanelMsg::Reset(0));
88
-
89
- let width = panel_div.cast::<HtmlElement>().unwrap().offset_width();
90
- assert_eq!(width, 0);
91
- }
@@ -1,149 +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
- #[cfg(test)]
14
- use wasm_bindgen::prelude::*;
15
-
16
- // Must use inline build because the test runner does not import itself in
17
- // the browser with `type=module` which causes `import.meta` calls to fail,
18
- // and `currentScript` does not resolve dynamic imports so the polyfill
19
- // for `import.meta` does not work either.
20
- #[cfg(test)]
21
- #[wasm_bindgen(inline_js = "
22
-
23
- export async function worker() {
24
- await import('/dist/wasm/test/perspective.js');
25
- return window.perspective.worker();
26
- }
27
-
28
- ")]
29
- extern "C" {
30
- fn worker() -> js_sys::Promise;
31
- }
32
-
33
- // /// Generate a test `Table`, but only create teh webworker once or the tests
34
- // /// will figuratively literally run forever.
35
- // #[cfg(test)]
36
- // pub async fn get_mock_table() -> JsPerspectiveTable {
37
- // thread_local! {
38
- // static WORKER: RefCell<Option<JsPerspectiveWorker>> =
39
- // RefCell::new(None); }
40
-
41
- // let worker: JsPerspectiveWorker = match WORKER.with(|x|
42
- // x.borrow().clone()) { Some(x) => x,
43
- // None => JsFuture::from(worker()).await.unwrap().unchecked_into(),
44
- // };
45
-
46
- // WORKER.with(|x| {
47
- // *x.borrow_mut() = Some(worker.clone());
48
- // });
49
-
50
- // worker
51
- // .table(
52
- // json!({
53
- // "A": [1, 2, 3]
54
- // })
55
- // .unchecked_into(),
56
- // )
57
- // .await
58
- // .unwrap()
59
- // }
60
-
61
- /// A macro which set a property called `weak_link` on the container
62
- /// `Properties` when `cfg(test)`, such that unit tests may send messages to a
63
- /// component.
64
- ///
65
- /// This macro needs to be called in `create()` on any Component which needs to
66
- /// receive messages in a test.
67
- #[macro_export]
68
- macro_rules! enable_weak_link_test {
69
- ($props:expr, $link:expr) => {
70
- #[cfg(test)]
71
- {
72
- *$props.weak_link.borrow_mut() = Some($link.clone());
73
- }
74
- };
75
- }
76
-
77
- /// A macro which derives a `yew::Component` for an arbitrary HTML snippet and
78
- /// mounts it, for testing.
79
- #[macro_export]
80
- macro_rules! test_html {
81
- ($($html:tt)*) => {{
82
- use wasm_bindgen::JsCast;
83
- use yew::prelude::*;
84
-
85
- struct TestElement {}
86
-
87
- #[derive(Properties, PartialEq)]
88
- struct TestElementProps {
89
- html: Html,
90
- root: NodeRef,
91
- }
92
-
93
- impl Component for TestElement {
94
- type Message = ();
95
- type Properties = TestElementProps;
96
-
97
- fn create(_ctx: &Context<Self>) -> Self {
98
- TestElement {}
99
- }
100
-
101
- fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool {
102
- false
103
- }
104
-
105
- fn changed(&mut self, _ctx: &Context<Self>, _old: &Self::Properties) -> bool {
106
- true
107
- }
108
-
109
- fn view(&self, ctx: &Context<Self>) -> Html {
110
- html! {
111
- <>
112
- <style>
113
- { "#test{position:absolute;top:0;bottom:0;left:0;right:0;}" }
114
- </style>
115
- <div ref={ ctx.props().root.clone() }>
116
- { ctx.props().html.clone() }
117
- </div>
118
- </>
119
- }
120
- }
121
- }
122
-
123
- let document = ::perspective_js::utils::global::document();
124
- let body = document.body().unwrap();
125
- let div = document.create_element("div").unwrap();
126
- body.append_child(&div).unwrap();
127
-
128
- let init = web_sys::ShadowRootInit::new(web_sys::ShadowRootMode::Open);
129
- let shadow_root = div
130
- .attach_shadow(&init)
131
- .unwrap()
132
- .unchecked_into::<web_sys::Element>();
133
-
134
- let root = NodeRef::default();
135
- let props = TestElementProps {
136
- html: html!{ $($html)* },
137
- root: root.clone(),
138
- };
139
-
140
- yew::Renderer::<TestElement>::with_root_and_props(shadow_root, props).render();
141
- request_animation_frame().await;
142
- root.cast::<web_sys::HtmlElement>()
143
- .unwrap()
144
- .children()
145
- .get_with_index(0)
146
- .unwrap()
147
- .unchecked_into::<web_sys::HtmlElement>()
148
- }}
149
- }
@@ -1,88 +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
- /// Trait for polymorphic return value via turbofish-const-generic syntax.
14
- ///
15
- /// The associated type `Output` is a functional dependency of the const generic
16
- /// parameter `N`, so there's typically no need to specify this parameter when
17
- /// invoking, which is what we want - this parameter is quite verbose and
18
- /// repetitive (see below), vs `N` which is a single character.
19
- pub trait TeeInternal<const N: usize> {
20
- type Output: Clone;
21
- fn tee_internal(self) -> Self::Output;
22
- }
23
-
24
- pub trait Tee {
25
- /// Extension method to add `tee()` method to all `T: Clone`.
26
- ///
27
- /// This can't be done directly as part of `TeeInternal` because it makes
28
- /// specifying the const param at the `tee()` invocation site
29
- /// cumbersome: `TeeInternal::<N>::tee(&obj)` as opposed to
30
- /// `obj.tee::<N>()`. The constraint `Self: TeeInternal<N>` collapses
31
- /// the potential `impl` matches to exactly 1, which makes the call to
32
- /// `tee_internal()` unambiguous. This constraint is also allowed to
33
- /// contain the generic parameter `N` because it is specified as a
34
- /// constraint to the method (as opposed to a constraint on the trait).
35
- /// I'm honestly quite surprised this works ...
36
- ///
37
- /// # Examples
38
- ///
39
- /// ```
40
- /// let x = "test".tee::<2>();
41
- /// assert_eq!(x.0, x.1);
42
- /// assert_eq!(x.0, "test");
43
- /// ```
44
- fn tee<const N: usize>(self) -> <Self as TeeInternal<N>>::Output
45
- where
46
- Self: TeeInternal<N>;
47
- }
48
-
49
- impl<T: Clone> Tee for T {
50
- fn tee<const N: usize>(self) -> <Self as TeeInternal<N>>::Output
51
- where
52
- Self: TeeInternal<N>,
53
- {
54
- self.tee_internal()
55
- }
56
- }
57
-
58
- macro_rules! gen_tee {
59
- ($($x:ty),*) => {
60
- impl<T: Clone> TeeInternal<{${count($x)} + 1}> for T {
61
- type Output = ($($x),*, T);
62
- fn tee_internal(self) -> Self::Output {
63
- ($( ${ignore($x)} self.clone() ),*, self)
64
- }
65
- }
66
- };
67
- }
68
-
69
- gen_tee!(T);
70
- gen_tee!(T, T);
71
- gen_tee!(T, T, T);
72
- gen_tee!(T, T, T, T);
73
- gen_tee!(T, T, T, T, T);
74
- gen_tee!(T, T, T, T, T, T);
75
- gen_tee!(T, T, T, T, T, T, T);
76
- gen_tee!(T, T, T, T, T, T, T, T);
77
-
78
- #[cfg(test)]
79
- mod tests {
80
- use super::*;
81
-
82
- #[test]
83
- fn test_test1() {
84
- let x = "test".tee::<2>();
85
- assert_eq!(x.0, x.1);
86
- assert_eq!(x.0, "test");
87
- }
88
- }