fix(style-source): 面板拉宽后右侧留白 —— 容器撑满 + 详情栏限宽 (1.1.1)
用户反馈:拉宽资源库后右边一大片空白没填充。 根因:宿主 .iwb-full-main 是 display:flex,插件容器 .iwb-full-panel-plugin 是裸 div, 作为 flex 子项默认 flex:0 1 auto ⇒ 宽度按内容算(实测 664px);根元素的 width:100% 只能等于 664,多出来的 380 全空着。 - mount 时按条件补 flex:1 1 0%:仅当「自身没有显式宽度 + 父容器是 flex row」。 无条件设 flex 会把固定宽度的侧栏拉满父容器(之前踩过),所以必须带判据 - 详情栏 46% → 40%,且 clamp 300~380:上限保持不变(用户确认现在宽度合适), 栅格才是浏览主体;1040 宽时栅格 660(5 列)、详情 380,两栏之和正好等于面板宽 - footer 按钮补 min-width:0 + ellipsis,避免超长文案顶出右边缘 - README 补「容器为何要 flex:1 且为何要判据」与详情限宽的理由 - harness 新增 3 条守门: · flex 父容器(1360 - 左栏 320)下容器撑满 1040 · 宽档两栏之和 == 容器宽(无空白) · 一行 ≥4 张且卡片 90~150px(越宽只加列、不撑宽卡片)
This commit is contained in:
1 parent
1ef85e7d55
commit
3969acb9b9
4 files changed
+104
-13
No files matched your search
@@ -68,10 +68,14 @@
|
||||
|
||||
资源库面板宽度不是固定的:侧栏 240–560 可拖、放大窗口 920×600 可八向缩放、还有 embedded 嵌入形态。所以:
|
||||
|
||||
- 网格列数交给 `repeat(auto-fill, minmax(112px, 1fr))`,不写死。
|
||||
- 网格列数交给 `repeat(auto-fill, minmax(112px, 1fr))`,不写死:面板越宽**只加列、不撑宽卡片**(1040 宽时一行 5 张,卡片仍是 ~122px)。
|
||||
- 详情用 **480px 一个拐点**切两种形态(窄=覆盖层 / 宽=右侧栏),**同一个 DOM 只换定位** —— 切档时变量输入和滚动位置不丢。
|
||||
- 宽档详情栏宽度 = `clamp(300px, 40%, 380px)`:**上限 380 是刻意的**,详情是「停下来看」的动作,栅格才是浏览主体,再宽就少一列。
|
||||
- 判定用 `ResizeObserver` 而不是 `@media`:拖侧栏时视口没变,`@media` 完全不响应。
|
||||
- 面板容器 `.iwb-full-panel-plugin` 在宿主 `style.css` 里**没有任何样式定义**(裸 div),所以根元素必须自带 `width/height:100%; min-height:0; display:flex`,否则撑不开或双滚动条。
|
||||
- 面板容器 `.iwb-full-panel-plugin` 在宿主 `style.css` 里**没有任何样式定义**(裸 div):
|
||||
- 根元素自带 `width/height:100%; min-width/height:0; display:flex`;
|
||||
- 容器自身补 `flex:1 1 0%`(**仅当它没有显式宽度、且父容器是 flex row 时**)—— 否则 flex 子项按内容宽收缩,
|
||||
面板拉到 1040 时只占 664,右边留一大片空白;反过来若无条件设 flex,固定宽度的侧栏会被拉满父容器。
|
||||
|
||||
> 侧栏 ↔ 放大窗口是两个不同的 React 位置,同一个插件会被 `mount` 两次(不同 DOM 节点)。DOM 每次重建,但数据 / 图片 blob / 选中项 / 搜索词 / 变量输入都在模块级缓存里,切形态不会重拉 1.1MB JSON、不重下预览图、不丢选中。
|
||||
|
||||
@@ -119,7 +123,7 @@
|
||||
```bash
|
||||
cp src/index.js /tmp/plugin-style-source.js
|
||||
cd ../image-workbench-web
|
||||
node scripts/plugins-publish.mjs /tmp/plugin-<其余插件>.js /tmp/plugin-style-source.js --upload --version style-source=1.0.4
|
||||
node scripts/plugins-publish.mjs /tmp/plugin-<其余插件>.js /tmp/plugin-style-source.js --upload --version style-source=1.0.5
|
||||
```
|
||||
|
||||
图标:宿主 `app.js` 的 `PLUGIN_ICONS` 可加 `'style-source': 'palette'`(不加则用面板 manifest 自带的 `palette`,效果一致)。
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@iwb-plugin/style-source",
|
||||
"private": true,
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "风格库:资源库面板里浏览 310 个 AI 绘画风格(12 分类 / 搜索 / 变量替换),一键把预览图插入画布 ref 节点、把提示词插入 prompt 节点",
|
||||
"ibwPlugin": {
|
||||
"id": "style-source",
|
||||
|
||||
@@ -191,7 +191,11 @@
|
||||
background: var(--iwb-panel, #fff);
|
||||
}
|
||||
.iwb-ss-root[data-layout="narrow"] .iwb-ss-detail.is-open { display: flex; position: absolute; inset: 0; z-index: 5; }
|
||||
.iwb-ss-root[data-layout="wide"] .iwb-ss-detail { display: flex; flex: 0 0 46%; max-width: 380px; border-left: 1px solid var(--iwb-border, #d5d9e0); }
|
||||
/* 宽档详情栏:占 40%,上下限 300~380。上限不能再大 —— 详情是「停下来看」的动作,
|
||||
栅格才是浏览主体;面板拉到 1040 时留 380 给详情,栅格能到 660(5 列),否则少一列。
|
||||
min-width:0 必须有:flex 子项默认 min-width:auto,内容(长标签 / 按钮文字)会把栏撑出右边缘,
|
||||
表现为「插入提示词」按钮最后一个字被裁在面板外。 */
|
||||
.iwb-ss-root[data-layout="wide"] .iwb-ss-detail { display: flex; flex: 0 0 40%; min-width: 300px; max-width: 380px; border-left: 1px solid var(--iwb-border, #d5d9e0); }
|
||||
|
||||
.iwb-ss-dhead {
|
||||
flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
|
||||
@@ -214,7 +218,7 @@
|
||||
flex: 0 0 auto; display: flex; gap: 6px;
|
||||
padding: 8px 10px; border-top: 1px solid var(--iwb-border, #d5d9e0);
|
||||
}
|
||||
.iwb-ss-dfoot .iwb-ss-btn { flex: 1 1 0; height: 30px; }
|
||||
.iwb-ss-dfoot .iwb-ss-btn { flex: 1 1 0; min-width: 0; height: 30px; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; }
|
||||
|
||||
/* 预览图比例差异极大(9:21 竖图到 21:9 横图都有)。不限高的话竖图会撑满详情栏,变量和提示词全被挤到折叠以下。
|
||||
用 contain 而不是 cover:宁可两侧留底色,也不裁掉画面 —— 用户是来参考构图的。 */
|
||||
@@ -543,16 +547,23 @@
|
||||
ensureStyle()
|
||||
ensureNodeCapStyle(ctx)
|
||||
host.innerHTML = ''
|
||||
// ⚠️ 宿主给的面板容器 .iwb-full-panel-plugin 是裸 div,没任何样式,flex 子项的 min-width 默认 auto。
|
||||
// 分类 chips 是单行不换行(13 个),它的 max-content 约 950px,会把容器顶到 950,
|
||||
// 资源中心窗口只有 680 左右 ⇒ 搜索框、chips 尾巴、状态栏全被裁在右边。
|
||||
// 补上 min-width:0 允许收缩 + flex:1 填满剩余,插件根才有正确的宽度可依。
|
||||
// 只给「可收缩」许可,不设 flex 宽度/方向:容器在不同宿主位置(资源中心 flex row / 侧栏 flex column)语义不同,
|
||||
// 写死 flex:1 会在固定宽度的侧栏里被拉满整个父容器。
|
||||
// ⚠️ 宿主给的面板容器 .iwb-full-panel-plugin 是裸 div,没任何样式,flex 子项默认 flex:0 1 auto:
|
||||
// ① min-width auto + 13 个分类 chips 单行不换行(max-content≈950px)⇒ 容器被顶宽,右侧被裁;
|
||||
// ② 反过来,父容器(.iwb-full-main,display:flex)宽 1040 时它只按**内容宽度**占 664,
|
||||
// 插件的 width:100% 只能等于 664 ⇒ 右边留一大片空白(用户拉宽窗口后最明显)。
|
||||
// 所以两件事都要做:允许收缩(min-width:0)+ 明确占满剩余空间(flex:1 1 0%,basis 0 才不吃内容宽度)。
|
||||
// ⚠️ 但只在「自身没有显式宽度 + 父容器是 flex row」时才设 flex:宿主侧栏里容器可能带固定宽度,
|
||||
// 无条件 flex:1 会把它拉到父容器满宽(2026-11-02 之前的坑)。
|
||||
host.style.minWidth = '0'
|
||||
host.style.minHeight = '0'
|
||||
host.style.height = '100%'
|
||||
host.style.overflow = 'hidden'
|
||||
try {
|
||||
const parent = host.parentElement
|
||||
const cs = parent && global.getComputedStyle ? global.getComputedStyle(parent) : null
|
||||
const isRow = cs && cs.display.indexOf('flex') >= 0 && /^row/.test(String(cs.flexDirection || ''))
|
||||
if (isRow && !host.style.width) host.style.flex = '1 1 0%'
|
||||
} catch (error) { /* 拿不到父容器样式就维持原生行为 */ }
|
||||
|
||||
const ui = {
|
||||
root: null, search: null, chips: null, grid: null, detail: null, status: null, toastEl: null,
|
||||
@@ -966,7 +977,7 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'style-source',
|
||||
name: '风格库',
|
||||
version: '1.1.0',
|
||||
version: '1.1.1',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'canvas', 'canvasWrite'],
|
||||
settings: {
|
||||
|
||||
@@ -550,6 +550,82 @@ async function main() {
|
||||
check('第二个容器 920px 挂载即判定 wide', dual.layoutB === 'wide', String(dual.layoutB))
|
||||
check('styles.json 总计仍只请求过一次', dataHits === 1, 'hits=' + dataHits)
|
||||
|
||||
// ---- 回归守门:宿主资源中心的容器是 flex 子项,插件容器不能「按内容宽度收缩」 ----
|
||||
// 真实宿主:.iwb-full-main{display:flex} > .iwb-full-panel-plugin(裸 div,无 width)。
|
||||
// 之前只给了 min-width:0,容器按内容算出 664px,而父容器 1040 ⇒ 右侧留一大片空白。
|
||||
const flexFill = await page.evaluate(() => {
|
||||
const stage = document.getElementById('stage')
|
||||
const wrap = document.createElement('div')
|
||||
// position:fixed 让它脱离 stage 的 flex 布局(stage 已被 hostA/hostB 占满,放进去会被 shrink 压窄);
|
||||
// pointer-events:none 防止它盖住 hostA 导致后续点击超时。
|
||||
// 尺寸按用户实际场景取:总宽 1360 - 左栏 320 = 面板 1040
|
||||
wrap.style.cssText = 'display:flex;position:fixed;left:0;top:0;width:1360px;height:640px;z-index:9999;background:#fff;pointer-events:none'
|
||||
const left = document.createElement('div')
|
||||
left.style.cssText = 'flex:0 0 320px'
|
||||
const hostC = document.createElement('div')
|
||||
hostC.id = 'hostC'
|
||||
wrap.appendChild(left)
|
||||
wrap.appendChild(hostC)
|
||||
stage.appendChild(wrap)
|
||||
window.__hostC = hostC
|
||||
window.__calls.panels[0].mount(hostC)
|
||||
const r = hostC.querySelector('.iwb-ss-root')
|
||||
const grid = hostC.querySelector('.iwb-ss-grid')
|
||||
return {
|
||||
hostW: Math.round(hostC.getBoundingClientRect().width),
|
||||
rootW: Math.round(r.getBoundingClientRect().width),
|
||||
gridW: Math.round(grid.getBoundingClientRect().width),
|
||||
avail: 1360 - 320,
|
||||
}
|
||||
})
|
||||
check('flex 父容器下插件容器撑满剩余宽度(不再按内容宽度收缩)',
|
||||
Math.abs(flexFill.rootW - flexFill.avail) <= 2 && Math.abs(flexFill.hostW - flexFill.avail) <= 2,
|
||||
'host=' + flexFill.hostW + ' root=' + flexFill.rootW + ' 可用=' + flexFill.avail)
|
||||
// 选中一个风格再量:宽档是「左栅格 + 右详情」常驻两栏,两栏之和必须等于容器宽,否则右边就是空白
|
||||
await page.evaluate(() => {
|
||||
const c = window.__hostC.querySelector('.iwb-ss-card')
|
||||
if (c) c.click()
|
||||
})
|
||||
await page.waitForTimeout(320)
|
||||
const flexCols = await page.evaluate(() => {
|
||||
const hostC = window.__hostC
|
||||
const q = (s) => Math.round(hostC.querySelector(s).getBoundingClientRect().width)
|
||||
const cards = Array.from(hostC.querySelectorAll('.iwb-ss-card'))
|
||||
const first = cards[0]
|
||||
const det = hostC.querySelector('.iwb-ss-detail')
|
||||
const foot = hostC.querySelector('.iwb-ss-dfoot')
|
||||
const btn = hostC.querySelectorAll('.iwb-ss-dfoot .iwb-ss-btn')
|
||||
// 同一行的卡片数 = 与第一张 top 相同的卡片数;卡片宽度用来确认「拉宽只加列、不撑宽卡片」
|
||||
return {
|
||||
root: q('.iwb-ss-root'),
|
||||
grid: q('.iwb-ss-grid'),
|
||||
detail: q('.iwb-ss-detail'),
|
||||
detailSW: det ? det.scrollWidth : 0,
|
||||
footW: foot ? Math.round(foot.getBoundingClientRect().width) : 0,
|
||||
footSW: foot ? foot.scrollWidth : 0,
|
||||
btnW: btn.length ? Array.from(btn).map((b) => Math.round(b.getBoundingClientRect().width)) : [],
|
||||
btnSW: btn.length ? Array.from(btn).map((b) => b.scrollWidth) : [],
|
||||
btnFs: btn.length ? Array.from(btn).map((b) => getComputedStyle(b).fontSize) : [],
|
||||
bodyW: hostC.querySelector('.iwb-ss-dbody') ? Math.round(hostC.querySelector('.iwb-ss-dbody').getBoundingClientRect().width) : 0,
|
||||
bodySW: hostC.querySelector('.iwb-ss-dbody') ? hostC.querySelector('.iwb-ss-dbody').scrollWidth : 0,
|
||||
cardW: first ? Math.round(first.getBoundingClientRect().width) : 0,
|
||||
perRow: cards.filter((c) => Math.abs(c.getBoundingClientRect().top - first.getBoundingClientRect().top) < 2).length,
|
||||
}
|
||||
})
|
||||
check('宽档两栏横向无空白(栅格 + 详情 = 容器宽)',
|
||||
Math.abs(flexCols.grid + flexCols.detail - flexCols.root) <= 2,
|
||||
'grid=' + flexCols.grid + ' detail=' + flexCols.detail + ' root=' + flexCols.root)
|
||||
check('面板 1040 时栅格一行 ≥4 张,且卡片不被撑宽(越宽只加列)',
|
||||
flexCols.perRow >= 4 && flexCols.cardW > 90 && flexCols.cardW <= 150,
|
||||
'每行=' + flexCols.perRow + ' 卡片宽=' + flexCols.cardW)
|
||||
check('详情栏内部不横向溢出(按钮/长标签不撑出右边缘)',
|
||||
flexCols.detailSW <= flexCols.detail + 1 && flexCols.footSW <= flexCols.footW + 1,
|
||||
'detail=' + flexCols.detail + '/sw' + flexCols.detailSW + ' body=' + flexCols.bodyW + '/sw' + flexCols.bodySW +
|
||||
' foot=' + flexCols.footW + '/sw' + flexCols.footSW + ' btn=' + JSON.stringify(flexCols.btnW) +
|
||||
'/sw' + JSON.stringify(flexCols.btnSW) + '/fs' + JSON.stringify(flexCols.btnFs))
|
||||
await page.locator('#hostC').screenshot({ path: path.resolve(HERE, 'shot-fill.png') }).catch(() => {})
|
||||
await page.locator('#hostC .iwb-ss-detail').screenshot({ path: path.resolve(HERE, 'shot-detail.png') }).catch(() => {})
|
||||
|
||||
// hostB 挂载后,hostA 的 ResizeObserver 必须仍然有效(这是被抢指针时最先坏掉的地方)
|
||||
await page.evaluate(() => { window.__hostA.style.width = '700px' })
|
||||
const aStillAlive = await poll(async () => {
|
||||
|
||||
Reference in new issue
Block a user