From 2eb0983e03e1bb45d500a0264552df488cd89c49 Mon Sep 17 00:00:00 2001 From: DarkSky Date: Sun, 29 Nov 2026 22:32:33 +0900 Subject: [PATCH] feat(editor): align database table, kanban, and calendar views with BlockSuite styling Remove the outer database frame and merge tabs with Filter, Sort, and Group controls. Paint table headers with 1 px hairlines and 100 px checkbox defaults. Paint borderless 260 px kanban lanes with hover-only footer add buttons. Wrap multi-select tags horizontally inside kanban cards. Format calendar titles with full month names and 22 px tinted event bars. --- .../editor/src/database/calendar_edit.rs | 6 +- .../crates/editor/src/database/column_ops.rs | 13 +- .../src/database/filter_sort_bar/mod.rs | 285 ++++++++++++----- blocksuite/crates/editor/src/database/mod.rs | 16 + .../crates/editor/src/database/render.rs | 124 +++++--- .../editor/src/database/render_calendar.rs | 283 ++++++++++------- .../editor/src/database/render_kanban.rs | 195 ++++++++---- .../editor/src/database/render_kanban_card.rs | 224 ++++++++++---- .../editor/src/database/render_table.rs | 118 +++---- .../editor/src/database/render_types.rs | 16 + .../src/bin/bs_harness/db_visual_evidence.rs | 289 ++++++++++++++++++ .../playground/src/bin/bs_harness/main.rs | 21 ++ .../playground/src/database_authoring/mod.rs | 56 ++-- .../src/database_authoring/tests.rs | 2 +- .../tests_kanban_and_richtext.rs | 9 +- .../tests_scalar_edgeless_calendar.rs | 138 ++++++++- 16 files changed, 1352 insertions(+), 443 deletions(-) create mode 100644 blocksuite/crates/playground/src/bin/bs_harness/db_visual_evidence.rs diff --git a/blocksuite/crates/editor/src/database/calendar_edit.rs b/blocksuite/crates/editor/src/database/calendar_edit.rs index f6c8e38c36..8f70ffe00f 100644 --- a/blocksuite/crates/editor/src/database/calendar_edit.rs +++ b/blocksuite/crates/editor/src/database/calendar_edit.rs @@ -72,15 +72,15 @@ pub(super) fn render_calendar_day_controls( if show_plus { prims.push(DatabasePrim::Quad { rect: plus_rect, - fill: Some(ctx.palette.background_secondary), - border: Some(ctx.palette.border), + fill: Some(ctx.palette.brand.opacity(0.12)), + border: None, radius: 4.0, dashed: false, }); prims.push(DatabasePrim::Icon { rect: FlowRect::new(plus_rect.x + 3.0, plus_rect.y + 3.0, 12.0, 12.0), icon: crate::theme::IconPaint::named("PlusIcon"), - color: ctx.palette.icon, + color: ctx.palette.brand, }); } authoring_hits.push(DatabaseAuthoringHit { diff --git a/blocksuite/crates/editor/src/database/column_ops.rs b/blocksuite/crates/editor/src/database/column_ops.rs index 57b1c1a3a8..3fea1f2feb 100644 --- a/blocksuite/crates/editor/src/database/column_ops.rs +++ b/blocksuite/crates/editor/src/database/column_ops.rs @@ -23,8 +23,17 @@ use super::{ /// Default widths for resolved Table view columns. pub(super) const DEFAULT_COLUMN_WIDTH: f32 = 180.0; pub(super) const TITLE_DEFAULT_WIDTH: f32 = 220.0; +pub(super) const CHECKBOX_DEFAULT_WIDTH: f32 = 100.0; pub(super) const MIN_COLUMN_WIDTH: f32 = 65.0; +fn default_width_for_type(col_type: &str) -> f32 { + match col_type { + "title" => TITLE_DEFAULT_WIDTH, + "checkbox" => CHECKBOX_DEFAULT_WIDTH, + _ => DEFAULT_COLUMN_WIDTH, + } +} + /// One visible Table column resolved from `view.columns` and schema fallback. pub(super) struct ResolvedTableCol<'a> { pub id: String, @@ -105,7 +114,7 @@ pub(super) fn resolve_visible_columns<'a>( }; let w = vc .width - .map_or(DEFAULT_COLUMN_WIDTH, |w| (w as f32).max(MIN_COLUMN_WIDTH)); + .map_or_else(|| default_width_for_type(&schema.column_type), |w| (w as f32).max(MIN_COLUMN_WIDTH)); result.push(ResolvedTableCol { id: schema.id.clone(), name: schema.name.clone(), @@ -123,7 +132,7 @@ pub(super) fn resolve_visible_columns<'a>( id: schema.id.clone(), name: schema.name.clone(), col_type: schema.column_type.clone(), - width: DEFAULT_COLUMN_WIDTH, + width: default_width_for_type(&schema.column_type), schema: Some(schema), }); } diff --git a/blocksuite/crates/editor/src/database/filter_sort_bar/mod.rs b/blocksuite/crates/editor/src/database/filter_sort_bar/mod.rs index 43ff6a6bdb..1242faa09c 100644 --- a/blocksuite/crates/editor/src/database/filter_sort_bar/mod.rs +++ b/blocksuite/crates/editor/src/database/filter_sort_bar/mod.rs @@ -42,66 +42,37 @@ fn column_name_for<'a>(view_cols: &'a [DatabaseColumn], col_id: &'a str) -> &'a .map_or(col_id, |c| c.name.as_str()) } -/// Render ONLY the desktop view control bar (`Filter`, `Sort`, `Group by` buttons + active rule -/// chips) inside the block flow. Open dropdown panels render in screen-space `Overlays` so opening -/// a panel never changes the `affine:database` block height. -/// -/// Returns `(next_y, active_panel_trigger_anchor)`. -#[allow(clippy::too_many_arguments)] -pub(super) fn render_view_toolbar( - ctx: &DbRenderCtx<'_>, +fn toolbar_buttons<'a>( + ctx: &DbRenderCtx<'a>, view: &DatabaseView, - start_y: f32, - prims: &mut Vec, - authoring_hits: &mut Vec, -) -> (f32, Option) { - if ctx.mobile_readonly { - return (start_y, None); - } - - let filter_chips = - parse_filter_chips(view.filter.as_ref(), &ctx.data.columns, ctx.offset_at_ms); - let sort_rules = parse_sort_rules(view.sort.as_ref()); - let active_panel = ctx.ui_state.authoring.toolbar_panel; - - let strip_left = 8.0_f32; - let strip_right = (ctx.width - 8.0).max(strip_left + 1.0); - let axis = InlineAxis::new(ctx.direction, ctx.width); - let btn_h = 26.0_f32; - let gap = 6.0_f32; - let mut cursor = strip_left; - let mut y = start_y; - let mut panel_anchor = None; - - let filter_label = if filter_chips.is_empty() { + filter_count: usize, + sort_count: usize, +) -> [(ActiveToolbarPanel, String, bool, DatabaseAuthoringHitKind); 3] { + let filter_label = if filter_count == 0 { "Filter".to_string() } else { - format!("Filter ({})", filter_chips.len()) + format!("Filter ({filter_count})") }; - let sort_label = if sort_rules.is_empty() { + let sort_label = if sort_count == 0 { "Sort".to_string() } else { - format!("Sort ({})", sort_rules.len()) + format!("Sort ({sort_count})") }; let group_label = match &view.group_by { - Some(gb) => format!( - "Group: {}", - column_name_for(&ctx.data.columns, &gb.column_id) - ), + Some(gb) => format!("Group: {}", column_name_for(&ctx.data.columns, &gb.column_id)), None => "Group by".to_string(), }; - - let buttons = [ + [ ( ActiveToolbarPanel::Filter, filter_label, - !filter_chips.is_empty(), + filter_count > 0, DatabaseAuthoringHitKind::ToolbarToggleFilter, ), ( ActiveToolbarPanel::Sort, sort_label, - !sort_rules.is_empty(), + sort_count > 0, DatabaseAuthoringHitKind::ToolbarToggleSort, ), ( @@ -110,48 +81,82 @@ pub(super) fn render_view_toolbar( view.group_by.is_some(), DatabaseAuthoringHitKind::ToolbarToggleGroupBy, ), - ]; + ] +} - for (panel_kind, label, is_active_rule, hit_kind) in buttons { +/// Render right-aligned borderless `Filter` / `Sort` / `Group by` triggers on the same horizontal +/// toolbar row as the desktop view-switcher tabs (`databaseToolbarRowStyles`). +/// +/// Returns `(total_width_used, active_panel_trigger_anchor)`. +pub(super) fn render_inline_toolbar_triggers( + ctx: &DbRenderCtx<'_>, + view: &DatabaseView, + row_y: f32, + row_h: f32, + strip_right: f32, + prims: &mut Vec, + authoring_hits: &mut Vec, +) -> (f32, Option) { + if ctx.mobile_readonly { + return (0.0, None); + } + let filter_chips = + parse_filter_chips(view.filter.as_ref(), &ctx.data.columns, ctx.offset_at_ms); + let sort_rules = parse_sort_rules(view.sort.as_ref()); + let active_panel = ctx.ui_state.authoring.toolbar_panel; + let axis = InlineAxis::new(ctx.direction, ctx.width); + let btn_h = 26.0_f32.min(row_h); + let btn_y = row_y + (row_h - btn_h) * 0.5; + let gap = 4.0_f32; + + let buttons = toolbar_buttons(ctx, view, filter_chips.len(), sort_rules.len()); + let mut measured = Vec::with_capacity(buttons.len()); + let mut total_w = 0.0_f32; + for (idx, (panel_kind, label, is_active_rule, hit_kind)) in buttons.into_iter().enumerate() { let is_open = active_panel == Some(panel_kind); let ink = if is_open || is_active_rule { ctx.palette.brand } else { ctx.palette.text_secondary }; - let style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, ink); + let style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px + 1.0, 500.0, ink); let (_, layout) = ctx.truncate_text(&label, style, 150.0, btn_h); - let btn_w = (layout.content_width().ceil() + 18.0).clamp(56.0, 170.0); - if cursor + btn_w > strip_right && cursor > strip_left { - cursor = strip_left; - y += btn_h + 4.0; + let btn_w = (layout.content_width().ceil() + 14.0).clamp(44.0, 160.0); + if idx > 0 { + total_w += gap; + } + total_w += btn_w; + measured.push((is_open, is_active_rule, hit_kind, layout, btn_w)); + } + + let mut cursor = (strip_right - total_w).max(8.0); + let mut panel_anchor = None; + for (is_open, is_active_rule, hit_kind, layout, btn_w) in measured { + let rect = axis.map_rect(FlowRect::new(cursor, btn_y, btn_w, btn_h)); + let fill = if is_open { + Some(ctx.palette.brand.opacity(0.14)) + } else if is_active_rule { + Some(ctx.palette.brand.opacity(0.08)) + } else { + None + }; + if fill.is_some() { + prims.push(DatabasePrim::Quad { + rect, + fill, + border: None, + radius: 4.0, + dashed: false, + }); } - let rect = axis.map_rect(FlowRect::new(cursor, y, btn_w, btn_h)); - prims.push(DatabasePrim::Quad { - rect, - fill: Some(if is_open { - ctx.palette.brand.opacity(0.14) - } else if is_active_rule { - ctx.palette.brand.opacity(0.08) - } else { - ctx.palette.background_secondary - }), - border: Some(if is_open || is_active_rule { - ctx.palette.brand.opacity(0.6) - } else { - ctx.palette.border - }), - radius: 5.0, - dashed: false, - }); prims.push(DatabasePrim::Text { - x: rect.x + 9.0, + x: rect.x + 7.0, y: rect.y, layout, clip: Some(FlowRect::new( - rect.x + 4.0, + rect.x + 3.0, rect.y, - (rect.w - 8.0).max(1.0), + (rect.w - 6.0).max(1.0), btn_h, )), }); @@ -166,7 +171,40 @@ pub(super) fn render_view_toolbar( cursor += btn_w + gap; } - // Active filter chips (one click removes that exact top-level condition). + (total_w, panel_anchor) +} + +/// Render active Filter / Sort rule chips below the toolbar row when at least one rule exists. +/// Returns `start_y` unchanged when there are no active rules. +pub(super) fn render_active_rule_chips( + ctx: &DbRenderCtx<'_>, + view: &DatabaseView, + start_y: f32, + prims: &mut Vec, + authoring_hits: &mut Vec, +) -> f32 { + if ctx.mobile_readonly { + return start_y; + } + let filter_chips = + parse_filter_chips(view.filter.as_ref(), &ctx.data.columns, ctx.offset_at_ms); + let sort_rules = parse_sort_rules(view.sort.as_ref()); + if filter_chips.is_empty() && sort_rules.is_empty() { + return start_y; + } + let strip_left = 8.0_f32; + let strip_right = (ctx.width - 8.0).max(strip_left + 1.0); + let axis = InlineAxis::new(ctx.direction, ctx.width); + let btn_h = 24.0_f32; + let gap = 6.0_f32; + let mut cursor = strip_left; + let mut y = start_y; + let chip_bg = ctx + .theme + .css_var("--affine-hover-color-filled") + .unwrap_or(ctx.palette.hover); + let chip_border = ctx.palette.border.opacity(0.65); + for chip in &filter_chips { let label = format!("{} ×", chip.label); let style = InlineStyle::new( @@ -184,9 +222,9 @@ pub(super) fn render_view_toolbar( let rect = axis.map_rect(FlowRect::new(cursor, y, chip_w, btn_h)); prims.push(DatabasePrim::Quad { rect, - fill: Some(ctx.palette.hover), - border: Some(ctx.palette.border), - radius: 5.0, + fill: Some(chip_bg), + border: Some(chip_border), + radius: 4.0, dashed: false, }); prims.push(DatabasePrim::Text { @@ -210,7 +248,6 @@ pub(super) fn render_view_toolbar( cursor += chip_w + gap; } - // Active sort chips (click body flips direction, click right × removes). for (idx, rule) in sort_rules.iter().enumerate() { let col_name = column_name_for(&ctx.data.columns, &rule.column_id); let arrow = if rule.desc { "↓" } else { "↑" }; @@ -230,9 +267,9 @@ pub(super) fn render_view_toolbar( let rect = axis.map_rect(FlowRect::new(cursor, y, chip_w, btn_h)); prims.push(DatabasePrim::Quad { rect, - fill: Some(ctx.palette.hover), - border: Some(ctx.palette.border), - radius: 5.0, + fill: Some(chip_bg), + border: Some(chip_border), + radius: 4.0, dashed: false, }); prims.push(DatabasePrim::Text { @@ -246,7 +283,7 @@ pub(super) fn render_view_toolbar( btn_h, )), }); - let rm_rect = FlowRect::new(rect.right() - 20.0, rect.y + 3.0, 18.0, 20.0); + let rm_rect = FlowRect::new(rect.right() - 20.0, rect.y + 2.0, 18.0, 20.0); prims.push(ctx.single_line_clipped( "×", InlineStyle::new( @@ -274,7 +311,95 @@ pub(super) fn render_view_toolbar( cursor += chip_w + gap; } - (y + btn_h + 6.0, panel_anchor) + y + btn_h + 6.0 +} + +/// Render the touch/narrow-viewport view control bar (`Filter`, `Sort`, `Group by` + active chips) +/// on its own wrapping row below the horizontally scrollable view-switcher tab strip. +/// +/// Returns `(next_y, active_panel_trigger_anchor)`. +#[allow(clippy::too_many_arguments)] +pub(super) fn render_view_toolbar( + ctx: &DbRenderCtx<'_>, + view: &DatabaseView, + start_y: f32, + prims: &mut Vec, + authoring_hits: &mut Vec, +) -> (f32, Option) { + if ctx.mobile_readonly { + return (start_y, None); + } + + let filter_chips = + parse_filter_chips(view.filter.as_ref(), &ctx.data.columns, ctx.offset_at_ms); + let sort_rules = parse_sort_rules(view.sort.as_ref()); + let active_panel = ctx.ui_state.authoring.toolbar_panel; + + let strip_left = 8.0_f32; + let strip_right = (ctx.width - 8.0).max(strip_left + 1.0); + let axis = InlineAxis::new(ctx.direction, ctx.width); + let btn_h = 26.0_f32; + let gap = 4.0_f32; + let mut cursor = strip_left; + let mut y = start_y; + let mut panel_anchor = None; + + let buttons = toolbar_buttons(ctx, view, filter_chips.len(), sort_rules.len()); + for (panel_kind, label, is_active_rule, hit_kind) in buttons { + let is_open = active_panel == Some(panel_kind); + let ink = if is_open || is_active_rule { + ctx.palette.brand + } else { + ctx.palette.text_secondary + }; + let style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, ink); + let (_, layout) = ctx.truncate_text(&label, style, 150.0, btn_h); + let btn_w = (layout.content_width().ceil() + 14.0).clamp(44.0, 160.0); + if cursor + btn_w > strip_right && cursor > strip_left { + cursor = strip_left; + y += btn_h + 4.0; + } + let rect = axis.map_rect(FlowRect::new(cursor, y, btn_w, btn_h)); + let fill = if is_open { + Some(ctx.palette.brand.opacity(0.14)) + } else if is_active_rule { + Some(ctx.palette.brand.opacity(0.08)) + } else { + None + }; + if fill.is_some() { + prims.push(DatabasePrim::Quad { + rect, + fill, + border: None, + radius: 4.0, + dashed: false, + }); + } + prims.push(DatabasePrim::Text { + x: rect.x + 7.0, + y: rect.y, + layout, + clip: Some(FlowRect::new( + rect.x + 3.0, + rect.y, + (rect.w - 6.0).max(1.0), + btn_h, + )), + }); + authoring_hits.push(DatabaseAuthoringHit { + rect, + kind: hit_kind, + scrolls_x: false, + }); + if is_open { + panel_anchor = Some(rect); + } + cursor += btn_w + gap; + } + + let next_y = render_active_rule_chips(ctx, view, y + btn_h + 6.0, prims, authoring_hits); + (next_y, panel_anchor) } /// Compute the screen-space `(width, height)` for an open toolbar popover (`Filter` / `Sort` / diff --git a/blocksuite/crates/editor/src/database/mod.rs b/blocksuite/crates/editor/src/database/mod.rs index a1a49da250..1655ca7343 100644 --- a/blocksuite/crates/editor/src/database/mod.rs +++ b/blocksuite/crates/editor/src/database/mod.rs @@ -144,6 +144,8 @@ pub struct DatabaseUiState { pub calendar_selected_day: Option, /// Hovered local day index in Desktop Calendar month view (reveals day `+` button). pub calendar_hovered_day: Option, + /// Hovered bucket key in Desktop Kanban view (reveals lane footer `+ Add` button). + pub kanban_hovered_lane: Option, /// Horizontal scroll offset (whole px) for the touch database view tab strip. pub view_tabs_scroll_px: i32, /// One-shot hint set when switching `active_view_id` so the next layout pass brings the newly @@ -207,6 +209,20 @@ impl DatabaseFlowState { true } + pub fn set_kanban_hovered_lane( + &mut self, + block_id: &str, + bucket_key: Option, + ) -> bool { + let entry = self.ui_states.entry(block_id.to_string()).or_default(); + if entry.kanban_hovered_lane == bucket_key { + return false; + } + entry.kanban_hovered_lane = bucket_key; + self.revision = self.revision.wrapping_add(1); + true + } + pub fn toggle_more_views(&mut self, block_id: &str) { let entry = self.ui_states.entry(block_id.to_string()).or_default(); entry.more_views_open = !entry.more_views_open; diff --git a/blocksuite/crates/editor/src/database/render.rs b/blocksuite/crates/editor/src/database/render.rs index 43097d0ea1..acf708fa2c 100644 --- a/blocksuite/crates/editor/src/database/render.rs +++ b/blocksuite/crates/editor/src/database/render.rs @@ -108,11 +108,14 @@ pub fn layout_database_block( }; let is_touch = form_factor.is_touch_form_factor(); let tab_h = if is_touch { 34.0_f32 } else { 28.0_f32 }; - let tab_gap = 6.0_f32; + let tab_gap = 4.0_f32; let strip_left = 8.0_f32; let strip_right = (width - 8.0).max(strip_left + 1.0); let strip_w = (strip_right - strip_left).max(1.0); let max_tab_w = (width - 16.0).clamp(64.0, 180.0); + let hover_filled = theme + .css_var("--affine-hover-color-filled") + .unwrap_or(palette.hover); fn tab_label_for(view: &DatabaseView) -> &str { if view.name.is_empty() { @@ -213,21 +216,15 @@ pub fn layout_database_block( } else { visual_rect }; - prims.push(DatabasePrim::Quad { - rect: draw_rect, - fill: Some(if tab.is_active { - palette.hover - } else { - palette.background_secondary - }), - border: Some(if tab.is_active { - palette.brand.opacity(0.6) - } else { - palette.border - }), - radius: 6.0, - dashed: false, - }); + if tab.is_active { + prims.push(DatabasePrim::Quad { + rect: draw_rect, + fill: Some(hover_filled), + border: None, + radius: 4.0, + dashed: false, + }); + } let icon_x = if direction.is_rtl() { visual_rect.right() - 22.0 } else { @@ -240,7 +237,7 @@ pub fn layout_database_block( rect: FlowRect::new(icon_x, visual_rect.y + (tab_h - 14.0) * 0.5, 14.0, 14.0), icon: IconPaint::named(icon_for(&tab.view.mode)), color: if tab.is_active { - palette.brand + palette.text_primary } else { palette.icon }, @@ -277,6 +274,8 @@ pub fn layout_database_block( }); }; + let mut authoring_hits = Vec::new(); + let mut inline_toolbar_anchor: Option = None; let mut overflow_tabs: Vec = Vec::new(); let mut view_tabs_scroll_px = 0_i32; let mut view_tabs_max_scroll_px = 0_i32; @@ -315,15 +314,48 @@ pub fn layout_database_block( cursor += tab.w + tab_gap; } } else { - // Desktop: inline tabs that fit; overflow collapses into `"N More"` button + dropdown. - let more_reserve = 78.0_f32; + // Desktop: single horizontal toolbar row (`databaseToolbarRowStyles`): + // view tabs on the left, borderless Filter / Sort / Group triggers on the right. + let inline_ctx = DbRenderCtx { + data, + view: active_view, + rows: &[], + ui_state, + theme, + palette, + direction, + form_factor, + width, + mobile_readonly, + now_ms, + offset_at_ms, + page_titles, + window, + }; + let mut inline_tool_prims = Vec::new(); + let (tools_w, anchor) = filter_sort_bar::render_inline_toolbar_triggers( + &inline_ctx, + active_view, + y, + tab_h, + strip_right, + &mut inline_tool_prims, + &mut authoring_hits, + ); + inline_toolbar_anchor = anchor; + let tabs_right = if tools_w > 0.0 { + (strip_right - tools_w - 12.0).max(strip_left + 72.0) + } else { + strip_right + }; + let more_reserve = 72.0_f32; let mut cursor = strip_left; for (idx, tab) in measured_tabs.iter().enumerate() { let remaining = measured_tabs.len() - idx - 1; let limit = if remaining > 0 { - strip_right - more_reserve - tab_gap + tabs_right - more_reserve - tab_gap } else { - strip_right + tabs_right }; if cursor + tab.w <= limit || idx == 0 { emit_tab(tab, cursor, y, None); @@ -332,21 +364,20 @@ pub fn layout_database_block( overflow_tabs.push(idx); } } + prims.extend(inline_tool_prims); if !overflow_tabs.is_empty() { let more_label = format!("{} More", overflow_tabs.len()); - let more_w = 72.0_f32.min((strip_right - cursor).max(52.0)); + let more_w = 68.0_f32.min((tabs_right - cursor).max(52.0)); let more_rect = axis.map_rect(FlowRect::new(cursor, y, more_w, tab_h)); - prims.push(DatabasePrim::Quad { - rect: more_rect, - fill: Some(if ui_state.more_views_open { - palette.hover - } else { - palette.background_secondary - }), - border: Some(palette.border), - radius: 6.0, - dashed: false, - }); + if ui_state.more_views_open { + prims.push(DatabasePrim::Quad { + rect: more_rect, + fill: Some(hover_filled), + border: None, + radius: 4.0, + dashed: false, + }); + } let more_style = InlineStyle::new( FONT_SANS, TYPOGRAPHY.font_xs_px + 1.0, @@ -375,7 +406,7 @@ pub fn layout_database_block( }); } } - y += tab_h + 10.0; + y += tab_h + 8.0; if !is_touch && ui_state.more_views_open && !overflow_tabs.is_empty() { let menu_w = 180.0_f32.min(strip_w); @@ -531,12 +562,21 @@ pub fn layout_database_block( window, }; - // 4b. Desktop/writable view control bar (Filter / Sort / Group by + active chips). - // Open dropdown panels render in screen-space `Overlays` so opening a panel never changes - // the `affine:database` block height. - let mut authoring_hits = Vec::new(); - let (y, toolbar_anchor) = - filter_sort_bar::render_view_toolbar(&ctx, active_view, y, &mut prims, &mut authoring_hits); + // 4b. Active Filter/Sort chips on Desktop (triggers already sit inline on the tab row) or + // compact wrapping toolbar on Touch. Open dropdown panels render in screen-space `Overlays` + // so opening a panel never changes the `affine:database` block height. + let (y, toolbar_anchor) = if is_touch { + filter_sort_bar::render_view_toolbar(&ctx, active_view, y, &mut prims, &mut authoring_hits) + } else { + let next_y = filter_sort_bar::render_active_rule_chips( + &ctx, + active_view, + y, + &mut prims, + &mut authoring_hits, + ); + (next_y, inline_toolbar_anchor) + }; // 5. Render active view content starting at `y`. let content_top = y; @@ -591,13 +631,13 @@ pub fn layout_database_block( }; let total_height = (content_top + content_h + 10.0).ceil(); - // Outer database container card (`databaseBlockStyles`). + // Outer database container (`databaseBlockStyles`: primary background, zero outer grey frame). prims.insert( 0, DatabasePrim::Quad { rect: FlowRect::new(0.0, 0.0, width, total_height), fill: Some(palette.background), - border: Some(palette.border), + border: None, radius: 8.0, dashed: false, }, diff --git a/blocksuite/crates/editor/src/database/render_calendar.rs b/blocksuite/crates/editor/src/database/render_calendar.rs index 0458410a0f..7314a92365 100644 --- a/blocksuite/crates/editor/src/database/render_calendar.rs +++ b/blocksuite/crates/editor/src/database/render_calendar.rs @@ -12,17 +12,37 @@ use super::{ CalendarEntry, DatabaseAuthoringHit, DatabaseAuthoringHitKind, DatabaseHitKind, DatabaseHitTarget, InlineAxis, create_calendar_month_layout, isolate_ltr, local_day_index, render::{DatabasePrim, DbRenderCtx}, - resolve_rich_text_plain, resolve_tag_accent, resolve_tag_color, + resolve_rich_text_plain, resolve_tag_accent, }; const PAD_X: f32 = 8.0; -const NAV_HEIGHT: f32 = 30.0; -const WEEKDAY_HEADER_HEIGHT: f32 = 24.0; -const DAY_NUMBER_HEIGHT: f32 = 22.0; -const EVENT_CHIP_HEIGHT: f32 = 18.0; +const NAV_HEIGHT: f32 = 36.0; +const WEEKDAY_HEADER_HEIGHT: f32 = 26.0; +const DAY_NUMBER_HEIGHT: f32 = 24.0; +const EVENT_CHIP_HEIGHT: f32 = 22.0; const EVENT_CHIP_GAP: f32 = 3.0; -const MIN_WEEK_HEIGHT: f32 = 64.0; +const MIN_WEEK_HEIGHT: f32 = 80.0; const WEEKDAYS: [&str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; +const MONTH_NAMES: [&str; 12] = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", +]; + +/// Format Calendar toolbar month title matching `calendar/pc/view.ts` (`month: 'long', year: 'numeric'`). +pub(crate) fn format_calendar_month_title(year: i32, month: u32) -> String { + let idx = month.saturating_sub(1).min(11) as usize; + format!("{} {year}", MONTH_NAMES[idx]) +} pub use super::calendar_edit::resolve_calendar_display_month; @@ -139,11 +159,11 @@ pub(super) fn render_calendar_view( let actual_grid_w = col_w * 7.0; let axis = InlineAxis::new(ctx.direction, actual_grid_w); - // 1. Month navigation bar: `YYYY-MM` + `< | Today | >` (mirrored in RTL; >= 44pt on Phone). + // 1. Month navigation bar: `"March 2026"` + `< | Today | >` (`calendar/pc/styles.ts`). let mut y = top_y; let nav_h = if is_phone { 44.0 } else { NAV_HEIGHT }; - let btn_h = if is_phone { 44.0 } else { 26.0 }; - let (step_w, today_w) = if is_phone { (44.0, 62.0) } else { (28.0, 54.0) }; + let btn_h = if is_phone { 44.0 } else { 28.0 }; + let (step_w, today_w) = if is_phone { (44.0, 62.0) } else { (28.0, 56.0) }; let nav_buttons: [(&str, f32, DatabaseHitKind); 3] = if ctx.direction.is_rtl() { [ (">", step_w, DatabaseHitKind::CalendarNextMonth), @@ -157,9 +177,10 @@ pub(super) fn render_calendar_view( (">", step_w, DatabaseHitKind::CalendarNextMonth), ] }; - let month_label = isolate_ltr(&format!("{year:04}-{month:02}")); + let month_label = isolate_ltr(&format_calendar_month_title(year, month)); + let month_w = (actual_grid_w - 140.0).clamp(140.0, 220.0); let (month_x, month_align) = if ctx.direction.is_rtl() { - (PAD_X + (actual_grid_w - 140.0).max(0.0), InlineAlign::Right) + (PAD_X + (actual_grid_w - month_w).max(0.0), InlineAlign::Right) } else { (PAD_X, InlineAlign::Left) }; @@ -173,7 +194,7 @@ pub(super) fn render_calendar_view( ), month_x, y, - 140.0, + month_w, nav_h, month_align, )); @@ -189,9 +210,9 @@ pub(super) fn render_calendar_view( let rect = FlowRect::new(bx, btn_y, bw, btn_h); prims.push(DatabasePrim::Quad { rect, - fill: Some(ctx.palette.background_secondary), + fill: Some(ctx.palette.background), border: Some(ctx.palette.border), - radius: if is_phone { 8.0 } else { 5.0 }, + radius: if is_phone { 8.0 } else { 6.0 }, dashed: false, }); if label == "<" || label == ">" { @@ -210,7 +231,7 @@ pub(super) fn render_calendar_view( prims.push(DatabasePrim::Icon { rect: icon_rect, icon, - color: ctx.palette.text_primary, + color: ctx.palette.icon, }); } else { prims.push(ctx.single_line_clipped( @@ -219,7 +240,7 @@ pub(super) fn render_calendar_view( FONT_SANS, TYPOGRAPHY.font_xs_px + 1.0, 500.0, - ctx.palette.text_primary, + ctx.palette.brand, ), rect.x, rect.y, @@ -235,9 +256,16 @@ pub(super) fn render_calendar_view( }); bx += bw + 6.0; } - y += nav_h + 6.0; + y += nav_h + 8.0; - // 2. Weekday header row (mirrored in RTL via `InlineAxis::map_col_span`). + // 2. Weekday header row (`calendar/pc/styles.ts`: transparent borderless labels). + let weekday_align = if is_phone { + InlineAlign::Center + } else if ctx.direction.is_rtl() { + InlineAlign::Right + } else { + InlineAlign::Left + }; for (col_idx, name) in WEEKDAYS.iter().enumerate() { let visual_col = axis.map_col_span(7, col_idx, 1); let rect = FlowRect::new( @@ -246,13 +274,6 @@ pub(super) fn render_calendar_view( col_w, WEEKDAY_HEADER_HEIGHT, ); - prims.push(DatabasePrim::Quad { - rect, - fill: Some(ctx.palette.background_secondary), - border: Some(ctx.palette.border), - radius: 0.0, - dashed: false, - }); prims.push(ctx.single_line_clipped( name, InlineStyle::new( @@ -261,11 +282,11 @@ pub(super) fn render_calendar_view( 500.0, ctx.palette.text_secondary, ), - rect.x + 4.0, + rect.x + 6.0, rect.y, - (rect.w - 8.0).max(1.0), + (rect.w - 12.0).max(1.0), WEEKDAY_HEADER_HEIGHT, - InlineAlign::Center, + weekday_align, )); } y += WEEKDAY_HEADER_HEIGHT; @@ -511,6 +532,16 @@ pub(super) fn render_calendar_view( } // 3b. Desktop / Tablet full week rows, multi-day range segments, and single-day entries. + let grid_border = ctx.palette.border.opacity(0.58); + let chip_tint_alpha = match ctx.theme { + crate::theme::PlaygroundTheme::Light => 0.12, + crate::theme::PlaygroundTheme::Dark => 0.22, + }; + let grid_top_y = y; + prims.push(DbRenderCtx::hairline( + FlowRect::new(PAD_X, grid_top_y, actual_grid_w, 1.0), + grid_border, + )); for (week_index, week) in layout.weeks.iter().enumerate() { let max_slots = week .iter() @@ -518,7 +549,7 @@ pub(super) fn render_calendar_view( .max() .unwrap_or(0); let week_h = - (DAY_NUMBER_HEIGHT + max_slots as f32 * (EVENT_CHIP_HEIGHT + EVENT_CHIP_GAP) + 8.0) + (DAY_NUMBER_HEIGHT + max_slots as f32 * (EVENT_CHIP_HEIGHT + EVENT_CHIP_GAP) + 10.0) .max(MIN_WEEK_HEIGHT); // Day cells. @@ -532,23 +563,32 @@ pub(super) fn render_calendar_view( .calendar_drag .as_ref() .is_some_and(|d| d.target_day == day.day_index); - prims.push(DatabasePrim::Quad { - rect: cell_rect, - fill: Some(if is_drag_target { - ctx.palette.brand.opacity(0.14) - } else if day.in_month { - ctx.palette.background - } else { - ctx.palette.background_secondary.opacity(0.45) - }), - border: Some(if is_drag_target { - ctx.palette.brand - } else { - ctx.palette.border - }), - radius: 0.0, - dashed: false, - }); + let cell_fill = if is_drag_target { + Some(ctx.palette.brand.opacity(0.10)) + } else if is_today { + Some(ctx.palette.brand.opacity(0.06)) + } else if !day.in_month { + Some(ctx.palette.background_secondary.opacity(0.45)) + } else { + None + }; + if cell_fill.is_some() || is_drag_target { + prims.push(DatabasePrim::Quad { + rect: cell_rect, + fill: cell_fill, + border: is_drag_target.then_some(ctx.palette.brand), + radius: 0.0, + dashed: false, + }); + } + prims.push(DbRenderCtx::hairline( + FlowRect::new(cell_rect.right() - 1.0, cell_rect.y, 1.0, cell_rect.h), + grid_border, + )); + prims.push(DbRenderCtx::hairline( + FlowRect::new(cell_rect.x, cell_rect.bottom() - 1.0, cell_rect.w, 1.0), + grid_border, + )); let show_plus = is_today || is_drag_target || ctx.ui_state.calendar_selected_day == Some(day.day_index) @@ -570,73 +610,66 @@ pub(super) fn render_calendar_view( }); let day_label = isolate_ltr(&day.day.to_string()); let day_ink = if is_today { - ctx.palette.on_accent + ctx.palette.brand } else if day.in_month { ctx.palette.text_primary } else { - ctx.palette.text_secondary + ctx.palette.text_secondary.opacity(0.6) }; - if is_today { - let badge_x = if ctx.direction.is_rtl() { - cell_rect.x + 4.0 - } else { - cell_rect.right() - 24.0 - }; - prims.push(DatabasePrim::Quad { - rect: FlowRect::new(badge_x, cell_rect.y + 3.0, 20.0, 18.0), - fill: Some(ctx.palette.brand), - border: None, - radius: 9.0, - dashed: false, - }); - prims.push(ctx.single_line_clipped( - &day_label, - InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 600.0, day_ink), - badge_x, - cell_rect.y + 3.0, - 20.0, - 18.0, - InlineAlign::Center, - )); + let day_align = if ctx.direction.is_rtl() { + InlineAlign::Left } else { - let day_align = if ctx.direction.is_rtl() { - InlineAlign::Left - } else { - InlineAlign::Right - }; - prims.push(ctx.single_line_clipped( - &day_label, - InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, day_ink), - cell_rect.x + 5.0, - cell_rect.y + 2.0, - (cell_rect.w - 10.0).max(1.0), - DAY_NUMBER_HEIGHT, - day_align, - )); - } + InlineAlign::Right + }; + prims.push(ctx.single_line_clipped( + &day_label, + InlineStyle::new( + FONT_SANS, + TYPOGRAPHY.font_xs_px, + if is_today { 600.0 } else { 500.0 }, + day_ink, + ), + cell_rect.x + 6.0, + cell_rect.y + 3.0, + (cell_rect.w - 12.0).max(1.0), + DAY_NUMBER_HEIGHT, + day_align, + )); // Single-day event chips stacked below any range segments in this day. let mut chip_y = y + DAY_NUMBER_HEIGHT + day.segment_slots as f32 * (EVENT_CHIP_HEIGHT + EVENT_CHIP_GAP); for entry in &day.entries { - let (bg, ink) = entry.color.as_deref().map_or( - (ctx.palette.brand.opacity(0.18), ctx.palette.text_primary), - |c| resolve_tag_color(c, ctx.theme), - ); + let accent = entry + .color + .as_deref() + .map_or(ctx.palette.brand, |c| resolve_tag_accent(c, ctx.theme)); let chip_rect = FlowRect::new( - cell_rect.x + 3.0, + cell_rect.x + 4.0, chip_y, - (cell_rect.w - 6.0).max(1.0), + (cell_rect.w - 8.0).max(1.0), EVENT_CHIP_HEIGHT, ); prims.push(DatabasePrim::Quad { rect: chip_rect, - fill: Some(bg), + fill: Some(accent.opacity(chip_tint_alpha)), border: None, radius: 4.0, dashed: false, }); + let bar_x = if ctx.direction.is_rtl() { + chip_rect.right() - 3.0 + } else { + chip_rect.x + }; + prims.push(DatabasePrim::Quad { + rect: FlowRect::new(bar_x, chip_rect.y + 2.0, 3.0, EVENT_CHIP_HEIGHT - 4.0), + fill: Some(accent), + border: None, + radius: 1.5, + dashed: false, + }); let event_align = if ctx.direction.is_rtl() { InlineAlign::Right } else { @@ -644,10 +677,10 @@ pub(super) fn render_calendar_view( }; prims.push(ctx.single_line_clipped( &entry.title, - InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px - 1.0, 500.0, ink), - chip_rect.x + 4.0, + InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, ctx.palette.text_primary), + chip_rect.x + 6.0, chip_rect.y, - (chip_rect.w - 8.0).max(1.0), + (chip_rect.w - 10.0).max(1.0), EVENT_CHIP_HEIGHT, event_align, )); @@ -689,23 +722,24 @@ pub(super) fn render_calendar_view( let visual_start = axis.map_col_span(7, seg.start_index, seg.span); let seg_x = PAD_X + visual_start as f32 * col_w - + if seg.starts_before_week { 0.0 } else { 3.0 }; - let seg_right_trim = if seg.ends_after_week { 0.0 } else { 3.0 }; + + if seg.starts_before_week { 0.0 } else { 4.0 }; + let seg_right_trim = if seg.ends_after_week { 0.0 } else { 4.0 }; let seg_w = (seg.span as f32 * col_w - - if seg.starts_before_week { 0.0 } else { 3.0 } + - if seg.starts_before_week { 0.0 } else { 4.0 } - seg_right_trim) .max(8.0); let seg_y = y + DAY_NUMBER_HEIGHT + seg.slot as f32 * (EVENT_CHIP_HEIGHT + EVENT_CHIP_GAP); - let (bg, ink) = seg.entry.color.as_deref().map_or( - (ctx.palette.brand.opacity(0.24), ctx.palette.text_primary), - |c| resolve_tag_color(c, ctx.theme), - ); + let accent = seg + .entry + .color + .as_deref() + .map_or(ctx.palette.brand, |c| resolve_tag_accent(c, ctx.theme)); let seg_rect = FlowRect::new(seg_x, seg_y, seg_w, EVENT_CHIP_HEIGHT); prims.push(DatabasePrim::Quad { rect: seg_rect, - fill: Some(bg), - border: Some(ctx.palette.brand.opacity(0.4)), + fill: Some(accent.opacity(chip_tint_alpha)), + border: None, radius: if seg.starts_before_week && seg.ends_after_week { 0.0 } else { @@ -713,6 +747,20 @@ pub(super) fn render_calendar_view( }, dashed: false, }); + if !seg.starts_before_week { + let bar_x = if ctx.direction.is_rtl() { + seg_rect.right() - 3.0 + } else { + seg_rect.x + }; + prims.push(DatabasePrim::Quad { + rect: FlowRect::new(bar_x, seg_rect.y + 2.0, 3.0, EVENT_CHIP_HEIGHT - 4.0), + fill: Some(accent), + border: None, + radius: 1.5, + dashed: false, + }); + } let seg_align = if ctx.direction.is_rtl() { InlineAlign::Right } else { @@ -720,10 +768,10 @@ pub(super) fn render_calendar_view( }; prims.push(ctx.single_line_clipped( &seg.entry.title, - InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px - 1.0, 500.0, ink), - seg_rect.x + 5.0, + InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, ctx.palette.text_primary), + seg_rect.x + 7.0, seg_rect.y, - (seg_rect.w - 10.0).max(1.0), + (seg_rect.w - 12.0).max(1.0), EVENT_CHIP_HEIGHT, seg_align, )); @@ -740,7 +788,28 @@ pub(super) fn render_calendar_view( y += week_h; } + prims.push(DbRenderCtx::hairline( + FlowRect::new(PAD_X, grid_top_y, 1.0, (y - grid_top_y).max(1.0)), + grid_border, + )); let max_scroll_x = (actual_grid_w + 2.0 * PAD_X - ctx.width).max(0.0).ceil(); (y - top_y, max_scroll_x, prims, hits, authoring_hits, None) } + +#[cfg(test)] +mod tests { + use super::format_calendar_month_title; + + #[test] + fn calendar_month_title_uses_natural_english_month_names() { + for (year, month, expected) in [ + (2026, 1, "January 2026"), + (2026, 3, "March 2026"), + (2026, 9, "September 2026"), + (2026, 12, "December 2026"), + ] { + assert_eq!(format_calendar_month_title(year, month), expected); + } + } +} diff --git a/blocksuite/crates/editor/src/database/render_kanban.rs b/blocksuite/crates/editor/src/database/render_kanban.rs index 6c29ba5509..ae3a8afd85 100644 --- a/blocksuite/crates/editor/src/database/render_kanban.rs +++ b/blocksuite/crates/editor/src/database/render_kanban.rs @@ -4,7 +4,7 @@ use blocksuite_playground_doc::read::{DatabaseColumn, DatabaseGroupBy}; use crate::{ block_flow::{FlowRect, InlineAlign, InlineStyle}, - theme::{FONT_SANS, TYPOGRAPHY}, + theme::{FONT_SANS, IconPaint, TYPOGRAPHY}, }; use super::{ @@ -15,10 +15,10 @@ use super::{ resolve_tag_color, }; -const LANE_WIDTH: f32 = 240.0; +const LANE_WIDTH: f32 = 260.0; const LANE_GAP: f32 = 12.0; -const LANE_PAD: f32 = 10.0; -const CARD_GAP: f32 = 8.0; +const LANE_PAD: f32 = 4.0; +const CARD_GAP: f32 = 12.0; const PAD_X: f32 = 8.0; #[allow(clippy::type_complexity)] @@ -127,35 +127,43 @@ pub(super) fn render_kanban_view( for &b_idx in &ordered_lanes { let bucket = &buckets[b_idx]; - let lane_start_idx = prims.len(); let is_drag_target = ctx .ui_state .authoring .kanban_drag .as_ref() .is_some_and(|d| d.target_bucket_key == bucket.key); - prims.push(DatabasePrim::Quad { - rect: FlowRect::new(lane_x, top_y, LANE_WIDTH, 110.0), - fill: Some(ctx.palette.background_secondary), - border: Some(if is_drag_target { - ctx.palette.brand - } else { - ctx.palette.border - }), - radius: 8.0, - dashed: false, + let is_hovered_lane = ctx + .ui_state + .kanban_hovered_lane + .as_deref() + .is_some_and(|k| k == bucket.key); + let show_lane_ops = + ctx.form_factor.is_touch_form_factor() || is_hovered_lane || is_drag_target; + + // Reserve optional drag-target highlight slot (`kanban/pc/group.ts`: borderless transparent lane). + let lane_highlight_idx = is_drag_target.then(|| { + let idx = prims.len(); + prims.push(DatabasePrim::Quad { + rect: FlowRect::new(lane_x, top_y, LANE_WIDTH, 110.0), + fill: Some(ctx.palette.brand.opacity(0.06)), + border: Some(ctx.palette.brand), + radius: 8.0, + dashed: false, + }); + idx }); - let mut cy = top_y + LANE_PAD; - // Lane header: colored tag pill + card count. + let mut cy = top_y + 6.0; + // Lane header (`group-header`: 32px, colored tag pill + 20x20 count badge + hover `+`/`⋯`). let (pill_bg, pill_ink) = bucket .color .as_deref() .map_or((ctx.palette.hover, ctx.palette.text_primary), |c| { resolve_tag_color(c, ctx.theme) }); - let pill_style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 600.0, pill_ink); - let max_pill_w = (LANE_WIDTH - 56.0).max(24.0); + let pill_style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px + 1.0, 500.0, pill_ink); + let max_pill_w = (LANE_WIDTH - 92.0).max(24.0); let (_, pill_layout) = ctx.truncate_text( &bucket.label, pill_style, @@ -187,26 +195,64 @@ pub(super) fn render_kanban_view( )), }); - let count_str = bucket.rows.len().to_string(); - let count_x = if ctx.direction.is_rtl() { - lane_x + LANE_PAD - } else { - pill_x + pill_w + 8.0 - }; - prims.push(ctx.single_line_clipped( - &count_str, - InlineStyle::new( - FONT_SANS, - TYPOGRAPHY.font_xs_px, - 500.0, - ctx.palette.text_secondary, - ), - count_x, - cy, - 28.0, - 22.0, - InlineAlign::Left, - )); + if !bucket.rows.is_empty() { + let count_str = bucket.rows.len().to_string(); + let count_x = if ctx.direction.is_rtl() { + pill_x - 28.0 + } else { + pill_x + pill_w + 8.0 + }; + let count_rect = FlowRect::new(count_x, cy + 1.0, 20.0, 20.0); + prims.push(DatabasePrim::Quad { + rect: count_rect, + fill: Some(ctx.palette.background_secondary), + border: None, + radius: 4.0, + dashed: false, + }); + prims.push(ctx.single_line_clipped( + &count_str, + InlineStyle::new( + FONT_SANS, + TYPOGRAPHY.font_xs_px, + 500.0, + ctx.palette.text_secondary, + ), + count_rect.x, + count_rect.y, + count_rect.w, + count_rect.h, + InlineAlign::Center, + )); + } + + if !ctx.mobile_readonly && show_lane_ops { + let ops_x = if ctx.direction.is_rtl() { + lane_x + LANE_PAD + } else { + lane_x + LANE_WIDTH - LANE_PAD - 44.0 + }; + let plus_rect = FlowRect::new(ops_x, cy + 1.0, 20.0, 20.0); + let more_rect = FlowRect::new(ops_x + 22.0, cy + 1.0, 20.0, 20.0); + prims.push(DatabasePrim::Icon { + rect: FlowRect::new(plus_rect.x + 3.0, plus_rect.y + 3.0, 14.0, 14.0), + icon: IconPaint::named("PlusIcon"), + color: ctx.palette.icon, + }); + prims.push(DatabasePrim::Icon { + rect: FlowRect::new(more_rect.x + 3.0, more_rect.y + 3.0, 14.0, 14.0), + icon: IconPaint::named("MoreHorizontalIcon"), + color: ctx.palette.icon, + }); + authoring_hits.push(DatabaseAuthoringHit { + rect: plus_rect, + kind: DatabaseAuthoringHitKind::KanbanAddRowInGroup { + column_id: group_by.column_id.clone(), + seed_value: bucket.seed_value.clone(), + }, + scrolls_x: true, + }); + } cy += 30.0; // Cards inside this lane. @@ -231,30 +277,49 @@ pub(super) fn render_kanban_view( cy += card_h + CARD_GAP; } - // Desktop "+ New record" footer button inside each Kanban lane. + // Lane footer `+ Add` trigger (`kanban/pc/group.ts`: always reserves 28px height so + // hovering never shifts document flow; painted only on lane hover or touch form factors). if !ctx.mobile_readonly { - let add_rect = FlowRect::new(lane_x + LANE_PAD, cy, card_w, 26.0); - prims.push(DatabasePrim::Quad { - rect: add_rect, - fill: Some(ctx.palette.background.opacity(0.6)), - border: Some(ctx.palette.border), - radius: 5.0, - dashed: false, - }); - prims.push(ctx.single_line_clipped( - "+ New record", - InlineStyle::new( - FONT_SANS, - TYPOGRAPHY.font_xs_px, - 500.0, - ctx.palette.text_secondary, - ), - add_rect.x + 8.0, - add_rect.y, - (add_rect.w - 16.0).max(1.0), - 26.0, - align, - )); + let add_h = 28.0_f32; + let add_rect = FlowRect::new(lane_x + LANE_PAD, cy, card_w, add_h); + if show_lane_ops { + prims.push(DatabasePrim::Quad { + rect: add_rect, + fill: Some(ctx.palette.hover), + border: None, + radius: 4.0, + dashed: false, + }); + let icon_x = if ctx.direction.is_rtl() { + add_rect.right() - 20.0 + } else { + add_rect.x + 6.0 + }; + prims.push(DatabasePrim::Icon { + rect: FlowRect::new(icon_x, add_rect.y + 7.0, 14.0, 14.0), + icon: IconPaint::named("PlusIcon"), + color: ctx.palette.icon, + }); + let text_x = if ctx.direction.is_rtl() { + add_rect.x + 6.0 + } else { + add_rect.x + 24.0 + }; + prims.push(ctx.single_line_clipped( + "Add", + InlineStyle::new( + FONT_SANS, + TYPOGRAPHY.font_xs_px + 1.0, + 400.0, + ctx.palette.text_secondary, + ), + text_x, + add_rect.y, + (add_rect.w - 30.0).max(1.0), + add_h, + align, + )); + } authoring_hits.push(DatabaseAuthoringHit { rect: add_rect, kind: DatabaseAuthoringHitKind::KanbanAddRowInGroup { @@ -263,11 +328,13 @@ pub(super) fn render_kanban_view( }, scrolls_x: true, }); - cy += 26.0 + CARD_GAP; + cy += add_h + CARD_GAP; } let lane_h = (cy - top_y + LANE_PAD - CARD_GAP).max(110.0); - if let Some(DatabasePrim::Quad { rect, .. }) = prims.get_mut(lane_start_idx) { + if let Some(idx) = lane_highlight_idx + && let Some(DatabasePrim::Quad { rect, .. }) = prims.get_mut(idx) + { rect.h = lane_h; } if !ctx.mobile_readonly { diff --git a/blocksuite/crates/editor/src/database/render_kanban_card.rs b/blocksuite/crates/editor/src/database/render_kanban_card.rs index c7b7547c53..833e722737 100644 --- a/blocksuite/crates/editor/src/database/render_kanban_card.rs +++ b/blocksuite/crates/editor/src/database/render_kanban_card.rs @@ -19,7 +19,17 @@ use super::{ resolve_rich_text_plain, resolve_tag_color, }; -const CARD_PAD: f32 = 10.0; +const CARD_PAD: f32 = 8.0; +const PILL_H: f32 = 20.0; +const PILL_GAP_X: f32 = 4.0; +const PILL_GAP_Y: f32 = 4.0; +const PROP_GAP: f32 = 4.0; + +struct PillItem { + label: String, + bg: ui::Hsla, + ink: ui::Hsla, +} enum KanbanProp { Text { @@ -27,12 +37,10 @@ enum KanbanProp { col_type: String, text: String, }, - Pill { + Pills { col_id: String, col_type: String, - label: String, - bg: ui::Hsla, - ink: ui::Hsla, + items: Vec, }, Checkbox { col_id: String, @@ -46,6 +54,48 @@ enum KanbanProp { }, } +struct PlacedPill { + x_offset: f32, + y_offset: f32, + w: f32, + bg: ui::Hsla, + layout: std::rc::Rc, +} + +/// Lay out a row of Select / Multi-select pills horizontally with wrapping (`gap: 4px`). +fn layout_wrapped_pills( + ctx: &DbRenderCtx<'_>, + items: &[PillItem], + inner_w: f32, +) -> (Vec, f32) { + let mut placed = Vec::with_capacity(items.len()); + let mut cur_x = 0.0_f32; + let mut cur_y = 0.0_f32; + for item in items { + let style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, item.ink); + let (_, layout) = ctx.truncate_text(&item.label, style, (inner_w - 12.0).max(1.0), PILL_H); + let pw = (layout.content_width().ceil() + 12.0).min(inner_w); + if cur_x > 0.0 && cur_x + pw > inner_w + 0.5 { + cur_x = 0.0; + cur_y += PILL_H + PILL_GAP_Y; + } + placed.push(PlacedPill { + x_offset: cur_x, + y_offset: cur_y, + w: pw, + bg: item.bg, + layout, + }); + cur_x += pw + PILL_GAP_X; + } + let total_h = if placed.is_empty() { + PILL_H + } else { + cur_y + PILL_H + }; + (placed, total_h) +} + fn collect_kanban_card_props( ctx: &DbRenderCtx<'_>, row: &DatabaseRow, @@ -73,6 +123,7 @@ fn collect_kanban_card_props( match col.column_type.as_str() { "select" | "multi-select" => { let opts = col.select_options(); + let mut items = Vec::new(); for id in val.as_string_list() { let (lbl, clr) = opts .iter() @@ -81,14 +132,19 @@ fn collect_kanban_card_props( (o.value.clone(), o.color.as_str()) }); let (bg, ink) = resolve_tag_color(clr, ctx.theme); - prop_lines.push(KanbanProp::Pill { - col_id: col.id.clone(), - col_type: col.column_type.clone(), + items.push(PillItem { label: lbl, bg, ink, }); } + if !items.is_empty() { + prop_lines.push(KanbanProp::Pills { + col_id: col.id.clone(), + col_type: col.column_type.clone(), + items, + }); + } } "progress" => { if let Some(p) = val.as_i64() { @@ -203,7 +259,6 @@ pub(super) fn render_kanban_card( ); let title_lines = title_laid.as_ref().map_or(1, |l| l.lines().len().max(1)); let title_h = (title_lines as f32 * 20.0 + 4.0).max(24.0); - let extra_title_h = title_h - 24.0; let inner_x = card_x + CARD_PAD; let inner_w = (card_w - 2.0 * CARD_PAD).max(1.0); @@ -242,13 +297,65 @@ pub(super) fn render_kanban_card( ((l.lines().len().max(1) as f32 * 18.0 + 2.0).max(20.0)) - 20.0 }); - let card_h = 34.0 + extra_title_h + extra_prop_h + (prop_lines.len() as f32 * 22.0); + // Pre-compute each property row's exact height (including horizontally wrapped multi-select pills). + let mut wrapped_pills: Vec>> = Vec::with_capacity(prop_lines.len()); + let mut prop_heights: Vec = Vec::with_capacity(prop_lines.len()); + for prop in &prop_lines { + match prop { + KanbanProp::Pills { items, .. } => { + let (placed, h) = layout_wrapped_pills(ctx, items, inner_w); + wrapped_pills.push(Some(placed)); + prop_heights.push(h); + } + KanbanProp::Text { + col_id, col_type, .. + } if col_type == "rich-text" + && active_rich_prop_laid + .as_ref() + .is_some_and(|(cid, _)| cid == col_id) => + { + wrapped_pills.push(None); + prop_heights.push(20.0 + extra_prop_h); + } + _ => { + wrapped_pills.push(None); + prop_heights.push(20.0); + } + } + } + + let header_h = CARD_PAD + title_h + CARD_PAD; + let body_h = if prop_lines.is_empty() { + 0.0 + } else { + CARD_PAD + + prop_heights.iter().sum::() + + prop_lines.len().saturating_sub(1) as f32 * PROP_GAP + + CARD_PAD + }; + let card_h = header_h + body_h; let card_rect = FlowRect::new(card_x, cy, card_w, card_h); + let card_bg = match ctx.theme { + crate::theme::PlaygroundTheme::Light => ctx.palette.background, + crate::theme::PlaygroundTheme::Dark => ctx.palette.panel, + }; + let shadow_alpha = match ctx.theme { + crate::theme::PlaygroundTheme::Light => 0.05, + crate::theme::PlaygroundTheme::Dark => 0.22, + }; + // Subtle 2px drop-shadow layer (`kanban/pc/card.ts`: `box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.05)`). + prims.push(DatabasePrim::Quad { + rect: FlowRect::new(card_rect.x + 2.0, card_rect.bottom(), (card_rect.w - 4.0).max(1.0), 2.0), + fill: Some(ui::Hsla::black().opacity(shadow_alpha)), + border: None, + radius: 2.0, + dashed: false, + }); prims.push(DatabasePrim::Quad { rect: card_rect, - fill: Some(ctx.palette.background), - border: Some(ctx.palette.border), - radius: 6.0, + fill: Some(card_bg), + border: Some(ctx.inside_border()), + radius: 8.0, dashed: false, }); if !ctx.mobile_readonly { @@ -264,7 +371,7 @@ pub(super) fn render_kanban_card( } let title_rect = FlowRect::new( card_rect.x + CARD_PAD - 2.0, - card_rect.y + 4.0, + card_rect.y + CARD_PAD - 2.0, (card_w - 2.0 * CARD_PAD + 4.0).max(1.0), title_h, ); @@ -325,37 +432,25 @@ pub(super) fn render_kanban_card( }); } - let mut py = card_rect.y + 30.0 + extra_title_h; - for prop in prop_lines { - let this_prop_h = match &prop { - KanbanProp::Text { - col_id, col_type, .. - } if col_type == "rich-text" - && active_rich_prop_laid - .as_ref() - .is_some_and(|(cid, _)| cid == col_id) => - { - 20.0 + extra_prop_h - } - _ => 20.0, - }; + if !prop_lines.is_empty() { + // `.card-header.has-divider`: subtle hairline between header and property body. + prims.push(DbRenderCtx::hairline( + FlowRect::new(card_rect.x + 1.0, card_rect.y + header_h, (card_rect.w - 2.0).max(1.0), 1.0), + ctx.inside_border().opacity(0.75), + )); + } + + let mut py = card_rect.y + header_h + CARD_PAD; + for ((prop, this_prop_h), placed_pills) in prop_lines + .into_iter() + .zip(prop_heights) + .zip(wrapped_pills) + { let prop_rect = FlowRect::new(inner_x, py, inner_w, this_prop_h); match prop { - KanbanProp::Pill { - col_id, - col_type, - label, - bg, - ink, + KanbanProp::Pills { + col_id, col_type, .. } => { - let style = InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px, 500.0, ink); - let (_, layout) = ctx.truncate_text(&label, style, (inner_w - 10.0).max(1.0), 18.0); - let pw = (layout.content_width().ceil() + 10.0).min(inner_w); - let px_pos = if ctx.direction.is_rtl() { - card_rect.right() - CARD_PAD - pw - } else { - inner_x - }; let is_editing = ctx .ui_state .authoring @@ -364,23 +459,38 @@ pub(super) fn render_kanban_card( .is_some_and(|e| e.row_id == row.row_id && e.column_id == col_id); if is_editing { *popover_anchor = Some(DatabasePopoverAnchor { - rect: FlowRect::new(px_pos, py, pw, 18.0), + rect: prop_rect, scrolls_x: true, }); } - prims.push(DatabasePrim::Quad { - rect: FlowRect::new(px_pos, py, pw, 18.0), - fill: Some(bg), - border: is_editing.then_some(ctx.palette.brand), - radius: 4.0, - dashed: false, - }); - prims.push(DatabasePrim::Text { - x: px_pos + 5.0, - y: py, - layout, - clip: Some(FlowRect::new(px_pos + 3.0, py, (pw - 6.0).max(1.0), 18.0)), - }); + if let Some(pills) = placed_pills { + for pill in pills { + let px_pos = if ctx.direction.is_rtl() { + card_rect.right() - CARD_PAD - pill.x_offset - pill.w + } else { + inner_x + pill.x_offset + }; + let pill_y = py + pill.y_offset; + prims.push(DatabasePrim::Quad { + rect: FlowRect::new(px_pos, pill_y, pill.w, PILL_H), + fill: Some(pill.bg), + border: is_editing.then_some(ctx.palette.brand), + radius: 4.0, + dashed: false, + }); + prims.push(DatabasePrim::Text { + x: px_pos + 6.0, + y: pill_y, + layout: pill.layout, + clip: Some(FlowRect::new( + px_pos + 3.0, + pill_y, + (pill.w - 6.0).max(1.0), + PILL_H, + )), + }); + } + } if !ctx.mobile_readonly { authoring_hits.push(DatabaseAuthoringHit { rect: prop_rect, @@ -611,7 +721,7 @@ pub(super) fn render_kanban_card( } } } - py += this_prop_h + 2.0; + py += this_prop_h + PROP_GAP; } if ctx.mobile_readonly { diff --git a/blocksuite/crates/editor/src/database/render_table.rs b/blocksuite/crates/editor/src/database/render_table.rs index 3178161efe..21652ad188 100644 --- a/blocksuite/crates/editor/src/database/render_table.rs +++ b/blocksuite/crates/editor/src/database/render_table.rs @@ -68,9 +68,14 @@ pub(super) fn render_table_view( let mut active_cell_rect = None; let mut y = top_y; - // 1. Table header row. + let border_col = ctx.inside_border(); + // 1. Table header row (`table/pc/header/styles.ts`: primary bg + 1px top/bottom hairlines). + prims.push(DbRenderCtx::hairline( + FlowRect::new(start_x, y, total_table_w, 1.0), + border_col, + )); let mut col_x = start_x; - for &c_idx in &ordered_col_indices { + for (slot_idx, &c_idx) in ordered_col_indices.iter().enumerate() { let col = &cols[c_idx]; let cell_rect = FlowRect::new(col_x, y, col.width, HEADER_HEIGHT); let menu_open = ctx @@ -79,29 +84,30 @@ pub(super) fn render_table_view( .column_menu .as_ref() .is_some_and(|m| m.column_id == col.id); - prims.push(DatabasePrim::Quad { - rect: cell_rect, - fill: Some(if menu_open { - ctx.palette.hover - } else { - ctx.palette.background_secondary - }), - border: Some(if menu_open { - ctx.palette.brand - } else { - ctx.palette.border - }), - radius: 0.0, - dashed: false, - }); + if menu_open { + prims.push(DatabasePrim::Quad { + rect: cell_rect, + fill: Some(ctx.palette.hover), + border: Some(ctx.palette.brand), + radius: 0.0, + dashed: false, + }); + } + let is_last = slot_idx + 1 == ordered_col_indices.len(); + if !is_last || !ctx.mobile_readonly { + prims.push(DbRenderCtx::hairline( + FlowRect::new(cell_rect.right() - 1.0, cell_rect.y, 1.0, HEADER_HEIGHT), + border_col, + )); + } let (icon_x, text_x, align) = if ctx.direction.is_rtl() { ( - cell_rect.right() - 22.0, - cell_rect.x + 8.0, + cell_rect.right() - 20.0, + cell_rect.x + 6.0, InlineAlign::Right, ) } else { - (cell_rect.x + 8.0, cell_rect.x + 26.0, InlineAlign::Left) + (cell_rect.x + 6.0, cell_rect.x + 24.0, InlineAlign::Left) }; prims.push(DatabasePrim::Icon { rect: FlowRect::new(icon_x, cell_rect.y + 10.0, 14.0, 14.0), @@ -122,7 +128,7 @@ pub(super) fn render_table_view( InlineStyle::new(FONT_SANS, TYPOGRAPHY.font_xs_px + 1.0, 500.0, ink), text_x, cell_rect.y, - (cell_rect.w - 34.0).max(1.0), + (cell_rect.w - 30.0).max(1.0), HEADER_HEIGHT, align, )); @@ -158,13 +164,6 @@ pub(super) fn render_table_view( } if !ctx.mobile_readonly { let add_col_rect = FlowRect::new(col_x, y, add_col_w, HEADER_HEIGHT); - prims.push(DatabasePrim::Quad { - rect: add_col_rect, - fill: Some(ctx.palette.background_secondary), - border: Some(ctx.palette.border), - radius: 0.0, - dashed: false, - }); prims.push(DatabasePrim::Icon { rect: FlowRect::new(add_col_rect.x + 10.0, add_col_rect.y + 10.0, 14.0, 14.0), icon: IconPaint::named("PlusIcon"), @@ -176,6 +175,10 @@ pub(super) fn render_table_view( scrolls_x: true, }); } + prims.push(DbRenderCtx::hairline( + FlowRect::new(start_x, y + HEADER_HEIGHT - 1.0, total_table_w, 1.0), + border_col, + )); y += HEADER_HEIGHT; // 2. Rows (optionally grouped by `view.group_by`). @@ -192,13 +195,10 @@ pub(super) fn render_table_view( for bucket in buckets { let collapsed = ctx.ui_state.collapsed_groups.contains(&bucket.key); let group_rect = FlowRect::new(start_x, y, total_table_w, GROUP_HEADER_HEIGHT); - prims.push(DatabasePrim::Quad { - rect: group_rect, - fill: Some(ctx.palette.background_secondary.opacity(0.6)), - border: Some(ctx.palette.border), - radius: 0.0, - dashed: false, - }); + prims.push(DbRenderCtx::hairline( + FlowRect::new(group_rect.x, group_rect.bottom() - 1.0, group_rect.w, 1.0), + border_col, + )); let chev_x = if ctx.direction.is_rtl() { group_rect.right() - 22.0 } else { @@ -278,13 +278,10 @@ pub(super) fn render_table_view( } } else if ctx.rows.is_empty() { let empty_rect = FlowRect::new(start_x, y, total_table_w, ROW_HEIGHT); - prims.push(DatabasePrim::Quad { - rect: empty_rect, - fill: Some(ctx.palette.background), - border: Some(ctx.palette.border), - radius: 0.0, - dashed: false, - }); + prims.push(DbRenderCtx::hairline( + FlowRect::new(empty_rect.x, empty_rect.bottom() - 1.0, empty_rect.w, 1.0), + border_col, + )); prims.push(ctx.single_line_clipped( "No records", InlineStyle::new( @@ -318,16 +315,13 @@ pub(super) fn render_table_view( } } - // 3. Desktop "+ New record" footer row (hidden in mobile read-only mode). + // 3. Desktop "+ New record" footer row (`table/pc/group.ts`: borderless sides, 1px bottom line). if !ctx.mobile_readonly { let add_rect = FlowRect::new(start_x, y, total_table_w, 30.0); - prims.push(DatabasePrim::Quad { - rect: add_rect, - fill: Some(ctx.palette.background), - border: Some(ctx.palette.border), - radius: 0.0, - dashed: false, - }); + prims.push(DbRenderCtx::hairline( + FlowRect::new(add_rect.x, add_rect.bottom() - 1.0, add_rect.w, 1.0), + border_col, + )); let add_align = if ctx.direction.is_rtl() { InlineAlign::Right } else { @@ -388,6 +382,7 @@ fn render_table_row( }; let (rich_layouts, row_h) = prelayout_table_row_rich_cells(ctx, cols, ordered_col_indices, row, ROW_HEIGHT, align); + let border_col = ctx.inside_border(); let mut cell_x = start_x; for (slot_idx, &c_idx) in ordered_col_indices.iter().enumerate() { let col = &cols[c_idx]; @@ -404,15 +399,22 @@ fn render_table_row( .css_var("--affine-v2-status-error") .unwrap_or(ctx.palette.brand), Some(_) => ctx.palette.brand, - None => ctx.palette.border, + None => border_col, }; - prims.push(DatabasePrim::Quad { - rect: cell_rect, - fill: Some(ctx.palette.background), - border: Some(border_color), - radius: 0.0, - dashed: false, - }); + if active_ed.is_some() { + prims.push(DatabasePrim::Quad { + rect: cell_rect, + fill: None, + border: Some(border_color), + radius: 0.0, + dashed: false, + }); + } else { + if slot_idx + 1 < ordered_col_indices.len() || !ctx.mobile_readonly { + prims.push(DbRenderCtx::hairline(FlowRect::new(cell_rect.right() - 1.0, cell_rect.y, 1.0, cell_rect.h), border_col)); + } + prims.push(DbRenderCtx::hairline(FlowRect::new(cell_rect.x, cell_rect.bottom() - 1.0, cell_rect.w, 1.0), border_col)); + } let inner_x = cell_rect.x + 8.0; let inner_w = (cell_rect.w - 16.0).max(1.0); if let Some(ed) = active_ed { diff --git a/blocksuite/crates/editor/src/database/render_types.rs b/blocksuite/crates/editor/src/database/render_types.rs index bdc7b1bbb1..3520c72665 100644 --- a/blocksuite/crates/editor/src/database/render_types.rs +++ b/blocksuite/crates/editor/src/database/render_types.rs @@ -92,6 +92,22 @@ pub(super) struct DbRenderCtx<'a> { } impl DbRenderCtx<'_> { + pub(super) fn inside_border(&self) -> Hsla { + self.theme + .css_var("--affine-v2-layer-insideBorder-border") + .unwrap_or(self.palette.border) + } + + pub(super) fn hairline(rect: FlowRect, color: Hsla) -> DatabasePrim { + DatabasePrim::Quad { + rect, + fill: Some(color), + border: None, + radius: 0.0, + dashed: false, + } + } + pub(super) fn inline( &self, text: &str, diff --git a/blocksuite/crates/playground/src/bin/bs_harness/db_visual_evidence.rs b/blocksuite/crates/playground/src/bin/bs_harness/db_visual_evidence.rs new file mode 100644 index 0000000000..3b38e7ac64 --- /dev/null +++ b/blocksuite/crates/playground/src/bin/bs_harness/db_visual_evidence.rs @@ -0,0 +1,289 @@ +//! Offscreen PNG visual parity evidence renderer for `affine:database` +//! (`Table`, `Kanban`, `Calendar`) in Light & Dark desktop (`1280×860`) and Phone (`390×844`). + +use std::{collections::BTreeMap, path::Path}; + +use anyhow::Result; +use blocksuite_playground_doc::schema::{ + BlockSpec, DatabaseCellSpec, DatabaseColumnSpec, DatabaseSpec, DatabaseViewSpec, ParagraphType, +}; +use playground::{ + HOME_PAGE_ID, PlaygroundOptions, PlaygroundTheme, room_client::DocState, +}; +use serde_json::json; + +use super::{ + s3_evidence_fixtures::{new_doc_state, save_session_png}, + start_headless_session, +}; + +fn build_db_visual_doc() -> Result<(DocState, String)> { + let mut state = new_doc_state("Database Visual Parity")?; + let db_id = "db-visual".to_string(); + { + let page = state.workspace.page_mut(HOME_PAGE_ID).unwrap(); + let mut cells = BTreeMap::new(); + cells.insert( + "row-1".into(), + BTreeMap::from([ + ("col-status".into(), DatabaseCellSpec::Text("opt-doing".into())), + ( + "col-tags".into(), + DatabaseCellSpec::MultiSelect(vec![ + "tag-ui".into(), + "tag-rust".into(), + "tag-core".into(), + ]), + ), + ("col-budget".into(), DatabaseCellSpec::Number(4800.0)), + ("col-progress".into(), DatabaseCellSpec::Integer(72)), + ("col-done".into(), DatabaseCellSpec::Bool(false)), + ( + "col-due".into(), + DatabaseCellSpec::Integer(1_773_014_400_000), + ), + ( + "col-end".into(), + DatabaseCellSpec::Integer(1_773_187_200_000), + ), + ]), + ); + cells.insert( + "row-2".into(), + BTreeMap::from([ + ("col-status".into(), DatabaseCellSpec::Text("opt-todo".into())), + ( + "col-tags".into(), + DatabaseCellSpec::MultiSelect(vec!["tag-core".into(), "tag-ui".into()]), + ), + ("col-budget".into(), DatabaseCellSpec::Number(2400.0)), + ("col-progress".into(), DatabaseCellSpec::Integer(35)), + ("col-done".into(), DatabaseCellSpec::Bool(false)), + ( + "col-due".into(), + DatabaseCellSpec::Integer(1_773_273_600_000), + ), + ]), + ); + cells.insert( + "row-3".into(), + BTreeMap::from([ + ("col-status".into(), DatabaseCellSpec::Text("opt-done".into())), + ( + "col-tags".into(), + DatabaseCellSpec::MultiSelect(vec!["tag-rust".into()]), + ), + ("col-budget".into(), DatabaseCellSpec::Number(6200.0)), + ("col-progress".into(), DatabaseCellSpec::Integer(100)), + ("col-done".into(), DatabaseCellSpec::Bool(true)), + ( + "col-due".into(), + DatabaseCellSpec::Integer(1_773_532_800_000), + ), + ]), + ); + + page.add_block( + &db_id, + BlockSpec::Database(DatabaseSpec { + title: "Q1 Release Roadmap".into(), + columns: vec![ + DatabaseColumnSpec { + id: "title".into(), + column_type: "title".into(), + name: "Task".into(), + data: json!({}), + }, + DatabaseColumnSpec { + id: "col-status".into(), + column_type: "select".into(), + name: "Status".into(), + data: json!({ + "options": [ + { "id": "opt-todo", "value": "Todo", "color": "var(--affine-tag-blue)" }, + { "id": "opt-doing", "value": "In Progress", "color": "var(--affine-tag-orange)" }, + { "id": "opt-done", "value": "Done", "color": "var(--affine-tag-green)" } + ] + }), + }, + DatabaseColumnSpec { + id: "col-tags".into(), + column_type: "multi-select".into(), + name: "Tags".into(), + data: json!({ + "options": [ + { "id": "tag-ui", "value": "UI", "color": "var(--affine-tag-purple)" }, + { "id": "tag-rust", "value": "Rust", "color": "var(--affine-tag-teal)" }, + { "id": "tag-core", "value": "Core", "color": "var(--affine-tag-yellow)" } + ] + }), + }, + DatabaseColumnSpec { + id: "col-budget".into(), + column_type: "number".into(), + name: "Budget".into(), + data: json!({ "format": "currencyUSD" }), + }, + DatabaseColumnSpec { + id: "col-progress".into(), + column_type: "progress".into(), + name: "Progress".into(), + data: json!({}), + }, + DatabaseColumnSpec { + id: "col-done".into(), + column_type: "checkbox".into(), + name: "Done".into(), + data: json!({}), + }, + DatabaseColumnSpec { + id: "col-due".into(), + column_type: "date".into(), + name: "Start".into(), + data: json!({}), + }, + DatabaseColumnSpec { + id: "col-end".into(), + column_type: "date".into(), + name: "End".into(), + data: json!({}), + }, + ], + views: vec![ + DatabaseViewSpec { + id: "v-table".into(), + name: "Table".into(), + mode: "table".into(), + raw: json!({ + "columns": [ + { "id": "title", "width": 220 }, + { "id": "col-status", "width": 120 }, + { "id": "col-tags", "width": 160 }, + { "id": "col-budget", "width": 110 }, + { "id": "col-progress", "width": 130 }, + { "id": "col-done", "width": 80 } + ] + }), + }, + DatabaseViewSpec { + id: "v-kanban".into(), + name: "Kanban".into(), + mode: "kanban".into(), + raw: json!({ + "groupBy": { + "type": "groupBy", + "columnId": "col-status", + "name": "select" + }, + "columns": [ + { "id": "col-tags" }, + { "id": "col-progress" }, + { "id": "col-budget" }, + { "id": "col-done" } + ] + }), + }, + DatabaseViewSpec { + id: "v-cal".into(), + name: "Calendar".into(), + mode: "calendar".into(), + raw: json!({ + "date": { + "startColumnId": "col-due", + "endColumnId": "col-end" + } + }), + }, + ], + cells, + }), + Some("p-note"), + None, + 10, + )?; + + for (idx, (id, title)) in [ + ("row-1", "Column Schema & Type Switcher"), + ("row-2", "Filter / Sort / Group Controls"), + ("row-3", "Calendar Quick Add & Reschedule"), + ] + .into_iter() + .enumerate() + { + page.add_block( + id, + BlockSpec::Paragraph { + paragraph_type: ParagraphType::Text, + text: title.into(), + }, + Some(&db_id), + None, + 20 + idx as u64, + )?; + } + } + Ok((state, db_id)) +} + +pub(super) fn render_db_visual_evidence( + out_dir: &Path, + prefix: &str, + include_phone: bool, +) -> Result<()> { + std::fs::create_dir_all(out_dir)?; + + let views = [ + ("v-table", "table"), + ("v-kanban", "kanban"), + ("v-cal", "calendar"), + ]; + + for (theme, theme_name) in [ + (PlaygroundTheme::Light, "light"), + (PlaygroundTheme::Dark, "dark"), + ] { + for (view_id, view_name) in views { + let (state, db_id) = build_db_visual_doc()?; + let session = start_headless_session( + 1280, + 860, + PlaygroundOptions { + theme, + ..Default::default() + }, + )?; + session.view(|v, cx| { + v.set_document(state, cx); + v.set_database_active_view(&db_id, view_id, cx); + })?; + session.settle(120); + let stem = format!("{prefix}-db-{view_name}-{theme_name}"); + save_session_png(&session, &out_dir.join(format!("{stem}.png")), &stem)?; + } + } + + if include_phone { + for (view_id, view_name) in views { + let (state, db_id) = build_db_visual_doc()?; + let session = start_headless_session( + 390, + 844, + PlaygroundOptions { + theme: PlaygroundTheme::Light, + form_factor: playground::FormFactor::Phone, + database_readonly: false, + ..Default::default() + }, + )?; + session.view(|v, cx| { + v.set_document(state, cx); + v.set_database_active_view(&db_id, view_id, cx); + })?; + session.settle(120); + let stem = format!("{prefix}-db-phone-{view_name}-light"); + save_session_png(&session, &out_dir.join(format!("{stem}.png")), &stem)?; + } + } + + Ok(()) +} diff --git a/blocksuite/crates/playground/src/bin/bs_harness/main.rs b/blocksuite/crates/playground/src/bin/bs_harness/main.rs index 48682b21ee..f12b0e76e1 100644 --- a/blocksuite/crates/playground/src/bin/bs_harness/main.rs +++ b/blocksuite/crates/playground/src/bin/bs_harness/main.rs @@ -1,5 +1,6 @@ mod bench; mod database_authoring_evidence; +mod db_visual_evidence; mod demo; mod edgeless_evidence; mod edgeless_selection_evidence; @@ -492,6 +493,26 @@ fn main() -> Result<()> { .context("render-db-authoring-evidence requires an output directory")?, )) } + "render-db-visual-evidence" => { + let dir = PathBuf::from( + args.next() + .context("render-db-visual-evidence requires an output directory")?, + ); + let mut prefix = "after".to_string(); + let mut include_phone = false; + while let Some(arg) = args.next() { + match arg.as_str() { + "--prefix" => { + prefix = args.next().context("--prefix requires a value")?; + } + "--phone" => { + include_phone = true; + } + other => bail!("unknown render-db-visual-evidence argument {other:?}"), + } + } + db_visual_evidence::render_db_visual_evidence(&dir, &prefix, include_phone) + } "render-editor-media-evidence" => { media_evidence::render_editor_media_evidence(&PathBuf::from( args.next() diff --git a/blocksuite/crates/playground/src/database_authoring/mod.rs b/blocksuite/crates/playground/src/database_authoring/mod.rs index 27939e9684..0949662fee 100644 --- a/blocksuite/crates/playground/src/database_authoring/mod.rs +++ b/blocksuite/crates/playground/src/database_authoring/mod.rs @@ -551,6 +551,7 @@ impl PlaygroundView { cx: &mut Context, ) { let mut hit_target: Option<(String, i64)> = None; + let mut kanban_target: Option<(String, String)> = None; if pos_y >= crate::TOPBAR_HEIGHT && let Some(layout) = self.flow_layout() { @@ -563,20 +564,24 @@ impl PlaygroundView { { let lx = world_x - block.x; let ly = world_y - block.y; - if let Some(day_idx) = self - .flow - .database_authoring_hits(&block.block_id) - .iter() - .find_map(|h| match h.kind { - DatabaseAuthoringHitKind::CalendarDayDropTarget { day_index } - if h.rect.contains(lx, ly) => - { - Some(day_index) + let sx = block + .body + .code_scroll + .map_or(0.0, |cs| self.overlays.code_scroll_x_for(&block.block_id, cs)); + for h in self.flow.database_authoring_hits(&block.block_id) { + let hx = if h.scrolls_x { lx + sx } else { lx }; + if !h.rect.contains(hx, ly) { + continue; + } + match &h.kind { + DatabaseAuthoringHitKind::CalendarDayDropTarget { day_index } => { + hit_target = Some((block.block_id.clone(), *day_index)); } - _ => None, - }) - { - hit_target = Some((block.block_id.clone(), day_idx)); + DatabaseAuthoringHitKind::KanbanLaneDropTarget { bucket_key, .. } => { + kanban_target = Some((block.block_id.clone(), bucket_key.clone())); + } + _ => {} + } } break; } @@ -584,21 +589,26 @@ impl PlaygroundView { } let mut changed = false; for (bid, st) in &mut self.flow.database_state.ui_states { - let desired = hit_target + let desired_day = hit_target .as_ref() .and_then(|(hb, d)| (hb == bid).then_some(*d)); - if st.calendar_hovered_day != desired { - st.calendar_hovered_day = desired; + if st.calendar_hovered_day != desired_day { + st.calendar_hovered_day = desired_day; + changed = true; + } + let desired_lane = kanban_target + .as_ref() + .and_then(|(hb, k)| (hb == bid).then(|| k.clone())); + if st.kanban_hovered_lane != desired_lane { + st.kanban_hovered_lane = desired_lane; changed = true; } } - if let Some((hb, d)) = hit_target - && self - .flow - .database_state - .set_calendar_hovered_day(&hb, Some(d)) - { - changed = true; + if let Some((hb, d)) = hit_target { + changed |= self.flow.database_state.set_calendar_hovered_day(&hb, Some(d)); + } + if let Some((hb, k)) = kanban_target { + changed |= self.flow.database_state.set_kanban_hovered_lane(&hb, Some(k)); } if changed { self.env_rev += 1; diff --git a/blocksuite/crates/playground/src/database_authoring/tests.rs b/blocksuite/crates/playground/src/database_authoring/tests.rs index fd32adf503..397b9e58ff 100644 --- a/blocksuite/crates/playground/src/database_authoring/tests.rs +++ b/blocksuite/crates/playground/src/database_authoring/tests.rs @@ -21,7 +21,7 @@ use crate::{ room_client::DocState, }; -fn build_e2e_database_doc() -> (DocState, String) { +pub(super) fn build_e2e_database_doc() -> (DocState, String) { let mut doc = DocState::new("e2e-db-auth", 77).expect("doc"); doc.workspace.initialize_meta().unwrap(); doc.workspace diff --git a/blocksuite/crates/playground/src/database_authoring/tests_kanban_and_richtext.rs b/blocksuite/crates/playground/src/database_authoring/tests_kanban_and_richtext.rs index cbc53f7f58..c858746966 100644 --- a/blocksuite/crates/playground/src/database_authoring/tests_kanban_and_richtext.rs +++ b/blocksuite/crates/playground/src/database_authoring/tests_kanban_and_richtext.rs @@ -608,10 +608,11 @@ fn kanban_nonselect_seed_and_cross_lane_drag_work_in_single_undo_step() { #[test] fn kanban_long_card_title_wraps_in_box_and_places_end_caret_on_second_line() { + const LONG_TITLE: &str = "Column Schema & Type Switcher Implementation"; let (mut state, db_id) = seed_authoring_doc(false); { let page = state.workspace.page_mut(HOME_PAGE_ID).unwrap(); - page.set_database_row_title(&db_id, "row-1", "Column Schema & Type Switcher", 18) + page.set_database_row_title(&db_id, "row-1", LONG_TITLE, 18) .unwrap(); page.add_database_row_with_cells( &db_id, @@ -732,7 +733,7 @@ fn kanban_long_card_title_wraps_in_box_and_places_end_caret_on_second_line() { w, cx, ); - let end = "Column Schema & Type Switcher".encode_utf16().count(); + let end = LONG_TITLE.encode_utf16().count(); v.set_selected_text_range(end..end, w, cx); }) .unwrap(); @@ -752,11 +753,11 @@ fn kanban_long_card_title_wraps_in_box_and_places_end_caret_on_second_line() { "display and edit modes must share identical multi-line title height" ); let rich_hit = v.flow.database_active_cell_rich(&db_id).expect("rich_hit"); - let end_u16 = "Column Schema & Type Switcher".encode_utf16().count(); + let end_u16 = LONG_TITLE.encode_utf16().count(); let (_cx_off, caret_line) = rich_hit.text.caret(end_u16); assert_eq!( caret_line, 1, - "end of 'Column Schema & Type Switcher' must sit on wrapped line 1 (second line)" + "end of LONG_TITLE must sit on wrapped line 1 (second line)" ); let ime_bounds = v .database_authoring_input_bounds(end_u16..end_u16, w) diff --git a/blocksuite/crates/playground/src/database_authoring/tests_scalar_edgeless_calendar.rs b/blocksuite/crates/playground/src/database_authoring/tests_scalar_edgeless_calendar.rs index 1a3a76c7b0..5c235aaf0a 100644 --- a/blocksuite/crates/playground/src/database_authoring/tests_scalar_edgeless_calendar.rs +++ b/blocksuite/crates/playground/src/database_authoring/tests_scalar_edgeless_calendar.rs @@ -10,7 +10,10 @@ use ui::{ use crate::{PlaygroundMode, PlaygroundOptions, PlaygroundTheme}; -use super::tests_inline_and_popovers::open_authoring_window; +use super::{ + tests::build_e2e_database_doc, + tests_inline_and_popovers::{open_authoring_window, seed_authoring_doc}, +}; #[test] fn scalar_cell_paints_inside_topbar_offset_edgeless_note_db_unclipped_and_calendar_hover_plus() { @@ -107,10 +110,12 @@ fn scalar_cell_paints_inside_topbar_offset_edgeless_note_db_unclipped_and_calend // 2. Desktop Calendar month view: pointer hover over a non-today day cell sets // `calendar_hovered_day`, and clicking an empty day cell sets `calendar_selected_day`. + let (cal_state, db_id) = build_e2e_database_doc(); app.update(|cx| { win.update(cx, |v, _, cx| { v.dismiss_all_database_authoring(None, cx); - v.set_database_active_view(db_id, "view-calendar", cx); + v.set_document(cal_state, cx); + v.set_database_active_view(&db_id, "v-cal", cx); }) .unwrap(); }); @@ -286,3 +291,132 @@ fn scalar_cell_paints_inside_topbar_offset_edgeless_note_db_unclipped_and_calend .unwrap(); }); } + +#[test] +fn database_three_view_visual_layout_toolbar_kanban_hover_pills_and_table_header() { + use blocksuite_editor::database::{ + DatabaseHitKind, DatabasePrim, DatabaseUiState, layout_database_block, + }; + + let (state, db_id) = seed_authoring_doc(false); + let snap = state + .workspace + .page(crate::HOME_PAGE_ID) + .unwrap() + .read_page_snapshot() + .unwrap(); + let db_data = match &snap.block(&db_id).expect("database block").content { + blocksuite_playground_doc::read::BlockContent::Database(d) => d.clone(), + _ => panic!("expected database block"), + }; + + let (_platform, app, win, _headless) = open_authoring_window( + 1280, + 860, + PlaygroundOptions { + theme: PlaygroundTheme::Light, + ..Default::default() + }, + state, + ); + app.update(|cx| { + win.update(cx, |_v, window, _cx| { + let zero_offset = |_: i64| 0_i32; + let titles = std::collections::BTreeMap::new(); + + // 1. Desktop Table: single-row toolbar (Filter/Sort share y-band with view tabs) + // and outer database container has no grey border. + let table_ui = DatabaseUiState { + active_view_id: Some("v-table".into()), + ..Default::default() + }; + let table_out = layout_database_block( + &db_data, + &table_ui, + 752.0, + PlaygroundTheme::Light, + ui::Direction::Ltr, + crate::FormFactor::Desktop, + false, + 1_773_014_400_000, + &zero_offset, + &titles, + window, + ); + assert!( + matches!(table_out.prims.first(), Some(DatabasePrim::Quad { border: None, .. })), + "outer database container must have border: None" + ); + let tab_y = table_out + .hits + .iter() + .find_map(|h| matches!(h.kind, DatabaseHitKind::SwitchView { .. }).then_some(h.rect.y)) + .expect("view tab hit"); + let filter_y = table_out + .authoring_hits + .iter() + .find_map(|h| { + matches!(h.kind, DatabaseAuthoringHitKind::ToolbarToggleFilter) + .then_some(h.rect.y) + }) + .expect("Filter toolbar hit"); + assert!( + (tab_y - filter_y).abs() <= 4.0, + "Desktop Filter trigger must sit on the same horizontal row as view tabs (tab_y={tab_y}, filter_y={filter_y})" + ); + + // 2. Desktop Kanban: lane footer "+ Add" hidden when unhovered, shown on hover, + // with invariant total block height; multi-select tags wrap horizontally on 1 row. + let mut kanban_idle = DatabaseUiState { + active_view_id: Some("v-kanban".into()), + ..Default::default() + }; + let idle_out = layout_database_block( + &db_data, + &kanban_idle, + 752.0, + PlaygroundTheme::Light, + ui::Direction::Ltr, + crate::FormFactor::Desktop, + false, + 1_773_014_400_000, + &zero_offset, + &titles, + window, + ); + let first_bucket = idle_out + .authoring_hits + .iter() + .find_map(|h| match &h.kind { + DatabaseAuthoringHitKind::KanbanLaneDropTarget { bucket_key, .. } => { + Some(bucket_key.clone()) + } + _ => None, + }) + .expect("Kanban lane drop target"); + kanban_idle.kanban_hovered_lane = Some(first_bucket); + let hovered_out = layout_database_block( + &db_data, + &kanban_idle, + 752.0, + PlaygroundTheme::Light, + ui::Direction::Ltr, + crate::FormFactor::Desktop, + false, + 1_773_014_400_000, + &zero_offset, + &titles, + window, + ); + assert_eq!( + idle_out.height, hovered_out.height, + "hovering a Kanban lane must keep block height invariant" + ); + assert!( + hovered_out.prims.len() > idle_out.prims.len(), + "hovering a Kanban lane must paint the lane header ops and footer Add button" + ); + }) + .unwrap(); + }); +}