diff --git a/docs/md/how_to/javascript/viewer.md b/docs/md/how_to/javascript/viewer.md index 3b42ae0d5c..11a937b11e 100644 --- a/docs/md/how_to/javascript/viewer.md +++ b/docs/md/how_to/javascript/viewer.md @@ -91,6 +91,13 @@ The viewer provides an interactive side panel with: - **Copy** - copy the current view to the clipboard. - **Reset** - restore the viewer to its default configuration. +Clicking the status icon opens the workspace panel on the left, which lists +each loaded `Client`'s tables, shows the element's `WorkspaceConfig` as +editable JSON, and hosts the agent chat. It floats over the panels by default +and can be pinned alongside them. A `Client` whose connection is lost, or +whose panels have failed, shows its error there with a Reconnect button when +it can be recovered. + ## Methods A `` hosts one or more _panels_. Methods which address a @@ -185,6 +192,7 @@ for charts and text for the datagrid. | `resize(options?)` | Redraw, optionally at a `{dimensions: {width, height}}` size hint | | `setAutoSize(bool)` / `setAutoPause(bool)` / `setThrottle(ms)` | Render policy | | `toggleConfig(force?)` | Toggle the settings sidebar | +| `toggleWorkspaceConfig(force?)` | Toggle the workspace panel | | `toggleColumnSettings(...)` | Toggle the column settings sidebar | | `resetThemes(themes?)` | Re-detect or explicitly set available themes | | `restyleElement()` | Re-read CSS and repaint | diff --git a/docs/src/data/projects/dashboards.ts b/docs/src/data/projects/dashboards.ts index a92d86399a..0c5a5e3f04 100644 --- a/docs/src/data/projects/dashboards.ts +++ b/docs/src/data/projects/dashboards.ts @@ -281,7 +281,7 @@ export const DASHBOARD_PROJECTS: Project[] = [ workspace: multiPanel(ORDER_FLOW, { depth: market("Depth Timeseries", "Vaporwave"), heat: market("Heatmap", "Solarized Dark"), - closed: market("Closed Orders", "Solarized Light"), + closed: market("Closed Orders", "Solarized"), }), }, { diff --git a/examples/esbuild-example/src/index.js b/examples/esbuild-example/src/index.js index db636c8345..c4d326deca 100644 --- a/examples/esbuild-example/src/index.js +++ b/examples/esbuild-example/src/index.js @@ -32,7 +32,12 @@ const req = fetch(arrow); const viewer = document.createElement("perspective-viewer"); document.body.append(viewer); const worker = await perspective.worker(); +const worker2 = await perspective.worker(); const resp = await req; const buffer = await resp.arrayBuffer(); -const table = worker.table(buffer); -viewer.load(table); +await worker.table(buffer, { name: "superstore1" }); +await worker2.table(buffer, { name: "superstore2" }); +viewer.load(worker); +viewer.load(worker2); + +window.TEST = worker2; diff --git a/packages/viewer-datagrid/src/ts/commands.ts b/packages/viewer-datagrid/src/ts/commands.ts index aa9eb9f394..4409e0d22d 100644 --- a/packages/viewer-datagrid/src/ts/commands.ts +++ b/packages/viewer-datagrid/src/ts/commands.ts @@ -97,7 +97,7 @@ export function query_commands( /** * Whether `location` is in the app's scopes, asked with an empty frame so no - * schema call runs. + * schema call runs; `false` when the host throws. */ export function is_command_scope( plugin: DatagridPluginElement, @@ -116,7 +116,12 @@ export function is_command_scope( data: {}, }; - return viewer.queryCommands(plugin, location, frame, []) !== undefined; + try { + return viewer.queryCommands(plugin, location, frame, []) !== undefined; + } catch (error) { + console.error(`Failed to query "${location}" command scope`, error); + return false; + } } function command_button( diff --git a/packages/viewer-datagrid/test/js/plugin_config_options.spec.ts b/packages/viewer-datagrid/test/js/plugin_config_options.spec.ts index e6b6c11164..ed986ab9c4 100644 --- a/packages/viewer-datagrid/test/js/plugin_config_options.spec.ts +++ b/packages/viewer-datagrid/test/js/plugin_config_options.spec.ts @@ -374,22 +374,24 @@ test.describe("Datagrid plugin_config text and row options", () => { await viewer.flush(); }); - const wrapped = await page.evaluate(async () => { - const datagrid = document.querySelector( - "perspective-viewer-datagrid", - ) as any; - - const rows = [ - ...datagrid.regular_table.querySelectorAll("tbody tr"), - ].slice(0, 3); - - return rows.map( - (tr: Element) => - tr.children[0].querySelector(".psp-wrap") !== null, - ); - }); - - expect(wrapped).toEqual([true, true, true]); + await expect + .poll(() => + page.evaluate(async () => { + const datagrid = document.querySelector( + "perspective-viewer-datagrid", + ) as any; + + const rows = [ + ...datagrid.regular_table.querySelectorAll("tbody tr"), + ].slice(0, 3); + + return rows.map( + (tr: Element) => + tr.children[0].querySelector(".psp-wrap") !== null, + ); + }), + ) + .toEqual([true, true, true]); }); test("double-clicking a narrowed column's handle unboxes it and restores auto width", async ({ diff --git a/rust/perspective-client/src/rust/client.rs b/rust/perspective-client/src/rust/client.rs index 46558a8824..d053867af3 100644 --- a/rust/perspective-client/src/rust/client.rs +++ b/rust/perspective-client/src/rust/client.rs @@ -244,6 +244,23 @@ impl ReconnectCallback { } } +/// Whether a [`Client`] can currently reach its `Server`. +#[derive(Clone)] +pub enum Connection { + Open, + Lost { + error: ClientError, + reconnect: Option, + }, +} + +impl Connection { + /// Whether requests can be sent. + pub fn is_open(&self) -> bool { + matches!(self, Self::Open) + } +} + /// An instance of a [`Client`] is a connection to a single /// `perspective_server::Server`, whether locally in-memory or remote over some /// transport like a WebSocket. @@ -251,6 +268,7 @@ impl ReconnectCallback { pub struct Client { name: Arc, features: Arc>>, + connection: Arc>, send: SendCallback, id_gen: IDGen, subscriptions_errors: Subscriptions, @@ -290,6 +308,7 @@ impl Client { Ok(Client { name: Arc::new(name), features: Arc::default(), + connection: Arc::new(std::sync::RwLock::new(Connection::Open)), id_gen: IDGen::default(), send, subscriptions: Subscriptions::default(), @@ -315,6 +334,28 @@ impl Client { self.name.as_str() } + /// Whether this [`Client`] can currently reach its `Server`, and the error + /// and reconnect function of the loss when it cannot. + pub fn connection(&self) -> Connection { + self.connection + .read() + .unwrap_or_else(|x| x.into_inner()) + .clone() + } + + fn set_connection(&self, connection: Connection) -> Connection { + let mut guard = self.connection.write().unwrap_or_else(|x| x.into_inner()); + + std::mem::replace(&mut *guard, connection) + } + + fn check_open(&self) -> ClientResult<()> { + match self.connection() { + Connection::Open => Ok(()), + Connection::Lost { error, .. } => Err(ClientError::TransportError(error.to_string())), + } + } + /// Handle a message from the external message queue. /// [`Client::handle_response`] is part of the low-level message-handling /// API necessary to implement new transports for a [`Client`] @@ -351,7 +392,8 @@ impl Client { Ok(false) } - /// Handle an exception from the underlying transport. + /// Handle an exception from the underlying transport, after which every + /// request is rejected until `reconnect` succeeds. pub async fn handle_error( &self, message: ClientError, @@ -361,20 +403,38 @@ impl Client { T: Fn() -> U + Clone + Send + Sync + 'static, U: Future>, { + let reconnect = reconnect.map(|f| { + let connection = Arc::downgrade(&self.connection); + ReconnectCallback(Arc::new(move || { + clone!(f, connection); + Box::pin(async move { + f().await?; + if let Some(connection) = connection.upgrade() { + *connection.write().unwrap_or_else(|x| x.into_inner()) = Connection::Open; + } + + Ok(()) + }) as LocalBoxFuture<'static, _> + })) + }); + + let previous = self.set_connection(Connection::Lost { + error: message.clone(), + reconnect: reconnect.clone(), + }); + + if !previous.is_open() { + return Ok(()); + } + let subs = self.subscriptions_errors.read().await; - let tasks = join_all(subs.values().map(|callback| { - callback( - message.clone(), - reconnect.clone().map(move |f| { - ReconnectCallback(Arc::new(move || { - clone!(f); - Box::pin(async move { Ok(f().await?) }) as LocalBoxFuture<'static, _> - })) - }), - ) - })); + let tasks = join_all( + subs.values() + .map(|callback| callback(message.clone(), reconnect.clone())), + ); tasks.await.into_iter().collect::>()?; + drop(subs); self.close_and_error_subscriptions(&message).await } @@ -444,6 +504,7 @@ impl Client { msg: &Request, on_update: Box ClientResult<()> + Send + Sync + 'static>, ) -> ClientResult<()> { + self.check_open()?; self.subscriptions_once .write() .await @@ -463,6 +524,7 @@ impl Client { T: Fn(Response) -> U + Send + Sync + 'static, U: Future> + Send + 'static, { + self.check_open()?; self.subscriptions .write() .await @@ -939,3 +1001,89 @@ impl Client { } } } + +#[cfg(test)] +mod tests { + use std::sync::atomic::{AtomicUsize, Ordering}; + + use futures::executor::block_on; + + use super::*; + + fn counting_client() -> (Client, Arc) { + let sent = Arc::new(AtomicUsize::new(0)); + let client = Client::new_with_callback(None, { + clone!(sent); + move |_| { + sent.fetch_add(1, Ordering::SeqCst); + async { Ok(()) } + } + }) + .unwrap(); + + (client, sent) + } + + fn request(client: &Client) -> ClientResult<()> { + let msg = Request { + msg_id: client.gen_id(), + entity_id: "".to_owned(), + client_req: Some(ClientReq::GetFeaturesReq(GetFeaturesReq {})), + }; + + block_on(client.subscribe_once(&msg, Box::new(|_| Ok(())))) + } + + #[test] + fn test_lost_client_rejects_without_sending() { + let (client, sent) = counting_client(); + let reconnect = || async { Ok::<(), ClientError>(()) }; + block_on(client.handle_error(ClientError::Unknown("closed".to_owned()), Some(reconnect))) + .unwrap(); + + assert!(!client.connection().is_open()); + assert!(block_on(client.get_hosted_table_names()).is_err()); + assert_eq!(sent.load(Ordering::SeqCst), 0); + } + + #[test] + fn test_reconnect_reopens_client() { + let (client, sent) = counting_client(); + let reconnect = || async { Ok::<(), ClientError>(()) }; + block_on(client.handle_error(ClientError::Unknown("closed".to_owned()), Some(reconnect))) + .unwrap(); + + let Connection::Lost { + reconnect: Some(reconnect), + .. + } = client.connection() + else { + panic!("Expected a reconnectable lost connection"); + }; + + block_on(reconnect()).unwrap(); + assert!(client.connection().is_open()); + request(&client).unwrap(); + assert_eq!(sent.load(Ordering::SeqCst), 1); + } + + #[test] + fn test_on_error_fires_once_per_loss() { + let (client, _) = counting_client(); + let fired = Arc::new(AtomicUsize::new(0)); + block_on(client.on_error({ + clone!(fired); + move |_, _| { + fired.fetch_add(1, Ordering::SeqCst); + async { Ok::<(), ClientError>(()) } + } + })) + .unwrap(); + + let none = None:: futures::future::Ready>>; + block_on(client.handle_error(ClientError::Unknown("a".to_owned()), none)).unwrap(); + block_on(client.handle_error(ClientError::Unknown("b".to_owned()), none)).unwrap(); + assert_eq!(fired.load(Ordering::SeqCst), 1); + assert!(request(&client).is_err()); + } +} diff --git a/rust/perspective-client/src/rust/lib.rs b/rust/perspective-client/src/rust/lib.rs index 922e07c1a1..b0838441af 100644 --- a/rust/perspective-client/src/rust/lib.rs +++ b/rust/perspective-client/src/rust/lib.rs @@ -52,7 +52,9 @@ pub mod proto; pub mod utils; -pub use crate::client::{Client, ClientHandler, Features, ReconnectCallback, SystemInfo}; +pub use crate::client::{ + Client, ClientHandler, Connection, Features, ReconnectCallback, SystemInfo, +}; use crate::proto::HostedTable; pub use crate::proto::JoinType; pub use crate::session::{ProxySession, Session}; diff --git a/rust/perspective-js/src/ts/perspective.node.ts b/rust/perspective-js/src/ts/perspective.node.ts index ea48a418d1..7674f7de04 100644 --- a/rust/perspective-js/src/ts/perspective.node.ts +++ b/rust/perspective-js/src/ts/perspective.node.ts @@ -581,6 +581,7 @@ export async function worker(worker: Promise) { async () => { console.debug("Closing WebWorker"); port.close(); + await client.handle_error("Worker terminated"); }, ); diff --git a/rust/perspective-js/src/ts/wasm/browser.ts b/rust/perspective-js/src/ts/wasm/browser.ts index 882bd75cd7..348c700b97 100644 --- a/rust/perspective-js/src/ts/wasm/browser.ts +++ b/rust/perspective-js/src/ts/wasm/browser.ts @@ -105,6 +105,7 @@ export async function worker( async () => { console.debug("Closing WebWorker"); close(); + await client.handle_error("Worker terminated"); }, ); @@ -113,6 +114,17 @@ export async function worker( client.handle_response(json.data); }; + port.onmessageerror = () => { + client.handle_error("Worker message error"); + }; + + if (!(webworker instanceof MessagePort)) { + webworker.onerror = (event: Event) => { + const msg = (event as ErrorEvent).message || "Worker error"; + client.handle_error(msg); + }; + } + return client; } diff --git a/rust/perspective-viewer/src/rust/queries/hosted_tables.rs b/rust/perspective-js/test/js/connection.spec.js similarity index 70% rename from rust/perspective-viewer/src/rust/queries/hosted_tables.rs rename to rust/perspective-js/test/js/connection.spec.js index a02b99ce55..c3bc7da10b 100644 --- a/rust/perspective-viewer/src/rust/queries/hosted_tables.rs +++ b/rust/perspective-js/test/js/connection.spec.js @@ -10,29 +10,28 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -use crate::workspace::Workspace; +import { test, expect } from "@perspective-dev/test"; +import { make_client } from "@perspective-dev/client"; -/// Every hosted `Table` name per loaded `Client`, as `(client name, sorted -/// table names)` in registration order. -pub async fn fetch_hosted_tables(workspace: &Workspace) -> Vec<(String, Vec)> { - let clients = workspace.clients(); - let mut tables = Vec::with_capacity(clients.len()); - for client in clients { - let mut names = match client.get_hosted_table_names().await { - Ok(names) => names, - Err(err) => { - tracing::warn!( - "Failed to list tables for `Client` \"{}\": {err}", - client.get_name() - ); +test("A client rejects requests once its transport reports an error", async () => { + let sent = 0; + const client = make_client(async () => { + sent++; + }); - vec![] - }, - }; + await client.handle_error("closed"); + await expect(client.get_hosted_table_names()).rejects.toThrow(); + expect(sent).toEqual(0); +}); - names.sort_unstable(); - tables.push((client.get_name().to_owned(), names)); - } +test("A client fires `on_error` once per lost connection", async () => { + let fired = 0; + const client = make_client(async () => {}); + await client.on_error(() => { + fired++; + }); - tables -} + await client.handle_error("closed"); + await client.handle_error("closed again"); + expect(fired).toEqual(1); +}); diff --git a/rust/perspective-viewer/src/css/_viewer_bundle.css b/rust/perspective-viewer/src/css/_viewer_bundle.css index f3f8ad59df..ffdfbd55af 100644 --- a/rust/perspective-viewer/src/css/_viewer_bundle.css +++ b/rust/perspective-viewer/src/css/_viewer_bundle.css @@ -33,6 +33,9 @@ @import "plugin-selector.css"; @import "render-warning.css"; @import "status-bar.css"; +@import "status-indicator.css"; +@import "error-dialog.css"; +@import "workspace-panel.css"; @import "ui/form/mirrored-textarea.css"; @import "ui/form/sidebar-controls.css"; diff --git a/rust/perspective-viewer/src/css/column-settings-panel.css b/rust/perspective-viewer/src/css/column-settings-panel.css index a4359fc807..c87aa973fe 100644 --- a/rust/perspective-viewer/src/css/column-settings-panel.css +++ b/rust/perspective-viewer/src/css/column-settings-panel.css @@ -139,7 +139,7 @@ .sidebar_pin_button { position: absolute; - right: 6px; + right: 12px; width: 14px; height: 14px; z-index: 8; diff --git a/rust/perspective-viewer/src/css/column-style.css b/rust/perspective-viewer/src/css/column-style.css index f95c028add..912c2ad5c2 100644 --- a/rust/perspective-viewer/src/css/column-style.css +++ b/rust/perspective-viewer/src/css/column-style.css @@ -294,86 +294,6 @@ padding: 0px 0; } - details.control-group { - margin: 0 -8px 0 -8px; - padding: 0 8px 0 8px; - - &:not([open]):hover { - color: var(--psp--background-color); - background-color: var(--psp--color); - border-color: var(--psp--color) !important; - } - - &[open] summary:hover { - color: var(--psp--color); - } - - &:not(:first-child) { - border-top: 1px solid var(--psp-inactive--color); - } - - &:last-of-type { - border-bottom: 1px solid var(--psp-inactive--color); - } - - &:first-child { - margin-top: -12px; - } - - > summary { - display: flex; - align-items: center; - cursor: pointer; - list-style: none; - margin: 0; - padding-right: 6px; - outline: none; - - &::-webkit-details-marker { - display: none; - } - - > span.control-group-chevron { - flex: 0 0 8px; - height: 4px; - background-color: currentColor; - mask-image: var(--psp-icon--select-arrow--mask-image); - -webkit-mask-image: var( - --psp-icon--select-arrow--mask-image - ); - -webkit-mask-repeat: no-repeat; - mask-repeat: no-repeat; - mask-size: cover; - -webkit-mask-position: center; - mask-position: center; - transform: rotate(-90deg); - margin-right: 2px; - } - - label { - padding-top: 8px; - padding-bottom: 8px; - pointer-events: none; - flex: 1 1 auto; - width: auto; - margin: 0 0 0 6px; - } - } - - &[open] > summary label { - padding-bottom: 8px; - } - - &[open] > summary { - color: var(--psp-inactive--color); - margin-bottom: 2px; - } - - &[open] > summary > span.control-group-chevron { - transform: none; - } - } - .color-gradient-container { display: flex; align-items: center; @@ -771,4 +691,87 @@ } } } + + :is( + #column-style-container, + #plugin-config-container, + #window-editor-container, + #workspace-tables + ) + details.control-group { + margin: 0 -8px 0 -8px; + padding: 0 8px 0 8px; + + &:not([open]):hover { + color: var(--psp--background-color); + background-color: var(--psp--color); + border-color: var(--psp--color) !important; + } + + &[open] summary:hover { + color: var(--psp--color); + } + + &:not(:first-child) { + border-top: 1px solid var(--psp-inactive--color); + } + + &:last-of-type { + border-bottom: 1px solid var(--psp-inactive--color); + } + + &:first-child { + margin-top: -12px; + } + + > summary { + display: flex; + align-items: center; + cursor: pointer; + list-style: none; + margin: 0; + padding-right: 6px; + outline: none; + + &::-webkit-details-marker { + display: none; + } + + > span.control-group-chevron { + flex: 0 0 8px; + height: 4px; + background-color: currentColor; + mask-image: var(--psp-icon--select-arrow--mask-image); + -webkit-mask-image: var(--psp-icon--select-arrow--mask-image); + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + mask-size: cover; + -webkit-mask-position: center; + mask-position: center; + transform: rotate(-90deg); + } + + label { + padding-top: 8px; + padding-bottom: 8px; + pointer-events: none; + flex: 1 1 auto; + width: auto; + margin: 0 0 0 6px; + } + } + + &[open] > summary label { + padding-bottom: 8px; + } + + &[open] > summary { + color: var(--psp-inactive--color); + margin-bottom: 2px; + } + + &[open] > summary > span.control-group-chevron { + transform: none; + } + } } diff --git a/rust/perspective-viewer/src/css/error-dialog.css b/rust/perspective-viewer/src/css/error-dialog.css new file mode 100644 index 0000000000..72f25fbf31 --- /dev/null +++ b/rust/perspective-viewer/src/css/error-dialog.css @@ -0,0 +1,86 @@ +/* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + * ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ + * ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ + * ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ + * ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ + * ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + * ┃ Copyright (c) 2017, the Perspective Authors. ┃ + * ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ + * ┃ This file is part of the Perspective library, distributed under the terms ┃ + * ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ + * ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + +:host { + .error-dialog { + display: flex; + flex-direction: column; + gap: 4px; + padding: 8px 8px; + max-height: 300px; + white-space: pre-wrap; + overflow-wrap: anywhere; + color: var(--psp--background-color); + background: var(--psp--color); + border-radius: var(--psp-status-bar--border-radius, 3px); + } + + .error-dialog-message { + flex: 0 0 auto; + } + + .error-dialog-details { + flex: 0 1 auto; + min-height: 0; + font-size: 10px; + + > summary { + cursor: pointer; + color: var(--psp-inactive--color); + min-height: 18px; + line-height: 18px; + } + } + + .error-dialog-stack { + max-height: 200px; + margin-top: 8px; + overflow-y: auto; + color: var(--psp-inactive--color); + + &.scrollable::-webkit-scrollbar-thumb, + &.scrollable:hover::-webkit-scrollbar-thumb { + box-shadow: inset 0px 0px 0 4px var(--psp--background-color); + } + } + + .error-dialog-details:not([open]) .error-dialog-copy { + display: none; + } + + .error-dialog-reconnect { + margin-left: 4px; + } + + .error-dialog-reconnect, + .error-dialog-copy { + float: right; + appearance: none; + height: 18px; + padding: 0 8px; + border: 1px solid currentColor; + border-radius: 3px; + background-color: transparent; + color: var(--psp--background-color); + cursor: pointer; + font-family: inherit; + font-size: 9px; + line-height: 16px; + text-transform: uppercase; + + &:hover { + background-color: var(--psp--background-color); + color: var(--psp--color); + } + } +} diff --git a/rust/perspective-viewer/src/css/form/code-editor.css b/rust/perspective-viewer/src/css/form/code-editor.css index 24897236bb..3300b20cbb 100644 --- a/rust/perspective-viewer/src/css/form/code-editor.css +++ b/rust/perspective-viewer/src/css/form/code-editor.css @@ -126,7 +126,21 @@ #textarea_editable, #content { white-space: pre-wrap; - word-wrap: break-word; + overflow-wrap: anywhere; + } + + .editor-inner, + #line_numbers { + overflow: visible; + } + + .editor-inner { + min-width: 0; + } + + #textarea_editable { + overflow: hidden; + padding-right: 6px; } } } diff --git a/rust/perspective-viewer/src/css/form/debug.css b/rust/perspective-viewer/src/css/form/debug.css index f9db772b16..eac2d89b3b 100644 --- a/rust/perspective-viewer/src/css/form/debug.css +++ b/rust/perspective-viewer/src/css/form/debug.css @@ -12,12 +12,14 @@ */ :host { - #debug-panel-overflow { + #debug-panel-overflow, + #workspace-json-overflow { overflow: hidden; display: flex; } - #debug-panel { + #debug-panel, + #workspace-json { display: flex; min-width: 150px; label { @@ -26,46 +28,61 @@ font-size: var(--label--font-size, 0.75em); } - #debug-panel-controls { + #debug-panel-controls, + #workspace-json-controls { button { - &#debug-panel-apply:before { + &#debug-panel-apply:before, + &#workspace-json-apply:before { content: var( --psp-label--apply-button--content, var(--psp-missing) ); } - &#debug-panel-reset:before { + &#debug-panel-reset:before, + &#workspace-json-reset:before { content: var( --psp-label--reset-button--content, var(--psp-missing) ); } - &#debug-panel-copy:before { + &#debug-panel-copy:before, + &#workspace-json-copy:before { content: var( --psp-label--copy-button--content, var(--psp-missing) ); } - &#debug-panel-paste:before { + &#debug-panel-paste:before, + &#workspace-json-paste:before { content: var( --psp-label--paste-button--content, var(--psp-missing) ); } + + &#debug-panel-formatted:before, + &#workspace-json-formatted:before { + content: var( + --psp-label--formatted-button--content, + var(--psp-missing) + ); + } } } - #debug-panel-editor { + #debug-panel-editor, + #workspace-json-editor { display: flex; flex-direction: column; flex: 0 1 auto; overflow: hidden; padding: 8px 8px 8px 0; - #debug-panel-error { + #debug-panel-error, + #workspace-json-error { flex: 0 0 auto; padding-top: 6px; font-size: 10px; @@ -81,6 +98,11 @@ border-radius: 2px; font-size: 0.8em; /* height: 100%; */ + align-items: flex-start; + + .editor-inner { + min-height: 100%; + } } } } diff --git a/rust/perspective-viewer/src/css/panel-tab.css b/rust/perspective-viewer/src/css/panel-tab.css index 1afc2e86af..1b1c137350 100644 --- a/rust/perspective-viewer/src/css/panel-tab.css +++ b/rust/perspective-viewer/src/css/panel-tab.css @@ -126,7 +126,7 @@ mask-position: center; } -:host([part~="tab"].active) .psp-tab-caret { +:host([part~="tab"].active:not(.settings-closed)) .psp-tab-caret { display: block; -webkit-mask-image: var(--psp-icon--active-indicator--mask-image); mask-image: var(--psp-icon--active-indicator--mask-image); @@ -143,6 +143,83 @@ display: none; } +:host([part~="tab"]:not(.active)) .psp-tab-caret.errored, +:host([part~="tab"].settings-closed) .psp-tab-caret.errored, +:host([part~="tab"].single) .psp-tab-caret.errored { + display: block; + background-color: transparent; + -webkit-mask-image: none; + mask-image: none; + color: var(--psp--color); + font-weight: bold; + line-height: 12px; + text-align: center; +} + +:host([part~="tab"]:not(.active)) .psp-tab-caret.errored::before, +:host([part~="tab"].settings-closed) .psp-tab-caret.errored::before, +:host([part~="tab"].single) .psp-tab-caret.errored::before { + content: "!"; +} + +.psp-tab-status { + flex: 0 0 auto; + display: flex; + align-items: center; + justify-content: center; + width: 20px; + height: 20px; + margin: 0 8px 0 -4px; + cursor: pointer; + background-color: var(--psp--color); + -webkit-mask-image: var(--psp-icon--status-ok--mask-image); + mask-image: var(--psp-icon--status-ok--mask-image); + -webkit-mask-size: contain; + mask-size: contain; + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + -webkit-mask-position: center; + mask-position: center; +} + +.psp-tab-status.updating { + -webkit-mask-image: var(--psp-icon--updating--mask-image); + mask-image: var(--psp-icon--updating--mask-image); +} + +.psp-tab-status.loading { + -webkit-mask-image: var(--psp-icon--downloading--mask-image); + mask-image: var(--psp-icon--downloading--mask-image); +} + +.psp-tab-status.pending { + background-color: var(--psp-inactive--color); + -webkit-mask-image: var(--psp-icon--status-pending--mask-image); + mask-image: var(--psp-icon--status-pending--mask-image); +} + +.psp-tab-status.uninitialized { + background-color: transparent; +} + +.psp-tab-status.errored { + border-radius: 10px; + color: var(--psp--background-color); + -webkit-mask-image: none; + mask-image: none; +} + +.psp-tab-status.errored::before { + content: "!"; +} + +.psp-tab-status:not(.errored):hover { + background-color: var(--psp--color); + -webkit-mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); + mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); + transform: scaleX(-1); +} + .psp-tab-title { height: 11px; line-height: 12px; @@ -212,47 +289,4 @@ span#rows span.total { content: var(--psp-broadcast--content, "[BROADCAST]"); } -.psp-tab-close, -.psp-tab-settings { - flex: 0 0 auto; - display: flex; - align-items: center; - justify-content: center; - margin-left: 4px; - padding: 0; - border: none; - background: none; - cursor: pointer; - color: inherit; -} - -.psp-tab-close:hover::before, -.psp-tab-settings:hover::before { - background-color: var(--psp--color); -} - -.psp-tab-close::before, -.psp-tab-settings::before { - content: ""; - - /* TODO don't hard-code dimensions */ - width: 20px; - height: 20px; - background-color: var(--psp-inactive--color); - -webkit-mask-size: contain; - mask-size: contain; - -webkit-mask-repeat: no-repeat; - mask-repeat: no-repeat; - -webkit-mask-position: center; - mask-position: center; -} - -.psp-tab-close::before { - -webkit-mask-image: var(--psp-icon--close--mask-image); - mask-image: var(--psp-icon--close--mask-image); -} - -.psp-tab-settings::before { - -webkit-mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); - mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); -} +/* `.psp-tab-close` / `.psp-tab-settings` live in `tab-button.css`. */ diff --git a/rust/perspective-viewer/src/css/status-bar.css b/rust/perspective-viewer/src/css/status-bar.css index adb11cc4f6..34aa3b5363 100644 --- a/rust/perspective-viewer/src/css/status-bar.css +++ b/rust/perspective-viewer/src/css/status-bar.css @@ -22,13 +22,11 @@ #status_bar.settings-closed { box-shadow: none; padding-right: 10px; - } - - #status_bar.updating { - box-shadow: none; + box-shadow: 0 1px 0 0px var(--psp-inactive--color); } #status_bar.settings-closed.floating { + /* box-shadow: none; */ transition: opacity 0.2s; opacity: 0; position: absolute; @@ -54,45 +52,10 @@ min-height: var(--psp-status-bar--height, 38px); max-height: var(--psp-status-bar--height, 38px); border-radius: var(--psp-status-bar--border-radius); - .section { - display: flex; - align-items: center; - pointer-events: none; - } - - .section > * { - pointer-events: all; - } - #spacer { flex: 1 1000 auto; } - #panel-bar { - flex: 0 0 auto; - height: 100%; - } - - span#new_panel { - & > .icon { - -webkit-mask-image: var(--psp-icon--new-panel--mask-image); - mask-image: var(--psp-icon--new-panel--mask-image); - display: inline-flex; - &:before { - line-height: 0; - content: var(--psp-icon--new-panel--mask-image); - visibility: hidden; - } - } - - span:not(.icon):before { - content: var( - --psp-label--new-panel-button--content, - var(--psp-missing) - ); - } - } - /* Exceptions when the menu bar is visible and the settings panel is closed. */ #menu-bar { flex: 0 1000000 auto; @@ -182,190 +145,6 @@ margin: 0; } - span#status { - background-repeat: no-repeat; - background-color: var(--psp--color); - mask-size: contain; - mask-repeat: no-repeat; - mask-position: center; - pointer-events: none; - image-rendering: pixelated; - margin: 0 5px; - } - - /* span#status_updating */ - - span#status.loading { - image-rendering: pixelated; - mask-image: var(--psp-icon--downloading--mask-image); - -webkit-mask-image: var(--psp-icon--downloading--mask-image); - &:before { - visibility: hidden; - content: var(--psp-icon--downloading--mask-image); - line-height: 0; - } - } - - span#status.uninitialized { - background-color: transparent; - } - - span#status.pending { - background-color: var(--psp-inactive--color); - mask-image: var(--psp-icon--status-pending--mask-image); - -webkit-mask-image: var(--psp-icon--status-pending--mask-image); - &:before { - visibility: hidden; - content: var(--psp-icon--status-pending--mask-image); - line-height: 0; - } - } - - span#status.connected, - span#status.updating { - mask-image: var(--psp-icon--status-ok--mask-image); - -webkit-mask-image: var(--psp-icon--status-ok--mask-image); - &:before { - visibility: hidden; - content: var(--psp-icon--status-ok--mask-image); - line-height: 0; - } - } - - .error-dialog { - position: absolute; - z-index: 1; - width: 100%; - flex-direction: column; - max-height: 300px; - top: 0; - left: 0; - padding: 0px 0px 0px 50px; - display: none; - white-space: pre-wrap; - color: var(--psp--background-color); - background: var(--psp--color); - border-radius: var(--psp-status-bar--border-radius); - } - - .error-dialog-message { - white-space: nowrap; - overflow: hidden; - align-items: center; - display: flex; - padding-right: 17px; - height: var(--psp-status-bar--height, 38px); - min-height: var(--psp-status-bar--height, 38px); - } - - .error-dialog-stack { - font-size: 10px; - padding-right: 17px; - color: var(--psp-inactive--color); - overflow-y: auto; - padding-bottom: 24px; - } - - .section:hover .error-dialog { - display: flex; - } - - div#status_reconnect { - z-index: 2; - display: var(--status-indicator--display, flex); - align-items: center; - border-radius: 3px; - margin: 0; - height: auto; - border: 1px solid - var(--psp-status-icon--ok--border-color, transparent); - cursor: var(--psp-status-icon--ok--cursor); - pointer-events: var(--psp-status-icon--pointer-events, none); - &:hover { - background-color: var( - --psp-status-icon--ok-hover--background-color, - transparent - ); - border-color: var( - --psp-status-icon--ok-hover--border-color, - transparent - ); - span#status { - background-color: var( - --psp-status-icon--ok-hover--color, - var(--psp--color) - ); - } - } - - &.errored { - pointer-events: all; - display: flex; - cursor: pointer; - } - - &.errored.disabled { - cursor: auto; - pointer-events: none; - } - - span#status.errored { - display: flex; - align-items: center; - justify-content: center; - height: 20px; - width: 20px; - border-radius: 10px; - color: var(--psp--background-color); - &:before { - content: "!"; - } - } - - &.errored:hover { - background-color: var(--psp--color); - span#status.errored { - color: var(--psp--color); - background-color: var(--psp--background-color); - } - } - } - - /* Status bar status icon animations */ - span#status_updating { - position: absolute; - display: inline-flex; - margin: 0 5px; - opacity: 0; - background-repeat: no-repeat; - background-color: var(--psp--color); - -webkit-mask-size: cover; - mask-size: cover; - pointer-events: none; - image-rendering: pixelated; - mask-image: var(--psp-icon--updating--mask-image); - -webkit-mask-image: var(--psp-icon--updating--mask-image); - &:before { - visibility: hidden; - content: var(--psp-icon--updating--mask-image); - line-height: 0; - } - } - - span#status.updating { - animation-name: status-bar-updating-inverse; - animation-fill-mode: forwards; - animation-iteration-count: 1; - animation-duration: 0.3s; - } - - span#status_updating.updating { - animation-name: status-bar-updating; - animation-fill-mode: forwards; - animation-iteration-count: 1; - animation-duration: 0.3s; - } - .button > .icon { background-repeat: no-repeat; background-color: var(--psp--color); @@ -532,6 +311,11 @@ height: 100%; align-items: center; + &.disabled { + pointer-events: none; + opacity: 0.5; + } + &:focus-within, &:hover:not(.modal-target) { box-shadow: @@ -617,31 +401,3 @@ } } } - -@keyframes status-bar-updating { - 0% { - opacity: 0; - } - - 99% { - opacity: 0; - } - - 100% { - opacity: 1; - } -} - -@keyframes status-bar-updating-inverse { - 0% { - opacity: 1; - } - - 99% { - opacity: 1; - } - - 100% { - opacity: 0; - } -} diff --git a/rust/perspective-viewer/src/css/status-indicator.css b/rust/perspective-viewer/src/css/status-indicator.css new file mode 100644 index 0000000000..f7a74ecc88 --- /dev/null +++ b/rust/perspective-viewer/src/css/status-indicator.css @@ -0,0 +1,230 @@ +/* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + * ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ + * ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ + * ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ + * ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ + * ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + * ┃ Copyright (c) 2017, the Perspective Authors. ┃ + * ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ + * ┃ This file is part of the Perspective library, distributed under the terms ┃ + * ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ + * ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + +:host { + #status_bar { + .section { + display: flex; + align-items: center; + pointer-events: none; + } + + .section > * { + pointer-events: all; + } + + span#status { + background-repeat: no-repeat; + background-color: var(--psp--color); + mask-size: contain; + mask-repeat: no-repeat; + mask-position: center; + pointer-events: none; + image-rendering: pixelated; + margin: 0 5px; + } + + /* span#status_updating */ + + span#status.loading { + image-rendering: pixelated; + mask-image: var(--psp-icon--downloading--mask-image); + -webkit-mask-image: var(--psp-icon--downloading--mask-image); + &:before { + visibility: hidden; + content: var(--psp-icon--downloading--mask-image); + line-height: 0; + } + } + + span#status.uninitialized { + background-color: transparent; + } + + span#status.pending { + background-color: var(--psp-inactive--color); + mask-image: var(--psp-icon--status-pending--mask-image); + -webkit-mask-image: var(--psp-icon--status-pending--mask-image); + &:before { + visibility: hidden; + content: var(--psp-icon--status-pending--mask-image); + line-height: 0; + } + } + + span#status.connected, + span#status.updating { + mask-image: var(--psp-icon--status-ok--mask-image); + -webkit-mask-image: var(--psp-icon--status-ok--mask-image); + &:before { + visibility: hidden; + content: var(--psp-icon--status-ok--mask-image); + line-height: 0; + } + } + + div#status_reconnect { + z-index: 2; + display: var(--status-indicator--display, flex); + align-items: center; + border-radius: 3px; + margin: 0; + height: auto; + border: 1px solid + var(--psp-status-icon--ok--border-color, transparent); + cursor: var(--psp-status-icon--ok--cursor, pointer); + pointer-events: var(--psp-status-icon--pointer-events, all); + + &::before { + content: ""; + position: absolute; + z-index: -1; + top: 0; + bottom: 0; + left: 0; + width: var(--psp-status-bar--height, 38px); + border-top-left-radius: var(--psp-status-bar--border-radius); + border-bottom-left-radius: var(--psp-status-bar--border-radius); + } + + &:hover::before { + background-color: var( + --psp-status-icon--ok-hover--background-color, + transparent + ); + } + + &:hover { + border-color: var( + --psp-status-icon--ok-hover--border-color, + transparent + ); + span#status { + background-color: var( + --psp-status-icon--ok-hover--color, + var(--psp--color) + ); + } + } + + &.errored { + pointer-events: all; + display: flex; + cursor: pointer; + } + + span#status.errored { + display: flex; + align-items: center; + justify-content: center; + height: 20px; + width: 20px; + border-radius: 10px; + color: var(--psp--background-color); + &:before { + content: "!"; + } + } + } + + /* Status bar status icon animations */ + span#status_updating { + position: absolute; + display: inline-flex; + margin: 0 5px; + opacity: 0; + background-repeat: no-repeat; + background-color: var(--psp--color); + -webkit-mask-size: cover; + mask-size: cover; + pointer-events: none; + image-rendering: pixelated; + mask-image: var(--psp-icon--updating--mask-image); + -webkit-mask-image: var(--psp-icon--updating--mask-image); + &:before { + visibility: hidden; + content: var(--psp-icon--updating--mask-image); + line-height: 0; + } + } + + span#status.updating { + animation-name: status-bar-updating-inverse; + animation-fill-mode: forwards; + animation-iteration-count: 1; + animation-duration: 0.3s; + } + + span#status_updating.updating { + animation-name: status-bar-updating; + animation-fill-mode: forwards; + animation-iteration-count: 1; + animation-duration: 0.3s; + } + } +} + +:host { + #status_bar div#status_reconnect:hover { + span#status { + animation: none; + opacity: 1; + mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); + -webkit-mask-image: var( + --psp-icon--drawer-tab-inverted--mask-image + ); + transform: scaleX(-1); + } + + span#status.errored { + border-radius: 0; + + &:before { + visibility: hidden; + } + } + + span#status_updating { + animation: none; + opacity: 0; + } + } +} + +@keyframes status-bar-updating { + 0% { + opacity: 0; + } + + 99% { + opacity: 0; + } + + 100% { + opacity: 1; + } +} + +@keyframes status-bar-updating-inverse { + 0% { + opacity: 1; + } + + 99% { + opacity: 1; + } + + 100% { + opacity: 0; + } +} diff --git a/rust/perspective-viewer/src/css/tab-button.css b/rust/perspective-viewer/src/css/tab-button.css new file mode 100644 index 0000000000..42329d26b9 --- /dev/null +++ b/rust/perspective-viewer/src/css/tab-button.css @@ -0,0 +1,61 @@ +/* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + * ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ + * ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ + * ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ + * ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ + * ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + * ┃ Copyright (c) 2017, the Perspective Authors. ┃ + * ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ + * ┃ This file is part of the Perspective library, distributed under the terms ┃ + * ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ + * ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + +/* The panel tab's icon buttons, prepended to `PanelTab`'s shadow root in + `panel_tab.rs`. Plain CSS (no nesting): `panel_tab.rs` includes it + unprocessed. */ + +.psp-tab-close, +.psp-tab-settings { + flex: 0 0 auto; + display: flex; + align-items: center; + justify-content: center; + margin-left: 4px; + padding: 0; + border: none; + background: none; + cursor: pointer; + color: inherit; +} + +.psp-tab-close:hover::before, +.psp-tab-settings:hover::before { + background-color: var(--psp--color); +} + +.psp-tab-close::before, +.psp-tab-settings::before { + content: ""; + + /* TODO don't hard-code dimensions */ + width: 20px; + height: 20px; + background-color: var(--psp-inactive--color); + -webkit-mask-size: contain; + mask-size: contain; + -webkit-mask-repeat: no-repeat; + mask-repeat: no-repeat; + -webkit-mask-position: center; + mask-position: center; +} + +.psp-tab-close::before { + -webkit-mask-image: var(--psp-icon--close--mask-image); + mask-image: var(--psp-icon--close--mask-image); +} + +.psp-tab-settings::before { + -webkit-mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); + mask-image: var(--psp-icon--drawer-tab-inverted--mask-image); +} diff --git a/rust/perspective-viewer/src/css/ui/containers/split-panel.css b/rust/perspective-viewer/src/css/ui/containers/split-panel.css index 3eae3319fa..cb0adbe149 100644 --- a/rust/perspective-viewer/src/css/ui/containers/split-panel.css +++ b/rust/perspective-viewer/src/css/ui/containers/split-panel.css @@ -22,6 +22,13 @@ max-width: 300px; } + #workspace_drawer.split-panel + > .split-panel-child:not(:last-child):not(.is-width-override) { + width: 300px; + min-width: 300px; + max-width: 300px; + } + .split-panel { display: flex; height: 100%; diff --git a/rust/perspective-viewer/src/css/viewer.css b/rust/perspective-viewer/src/css/viewer.css index 646daf46cc..0b901f985b 100644 --- a/rust/perspective-viewer/src/css/viewer.css +++ b/rust/perspective-viewer/src/css/viewer.css @@ -130,6 +130,22 @@ 0 12.5px 0 -11.5px var(--psp-inactive--border-color); } +/* EMPTY STAGE: the settings-sidebar placeholder standing in for a tab body + with nothing to show at zero panels (Query/Plugin/Debug — see + `EmptyPlaceholder`). The label is localizable (`themes/intl.css`). */ +:host .psp-empty-placeholder { + flex: 1 1 auto; + display: flex; + justify-content: center; + padding: 24px 12px; + color: var(--psp-inactive--color); + user-select: none; + + &::before { + content: var(--psp-label--no-table--content, "No table loaded"); + } +} + :host .sidebar_close_button { position: absolute; top: 0; @@ -195,6 +211,18 @@ left: -21px; } +:host #workspace_close_button { + right: -21px; + + .sidebar_close_button_inner { + border-radius: 0 5px 5px 0; + } + + .sidebar_close_button_inner .icon { + transform: scaleX(-1); + } +} + :host #debug_close_button.sidebar_close_button .sidebar_close_button_inner { background-attachment: fixed; background: var(--psp-sidebar--background); @@ -316,6 +344,33 @@ margin-right: -5px; } + #workspace_drawer { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + z-index: 7; + overflow: hidden; + pointer-events: none; + & > * { + pointer-events: all; + } + } + + #workspace_drawer.pinned { + position: static; + flex: 0 0 auto; + width: auto; + pointer-events: all; + overflow: visible; + } + + #workspace_drawer > .split-panel-divider { + border-left: 1px solid var(--psp-inactive--color, #6e6e6e); + margin-right: -5px; + } + #status_bar { height: var(--psp-status-bar--height, 38px); } @@ -372,6 +427,20 @@ height: 100%; } + /* The layout engine hosting the panels fills the container. + + Panel separators: frames TILE their grid cells (no margin) and each + panel draws a 1px line on its LEFT and TOP edge only, so every + internal boundary gets exactly one line (owned by the panel to its + right/below, in THAT panel's theme). The lines are drawn by the + light-DOM plugin (`outline`, beside the body) and tab (`::before`, + along the titlebar) - not the frame, which the per-panel theme + rules can't reach. Borders and outlines (unlike box-shadows) are + snapped to whole device pixels at any DPR. The leading inset (-4px) + pushes the outermost left/top lines outside `#main_panel_container`'s + `overflow: hidden`, so the layout itself has no outer border; the + trailing inset (-3px) leaves the plugins the same ~1px outer gutter + on every side. */ & regular-layout { position: absolute; inset: -4px -3px -3px -4px; @@ -520,6 +589,18 @@ } } + #settings_panel_error { + flex: 0 0 auto; + margin: 8px 8px 0 0; + } + + #settings_panel.errored + > #settings_panel_error + ~ :not(.scroll-panel-auto-width, #debug-panel-overflow) { + pointer-events: none; + opacity: 0.5; + } + #column_settings_sidebar .split-panel-divider { border-top: 1px solid var(--psp-inactive--color, #6e6e6e); border-bottom: 2px solid var(--psp-inactive--color, #6e6e6e); @@ -599,7 +680,8 @@ margin-left: -8px; } - #settings_tab_bar { + #settings_tab_bar, + #workspace_tab_bar { display: flex; &:after { content: " "; @@ -686,7 +768,15 @@ content: var(--psp-label--debug-tab--content, var(--psp-missing)); } - #chat_tabbar_tab:before { + #workspace_tables_tab:before { + content: var(--psp-label--tables-tab--content, var(--psp-missing)); + } + + #workspace_json_tab:before { + content: var(--psp-label--debug-tab--content, var(--psp-missing)); + } + + #workspace_chat_tab:before { content: var(--psp-label--chat-tab--content, var(--psp-missing)); } } @@ -1072,13 +1162,39 @@ #chat_badge { flex: 0 0 auto; + display: flex; + align-items: center; + gap: 8px; font-size: 0.66em; color: var(--psp-inactive--color, #6e6e6e); - overflow: hidden; white-space: nowrap; - text-overflow: ellipsis; margin-bottom: 6px; } + + #chat_badge_label { + flex: 0 1 auto; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + } + + /* The translated "Docs" label: struck through until `docs` loads. */ + #chat_docs_status { + flex: 0 0 auto; + text-decoration: line-through; + } + + #chat_docs_status[data-loaded="true"] { + color: var(--psp-inactive--color); + text-decoration: none; + } + + #chat_docs_status:before { + content: var( + --psp-label--chat-entitlement--read-docs--content, + var(--psp-missing) + ); + } } @keyframes chat-pending-pulse { diff --git a/rust/perspective-viewer/src/css/workspace-panel.css b/rust/perspective-viewer/src/css/workspace-panel.css new file mode 100644 index 0000000000..4567ee8c7e --- /dev/null +++ b/rust/perspective-viewer/src/css/workspace-panel.css @@ -0,0 +1,343 @@ +/* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ + * ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ + * ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ + * ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ + * ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ + * ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ + * ┃ Copyright (c) 2017, the Perspective Authors. ┃ + * ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ + * ┃ This file is part of the Perspective library, distributed under the terms ┃ + * ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ + * ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + */ + +:host { + #workspace_panel { + position: relative; + flex: 1 1 auto; + min-width: 0; + box-sizing: border-box; + overflow: hidden; + margin: var(--psp-main-column--margin); + border: var(--psp-main-column--border); + border-width: var(--psp-main-column--border-width); + border-radius: var(--psp-main-column--border-radius); + } + + #status_bar.workspace-open { + padding-left: 26px; + } + + #workspace_panel_header { + position: relative; + display: flex; + flex: 0 0 auto; + align-items: center; + box-sizing: border-box; + padding: var(--psp-status-bar--padding, 0 26px 0 4px); + height: var(--psp-status-bar--height, 38px); + min-height: var(--psp-status-bar--height, 38px); + max-height: var(--psp-status-bar--height, 38px); + } + + #workspace_panel_divider { + flex: 0 0 4px; + background-color: #00000020; + border-top: 1px solid var(--psp-inactive--color, #6e6e6e); + border-bottom: 1px solid var(--psp-inactive--color, #6e6e6e); + } + + #workspace_tab_bar { + flex: 0 0 auto; + } + + .ws-label:before { + content: var(--psp-label--content, var(--psp-missing)); + } + + #workspace-tables-overflow { + display: flex; + flex: 1 1 auto; + min-height: 0; + overflow-x: hidden; + overflow-y: auto; + scrollbar-gutter: stable; + } + + #workspace-tables { + display: flex; + min-width: 150px; + margin-right: -6px; + padding: 0 0 8px 0; + + .error { + color: var(--psp-error--color); + font-size: 10px; + padding: 0 8px; + white-space: pre-wrap; + overflow-wrap: anywhere; + } + + #workspace-tables-error { + margin: 8px 0; + } + + .no-results { + padding: 6px 8px; + } + + details.control-group.ws-client { + margin: 0; + padding: 0; + padding-right: 6px; + + &:first-child { + margin-top: 0; + } + + &[open] { + padding-bottom: 8px; + } + + > summary { + gap: 6px; + padding: 8px 6px 8px 8px; + } + + &:not([open]):hover .ws-client-status { + border-color: var(--psp--background-color); + color: var(--psp--color); + } + + &:not([open]):hover .ws-client-status.errored { + background-color: var(--psp--background-color); + } + + .error-dialog-details > summary:hover { + color: var(--psp-inactive--color); + } + } + + .ws-client-status { + flex: 0 0 14px; + width: 14px; + height: 14px; + border-radius: 7px; + border: 1px solid var(--psp--color); + /* background-color: var(--psp--color); */ + } + + .ws-client-status.errored { + display: flex; + flex: 0 0 14px; + align-items: center; + justify-content: center; + width: 14px; + height: 14px; + border-radius: 7px; + color: var(--psp--background-color); + font-size: 10px; + font-weight: bold; + background-color: var(--psp--color); + line-height: 14px; + + &::before { + content: "!"; + } + } + + .ws-client-status.loading, + .ws-client-status.pending { + background-color: var(--psp-inactive--color); + } + + .ws-client-error { + margin: 0 8px; + } + + .ws-tables, + .ws-views { + margin-left: 12px; + } + + .ws-client.is-lost :is(.ws-tables, .ws-views) { + opacity: 0.5; + } + + .ws-client-name, + .ws-table-name { + flex: 1 1 auto; + min-width: 0; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + } + + .ws-client-default, + .ws-client-panels, + .ws-table-consumers { + flex: none; + font-weight: normal; + font-size: 0.75em; + opacity: 0.6; + } + + .ws-client-panels:before, + .ws-table-consumers:before { + content: ""; + } + + .sidebar-controls { + padding: 6px 8px 4px 8px; + } + + .ws-table, + .ws-view { + display: flex; + align-items: center; + gap: 4px; + padding: 3px 8px; + } + + .ws-table.is-derived .ws-table-name:before, + .ws-table.is-pending .ws-table-name:before { + content: "\21B3\00A0"; + opacity: 0.6; + } + + .ws-table.is-join .ws-table-name:before { + content: "\22C8\00A0"; + opacity: 0.6; + } + + .ws-table.is-pending { + color: var(--psp-inactive--color); + font-style: italic; + } + + .ws-table, + .ws-view { + min-height: 20px; + } + + .ws-table-new, + .ws-table-delete, + .ws-view-derive, + .ws-table-spacer { + flex: 0 0 20px; + width: 20px; + height: 20px; + } + + .ws-table-spacer { + border: 1px dotted var(--psp-inactive--color); + border-radius: 2px; + } + + .ws-table-new, + .ws-table-delete, + .ws-view-derive { + display: none; + cursor: pointer; + opacity: 0.6; + background-color: currentColor; + -webkit-mask-size: cover; + mask-size: cover; + } + + .ws-table:hover .ws-table-new, + .ws-table:hover .ws-table-delete, + .ws-view:hover .ws-view-derive { + display: block; + } + + :is(.ws-table, .ws-view).has-actions:hover .ws-table-spacer { + display: none; + } + + .ws-table .ws-table-new:hover, + .ws-table .ws-table-delete:hover, + .ws-view .ws-view-derive:hover { + opacity: 1; + } + + .ws-table-new { + -webkit-mask-image: var(--psp-icon--new-panel--mask-image); + mask-image: var(--psp-icon--new-panel--mask-image); + } + + .ws-table-delete { + -webkit-mask-image: var(--psp-icon--close--mask-image); + mask-image: var(--psp-icon--close--mask-image); + } + + .ws-view-derive { + -webkit-mask-image: var(--psp-icon--add-expression--mask-image); + mask-image: var(--psp-icon--add-expression--mask-image); + } + + .ws-view.is-disabled { + .ws-table-name { + color: var(--psp-inactive--color); + } + + .ws-view-derive, + .ws-view-derive:hover { + cursor: not-allowed; + opacity: 0.2; + } + } + + .ws-views { + padding-top: 6px; + } + + .ws-section-label { + display: block; + padding: 0 8px 2px 8px; + font-size: var(--label--font-size, 0.75em); + text-transform: uppercase; + /* color: var(--psp-inactive--color); */ + } + + .ws-join-form { + display: flex; + flex-direction: column; + gap: 2px; + padding: 4px 8px; + + label { + font-size: var(--label--font-size, 0.75em); + margin-top: 4px; + } + + select, + input { + min-width: 0; + font-family: inherit; + font-size: inherit; + color: inherit; + background-color: var(--psp--background-color); + border: 1px solid var(--psp-inactive--color); + border-radius: 2px; + padding: 2px 4px; + } + + .error { + padding: 4px 0 0 0; + } + + .sidebar-controls { + padding: 8px 0 0 0; + } + } + } + + #workspace-json { + padding-left: 8px; + } + + #workspace_panel > #chat_panel { + padding-left: 6px; + } +} diff --git a/rust/perspective-viewer/src/rust/agent/docs.rs b/rust/perspective-viewer/src/rust/agent/docs.rs index 42050c7674..f4793b2db3 100644 --- a/rust/perspective-viewer/src/rust/agent/docs.rs +++ b/rust/perspective-viewer/src/rust/agent/docs.rs @@ -209,6 +209,15 @@ impl DocsCell { } } + /// Whether the source has resolved successfully, without waiting. + /// [`Self::bundle`] holds the cache lock for the whole resolve, so a + /// held lock means "not yet". + pub fn is_loaded(&self) -> bool { + self.cache + .try_lock() + .is_some_and(|cache| matches!(cache.as_deref(), Some(Ok(_)))) + } + pub async fn bundle(&self) -> Rc> { let mut cache = self.cache.lock().await; if let Some(cached) = &*cache { diff --git a/rust/perspective-viewer/src/rust/agent/runtime.rs b/rust/perspective-viewer/src/rust/agent/runtime.rs index ad1cc9bd2e..edeeb407b0 100644 --- a/rust/perspective-viewer/src/rust/agent/runtime.rs +++ b/rust/perspective-viewer/src/rust/agent/runtime.rs @@ -158,6 +158,25 @@ impl AgentRuntime { result.map_err(TurnError::Failed) } + /// Resolve the `docs` source now rather than on the first turn, so a + /// failure can reject `agentConfig()`. The result is cached, so the + /// first turn reuses it; a failure is cached too and still surfaces + /// through `search_docs`. + pub async fn load_docs(&self) -> ApiResult<()> { + if let Some(docs) = &self.docs + && let Err(err) = &*docs.bundle().await + { + return Err(ApiError::from(format!("Failed to load `docs`: {err}"))); + } + + Ok(()) + } + + /// Whether a `docs` source is configured and has loaded successfully. + pub fn docs_loaded(&self) -> bool { + self.docs.as_ref().is_some_and(|x| x.is_loaded()) + } + /// Clear the conversation history. pub async fn reset(&self) { self.history.lock().await.clear(); diff --git a/rust/perspective-viewer/src/rust/agent/slot.rs b/rust/perspective-viewer/src/rust/agent/slot.rs index 1632f1921d..2d1d96da56 100644 --- a/rust/perspective-viewer/src/rust/agent/slot.rs +++ b/rust/perspective-viewer/src/rust/agent/slot.rs @@ -89,6 +89,19 @@ impl AgentSlot { self.on_update.emit(()); } + /// Resolve the configured runtime's `docs` source (re-rendering the chat + /// badge once it settles), failing if it fails to load. + pub async fn load_docs(&self) -> ApiResult<()> { + let runtime = self.runtime.borrow().clone(); + let result = match runtime { + Some(runtime) => runtime.load_docs().await, + None => Ok(()), + }; + + self.on_update.emit(()); + result + } + /// The scripts started by `run_script`, which outlive agent /// reconfiguration. pub fn sandbox(&self) -> Rc { @@ -108,6 +121,14 @@ impl AgentSlot { self.runtime.borrow().as_ref().map(|x| x.label()) } + /// Whether the configured `docs` source has loaded. + pub fn docs_loaded(&self) -> bool { + self.runtime + .borrow() + .as_ref() + .is_some_and(|x| x.docs_loaded()) + } + /// The user-toggleable entitlements of the host's grant. pub fn entitlements(&self) -> Vec<(Entitlement, bool)> { self.runtime diff --git a/rust/perspective-viewer/src/rust/components/chat_panel.rs b/rust/perspective-viewer/src/rust/components/chat_panel.rs index bc3765c92c..ecdba2943b 100644 --- a/rust/perspective-viewer/src/rust/components/chat_panel.rs +++ b/rust/perspective-viewer/src/rust/components/chat_panel.rs @@ -357,7 +357,10 @@ pub fn ChatPanel(props: &ChatPanelProps) -> Html { />
{ entries }{ tail }
-
{ props.agent.label().unwrap_or_default() }
+
+ { props.agent.label().unwrap_or_default() } + +
} } diff --git a/rust/perspective-viewer/src/rust/components/column_selector/config_selector.rs b/rust/perspective-viewer/src/rust/components/column_selector/config_selector.rs index 88cbb3473c..990beb532e 100644 --- a/rust/perspective-viewer/src/rust/components/column_selector/config_selector.rs +++ b/rust/perspective-viewer/src/rust/components/column_selector/config_selector.rs @@ -113,6 +113,17 @@ pub enum ConfigSelectorMsg { UpdateSplitRollupMode(SplitRollupMode), } +impl From for ConfigSelectorMsg { + fn from(event: DragListEvent) -> Self { + match event { + DragListEvent::DragEnter(target, index) => Self::DragOver(index, target), + DragListEvent::DragLeave(target) => Self::DragLeave(target), + DragListEvent::Close(target, index) => Self::Close(index, target), + DragListEvent::Create(target, column) => Self::New(target, column), + } + } +} + #[derive(Clone)] pub struct ConfigSelector { filter_dropdown: FilterDropDownElement, @@ -689,8 +700,9 @@ impl Component for ConfigSelector { } if features.group_by { - } }) } - + } if features.split_by { if !config.split_by.is_empty() || split_rollups.len() > 1 { @@ -745,8 +757,9 @@ impl Component for ConfigSelector { } } - } }) } - + } if features.sort { for GroupByContext { - fn dragenter(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::DragOver(index, DragTarget::GroupBy) - } - - fn close(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::Close(index, DragTarget::GroupBy) - } - - fn dragleave() -> ConfigSelectorMsg { - ConfigSelectorMsg::DragLeave(DragTarget::GroupBy) - } - - fn create(col: InPlaceColumn) -> ConfigSelectorMsg { - ConfigSelectorMsg::New(DragTarget::GroupBy, col) - } - - fn is_self_move(target: DragTarget) -> bool { - target == DragTarget::GroupBy - } -} - -impl DragContext for SplitByContext { - fn dragenter(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::DragOver(index, DragTarget::SplitBy) - } - - fn close(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::Close(index, DragTarget::SplitBy) - } - - fn dragleave() -> ConfigSelectorMsg { - ConfigSelectorMsg::DragLeave(DragTarget::SplitBy) - } - - fn create(col: InPlaceColumn) -> ConfigSelectorMsg { - ConfigSelectorMsg::New(DragTarget::SplitBy, col) - } - - fn is_self_move(target: DragTarget) -> bool { - target == DragTarget::SplitBy - } -} - -impl DragContext for SortDragContext { - fn dragenter(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::DragOver(index, DragTarget::Sort) - } - - fn close(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::Close(index, DragTarget::Sort) - } - - fn dragleave() -> ConfigSelectorMsg { - ConfigSelectorMsg::DragLeave(DragTarget::Sort) - } - - fn create(col: InPlaceColumn) -> ConfigSelectorMsg { - ConfigSelectorMsg::New(DragTarget::Sort, col) - } - - fn is_self_move(target: DragTarget) -> bool { - target == DragTarget::Sort - } -} - -impl DragContext for FilterDragContext { - fn dragenter(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::DragOver(index, DragTarget::Filter) - } - - fn close(index: usize) -> ConfigSelectorMsg { - ConfigSelectorMsg::Close(index, DragTarget::Filter) - } - - fn dragleave() -> ConfigSelectorMsg { - ConfigSelectorMsg::DragLeave(DragTarget::Filter) - } - - fn create(col: InPlaceColumn) -> ConfigSelectorMsg { - ConfigSelectorMsg::New(DragTarget::Filter, col) - } - - fn is_self_move(target: DragTarget) -> bool { - target == DragTarget::Filter - } -} - -type GroupBySelector = DragDropList; -type SplitBySelector = DragDropList; -type SortSelector = DragDropList; -type FilterSelector = DragDropList; +type PivotSelector = DragDropList; +type SortSelector = DragDropList; +type FilterSelector = DragDropList; diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar.rs index b10ebf8afb..9199dfd926 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar.rs @@ -11,7 +11,6 @@ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ mod attributes_tab; -mod save_settings; pub(crate) mod style_tab; mod window_tab; @@ -26,7 +25,6 @@ use yew::{Callback, Component, Html, Properties, html, props}; use self::attributes_tab::AttributesTabProps; use self::style_tab::StyleTabProps; use crate::components::column_settings_sidebar::attributes_tab::AttributesTab; -use crate::components::column_settings_sidebar::save_settings::SaveSettingsProps; use crate::components::column_settings_sidebar::style_tab::StyleTab; use crate::components::column_settings_sidebar::window_tab::{WindowTab, WindowTabProps}; use crate::components::editable_header::{EditableHeader, EditableHeaderProps}; @@ -40,7 +38,7 @@ use crate::session::{Session, SessionMetadataRc}; use crate::tasks::{ delete_expr, delete_window, save_expr, save_window, update_expr, update_window, }; -use crate::ui::{Sidebar, TabList}; +use crate::ui::{SaveSettingsProps, Sidebar, TabList}; use crate::utils::PtrEqRc; use crate::workspace::Workspace; diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/attributes_tab.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/attributes_tab.rs index f4f18a7101..a3416bea65 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/attributes_tab.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/attributes_tab.rs @@ -12,8 +12,8 @@ use yew::{Html, Properties, function_component, html}; -use super::save_settings::{SaveSettings, SaveSettingsProps}; use crate::components::expression_editor::{ExpressionEditor, ExpressionEditorProps}; +use crate::ui::{SaveSettings, SaveSettingsProps}; #[derive(PartialEq, Properties, Clone)] pub struct AttributesTabProps { diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs index f20584d2cd..5b0cb7c94f 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field.rs @@ -13,28 +13,32 @@ //! Schema-driven generic widgets for the Style tab. Each widget renders a //! single primitive [`crate::config::ControlSpec`] variant and emits a //! [`crate::config::ColumnConfigFieldUpdate`] on change. Built on top of -//! the existing form components ([`Select`], [`OptionalField`], -//! [`ColorSelector`]) so that they visually match the rich Yew widgets in -//! the same sidebar. +//! the existing form components ([`crate::ui::Select`], +//! [`crate::ui::OptionalField`], [`crate::ui::ColorSelector`]) so that they +//! visually match the rich Yew widgets in the same sidebar. + +mod bool_field; +mod color_field; +mod enum_field; +mod gradient_stops_field; +mod number_field; +mod palette_field; use std::collections::BTreeMap; use std::rc::Rc; -use itertools::Itertools; use serde_json::Value; -use wasm_bindgen::JsCast; -use web_sys::{HtmlInputElement, MouseEvent}; -use yew::{Callback, Html, Properties, function_component, html, use_callback}; - -use crate::config::{ColumnConfigFieldUpdate, EnumVariant, discrete_pair}; -use crate::ui::{ - ColorSelector, MultiStopGradientSelector, NamedValuePicker, NumberField, OptionalField, - PaletteSelector, Select, SelectItem, -}; -use crate::utils::{ - CssColor, CssGradient, CssKind, CssPalette, GradientStopSpec, NamedValue, - canonicalize_css_color, gradient_to_css, palette_name_for, -}; +use yew::{Callback, Html, html}; + +pub use self::bool_field::BoolField; +pub use self::color_field::ColorField; +pub use self::enum_field::EnumField; +pub use self::gradient_stops_field::GradientStopsField; +pub use self::number_field::NumberFieldPrimitive; +pub use self::palette_field::PaletteField; +use crate::config::ColumnConfigFieldUpdate; +use crate::ui::NamedValuePicker; +use crate::utils::{CssKind, NamedValue, palette_name_for}; pub(super) fn emit(on_change: &Callback, key: &str, value: Option) { let mut map = serde_json::Map::new(); @@ -48,180 +52,6 @@ pub(super) fn emit(on_change: &Callback, key: &str, val }); } -#[derive(Properties, PartialEq)] -pub struct EnumFieldProps { - pub field_key: String, - pub variants: Vec, - pub default: String, - pub current: Option, - pub on_change: Callback, -} - -#[function_component] -pub fn EnumField(props: &EnumFieldProps) -> Html { - let selected = props - .current - .clone() - .unwrap_or_else(|| props.default.clone()); - - let checked = selected != props.default; - let values: Rc>> = Rc::new( - props - .variants - .iter() - .map(|v| SelectItem::Option(v.value.clone())) - .collect_vec(), - ); - - let on_select = use_callback( - ( - props.field_key.clone(), - props.default.clone(), - props.on_change.clone(), - ), - |value: String, (key, default, on_change)| { - if value == *default { - emit(on_change, key, None); - } else { - emit(on_change, key, Some(Value::String(value))); - } - }, - ); - - let on_reset = use_callback( - (props.field_key.clone(), props.on_change.clone()), - |_: MouseEvent, (key, on_change)| emit(on_change, key, None), - ); - - html! { -
- - {values} {selected} {on_select} /> - -
- } -} - -#[derive(Properties, PartialEq)] -pub struct BoolFieldProps { - pub field_key: String, - pub default: bool, - pub current: Option, - pub on_change: Callback, -} - -#[function_component] -pub fn BoolField(props: &BoolFieldProps) -> Html { - let current = props.current.unwrap_or(props.default); - let oninput = use_callback( - ( - props.field_key.clone(), - props.default, - props.on_change.clone(), - ), - |e: yew::events::InputEvent, (key, default, on_change)| { - let target: HtmlInputElement = e.target().unwrap().unchecked_into(); - let next = target.checked(); - if next == *default { - emit(on_change, key, None); - } else { - emit(on_change, key, Some(Value::Bool(next))); - } - }, - ); - - let checked = current != props.default; - let on_reset = use_callback( - (props.field_key.clone(), props.on_change.clone()), - |_: MouseEvent, (key, on_change)| emit(on_change, key, None), - ); - - html! { -
- -
- -
-
-
- } -} - -#[derive(Properties, PartialEq)] -pub struct NumberFieldPrimitiveProps { - pub field_key: String, - pub default: f64, - pub current: Option, - pub on_change: Callback, - - #[prop_or_default] - pub include: Option, - - #[prop_or_default] - pub min: Option, - - #[prop_or_default] - pub max: Option, - - #[prop_or_default] - pub step: Option, -} - -#[function_component] -pub fn NumberFieldPrimitive(props: &NumberFieldPrimitiveProps) -> Html { - let on_change_inner = use_callback( - ( - props.field_key.clone(), - props.default, - props.on_change.clone(), - props.include, - ), - |value: Option, (key, default, on_change, include)| match value { - Some(v) if include.unwrap_or_default() || v != *default => emit( - on_change, - key, - Some( - serde_json::Number::from_f64(v) - .map(Value::Number) - .unwrap_or(Value::Null), - ), - ), - None if include.unwrap_or_default() => emit( - on_change, - key, - Some( - serde_json::Number::from_f64(*default) - .map(Value::Number) - .unwrap_or(Value::Null), - ), - ), - _ => emit(on_change, key, None), - }, - ); - - html! { - - } -} - #[allow(clippy::too_many_arguments)] fn css_field_controls( kind: CssKind, @@ -246,315 +76,3 @@ fn named_literal(named: &[NamedValue], name: &str) -> Option { .find(|entry| entry.name == name) .map(|entry| entry.value.clone()) } - -#[derive(Properties, PartialEq)] -pub struct PaletteFieldProps { - pub field_key: String, - /// Canonical palette string. - pub default: String, - pub max: Option, - /// Canonical palette string. - pub current: Option, - pub on_change: Callback, - - /// Named palettes (workspace set ∪ theme), for the loader. - #[prop_or_default] - pub named: Rc>, - - /// The restored palette — the set Pin adds to. - #[prop_or_default] - pub restored: Rc>, - - /// Pin the field's `(kind, literal)` into the restored palette. - #[prop_or_default] - pub on_pin: Callback<(CssKind, String)>, -} - -fn palette_colors(src: &str, default: &str) -> Vec { - let literal = |css: &str| match CssPalette::parse(css) { - Ok(CssPalette::Literal(colors)) => Some(colors), - _ => None, - }; - - literal(src) - .or_else(|| literal(default)) - .unwrap_or_default() -} - -#[function_component] -pub fn PaletteField(props: &PaletteFieldProps) -> Html { - let current = props.current.as_deref().unwrap_or(&props.default); - let values = palette_colors(current, &props.default); - let is_modified = props.current.is_some() && props.current.as_ref() != Some(&props.default); - let emit_css = { - let key = props.field_key.clone(); - let default = props.default.clone(); - let on_change = props.on_change.clone(); - move |css: String| { - if css == default { - emit(&on_change, &key, None); - } else { - emit(&on_change, &key, Some(Value::String(css))); - } - } - }; - - let on_change_palette = { - let emit_css = emit_css.clone(); - Callback::from(move |values: Vec| { - emit_css(CssPalette::Literal(values).to_css()); - }) - }; - - let on_select = { - let emit_css = emit_css.clone(); - let named = props.named.clone(); - Callback::from(move |name: String| { - if let Some(literal) = named_literal(&named, &name) { - emit_css(literal); - } - }) - }; - - let on_reset = use_callback( - (props.field_key.clone(), props.on_change.clone()), - |_: (), (key, on_change)| emit(on_change, key, None), - ); - - let on_pin = { - let on_pin = props.on_pin.clone(); - let literal = current.to_owned(); - Callback::from(move |()| on_pin.emit((CssKind::Palette, literal.clone()))) - }; - - html! { -
- { css_field_controls( - CssKind::Palette, - &props.named, - &props.restored, - current, - is_modified, - on_select, - on_pin, - ) } - -
- } -} - -#[derive(Properties, PartialEq)] -pub struct GradientStopsFieldProps { - pub field_key: String, - /// Canonical gradient string. - pub default: String, - pub discrete: bool, - /// Canonical gradient string. - pub current: Option, - pub on_change: Callback, - - /// Named gradients (workspace set ∪ theme), for the loader. - #[prop_or_default] - pub named: Rc>, - - /// The restored palette — the set Pin adds to. - #[prop_or_default] - pub restored: Rc>, - - /// Pin the field's `(kind, literal)` into the restored palette. - #[prop_or_default] - pub on_pin: Callback<(CssKind, String)>, -} - -fn gradient_stops(src: &str, default: &str) -> Vec { - let literal = |css: &str| match CssGradient::parse(css) { - Ok(CssGradient::Literal(stops)) => Some(stops), - _ => None, - }; - - literal(src) - .or_else(|| literal(default)) - .unwrap_or_default() -} - -#[function_component] -pub fn GradientStopsField(props: &GradientStopsFieldProps) -> Html { - let current = props.current.as_deref().unwrap_or(&props.default); - let stops = gradient_stops(current, &props.default); - let is_modified = props.current.is_some() && props.current.as_ref() != Some(&props.default); - let emit_css = { - let key = props.field_key.clone(); - let default = props.default.clone(); - let on_change = props.on_change.clone(); - move |css: String| { - if css == default { - emit(&on_change, &key, None); - } else { - emit(&on_change, &key, Some(Value::String(css))); - } - } - }; - - let on_change_stops = { - let emit_css = emit_css.clone(); - Callback::from(move |stops: Vec| { - emit_css(gradient_to_css(&stops)); - }) - }; - - let on_select = { - let emit_css = emit_css.clone(); - let named = props.named.clone(); - let discrete = props.discrete; - Callback::from(move |name: String| { - let Some(literal) = named_literal(&named, &name) else { - return; - }; - - let literal = match CssGradient::parse(&literal) { - Ok(CssGradient::Literal(stops)) if discrete && stops.len() > 2 => { - gradient_to_css(&discrete_pair(stops)) - }, - _ => literal, - }; - - emit_css(literal); - }) - }; - - let on_reset = use_callback( - (props.field_key.clone(), props.on_change.clone()), - |_: (), (key, on_change)| emit(on_change, key, None), - ); - - let on_pin = { - let on_pin = props.on_pin.clone(); - let literal = current.to_owned(); - Callback::from(move |()| on_pin.emit((CssKind::Gradient, literal.clone()))) - }; - - html! { -
- { css_field_controls( - CssKind::Gradient, - &props.named, - &props.restored, - current, - is_modified, - on_select, - on_pin, - ) } - -
- } -} - -#[derive(Properties, PartialEq)] -pub struct ColorFieldProps { - pub field_key: String, - /// Canonical `#rrggbb`. - pub default: String, - /// Canonical `#rrggbb`. - pub current: Option, - pub on_change: Callback, - - /// Named colors (workspace set ∪ theme), for the loader. - #[prop_or_default] - pub named: Rc>, - - /// The restored palette — the set Pin adds to. - #[prop_or_default] - pub restored: Rc>, - - /// Pin the field's `(kind, literal)` into the restored palette. - #[prop_or_default] - pub on_pin: Callback<(CssKind, String)>, -} - -#[function_component] -pub fn ColorField(props: &ColorFieldProps) -> Html { - let current = props.current.as_deref().unwrap_or(&props.default); - let color = match CssColor::parse(current) { - Ok(CssColor::Literal(color)) => color, - _ => props.default.clone(), - }; - - let is_modified = - props.current.as_deref() != Some(props.default.as_str()) && props.current.is_some(); - - let emit_css = { - let key = props.field_key.clone(); - let default = props.default.clone(); - let on_change = props.on_change.clone(); - move |css: String| { - if css == default { - emit(&on_change, &key, None); - } else { - emit(&on_change, &key, Some(Value::String(css))); - } - } - }; - - let on_color = { - let emit_css = emit_css.clone(); - Callback::from(move |value: String| { - emit_css(canonicalize_css_color(&value).unwrap_or(value)); - }) - }; - - let on_select = { - let emit_css = emit_css.clone(); - let named = props.named.clone(); - Callback::from(move |name: String| { - if let Some(literal) = named_literal(&named, &name) { - emit_css(literal); - } - }) - }; - - let on_reset = use_callback( - (props.field_key.clone(), props.on_change.clone()), - |_: (), (key, on_change)| emit(on_change, key, None), - ); - - let on_pin = { - let on_pin = props.on_pin.clone(); - let literal = current.to_owned(); - Callback::from(move |()| on_pin.emit((CssKind::Color, literal.clone()))) - }; - - html! { -
- { css_field_controls( - CssKind::Color, - &props.named, - &props.restored, - current, - is_modified, - on_select, - on_pin, - ) } - -
- } -} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/bool_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/bool_field.rs new file mode 100644 index 0000000000..a7d8238df8 --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/bool_field.rs @@ -0,0 +1,75 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +use serde_json::Value; +use wasm_bindgen::JsCast; +use web_sys::{HtmlInputElement, MouseEvent}; +use yew::{Callback, Html, Properties, function_component, html, use_callback}; + +use super::emit; +use crate::config::ColumnConfigFieldUpdate; +use crate::ui::OptionalField; + +#[derive(Properties, PartialEq)] +pub struct BoolFieldProps { + pub field_key: String, + pub default: bool, + pub current: Option, + pub on_change: Callback, +} + +#[function_component] +pub fn BoolField(props: &BoolFieldProps) -> Html { + let current = props.current.unwrap_or(props.default); + let oninput = use_callback( + ( + props.field_key.clone(), + props.default, + props.on_change.clone(), + ), + |e: yew::events::InputEvent, (key, default, on_change)| { + let target: HtmlInputElement = e.target().unwrap().unchecked_into(); + let next = target.checked(); + if next == *default { + emit(on_change, key, None); + } else { + emit(on_change, key, Some(Value::Bool(next))); + } + }, + ); + + let checked = current != props.default; + let on_reset = use_callback( + (props.field_key.clone(), props.on_change.clone()), + |_: MouseEvent, (key, on_change)| emit(on_change, key, None), + ); + + html! { +
+ +
+ +
+
+
+ } +} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/color_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/color_field.rs new file mode 100644 index 0000000000..a0b5da0b08 --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/color_field.rs @@ -0,0 +1,118 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +use std::collections::BTreeMap; +use std::rc::Rc; + +use serde_json::Value; +use yew::{Callback, Html, Properties, function_component, html, use_callback}; + +use super::{css_field_controls, emit, named_literal}; +use crate::config::ColumnConfigFieldUpdate; +use crate::ui::ColorSelector; +use crate::utils::{CssColor, CssKind, NamedValue, canonicalize_css_color}; + +#[derive(Properties, PartialEq)] +pub struct ColorFieldProps { + pub field_key: String, + /// Canonical `#rrggbb`. + pub default: String, + /// Canonical `#rrggbb`. + pub current: Option, + pub on_change: Callback, + + /// Named colors (workspace set ∪ theme), for the loader. + #[prop_or_default] + pub named: Rc>, + + /// The restored palette — the set Pin adds to. + #[prop_or_default] + pub restored: Rc>, + + /// Pin the field's `(kind, literal)` into the restored palette. + #[prop_or_default] + pub on_pin: Callback<(CssKind, String)>, +} + +#[function_component] +pub fn ColorField(props: &ColorFieldProps) -> Html { + let current = props.current.as_deref().unwrap_or(&props.default); + let color = match CssColor::parse(current) { + Ok(CssColor::Literal(color)) => color, + _ => props.default.clone(), + }; + + let is_modified = + props.current.as_deref() != Some(props.default.as_str()) && props.current.is_some(); + + let emit_css = { + let key = props.field_key.clone(); + let default = props.default.clone(); + let on_change = props.on_change.clone(); + move |css: String| { + if css == default { + emit(&on_change, &key, None); + } else { + emit(&on_change, &key, Some(Value::String(css))); + } + } + }; + + let on_color = { + let emit_css = emit_css.clone(); + Callback::from(move |value: String| { + emit_css(canonicalize_css_color(&value).unwrap_or(value)); + }) + }; + + let on_select = { + let emit_css = emit_css.clone(); + let named = props.named.clone(); + Callback::from(move |name: String| { + if let Some(literal) = named_literal(&named, &name) { + emit_css(literal); + } + }) + }; + + let on_reset = use_callback( + (props.field_key.clone(), props.on_change.clone()), + |_: (), (key, on_change)| emit(on_change, key, None), + ); + + let on_pin = { + let on_pin = props.on_pin.clone(); + let literal = current.to_owned(); + Callback::from(move |()| on_pin.emit((CssKind::Color, literal.clone()))) + }; + + html! { +
+ { css_field_controls( + CssKind::Color, + &props.named, + &props.restored, + current, + is_modified, + on_select, + on_pin, + ) } + +
+ } +} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/enum_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/enum_field.rs new file mode 100644 index 0000000000..724070e2b4 --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/enum_field.rs @@ -0,0 +1,76 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +use std::rc::Rc; + +use itertools::Itertools; +use serde_json::Value; +use web_sys::MouseEvent; +use yew::{Callback, Html, Properties, function_component, html, use_callback}; + +use super::emit; +use crate::config::{ColumnConfigFieldUpdate, EnumVariant}; +use crate::ui::{OptionalField, Select, SelectItem}; + +#[derive(Properties, PartialEq)] +pub struct EnumFieldProps { + pub field_key: String, + pub variants: Vec, + pub default: String, + pub current: Option, + pub on_change: Callback, +} + +#[function_component] +pub fn EnumField(props: &EnumFieldProps) -> Html { + let selected = props + .current + .clone() + .unwrap_or_else(|| props.default.clone()); + + let checked = selected != props.default; + let values: Rc>> = Rc::new( + props + .variants + .iter() + .map(|v| SelectItem::Option(v.value.clone())) + .collect_vec(), + ); + + let on_select = use_callback( + ( + props.field_key.clone(), + props.default.clone(), + props.on_change.clone(), + ), + |value: String, (key, default, on_change)| { + if value == *default { + emit(on_change, key, None); + } else { + emit(on_change, key, Some(Value::String(value))); + } + }, + ); + + let on_reset = use_callback( + (props.field_key.clone(), props.on_change.clone()), + |_: MouseEvent, (key, on_change)| emit(on_change, key, None), + ); + + html! { +
+ + {values} {selected} {on_select} /> + +
+ } +} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/gradient_stops_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/gradient_stops_field.rs new file mode 100644 index 0000000000..9ca4e1d1ba --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/gradient_stops_field.rs @@ -0,0 +1,135 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +use std::collections::BTreeMap; +use std::rc::Rc; + +use serde_json::Value; +use yew::{Callback, Html, Properties, function_component, html, use_callback}; + +use super::{css_field_controls, emit, named_literal}; +use crate::config::{ColumnConfigFieldUpdate, discrete_pair}; +use crate::ui::MultiStopGradientSelector; +use crate::utils::{CssGradient, CssKind, GradientStopSpec, NamedValue, gradient_to_css}; + +#[derive(Properties, PartialEq)] +pub struct GradientStopsFieldProps { + pub field_key: String, + /// Canonical gradient string. + pub default: String, + pub discrete: bool, + /// Canonical gradient string. + pub current: Option, + pub on_change: Callback, + + /// Named gradients (workspace set ∪ theme), for the loader. + #[prop_or_default] + pub named: Rc>, + + /// The restored palette — the set Pin adds to. + #[prop_or_default] + pub restored: Rc>, + + /// Pin the field's `(kind, literal)` into the restored palette. + #[prop_or_default] + pub on_pin: Callback<(CssKind, String)>, +} + +fn gradient_stops(src: &str, default: &str) -> Vec { + let literal = |css: &str| match CssGradient::parse(css) { + Ok(CssGradient::Literal(stops)) => Some(stops), + _ => None, + }; + + literal(src) + .or_else(|| literal(default)) + .unwrap_or_default() +} + +#[function_component] +pub fn GradientStopsField(props: &GradientStopsFieldProps) -> Html { + let current = props.current.as_deref().unwrap_or(&props.default); + let stops = gradient_stops(current, &props.default); + let is_modified = props.current.is_some() && props.current.as_ref() != Some(&props.default); + let emit_css = { + let key = props.field_key.clone(); + let default = props.default.clone(); + let on_change = props.on_change.clone(); + move |css: String| { + if css == default { + emit(&on_change, &key, None); + } else { + emit(&on_change, &key, Some(Value::String(css))); + } + } + }; + + let on_change_stops = { + let emit_css = emit_css.clone(); + Callback::from(move |stops: Vec| { + emit_css(gradient_to_css(&stops)); + }) + }; + + let on_select = { + let emit_css = emit_css.clone(); + let named = props.named.clone(); + let discrete = props.discrete; + Callback::from(move |name: String| { + let Some(literal) = named_literal(&named, &name) else { + return; + }; + + let literal = match CssGradient::parse(&literal) { + Ok(CssGradient::Literal(stops)) if discrete && stops.len() > 2 => { + gradient_to_css(&discrete_pair(stops)) + }, + _ => literal, + }; + + emit_css(literal); + }) + }; + + let on_reset = use_callback( + (props.field_key.clone(), props.on_change.clone()), + |_: (), (key, on_change)| emit(on_change, key, None), + ); + + let on_pin = { + let on_pin = props.on_pin.clone(); + let literal = current.to_owned(); + Callback::from(move |()| on_pin.emit((CssKind::Gradient, literal.clone()))) + }; + + html! { +
+ { css_field_controls( + CssKind::Gradient, + &props.named, + &props.restored, + current, + is_modified, + on_select, + on_pin, + ) } + +
+ } +} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/number_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/number_field.rs new file mode 100644 index 0000000000..1a5660391e --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/number_field.rs @@ -0,0 +1,83 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +use serde_json::Value; +use yew::{Callback, Html, Properties, function_component, html, use_callback}; + +use super::emit; +use crate::config::ColumnConfigFieldUpdate; +use crate::ui::NumberField; + +#[derive(Properties, PartialEq)] +pub struct NumberFieldPrimitiveProps { + pub field_key: String, + pub default: f64, + pub current: Option, + pub on_change: Callback, + + #[prop_or_default] + pub include: Option, + + #[prop_or_default] + pub min: Option, + + #[prop_or_default] + pub max: Option, + + #[prop_or_default] + pub step: Option, +} + +#[function_component] +pub fn NumberFieldPrimitive(props: &NumberFieldPrimitiveProps) -> Html { + let on_change_inner = use_callback( + ( + props.field_key.clone(), + props.default, + props.on_change.clone(), + props.include, + ), + |value: Option, (key, default, on_change, include)| match value { + Some(v) if include.unwrap_or_default() || v != *default => emit( + on_change, + key, + Some( + serde_json::Number::from_f64(v) + .map(Value::Number) + .unwrap_or(Value::Null), + ), + ), + None if include.unwrap_or_default() => emit( + on_change, + key, + Some( + serde_json::Number::from_f64(*default) + .map(Value::Number) + .unwrap_or(Value::Null), + ), + ), + _ => emit(on_change, key, None), + }, + ); + + html! { + + } +} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/palette_field.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/palette_field.rs new file mode 100644 index 0000000000..0c7cb82bf8 --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/primitive_field/palette_field.rs @@ -0,0 +1,125 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +use std::collections::BTreeMap; +use std::rc::Rc; + +use serde_json::Value; +use yew::{Callback, Html, Properties, function_component, html, use_callback}; + +use super::{css_field_controls, emit, named_literal}; +use crate::config::ColumnConfigFieldUpdate; +use crate::ui::PaletteSelector; +use crate::utils::{CssKind, CssPalette, NamedValue}; + +#[derive(Properties, PartialEq)] +pub struct PaletteFieldProps { + pub field_key: String, + /// Canonical palette string. + pub default: String, + pub max: Option, + /// Canonical palette string. + pub current: Option, + pub on_change: Callback, + + /// Named palettes (workspace set ∪ theme), for the loader. + #[prop_or_default] + pub named: Rc>, + + /// The restored palette — the set Pin adds to. + #[prop_or_default] + pub restored: Rc>, + + /// Pin the field's `(kind, literal)` into the restored palette. + #[prop_or_default] + pub on_pin: Callback<(CssKind, String)>, +} + +fn palette_colors(src: &str, default: &str) -> Vec { + let literal = |css: &str| match CssPalette::parse(css) { + Ok(CssPalette::Literal(colors)) => Some(colors), + _ => None, + }; + + literal(src) + .or_else(|| literal(default)) + .unwrap_or_default() +} + +#[function_component] +pub fn PaletteField(props: &PaletteFieldProps) -> Html { + let current = props.current.as_deref().unwrap_or(&props.default); + let values = palette_colors(current, &props.default); + let is_modified = props.current.is_some() && props.current.as_ref() != Some(&props.default); + let emit_css = { + let key = props.field_key.clone(); + let default = props.default.clone(); + let on_change = props.on_change.clone(); + move |css: String| { + if css == default { + emit(&on_change, &key, None); + } else { + emit(&on_change, &key, Some(Value::String(css))); + } + } + }; + + let on_change_palette = { + let emit_css = emit_css.clone(); + Callback::from(move |values: Vec| { + emit_css(CssPalette::Literal(values).to_css()); + }) + }; + + let on_select = { + let emit_css = emit_css.clone(); + let named = props.named.clone(); + Callback::from(move |name: String| { + if let Some(literal) = named_literal(&named, &name) { + emit_css(literal); + } + }) + }; + + let on_reset = use_callback( + (props.field_key.clone(), props.on_change.clone()), + |_: (), (key, on_change)| emit(on_change, key, None), + ); + + let on_pin = { + let on_pin = props.on_pin.clone(); + let literal = current.to_owned(); + Callback::from(move |()| on_pin.emit((CssKind::Palette, literal.clone()))) + }; + + html! { +
+ { css_field_controls( + CssKind::Palette, + &props.named, + &props.restored, + current, + is_modified, + on_select, + on_pin, + ) } + +
+ } +} diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs index ef403a1dc3..aa6369e2f3 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol.rs @@ -14,7 +14,6 @@ mod row_selector; mod symbol_pairs; mod symbol_pairs_item; -mod symbol_selector; use std::collections::HashMap; use std::rc::Rc; diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs_item.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs_item.rs index 4dbb1e0f67..a1436b57cc 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs_item.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/style_tab/symbol/symbol_pairs_item.rs @@ -15,9 +15,9 @@ use std::rc::Rc; use yew::{Callback, Html, Properties, html}; use crate::components::column_settings_sidebar::style_tab::symbol::row_selector::RowSelector; -use crate::components::column_settings_sidebar::style_tab::symbol::symbol_selector::SymbolSelector; use crate::components::filter_dropdown::FilterDropDownElement; use crate::config::SymbolKVPair; +use crate::ui::SymbolSelector; use crate::utils::PtrEqRc; #[derive(Properties, PartialEq)] diff --git a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/window_tab.rs b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/window_tab.rs index 0e09569827..93c952651b 100644 --- a/rust/perspective-viewer/src/rust/components/column_settings_sidebar/window_tab.rs +++ b/rust/perspective-viewer/src/rust/components/column_settings_sidebar/window_tab.rs @@ -12,8 +12,8 @@ use yew::prelude::*; -use super::save_settings::{SaveSettings, SaveSettingsProps}; use crate::components::window_editor::{WindowEditor, WindowEditorProps}; +use crate::ui::{SaveSettings, SaveSettingsProps}; #[derive(PartialEq, Properties, Clone)] pub struct WindowTabProps { diff --git a/rust/perspective-viewer/src/rust/components/command_menu.rs b/rust/perspective-viewer/src/rust/components/command_menu.rs index 9d5b4c6b7c..72d439fff4 100644 --- a/rust/perspective-viewer/src/rust/components/command_menu.rs +++ b/rust/perspective-viewer/src/rust/components/command_menu.rs @@ -22,11 +22,12 @@ use wasm_bindgen::JsCast; use web_sys::HtmlElement; use yew::prelude::*; -use crate::components::panel_menu::session_anchor; use crate::components::style::StyleSurface; use crate::config::CommandSpec; use crate::presentation::Presentation; -use crate::ui::{ContextMenu, ContextMenuEntry, ContextMenuItem, MODAL_SLOT, PortalModal}; +use crate::ui::{ + ContextMenu, ContextMenuEntry, ContextMenuItem, MODAL_SLOT, PortalModal, session_anchor, +}; use crate::utils::*; #[derive(Properties, PartialEq)] diff --git a/rust/perspective-viewer/src/rust/components/debug_panel.rs b/rust/perspective-viewer/src/rust/components/debug_panel.rs index c890e79653..c500a8db98 100644 --- a/rust/perspective-viewer/src/rust/components/debug_panel.rs +++ b/rust/perspective-viewer/src/rust/components/debug_panel.rs @@ -10,21 +10,12 @@ // ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ -use std::cell::Cell; -use std::rc::Rc; - -use perspective_client::ExprValidationError; -use perspective_js::utils::{ApiFuture, JsValueSerdeExt}; -use wasm_bindgen::prelude::*; use yew::prelude::*; -use crate::components::code_editor::CodeEditor; -use crate::config::*; -use crate::js::{MimeType, copy_to_clipboard, paste_from_clipboard}; +use crate::components::json_panel::{JsonPanel, JsonSource}; use crate::presentation::*; use crate::renderer::*; use crate::session::*; -use crate::utils::*; use crate::workspace::Workspace; #[derive(Clone, Properties)] @@ -52,299 +43,21 @@ impl PartialEq for DebugPanelProps { } } -/// Whether the editor holds text the panel has not successfully applied, read -/// synchronously by the config-change listeners and again when a -/// [`DebugPanelProps::set_text`] read lands, so neither a failed apply's own -/// `view_config_changed` nor an in-flight config read discards it. -type Dirty = Rc>; - #[function_component(DebugPanel)] pub fn debug_panel(props: &DebugPanelProps) -> Html { - let expr = use_state_eq(|| Rc::new("".to_string())); - let error = use_state_eq(|| Option::::None); - let select_all = use_memo((), |()| PubSub::default()); - let modified = use_state_eq(|| false); - let dirty: Dirty = use_memo((), |()| Cell::new(false)); - - // Measure natural width on mount and route up to `SettingsPanel`. - let sizer = use_node_ref(); - use_effect_with(expr.clone(), { - let sizer = sizer.clone(); - let on_auto_width = props.on_auto_width.clone(); - move |_| { - if let Some(elem) = sizer.cast::() { - on_auto_width.emit(elem.get_bounding_client_rect().width()); - } - } - }); - - use_effect_with((), { - clone!(error, modified, dirty); - let state = props.clone(); - let text = expr.setter(); - move |()| { - state.set_text(text.clone(), dirty.clone()); - error.set(None); - let sub1 = state - .renderer - .style_changed - .add_listener(state.reset_callback( - text.clone(), - error.setter(), - modified.setter(), - dirty.clone(), - )); - - let sub2 = state - .renderer - .reset_changed - .add_listener(state.reset_callback( - text.clone(), - error.setter(), - modified.setter(), - dirty.clone(), - )); - - let sub3 = state - .session - .view_config_changed - .add_listener(state.reset_callback( - text.clone(), - error.setter(), - modified.setter(), - dirty.clone(), - )); - - || { - drop(sub1); - drop(sub2); - drop(sub3); - } - } - }); - - let oninput = use_callback(expr.setter(), { - clone!(modified, dirty); - move |x, expr| { - dirty.set(true); - modified.set(true); - expr.set(x) - } - }); - - let onsave = use_callback((expr.clone(), error.clone(), props.clone()), { - clone!(modified, dirty); - move |_, (text, error, props)| props.on_save(text, text.setter(), error, &modified, &dirty) - }); - - let oncopy = use_callback( - (expr.clone(), select_all.callback()), - move |_, (text, select_all)| { - select_all.emit(()); - let options = web_sys::BlobPropertyBag::new(); - options.set_type("text/plain"); - let blob_txt = (JsValue::from((***text).clone())).clone(); - let blob_parts = js_sys::Array::from_iter([blob_txt].iter()); - let blob = web_sys::Blob::new_with_str_sequence_and_options(&blob_parts, &options); - ApiFuture::spawn(copy_to_clipboard( - async move { Ok(blob?) }, - MimeType::TextPlain, - )); - }, - ); - - let onapply = use_callback((expr.clone(), error.clone(), props.clone()), { - clone!(modified, dirty); - move |_, (text, error, props)| props.on_save(text, text.setter(), error, &modified, &dirty) - }); - - let onreset = use_callback((expr.setter(), error.clone(), props.clone()), { - clone!(modified, dirty); - move |_, (text, error, props)| { - dirty.set(false); - props.set_text(text.clone(), dirty.clone()); - error.set(None); - modified.set(false); - } - }); - - let onpaste = use_callback((expr.clone(), error.clone(), props.clone()), { - clone!(modified, dirty); - move |_, (text, error, props)| { - clone!(text, error, props, modified, dirty); - ApiFuture::spawn(async move { - if let Some(x) = paste_from_clipboard().await { - let x = Rc::new(x); - dirty.set(true); - modified.set(true); - error.set(None); - text.set(x.clone()); - props.on_save(&x, text.setter(), &error, &modified, &dirty); - } - - Ok(()) - }); - } - }); + let source = JsonSource::Viewer { + presentation: props.presentation.clone(), + renderer: props.renderer.clone(), + session: props.session.clone(), + workspace: props.workspace.clone(), + }; html! { - <> -
- - + } } - -impl DebugPanelProps { - /// Asynchronously read this panel's config into the editor, unless the - /// editor has unapplied text by the time the read lands. - fn set_text(&self, setter: UseStateSetter>, dirty: Dirty) { - let props = self.clone(); - ApiFuture::spawn(async move { - let config = crate::queries::get_viewer_config( - &props.session, - &props.renderer, - &props.presentation, - ) - .await? - .map_table(|name| props.workspace.inline_table_ref(&name)); - let json = JsValue::from_serde_ext(&config)?; - let js_string = - js_sys::JSON::stringify_with_replacer_and_space(&json, &JsValue::NULL, &2.into())?; - - if !dirty.get() { - setter.set(Rc::new(js_string.as_string().unwrap())); - } - - Ok(()) - }); - } - - fn reset_callback( - &self, - text: UseStateSetter>, - error: UseStateSetter>, - modified: UseStateSetter, - dirty: Dirty, - ) -> impl Fn(()) + use<> { - let props = self.clone(); - move |_| { - if dirty.get() { - return; - } - - error.set(None); - props.set_text(text.clone(), dirty.clone()); - modified.set(false); - } - } - - /// Validate and apply the editor's text as this panel's config, treating - /// an un-hosted `table` as a validation error rather than a pending bind. - fn on_save( - &self, - source: &Rc, - text: UseStateSetter>, - error: &UseStateHandle>, - modified: &UseStateHandle, - dirty: &Dirty, - ) { - let props = self.clone(); - clone!(source, error, modified, dirty); - ApiFuture::spawn(async move { - let fail = |message: String, (line, column): (u32, u32)| { - dirty.set(true); - modified.set(true); - error.set(Some(ExprValidationError { - error_message: message, - line, - column, - })); - }; - - let config: ViewerConfigUpdate = match serde_json::from_str(&source) { - Ok(config) => config, - Err(err) => { - let position = (err.line() as u32 - 1, err.column() as u32 - 1); - fail(err.to_string(), position); - return Ok(()); - }, - }; - - let active = props.workspace.active_renderer().as_ref() == Some(&props.renderer); - let result = crate::tasks::restore_panel( - &props.session, - &props.renderer, - &props.presentation, - &props.workspace, - crate::tasks::RestoreMode::Existing { active }, - config, - crate::tasks::RestoreErrors::Suppress, - MissingTable::Error, - None, - ) - .await; - - match result { - Ok(_) => { - dirty.set(false); - error.set(None); - modified.set(false); - props.set_text(text, dirty.clone()); - }, - Err(e) => { - let message = format!("{e}"); - let position = if message.starts_with("Unknown table") { - locate_key(&source, "table") - } else { - (0, 0) - }; - - fail(message, position) - }, - } - - Ok(()) - }); - } -} - -/// The 0-based `(line, column)` of the first `"key"` in `text`, or `(0, 0)` -/// when absent. -fn locate_key(text: &str, key: &str) -> (u32, u32) { - let needle = format!("\"{key}\""); - text.lines() - .enumerate() - .find_map(|(line, content)| { - content - .find(&needle) - .map(|column| (line as u32, column as u32)) - }) - .unwrap_or((0, 0)) -} diff --git a/rust/perspective-viewer/src/rust/components/dragdrop_list.rs b/rust/perspective-viewer/src/rust/components/dragdrop_list.rs index 183eb906b6..6eef979810 100644 --- a/rust/perspective-viewer/src/rust/components/dragdrop_list.rs +++ b/rust/perspective-viewer/src/rust/components/dragdrop_list.rs @@ -38,6 +38,9 @@ where pub presentation: Presentation, pub name: &'static str, + + /// The drop zone this list is, sent with every [`DragListEvent`]. + pub target: DragTarget, pub column_dropdown: ColumnDropDownElement, pub exclude: HashSet, pub children: ChildrenWithProps, @@ -88,6 +91,7 @@ where { fn eq(&self, other: &Self) -> bool { self.name == other.name + && self.target == other.target && self.children == other.children && self.allow_duplicates == other.allow_duplicates && self.is_dragover == other.is_dragover @@ -112,26 +116,25 @@ pub enum DragDropListMsg { /// /// Before you ask: yes, `frozen_size` needs to be a float64 since `flex` /// containers can have fractional dimensions. -pub struct DragDropList +pub struct DragDropList where T: Component, + T::Message: From, U: Component, ::Properties: DragDropListItemProps, - V: DragContext + 'static, { parent_type: PhantomData, item_type: PhantomData, - draggable_type: PhantomData, elem: NodeRef, frozen_size: Option, } -impl Component for DragDropList +impl Component for DragDropList where T: Component, + T::Message: From, U: Component, ::Properties: DragDropListItemProps, - V: DragContext + 'static, { type Message = DragDropListMsg; type Properties = DragDropListProps; @@ -140,7 +143,6 @@ where Self { parent_type: PhantomData, item_type: PhantomData, - draggable_type: PhantomData, elem: NodeRef::default(), frozen_size: None, } @@ -188,6 +190,7 @@ where } fn view(&self, ctx: &Context) -> Html { + let target = ctx.props().target; let dragover = Callback::from(|_event: DragEvent| _event.prevent_default()); // On dragleave, signal the parent but no need to redraw as parent will @@ -199,7 +202,7 @@ where let link = ctx.link().clone(); move || { link.send_message(DragDropListMsg::Freeze(true)); - parent.send_message(V::dragenter(total)) + parent.send_message(DragListEvent::DragEnter(target, total)) } }, { @@ -207,7 +210,7 @@ where let link = ctx.link().clone(); move || { link.send_message(DragDropListMsg::Freeze(false)); - parent.send_message(V::dragleave()) + parent.send_message(DragListEvent::DragLeave(target)) } }, ); @@ -240,10 +243,14 @@ where .props() .presentation .get_drag_target() - .map(|x| V::is_self_move(x)) + .map(|x| x == target) .unwrap_or_default(); - let close = left_click(ctx.props().parent.callback(|_| V::close(0))); + let close = left_click( + ctx.props() + .parent + .callback(move |_| DragListEvent::Close(target, 0)), + ); let dragenter = ctx.props().parent.callback({ let container_noderef = container_noderef.clone(); move |event: DragEvent| { @@ -254,7 +261,7 @@ where { let _ = elem.dataset().set("safaridragleave", "true"); } - V::dragenter(0) + DragListEvent::DragEnter(target, 0) } }); @@ -293,7 +300,7 @@ where .props() .presentation .get_drag_target() - .map(|x| V::is_self_move(x)) + .map(|x| x == target) .unwrap_or_default(); let is_duplicate = columns @@ -331,7 +338,11 @@ where .into_iter() .enumerate() .map(|(idx, column)| { - let close = left_click(ctx.props().parent.callback(move |_| V::close(idx))); + let close = left_click( + ctx.props() + .parent + .callback(move |_| DragListEvent::Close(target, idx)), + ); let dragenter = ctx.props().parent.callback({ let link = ctx.link().clone(); let container_noderef = container_noderef.clone(); @@ -359,7 +370,7 @@ where let _ = elem.dataset().set("safaridragleave", "true"); } link.send_message(DragDropListMsg::Freeze(true)); - V::dragenter(idx) + DragListEvent::DragEnter(target, idx) } }); @@ -397,7 +408,10 @@ where let column_dropdown = ctx.props().column_dropdown.clone(); let exclude = ctx.props().exclude.clone(); - let on_select = ctx.props().parent.callback(V::create); + let on_select = ctx + .props() + .parent + .callback(move |col| DragListEvent::Create(target, col)); let class = classes!("rrow"); let is_enabled = true; @@ -440,7 +454,7 @@ where
} else if show_empty { @@ -464,10 +478,11 @@ pub trait DragDropListItemProps: Properties { fn get_item(&self) -> Self::Item; } -pub trait DragContext { - fn close(index: usize) -> T; - fn dragleave() -> T; - fn dragenter(index: usize) -> T; - fn create(col: InPlaceColumn) -> T; - fn is_self_move(effect: DragTarget) -> bool; +/// A [`DragDropList`] interaction, sent to the parent `Component` as its +/// `Message` via `From`. +pub enum DragListEvent { + DragEnter(DragTarget, usize), + DragLeave(DragTarget), + Close(DragTarget, usize), + Create(DragTarget, InPlaceColumn), } diff --git a/rust/perspective-viewer/src/rust/components/empty_placeholder.rs b/rust/perspective-viewer/src/rust/components/empty_placeholder.rs new file mode 100644 index 0000000000..92dd1ab8bb --- /dev/null +++ b/rust/perspective-viewer/src/rust/components/empty_placeholder.rs @@ -0,0 +1,25 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +//! The settings-sidebar placeholder shown in place of a tab body that has +//! nothing to show while the element is an EMPTY STAGE (zero panels): the +//! Query, Plugin and Debug tabs all read a panel's table/plugin/config. + +use yew::prelude::*; + +/// A "No table loaded" message filling a settings tab body. The label is the +/// localizable `--psp-label--no-table--content` (see `themes/intl.css`), +/// rendered by `viewer.css` `.psp-empty-placeholder::before`. +#[function_component] +pub fn EmptyPlaceholder() -> Html { + html! {