dsh-per-message-model 0.1.5 → 0.1.6
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 +32 -21
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -118,26 +118,37 @@ window.__ModuleLoader__.load({
|
|
|
118
118
|
* existing chip behavior (color change + title); a single click rolls the
|
|
119
119
|
* model name out from left to right like a scroll (icon rotates by a random
|
|
120
120
|
* angle); clicking again rolls it back (icon rotates back).
|
|
121
|
+
*
|
|
122
|
+
* Implemented WITHOUT React state on purpose: the DSH slot renderer mounts
|
|
123
|
+
* registrants through an error boundary and some hosts do not tolerate
|
|
124
|
+
* hook-based state in dock seats; the unfold/collapse is a pure DOM class
|
|
125
|
+
* toggle plus an inline transform on the icon, so it works in any host.
|
|
121
126
|
*/
|
|
122
127
|
function FooterModelBadge({ useProjection, t }) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const current =
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
128
|
+
let value = null;
|
|
129
|
+
try { value = useProjection("perMessageModel"); } catch (err) { value = null; }
|
|
130
|
+
const hasValue = value !== null && value !== void 0 && typeof value === "object";
|
|
131
|
+
const current = hasValue && typeof value.current === "object" && value.current !== null ? value.current : null;
|
|
132
|
+
const provider = current !== null && typeof current.provider === "string" ? current.provider : null;
|
|
133
|
+
const model = current !== null && typeof current.model === "string" ? current.model : null;
|
|
134
|
+
let label;
|
|
135
|
+
try { label = provider !== null && model !== null ? provider + " / " + model : (typeof t === "function" ? t("badge.unknown") : "model unknown"); }
|
|
136
|
+
catch (err) { label = provider !== null && model !== null ? provider + " / " + model : "model unknown"; }
|
|
137
|
+
const toggle = (event) => {
|
|
138
|
+
const btn = event && event.currentTarget ? event.currentTarget : null;
|
|
139
|
+
if (btn === null) return;
|
|
140
|
+
const labelEl = btn.querySelector('[class*="footer-label"]');
|
|
141
|
+
const iconEl = btn.querySelector('[class*="footer-icon"]');
|
|
142
|
+
const isOpen = btn.getAttribute("aria-expanded") === "true";
|
|
143
|
+
if (isOpen) {
|
|
144
|
+
btn.setAttribute("aria-expanded", "false");
|
|
145
|
+
if (labelEl !== null) labelEl.setAttribute("data-open", "false");
|
|
146
|
+
if (iconEl !== null) iconEl.style.transform = "rotate(0deg)";
|
|
138
147
|
} else {
|
|
139
|
-
|
|
140
|
-
|
|
148
|
+
const deg = Math.round(90 + Math.random() * 180);
|
|
149
|
+
btn.setAttribute("aria-expanded", "true");
|
|
150
|
+
if (labelEl !== null) labelEl.setAttribute("data-open", "true");
|
|
151
|
+
if (iconEl !== null) iconEl.style.transform = "rotate(" + deg + "deg)";
|
|
141
152
|
}
|
|
142
153
|
};
|
|
143
154
|
return createElement("button", {
|
|
@@ -146,22 +157,22 @@ window.__ModuleLoader__.load({
|
|
|
146
157
|
"data-dsh-per-message-model-footer": "true",
|
|
147
158
|
"aria-label": label,
|
|
148
159
|
title: label,
|
|
149
|
-
"aria-expanded":
|
|
160
|
+
"aria-expanded": "false",
|
|
150
161
|
onClick: toggle
|
|
151
162
|
}, [
|
|
152
163
|
createElement("span", {
|
|
153
164
|
key: "icon",
|
|
154
165
|
className: BADGE_PREFIX + "footer-icon",
|
|
155
|
-
style: { transform:
|
|
166
|
+
style: { transform: "rotate(0deg)" }
|
|
156
167
|
}, chipIcon()),
|
|
157
168
|
createElement("span", {
|
|
158
169
|
key: "label",
|
|
159
170
|
className: BADGE_PREFIX + "footer-label",
|
|
160
|
-
"data-open":
|
|
171
|
+
"data-open": "false"
|
|
161
172
|
}, label)
|
|
162
173
|
]);
|
|
163
174
|
}
|
|
164
|
-
//#endregion
|
|
175
|
+
//#endregion //#endregion
|
|
165
176
|
//#region client divider
|
|
166
177
|
/** Fixed Chinese copy for the model-switch divider (user-required). */
|
|
167
178
|
const SWITCH_COPY = "模型切换:";
|