@nestim/koishi-plugin-qqgm-webui 0.2.19 → 0.2.20
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/index.js +1 -1
- package/lib/main-schema.js +17 -2
- package/package.json +1 -1
- package/public/app.js +20 -4
- package/public/styles.css +19 -1
package/index.js
CHANGED
package/lib/main-schema.js
CHANGED
|
@@ -17,6 +17,13 @@ function loadMainPlugin() {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
function humanLabel(key, description) {
|
|
21
|
+
const text = String(description || '').replace(/\s+/g, ' ').trim();
|
|
22
|
+
const first = text.split(/[::((]/)[0].trim();
|
|
23
|
+
if (first && first.length >= 2 && first.length <= 28) return first;
|
|
24
|
+
return key;
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
function fieldInfo(key, field) {
|
|
21
28
|
const meta = field.meta || {};
|
|
22
29
|
const type = String(field.type || 'string');
|
|
@@ -24,14 +31,22 @@ function fieldInfo(key, field) {
|
|
|
24
31
|
if (type === 'union') {
|
|
25
32
|
for (const match of String(field).matchAll(/"([^"]+)"/g)) options.push(match[1]);
|
|
26
33
|
}
|
|
34
|
+
const description = meta.description || '';
|
|
35
|
+
const defaultValue = meta.default;
|
|
36
|
+
const long = type === 'string' && (
|
|
37
|
+
/prompt|system|persona|template|greeting|welcome|instruction|rule/i.test(key)
|
|
38
|
+
|| (typeof defaultValue === 'string' && defaultValue.length > 60)
|
|
39
|
+
);
|
|
27
40
|
return {
|
|
28
41
|
key,
|
|
42
|
+
label: humanLabel(key, description),
|
|
29
43
|
type,
|
|
30
|
-
description
|
|
31
|
-
default:
|
|
44
|
+
description,
|
|
45
|
+
default: defaultValue,
|
|
32
46
|
options,
|
|
33
47
|
sensitive: /key|token|secret|password/i.test(key),
|
|
34
48
|
json: type === 'array' || type === 'object' || type === 'intersect',
|
|
49
|
+
long,
|
|
35
50
|
};
|
|
36
51
|
}
|
|
37
52
|
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -350,24 +350,40 @@ function renderMainGroup(index) {
|
|
|
350
350
|
form.innerHTML = `<div class="form-head"><div><h2>${group.title}</h2><p>${group.fields.length} 个字段 · 与 Koishi 配置页同源</p></div><span class="status ok">运行中</span></div>`
|
|
351
351
|
+ group.fields.map((field) => {
|
|
352
352
|
const value = mainSchema.values[field.key] ?? field.default;
|
|
353
|
+
const esc = (text) => String(text == null ? '' : text).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
353
354
|
let control = '';
|
|
354
355
|
if (field.type === 'boolean') {
|
|
355
|
-
control = `<input type="checkbox" data-key="${field.key}" data-kind="boolean" ${value ? 'checked' : ''}
|
|
356
|
+
control = `<label class="switch"><input type="checkbox" data-key="${field.key}" data-kind="boolean" ${value ? 'checked' : ''} /><i></i><span>${value ? '已开启' : '已关闭'}</span></label>`;
|
|
356
357
|
} else if (field.type === 'union') {
|
|
357
358
|
const options = (field.options.length ? field.options : [String(value || '')]).map((opt) => `<option ${String(value) === opt ? 'selected' : ''}>${opt}</option>`).join('');
|
|
358
359
|
control = `<select data-key="${field.key}" data-kind="string">${options}</select>`;
|
|
359
360
|
} else if (field.type === 'number') {
|
|
360
361
|
control = `<input type="number" data-key="${field.key}" data-kind="number" value="${value ?? field.default ?? 0}" />`;
|
|
361
362
|
} else if (field.json) {
|
|
362
|
-
control = `<textarea rows="
|
|
363
|
+
control = `<textarea rows="5" class="json-input" data-key="${field.key}" data-kind="json">${esc(JSON.stringify(value ?? field.default ?? (field.type === 'array' ? [] : {}), null, 2))}</textarea>`;
|
|
364
|
+
} else if (field.long) {
|
|
365
|
+
control = `<textarea rows="7" data-key="${field.key}" data-kind="string">${esc(value ?? field.default ?? '')}</textarea>`;
|
|
363
366
|
} else {
|
|
364
|
-
control = `<input ${field.sensitive ? 'type="password"' : ''} data-key="${field.key}" data-kind="string" value="${
|
|
367
|
+
control = `<input ${field.sensitive ? 'type="password"' : ''} data-key="${field.key}" data-kind="string" value="${esc(value ?? field.default ?? '')}" />`;
|
|
365
368
|
}
|
|
366
|
-
return `<div class="schema-field
|
|
369
|
+
return `<div class="schema-field ${field.long ? 'long' : ''}">
|
|
370
|
+
<div class="schema-field-info">
|
|
371
|
+
<div class="schema-field-title">${esc(field.label || field.key)}</div>
|
|
372
|
+
<p class="schema-field-desc">${esc(field.description || '')}</p>
|
|
373
|
+
<code class="schema-field-key">${field.key}</code>
|
|
374
|
+
</div>
|
|
375
|
+
<div class="schema-field-control">${control}</div>
|
|
376
|
+
</div>`;
|
|
367
377
|
}).join('')
|
|
368
378
|
+ `<div class="form-foot"><span>保存只改本组字段;写前备份 koishi.yml,重启后生效</span></div>`;
|
|
369
379
|
const save = $('#saveMainSchemaGroup');
|
|
370
380
|
if (save) save.onclick = () => saveMainGroup(group);
|
|
381
|
+
$$('#mainSchemaForm .switch input').forEach((input) => {
|
|
382
|
+
input.addEventListener('change', () => {
|
|
383
|
+
const text = input.parentElement?.querySelector('span');
|
|
384
|
+
if (text) text.textContent = input.checked ? '已开启' : '已关闭';
|
|
385
|
+
});
|
|
386
|
+
});
|
|
371
387
|
}
|
|
372
388
|
|
|
373
389
|
async function saveMainGroup(group) {
|
package/public/styles.css
CHANGED
|
@@ -304,7 +304,25 @@ code { background: #f2f5f9; color: #55657d; border-radius: 4px; padding: 1px 4px
|
|
|
304
304
|
.word-list { display: flex; flex-wrap: wrap; gap: 7px; }
|
|
305
305
|
.word-list span { display: inline-flex; align-items: center; gap: 5px; background: #f3f6fb; border: 1px solid #e6ecf5; color: #53647b; border-radius: 6px; padding: 5px 8px; font-size: 10.5px; }
|
|
306
306
|
.word-list button { color: #a6b2c2; font-size: 12px; line-height: 1; }
|
|
307
|
-
.schema-field {
|
|
307
|
+
.schema-field { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; align-items: start; padding: 18px 2px; border-bottom: 1px solid #f1f4f8; }
|
|
308
|
+
.schema-field.long { grid-template-columns: 1fr; gap: 10px; }
|
|
309
|
+
.schema-field-info { min-width: 0; }
|
|
310
|
+
.schema-field-title { font-size: 12.5px; font-weight: 650; color: #2f4058; margin-bottom: 5px; }
|
|
311
|
+
.schema-field-desc { margin: 0 0 7px; font-size: 10.5px; color: #8a98ab; line-height: 1.6; }
|
|
312
|
+
.schema-field-key { display: inline-block; font-size: 9px; color: #a0adbe; background: #f5f7fa; border: 1px solid #eef2f7; border-radius: 4px; padding: 2px 5px; }
|
|
313
|
+
.schema-field-control { min-width: 0; padding-top: 1px; }
|
|
314
|
+
.schema-field-control > input:not([type=checkbox]), .schema-field-control > select, .schema-field-control > textarea { width: 100%; }
|
|
315
|
+
.schema-field-control > input:not([type=checkbox]), .schema-field-control > select { height: 36px; border: 1px solid #e2e8f1; border-radius: 8px; background: #fbfcfe; padding: 0 10px; font-size: 12px; color: #3b4b61; outline: none; }
|
|
316
|
+
.schema-field-control > textarea { border: 1px solid #e2e8f1; border-radius: 8px; background: #fbfcfe; padding: 9px 10px; font-size: 12px; color: #3b4b61; outline: none; resize: vertical; line-height: 1.65; font-family: inherit; }
|
|
317
|
+
.schema-field-control > textarea:focus, .schema-field-control > input:focus, .schema-field-control > select:focus { border-color: #9ab7ef; background: #fff; }
|
|
318
|
+
.schema-field .json-input { font-family: Consolas, monospace; font-size: 10.5px; }
|
|
319
|
+
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
|
|
320
|
+
.switch input { display: none; }
|
|
321
|
+
.switch i { width: 34px; height: 19px; border-radius: 20px; background: #dfe5ee; position: relative; transition: .15s; }
|
|
322
|
+
.switch i::after { content: ""; position: absolute; width: 15px; height: 15px; border-radius: 50%; background: #fff; left: 2px; top: 2px; box-shadow: 0 1px 3px rgba(20,35,55,.2); transition: .15s; }
|
|
323
|
+
.switch input:checked + i { background: #4f7df3; }
|
|
324
|
+
.switch input:checked + i::after { transform: translateX(15px); }
|
|
325
|
+
.switch span { font-size: 10.5px; color: #9aa7b8; }
|
|
308
326
|
.schema-field .field > span { flex: 0 0 200px; font-family: Consolas, monospace; font-size: 10.5px; color: #3f5270; }
|
|
309
327
|
.schema-field .field input:not([type=checkbox]), .schema-field .field select, .schema-field .field textarea { width: 100%; }
|
|
310
328
|
.form-hint { margin: 5px 0 0 200px; font-size: 9.5px; color: #9aa7b8; line-height: 1.5; }
|