From 9c8e7745f99b3a09c7395f71efa24d5266c8bcb1 Mon Sep 17 00:00:00 2001 From: qiqi Date: Tue, 24 Nov 2026 11:20:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugins):=20=E5=90=8C=E6=AD=A5=E4=BE=BF?= =?UTF-8?q?=E5=88=A9=E8=B4=B4=20sticky=20v1.0.2=EF=BC=88=E8=B4=B4=E5=AD=97?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94+=E8=89=B2=E6=9D=BF=E8=B7=9F?= =?UTF-8?q?=E9=9A=8F=E6=8C=89=E9=92=AE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/index.json | 6 ++--- ...035ca.js => plugin-sticky.d2b0bb7022e2.js} | 27 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) rename plugins/runtime/{plugin-sticky.adadb09035ca.js => plugin-sticky.d2b0bb7022e2.js} (91%) diff --git a/plugins/index.json b/plugins/index.json index 6fcb515..30b08a6 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -64,9 +64,9 @@ }, { "id": "sticky", - "file": "plugin-sticky.adadb09035ca.js", - "version": "1.0.1", - "integrity": "sha256-ra2wkDXK2K1b2G11vmWyOynBLgzFsOmJSuTAUImb0dE=" + "file": "plugin-sticky.d2b0bb7022e2.js", + "version": "1.0.2", + "integrity": "sha256-0rC7cCLiv15UN8vkk1O75JAfspbolXNN4nMsBH+K084=" }, { "id": "style-source", diff --git a/plugins/runtime/plugin-sticky.adadb09035ca.js b/plugins/runtime/plugin-sticky.d2b0bb7022e2.js similarity index 91% rename from plugins/runtime/plugin-sticky.adadb09035ca.js rename to plugins/runtime/plugin-sticky.d2b0bb7022e2.js index d546ef9..21abc80 100644 --- a/plugins/runtime/plugin-sticky.adadb09035ca.js +++ b/plugins/runtime/plugin-sticky.d2b0bb7022e2.js @@ -46,7 +46,10 @@ '.iwb-sticky-pal-sw{width:18px;height:18px;border-radius:50%;border:1px solid rgba(0,0,0,.2);cursor:pointer;padding:0}' + '.iwb-sticky-wheel{grid-column:1/-1;display:flex;justify-content:center;padding-top:8px;border-top:1px solid var(--iwb-border,#d5d9e0)}' + '.iwb-sticky-wheel-btn{cursor:pointer;width:22px;height:22px;border-radius:50%;border:0;padding:0;background:conic-gradient(#e24b4a,#ef9f27,#fac775,#639922,#1d9e75,#378add,#7f77dd,#d4537e,#e24b4a)}' + - '.iwb-sticky-body{flex:1 1 auto;min-height:0;width:100%;box-sizing:border-box;resize:none;border:0;outline:0;background:transparent;color:inherit;font-family:inherit;line-height:1.7;padding:12px;overflow:auto;overflow-wrap:anywhere;cursor:move}' + + // 高度随内容自适应(贴字):不再 flex:1 撑满剩余空间,否则字号大/文字少时 + // 下方留出大片空白;高度由 syncSkeleton 按行数×字号算,宿主外框 height:auto + // 会跟着内容收缩,resize 手柄就能拖到贴字。overflow:hidden 避免自适应高度出滚动条。 + '.iwb-sticky-body{flex:0 0 auto;min-height:1.7em;width:100%;box-sizing:border-box;resize:none;border:0;outline:0;background:transparent;color:inherit;font-family:inherit;line-height:1.7;padding:12px;overflow:hidden;overflow-wrap:anywhere;cursor:move}' + // 与宿主文本节点一致:只读态单击穿透给节点拖动/选中;双击进入编辑才变 text 光标。 // 宿主 style.css 有 `.iwb-node textarea[readonly]{pointer-events:none}`,这里用自身 class 兜底。 '.iwb-sticky-body.iwb-sticky-editing{cursor:text}' + @@ -154,7 +157,10 @@ body.setAttribute('readonly', '') tools.appendChild(minus); tools.appendChild(plus); tools.appendChild(bold); tools.appendChild(dot) - root.appendChild(tools); root.appendChild(pal); root.appendChild(colorInput); root.appendChild(body) + // 色板挂在工具条内(tools 已 position:relative):CSS top:100% 落在调色按钮正下方, + // 而不是贴整个便签底部右下角(那样会盖住宿主 resize 手柄、且离按钮很远)。 + tools.appendChild(pal) + root.appendChild(tools); root.appendChild(colorInput); root.appendChild(body) host.appendChild(root) var st = { root: root, tools: tools, minus: minus, plus: plus, bold: bold, dot: dot, @@ -266,6 +272,20 @@ return st } + // textarea 高度贴字:数据(文本/字号)变了才重算,避免每次 render 都 reflow。 + // 设 auto → 读 scrollHeight → 写回,是 textarea 自适应的标准做法;浏览器里行数/自动换行都算准。 + function fitBody(st, text, size) { + if (st.fitText === text && st.fitSize === size) return + st.fitText = text; st.fitSize = size + var b = st.body + var prev = b.style.height + b.style.height = 'auto' + var h = b.scrollHeight + b.style.height = (h && h > 0 ? h : Math.max(1, text.split('\n').length) * Math.round(size * 1.7) + 24) + 'px' + // 高度没变就不留空字符串(兼容 stub:style.height 是普通对象) + if (!b.style.height && prev) b.style.height = prev + } + function syncSkeleton(st, data) { var bg = data.bgColor || DEFAULT_BG var size = normSize(data.fontSize == null ? DEFAULT_SIZE : data.fontSize) @@ -279,6 +299,7 @@ if (!st.editing && document.activeElement !== st.body && st.body.value !== text) st.body.value = text if (st.body.style.fontSize !== size + 'px') st.body.style.fontSize = size + 'px' if (st.body.style.fontWeight !== String(weight)) st.body.style.fontWeight = String(weight) + fitBody(st, text, size) if (st.bold.className !== 'iwb-sticky-btn' + (weight === 600 ? ' iwb-sticky-btn-on' : '')) { st.bold.className = 'iwb-sticky-btn' + (weight === 600 ? ' iwb-sticky-btn-on' : '') } @@ -365,7 +386,7 @@ global.IWBPluginHost.register({ id: 'sticky', name: '便利贴', - version: '1.0.1', + version: '1.0.2', apiVersion: 1, capabilities: ['panels', 'nodeTypes', 'canvas'], }, function (ctx) {