From 56f9543a95ded43066505521f6178758ad139e90 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Wed, 21 Sep 2022 12:39:59 -0700 Subject: [PATCH 01/55] reworked style tree to use colorScheme instead of old theme. Very limited style for now --- Cargo.lock | 17 - crates/chat_panel/Cargo.toml | 20 - crates/chat_panel/src/chat_panel.rs | 433 ------------------ crates/terminal/src/mappings/colors.rs | 130 +++--- crates/terminal/src/terminal.rs | 2 +- .../terminal/src/terminal_container_view.rs | 12 +- crates/terminal/src/terminal_element.rs | 25 +- crates/terminal/src/terminal_view.rs | 1 - crates/theme/src/theme.rs | 19 - crates/zed/Cargo.toml | 1 - crates/zed/src/main.rs | 1 - styles/src/buildThemes.ts | 22 +- styles/src/colorSchemes.ts | 31 ++ styles/src/styleTree/app.ts | 42 +- styles/src/styleTree/chatPanel.ts | 108 ----- styles/src/styleTree/commandPalette.ts | 15 +- styles/src/styleTree/components.ts | 185 +++++--- styles/src/styleTree/contactFinder.ts | 19 +- styles/src/styleTree/contactNotification.ts | 21 +- styles/src/styleTree/contactsPanel.ts | 67 +-- styles/src/styleTree/contextMenu.ts | 33 +- styles/src/styleTree/editor.ts | 219 ++++++--- styles/src/styleTree/hoverPopover.ts | 38 +- styles/src/styleTree/picker.ts | 38 +- styles/src/styleTree/projectDiagnostics.ts | 11 +- styles/src/styleTree/projectPanel.ts | 27 +- styles/src/styleTree/search.ts | 50 +- styles/src/styleTree/statusBar.ts | 77 ++-- styles/src/styleTree/tabBar.ts | 52 ++- styles/src/styleTree/terminal.ts | 79 ++-- styles/src/styleTree/tooltip.ts | 20 +- styles/src/styleTree/updateNotification.ts | 17 +- styles/src/styleTree/workspace.ts | 101 ++-- styles/src/themes.ts | 31 -- styles/src/themes/abruzzo.ts | 4 +- styles/src/themes/andromeda.ts | 4 +- styles/src/themes/brushtrees.ts | 6 +- styles/src/themes/cave.ts | 6 +- styles/src/themes/common/base16.ts | 288 ------------ styles/src/themes/common/colorScheme.ts | 83 ++++ styles/src/themes/common/ramps.ts | 176 +++++++ styles/src/themes/common/theme.ts | 164 ------- styles/src/themes/one-dark.ts | 4 +- styles/src/themes/one-light.ts | 4 +- styles/src/themes/rose-pine-dawn.ts | 4 +- styles/src/themes/rose-pine-moon.ts | 4 +- styles/src/themes/rose-pine.ts | 4 +- styles/src/themes/sandcastle.ts | 4 +- styles/src/themes/solarized.ts | 6 +- styles/src/themes/sulphurpool.ts | 6 +- styles/src/themes/summercamp.ts | 4 +- styles/src/themes/summerfruit.ts | 6 +- styles/src/themes/template.ts | 10 +- 53 files changed, 1017 insertions(+), 1734 deletions(-) delete mode 100644 crates/chat_panel/Cargo.toml delete mode 100644 crates/chat_panel/src/chat_panel.rs create mode 100644 styles/src/colorSchemes.ts delete mode 100644 styles/src/styleTree/chatPanel.ts delete mode 100644 styles/src/themes.ts delete mode 100644 styles/src/themes/common/base16.ts create mode 100644 styles/src/themes/common/colorScheme.ts create mode 100644 styles/src/themes/common/ramps.ts delete mode 100644 styles/src/themes/common/theme.ts diff --git a/Cargo.lock b/Cargo.lock index dad1219ddf..ea877a39d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,22 +814,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chat_panel" -version = "0.1.0" -dependencies = [ - "client", - "editor", - "gpui", - "menu", - "postage", - "settings", - "theme", - "time 0.3.11", - "util", - "workspace", -] - [[package]] name = "chrono" version = "0.4.19" @@ -7138,7 +7122,6 @@ dependencies = [ "auto_update", "backtrace", "breadcrumbs", - "chat_panel", "chrono", "cli", "client", diff --git a/crates/chat_panel/Cargo.toml b/crates/chat_panel/Cargo.toml deleted file mode 100644 index 3f3a2651b0..0000000000 --- a/crates/chat_panel/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "chat_panel" -version = "0.1.0" -edition = "2021" - -[lib] -path = "src/chat_panel.rs" -doctest = false - -[dependencies] -client = { path = "../client" } -editor = { path = "../editor" } -gpui = { path = "../gpui" } -menu = { path = "../menu" } -settings = { path = "../settings" } -theme = { path = "../theme" } -util = { path = "../util" } -workspace = { path = "../workspace" } -postage = { version = "0.4.1", features = ["futures-traits"] } -time = { version = "0.3", features = ["serde", "serde-well-known"] } diff --git a/crates/chat_panel/src/chat_panel.rs b/crates/chat_panel/src/chat_panel.rs deleted file mode 100644 index 6744ae9339..0000000000 --- a/crates/chat_panel/src/chat_panel.rs +++ /dev/null @@ -1,433 +0,0 @@ -use client::{ - channel::{Channel, ChannelEvent, ChannelList, ChannelMessage}, - Client, -}; -use editor::Editor; -use gpui::{ - actions, - elements::*, - platform::CursorStyle, - views::{ItemType, Select, SelectStyle}, - AnyViewHandle, AppContext, Entity, ModelHandle, MouseButton, MutableAppContext, RenderContext, - Subscription, Task, View, ViewContext, ViewHandle, -}; -use menu::Confirm; -use postage::prelude::Stream; -use settings::{Settings, SoftWrap}; -use std::sync::Arc; -use time::{OffsetDateTime, UtcOffset}; -use util::{ResultExt, TryFutureExt}; - -const MESSAGE_LOADING_THRESHOLD: usize = 50; - -pub struct ChatPanel { - rpc: Arc, - channel_list: ModelHandle, - active_channel: Option<(ModelHandle, Subscription)>, - message_list: ListState, - input_editor: ViewHandle, - channel_select: ViewHandle, - local_timezone: UtcOffset, - _observe_status: Task<()>, -} - -pub enum Event {} - -actions!(chat_panel, [LoadMoreMessages]); - -pub fn init(cx: &mut MutableAppContext) { - cx.add_action(ChatPanel::send); - cx.add_action(ChatPanel::load_more_messages); -} - -impl ChatPanel { - pub fn new( - rpc: Arc, - channel_list: ModelHandle, - cx: &mut ViewContext, - ) -> Self { - let input_editor = cx.add_view(|cx| { - let mut editor = - Editor::auto_height(4, Some(|theme| theme.chat_panel.input_editor.clone()), cx); - editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); - editor - }); - let channel_select = cx.add_view(|cx| { - let channel_list = channel_list.clone(); - Select::new(0, cx, { - move |ix, item_type, is_hovered, cx| { - Self::render_channel_name( - &channel_list, - ix, - item_type, - is_hovered, - &cx.global::().theme.chat_panel.channel_select, - cx, - ) - } - }) - .with_style(move |cx| { - let theme = &cx.global::().theme.chat_panel.channel_select; - SelectStyle { - header: theme.header.container, - menu: theme.menu, - } - }) - }); - - let mut message_list = ListState::new(0, Orientation::Bottom, 1000., cx, { - let this = cx.weak_handle(); - move |_, ix, cx| { - let this = this.upgrade(cx).unwrap().read(cx); - let message = this.active_channel.as_ref().unwrap().0.read(cx).message(ix); - this.render_message(message, cx) - } - }); - message_list.set_scroll_handler(|visible_range, cx| { - if visible_range.start < MESSAGE_LOADING_THRESHOLD { - cx.dispatch_action(LoadMoreMessages); - } - }); - let _observe_status = cx.spawn_weak(|this, mut cx| { - let mut status = rpc.status(); - async move { - while (status.recv().await).is_some() { - if let Some(this) = this.upgrade(&cx) { - this.update(&mut cx, |_, cx| cx.notify()); - } else { - break; - } - } - } - }); - - let mut this = Self { - rpc, - channel_list, - active_channel: Default::default(), - message_list, - input_editor, - channel_select, - local_timezone: cx.platform().local_timezone(), - _observe_status, - }; - - this.init_active_channel(cx); - cx.observe(&this.channel_list, |this, _, cx| { - this.init_active_channel(cx); - }) - .detach(); - cx.observe(&this.channel_select, |this, channel_select, cx| { - let selected_ix = channel_select.read(cx).selected_index(); - let selected_channel = this.channel_list.update(cx, |channel_list, cx| { - let available_channels = channel_list.available_channels()?; - let channel_id = available_channels.get(selected_ix)?.id; - channel_list.get_channel(channel_id, cx) - }); - if let Some(selected_channel) = selected_channel { - this.set_active_channel(selected_channel, cx); - } - }) - .detach(); - - this - } - - fn init_active_channel(&mut self, cx: &mut ViewContext) { - let (active_channel, channel_count) = self.channel_list.update(cx, |list, cx| { - let channel_count; - let mut active_channel = None; - - if let Some(available_channels) = list.available_channels() { - channel_count = available_channels.len(); - if self.active_channel.is_none() { - if let Some(channel_id) = available_channels.first().map(|channel| channel.id) { - active_channel = list.get_channel(channel_id, cx); - } - } - } else { - channel_count = 0; - } - - (active_channel, channel_count) - }); - - if let Some(active_channel) = active_channel { - self.set_active_channel(active_channel, cx); - } else { - self.message_list.reset(0); - self.active_channel = None; - } - - self.channel_select.update(cx, |select, cx| { - select.set_item_count(channel_count, cx); - }); - } - - fn set_active_channel(&mut self, channel: ModelHandle, cx: &mut ViewContext) { - if self.active_channel.as_ref().map(|e| &e.0) != Some(&channel) { - { - let channel = channel.read(cx); - self.message_list.reset(channel.message_count()); - let placeholder = format!("Message #{}", channel.name()); - self.input_editor.update(cx, move |editor, cx| { - editor.set_placeholder_text(placeholder, cx); - }); - } - let subscription = cx.subscribe(&channel, Self::channel_did_change); - self.active_channel = Some((channel, subscription)); - } - } - - fn channel_did_change( - &mut self, - _: ModelHandle, - event: &ChannelEvent, - cx: &mut ViewContext, - ) { - match event { - ChannelEvent::MessagesUpdated { - old_range, - new_count, - } => { - self.message_list.splice(old_range.clone(), *new_count); - } - } - cx.notify(); - } - - fn render_channel(&self, cx: &mut RenderContext) -> ElementBox { - let theme = &cx.global::().theme; - Flex::column() - .with_child( - Container::new(ChildView::new(&self.channel_select, cx).boxed()) - .with_style(theme.chat_panel.channel_select.container) - .boxed(), - ) - .with_child(self.render_active_channel_messages()) - .with_child(self.render_input_box(cx)) - .boxed() - } - - fn render_active_channel_messages(&self) -> ElementBox { - let messages = if self.active_channel.is_some() { - List::new(self.message_list.clone()).boxed() - } else { - Empty::new().boxed() - }; - - FlexItem::new(messages).flex(1., true).boxed() - } - - fn render_message(&self, message: &ChannelMessage, cx: &AppContext) -> ElementBox { - let now = OffsetDateTime::now_utc(); - let settings = cx.global::(); - let theme = if message.is_pending() { - &settings.theme.chat_panel.pending_message - } else { - &settings.theme.chat_panel.message - }; - - Container::new( - Flex::column() - .with_child( - Flex::row() - .with_child( - Container::new( - Label::new( - message.sender.github_login.clone(), - theme.sender.text.clone(), - ) - .boxed(), - ) - .with_style(theme.sender.container) - .boxed(), - ) - .with_child( - Container::new( - Label::new( - format_timestamp(message.timestamp, now, self.local_timezone), - theme.timestamp.text.clone(), - ) - .boxed(), - ) - .with_style(theme.timestamp.container) - .boxed(), - ) - .boxed(), - ) - .with_child(Text::new(message.body.clone(), theme.body.clone()).boxed()) - .boxed(), - ) - .with_style(theme.container) - .boxed() - } - - fn render_input_box(&self, cx: &AppContext) -> ElementBox { - let theme = &cx.global::().theme; - Container::new(ChildView::new(&self.input_editor, cx).boxed()) - .with_style(theme.chat_panel.input_editor.container) - .boxed() - } - - fn render_channel_name( - channel_list: &ModelHandle, - ix: usize, - item_type: ItemType, - is_hovered: bool, - theme: &theme::ChannelSelect, - cx: &AppContext, - ) -> ElementBox { - let channel = &channel_list.read(cx).available_channels().unwrap()[ix]; - let theme = match (item_type, is_hovered) { - (ItemType::Header, _) => &theme.header, - (ItemType::Selected, false) => &theme.active_item, - (ItemType::Selected, true) => &theme.hovered_active_item, - (ItemType::Unselected, false) => &theme.item, - (ItemType::Unselected, true) => &theme.hovered_item, - }; - Container::new( - Flex::row() - .with_child( - Container::new(Label::new("#".to_string(), theme.hash.text.clone()).boxed()) - .with_style(theme.hash.container) - .boxed(), - ) - .with_child(Label::new(channel.name.clone(), theme.name.clone()).boxed()) - .boxed(), - ) - .with_style(theme.container) - .boxed() - } - - fn render_sign_in_prompt(&self, cx: &mut RenderContext) -> ElementBox { - let theme = cx.global::().theme.clone(); - let rpc = self.rpc.clone(); - let this = cx.handle(); - - enum SignInPromptLabel {} - - Align::new( - MouseEventHandler::::new(0, cx, |mouse_state, _| { - Label::new( - "Sign in to use chat".to_string(), - if mouse_state.hovered() { - theme.chat_panel.hovered_sign_in_prompt.clone() - } else { - theme.chat_panel.sign_in_prompt.clone() - }, - ) - .boxed() - }) - .with_cursor_style(CursorStyle::PointingHand) - .on_click(MouseButton::Left, move |_, cx| { - let rpc = rpc.clone(); - let this = this.clone(); - cx.spawn(|mut cx| async move { - if rpc - .authenticate_and_connect(true, &cx) - .log_err() - .await - .is_some() - { - cx.update(|cx| { - if let Some(this) = this.upgrade(cx) { - if this.is_focused(cx) { - this.update(cx, |this, cx| cx.focus(&this.input_editor)); - } - } - }) - } - }) - .detach(); - }) - .boxed(), - ) - .boxed() - } - - fn send(&mut self, _: &Confirm, cx: &mut ViewContext) { - if let Some((channel, _)) = self.active_channel.as_ref() { - let body = self.input_editor.update(cx, |editor, cx| { - let body = editor.text(cx); - editor.clear(cx); - body - }); - - if let Some(task) = channel - .update(cx, |channel, cx| channel.send_message(body, cx)) - .log_err() - { - task.detach(); - } - } - } - - fn load_more_messages(&mut self, _: &LoadMoreMessages, cx: &mut ViewContext) { - if let Some((channel, _)) = self.active_channel.as_ref() { - channel.update(cx, |channel, cx| { - channel.load_more_messages(cx); - }) - } - } -} - -impl Entity for ChatPanel { - type Event = Event; -} - -impl View for ChatPanel { - fn ui_name() -> &'static str { - "ChatPanel" - } - - fn render(&mut self, cx: &mut RenderContext) -> ElementBox { - let element = if self.rpc.user_id().is_some() { - self.render_channel(cx) - } else { - self.render_sign_in_prompt(cx) - }; - let theme = &cx.global::().theme; - ConstrainedBox::new( - Container::new(element) - .with_style(theme.chat_panel.container) - .boxed(), - ) - .with_min_width(150.) - .boxed() - } - - fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext) { - if matches!( - *self.rpc.status().borrow(), - client::Status::Connected { .. } - ) { - cx.focus(&self.input_editor); - } - } -} - -fn format_timestamp( - mut timestamp: OffsetDateTime, - mut now: OffsetDateTime, - local_timezone: UtcOffset, -) -> String { - timestamp = timestamp.to_offset(local_timezone); - now = now.to_offset(local_timezone); - - let today = now.date(); - let date = timestamp.date(); - let mut hour = timestamp.hour(); - let mut part = "am"; - if hour > 12 { - hour -= 12; - part = "pm"; - } - if date == today { - format!("{:02}:{:02}{}", hour, timestamp.minute(), part) - } else if date.next_day() == Some(today) { - format!("yesterday at {:02}:{:02}{}", hour, timestamp.minute(), part) - } else { - format!("{:02}/{}/{}", date.month() as u32, date.day(), date.year()) - } -} From 0d9eecd2edc3fca520b02bb8265ec57ed47d03cd Mon Sep 17 00:00:00 2001 From: Nate Butler Date: Wed, 19 Oct 2022 14:55:22 -0400 Subject: [PATCH 49/55] WIP command palette changes --- styles/src/styleTree/commandPalette.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/styles/src/styleTree/commandPalette.ts b/styles/src/styleTree/commandPalette.ts index 1aa45c8c57..4bde81f7d8 100644 --- a/styles/src/styleTree/commandPalette.ts +++ b/styles/src/styleTree/commandPalette.ts @@ -7,7 +7,7 @@ export default function commandPalette(colorScheme: ColorScheme) { return { keystrokeSpacing: 8, key: { - text: text(layer, "mono", "on", "default", { size: "xs" }), + text: text(layer, "mono", "variant", "default", { size: "xs" }), cornerRadius: 2, background: background(layer, "on"), padding: { @@ -22,7 +22,7 @@ export default function commandPalette(colorScheme: ColorScheme) { left: 2, }, active: { - text: text(layer, "mono", "on", "inverted", { size: "xs" }), + text: text(layer, "mono", "on", "default", { size: "xs" }), background: withOpacity(background(layer, "on"), 0.2), }, }, From e3809c267d51a5ebac6975d545c5de5ca670a722 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Wed, 19 Oct 2022 13:02:51 -0700 Subject: [PATCH 50/55] flattened layers and elevations --- Cargo.lock | 16 --- crates/theme/src/theme.rs | 18 +-- crates/theme_testbench/src/theme_testbench.rs | 109 ++++-------------- styles/src/styleTree/app.ts | 70 +++-------- styles/src/styleTree/commandPalette.ts | 2 +- styles/src/styleTree/contactFinder.ts | 2 +- styles/src/styleTree/contactList.ts | 2 +- styles/src/styleTree/contactNotification.ts | 2 +- styles/src/styleTree/contactsPopover.ts | 4 +- styles/src/styleTree/contextMenu.ts | 5 +- styles/src/styleTree/editor.ts | 97 ++++++++-------- styles/src/styleTree/hoverPopover.ts | 10 +- .../src/styleTree/incomingCallNotification.ts | 2 +- styles/src/styleTree/picker.ts | 5 +- styles/src/styleTree/projectDiagnostics.ts | 2 +- styles/src/styleTree/projectPanel.ts | 2 +- .../styleTree/projectSharedNotification.ts | 5 +- styles/src/styleTree/search.ts | 2 +- styles/src/styleTree/statusBar.ts | 2 +- styles/src/styleTree/tabBar.ts | 7 +- styles/src/styleTree/terminal.ts | 64 +++++----- styles/src/styleTree/tooltip.ts | 5 +- styles/src/styleTree/updateNotification.ts | 2 +- styles/src/styleTree/workspace.ts | 37 +++--- styles/src/themes/common/colorScheme.ts | 22 ++-- styles/src/themes/common/ramps.ts | 107 +++++------------ 26 files changed, 203 insertions(+), 398 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b442f8d716..d960b467ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -855,22 +855,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chat_panel" -version = "0.1.0" -dependencies = [ - "client", - "editor", - "gpui", - "menu", - "postage", - "settings", - "theme", - "time 0.3.15", - "util", - "workspace", -] - [[package]] name = "chrono" version = "0.4.22" diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 11296af6ab..b2e97ac831 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -797,22 +797,16 @@ pub struct ColorScheme { pub name: String, pub is_light: bool, - pub lowest: Elevation, - pub middle: Elevation, - pub highest: Elevation, - - pub players: Vec, -} - -#[derive(Clone, Deserialize, Default)] -pub struct Elevation { pub ramps: RampSet, - pub bottom: Layer, + pub lowest: Layer, pub middle: Layer, - pub top: Layer, + pub highest: Layer, - pub shadow: Option, + pub popover_shadow: Shadow, + pub modal_shadow: Shadow, + + pub players: Vec, } #[derive(Clone, Deserialize, Default)] diff --git a/crates/theme_testbench/src/theme_testbench.rs b/crates/theme_testbench/src/theme_testbench.rs index f9f0d96f4e..ac78cce1c9 100644 --- a/crates/theme_testbench/src/theme_testbench.rs +++ b/crates/theme_testbench/src/theme_testbench.rs @@ -11,7 +11,7 @@ use gpui::{ use project::{Project, ProjectEntryId, ProjectPath}; use settings::Settings; use smallvec::SmallVec; -use theme::{ColorScheme, Elevation, Layer, Style, StyleSet}; +use theme::{ColorScheme, Layer, Style, StyleSet}; use workspace::{Item, Workspace}; actions!(theme, [DeployThemeTestbench]); @@ -51,38 +51,15 @@ impl ThemeTestbench { } Flex::column() - .with_child(display_ramp(&color_scheme.lowest.ramps.neutral)) - .with_child(display_ramp(&color_scheme.lowest.ramps.red)) - .with_child(display_ramp(&color_scheme.lowest.ramps.orange)) - .with_child(display_ramp(&color_scheme.lowest.ramps.yellow)) - .with_child(display_ramp(&color_scheme.lowest.ramps.green)) - .with_child(display_ramp(&color_scheme.lowest.ramps.cyan)) - .with_child(display_ramp(&color_scheme.lowest.ramps.blue)) - .with_child(display_ramp(&color_scheme.lowest.ramps.violet)) - .with_child(display_ramp(&color_scheme.lowest.ramps.magenta)) - } - - fn render_elevation( - elevation_index: usize, - elevation: &Elevation, - cx: &mut RenderContext<'_, Self>, - ) -> Flex { - Flex::column() - .with_child( - Self::render_layer(elevation_index * 1000 + 100, &elevation.bottom, cx) - .flex(1., true) - .boxed(), - ) - .with_child( - Self::render_layer(elevation_index * 1000 + 200, &elevation.middle, cx) - .flex(1., true) - .boxed(), - ) - .with_child( - Self::render_layer(elevation_index * 1000 + 300, &elevation.top, cx) - .flex(1., true) - .boxed(), - ) + .with_child(display_ramp(&color_scheme.ramps.neutral)) + .with_child(display_ramp(&color_scheme.ramps.red)) + .with_child(display_ramp(&color_scheme.ramps.orange)) + .with_child(display_ramp(&color_scheme.ramps.yellow)) + .with_child(display_ramp(&color_scheme.ramps.green)) + .with_child(display_ramp(&color_scheme.ramps.cyan)) + .with_child(display_ramp(&color_scheme.ramps.blue)) + .with_child(display_ramp(&color_scheme.ramps.violet)) + .with_child(display_ramp(&color_scheme.ramps.magenta)) } fn render_layer( @@ -272,44 +249,6 @@ impl ThemeTestbench { Label::new(text, text_style) } - - fn elevation_style(elevation: &Elevation) -> ContainerStyle { - let style = ContainerStyle { - margin: Margin { - top: 10., - bottom: 10., - left: 10., - right: 10., - }, - background_color: Some(elevation.bottom.base.default.background), - ..Default::default() - }; - - if elevation.shadow.is_some() { - ContainerStyle { - padding: Padding { - top: 10., - bottom: 10., - left: 10., - right: 10., - }, - border: Border { - width: 1., - color: elevation.bottom.base.default.border, - overlay: false, - top: true, - bottom: true, - left: true, - right: true, - }, - corner_radius: 32., - shadow: elevation.shadow, - ..style - } - } else { - style - } - } } impl Entity for ThemeTestbench { @@ -333,32 +272,24 @@ impl View for ThemeTestbench { .boxed(), ) .with_child( - Self::render_elevation(0, &color_scheme.lowest, cx) - .flex(1., true) - .boxed(), - ) - .with_child( - Flex::row() + Flex::column() .with_child( - Self::render_elevation(1, &color_scheme.middle, cx) + Self::render_layer(100, &color_scheme.lowest, cx) .flex(1., true) .boxed(), ) .with_child( - Container::new( - Self::render_elevation(2, &color_scheme.highest, cx).boxed(), - ) - .with_style(Self::elevation_style(&color_scheme.highest)) - .flex(1., true) - .boxed(), + Self::render_layer(200, &color_scheme.middle, cx) + .flex(1., true) + .boxed(), + ) + .with_child( + Self::render_layer(300, &color_scheme.highest, cx) + .flex(1., true) + .boxed(), ) - .contained() - .with_style(Self::elevation_style(&color_scheme.middle)) - .flex(2., true) .boxed(), ) - .contained() - .with_style(Self::elevation_style(&color_scheme.lowest)) .boxed() } } diff --git a/styles/src/styleTree/app.ts b/styles/src/styleTree/app.ts index 3a800c415b..bc4b992ed3 100644 --- a/styles/src/styleTree/app.ts +++ b/styles/src/styleTree/app.ts @@ -18,10 +18,6 @@ import contactList from "./contactList"; import incomingCallNotification from "./incomingCallNotification"; import { ColorScheme } from "../themes/common/colorScheme"; -// export const panel = { -// padding: { top: 12, bottom: 12 }, -// }; - export default function app(colorScheme: ColorScheme): Object { return { meta: { @@ -43,68 +39,28 @@ export default function app(colorScheme: ColorScheme): Object { contactList: contactList(colorScheme), search: search(colorScheme), breadcrumbs: { - ...text(colorScheme.lowest.top, "sans", "variant"), + ...text(colorScheme.highest, "sans", "variant"), padding: { left: 6, }, }, updateNotification: updateNotification(colorScheme), tooltip: tooltip(colorScheme), - terminal: terminal(colorScheme.lowest, colorScheme.players[0].cursor), + terminal: terminal(colorScheme), colorScheme: { ...colorScheme, - lowest: { - ...colorScheme.lowest, - ramps: { - neutral: colorScheme.lowest.ramps.neutral.colors(100, "hex"), - red: colorScheme.lowest.ramps.red.colors(100, "hex"), - orange: colorScheme.lowest.ramps.orange.colors(100, "hex"), - yellow: colorScheme.lowest.ramps.yellow.colors(100, "hex"), - green: colorScheme.lowest.ramps.green.colors(100, "hex"), - cyan: colorScheme.lowest.ramps.cyan.colors(100, "hex"), - blue: colorScheme.lowest.ramps.blue.colors(100, "hex"), - violet: colorScheme.lowest.ramps.violet.colors(100, "hex"), - magenta: colorScheme.lowest.ramps.magenta.colors(100, "hex"), - }, + players: Object.values(colorScheme.players), + ramps: { + neutral: colorScheme.ramps.neutral.colors(100, "hex"), + red: colorScheme.ramps.red.colors(100, "hex"), + orange: colorScheme.ramps.orange.colors(100, "hex"), + yellow: colorScheme.ramps.yellow.colors(100, "hex"), + green: colorScheme.ramps.green.colors(100, "hex"), + cyan: colorScheme.ramps.cyan.colors(100, "hex"), + blue: colorScheme.ramps.blue.colors(100, "hex"), + violet: colorScheme.ramps.violet.colors(100, "hex"), + magenta: colorScheme.ramps.magenta.colors(100, "hex"), }, - middle: { - ...colorScheme.middle, - ramps: { - neutral: colorScheme.middle.ramps.neutral.colors(100, "hex"), - red: colorScheme.middle.ramps.red.colors(100, "hex"), - orange: colorScheme.middle.ramps.orange.colors(100, "hex"), - yellow: colorScheme.middle.ramps.yellow.colors(100, "hex"), - green: colorScheme.middle.ramps.green.colors(100, "hex"), - cyan: colorScheme.middle.ramps.cyan.colors(100, "hex"), - blue: colorScheme.middle.ramps.blue.colors(100, "hex"), - violet: colorScheme.middle.ramps.violet.colors(100, "hex"), - magenta: colorScheme.middle.ramps.magenta.colors(100, "hex"), - }, - }, - highest: { - ...colorScheme.highest, - ramps: { - neutral: colorScheme.highest.ramps.neutral.colors(100, "hex"), - red: colorScheme.highest.ramps.red.colors(100, "hex"), - orange: colorScheme.highest.ramps.orange.colors(100, "hex"), - yellow: colorScheme.highest.ramps.yellow.colors(100, "hex"), - green: colorScheme.highest.ramps.green.colors(100, "hex"), - cyan: colorScheme.highest.ramps.cyan.colors(100, "hex"), - blue: colorScheme.highest.ramps.blue.colors(100, "hex"), - violet: colorScheme.highest.ramps.violet.colors(100, "hex"), - magenta: colorScheme.highest.ramps.magenta.colors(100, "hex"), - }, - }, - players: [ - colorScheme.players["0"], - colorScheme.players["1"], - colorScheme.players["2"], - colorScheme.players["3"], - colorScheme.players["4"], - colorScheme.players["5"], - colorScheme.players["6"], - colorScheme.players["7"], - ], }, }; } diff --git a/styles/src/styleTree/commandPalette.ts b/styles/src/styleTree/commandPalette.ts index 4bde81f7d8..0e0c10bed0 100644 --- a/styles/src/styleTree/commandPalette.ts +++ b/styles/src/styleTree/commandPalette.ts @@ -3,7 +3,7 @@ import { withOpacity } from "../utils/color"; import { text, background } from "./components"; export default function commandPalette(colorScheme: ColorScheme) { - let layer = colorScheme.highest.top; + let layer = colorScheme.highest; return { keystrokeSpacing: 8, key: { diff --git a/styles/src/styleTree/contactFinder.ts b/styles/src/styleTree/contactFinder.ts index 4ed49ef26c..c389c126a3 100644 --- a/styles/src/styleTree/contactFinder.ts +++ b/styles/src/styleTree/contactFinder.ts @@ -3,7 +3,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, foreground, text } from "./components"; export default function contactFinder(colorScheme: ColorScheme) { - let layer = colorScheme.highest.top; + let layer = colorScheme.highest; const sideMargin = 6; const contactButton = { diff --git a/styles/src/styleTree/contactList.ts b/styles/src/styleTree/contactList.ts index 42f6ce884e..a58bf90fd1 100644 --- a/styles/src/styleTree/contactList.ts +++ b/styles/src/styleTree/contactList.ts @@ -11,7 +11,7 @@ export default function contactsPanel(colorScheme: ColorScheme) { const nameMargin = 8; const sidePadding = 12; - let layer = colorScheme.lowest.middle; + let layer = colorScheme.middle; const contactButton = { background: background(layer, "on"), diff --git a/styles/src/styleTree/contactNotification.ts b/styles/src/styleTree/contactNotification.ts index 0908d8035d..e0b967203d 100644 --- a/styles/src/styleTree/contactNotification.ts +++ b/styles/src/styleTree/contactNotification.ts @@ -5,7 +5,7 @@ const avatarSize = 12; const headerPadding = 8; export default function contactNotification(colorScheme: ColorScheme): Object { - let layer = colorScheme.middle.bottom; + let layer = colorScheme.lowest; return { headerAvatar: { height: avatarSize, diff --git a/styles/src/styleTree/contactsPopover.ts b/styles/src/styleTree/contactsPopover.ts index be792a1981..50a8251737 100644 --- a/styles/src/styleTree/contactsPopover.ts +++ b/styles/src/styleTree/contactsPopover.ts @@ -2,14 +2,14 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function contactsPopover(colorScheme: ColorScheme) { - let layer = colorScheme.middle.middle; + let layer = colorScheme.middle; const sidePadding = 12; return { background: background(layer), cornerRadius: 6, padding: { top: 6 }, margin: { top: -6 }, - shadow: colorScheme.middle.shadow, + shadow: colorScheme.popoverShadow, border: border(layer), width: 300, height: 400, diff --git a/styles/src/styleTree/contextMenu.ts b/styles/src/styleTree/contextMenu.ts index fcdf855e56..440ef5b439 100644 --- a/styles/src/styleTree/contextMenu.ts +++ b/styles/src/styleTree/contextMenu.ts @@ -2,13 +2,12 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, borderColor, text } from "./components"; export default function contextMenu(colorScheme: ColorScheme) { - let elevation = colorScheme.middle; - let layer = elevation.bottom; + let layer = colorScheme.lowest; return { background: background(layer), cornerRadius: 10, padding: 4, - shadow: elevation.shadow, + shadow: colorScheme.popoverShadow, border: border(layer), keystrokeMargin: 30, item: { diff --git a/styles/src/styleTree/editor.ts b/styles/src/styleTree/editor.ts index dd6c5bead7..3b961b7dc0 100644 --- a/styles/src/styleTree/editor.ts +++ b/styles/src/styleTree/editor.ts @@ -15,8 +15,7 @@ import { import hoverPopover from "./hoverPopover"; export default function editor(colorScheme: ColorScheme) { - let elevation = colorScheme.lowest; - let layer = elevation.top; + let layer = colorScheme.highest; const autocompleteItem = { cornerRadius: 6, @@ -48,88 +47,88 @@ export default function editor(colorScheme: ColorScheme) { const syntax = { primary: { - color: elevation.ramps.neutral(1).hex(), + color: colorScheme.ramps.neutral(1).hex(), weight: fontWeights.normal, }, comment: { - color: elevation.ramps.neutral(0.71).hex(), + color: colorScheme.ramps.neutral(0.71).hex(), weight: fontWeights.normal, }, punctuation: { - color: elevation.ramps.neutral(0.86).hex(), + color: colorScheme.ramps.neutral(0.86).hex(), weight: fontWeights.normal, }, constant: { - color: elevation.ramps.green(0.5).hex(), + color: colorScheme.ramps.green(0.5).hex(), weight: fontWeights.normal, }, keyword: { - color: elevation.ramps.blue(0.5).hex(), + color: colorScheme.ramps.blue(0.5).hex(), weight: fontWeights.normal, }, function: { - color: elevation.ramps.yellow(0.5).hex(), + color: colorScheme.ramps.yellow(0.5).hex(), weight: fontWeights.normal, }, type: { - color: elevation.ramps.cyan(0.5).hex(), + color: colorScheme.ramps.cyan(0.5).hex(), weight: fontWeights.normal, }, constructor: { - color: elevation.ramps.blue(0.5).hex(), + color: colorScheme.ramps.blue(0.5).hex(), weight: fontWeights.normal, }, variant: { - color: elevation.ramps.blue(0.5).hex(), + color: colorScheme.ramps.blue(0.5).hex(), weight: fontWeights.normal, }, property: { - color: elevation.ramps.blue(0.5).hex(), + color: colorScheme.ramps.blue(0.5).hex(), weight: fontWeights.normal, }, enum: { - color: elevation.ramps.orange(0.5).hex(), + color: colorScheme.ramps.orange(0.5).hex(), weight: fontWeights.normal, }, operator: { - color: elevation.ramps.orange(0.5).hex(), + color: colorScheme.ramps.orange(0.5).hex(), weight: fontWeights.normal, }, string: { - color: elevation.ramps.orange(0.5).hex(), + color: colorScheme.ramps.orange(0.5).hex(), weight: fontWeights.normal, }, number: { - color: elevation.ramps.green(0.5).hex(), + color: colorScheme.ramps.green(0.5).hex(), weight: fontWeights.normal, }, boolean: { - color: elevation.ramps.green(0.5).hex(), + color: colorScheme.ramps.green(0.5).hex(), weight: fontWeights.normal, }, predictive: { - color: elevation.ramps.neutral(0.57).hex(), + color: colorScheme.ramps.neutral(0.57).hex(), weight: fontWeights.normal, }, title: { - color: elevation.ramps.yellow(0.5).hex(), + color: colorScheme.ramps.yellow(0.5).hex(), weight: fontWeights.bold, }, emphasis: { - color: elevation.ramps.blue(0.5).hex(), + color: colorScheme.ramps.blue(0.5).hex(), weight: fontWeights.normal, }, "emphasis.strong": { - color: elevation.ramps.blue(0.5).hex(), + color: colorScheme.ramps.blue(0.5).hex(), weight: fontWeights.bold, }, linkUri: { - color: elevation.ramps.green(0.5).hex(), + color: colorScheme.ramps.green(0.5).hex(), weight: fontWeights.normal, underline: true, }, linkText: { - color: elevation.ramps.orange(0.5).hex(), + color: colorScheme.ramps.orange(0.5).hex(), weight: fontWeights.normal, italic: true, }, @@ -152,11 +151,11 @@ export default function editor(colorScheme: ColorScheme) { widthEm: 0.16, cornerRadius: 0.05, }, - documentHighlightReadBackground: elevation.ramps + documentHighlightReadBackground: colorScheme.ramps .neutral(0.5) .alpha(0.2) .hex(), // TODO: This was blend - documentHighlightWriteBackground: elevation.ramps + documentHighlightWriteBackground: colorScheme.ramps .neutral(0.5) .alpha(0.4) .hex(), // TODO: This was blend * 2 @@ -178,67 +177,69 @@ export default function editor(colorScheme: ColorScheme) { colorScheme.players[7], ], autocomplete: { - background: background(elevation.bottom), + background: background(colorScheme.lowest), cornerRadius: 8, padding: 4, margin: { left: -14, }, - border: border(elevation.bottom), - shadow: elevation.above.shadow, - matchHighlight: elevation.above.ramps.blue(0.5).hex(), + border: border(colorScheme.lowest), + shadow: colorScheme.popoverShadow, + matchHighlight: foreground(colorScheme.lowest, "accent"), item: autocompleteItem, hoveredItem: { ...autocompleteItem, - background: background(elevation.bottom, "hovered"), + matchHighlight: foreground(colorScheme.lowest, "accent", "hovered"), + background: background(colorScheme.lowest, "hovered"), }, selectedItem: { ...autocompleteItem, - background: background(elevation.bottom, "active"), + matchHighlight: foreground(colorScheme.lowest, "accent", "active"), + background: background(colorScheme.lowest, "active"), }, }, diagnosticHeader: { - background: background(elevation.middle), + background: background(colorScheme.middle), iconWidthFactor: 1.5, textScaleFactor: 0.857, - border: border(elevation.middle, { + border: border(colorScheme.middle, { bottom: true, top: true, }), code: { - ...text(elevation.middle, "mono", { size: "sm" }), + ...text(colorScheme.middle, "mono", { size: "sm" }), margin: { left: 10, }, }, message: { - highlightText: text(elevation.middle, "sans", { + highlightText: text(colorScheme.middle, "sans", { size: "sm", weight: "bold", }), - text: text(elevation.middle, "sans", { size: "sm" }), + text: text(colorScheme.middle, "sans", { size: "sm" }), }, }, diagnosticPathHeader: { - background: background(elevation.middle), + background: background(colorScheme.middle), textScaleFactor: 0.857, - filename: text(elevation.middle, "mono", { size: "sm" }), + filename: text(colorScheme.middle, "mono", { size: "sm" }), path: { - ...text(elevation.middle, "mono", { size: "sm" }), + ...text(colorScheme.middle, "mono", { size: "sm" }), margin: { left: 12, }, }, }, - errorDiagnostic: diagnostic(elevation.middle, "negative"), - warningDiagnostic: diagnostic(elevation.middle, "warning"), - informationDiagnostic: diagnostic(elevation.middle, "accent"), - hintDiagnostic: diagnostic(elevation.middle, "warning"), - invalidErrorDiagnostic: diagnostic(elevation.middle, "base"), - invalidHintDiagnostic: diagnostic(elevation.middle, "base"), - invalidInformationDiagnostic: diagnostic(elevation.middle, "base"), - invalidWarningDiagnostic: diagnostic(elevation.middle, "base"), - hoverPopover: hoverPopover(elevation.above), + errorDiagnostic: diagnostic(colorScheme.middle, "negative"), + warningDiagnostic: diagnostic(colorScheme.middle, "warning"), + informationDiagnostic: diagnostic(colorScheme.middle, "accent"), + hintDiagnostic: diagnostic(colorScheme.middle, "warning"), + invalidErrorDiagnostic: diagnostic(colorScheme.middle, "base"), + invalidHintDiagnostic: diagnostic(colorScheme.middle, "base"), + invalidInformationDiagnostic: diagnostic(colorScheme.middle, "base"), + invalidWarningDiagnostic: diagnostic(colorScheme.middle, "base"), + hoverPopover: hoverPopover(colorScheme), linkDefinition: { color: syntax.linkUri.color, underline: syntax.linkUri.underline, diff --git a/styles/src/styleTree/hoverPopover.ts b/styles/src/styleTree/hoverPopover.ts index 67b619890f..ab4beee11b 100644 --- a/styles/src/styleTree/hoverPopover.ts +++ b/styles/src/styleTree/hoverPopover.ts @@ -1,8 +1,8 @@ -import { Elevation } from "../themes/common/colorScheme"; +import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; -export default function HoverPopover(elevation: Elevation) { - let layer = elevation.middle; +export default function HoverPopover(colorScheme: ColorScheme) { + let layer = colorScheme.middle; let baseContainer = { background: background(layer), cornerRadius: 8, @@ -12,7 +12,7 @@ export default function HoverPopover(elevation: Elevation) { top: 4, bottom: 4, }, - shadow: elevation.shadow, + shadow: colorScheme.popoverShadow, border: border(layer), margin: { left: -8, @@ -40,6 +40,6 @@ export default function HoverPopover(elevation: Elevation) { padding: { top: 4 }, }, prose: text(layer, "sans", { size: "sm" }), - highlight: elevation.ramps.neutral(0.5).alpha(0.2).hex(), // TODO: blend was used here. Replace with something better + highlight: colorScheme.ramps.neutral(0.5).alpha(0.2).hex(), // TODO: blend was used here. Replace with something better }; } diff --git a/styles/src/styleTree/incomingCallNotification.ts b/styles/src/styleTree/incomingCallNotification.ts index f0eb6c3bf5..2540e5e78a 100644 --- a/styles/src/styleTree/incomingCallNotification.ts +++ b/styles/src/styleTree/incomingCallNotification.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function incomingCallNotification(colorScheme: ColorScheme): Object { - let layer = colorScheme.middle.middle; + let layer = colorScheme.middle; const avatarSize = 48; return { windowHeight: 74, diff --git a/styles/src/styleTree/picker.ts b/styles/src/styleTree/picker.ts index 3e126f4f2e..4d0b89a159 100644 --- a/styles/src/styleTree/picker.ts +++ b/styles/src/styleTree/picker.ts @@ -2,12 +2,11 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function picker(colorScheme: ColorScheme) { - let elevation = colorScheme.highest; - let layer = elevation.top; + let layer = colorScheme.highest; return { background: background(layer), border: border(layer), - shadow: elevation.shadow, + shadow: colorScheme.modalShadow, cornerRadius: 12, padding: { bottom: 4, diff --git a/styles/src/styleTree/projectDiagnostics.ts b/styles/src/styleTree/projectDiagnostics.ts index 32127a84c7..c80a5e1052 100644 --- a/styles/src/styleTree/projectDiagnostics.ts +++ b/styles/src/styleTree/projectDiagnostics.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, text } from "./components"; export default function projectDiagnostics(colorScheme: ColorScheme) { - let layer = colorScheme.lowest.top; + let layer = colorScheme.highest; return { background: background(layer), tabIconSpacing: 4, diff --git a/styles/src/styleTree/projectPanel.ts b/styles/src/styleTree/projectPanel.ts index e90fd05598..9b906c893f 100644 --- a/styles/src/styleTree/projectPanel.ts +++ b/styles/src/styleTree/projectPanel.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, foreground, text } from "./components"; export default function projectPanel(colorScheme: ColorScheme) { - let layer = colorScheme.lowest.middle; + let layer = colorScheme.middle; return { background: background(layer), padding: { left: 12, right: 12, top: 6, bottom: 6 }, diff --git a/styles/src/styleTree/projectSharedNotification.ts b/styles/src/styleTree/projectSharedNotification.ts index 4c40544c03..05542ca20c 100644 --- a/styles/src/styleTree/projectSharedNotification.ts +++ b/styles/src/styleTree/projectSharedNotification.ts @@ -2,14 +2,13 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function projectSharedNotification(colorScheme: ColorScheme): Object { - let elevation = colorScheme.middle; - let layer = elevation.middle; + let layer = colorScheme.middle; const avatarSize = 48; return { windowHeight: 74, windowWidth: 380, - background: background(layer,), + background: background(layer), ownerContainer: { padding: 12, }, diff --git a/styles/src/styleTree/search.ts b/styles/src/styleTree/search.ts index a9a8a18821..b494c237cc 100644 --- a/styles/src/styleTree/search.ts +++ b/styles/src/styleTree/search.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function search(colorScheme: ColorScheme) { - let layer = colorScheme.lowest.top; + let layer = colorScheme.highest; // Search input const editor = { diff --git a/styles/src/styleTree/statusBar.ts b/styles/src/styleTree/statusBar.ts index 7af530b273..bd9a9e2f00 100644 --- a/styles/src/styleTree/statusBar.ts +++ b/styles/src/styleTree/statusBar.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, foreground, text } from "./components"; export default function statusBar(colorScheme: ColorScheme) { - let layer = colorScheme.lowest.bottom; + let layer = colorScheme.lowest; const statusContainer = { cornerRadius: 6, diff --git a/styles/src/styleTree/tabBar.ts b/styles/src/styleTree/tabBar.ts index 01ea3b3dd7..bd6070e0ed 100644 --- a/styles/src/styleTree/tabBar.ts +++ b/styles/src/styleTree/tabBar.ts @@ -5,9 +5,8 @@ import { text, border, background, foreground } from "./components"; export default function tabBar(colorScheme: ColorScheme) { const height = 32; - let elevation = colorScheme.lowest; - let activeLayer = elevation.top; - let layer = elevation.middle; + let activeLayer = colorScheme.highest; + let layer = colorScheme.middle; const tab = { height, @@ -70,7 +69,7 @@ export default function tabBar(colorScheme: ColorScheme) { ...activePaneActiveTab, background: withOpacity(tab.background, 0.95), border: undefined as any, - shadow: elevation.above.shadow, + shadow: colorScheme.popoverShadow, }; return { diff --git a/styles/src/styleTree/terminal.ts b/styles/src/styleTree/terminal.ts index a32a976fbf..2f5c34e5b8 100644 --- a/styles/src/styleTree/terminal.ts +++ b/styles/src/styleTree/terminal.ts @@ -1,6 +1,6 @@ -import { Elevation } from "../themes/common/colorScheme"; +import { ColorScheme } from "../themes/common/colorScheme"; -export default function terminal(elevation: Elevation, cursor_color: string) { +export default function terminal(colorScheme: ColorScheme) { /** * Colors are controlled per-cell in the terminal grid. * Cells can be set to any of these more 'theme-capable' colors @@ -9,44 +9,44 @@ export default function terminal(elevation: Elevation, cursor_color: string) { * https://en.wikipedia.org/wiki/ANSI_escape_code#Colors */ return { - black: elevation.ramps.neutral(0).hex(), - red: elevation.ramps.red(0.5).hex(), - green: elevation.ramps.green(0.5).hex(), - yellow: elevation.ramps.yellow(0.5).hex(), - blue: elevation.ramps.blue(0.5).hex(), - magenta: elevation.ramps.magenta(0.5).hex(), - cyan: elevation.ramps.cyan(0.5).hex(), - white: elevation.ramps.neutral(1).hex(), - brightBlack: elevation.ramps.neutral(0.4).hex(), - brightRed: elevation.ramps.red(0.25).hex(), - brightGreen: elevation.ramps.green(0.25).hex(), - brightYellow: elevation.ramps.yellow(0.25).hex(), - brightBlue: elevation.ramps.blue(0.25).hex(), - brightMagenta: elevation.ramps.magenta(0.25).hex(), - brightCyan: elevation.ramps.cyan(0.25).hex(), - brightWhite: elevation.ramps.neutral(1).hex(), + black: colorScheme.ramps.neutral(0).hex(), + red: colorScheme.ramps.red(0.5).hex(), + green: colorScheme.ramps.green(0.5).hex(), + yellow: colorScheme.ramps.yellow(0.5).hex(), + blue: colorScheme.ramps.blue(0.5).hex(), + magenta: colorScheme.ramps.magenta(0.5).hex(), + cyan: colorScheme.ramps.cyan(0.5).hex(), + white: colorScheme.ramps.neutral(1).hex(), + brightBlack: colorScheme.ramps.neutral(0.4).hex(), + brightRed: colorScheme.ramps.red(0.25).hex(), + brightGreen: colorScheme.ramps.green(0.25).hex(), + brightYellow: colorScheme.ramps.yellow(0.25).hex(), + brightBlue: colorScheme.ramps.blue(0.25).hex(), + brightMagenta: colorScheme.ramps.magenta(0.25).hex(), + brightCyan: colorScheme.ramps.cyan(0.25).hex(), + brightWhite: colorScheme.ramps.neutral(1).hex(), /** * Default color for characters */ - foreground: elevation.ramps.neutral(1).hex(), + foreground: colorScheme.ramps.neutral(1).hex(), /** * Default color for the rectangle background of a cell */ - background: elevation.ramps.neutral(0).hex(), - modalBackground: elevation.ramps.neutral(0.1).hex(), + background: colorScheme.ramps.neutral(0).hex(), + modalBackground: colorScheme.ramps.neutral(0.1).hex(), /** * Default color for the cursor */ - cursor: cursor_color, - dimBlack: elevation.ramps.neutral(1).hex(), - dimRed: elevation.ramps.red(0.75).hex(), - dimGreen: elevation.ramps.green(0.75).hex(), - dimYellow: elevation.ramps.yellow(0.75).hex(), - dimBlue: elevation.ramps.blue(0.75).hex(), - dimMagenta: elevation.ramps.magenta(0.75).hex(), - dimCyan: elevation.ramps.cyan(0.75).hex(), - dimWhite: elevation.ramps.neutral(0.6).hex(), - brightForeground: elevation.ramps.neutral(1).hex(), - dimForeground: elevation.ramps.neutral(0).hex(), + cursor: colorScheme.players[0].cursor, + dimBlack: colorScheme.ramps.neutral(1).hex(), + dimRed: colorScheme.ramps.red(0.75).hex(), + dimGreen: colorScheme.ramps.green(0.75).hex(), + dimYellow: colorScheme.ramps.yellow(0.75).hex(), + dimBlue: colorScheme.ramps.blue(0.75).hex(), + dimMagenta: colorScheme.ramps.magenta(0.75).hex(), + dimCyan: colorScheme.ramps.cyan(0.75).hex(), + dimWhite: colorScheme.ramps.neutral(0.6).hex(), + brightForeground: colorScheme.ramps.neutral(1).hex(), + dimForeground: colorScheme.ramps.neutral(0).hex(), }; } diff --git a/styles/src/styleTree/tooltip.ts b/styles/src/styleTree/tooltip.ts index c6551f02fa..5a43b1ef4c 100644 --- a/styles/src/styleTree/tooltip.ts +++ b/styles/src/styleTree/tooltip.ts @@ -2,14 +2,13 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function tooltip(colorScheme: ColorScheme) { - let elevation = colorScheme.middle; - let layer = colorScheme.middle.middle; + let layer = colorScheme.middle; return { background: background(layer), border: border(layer), padding: { top: 4, bottom: 4, left: 8, right: 8 }, margin: { top: 6, left: 6 }, - shadow: elevation.shadow, + shadow: colorScheme.popoverShadow, cornerRadius: 6, text: text(layer, "sans", { size: "xs" }), keystroke: { diff --git a/styles/src/styleTree/updateNotification.ts b/styles/src/styleTree/updateNotification.ts index d0922a4756..08c0b08430 100644 --- a/styles/src/styleTree/updateNotification.ts +++ b/styles/src/styleTree/updateNotification.ts @@ -4,7 +4,7 @@ import { foreground, text } from "./components"; const headerPadding = 8; export default function updateNotification(colorScheme: ColorScheme): Object { - let layer = colorScheme.middle.middle; + let layer = colorScheme.middle; return { message: { ...text(layer, "sans", { size: "xs" }), diff --git a/styles/src/styleTree/workspace.ts b/styles/src/styleTree/workspace.ts index 9641e3f92f..4b5ee4d0de 100644 --- a/styles/src/styleTree/workspace.ts +++ b/styles/src/styleTree/workspace.ts @@ -11,8 +11,7 @@ import statusBar from "./statusBar"; import tabBar from "./tabBar"; export default function workspace(colorScheme: ColorScheme) { - const elevation = colorScheme.lowest; - const layer = elevation.bottom; + const layer = colorScheme.lowest; const titlebarPadding = 6; const titlebarButton = { cornerRadius: 6, @@ -28,7 +27,7 @@ export default function workspace(colorScheme: ColorScheme) { hover: { ...text(layer, "sans", "hovered", { size: "xs" }), background: background(layer, "hovered"), - border: border(elevation.top, "hovered"), + border: border(layer, "hovered"), }, }; const avatarWidth = 18; @@ -44,12 +43,12 @@ export default function workspace(colorScheme: ColorScheme) { ...text(layer, "sans", { size: "lg" }), }, externalLocationMessage: { - background: background(elevation.middle, "accent"), - border: border(elevation.middle, "accent"), + background: background(colorScheme.middle, "accent"), + border: border(colorScheme.middle, "accent"), cornerRadius: 6, padding: 12, margin: { bottom: 8, right: 8 }, - ...text(elevation.middle, "sans", "accent", { size: "xs" }), + ...text(colorScheme.middle, "sans", "accent", { size: "xs" }), }, leaderBorderOpacity: 0.7, leaderBorderWidth: 2.0, @@ -166,20 +165,20 @@ export default function workspace(colorScheme: ColorScheme) { toolbar: { height: 34, - background: background(elevation.top), - border: border(elevation.top, { bottom: true }), + background: background(colorScheme.highest), + border: border(colorScheme.highest, { bottom: true }), itemSpacing: 8, navButton: { - color: foreground(elevation.top, "on"), + color: foreground(colorScheme.highest, "on"), iconWidth: 12, buttonWidth: 24, cornerRadius: 6, hover: { - color: foreground(elevation.top, "on", "hovered"), - background: background(elevation.top, "on", "hovered"), + color: foreground(colorScheme.highest, "on", "hovered"), + background: background(colorScheme.highest, "on", "hovered"), }, disabled: { - color: foreground(elevation.top, "on", "disabled"), + color: foreground(colorScheme.highest, "on", "disabled"), }, }, padding: { left: 8, right: 8, top: 4, bottom: 4 }, @@ -194,11 +193,11 @@ export default function workspace(colorScheme: ColorScheme) { }, notification: { margin: { top: 10 }, - background: background(elevation.above.middle), + background: background(colorScheme.middle), cornerRadius: 6, padding: 12, - border: border(elevation.above.middle), - shadow: elevation.above.shadow, + border: border(colorScheme.middle), + shadow: colorScheme.popoverShadow, }, notifications: { width: 400, @@ -207,14 +206,14 @@ export default function workspace(colorScheme: ColorScheme) { dock: { initialSizeRight: 640, initialSizeBottom: 480, - wash_color: withOpacity(background(elevation.top), 0.5), + wash_color: withOpacity(background(colorScheme.highest), 0.5), panel: { - border: border(elevation.top), + border: border(colorScheme.highest), }, maximized: { margin: 32, - border: border(elevation.above.top, { overlay: true }), - shadow: elevation.above.shadow, + border: border(colorScheme.highest, { overlay: true }), + shadow: colorScheme.modalShadow, }, }, }; diff --git a/styles/src/themes/common/colorScheme.ts b/styles/src/themes/common/colorScheme.ts index c0118a67c3..1b2c2cf7e8 100644 --- a/styles/src/themes/common/colorScheme.ts +++ b/styles/src/themes/common/colorScheme.ts @@ -4,9 +4,14 @@ export interface ColorScheme { name: string; isLight: boolean; - lowest: Elevation; - middle: Elevation; - highest: Elevation; + lowest: Layer; + middle: Layer; + highest: Layer; + + ramps: RampSet; + + popoverShadow: Shadow; + modalShadow: Shadow; players: Players; } @@ -27,17 +32,6 @@ export interface Players { "7": Player; } -export interface Elevation { - ramps: RampSet; - - bottom: Layer; - middle: Layer; - top: Layer; - - above?: Elevation; - shadow?: Shadow; -} - export interface Shadow { blur: number; color: string; diff --git a/styles/src/themes/common/ramps.ts b/styles/src/themes/common/ramps.ts index cb8f3c3dce..81b94bdb84 100644 --- a/styles/src/themes/common/ramps.ts +++ b/styles/src/themes/common/ramps.ts @@ -1,11 +1,9 @@ import chroma, { Color, Scale } from "chroma-js"; import { ColorScheme, - Elevation, Layer, Player, RampSet, - Shadow, Style, Styles, StyleSet, @@ -23,7 +21,7 @@ export function createColorScheme( colorRamps: { [rampName: string]: Scale } ): ColorScheme { // Chromajs scales from 0 to 1 flipped if isLight is true - let baseRamps: typeof colorRamps = {}; + let ramps: RampSet = {} as any; // Chromajs mutates the underlying ramp when you call domain. This causes problems because // we now store the ramps object in the theme so that we can pull colors out of them. @@ -33,73 +31,66 @@ export function createColorScheme( // function to any in order to get the colors back out from the original ramps. if (isLight) { for (var rampName in colorRamps) { - baseRamps[rampName] = chroma.scale( + (ramps as any)[rampName] = chroma.scale( colorRamps[rampName].colors(100).reverse() ); } - baseRamps.neutral = chroma.scale(colorRamps.neutral.colors(100).reverse()); + ramps.neutral = chroma.scale(colorRamps.neutral.colors(100).reverse()); } else { for (var rampName in colorRamps) { - baseRamps[rampName] = chroma.scale(colorRamps[rampName].colors(100)); + (ramps as any)[rampName] = chroma.scale(colorRamps[rampName].colors(100)); } - baseRamps.neutral = chroma.scale(colorRamps.neutral.colors(100)); + ramps.neutral = chroma.scale(colorRamps.neutral.colors(100)); } - let baseSet = { - neutral: baseRamps.neutral, - red: baseRamps.red, - orange: baseRamps.orange, - yellow: baseRamps.yellow, - green: baseRamps.green, - cyan: baseRamps.cyan, - blue: baseRamps.blue, - violet: baseRamps.violet, - magenta: baseRamps.magenta, - }; + let lowest = lowestLayer(ramps); + let middle = middleLayer(ramps); + let highest = highestLayer(ramps); - let lowest = elevation(resampleSet(baseSet, evenSamples(0, 1))); - - let middle = elevation(resampleSet(baseSet, evenSamples(0.08, 1)), { + let popoverShadow = { blur: 4, - color: baseSet + color: ramps .neutral(isLight ? 7 : 0) .darken() .alpha(0.2) .hex(), // TODO used blend previously. Replace with something else offset: [1, 2], - }); - lowest.above = middle; + }; - let highest = elevation(resampleSet(baseSet, evenSamples(0.16, 1)), { + let modalShadow = { blur: 16, - color: baseSet + color: ramps .neutral(isLight ? 7 : 0) .darken() .alpha(0.2) .hex(), // TODO used blend previously. Replace with something else offset: [0, 2], - }); - middle.above = highest; + }; let players = { - "0": player(baseSet.blue), - "1": player(baseSet.green), - "2": player(baseSet.magenta), - "3": player(baseSet.orange), - "4": player(baseSet.violet), - "5": player(baseSet.cyan), - "6": player(baseSet.red), - "7": player(baseSet.yellow), + "0": player(ramps.blue), + "1": player(ramps.green), + "2": player(ramps.magenta), + "3": player(ramps.orange), + "4": player(ramps.violet), + "5": player(ramps.cyan), + "6": player(ramps.red), + "7": player(ramps.yellow), }; return { name, isLight, + ramps, + lowest, middle, highest, + popoverShadow, + modalShadow, + players, }; } @@ -111,47 +102,7 @@ function player(ramp: Scale): Player { }; } -function evenSamples(min: number, max: number): number[] { - return Array.from(Array(101).keys()).map( - (i) => (i / 100) * (max - min) + min - ); -} - -function resampleSet(ramps: RampSet, samples: number[]): RampSet { - return { - neutral: resample(ramps.neutral, samples), - red: resample(ramps.red, samples), - orange: resample(ramps.orange, samples), - yellow: resample(ramps.yellow, samples), - green: resample(ramps.green, samples), - cyan: resample(ramps.cyan, samples), - blue: resample(ramps.blue, samples), - violet: resample(ramps.violet, samples), - magenta: resample(ramps.magenta, samples), - }; -} - -function resample(scale: Scale, samples: number[]): Scale { - let newColors = samples.map((sample) => scale(sample)); - return chroma.scale(newColors); -} - -function elevation( - ramps: RampSet, - shadow?: Shadow -): Elevation { - return { - ramps, - - bottom: bottomLayer(ramps), - middle: middleLayer(ramps), - top: topLayer(ramps), - - shadow, - }; -} - -function bottomLayer(ramps: RampSet): Layer { +function lowestLayer(ramps: RampSet): Layer { return { base: buildStyleSet(ramps.neutral, 0.2, 1), variant: buildStyleSet(ramps.neutral, 0.2, 0.7), @@ -175,7 +126,7 @@ function middleLayer(ramps: RampSet): Layer { }; } -function topLayer(ramps: RampSet): Layer { +function highestLayer(ramps: RampSet): Layer { return { base: buildStyleSet(ramps.neutral, 0, 1), variant: buildStyleSet(ramps.neutral, 0, 0.7), From caec9c1f450f82c239ca88d7304b93ad94184440 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Wed, 19 Oct 2022 13:13:50 -0700 Subject: [PATCH 51/55] fixed issue in testbench --- crates/theme_testbench/src/theme_testbench.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/theme_testbench/src/theme_testbench.rs b/crates/theme_testbench/src/theme_testbench.rs index ac78cce1c9..17b6248671 100644 --- a/crates/theme_testbench/src/theme_testbench.rs +++ b/crates/theme_testbench/src/theme_testbench.rs @@ -268,7 +268,7 @@ impl View for ThemeTestbench { Self::render_ramps(color_scheme) .contained() .with_margin_right(10.) - .flex(0.2, false) + .flex(0.1, false) .boxed(), ) .with_child( @@ -288,6 +288,7 @@ impl View for ThemeTestbench { .flex(1., true) .boxed(), ) + .flex(1., false) .boxed(), ) .boxed() From 83e4e269896e84c43f64e523f02973a4c41f9673 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 19 Oct 2022 13:27:14 -0700 Subject: [PATCH 52/55] Allow setting ZED_SERVER_URL to URL of a collab server --- crates/client/src/client.rs | 82 ++++++++++++++++++++----------------- crates/collab/src/auth.rs | 11 ++--- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 9cfccba37f..64075472cd 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -926,29 +926,34 @@ impl Client { } async fn get_rpc_url(http: Arc) -> Result { - let rpc_response = http - .get( - &(format!("{}/rpc", *ZED_SERVER_URL)), - Default::default(), - false, - ) - .await?; - if !rpc_response.status().is_redirection() { + let url = format!("{}/rpc", *ZED_SERVER_URL); + let response = http.get(&url, Default::default(), false).await?; + + // Normally, ZED_SERVER_URL is set to the URL of zed.dev website. + // The website's /rpc endpoint redirects to a collab server's /rpc endpoint, + // which requires authorization via an HTTP header. + // + // For testing purposes, ZED_SERVER_URL can also set to the direct URL of + // of a collab server. In that case, a request to the /rpc endpoint will + // return an 'unauthorized' response. + let collab_url = if response.status().is_redirection() { + response + .headers() + .get("Location") + .ok_or_else(|| anyhow!("missing location header in /rpc response"))? + .to_str() + .map_err(EstablishConnectionError::other)? + .to_string() + } else if response.status() == StatusCode::UNAUTHORIZED { + url + } else { Err(anyhow!( "unexpected /rpc response status {}", - rpc_response.status() + response.status() ))? - } + }; - let rpc_url = rpc_response - .headers() - .get("Location") - .ok_or_else(|| anyhow!("missing location header in /rpc response"))? - .to_str() - .map_err(EstablishConnectionError::other)? - .to_string(); - - Url::parse(&rpc_url).context("invalid rpc url") + Url::parse(&collab_url).context("invalid rpc url") } fn establish_websocket_connection( @@ -1105,25 +1110,6 @@ impl Client { login: String, mut api_token: String, ) -> Result { - let mut url = Self::get_rpc_url(http.clone()).await?; - url.set_path("/user"); - url.set_query(Some(&format!("github_login={login}"))); - let request = Request::get(url.as_str()) - .header("Authorization", format!("token {api_token}")) - .body("".into())?; - - let mut response = http.send(request).await?; - let mut body = String::new(); - response.body_mut().read_to_string(&mut body).await?; - - if !response.status().is_success() { - Err(anyhow!( - "admin user request failed {} - {}", - response.status().as_u16(), - body, - ))?; - } - #[derive(Deserialize)] struct AuthenticatedUserResponse { user: User, @@ -1134,8 +1120,28 @@ impl Client { id: u64, } + // Use the collab server's admin API to retrieve the id + // of the impersonated user. + let mut url = Self::get_rpc_url(http.clone()).await?; + url.set_path("/user"); + url.set_query(Some(&format!("github_login={login}"))); + let request = Request::get(url.as_str()) + .header("Authorization", format!("token {api_token}")) + .body("".into())?; + + let mut response = http.send(request).await?; + let mut body = String::new(); + response.body_mut().read_to_string(&mut body).await?; + if !response.status().is_success() { + Err(anyhow!( + "admin user request failed {} - {}", + response.status().as_u16(), + body, + ))?; + } let response: AuthenticatedUserResponse = serde_json::from_str(&body)?; + // Use the admin API token to authenticate as the impersonated user. api_token.insert_str(0, "ADMIN_TOKEN:"); Ok(Credentials { user_id: response.user.id, diff --git a/crates/collab/src/auth.rs b/crates/collab/src/auth.rs index e9e2855f1c..9081fe1f1e 100644 --- a/crates/collab/src/auth.rs +++ b/crates/collab/src/auth.rs @@ -1,7 +1,7 @@ -use std::sync::Arc; - -use super::db::{self, UserId}; -use crate::{AppState, Error, Result}; +use crate::{ + db::{self, UserId}, + AppState, Error, Result, +}; use anyhow::{anyhow, Context}; use axum::{ http::{self, Request, StatusCode}, @@ -13,6 +13,7 @@ use scrypt::{ password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString}, Scrypt, }; +use std::sync::Arc; pub async fn validate_header(mut req: Request, next: Next) -> impl IntoResponse { let mut auth_header = req @@ -21,7 +22,7 @@ pub async fn validate_header(mut req: Request, next: Next) -> impl Into .and_then(|header| header.to_str().ok()) .ok_or_else(|| { Error::Http( - StatusCode::BAD_REQUEST, + StatusCode::UNAUTHORIZED, "missing authorization header".to_string(), ) })? From b7c439f4c44db03eaff27906b1526d442ff78516 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Wed, 19 Oct 2022 13:39:46 -0700 Subject: [PATCH 53/55] Fixup some theme inconsistencies and incorrect layer selections --- styles/src/styleTree/editor.ts | 14 +++++++------- styles/src/styleTree/picker.ts | 2 +- styles/src/styleTree/workspace.ts | 10 +++++----- styles/src/themes/cave.ts | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/styles/src/styleTree/editor.ts b/styles/src/styleTree/editor.ts index 3b961b7dc0..c94b6d81d2 100644 --- a/styles/src/styleTree/editor.ts +++ b/styles/src/styleTree/editor.ts @@ -177,25 +177,25 @@ export default function editor(colorScheme: ColorScheme) { colorScheme.players[7], ], autocomplete: { - background: background(colorScheme.lowest), + background: background(colorScheme.middle), cornerRadius: 8, padding: 4, margin: { left: -14, }, - border: border(colorScheme.lowest), + border: border(colorScheme.middle), shadow: colorScheme.popoverShadow, - matchHighlight: foreground(colorScheme.lowest, "accent"), + matchHighlight: foreground(colorScheme.middle, "accent"), item: autocompleteItem, hoveredItem: { ...autocompleteItem, - matchHighlight: foreground(colorScheme.lowest, "accent", "hovered"), - background: background(colorScheme.lowest, "hovered"), + matchHighlight: foreground(colorScheme.middle, "accent", "hovered"), + background: background(colorScheme.middle, "hovered"), }, selectedItem: { ...autocompleteItem, - matchHighlight: foreground(colorScheme.lowest, "accent", "active"), - background: background(colorScheme.lowest, "active"), + matchHighlight: foreground(colorScheme.middle, "accent", "active"), + background: background(colorScheme.middle, "active"), }, }, diagnosticHeader: { diff --git a/styles/src/styleTree/picker.ts b/styles/src/styleTree/picker.ts index 4d0b89a159..30608eeb9e 100644 --- a/styles/src/styleTree/picker.ts +++ b/styles/src/styleTree/picker.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, text } from "./components"; export default function picker(colorScheme: ColorScheme) { - let layer = colorScheme.highest; + let layer = colorScheme.lowest; return { background: background(layer), border: border(layer), diff --git a/styles/src/styleTree/workspace.ts b/styles/src/styleTree/workspace.ts index 4b5ee4d0de..dc37444159 100644 --- a/styles/src/styleTree/workspace.ts +++ b/styles/src/styleTree/workspace.ts @@ -21,13 +21,13 @@ export default function workspace(colorScheme: ColorScheme) { left: 8, right: 8, }, - ...text(layer, "sans", { size: "xs" }), - background: background(layer), + ...text(layer, "sans", "variant", { size: "xs" }), + background: background(layer, "variant"), border: border(layer), hover: { - ...text(layer, "sans", "hovered", { size: "xs" }), - background: background(layer, "hovered"), - border: border(layer, "hovered"), + ...text(layer, "sans", "variant", "hovered", { size: "xs" }), + background: background(layer, "variant", "hovered"), + border: border(layer, "variant", "hovered"), }, }; const avatarWidth = 18; diff --git a/styles/src/themes/cave.ts b/styles/src/themes/cave.ts index 3914fb03d7..f13b9f028a 100644 --- a/styles/src/themes/cave.ts +++ b/styles/src/themes/cave.ts @@ -15,7 +15,7 @@ export const dark = createColorScheme(`${name}-dark`, false, { "#e2dfe7", "#efecf4", ]) - .domain([0, 0.3, 0.45, 0.6, 0.65, 0.7, 0.85, 1]), + .domain([0, 0.15, 0.45, 0.6, 0.65, 0.7, 0.85, 1]), red: colorRamp(chroma("#be4678")), orange: colorRamp(chroma("#aa573c")), yellow: colorRamp(chroma("#a06e3b")), From 2aa2e5af7a80d6b54cd8e87b33801585b311c0a1 Mon Sep 17 00:00:00 2001 From: K Simmons Date: Wed, 19 Oct 2022 13:45:00 -0700 Subject: [PATCH 54/55] fix issue with text component and adjust layer selections some more --- styles/src/styleTree/components.ts | 3 ++- styles/src/styleTree/contextMenu.ts | 2 +- styles/src/styleTree/workspace.ts | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/styles/src/styleTree/components.ts b/styles/src/styleTree/components.ts index 3062a73130..7776c4f14f 100644 --- a/styles/src/styleTree/components.ts +++ b/styles/src/styleTree/components.ts @@ -123,7 +123,6 @@ export function text( properties?: TextProperties ) { let style = getStyle(layer, styleSetStyleOrProperties, styleOrProperties); - let size = fontSizes[properties?.size || "sm"]; if (typeof styleSetStyleOrProperties === "object") { properties = styleSetStyleOrProperties; @@ -132,6 +131,8 @@ export function text( properties = styleOrProperties; } + let size = fontSizes[properties?.size || "sm"]; + return { family: fontFamilies[fontFamily], color: style.foreground, diff --git a/styles/src/styleTree/contextMenu.ts b/styles/src/styleTree/contextMenu.ts index 440ef5b439..49f3a3b472 100644 --- a/styles/src/styleTree/contextMenu.ts +++ b/styles/src/styleTree/contextMenu.ts @@ -2,7 +2,7 @@ import { ColorScheme } from "../themes/common/colorScheme"; import { background, border, borderColor, text } from "./components"; export default function contextMenu(colorScheme: ColorScheme) { - let layer = colorScheme.lowest; + let layer = colorScheme.middle; return { background: background(layer), cornerRadius: 10, diff --git a/styles/src/styleTree/workspace.ts b/styles/src/styleTree/workspace.ts index dc37444159..aced6d2a2f 100644 --- a/styles/src/styleTree/workspace.ts +++ b/styles/src/styleTree/workspace.ts @@ -139,16 +139,16 @@ export default function workspace(colorScheme: ColorScheme) { }, toggleContactsButton: { cornerRadius: 6, - color: foreground(layer), + color: foreground(layer, "variant"), iconWidth: 8, buttonWidth: 20, active: { - background: background(layer, "active"), - color: foreground(layer, "active"), + background: background(layer, "variant", "active"), + color: foreground(layer, "variant", "active"), }, hover: { - background: background(layer, "hovered"), - color: foreground(layer, "hovered"), + background: background(layer, "variant", "hovered"), + color: foreground(layer, "variant", "hovered"), }, }, toggleContactsBadge: { From 985890646369ef128150ecdcc8a964f588284a0e Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 20 Oct 2022 10:52:34 -0600 Subject: [PATCH 55/55] Return an optional response when creating users via invites If the user already exists, we return none. This will allow the web frontend to avoid reporting a "join alpha" user event but also not error. Co-Authored-By: Max Brunsfeld Co-Authored-By: Joseph Lyons --- crates/collab/src/api.rs | 14 ++++++++++---- crates/collab/src/db.rs | 15 ++++++--------- crates/collab/src/db_tests.rs | 32 +++++++++++++++++++------------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/crates/collab/src/api.rs b/crates/collab/src/api.rs index 5d28fdf668..4f97d93824 100644 --- a/crates/collab/src/api.rs +++ b/crates/collab/src/api.rs @@ -156,7 +156,7 @@ async fn create_user( Json(params): Json, Extension(app): Extension>, Extension(rpc_server): Extension>, -) -> Result> { +) -> Result>> { let user = NewUserParams { github_login: params.github_login, github_user_id: params.github_user_id, @@ -165,7 +165,8 @@ async fn create_user( // Creating a user via the normal signup process let result = if let Some(email_confirmation_code) = params.email_confirmation_code { - app.db + if let Some(result) = app + .db .create_user_from_invite( &Invite { email_address: params.email_address, @@ -174,6 +175,11 @@ async fn create_user( user, ) .await? + { + result + } else { + return Ok(Json(None)); + } } // Creating a user as an admin else if params.admin { @@ -200,11 +206,11 @@ async fn create_user( .await? .ok_or_else(|| anyhow!("couldn't find the user we just created"))?; - Ok(Json(CreateUserResponse { + Ok(Json(Some(CreateUserResponse { user, metrics_id: result.metrics_id, signup_device_id: result.signup_device_id, - })) + }))) } #[derive(Deserialize)] diff --git a/crates/collab/src/db.rs b/crates/collab/src/db.rs index 9b3dca1f2c..b8c09d9afb 100644 --- a/crates/collab/src/db.rs +++ b/crates/collab/src/db.rs @@ -51,7 +51,7 @@ pub trait Db: Send + Sync { &self, invite: &Invite, user: NewUserParams, - ) -> Result; + ) -> Result>; /// Registers a new project for the given user. async fn register_project(&self, host_user_id: UserId) -> Result; @@ -482,7 +482,7 @@ impl Db for PostgresDb { &self, invite: &Invite, user: NewUserParams, - ) -> Result { + ) -> Result> { let mut tx = self.pool.begin().await?; let (signup_id, existing_user_id, inviting_user_id, signup_device_id): ( @@ -506,10 +506,7 @@ impl Db for PostgresDb { .ok_or_else(|| Error::Http(StatusCode::NOT_FOUND, "no such invite".to_string()))?; if existing_user_id.is_some() { - Err(Error::Http( - StatusCode::UNPROCESSABLE_ENTITY, - "invitation already redeemed".to_string(), - ))?; + return Ok(None); } let (user_id, metrics_id): (UserId, String) = sqlx::query_as( @@ -576,12 +573,12 @@ impl Db for PostgresDb { } tx.commit().await?; - Ok(NewUserResult { + Ok(Some(NewUserResult { user_id, metrics_id, inviting_user_id, signup_device_id, - }) + })) } // invite codes @@ -1958,7 +1955,7 @@ mod test { &self, _invite: &Invite, _user: NewUserParams, - ) -> Result { + ) -> Result> { unimplemented!() } diff --git a/crates/collab/src/db_tests.rs b/crates/collab/src/db_tests.rs index d5ef045e66..ff5e05dd5d 100644 --- a/crates/collab/src/db_tests.rs +++ b/crates/collab/src/db_tests.rs @@ -852,6 +852,7 @@ async fn test_invite_codes() { }, ) .await + .unwrap() .unwrap(); let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap(); assert_eq!(invite_count, 1); @@ -897,6 +898,7 @@ async fn test_invite_codes() { }, ) .await + .unwrap() .unwrap(); let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap(); assert_eq!(invite_count, 0); @@ -954,6 +956,7 @@ async fn test_invite_codes() { ) .await .unwrap() + .unwrap() .user_id; let (_, invite_count) = db.get_invite_code_for_user(user1).await.unwrap().unwrap(); @@ -1099,6 +1102,7 @@ async fn test_signups() { }, ) .await + .unwrap() .unwrap(); let user = db.get_user_by_id(user_id).await.unwrap().unwrap(); assert!(inviting_user_id.is_none()); @@ -1108,19 +1112,21 @@ async fn test_signups() { assert_eq!(signup_device_id.unwrap(), "device_id_0"); // cannot redeem the same signup again. - db.create_user_from_invite( - &Invite { - email_address: signups_batch1[0].email_address.clone(), - email_confirmation_code: signups_batch1[0].email_confirmation_code.clone(), - }, - NewUserParams { - github_login: "some-other-github_account".into(), - github_user_id: 1, - invite_count: 5, - }, - ) - .await - .unwrap_err(); + assert!(db + .create_user_from_invite( + &Invite { + email_address: signups_batch1[0].email_address.clone(), + email_confirmation_code: signups_batch1[0].email_confirmation_code.clone(), + }, + NewUserParams { + github_login: "some-other-github_account".into(), + github_user_id: 1, + invite_count: 5, + }, + ) + .await + .unwrap() + .is_none()); // cannot redeem a signup with the wrong confirmation code. db.create_user_from_invite(