diff --git a/promptlib/package.json b/promptlib/package.json index a0d3c74..c86cde9 100644 --- a/promptlib/package.json +++ b/promptlib/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/promptlib", "private": true, - "version": "1.7.1", + "version": "1.7.2", "description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供", "ibwPlugin": { "id": "promptlib", diff --git a/promptlib/src/index.js b/promptlib/src/index.js index 812b2f3..61f2f10 100644 --- a/promptlib/src/index.js +++ b/promptlib/src/index.js @@ -1466,11 +1466,29 @@ left.appendChild(el('label', { class: 'iwb-plp-lrow' }, el('span', { text: '分组' }), groupIn)) left.appendChild(el('label', { class: 'iwb-plp-lrow' }, el('span', { text: '标签' }), tagsIn)) var textIn = el('textarea', { class: 'iwb-input iwb-plp-etext', placeholder: '提示词正文' }) + var hl = el('div', { class: 'iwb-plp-hl' }) + var textWrap = el('div', { class: 'iwb-plp-ewrap' }) + textWrap.appendChild(hl); textWrap.appendChild(textIn) + function paintHl () { + var v = textIn.value || '' + hl.textContent = '' + var re = /[{]([^{}]{1,24})[}]/g, last = 0, m + while ((m = re.exec(v))) { + if (m.index > last) hl.appendChild(document.createTextNode(v.slice(last, m.index))) + hl.appendChild(el('span', { class: 'iwb-plp-hlvar', text: m[0] })) + last = m.index + m[0].length + } + if (last < v.length) hl.appendChild(document.createTextNode(v.slice(last))) + hl.appendChild(document.createTextNode('\n')) + } + textIn.addEventListener('scroll', function () { hl.scrollTop = textIn.scrollTop }) textIn.value = draft.text || '' - var varEd = makeVarsEditor(draft.text || '', draft.vars || [], function (nt) { textIn.value = nt; dirty = true }) + paintHl() + var varEd = makeVarsEditor(draft.text || '', draft.vars || [], function (nt) { textIn.value = nt; dirty = true; paintHl() }) var syncTimer = 0 textIn.addEventListener('input', function () { dirty = true + paintHl() if (syncTimer) clearTimeout(syncTimer) syncTimer = setTimeout(function () { varEd.sync(textIn.value) }, 200) }) @@ -1492,7 +1510,7 @@ }) var mid = el('div', { class: 'iwb-plp-emid' }) mid.appendChild(el('div', { class: 'iwb-plp-etool' }, insVarBtn, el('span', { class: 'iwb-hint', text: '在光标处插入 {变量},并自动聚焦变量名' }))) - mid.appendChild(textIn) + mid.appendChild(textWrap) var split = el('div', { class: 'iwb-plp-esplit', title: '拖动调整变量列宽度' }) var right = el('div', { class: 'iwb-plp-eright' }) right.appendChild(varEd.node) @@ -1684,7 +1702,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.7.1', + version: '1.7.2', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, diff --git a/promptlib/styles.css b/promptlib/styles.css index 4a234e9..9970a6d 100644 --- a/promptlib/styles.css +++ b/promptlib/styles.css @@ -434,3 +434,13 @@ body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webki .iwb-plp-dialog .iwb-plp-lrow span{color:#8a919c;font-size:11.5px} .iwb-plp-dialog .iwb-plp-lrow .iwb-input{background:#fbfcfd;border:1px solid #eceef2;border-radius:8px;height:32px} .iwb-plp-dialog .iwb-plp-lrow .iwb-input:focus{background:#fff;border-color:#cfc3ff} +/* v1.7.2:正文变量高亮(黑粗)+ 说明灰按钮 + 说明背景回归面板底 */ +.iwb-plp-ewrap{position:relative;flex:1 1 auto;min-height:0;display:flex;border-radius:9px;background:#fbfcfd;border:1px solid #eef0f3} +.iwb-plp-ewrap:focus-within{background:#fff;border-color:#cfc3ff;box-shadow:0 0 0 3px rgba(107,77,255,.08)} +.iwb-plp-ewrap .iwb-plp-etext{flex:1 1 auto;min-height:0;border:0;background:transparent;box-shadow:none;color:transparent;caret-color:#1d2129;position:relative;z-index:1;resize:none} +.iwb-plp-ewrap .iwb-plp-etext:focus{background:transparent;border:0;box-shadow:none} +.iwb-plp-hl{position:absolute;inset:0;padding:10px 12px;overflow:hidden;white-space:pre-wrap;word-wrap:break-word;font-size:13px;line-height:1.9;color:#5b6472;pointer-events:none;z-index:0} +.iwb-plp-hlvar{color:#1d2129;font-weight:600} +.iwb-plp-dialog .iwb-plp-vi.is-open{background:#eef0f3;color:#5b6472} +.iwb-plp-dialog .iwb-plp-vdesc{background:transparent;border:1px dashed #dfe3e9} +.iwb-plp-dvar{background:transparent;color:#1d2129;font-weight:600;padding:0}