feat(DockView): support switching layouts - #1126
Open
ArgoZhang wants to merge 23 commits into
Open
Conversation
This reverts commit 2b43179.
- reset 前整体清空抽屉按钮容器(:scope > 限定直接子元素),避免 onDidLayoutFromJSON 重建后累积 - 浮动组位置恢复与抽屉重建解耦:位置缺失跳过防解构抛错,抽屉重建无条件执行 - 布局切换判定收敛到 C# 侧显式调用 switchLayout,update 仅做增量更新 - removeDrawerBtn 空值保护;纯 LayoutConfig 用法的空集合守卫(C#/JS 各处) - GetLayoutContents 空集合守卫,防 _components[0] 越界
Reviewer's GuideAdds named declarative layouts with server/client selection, explicit runtime switching, layout-specific persistence, and defensive reconstruction of panels, floating groups, sizing, and drawer controls while preserving existing unnamed single-layout behavior. Sequence diagram for runtime DockView layout switchingsequenceDiagram
participant Blazor as DockViewV2
participant JS as DockViewV2.js
participant Dock as DockView
participant Config as LayoutConfig
Blazor->>Blazor: GetLayoutContents()
Blazor->>JS: switchLayout(id, options)
JS->>Dock: switchLayout(options)
Dock->>Dock: reset(options)
Dock->>Config: getRootContent(options)
Config-->>Dock: selected layout content
Dock->>Dock: fromJSON(layout)
Dock->>Dock: syncLayoutToContainer()
Dock-->>Blazor: render selected layout
Flow diagram for defensive DockView layout reconstructionflowchart TD
Reset["reset(options)"] --> Clear["Remove drawer buttons"]
Clear --> Init["Initialize selected layout"]
Init --> Empty{"Root content exists?"}
Empty -->|No| Fallback["Create empty grid"]
Empty -->|Yes| Build["Build panels from selected root"]
Fallback --> Measure["syncLayoutToContainer()"]
Build --> Measure
Measure --> Token["Validate layout sequence"]
Token -->|Current| Rebuild["Restore floating groups and drawer controls"]
Token -->|Superseded| Stop["Discard stale callback"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/components/BootstrapBlazor.DockView/Components/DockViewComponent.razor" line_range="4-22" />
<code_context>
- }
-</div>
+@* 多布局下同一组件会在各布局重复声明(仅一处有内容);无条件渲染外壳会产生同 key 空 div,导致 querySelector 命中空壳 *@
+@if (ChildContent != null)
+{
+ <div id="@Id" class="bb-dockview-panel" data-bb-key="@Key" data-bb-title="@Title">
+ @if (TitleTemplate != null)
+ {
+ <div class="bb-dockview-item-title">
+ @TitleTemplate
+ </div>
+ }
+ else if (ShowTitleBar)
+ {
</code_context>
<issue_to_address>
**issue (broader_impact):** When a `DockViewComponent` has no child content, the entire panel shell and its title bar are omitted. This changes the previous behavior, where the shell and title bar were still rendered, so valid title-only or otherwise content-less panels are no longer discoverable or renderable by DockView.
**Triggers:** When an unnamed single-layout configuration contains a component with `ChildContent == null`.
**Suggested fix:** Only suppress duplicate shells when the component is a known inactive layout declaration; preserve shell rendering for the existing single-layout case.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- postLayoutInit:浮窗位置恢复/观察器挂载/inited 门控从 setTimeout(0) 提前到 initDockviewFromConfig 返回后同步执行 - 可见性通知/loadTabs/initialized 改为微任务发出(早于绘制,消除队列空等约50ms) - 抽屉外点关闭改为实例级单次绑定,修复重复绑定 - onDidLayoutFromJSON 仅保留 markFirstVisibleElement,重建后处理收敛到 postLayoutInit 单处维护
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link issues
fixes #1125
Summary By Copilot
LayoutNameto DockViewV2 and its child layout definitions for runtime layout selectionRegression?
Existing unnamed single-layout usage and its local-storage key format remain unchanged.
Risk
The change updates layout reconstruction, drawer lifecycle, panel selection, and persisted-layout behavior. Guards preserve existing single-layout behavior and handle empty or superseded layouts.
Verification
Manual (required)
Automated
built BootstrapBlazor.DockView for all target frameworks with no warnings or errors
checked all six changed JavaScript modules with Node.js syntax validation
checked the branch diff for whitespace errors
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Enable DockView applications to select and switch between named layouts while preserving existing single-layout behavior.
New Features:
Bug Fixes:
Enhancements:
Build: