@robot-admin/layout 2.3.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,153 @@
1
+ # Changelog
2
+
3
+ ## 3.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `createLayoutContext()` and `provideLayout()` to derive the complete reactive layout contract from a settings Store, menus, dark state, brand data, and an optional icon component.
8
+ - Keep the advanced `LayoutContext` API intact while formally deprecating the legacy `C_*Layout` aliases for removal in 4.0.
9
+ - Add browser interaction coverage for SettingsDrawer providers, atomic imports, reset rollback, host-owned cache clearing, and global visual-effect cleanup.
10
+ - Correct integration prerequisites, host-owned setting semantics, migration guidance, architecture diagrams, and stale version references without changing existing layout visuals or interactions.
11
+
12
+ ## 3.0.0
13
+
14
+ ### Major Changes
15
+
16
+ - Release the 3.0 architecture upgrade while preserving the existing Naive UI layouts, interactions, slots, and visual styling.
17
+
18
+ - Add a UI-independent `@robot-admin/layout/core` entrypoint for validated settings and shared contracts.
19
+ - Make layout/store injection and collapsed state work reliably with custom stores and multi-instance hosts.
20
+ - Replace destructive built-in storage clearing with explicit host actions and add stable SettingsDrawer extension slots.
21
+ - Validate complete imported configuration files before applying state and restore host-owned global classes on teardown.
22
+ - Respect the transition enable switch, harden route caching and responsive measurement, and improve built-in menu keyboard semantics.
23
+ - Verify all six layout modes in SSR and validate both ESM and CommonJS package entrypoints before publishing.
24
+
25
+ ## 2.3.2
26
+
27
+ ### Patch Changes
28
+
29
+ - Validate imported settings at runtime, support short hex colors safely, and preserve invalid color input instead of silently turning it black.
30
+ - Use route-segment-aware menu matching so `/users` no longer activates `/users-admin`.
31
+ - Disable cache debug logging and global window helpers by default; add configurable Settings Store ids.
32
+ - Standardize the automatic theme value on `system` and roll back settings if asynchronous theme synchronization fails.
33
+ - Improve menu/drawer keyboard navigation, focus restoration and ARIA state; guard browser and Canvas APIs for SSR or unsupported environments.
34
+ - Synchronize the exported version constant with package version 2.3.2 and add regression tests for the critical settings and routing contracts.
35
+
36
+ ## 2.2.0
37
+
38
+ ### 🐛 Bug 修复
39
+
40
+ - **ReverseHorizontalMixLayout 右侧菜单错位**: 修复右侧菜单显示在底部而非右侧的问题(`.main-area` 添加 `flex-direction: row`)
41
+ - **MixLayout 二级菜单消失**: 修复鼠标离开后二级菜单内容消失的问题(新增 `displayMenuItem` 作为 `hoveredMenuItem` 的 fallback)
42
+ - **MixTopLayout 全局 CSS 泄漏**: 修复 `.main-area`、`.content-layout` 等选择器污染其他布局的问题(嵌套到 `.mix-top-layout-container` 内)
43
+
44
+ ### ✨ 功能优化
45
+
46
+ - **ResponsiveMenu 字符宽度估算**: 区分 CJK 字符(15px)和 ASCII 字符(8px),顶部菜单文字完整显示不截断
47
+ - **ReverseHorizontalMixLayout 折叠动画**: 用 width 过渡替代 Transition,避免黑色闪烁,动画更流畅(0.35s cubic-bezier)
48
+ - **MixLayout 交互模式**: 从悬停触发改为纯点击模式,点击同一菜单切换展开/折叠,点击不同菜单切换内容不关闭
49
+
50
+ ### 🎨 视觉设计
51
+
52
+ - **ReverseHorizontalMixLayout 玻璃质感**: 参考搜索组件样式,应用 indigo 渐变玻璃设计(`linear-gradient` + `backdrop-filter` + 顶部高光线)
53
+ - **pure CSS 图标**: 替换所有 UnoCSS 图标(`i-ri:*`)为纯 CSS 实现(dots-icon、grid-icon、hamburger-icon、collapse-arrow),减少外部依赖
54
+
55
+ ### 📦 依赖
56
+
57
+ - 移除对 UnoCSS 图标的依赖,提升包的独立性
58
+
59
+ ---
60
+
61
+ ## 2.1.0
62
+
63
+ ### Minor Changes
64
+
65
+ - 重构目录结构 + 代码优化
66
+
67
+ - **目录重构**: 6 种布局骨架迁入 `components/layouts/` 子目录,层次更清晰
68
+ - **文件分离**: 每个布局的样式从 `<style>` 标签提取到独立的 `index.scss` 文件
69
+ - **注释统一**: 所有组件注释标准化为 `@robot-admin/layout - ComponentName` 格式
70
+ - **文档优化**: 重写 README,精简核心内容、添加目录树、API 参考更清晰
71
+
72
+ All notable changes to this project will be documented in this file.
73
+
74
+ ## [2.0.2] - 2026-02-11
75
+
76
+ ### 🗑️ Removed
77
+
78
+ - **Dead files**: Removed unused `tsup.config.ts` (actual build uses Vite)
79
+ - **Empty directories**: Removed `composables/`, `core/`, `layouts/` (8 empty directories total)
80
+ - **Unused dependencies**: Removed `vue-router` from peerDependencies and devDependencies (never used in source code)
81
+
82
+ ### 🔧 Fixed
83
+
84
+ - **package.json**:
85
+ - Refined `sideEffects` to `["*.css", "*.scss"]` for better tree-shaking
86
+ - Removed blocking patterns `"*.vue"` and `"src/index.ts"`
87
+ - **Source code**:
88
+
89
+ - `constants/index.ts`: Removed commented-out code, fixed version from `"1.0.0"` to `"2.0.2"`
90
+ - `types/index.ts`: Removed unimplemented `storageKey` option from `SettingsStoreOptions`
91
+ - `stores/settings.ts`:
92
+ - Exported `adjustColor` utility function (was private)
93
+ - Removed redundant `|| false` in collapsed state initialization
94
+ - `data.ts`:
95
+ - Fixed `COLOR_SWATCHES` duplication (now imports from constants)
96
+ - Renamed `LAYOUT_MODES` to `LAYOUT_MODE_OPTIONS` to avoid naming conflict
97
+
98
+ - **SettingsDrawer component**:
99
+
100
+ - Removed unimplemented `storageKey` prop
101
+ - Fixed hardcoded timezone `"XIAn"` → `Intl.DateTimeFormat().resolvedOptions().timeZone`
102
+ - Fixed `handleResetLayout` missing `fixedHeader` and `tagsViewStyle` resets
103
+ - Fixed `handleImportConfig` to use `$patch` instead of `Object.assign` for proper reactivity
104
+
105
+ - **Styles (`settings.scss`)**:
106
+
107
+ - Replaced hardcoded `#409EFF` with `var(--primary-color, #409eff)` for theme color support
108
+ - Replaced hardcoded `rgba(32, 128, 240)` shadows with CSS variable fallbacks
109
+
110
+ - **Build config**:
111
+ - Removed unused `globals` from `vite.config.ts` (no UMD output)
112
+
113
+ ### 📖 Documentation
114
+
115
+ - **README.md**: Fixed multiple inconsistencies with actual code:
116
+ - `themeMode` default: `'system'` → `'light'`
117
+ - `transitionType` default: `'fade'` → `'slide'`
118
+ - `tagsViewHeight` default: `40` → `44`
119
+ - `showFooter` default: `false` → `true`
120
+ - Removed non-existent store properties: `enableWatermark`, `watermarkText`, `enableGrayMode`, `enableColorWeakMode`
121
+ - Removed non-existent methods: `exportSettings()`, `importSettings()`
122
+ - Removed unimplemented feature: "持久化存储"
123
+ - Removed all `storageKey` parameter references
124
+ - Added `adjustColor` utility function documentation
125
+ - Fixed `ThemeMode` type: `'system'` → `'auto'`
126
+
127
+ ### ✨ Enhanced
128
+
129
+ - Exported `adjustColor` utility function for external use
130
+ - Improved CSS variable support for theme customization
131
+
132
+ ---
133
+
134
+ ## [2.0.1] - 2026-02-09
135
+
136
+ ### ✨ Added
137
+
138
+ - Initial v2.0 release with decoupled architecture
139
+ - Complete settings management system
140
+ - SettingsDrawer UI component
141
+ - 6 layout mode presets
142
+ - Theme customization with CSS variables
143
+ - Full TypeScript support
144
+
145
+ ---
146
+
147
+ ## [2.0.0] - 2026-02-09
148
+
149
+ ### 🎉 Initial Release
150
+
151
+ - Layout and settings management system
152
+ - Integration with @robot-admin/theme
153
+ - Naive UI components support
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CHENY
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![npm version](https://img.shields.io/npm/v/@robot-admin/layout.svg)](https://www.npmjs.com/package/@robot-admin/layout)
6
6
  [![license](https://img.shields.io/npm/l/@robot-admin/layout.svg)](https://github.com/ChenyCHENYU/robot-admin-packages/blob/main/LICENSE)
7
7
 
8
- 当前版本:`2.3.2`。
8
+ 当前版本:`3.1.0`。
9
9
 
10
10
  ---
11
11
 
@@ -17,6 +17,7 @@
17
17
  - 🧩 **开箱即用** - 提供 SettingsDrawer 设置抽屉,覆盖外观 / 布局 / 功能配置
18
18
  - 🧭 **菜单展开方式** - 内置传统展开 / 右侧面板两种菜单展开模式配置
19
19
  - 🔌 **插槽系统** - 灵活的 slot 机制,主项目仅关注业务组件
20
+ - 🪄 **精简适配** - `provideLayout()` 从最小宿主输入自动创建完整响应式上下文
20
21
  - 🎨 **CSS 变量同步** - 配置变更自动同步到 CSS 变量,样式实时响应
21
22
  - ♿ **键盘与焦点可访问性** - 抽屉/菜单支持 Escape、方向键、焦点恢复与语义属性
22
23
  - 🛡️ **安全设置导入** - 对枚举、布尔值、数值范围与主题色进行运行时校验
@@ -35,7 +36,7 @@
35
36
  │ LayoutContext (provide/inject)
36
37
 
37
38
  ┌──────────────────────────────────────┐
38
- │ @robot-admin/layout
39
+ │ @robot-admin/layout(Vue + Naive UI)│
39
40
  │ ├─ C_LayoutContainer (智能容器) │
40
41
  │ │ └─ 根据 layoutMode 自动调度 │
41
42
  │ ├─ layouts/ (6 种布局骨架) │
@@ -47,6 +48,12 @@
47
48
  │ │ └─ CardLayout │
48
49
  │ └─ SettingsDrawer (设置 UI) │
49
50
  └──────────────────────────────────────┘
51
+
52
+ ┌──────────────────────────────────────┐
53
+ │ @robot-admin/layout/core │
54
+ │ 设置协议、运行时校验、常量和纯函数 │
55
+ │ 不依赖 Vue / Pinia / UI 框架 │
56
+ └──────────────────────────────────────┘
50
57
  ```
51
58
 
52
59
  ---
@@ -57,6 +64,10 @@
57
64
  src/
58
65
  ├── index.ts # 主入口(统一导出)
59
66
  ├── setup.ts # 一键初始化 setupLayout()
67
+ ├── core/ # 无框架设置协议、校验与纯函数
68
+ │ ├── index.ts
69
+ │ ├── settings.ts
70
+ │ └── types.ts
60
71
  ├── components/
61
72
  │ ├── C_LayoutContainer/ # 智能布局容器(主入口组件)
62
73
  │ │ └── index.vue
@@ -91,6 +102,7 @@ src/
91
102
  │ └── MenuTrigger/ # 菜单触发区域
92
103
  ├── composables/
93
104
  │ ├── useLayoutContext.ts # LayoutContext provide/inject
105
+ │ ├── createLayoutContext.ts # 最小宿主输入适配助手
94
106
  │ ├── useLayoutCache.ts # 页面缓存管理
95
107
  │ └── useMenuSplit.ts # 菜单拆分(一级/二级分离)
96
108
  ├── stores/
@@ -110,10 +122,13 @@ src/
110
122
  ## 📦 安装
111
123
 
112
124
  ```bash
113
- bun add @robot-admin/layout @robot-admin/theme naive-ui
125
+ bun add @robot-admin/layout naive-ui
114
126
  ```
115
127
 
116
- **Peer Dependencies**: `vue ^3.4` · `vue-router ^4.0` · `pinia ^2.0 || ^3.0` · `naive-ui ^2.38` · `@robot-admin/theme ^0.3 || ^0.4`
128
+ **Peer Dependencies**: `vue ^3.4` · `vue-router ^4.0` · `pinia ^2.0 || ^3.0` · `naive-ui ^2.38`
129
+
130
+ > 3.0 仍完整保留现有 Naive UI 组件、交互和样式。状态校验等无 UI 能力可从
131
+ > `@robot-admin/layout/core` 独立导入,为后续适配其他 UI 框架预留稳定边界;当前版本不包含 Element Plus 视图适配器。
117
132
 
118
133
  ---
119
134
 
@@ -126,18 +141,15 @@ bun add @robot-admin/layout @robot-admin/theme naive-ui
126
141
  import { createApp } from "vue";
127
142
  import { createPinia } from "pinia";
128
143
  import { setupLayout } from "@robot-admin/layout";
129
- import { useThemeStore } from "@robot-admin/theme";
130
- import "@robot-admin/layout/style"; // 导入样式
144
+ import "@robot-admin/layout/style"; // 导入样式
131
145
  import App from "./App.vue";
132
146
 
133
147
  const app = createApp(App);
134
148
  app.use(createPinia());
135
149
 
136
- const themeStore = useThemeStore();
137
- themeStore.init();
138
-
139
150
  setupLayout(app, {
140
- onThemeModeChange: (mode) => themeStore.setMode(mode),
151
+ // 可选:同步到宿主自己的主题系统
152
+ onThemeModeChange: (mode) => syncAppTheme(mode),
141
153
  defaults: {
142
154
  layoutMode: "side",
143
155
  primaryColor: "#409eff",
@@ -147,14 +159,15 @@ setupLayout(app, {
147
159
  app.mount("#app");
148
160
  ```
149
161
 
150
- ### 2. 使用布局容器
162
+ ### 2. 提供宿主数据并使用布局容器
151
163
 
152
164
  ```vue
153
- <!-- src/components/C_Layout/index.vue -->
154
165
  <template>
155
166
  <C_LayoutContainer>
156
167
  <template #logo><AppLogo /></template>
157
- <template #menu="{ collapsed }"><AppMenu :collapsed="collapsed" /></template>
168
+ <template #menu="{ collapsed }"
169
+ ><AppMenu :collapsed="collapsed"
170
+ /></template>
158
171
  <template #header><AppHeader /></template>
159
172
  <template #tags-view><AppTags /></template>
160
173
  <template #footer><AppFooter /></template>
@@ -162,51 +175,91 @@ app.mount("#app");
162
175
  </template>
163
176
 
164
177
  <script setup lang="ts">
165
- import { C_LayoutContainer } from "@robot-admin/layout";
178
+ import {
179
+ C_LayoutContainer,
180
+ provideLayout,
181
+ useSettingsStore,
182
+ type MenuOptions,
183
+ } from "@robot-admin/layout";
184
+
185
+ const props = defineProps<{
186
+ menus: MenuOptions[];
187
+ isDark: boolean;
188
+ }>();
189
+
190
+ provideLayout({
191
+ settings: useSettingsStore(),
192
+ menus: () => props.menus,
193
+ isDark: () => props.isDark,
194
+ brand: { name: "My Admin", homePath: "/home" },
195
+ });
166
196
  </script>
167
197
  ```
168
198
 
199
+ `provideLayout()` 会自动桥接布局模式、折叠状态、尺寸、动画和显示开关。只有需要完全
200
+ 自定义响应式来源时,才直接构造 `LayoutContext` 并调用 `provideLayoutContext()`。
201
+
169
202
  ### 3. 添加设置抽屉
170
203
 
171
204
  ```vue
172
205
  <script setup lang="ts">
173
206
  import { ref } from "vue";
207
+ import { NDialogProvider, NMessageProvider } from "naive-ui";
174
208
  import { SettingsDrawer } from "@robot-admin/layout";
175
209
 
176
210
  const visible = ref(false);
211
+ const settingsActions = {
212
+ clearCache: () => localStorage.removeItem("my-app-disposable-cache"),
213
+ };
177
214
  </script>
178
215
 
179
216
  <template>
180
217
  <button @click="visible = true">⚙️ 设置</button>
181
- <SettingsDrawer v-model:show="visible" />
218
+ <NDialogProvider>
219
+ <NMessageProvider>
220
+ <SettingsDrawer v-model:show="visible" :actions="settingsActions">
221
+ <template #appearance-prepend>
222
+ <AppThemeExtension />
223
+ </template>
224
+ </SettingsDrawer>
225
+ </NMessageProvider>
226
+ </NDialogProvider>
182
227
  </template>
183
228
  ```
184
229
 
230
+ `SettingsDrawer` 使用 Naive UI 的 Message/Dialog API,因此必须位于
231
+ `NMessageProvider` 和 `NDialogProvider` 下;应用根部已有 Provider 时无需重复包裹。
232
+
233
+ `SettingsDrawer` 不再自行清空 `localStorage` / `sessionStorage`。缓存清理由宿主通过
234
+ `actions.clearCache` 明确实现,避免误删登录态、语言和业务数据。可用扩展插槽:
235
+ `appearance-prepend/append`、`layout-prepend/after-mode/append`、
236
+ `features-prepend/append`;插槽均暴露当前 `settings`。
237
+
185
238
  ---
186
239
 
187
240
  ## 📐 布局模式
188
241
 
189
- | 模式 | 常量值 | 一级菜单 | 二级菜单 | 适用场景 |
190
- |------|--------|----------|----------|----------|
191
- | **左侧菜单** | `side` | 左侧栏 | 左侧栏(折叠) | 经典后台管理(ERP、CRM) |
192
- | **顶部菜单** | `top` | 顶部横向 | 顶部下拉 | 菜单少,需更宽内容区 |
193
- | **混合布局** | `mix` | 左侧图标栏 | 悬浮弹出 | 一级菜单少,二级多 |
194
- | **顶部混合** | `mix-top` | 左侧图标栏 | 顶部横向 | 全局导航 + 侧边详情 |
195
- | **反转混合** | `reverse-horizontal-mix` | 顶部横向 | 右侧栏 | 特殊需求,右手操作 |
196
- | **卡片布局** | `card-layout` | hover 抽屉 | 网格铺开 | 应用首页 / 工作台 |
242
+ | 模式 | 常量值 | 一级菜单 | 二级菜单 | 适用场景 |
243
+ | ------------ | ------------------------ | ---------- | -------------- | ------------------------ |
244
+ | **左侧菜单** | `side` | 左侧栏 | 左侧栏(折叠) | 经典后台管理(ERP、CRM) |
245
+ | **顶部菜单** | `top` | 顶部横向 | 顶部下拉 | 菜单少,需更宽内容区 |
246
+ | **混合布局** | `mix` | 左侧图标栏 | 悬浮弹出 | 一级菜单少,二级多 |
247
+ | **顶部混合** | `mix-top` | 左侧图标栏 | 顶部横向 | 全局导航 + 侧边详情 |
248
+ | **反转混合** | `reverse-horizontal-mix` | 顶部横向 | 右侧栏 | 特殊需求,右手操作 |
249
+ | **卡片布局** | `card-layout` | hover 抽屉 | 网格铺开 | 应用首页 / 工作台 |
197
250
 
198
251
  ---
199
252
 
200
253
  ## 🎨 主题预设
201
254
 
202
- | 预设 | 主题色 | 图标 |
203
- |------|--------|------|
204
- | 科技蓝 | `#409eff` | 💙 |
205
- | 清新绿 | `#52c41a` | 💚 |
206
- | 商务灰 | `#595959` | 🖤 |
207
- | 活力橙 | `#fa8c16` | 🧡 |
208
- | 优雅紫 | `#722ed1` | 💜 |
209
- | 经典红 | `#f5222d` | ❤️ |
255
+ | 预设 | 主题色 | 图标 |
256
+ | ------ | --------- | ---- |
257
+ | 科技蓝 | `#409eff` | 💙 |
258
+ | 清新绿 | `#52c41a` | 💚 |
259
+ | 商务灰 | `#595959` | 🖤 |
260
+ | 活力橙 | `#fa8c16` | 🧡 |
261
+ | 优雅紫 | `#722ed1` | 💜 |
262
+ | 经典红 | `#f5222d` | ❤️ |
210
263
 
211
264
  ---
212
265
 
@@ -220,10 +273,10 @@ import { useSettingsStore } from "@robot-admin/layout";
220
273
  const settings = useSettingsStore();
221
274
 
222
275
  // 读取
223
- settings.layoutMode; // 'side' | 'top' | 'mix' | ...
224
- settings.menuExpandMode; // 'inline' | 'panel'
225
- settings.primaryColor; // '#409eff'
226
- settings.themeMode; // 'light' | 'dark' | 'system'
276
+ settings.layoutMode; // 'side' | 'top' | 'mix' | ...
277
+ settings.menuExpandMode; // 'inline' | 'panel'
278
+ settings.primaryColor; // '#409eff'
279
+ settings.themeMode; // 'light' | 'dark' | 'system'
227
280
 
228
281
  // 修改
229
282
  settings.layoutMode = "mix";
@@ -235,21 +288,31 @@ settings.resetSettings();
235
288
 
236
289
  ### 设置属性一览
237
290
 
238
- | 属性 | 类型 | 默认值 | 说明 |
239
- |------|------|--------|------|
240
- | `themeMode` | `ThemeMode` | `'light'` | 主题模式 |
241
- | `primaryColor` | `string` | `'#409eff'` | 主题色 |
242
- | `layoutMode` | `LayoutMode` | `'side'` | 布局模式 |
243
- | `menuExpandMode` | `MenuExpandMode` | `'inline'` | 菜单展开方式 |
244
- | `borderRadius` | `BorderRadiusSize` | `'medium'` | 圆角大小 |
245
- | `transitionType` | `TransitionType` | `'slide'` | 页面动画 |
246
- | `fixedHeader` | `boolean` | `true` | 固定头部 |
247
- | `showBreadcrumb` | `boolean` | `true` | 显示面包屑 |
248
- | `showTagsView` | `boolean` | `true` | 显示标签页 |
249
- | `showFooter` | `boolean` | `true` | 显示页脚 |
250
- | `sidebarWidth` | `number` | `220` | 侧边栏宽度 (px) |
251
- | `sidebarCollapsedWidth` | `number` | `64` | 折叠宽度 (px) |
252
- | `headerHeight` | `number` | `56` | 头部高度 (px) |
291
+ | 属性 | 默认值 | 作用方 | 说明 |
292
+ | ----------------------- | ----------- | ----------- | ---------------------------- |
293
+ | `themeMode` | `'light'` | 宿主回调 | 标准主题模式 |
294
+ | `primaryColor` | `'#409eff'` | 包内 | 主题色与派生 CSS 变量 |
295
+ | `borderRadius` | `'medium'` | 包内 | 圆角 CSS 变量 |
296
+ | `transitionType` | `'slide'` | 包内 | 页面动画类型 |
297
+ | `enableTransition` | `true` | 包内 | 是否启用页面动画 |
298
+ | `layoutMode` | `'side'` | 包内 | 当前布局模式 |
299
+ | `menuExpandMode` | `'inline'` | 宿主菜单 | 菜单展开方式 |
300
+ | `collapsed` | `false` | 包内/宿主 | 共享侧栏折叠状态 |
301
+ | `fixedHeader` | `true` | 宿主头部 | 固定头部策略 |
302
+ | `showBreadcrumb` | `true` | 宿主头部 | 显示面包屑 |
303
+ | `showBreadcrumbIcon` | `true` | 宿主头部 | 显示面包屑图标 |
304
+ | `showTagsView` | `true` | 包内 | 显示标签页 |
305
+ | `tagsViewHeight` | `44` | 包内 | 标签页高度 (px) |
306
+ | `tagsViewStyle` | `'default'` | 宿主标签页 | 标签页风格 |
307
+ | `showFooter` | `true` | 包内 | 显示页脚 |
308
+ | `sidebarWidth` | `220` | 包内 | 侧边栏宽度 (px) |
309
+ | `sidebarCollapsedWidth` | `64` | 包内 | 折叠宽度 (px) |
310
+ | `headerHeight` | `56` | 包内/宿主 | 头部高度 (px) |
311
+ | `enableHotkeys` | `true` | 宿主扩展 | 是否启用宿主快捷键 |
312
+ | `version` | `'3.1.0'` | 配置元数据 | 当前默认配置来源版本 |
313
+
314
+ “宿主”字段由 Store 和导入导出协议统一维护,但布局包不会越权修改宿主业务组件;这种边界
315
+ 避免重复实现面包屑、快捷键和标签页等业务能力。
253
316
 
254
317
  ### CSS 变量
255
318
 
@@ -270,32 +333,37 @@ settings.resetSettings();
270
333
 
271
334
  ## 🧩 C_LayoutContainer Slots
272
335
 
273
- | Slot 名称 | 说明 | 适用布局 |
274
- |-----------|------|----------|
275
- | `#logo` | 品牌 Logo | 全部 |
276
- | `#menu` | 垂直菜单 | Side |
277
- | `#header` | 完整头部 | Side / Mix |
336
+ | Slot 名称 | 说明 | 适用布局 |
337
+ | --------------- | -------------- | ----------------------------- |
338
+ | `#logo` | 品牌 Logo | 全部 |
339
+ | `#menu` | 垂直菜单 | Side |
340
+ | `#header` | 完整头部 | Side / Mix |
278
341
  | `#header-extra` | 头部右侧操作区 | Top / MixTop / Reverse / Card |
279
- | `#top-menu` | 水平菜单 | Top / MixTop / Reverse |
280
- | `#tags-view` | 标签页 | 全部 |
281
- | `#footer` | 页脚 | 全部 |
282
- | `#brand` | 顶部品牌区 | MixTop |
283
- | `#menu-trigger` | 菜单触发区 | Card |
284
- | `#drawer-menu` | 抽屉菜单 | Card |
342
+ | `#top-menu` | 水平菜单 | Top / MixTop / Reverse |
343
+ | `#tags-view` | 标签页 | 全部 |
344
+ | `#footer` | 页脚 | 全部 |
345
+ | `#brand` | 顶部品牌区 | MixTop |
346
+ | `#menu-trigger` | 菜单触发区 | Card |
347
+ | `#drawer-menu` | 抽屉菜单 | Card |
285
348
 
286
349
  ---
287
350
 
288
351
  ## 📖 类型定义
289
352
 
290
353
  ```typescript
291
- type LayoutMode = "side" | "top" | "mix" | "mix-top" | "reverse-horizontal-mix" | "card-layout";
354
+ type LayoutMode =
355
+ "side" | "top" | "mix" | "mix-top" | "reverse-horizontal-mix" | "card-layout";
292
356
  type MenuExpandMode = "inline" | "panel";
293
357
  type TransitionType = "fade" | "slide" | "zoom" | "none";
294
358
  type BorderRadiusSize = "small" | "medium" | "large";
295
359
  type TagsViewStyle = "default" | "card" | "smart";
296
360
  type ThemeMode = "light" | "dark" | "system";
297
361
 
298
- interface ThemePreset { name: string; icon: string; primaryColor: string; }
362
+ interface ThemePreset {
363
+ name: string;
364
+ icon: string;
365
+ primaryColor: string;
366
+ }
299
367
  interface SettingsStoreOptions {
300
368
  id?: string;
301
369
  defaults?: Partial<SettingsState>;
@@ -328,10 +396,13 @@ export const useSettingsStore = createSettingsStore({
328
396
  从文件、URL 或远端接口加载的设置属于不可信输入,写入 Store 前应先校验:
329
397
 
330
398
  ```typescript
331
- import { sanitizeSettingsPatch, useSettingsStore } from "@robot-admin/layout";
399
+ import { sanitizeLayoutSettingsConfig } from "@robot-admin/layout/core";
400
+ import { useSettingsStore } from "@robot-admin/layout";
332
401
 
333
402
  const imported = JSON.parse(await file.text());
334
- const safePatch = sanitizeSettingsPatch(imported.settings);
403
+ // 一次校验完整文件,失败时不会产生部分状态写入。
404
+ const config = sanitizeLayoutSettingsConfig(imported);
405
+ const safePatch = config.settings ?? {};
335
406
  const settings = useSettingsStore();
336
407
 
337
408
  if (safePatch.themeMode !== undefined) {
@@ -347,6 +418,26 @@ settings.$patch(safePatch);
347
418
  `useLayoutCache()` 默认不会输出开发日志,也不会向 `window` 暴露调试函数;仅在
348
419
  受控的本地开发场景显式设置 `enableDevLog` / `exposeToWindow`。
349
420
 
421
+ ### 3.1 升级说明
422
+
423
+ - 新增 `createLayoutContext()` 与 `provideLayout()`,用于精简普通项目的上下文桥接代码。
424
+ - 原有 `LayoutContext`、`provideLayoutContext()` 和所有组件/插槽继续兼容。
425
+ - `C_SideLayout` 等旧别名已正式标记为废弃,3.x 仍保留,计划在 4.0 移除;请改用
426
+ `SideLayout`、`TopLayout`、`MixLayout`、`MixTopLayout`、
427
+ `ReverseHorizontalMixLayout`、`CardLayout`。
428
+
429
+ ### 3.0 升级说明
430
+
431
+ - 现有根入口、6 种布局、组件名、slot 名和 CSS 入口保持兼容。
432
+ - `LayoutContext.collapsed` 为可选的双向状态;提供后,侧栏与宿主头部共享同一折叠状态。
433
+ - 自定义 Store 可通过 `setupLayout()` 注入,也可用 `SettingsDrawer :store="store"` 显式传入。
434
+ - `enableTransition: false` 现在会真正关闭路由过渡,但保留已选择的动画类型。
435
+ - 缓存清理改为宿主白名单动作;从 2.x 升级时请传入 `actions.clearCache`。
436
+ - `@robot-admin/theme` 不再是 peer dependency;需要主题联动时使用 `onThemeModeChange`。
437
+
438
+ 多 Store 实例可以拥有独立状态,但默认 CSS 变量和设置抽屉的灰度、色弱、水印属于页面级
439
+ 视觉效果;同一页面应由一个布局宿主统一管理,避免多个应用同时争用 `document` 根节点。
440
+
350
441
  ### 单独使用布局骨架
351
442
 
352
443
  ```typescript