Skip to content

feat(Vditor): support edit form#771

Merged
ArgoZhang merged 2 commits intomasterfrom
feat-vditor
Dec 3, 2025
Merged

feat(Vditor): support edit form#771
ArgoZhang merged 2 commits intomasterfrom
feat-vditor

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Dec 3, 2025

Link issues

fixes #752

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Integrate Vditor with a dedicated inner container element and adjust styling and reinitialization logic to target that container rather than the outer wrapper.

Enhancements:

  • Change Vditor initialization and reset to mount onto a dedicated .bb-vditor-container element within the component markup.
  • Update Vditor-related CSS selectors so validation styles apply specifically to the inner .vditor element instead of the outer wrapper container.

Copilot AI review requested due to automatic review settings December 3, 2025 02:14
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Dec 3, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the Vditor component to render the editor inside a dedicated container element and updates styling selectors accordingly, ensuring validation styles apply to the inner Vditor instance while preserving re-initialization behavior.

Sequence diagram for updated Vditor initialization and reset

sequenceDiagram
    actor BlazorComponent
    participant JSModule as JSModule_Vditor_razor_js
    participant DOM as Document
    participant DataStore as DataModule
    participant VditorClass as Vditor

    BlazorComponent->>JSModule: init(id, invoke, options)
    JSModule->>DOM: getElementById(id)
    DOM-->>JSModule: el
    JSModule->>JSModule: addLink(css)
    JSModule->>JSModule: addScript(js)
    JSModule->>DOM: el.querySelector(.bb-vditor-container)
    DOM-->>JSModule: root
    JSModule->>VditorClass: new Vditor(root, getOptions(invoke, optionsWithValue))
    VditorClass-->>JSModule: vditorInstance
    JSModule->>DataStore: set(id, { el, invoke, vditor })
    DataStore-->>JSModule: stored
    JSModule-->>BlazorComponent: vditorInstance

    BlazorComponent->>JSModule: reset(id, value, options)
    JSModule->>DataStore: get(id)
    DataStore-->>JSModule: { el, invoke, vditor }
    JSModule->>VditorClass: vditor.destroy()
    JSModule->>DOM: el.querySelector(.bb-vditor-container)
    DOM-->>JSModule: root
    JSModule->>VditorClass: new Vditor(root, getOptions(invoke, optionsWithValue))
    VditorClass-->>JSModule: newVditorInstance
    JSModule->>DataStore: update(id, { el, invoke, vditor })
    DataStore-->>JSModule: updated
    JSModule-->>BlazorComponent: newVditorInstance
Loading

Flow diagram for updated Vditor DOM structure and styling

flowchart TD
    A[bb_vditor_root_div
class: ClassString
id: Id] --> B[bb_vditor_container_div
class: bb-vditor-container]
    B --> C[vditor_inner_root
class: vditor
created by Vditor]

    subgraph ValidationClasses[Validation state on bb_vditor_root_div]
        D[bb-vditor_root_div.hasClass is-invalid] --> E[CSS selector
.bb-vditor.is-invalid .vditor]
        F[bb-vditor_root_div.hasClass is-valid] --> G[CSS selector
.bb-vditor.is-valid .vditor]
    end

    E --> C
    G --> C

    subgraph Styles[Border styling applied to inner vditor]
        H[.bb-vditor .vditor] --> I[border-radius
overflow hidden]
        E --> J[border-color: bs-danger]
        G --> K[border-color: bs-success]
    end

    C --> I
    C --> J
    C --> K
Loading

File-Level Changes

Change Details Files
Instantiate Vditor against a nested container element instead of the root host div, and ensure re-initialization uses the same container.
  • Query the nested .bb-vditor-container element from the component root before creating a Vditor instance.
  • Pass the nested container element to the Vditor constructor instead of the root element id.
  • On reset, reuse the stored root element to re-query .bb-vditor-container before constructing a new Vditor instance after destroy.
src/components/BootstrapBlazor.Vditor/Vditor.razor.js
Update Vditor CSS to target the internal .vditor element within the component wrapper for border radius and validation colors.
  • Change selectors from .bb-vditor to .bb-vditor .vditor so styles apply specifically to the inner Vditor element.
  • Adjust validation state selectors so .is-invalid and .is-valid modify the inner .vditor border color instead of the wrapper.
src/components/BootstrapBlazor.Vditor/wwwroot/css/vditor.css
Wrap the Vditor host with an internal container element that serves as the mount point for the JS Vditor instance.
  • Nest a div.bb-vditor-container inside the main Vditor root div while preserving existing attributes, classes, and id on the root.
  • Keep label rendering logic unchanged so only the internal layout and mount point are affected.
src/components/BootstrapBlazor.Vditor/Vditor.razor

Assessment against linked issues

Issue Objective Addressed Explanation
#752 Fix the Vditor layout/style bug when used in a table edit form (double-binding scenario), where the toolbar becomes misaligned and occupies most of the popup.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the bug Something isn't working label Dec 3, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Dec 3, 2025
@ArgoZhang ArgoZhang merged commit 4cb96db into master Dec 3, 2025
5 of 6 checks passed
@ArgoZhang ArgoZhang deleted the feat-vditor branch December 3, 2025 02:14
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • In both init and reset, consider guarding against el.querySelector('.bb-vditor-container') returning null and either throwing a clearer error or no-oping, to avoid a hard runtime crash if the markup is ever changed or misused.
  • Since reset needs the .bb-vditor-container again, you might store the container element alongside el in Data.set during init to avoid repeated DOM queries and keep the code slightly simpler.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both `init` and `reset`, consider guarding against `el.querySelector('.bb-vditor-container')` returning null and either throwing a clearer error or no-oping, to avoid a hard runtime crash if the markup is ever changed or misused.
- Since `reset` needs the `.bb-vditor-container` again, you might store the container element alongside `el` in `Data.set` during `init` to avoid repeated DOM queries and keep the code slightly simpler.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modifies the Vditor component to support usage within edit forms by restructuring the component's DOM hierarchy. The changes ensure that the Vditor editor is initialized within a dedicated container element rather than directly on the component's root element, allowing for proper form validation styling.

Key Changes:

  • Restructured the Vditor component to use a dedicated container element for editor initialization
  • Updated CSS selectors to target the nested Vditor instance for validation states
  • Bumped package version to 10.0.2

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
vditor.css Updated CSS selectors to target nested .vditor elements for border styling and validation states
Vditor.razor.js Modified initialization and reset logic to query and use the .bb-vditor-container element instead of the root element
Vditor.razor Added a nested bb-vditor-container div inside the root component element
BootstrapBlazor.Vditor.csproj Incremented version from 10.0.1 to 10.0.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Vditor): Vditor在表格双绑的时候会出现样式异常

2 participants