dsh-skill-hub 0.3.1 → 0.3.2
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/lib/client.js +38 -1
- package/lib/client.js.map +1 -1
- package/lib/types/client/slash-dots.d.ts +0 -8
- package/package.json +1 -1
- package/src/client/slash-dots.tsx +48 -3
package/lib/client.js
CHANGED
|
@@ -1066,17 +1066,54 @@ window.__ModuleLoader__.load({
|
|
|
1066
1066
|
* @param scope - hub settings scope for the dot colors.
|
|
1067
1067
|
* @returns a disposer restoring the original candidates.
|
|
1068
1068
|
*/
|
|
1069
|
+
/**
|
|
1070
|
+
* DOM 兜底:在 alpha.2 新版 MenuView(icon 仅枚举)下通过直接操作
|
|
1071
|
+
* 已渲染的 `[role="option"]` 列表注入彩色点,绕过 `icon` 限制。
|
|
1072
|
+
* 旧版仍走 `icon` 注入,此处仅为新版。
|
|
1073
|
+
*/
|
|
1074
|
+
function injectDotsViaDOM(modelByName, modelColor, userColor) {
|
|
1075
|
+
if (typeof document === "undefined" || typeof requestAnimationFrame === "undefined") return;
|
|
1076
|
+
const run = () => {
|
|
1077
|
+
const options = document.querySelectorAll("[role=\"option\"]");
|
|
1078
|
+
for (const opt of options) {
|
|
1079
|
+
if (opt.querySelector("[data-skill-dot]") !== null) continue;
|
|
1080
|
+
const nameEl = opt.querySelector("[class*=\"itemName\"]");
|
|
1081
|
+
if (nameEl === null) continue;
|
|
1082
|
+
const name = (nameEl.textContent ?? "").trim();
|
|
1083
|
+
if (name.length === 0) continue;
|
|
1084
|
+
if (!modelByName.has(name) && nameEl.textContent !== name) continue;
|
|
1085
|
+
const color = modelByName.get(name) ?? true ? modelColor : userColor;
|
|
1086
|
+
const dot = document.createElement("span");
|
|
1087
|
+
dot.setAttribute("data-skill-dot", "");
|
|
1088
|
+
dot.setAttribute("aria-hidden", "true");
|
|
1089
|
+
dot.style.display = "inline-block";
|
|
1090
|
+
dot.style.width = "6px";
|
|
1091
|
+
dot.style.height = "6px";
|
|
1092
|
+
dot.style.borderRadius = "3px";
|
|
1093
|
+
dot.style.background = color;
|
|
1094
|
+
dot.style.flex = "none";
|
|
1095
|
+
const iconEl = opt.querySelector("[class*=\"itemIcon\"]");
|
|
1096
|
+
if (iconEl !== null && iconEl.nextSibling !== null) iconEl.parentElement?.insertBefore(dot, iconEl.nextSibling);
|
|
1097
|
+
else nameEl.parentElement?.insertBefore(dot, nameEl);
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
requestAnimationFrame(() => setTimeout(run, 0));
|
|
1101
|
+
}
|
|
1069
1102
|
function wrapSkillSource(source, api, scope) {
|
|
1070
1103
|
const original = source.candidates;
|
|
1071
1104
|
source.candidates = async (session, req) => {
|
|
1072
1105
|
const items = await original(session, req);
|
|
1073
1106
|
if (req.signal.aborted) return items;
|
|
1074
|
-
|
|
1107
|
+
const isNewHost = req !== null && typeof req === "object" && "drilled" in req;
|
|
1075
1108
|
const modelByName = await modelInvocableMap(api);
|
|
1076
1109
|
if (req.signal.aborted) return items;
|
|
1077
1110
|
const snapshot = scope.getSnapshot();
|
|
1078
1111
|
const modelColor = snapshot.value?.dotModelColor ?? "#2f81f7";
|
|
1079
1112
|
const userColor = snapshot.value?.dotUserColor ?? "#3fb950";
|
|
1113
|
+
if (isNewHost) {
|
|
1114
|
+
injectDotsViaDOM(modelByName, modelColor, userColor);
|
|
1115
|
+
return items;
|
|
1116
|
+
}
|
|
1080
1117
|
return items.map((item) => ({
|
|
1081
1118
|
...item,
|
|
1082
1119
|
icon: dotIcon(modelByName.get(item.name) ?? true ? modelColor : userColor)
|