Skip to content

feat(bubble): add provider-level box and content attributes#332

Open
gene9831 wants to merge 1 commit intoopentiny:developfrom
gene9831:feat/bubble-provider-attributes
Open

feat(bubble): add provider-level box and content attributes#332
gene9831 wants to merge 1 commit intoopentiny:developfrom
gene9831:feat/bubble-provider-attributes

Conversation

@gene9831
Copy link
Copy Markdown
Collaborator

@gene9831 gene9831 commented Apr 23, 2026

背景

当前如果想给所有 Box / Content 统一注入 attributes,只依赖 renderer match 不够稳定,因为无法保证所有消息都会匹配到自定义 renderer。

改动

  • BubbleProvider 新增 boxAttributescontentAttributes
  • 支持静态对象和基于上下文的动态 resolver
  • Box / Content 两条渲染链路统一支持 attributes 合并
  • 补齐 useBubbleContentRenderer 的 attributes 返回能力
  • 更新文档并新增 demo 展示 provider 级 attributes 的用法

验证

  • 已新增 demo:docs/demos/bubble/provider-attributes.vue

Summary by CodeRabbit

  • New Features

    • Added support for injecting custom attributes into bubble elements via provider-level configuration using box-attributes and content-attributes props
    • Attributes can be defined as static objects or dynamic resolver functions based on message and content context
  • Documentation

    • Added comprehensive documentation and interactive demo showing attribute injection capabilities for bubble providers

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 23, 2026

Walkthrough

This change introduces provider-level attribute injection to the Bubble chat component system. It adds optional boxAttributes and contentAttributes configuration to BubbleProvider, enabling dynamic attribute resolution based on message and content context. These resolved attributes are merged with renderer-level attributes during rendering, with comprehensive documentation and a demo component.

Changes

Cohort / File(s) Summary
Type System Updates
packages/components/src/bubble/index.type.ts, packages/components/src/bubble/constants.ts
Extended type definitions to support attribute injection: introduced BubbleAttributes, BubbleBoxAttributesResolver, BubbleContentAttributesResolver, and their config types; changed attributes field type from Record<string, string> to BubbleAttributes; added two new injection keys for provider/inject integration.
Renderer Composables
packages/components/src/bubble/composables/useBubbleBoxRenderer.ts, packages/components/src/bubble/composables/useBubbleContentRenderer.ts
Enhanced composables to support provider-level attribute resolution: setupBubbleBoxRenderer and setupBubbleContentRenderer now accept optional attribute config; composables resolve attributes dynamically, merge provider attributes with match attributes, and return both renderer and resolved attributes from the computed result.
Provider & Wrapper Components
packages/components/src/bubble/BubbleProvider.vue, packages/components/src/bubble/BubbleBoxWrapper.vue, packages/components/src/bubble/BubbleContentWrapper.vue
Integrated attribute injection into component lifecycle: provider passes attribute resolvers to composables; wrappers updated to handle computed component props and apply attributes; BubbleContentWrapper now uses computed to build props from renderer attributes.
Documentation & Demo
docs/src/components/bubble.md, docs/demos/bubble/provider-attributes.vue
Added documentation for new boxAttributes and contentAttributes props; included demo component illustrating attribute injection with click-to-inspect functionality that displays resolved data-* attributes as JSON.

Sequence Diagram(s)

sequenceDiagram
    participant App as User Application
    participant Provider as BubbleProvider
    participant Composable as useBubbleBoxRenderer
    participant Config as Attribute Config
    participant Wrapper as BubbleBoxWrapper
    participant Renderer as Selected Renderer

    App->>Provider: Initialize with boxAttributes config
    Provider->>Composable: Call setupBubbleBoxRenderer(renderers, boxAttributes)
    Composable->>Config: Provide injection key with config
    
    Wrapper->>Composable: useBubbleBoxRenderer(message, contentIndex)
    Composable->>Config: Inject and resolve attributes from config
    Config-->>Composable: Return resolved attributes
    
    Composable->>Composable: Merge provider attributes with match.attributes
    Composable-->>Wrapper: Return {renderer, attributes}
    
    Wrapper->>Renderer: Apply v-bind="attributes"
    Renderer->>Renderer: Render with merged attributes
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 Attributes now flow from the provider's heart,
Each box and content gets a dynamic part!
Merging attributes with elegant grace,
Bubbles adorned in their proper place.
Demo included to show the way—
A-*ttributes dancing throughout the day! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding provider-level box and content attributes to the bubble component system.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/src/components/bubble.md (1)

213-226: Consider documenting the Box wrapper's reserved attributes.

This section describes provider↔match merge precedence, but does not mention that the Box wrapper still applies its own data-role/data-placement/data-shape on top of the merged attributes (see related note on BubbleBoxWrapper.vue). If that override is intentional, a one-line callout here would prevent surprises for users who try to set those specific keys via box-attributes.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/src/components/bubble.md` around lines 213 - 226, Add a one-line callout
under the BubbleProvider attributes section clarifying that the Box wrapper
applies reserved attributes and may override provider/match attributes:
explicitly mention BubbleBoxWrapper.vue reserves data-role, data-placement, and
data-shape on the Box and that those keys set by box-attributes or match-level
attributes will be overridden by the wrapper's values; reference BubbleProvider,
box-attributes, content-attributes and BubbleBoxWrapper.vue so readers know
where the behavior originates.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/components/src/bubble/BubbleBoxWrapper.vue`:
- Around line 16-22: The wrapper currently binds renderer.attributes before the
explicit :data-role/:data-placement/:data-shape props, causing
props.role/placement/shape to always override any same-named entries in
renderer.attributes; either revert the order (move v-bind="renderer.attributes"
after the explicit bindings) so provider/match-supplied attributes win, or if
the override is intentional, document that BubbleBoxWrapper reserves these
structural attributes (mention renderer.renderer, renderer.attributes, and
props.role/props.placement/props.shape) and update docs to describe the
merge/precedence rule.

---

Nitpick comments:
In `@docs/src/components/bubble.md`:
- Around line 213-226: Add a one-line callout under the BubbleProvider
attributes section clarifying that the Box wrapper applies reserved attributes
and may override provider/match attributes: explicitly mention
BubbleBoxWrapper.vue reserves data-role, data-placement, and data-shape on the
Box and that those keys set by box-attributes or match-level attributes will be
overridden by the wrapper's values; reference BubbleProvider, box-attributes,
content-attributes and BubbleBoxWrapper.vue so readers know where the behavior
originates.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 84913a30-f025-449e-a095-efabec5f30c5

📥 Commits

Reviewing files that changed from the base of the PR and between 6a8bf29 and 8e20fce.

📒 Files selected for processing (9)
  • docs/demos/bubble/provider-attributes.vue
  • docs/src/components/bubble.md
  • packages/components/src/bubble/BubbleBoxWrapper.vue
  • packages/components/src/bubble/BubbleContentWrapper.vue
  • packages/components/src/bubble/BubbleProvider.vue
  • packages/components/src/bubble/composables/useBubbleBoxRenderer.ts
  • packages/components/src/bubble/composables/useBubbleContentRenderer.ts
  • packages/components/src/bubble/constants.ts
  • packages/components/src/bubble/index.type.ts

Comment thread packages/components/src/bubble/BubbleBoxWrapper.vue
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

✅ Preview build completed successfully!

Click the image above to preview.
Preview will be automatically removed when this PR is closed.

@github-actions
Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant