dsh-skill-hub 0.3.1 → 0.3.3
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 +43 -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,59 @@ 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
|
+
const color = modelByName.get(name) ?? true ? modelColor : userColor;
|
|
1085
|
+
const wrapper = document.createElement("span");
|
|
1086
|
+
wrapper.setAttribute("data-skill-dot", "");
|
|
1087
|
+
wrapper.setAttribute("aria-hidden", "true");
|
|
1088
|
+
wrapper.style.width = "16px";
|
|
1089
|
+
wrapper.style.height = "16px";
|
|
1090
|
+
wrapper.style.display = "inline-flex";
|
|
1091
|
+
wrapper.style.justifyContent = "center";
|
|
1092
|
+
wrapper.style.alignItems = "center";
|
|
1093
|
+
wrapper.style.flex = "none";
|
|
1094
|
+
const dot = document.createElement("span");
|
|
1095
|
+
dot.style.display = "inline-block";
|
|
1096
|
+
dot.style.width = "6px";
|
|
1097
|
+
dot.style.height = "6px";
|
|
1098
|
+
dot.style.borderRadius = "3px";
|
|
1099
|
+
dot.style.background = color;
|
|
1100
|
+
dot.style.flex = "none";
|
|
1101
|
+
wrapper.appendChild(dot);
|
|
1102
|
+
nameEl.parentElement?.insertBefore(wrapper, nameEl);
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
requestAnimationFrame(() => setTimeout(run, 0));
|
|
1106
|
+
}
|
|
1069
1107
|
function wrapSkillSource(source, api, scope) {
|
|
1070
1108
|
const original = source.candidates;
|
|
1071
1109
|
source.candidates = async (session, req) => {
|
|
1072
1110
|
const items = await original(session, req);
|
|
1073
1111
|
if (req.signal.aborted) return items;
|
|
1074
|
-
|
|
1112
|
+
const isNewHost = req !== null && typeof req === "object" && "drilled" in req;
|
|
1075
1113
|
const modelByName = await modelInvocableMap(api);
|
|
1076
1114
|
if (req.signal.aborted) return items;
|
|
1077
1115
|
const snapshot = scope.getSnapshot();
|
|
1078
1116
|
const modelColor = snapshot.value?.dotModelColor ?? "#2f81f7";
|
|
1079
1117
|
const userColor = snapshot.value?.dotUserColor ?? "#3fb950";
|
|
1118
|
+
if (isNewHost) {
|
|
1119
|
+
injectDotsViaDOM(modelByName, modelColor, userColor);
|
|
1120
|
+
return items;
|
|
1121
|
+
}
|
|
1080
1122
|
return items.map((item) => ({
|
|
1081
1123
|
...item,
|
|
1082
1124
|
icon: dotIcon(modelByName.get(item.name) ?? true ? modelColor : userColor)
|