Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(external-sources): add externalSourcesEmbedCss config option to set embed css on external sources iframe #769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nd0ut
Copy link
Member

@nd0ut nd0ut commented Dec 24, 2024

Description

Checklist

Summary by CodeRabbit

  • New Features

    • Introduced a new configuration option for embedding CSS for external sources.
    • Enhanced the ExternalSource functionality to dynamically apply embedded CSS and manage themes.
  • Bug Fixes

    • Updated type representation for CSS in the output message to simplify handling.
  • Documentation

    • Added new property to configuration type definitions for better clarity on external source styling options.

…o set embed css on external sources iframe
Copy link
Contributor

coderabbitai bot commented Dec 24, 2024

Walkthrough

The pull request introduces a new configuration option externalSourcesEmbedCss for handling CSS embedding in external sources. This change spans multiple files, adding type definitions, configuration mapping, and implementation logic to support dynamic CSS embedding. The modification allows users to specify custom CSS for external sources, enhancing the flexibility of styling external content within the application.

Changes

File Change Summary
blocks/Config/initialConfig.js Added externalSourcesEmbedCss property initialized as an empty string
blocks/Config/normalizeConfigValue.js Added mapping for externalSourcesEmbedCss with asString normalization
blocks/ExternalSource/ExternalSource.js - Added applyEmbedCss method
- Renamed applyStyles to applyTheme
- Updated initCallback and handleIframeLoad methods
blocks/ExternalSource/types.js Changed css property type from Partial<ThemeDefinition> to string
types/exported.d.ts Added externalSourcesEmbedCss: string to ConfigType

Sequence Diagram

sequenceDiagram
    participant User
    participant Config
    participant ExternalSource
    participant MessageBridge

    User->>Config: Set externalSourcesEmbedCss
    Config->>ExternalSource: Trigger initCallback
    ExternalSource->>MessageBridge: Send applyEmbedCss
    MessageBridge->>ExternalSource: Apply CSS to external source
Loading

Poem

🐰 A rabbit's ode to CSS delight,
Embedding styles with all my might!
External sources now can shine,
With custom themes that intertwine,
A configuration so bright! 🎨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nd0ut nd0ut requested a review from egordidenko December 24, 2024 11:47
Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
blocks/ExternalSource/ExternalSource.js (1)

163-164: Recheck load sequence for consistency

Calling applyEmbedCss before applyTheme is fine, but confirm there's no conflict between the two operations. For instance, if the embedded CSS overrides theme variables, verify that the outcome is intentional.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57ab42a and 1be2a09.

📒 Files selected for processing (5)
  • blocks/Config/initialConfig.js (1 hunks)
  • blocks/Config/normalizeConfigValue.js (1 hunks)
  • blocks/ExternalSource/ExternalSource.js (2 hunks)
  • blocks/ExternalSource/types.js (1 hunks)
  • types/exported.d.ts (1 hunks)
🔇 Additional comments (6)
blocks/Config/initialConfig.js (1)

21-21: Great addition to the initial configuration

By introducing externalSourcesEmbedCss, we now provide a straightforward way to embed arbitrary CSS in external iframes. This makes styling more flexible.

blocks/ExternalSource/types.js (1)

139-139: Confirm switch from object-based to string-based CSS

Switching from Partial<ThemeDefinition> to a simple string type offers broad styling flexibility, but it removes structured or type-checked constraints. Ensure that any validations or sanitizations are performed upstream if needed.

blocks/Config/normalizeConfigValue.js (1)

116-116: String normalization for externalSourcesEmbedCss

Mapping externalSourcesEmbedCss to asString correctly aligns with its usage in the external source's logic. This is a straightforward approach, and no issues are apparent.

blocks/ExternalSource/ExternalSource.js (2)

109-112: Watch for untrusted CSS

Subscribing to externalSourcesEmbedCss and applying it through applyEmbedCss is a valuable feature. However, ensure no untrusted input is passed to avoid unexpected styling or potential CSS injection.


169-186: New applyEmbedCss method is well-designed

The applyEmbedCss(css) method accurately sends a set-embed-css message. This keeps the logic consistent with how the theme definition is sent, fostering a clear separation of concerns.

types/exported.d.ts (1)

35-35: Consider adding a doc comment or making this property optional
If externalSourcesEmbedCss is not strictly required in all usage scenarios, it can be marked as optional. Alternatively, consider adding a short doc comment to clarify its purpose and usage, for instance:

+  /**
+   * Custom CSS applied on embedded external sources (e.g., iframes). 
+   * If not set, defaults to an empty string.
+   */
  externalSourcesEmbedCss: string;

Check whether any usage in the codebase expects this property to always be defined. If not, making it optional might be more flexible. To verify:

✅ Verification successful

Property has a default value and is used safely - can be documented but optional flag not needed

The verification shows that externalSourcesEmbedCss is well-handled in the codebase:

  • It has a default empty string value in blocks/Config/initialConfig.js
  • It's normalized using asString in blocks/Config/normalizeConfigValue.js
  • It's safely used in ExternalSource.js through subConfigValue and applyEmbedCss

Given this implementation, the property doesn't need to be optional since it always has a value. However, documenting the default value would be helpful:

+  /**
+   * Custom CSS applied on embedded external sources (e.g., iframes).
+   * Defaults to an empty string.
+   */
  externalSourcesEmbedCss: string;
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for references to `externalSourcesEmbedCss` in the entire repository
rg -A 4 "externalSourcesEmbedCss"

Length of output: 1554

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

Successfully merging this pull request may close these issues.

2 participants