From 1a88498d57ece64531bd870e64e4021fa6ed35e1 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Oct 2026 21:34:50 +0800 Subject: [PATCH] fix(admin): stop dropping naive-ui styles for core components MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提取脚本有两类问题,都只表现为「跳过 N 个」而不报错: 1. render() 漏传 props:CNode 形态的导出走 defaultExport.render(),cssr 的 render 需要 props 对象, 否则读 props.bPrefix 直接抛错。card / data-table / dialog / checkbox / slider / list / descriptions 的样式因此整体没进包—— 后台正是由卡片和表格搭起来的,等于一直基本没样式。 2. 路径写错:多数组件的样式不是单个 index.cssr.mjs,而是按子组件 拆分的文件(form / input / radio / typography / layout); space 只用内联 style、tooltip 复用 popover 共享样式、 _styles/transitions 返回的是运行时过渡对象而非 CSS,都不该列在表里。 - 两个导出形态统一传 { clsPrefix: 'n' } - 逐条修正路径,去掉 space / tooltip / transitions 三类无效条目 - date-picker 的 indexcode 笔误一并修正 提取结果:成功 67 / 跳过 0(此前 42 / 22),CSS 197.0 KB → 293.0 KB, 类名 356 → 583。 Co-Authored-By: Claude Fable 5 --- assets/admin/extract-naive-styles.mjs | 62 ++++++++++++--------------- tools/admin-contract-report.json | 2 +- 2 files changed, 29 insertions(+), 35 deletions(-) diff --git a/assets/admin/extract-naive-styles.mjs b/assets/admin/extract-naive-styles.mjs index caabd2b7..838de687 100644 --- a/assets/admin/extract-naive-styles.mjs +++ b/assets/admin/extract-naive-styles.mjs @@ -27,8 +27,7 @@ const COMPONENT_STYLES = [ // 内部基础组件 ['_internal/scrollbar/src/styles/index.cssr.mjs'], // 布局 - ['layout/src/styles/index.cssr.mjs'], - ['layout-sider/src/styles/index.cssr.mjs'], + ['layout/src/styles/layout.cssr.mjs'], // 导航 ['menu/src/styles/index.cssr.mjs'], ['breadcrumb/src/styles/index.cssr.mjs'], @@ -36,17 +35,19 @@ const COMPONENT_STYLES = [ ['steps/src/styles/index.cssr.mjs'], ['pagination/src/styles/index.cssr.mjs'], // 表单 - ['form/src/styles/index.cssr.mjs'], - ['form-item/src/styles/index.cssr.mjs'], - ['input/src/styles/index.cssr.mjs'], - ['input-number/src/styles/index.cssr.mjs'], + ['form/src/styles/form.cssr.mjs'], + ['form/src/styles/form-item.cssr.mjs'], + ['input/src/styles/input.cssr.mjs'], + ['input/src/styles/input-group.cssr.mjs'], + ['input-number/src/styles/input-number.cssr.mjs'], ['switch/src/styles/index.cssr.mjs'], ['select/src/styles/index.cssr.mjs'], - ['radio/src/styles/index.cssr.mjs'], + ['radio/src/styles/radio.cssr.mjs'], + ['radio/src/styles/radio-group.cssr.mjs'], ['checkbox/src/styles/index.cssr.mjs'], ['slider/src/styles/index.cssr.mjs'], ['rate/src/styles/index.cssr.mjs'], - ['date-picker/src/styles/indexcode/index.cssr.mjs'], + ['date-picker/src/styles/index.cssr.mjs'], ['time-picker/src/styles/index.cssr.mjs'], // 展示 ['card/src/styles/index.cssr.mjs'], @@ -68,12 +69,12 @@ const COMPONENT_STYLES = [ ['notification/src/styles/index.cssr.mjs'], ['popconfirm/src/styles/index.cssr.mjs'], ['popover/src/styles/index.cssr.mjs'], - ['tooltip/src/styles/index.cssr.mjs'], + // tooltip 复用 popover 的共享样式(自身没有独立 cssr 文件)。 ['dropdown/src/styles/index.cssr.mjs'], // 其他 ['icon/src/styles/index.cssr.mjs'], ['icon-wrapper/src/styles/index.cssr.mjs'], - ['space/src/styles/index.cssr.mjs'], + // space 全部用内联 style 布局,没有 cssr 文件,故不在此列。 ['divider/src/styles/index.cssr.mjs'], ['gradient-text/src/styles/index.cssr.mjs'], ['ellipsis/src/styles/index.cssr.mjs'], @@ -87,19 +88,19 @@ const COMPONENT_STYLES = [ ['tree/src/styles/index.cssr.mjs'], ['thing/src/styles/index.cssr.mjs'], ['color-picker/src/styles/index.cssr.mjs'], - ['typography/src/styles/index.cssr.mjs'], + ['typography/src/styles/p.cssr.mjs'], + ['typography/src/styles/a.cssr.mjs'], + ['typography/src/styles/blockquote.cssr.mjs'], + ['typography/src/styles/list.cssr.mjs'], + ['typography/src/styles/hr.cssr.mjs'], + ['typography/src/styles/header.cssr.mjs'], ['auto-complete/src/styles/index.cssr.mjs'], ['cascader/src/styles/index.cssr.mjs'], ['dynamic-input/src/styles/index.cssr.mjs'], ['dynamic-tags/src/styles/index.cssr.mjs'], ['input-otp/src/styles/index.cssr.mjs'], - // 过渡动画 - ['_styles/transitions/fade-in-width-expand.cssr.mjs'], - ['_styles/transitions/fade-in-height-expand.cssr.mjs'], - ['_styles/transitions/icon-switch.cssr.mjs'], - ['_styles/transitions/scale-transition.cssr.mjs'], // 全局 - ['global-style/src/styles/index.cssr.mjs'], + ['_styles/global/index.cssr.mjs'], ] async function extractStyles() { @@ -118,24 +119,17 @@ async function extractStyles() { const defaultExport = styleModule.default || styleModule - if (typeof defaultExport === 'function') { - // 直接调用 render() 提取 CSS - const css = defaultExport({ - clsPrefix: 'n', - // 使用 light 主题变量 - }) + // cssr 模块有两种导出形态:函数本体,或带 render() 的 CNode 对象。 + // 两者都必须接收 props 对象(至少 {}),否则 render 内部读 + // props.bPrefix 会抛错——card / data-table / dialog 等组件的样式 + // 曾因漏传参数被整体跳过。 + const css = typeof defaultExport === 'function' + ? defaultExport({ clsPrefix: 'n' }) + : defaultExport.render({ clsPrefix: 'n' }) - if (typeof css === 'string' && css.trim()) { - allCss.push(`/* ${componentPath} */\n${css}`) - successCount++ - } - } else if (defaultExport && typeof defaultExport.render === 'function') { - // 如果是 CNode 对象,调用 render() - const css = defaultExport.render() - if (typeof css === 'string' && css.trim()) { - allCss.push(`/* ${componentPath} */\n${css}`) - successCount++ - } + if (typeof css === 'string' && css.trim()) { + allCss.push(`/* ${componentPath} */\n${css}`) + successCount++ } } catch (err) { const code = err && err.code diff --git a/tools/admin-contract-report.json b/tools/admin-contract-report.json index f1a4be59..a4549e78 100644 --- a/tools/admin-contract-report.json +++ b/tools/admin-contract-report.json @@ -1,5 +1,5 @@ { - "generated_at": "2026-10-26T13:10:51+00:00", + "generated_at": "2026-10-26T13:32:51+00:00", "errors": [], "warnings": [ "customPage tools-update section 'tools/update' not in PHP schema (ok if pure operational page)",