@mushi-mushi/web 1.14.0 → 1.16.0
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/CONTRIBUTING.md +50 -9
- package/README.md +4 -1
- package/dist/index.cjs +2031 -1766
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +60 -90
- package/dist/index.d.ts +60 -90
- package/dist/index.js +2032 -1767
- package/dist/index.js.map +1 -1
- package/dist/mushi.loader.global.js +2133 -0
- package/dist/mushi.loader.global.js.map +1 -0
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -293,6 +293,9 @@ function getAvailableLocales() {
|
|
|
293
293
|
// src/styles.ts
|
|
294
294
|
function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
295
295
|
const isDark = theme === "dark";
|
|
296
|
+
const safeHex = (v) => /^#[0-9a-fA-F]{3,8}$/.test(v) ? v : "";
|
|
297
|
+
const safeAccent = safeHex(accent);
|
|
298
|
+
const safeAccentText = safeHex(accentText);
|
|
296
299
|
const paper = isDark ? "#0F0E0C" : "#F8F4ED";
|
|
297
300
|
const ink = isDark ? "#F2EBDD" : "#0E0D0B";
|
|
298
301
|
const inkMuted = isDark ? "#928B7E" : "#5C5852";
|
|
@@ -300,9 +303,9 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
|
300
303
|
const inkDim = isDark ? "#7A7268" : "#6E6760";
|
|
301
304
|
const rule = isDark ? "rgba(242,235,221,0.10)" : "rgba(14,13,11,0.10)";
|
|
302
305
|
const ruleStrong = isDark ? "rgba(242,235,221,0.18)" : "rgba(14,13,11,0.16)";
|
|
303
|
-
const widgetAccent =
|
|
306
|
+
const widgetAccent = safeAccent || (isDark ? "#FF5A47" : "#E03C2C");
|
|
304
307
|
const widgetAccentWash = isDark ? `${widgetAccent}1F` : `${widgetAccent}14`;
|
|
305
|
-
const widgetAccentInk =
|
|
308
|
+
const widgetAccentInk = safeAccentText || (isDark ? "#FFE5E0" : "#7A1F15");
|
|
306
309
|
const fontDisplay = `'Iowan Old Style', 'Palatino Linotype', 'Palatino', 'Book Antiqua', 'Cambria', Georgia, 'Times New Roman', serif`;
|
|
307
310
|
const fontBody = `system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI Variable Display', 'Segoe UI', sans-serif`;
|
|
308
311
|
const fontMono = `ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, 'Liberation Mono', monospace`;
|
|
@@ -478,8 +481,8 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
|
478
481
|
|
|
479
482
|
@keyframes mushi-pulse {
|
|
480
483
|
0% { box-shadow: 0 0 0 0 ${widgetAccent}; opacity: 1; }
|
|
481
|
-
70% { box-shadow: 0 0 0 8px
|
|
482
|
-
100% { box-shadow: 0 0 0 0
|
|
484
|
+
70% { box-shadow: 0 0 0 8px ${widgetAccent}00; opacity: 0.5; }
|
|
485
|
+
100% { box-shadow: 0 0 0 0 ${widgetAccent}00; opacity: 1; }
|
|
483
486
|
}
|
|
484
487
|
|
|
485
488
|
.mushi-panel {
|
|
@@ -1625,12 +1628,18 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
|
1625
1628
|
position: fixed;
|
|
1626
1629
|
left: 0;
|
|
1627
1630
|
right: 0;
|
|
1628
|
-
height
|
|
1631
|
+
/* min-height (not fixed height) + border-box so the safe-area padding
|
|
1632
|
+
below extends the bar into the notch/home-indicator zone instead of
|
|
1633
|
+
letting content bleed under the status bar (mobile safe-area bleed
|
|
1634
|
+
fix \u2014 Workstream C). Horizontal padding also clears the left/right
|
|
1635
|
+
insets for landscape notches. */
|
|
1636
|
+
box-sizing: border-box;
|
|
1637
|
+
min-height: 36px;
|
|
1629
1638
|
display: flex;
|
|
1630
1639
|
align-items: center;
|
|
1631
1640
|
justify-content: center;
|
|
1632
1641
|
gap: 10px;
|
|
1633
|
-
padding: 0 16px;
|
|
1642
|
+
padding: 0 calc(16px + env(safe-area-inset-right, 0px)) 0 calc(16px + env(safe-area-inset-left, 0px));
|
|
1634
1643
|
font-family: ${fontMono};
|
|
1635
1644
|
font-size: 12px;
|
|
1636
1645
|
letter-spacing: 0.04em;
|
|
@@ -1640,8 +1649,8 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
|
1640
1649
|
animation: mushi-banner-slide-in 0.3s ${easeStamp} both;
|
|
1641
1650
|
}
|
|
1642
1651
|
|
|
1643
|
-
.mushi-banner.top { top: 0; }
|
|
1644
|
-
.mushi-banner.bottom { bottom: 0; }
|
|
1652
|
+
.mushi-banner.top { top: 0; padding-top: env(safe-area-inset-top, 0px); }
|
|
1653
|
+
.mushi-banner.bottom { bottom: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
|
|
1645
1654
|
|
|
1646
1655
|
/* --- neon variant (electric lime \u2014 dev / beta tool aesthetic) --- */
|
|
1647
1656
|
.mushi-banner.neon {
|
|
@@ -1893,10 +1902,35 @@ function getWidgetStyles(theme, accent = "", accentText = "") {
|
|
|
1893
1902
|
.mushi-xapp-app-name{font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;margin:0 0 6px}
|
|
1894
1903
|
.mushi-xapp-group{margin-bottom:14px}
|
|
1895
1904
|
.mushi-label{display:block;font-weight:600;margin-bottom:6px}
|
|
1905
|
+
|
|
1906
|
+
/* \u2500\u2500 Assistant tab (P5) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
1907
|
+
.mushi-assistant{display:flex;flex-direction:column;height:100%;min-height:0;max-height:60vh}
|
|
1908
|
+
.mushi-assistant-log{flex:1;min-height:120px;overflow-y:auto;display:flex;flex-direction:column;gap:8px;padding:4px 2px 8px}
|
|
1909
|
+
.mushi-assistant-greeting{font:400 14px/1.5 ${fontBody};color:${inkMuted};padding:6px 2px}
|
|
1910
|
+
.mushi-assistant-suggestions{display:flex;flex-wrap:wrap;gap:6px;margin-top:4px}
|
|
1911
|
+
.mushi-assistant-chip{background:${widgetAccentWash};color:${widgetAccentInk};border:1px solid ${ruleStrong};border-radius:999px;padding:5px 12px;font-size:12px;cursor:pointer;font-family:${fontBody};transition:background .15s}
|
|
1912
|
+
.mushi-assistant-chip:hover{background:${isDark ? "rgba(255,90,71,0.22)" : "rgba(224,60,44,0.14)"}}
|
|
1913
|
+
.mushi-assistant-chip:focus-visible{outline:2px solid ${widgetAccent};outline-offset:2px}
|
|
1914
|
+
.mushi-assistant-msg{max-width:85%;padding:8px 12px;border-radius:12px;font:400 14px/1.45 ${fontBody};white-space:pre-wrap;word-break:break-word}
|
|
1915
|
+
.mushi-assistant-msg-user{align-self:flex-end;background:${widgetAccent};color:#fff;border-bottom-right-radius:4px}
|
|
1916
|
+
.mushi-assistant-msg-bot{align-self:flex-start;background:${isDark ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.05)"};color:${ink};border-bottom-left-radius:4px}
|
|
1917
|
+
.mushi-assistant-thinking{opacity:0.6;font-size:18px;letter-spacing:2px}
|
|
1918
|
+
.mushi-assistant-error{align-self:flex-start;color:${isDark ? "#F87171" : "#DC2626"};font-size:12px;padding:4px 2px}
|
|
1919
|
+
.mushi-assistant-form{display:flex;align-items:flex-end;gap:8px;border-top:1px solid ${rule};padding-top:8px}
|
|
1920
|
+
.mushi-assistant-input{flex:1;resize:none;max-height:120px;border:1px solid ${ruleStrong};border-radius:10px;padding:8px 12px;font:400 14px/1.4 ${fontBody};background:${paper};color:${ink}}
|
|
1921
|
+
.mushi-assistant-input:focus-visible{outline:2px solid ${widgetAccent};outline-offset:1px}
|
|
1922
|
+
.mushi-assistant-submit{flex-shrink:0;width:36px;height:36px;border:none;border-radius:50%;background:${widgetAccent};color:#fff;font-size:18px;line-height:1;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:transform .15s,opacity .15s}
|
|
1923
|
+
.mushi-assistant-submit:hover{transform:translateY(-1px)}
|
|
1924
|
+
.mushi-assistant-submit:disabled{opacity:0.5;cursor:default;transform:none}
|
|
1925
|
+
.mushi-assistant-submit:focus-visible{outline:2px solid ${widgetAccent};outline-offset:2px}
|
|
1896
1926
|
`;
|
|
1897
1927
|
}
|
|
1898
1928
|
|
|
1899
|
-
// src/
|
|
1929
|
+
// src/version.ts
|
|
1930
|
+
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
1931
|
+
var MUSHI_SDK_VERSION = "1.16.0" ;
|
|
1932
|
+
|
|
1933
|
+
// src/widget-helpers.ts
|
|
1900
1934
|
var CATEGORY_ICONS = {
|
|
1901
1935
|
bug: "\u26A0\uFE0F",
|
|
1902
1936
|
slow: "\u{1F40C}",
|
|
@@ -2016,1735 +2050,1874 @@ function isSubmitShortcut(e) {
|
|
|
2016
2050
|
function escapeHtml(value) {
|
|
2017
2051
|
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
2018
2052
|
}
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
environments: config.environments ?? {},
|
|
2046
|
-
smartHide: config.smartHide ?? false,
|
|
2047
|
-
draggable: config.draggable ?? false,
|
|
2048
|
-
brandFooter: config.brandFooter ?? true,
|
|
2049
|
-
outdatedBanner: config.outdatedBanner ?? "auto",
|
|
2050
|
-
betaMode: config.betaMode ?? {},
|
|
2051
|
-
minDescriptionLength: config.minDescriptionLength ?? 20,
|
|
2052
|
-
dashboardUrl: config.dashboardUrl ?? "",
|
|
2053
|
-
responseSlaLabel: config.responseSlaLabel ?? "",
|
|
2054
|
-
featureRequestCard: config.featureRequestCard ?? true,
|
|
2055
|
-
featureRequestLabel: config.featureRequestLabel ?? "",
|
|
2056
|
-
featureRequestDescription: config.featureRequestDescription ?? "",
|
|
2057
|
-
avoidSelectors: config.avoidSelectors ?? [],
|
|
2058
|
-
categories: config.categories ?? [],
|
|
2059
|
-
accent: config.accent ?? "",
|
|
2060
|
-
accentText: config.accentText ?? ""
|
|
2061
|
-
};
|
|
2062
|
-
this.callbacks = callbacks;
|
|
2063
|
-
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2064
|
-
this.host = document.createElement("div");
|
|
2065
|
-
this.host.id = "mushi-mushi-widget";
|
|
2066
|
-
this.shadow = this.host.attachShadow({ mode: "closed" });
|
|
2067
|
-
}
|
|
2068
|
-
sdkVersion;
|
|
2069
|
-
host;
|
|
2070
|
-
shadow;
|
|
2071
|
-
config;
|
|
2072
|
-
callbacks;
|
|
2073
|
-
locale;
|
|
2074
|
-
isOpen = false;
|
|
2075
|
-
step = "category";
|
|
2076
|
-
/**
|
|
2077
|
-
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
2078
|
-
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
2079
|
-
* after resolving through `resolveBaseCategory()`.
|
|
2080
|
-
*/
|
|
2081
|
-
selectedCategory = null;
|
|
2082
|
-
selectedIntent = null;
|
|
2083
|
-
/**
|
|
2084
|
-
* True when the user took the "Feature request" shortcut. We track this
|
|
2085
|
-
* separately from `selectedCategory='other'` so the Back button on the
|
|
2086
|
-
* details step jumps straight back to the category picker instead of
|
|
2087
|
-
* landing on the intent picker the user explicitly skipped.
|
|
2088
|
-
*/
|
|
2089
|
-
viaFeatureRequest = false;
|
|
2090
|
-
screenshotAttached = false;
|
|
2091
|
-
screenshotCapturing = false;
|
|
2092
|
-
screenshotError = false;
|
|
2093
|
-
allowScreenshotRemove = true;
|
|
2094
|
-
elementSelected = false;
|
|
2095
|
-
elementCapturing = false;
|
|
2096
|
-
submitting = false;
|
|
2097
|
-
/** Hint element injected outside the shadow DOM during element selection. */
|
|
2098
|
-
selectorHint = null;
|
|
2099
|
-
triggerVisible = true;
|
|
2100
|
-
triggerShrunk = false;
|
|
2101
|
-
triggerHiddenByScroll = false;
|
|
2102
|
-
/** Milliseconds since mount — used for the 30s first-time nudge gate. */
|
|
2103
|
-
mountedAt = null;
|
|
2104
|
-
nudgeShown = false;
|
|
2105
|
-
nudgeEl = null;
|
|
2106
|
-
nudgeTimer = null;
|
|
2107
|
-
sdkFreshness = null;
|
|
2108
|
-
reporterReports = [];
|
|
2109
|
-
featureBoard = [];
|
|
2110
|
-
reporterComments = [];
|
|
2111
|
-
selectedReportId = null;
|
|
2112
|
-
reporterLoading = false;
|
|
2113
|
-
reporterError = null;
|
|
2114
|
-
attachedLaunchers = [];
|
|
2115
|
-
smartHideCleanup = null;
|
|
2116
|
-
smartHideTimer = null;
|
|
2117
|
-
/** Captured at the moment of submit so the success ledger metadata
|
|
2118
|
-
* ("REPORT · 14:23:07 JST") doesn't drift while the success step
|
|
2119
|
-
* is on screen. */
|
|
2120
|
-
submittedAt = null;
|
|
2121
|
-
/** Pending success-state + auto-close timers. Tracked so destroy()
|
|
2122
|
-
* can clear them — otherwise a host that unmounts mid-submit leaks
|
|
2123
|
-
* this MushiWidget reference (and re-renders into a detached shadow
|
|
2124
|
-
* root) for up to ~3.3s after destroy. */
|
|
2125
|
-
successTimer = null;
|
|
2126
|
-
autoCloseTimer = null;
|
|
2127
|
-
rewardsState = null;
|
|
2128
|
-
leaderboardEntries = null;
|
|
2129
|
-
leaderboardLoading = false;
|
|
2130
|
-
/** Server-confirmed id for the just-submitted report. Surfaces in
|
|
2131
|
-
* the success step as a copyable receipt + optional deep link to
|
|
2132
|
-
* the Mushi console (when `dashboardUrl` is configured). Cleared
|
|
2133
|
-
* on every new `open()` so a re-opened widget never reuses a
|
|
2134
|
-
* stale id from the previous session. */
|
|
2135
|
-
lastReportId = null;
|
|
2136
|
-
/** True when the just-submitted report was queued offline (no
|
|
2137
|
-
* network, or the API errored and went into the retry queue).
|
|
2138
|
-
* Drives a different success copy so the user knows the report
|
|
2139
|
-
* hasn't actually reached the console yet. */
|
|
2140
|
-
lastSubmitQueuedOffline = false;
|
|
2141
|
-
/** Whether the user has clicked ✕ on the header banner this session. */
|
|
2142
|
-
bannerDismissed = false;
|
|
2143
|
-
/** Persisted FAB position when draggable is enabled. */
|
|
2144
|
-
fabPos = null;
|
|
2145
|
-
/** Cleanup fn for visualViewport keyboard listener. */
|
|
2146
|
-
vvCleanup = null;
|
|
2147
|
-
/** Mushi tester session JWT — set after in-widget sign-in or by mushi.ts. */
|
|
2148
|
-
testerJwt = null;
|
|
2149
|
-
/** Tester identity (public_handle, display_name). */
|
|
2150
|
-
testerInfo = null;
|
|
2151
|
-
/** Cross-app reports for the signed-in tester. */
|
|
2152
|
-
crossAppReports = null;
|
|
2153
|
-
crossAppLoading = false;
|
|
2154
|
-
/** Global leaderboard entries (from mushi_testers, not org-scoped). */
|
|
2155
|
-
globalLeaderboard = null;
|
|
2156
|
-
globalLeaderboardLoading = false;
|
|
2157
|
-
/** Reputation for the signed-in tester. */
|
|
2158
|
-
testerReputation = null;
|
|
2159
|
-
/** Whether an in-widget magic-link email was just sent. */
|
|
2160
|
-
magicLinkSent = false;
|
|
2161
|
-
magicLinkEmail = "";
|
|
2162
|
-
magicLinkError = "";
|
|
2163
|
-
mount() {
|
|
2164
|
-
if (this.host.isConnected) return;
|
|
2165
|
-
this.syncHostChromeState();
|
|
2166
|
-
document.body.appendChild(this.host);
|
|
2167
|
-
this.syncAttachedLaunchers();
|
|
2168
|
-
this.syncSmartHide();
|
|
2169
|
-
this.render();
|
|
2170
|
-
this.mountedAt = Date.now();
|
|
2171
|
-
}
|
|
2172
|
-
getIsMounted() {
|
|
2173
|
-
return this.host.isConnected;
|
|
2174
|
-
}
|
|
2175
|
-
updateConfig(config = {}) {
|
|
2176
|
-
this.config = {
|
|
2177
|
-
...this.config,
|
|
2178
|
-
...config.position ? { position: config.position } : {},
|
|
2179
|
-
...config.anchor !== void 0 ? { anchor: config.anchor } : {},
|
|
2180
|
-
...config.theme ? { theme: config.theme } : {},
|
|
2181
|
-
...config.triggerText !== void 0 ? { triggerText: config.triggerText || "\u{1F41B}" } : {},
|
|
2182
|
-
...config.expandedTitle !== void 0 ? { expandedTitle: config.expandedTitle } : {},
|
|
2183
|
-
...config.mode ? { mode: config.mode } : {},
|
|
2184
|
-
...config.locale ? { locale: config.locale } : {},
|
|
2185
|
-
...config.zIndex !== void 0 ? { zIndex: config.zIndex } : {},
|
|
2186
|
-
...config.trigger ? { trigger: config.trigger } : {},
|
|
2187
|
-
...config.attachToSelector !== void 0 ? { attachToSelector: config.attachToSelector } : {},
|
|
2188
|
-
...config.inset !== void 0 ? { inset: config.inset } : {},
|
|
2189
|
-
...config.respectSafeArea !== void 0 ? { respectSafeArea: config.respectSafeArea } : {},
|
|
2190
|
-
...config.hideOnSelector !== void 0 ? { hideOnSelector: config.hideOnSelector } : {},
|
|
2191
|
-
...config.hideOnRoutes !== void 0 ? { hideOnRoutes: config.hideOnRoutes } : {},
|
|
2192
|
-
...config.environments !== void 0 ? { environments: config.environments } : {},
|
|
2193
|
-
...config.smartHide !== void 0 ? { smartHide: config.smartHide } : {},
|
|
2194
|
-
...config.draggable !== void 0 ? { draggable: config.draggable } : {},
|
|
2195
|
-
...config.brandFooter !== void 0 ? { brandFooter: config.brandFooter } : {},
|
|
2196
|
-
...config.outdatedBanner !== void 0 ? { outdatedBanner: config.outdatedBanner } : {},
|
|
2197
|
-
...config.betaMode !== void 0 ? { betaMode: config.betaMode } : {},
|
|
2198
|
-
...config.minDescriptionLength !== void 0 ? { minDescriptionLength: config.minDescriptionLength } : {},
|
|
2199
|
-
...config.dashboardUrl !== void 0 ? { dashboardUrl: config.dashboardUrl } : {},
|
|
2200
|
-
...config.responseSlaLabel !== void 0 ? { responseSlaLabel: config.responseSlaLabel } : {},
|
|
2201
|
-
...config.featureRequestCard !== void 0 ? { featureRequestCard: config.featureRequestCard } : {},
|
|
2202
|
-
...config.featureRequestLabel !== void 0 ? { featureRequestLabel: config.featureRequestLabel } : {},
|
|
2203
|
-
...config.featureRequestDescription !== void 0 ? { featureRequestDescription: config.featureRequestDescription } : {},
|
|
2204
|
-
// Runtime/dashboard config delivers bannerMessage/bannerLabel via
|
|
2205
|
-
// mergeRuntimeConfig → bannerConfig. The widget is constructed before
|
|
2206
|
-
// that fetch resolves, so this pass-through is what makes server-driven
|
|
2207
|
-
// banner copy actually render.
|
|
2208
|
-
...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {},
|
|
2209
|
-
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2210
|
-
};
|
|
2211
|
-
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2212
|
-
if (this.host.isConnected) this.syncHostChromeState();
|
|
2213
|
-
this.syncAttachedLaunchers();
|
|
2214
|
-
this.syncSmartHide();
|
|
2215
|
-
this.render();
|
|
2216
|
-
}
|
|
2217
|
-
// ─── Custom category helpers ──────────────────────────────────────────────
|
|
2218
|
-
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
2219
|
-
resolveCustomCategory(id) {
|
|
2220
|
-
return this.config.categories?.find((c) => c.id === id);
|
|
2221
|
-
}
|
|
2222
|
-
/**
|
|
2223
|
-
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
2224
|
-
* used for the report wire format. Falls back to `'other'`.
|
|
2225
|
-
*/
|
|
2226
|
-
resolveBaseCategory(id) {
|
|
2227
|
-
const BUILTIN = ["bug", "slow", "visual", "confusing", "other"];
|
|
2228
|
-
if (BUILTIN.includes(id)) return id;
|
|
2229
|
-
const custom = this.resolveCustomCategory(id);
|
|
2230
|
-
return custom?.baseCategory ?? "other";
|
|
2231
|
-
}
|
|
2232
|
-
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
2233
|
-
categoryIcon(id) {
|
|
2234
|
-
const custom = this.resolveCustomCategory(id);
|
|
2235
|
-
if (custom?.icon) return custom.icon;
|
|
2236
|
-
return CATEGORY_ICONS[id] ?? "\u{1F4AC}";
|
|
2237
|
-
}
|
|
2238
|
-
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
2239
|
-
categoryLabel(id) {
|
|
2240
|
-
const custom = this.resolveCustomCategory(id);
|
|
2241
|
-
if (custom) return custom.label;
|
|
2242
|
-
const t = this.locale;
|
|
2243
|
-
return t.step1.categories[id] ?? id;
|
|
2053
|
+
|
|
2054
|
+
// src/widget-render.ts
|
|
2055
|
+
function renderStep(ctx) {
|
|
2056
|
+
switch (ctx.step) {
|
|
2057
|
+
case "category":
|
|
2058
|
+
return renderCategoryStep(ctx);
|
|
2059
|
+
case "intent":
|
|
2060
|
+
return renderIntentStep(ctx);
|
|
2061
|
+
case "details":
|
|
2062
|
+
return renderDetailsStep(ctx);
|
|
2063
|
+
case "success":
|
|
2064
|
+
return renderSuccessStep(ctx);
|
|
2065
|
+
case "reports":
|
|
2066
|
+
return renderReportsStep(ctx);
|
|
2067
|
+
case "report-detail":
|
|
2068
|
+
return renderReportDetailStep(ctx);
|
|
2069
|
+
case "leaderboard":
|
|
2070
|
+
return renderLeaderboardStep(ctx);
|
|
2071
|
+
case "roadmap":
|
|
2072
|
+
return renderRoadmapStep(ctx);
|
|
2073
|
+
case "account":
|
|
2074
|
+
return renderAccountStep(ctx);
|
|
2075
|
+
case "cross-app-reports":
|
|
2076
|
+
return renderCrossAppReportsStep(ctx);
|
|
2077
|
+
case "assistant":
|
|
2078
|
+
return renderAssistantStep(ctx);
|
|
2244
2079
|
}
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
*/
|
|
2291
|
-
pulseTrigger() {
|
|
2292
|
-
if (this.isOpen) return;
|
|
2293
|
-
const trigger = this.shadow.querySelector(".mushi-trigger");
|
|
2294
|
-
if (!trigger) return;
|
|
2295
|
-
trigger.classList.add("mushi-trigger-pulse");
|
|
2296
|
-
window.setTimeout(() => {
|
|
2297
|
-
trigger.classList.remove("mushi-trigger-pulse");
|
|
2298
|
-
}, 2400);
|
|
2299
|
-
}
|
|
2300
|
-
getIsOpen() {
|
|
2301
|
-
return this.isOpen;
|
|
2302
|
-
}
|
|
2303
|
-
showTrigger() {
|
|
2304
|
-
this.triggerVisible = true;
|
|
2305
|
-
this.render();
|
|
2306
|
-
}
|
|
2307
|
-
hideTrigger() {
|
|
2308
|
-
this.triggerVisible = false;
|
|
2309
|
-
this.render();
|
|
2310
|
-
}
|
|
2311
|
-
setTrigger(trigger) {
|
|
2312
|
-
this.updateConfig({ trigger });
|
|
2313
|
-
}
|
|
2314
|
-
attachTo(selectorOrElement, options = {}) {
|
|
2315
|
-
const elements = typeof selectorOrElement === "string" ? Array.from(document.querySelectorAll(selectorOrElement)) : [selectorOrElement];
|
|
2316
|
-
const cleanups = elements.map((el) => {
|
|
2317
|
-
const onClick = (event) => {
|
|
2318
|
-
event.preventDefault();
|
|
2319
|
-
this.updateConfig(options);
|
|
2320
|
-
this.open();
|
|
2321
|
-
};
|
|
2322
|
-
el.addEventListener("click", onClick);
|
|
2323
|
-
return () => el.removeEventListener("click", onClick);
|
|
2324
|
-
});
|
|
2325
|
-
return () => cleanups.forEach((cleanup) => cleanup());
|
|
2326
|
-
}
|
|
2327
|
-
setScreenshotAttached(attached) {
|
|
2328
|
-
this.screenshotAttached = attached;
|
|
2329
|
-
if (this.isOpen) this.render();
|
|
2330
|
-
}
|
|
2331
|
-
setAllowScreenshotRemove(allow) {
|
|
2332
|
-
this.allowScreenshotRemove = allow;
|
|
2333
|
-
if (this.isOpen) this.render();
|
|
2334
|
-
}
|
|
2335
|
-
setElementSelected(selected) {
|
|
2336
|
-
this.elementSelected = selected;
|
|
2337
|
-
this.elementCapturing = false;
|
|
2338
|
-
this.removeSelectorHint();
|
|
2339
|
-
if (this.isOpen) this.render();
|
|
2340
|
-
}
|
|
2341
|
-
setScreenshotCapturing(capturing) {
|
|
2342
|
-
this.screenshotCapturing = capturing;
|
|
2343
|
-
this.screenshotError = false;
|
|
2344
|
-
if (this.isOpen) this.render();
|
|
2345
|
-
}
|
|
2346
|
-
setScreenshotError(failed) {
|
|
2347
|
-
this.screenshotError = failed;
|
|
2348
|
-
this.screenshotCapturing = false;
|
|
2349
|
-
if (this.isOpen) this.render();
|
|
2350
|
-
}
|
|
2351
|
-
setElementCapturing(capturing) {
|
|
2352
|
-
this.elementCapturing = capturing;
|
|
2353
|
-
if (capturing) {
|
|
2354
|
-
this.showSelectorHint();
|
|
2355
|
-
} else {
|
|
2356
|
-
this.removeSelectorHint();
|
|
2357
|
-
}
|
|
2358
|
-
if (this.isOpen) this.render();
|
|
2359
|
-
}
|
|
2360
|
-
/** Hide the widget panel (but keep the host element) during element selection
|
|
2361
|
-
* so the user can click any element on the page without the panel
|
|
2362
|
-
* intercepting the event. */
|
|
2363
|
-
hidePanel() {
|
|
2364
|
-
const panel = this.shadow.querySelector(".mushi-panel");
|
|
2365
|
-
if (panel) panel.style.display = "none";
|
|
2366
|
-
}
|
|
2367
|
-
showPanel() {
|
|
2368
|
-
const panel = this.shadow.querySelector(".mushi-panel");
|
|
2369
|
-
if (panel) panel.style.display = "";
|
|
2370
|
-
}
|
|
2371
|
-
showSelectorHint() {
|
|
2372
|
-
this.removeSelectorHint();
|
|
2373
|
-
const hint = document.createElement("div");
|
|
2374
|
-
hint.id = "mushi-selector-hint";
|
|
2375
|
-
hint.setAttribute("role", "status");
|
|
2376
|
-
hint.setAttribute("aria-live", "polite");
|
|
2377
|
-
hint.style.cssText = `
|
|
2378
|
-
position: fixed;
|
|
2379
|
-
bottom: 24px;
|
|
2380
|
-
left: 50%;
|
|
2381
|
-
transform: translateX(-50%);
|
|
2382
|
-
z-index: 2147483646;
|
|
2383
|
-
background: rgba(17,17,17,0.92);
|
|
2384
|
-
color: #fff;
|
|
2385
|
-
font-family: ui-monospace, SFMono-Regular, monospace;
|
|
2386
|
-
font-size: 12px;
|
|
2387
|
-
letter-spacing: 0.04em;
|
|
2388
|
-
padding: 8px 16px;
|
|
2389
|
-
border-radius: 20px;
|
|
2390
|
-
pointer-events: none;
|
|
2391
|
-
white-space: nowrap;
|
|
2392
|
-
backdrop-filter: blur(4px);
|
|
2393
|
-
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
2080
|
+
}
|
|
2081
|
+
function renderAssistantStep(ctx) {
|
|
2082
|
+
const label = ctx.callbacks.assistantLabel || "Ask";
|
|
2083
|
+
const greeting = ctx.callbacks.assistantGreeting || "Ask me anything about this app.";
|
|
2084
|
+
const suggestions = ctx.callbacks.assistantSuggestions ?? [];
|
|
2085
|
+
const empty = ctx.assistantTurns.length === 0;
|
|
2086
|
+
const transcript = empty ? `<div class="mushi-assistant-greeting">${escapeHtml(greeting)}</div>
|
|
2087
|
+
${suggestions.length ? `<div class="mushi-assistant-suggestions">${suggestions.map((s) => `<button type="button" class="mushi-assistant-chip" data-action="assistant-suggest" data-value="${escapeHtml(s)}">${escapeHtml(s)}</button>`).join("")}</div>` : ""}` : ctx.assistantTurns.map((turn) => {
|
|
2088
|
+
const cls = turn.role === "user" ? "mushi-assistant-msg-user" : "mushi-assistant-msg-bot";
|
|
2089
|
+
const opts = turn.options && turn.options.length ? `<div class="mushi-assistant-suggestions">${turn.options.map((o) => `<button type="button" class="mushi-assistant-chip" data-action="assistant-suggest" data-value="${escapeHtml(o)}">${escapeHtml(o)}</button>`).join("")}</div>` : "";
|
|
2090
|
+
return `<div class="mushi-assistant-msg ${cls}">${escapeHtml(turn.text)}</div>${opts}`;
|
|
2091
|
+
}).join("");
|
|
2092
|
+
const thinking = ctx.assistantSending ? `<div class="mushi-assistant-msg mushi-assistant-msg-bot mushi-assistant-thinking">\u2026</div>` : "";
|
|
2093
|
+
const error = ctx.assistantError ? `<div class="mushi-assistant-error" role="alert">${escapeHtml(ctx.assistantError)}</div>` : "";
|
|
2094
|
+
return `
|
|
2095
|
+
${renderHeader(ctx, { title: label, showBack: true })}
|
|
2096
|
+
<div class="mushi-assistant">
|
|
2097
|
+
<div class="mushi-assistant-log">
|
|
2098
|
+
${transcript}
|
|
2099
|
+
${thinking}
|
|
2100
|
+
${error}
|
|
2101
|
+
</div>
|
|
2102
|
+
<form class="mushi-assistant-form" data-action="assistant-send">
|
|
2103
|
+
<textarea
|
|
2104
|
+
class="mushi-assistant-input"
|
|
2105
|
+
rows="1"
|
|
2106
|
+
placeholder="Type your question\u2026"
|
|
2107
|
+
${ctx.assistantSending ? "disabled" : ""}
|
|
2108
|
+
></textarea>
|
|
2109
|
+
<button type="submit" class="mushi-assistant-submit" ${ctx.assistantSending ? "disabled" : ""} aria-label="Send">\u2191</button>
|
|
2110
|
+
</form>
|
|
2111
|
+
</div>
|
|
2112
|
+
`;
|
|
2113
|
+
}
|
|
2114
|
+
function renderOutdatedBanner(ctx) {
|
|
2115
|
+
if (!ctx.sdkFreshness) return "";
|
|
2116
|
+
if (ctx.config.outdatedBanner === "off" || ctx.config.outdatedBanner === "console-only") return "";
|
|
2117
|
+
const { latest, current, deprecated, message } = ctx.sdkFreshness;
|
|
2118
|
+
if (!latest && !deprecated) return "";
|
|
2119
|
+
return `
|
|
2120
|
+
<div class="mushi-outdated" role="status">
|
|
2121
|
+
<strong>Mushi SDK ${escapeHtml(current)}</strong>
|
|
2122
|
+
${latest ? `latest is ${escapeHtml(latest)}.` : "needs attention."}
|
|
2123
|
+
${message ? `<span>${escapeHtml(message)}</span>` : ""}
|
|
2124
|
+
</div>
|
|
2394
2125
|
`;
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
}
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
}
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
background: rgba(17,17,17,0.92);
|
|
2418
|
-
color: #fff;
|
|
2419
|
-
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
2420
|
-
font-size: 12px;
|
|
2421
|
-
line-height: 1.4;
|
|
2422
|
-
padding: 8px 12px;
|
|
2423
|
-
border-radius: 8px;
|
|
2424
|
-
max-width: 200px;
|
|
2425
|
-
pointer-events: none;
|
|
2426
|
-
backdrop-filter: blur(4px);
|
|
2427
|
-
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
2428
|
-
animation: mushi-fade-in 0.15s ease forwards;
|
|
2126
|
+
}
|
|
2127
|
+
function renderBrandFooter(ctx) {
|
|
2128
|
+
if (ctx.config.brandFooter === false) return "";
|
|
2129
|
+
return `<div class="mushi-brand-footer">Powered by Mushi v${escapeHtml(ctx.sdkVersion)}</div>`;
|
|
2130
|
+
}
|
|
2131
|
+
function renderHeader(ctx, opts) {
|
|
2132
|
+
const t = ctx.locale;
|
|
2133
|
+
const { title, showBack = false, step, eyebrow } = opts;
|
|
2134
|
+
const eyebrowHtml = showBack ? `<button type="button" class="mushi-back" data-action="back" aria-label="${t.widget.back}">\u2190</button>` : `<span class="mushi-header-eyebrow">${eyebrow ?? "Mushi \xB7 Report"}</span>`;
|
|
2135
|
+
const counterHtml = step ? `<span class="mushi-step-counter" aria-label="Step ${step} of ${TOTAL_STEPS}"><b>${pad2(step)}</b> / ${pad2(TOTAL_STEPS)}</span>` : "";
|
|
2136
|
+
return `
|
|
2137
|
+
<div class="mushi-header">
|
|
2138
|
+
<div class="mushi-header-mark" aria-hidden="true">\u866B</div>
|
|
2139
|
+
<div class="mushi-header-titles">
|
|
2140
|
+
${eyebrowHtml}
|
|
2141
|
+
<h3>${title}</h3>
|
|
2142
|
+
</div>
|
|
2143
|
+
<div class="mushi-header-meta">
|
|
2144
|
+
${counterHtml}
|
|
2145
|
+
<button type="button" class="mushi-close" data-action="close" aria-label="${t.widget.close}">\u2715</button>
|
|
2146
|
+
</div>
|
|
2147
|
+
</div>
|
|
2429
2148
|
`;
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2149
|
+
}
|
|
2150
|
+
function renderStepIndicator(_ctx, currentStep) {
|
|
2151
|
+
const segments = [];
|
|
2152
|
+
for (let i = 1; i <= TOTAL_STEPS; i++) {
|
|
2153
|
+
const cls = i < currentStep ? "mushi-step-num done" : i === currentStep ? "mushi-step-num active" : "mushi-step-num";
|
|
2154
|
+
segments.push(`<span class="${cls}">${pad2(i)}</span>`);
|
|
2155
|
+
if (i < TOTAL_STEPS) segments.push('<span class="mushi-step-sep" aria-hidden="true"></span>');
|
|
2156
|
+
}
|
|
2157
|
+
return `<div class="mushi-step-indicator" aria-hidden="true">${segments.join("")}</div>`;
|
|
2158
|
+
}
|
|
2159
|
+
function renderCategoryStep(ctx) {
|
|
2160
|
+
const t = ctx.locale;
|
|
2161
|
+
const categoryEntries = ctx.config.categories && ctx.config.categories.length > 0 ? ctx.config.categories.map((c) => ({
|
|
2162
|
+
id: c.id,
|
|
2163
|
+
icon: c.icon ?? "\u{1F4AC}",
|
|
2164
|
+
label: c.label,
|
|
2165
|
+
desc: c.description ?? ""
|
|
2166
|
+
})) : ["bug", "slow", "visual", "confusing", "other"].map((id) => ({
|
|
2167
|
+
id,
|
|
2168
|
+
icon: CATEGORY_ICONS[id],
|
|
2169
|
+
label: t.step1.categories[id],
|
|
2170
|
+
desc: t.step1.categoryDescriptions[id]
|
|
2171
|
+
}));
|
|
2172
|
+
const categories = categoryEntries.map(({ id, icon, label, desc }) => `
|
|
2173
|
+
<button type="button" class="mushi-option-btn" data-category="${escapeHtml(id)}" role="radio" aria-checked="false">
|
|
2174
|
+
<span class="mushi-option-icon" aria-hidden="true">${escapeHtml(icon)}</span>
|
|
2175
|
+
<div class="mushi-option-text">
|
|
2176
|
+
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2177
|
+
${desc ? `<span class="mushi-option-desc">${escapeHtml(desc)}</span>` : ""}
|
|
2178
|
+
</div>
|
|
2179
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2180
|
+
</button>
|
|
2181
|
+
`).join("");
|
|
2182
|
+
return `
|
|
2183
|
+
${renderHeader(ctx, { title: t.step1.heading, step: STEP_NUMBER.category })}
|
|
2184
|
+
${ctx.config.betaMode?.enabled ? renderBetaStrip(ctx) : ""}
|
|
2185
|
+
<div class="mushi-body" role="radiogroup" aria-label="${t.step1.heading}">
|
|
2186
|
+
<button type="button" class="mushi-option-btn mushi-reports-entry" data-action="reports">
|
|
2187
|
+
<span class="mushi-option-icon" aria-hidden="true">\u{1F4EC}</span>
|
|
2188
|
+
<div class="mushi-option-text">
|
|
2189
|
+
<span class="mushi-option-label">Your reports${ctx.unreadCount() ? ` (${ctx.unreadCount()} new)` : ""}</span>
|
|
2190
|
+
<span class="mushi-option-desc">See status, developer replies, and respond</span>
|
|
2191
|
+
</div>
|
|
2192
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2193
|
+
</button>
|
|
2194
|
+
${renderFeatureRequestEntry(ctx)}
|
|
2195
|
+
${ctx.callbacks.onFeatureBoardRequest ? `
|
|
2196
|
+
<button type="button" class="mushi-option-btn" data-action="roadmap">
|
|
2197
|
+
<span class="mushi-option-icon" aria-hidden="true">\u{1F5F3}\uFE0F</span>
|
|
2198
|
+
<div class="mushi-option-text">
|
|
2199
|
+
<span class="mushi-option-label">Community ideas</span>
|
|
2200
|
+
<span class="mushi-option-desc">Vote on features and see what shipped</span>
|
|
2201
|
+
</div>
|
|
2202
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2203
|
+
</button>` : ""}
|
|
2204
|
+
${categories}
|
|
2205
|
+
${ctx.rewardsState ? renderRewardsNudge(ctx) : ""}
|
|
2206
|
+
<div class="mushi-community-footer">
|
|
2207
|
+
<button type="button" class="mushi-link-btn mushi-community-btn" data-action="open-account">
|
|
2208
|
+
${ctx.testerInfo ? `\u{1F464} ${escapeHtml(ctx.testerInfo.public_handle ?? ctx.testerInfo.display_name ?? "My account")}` : "\u{1F310} Join community \xB7 Track reports across apps"}
|
|
2209
|
+
</button>
|
|
2210
|
+
${ctx.rewardsState ? `<button type="button" class="mushi-link-btn" data-action="open-leaderboard">\u{1F3C6} Leaderboard</button>` : ""}
|
|
2211
|
+
</div>
|
|
2212
|
+
</div>
|
|
2213
|
+
${renderStepIndicator(ctx, STEP_NUMBER.category)}
|
|
2214
|
+
`;
|
|
2215
|
+
}
|
|
2216
|
+
function renderFeatureRequestEntry(ctx) {
|
|
2217
|
+
const enabled = ctx.config.featureRequestCard !== false;
|
|
2218
|
+
if (!enabled) return "";
|
|
2219
|
+
const label = ctx.config.featureRequestLabel || "Feature request";
|
|
2220
|
+
const desc = ctx.config.featureRequestDescription || "Suggest something new \u2014 even rough ideas help us prioritise";
|
|
2221
|
+
return `
|
|
2222
|
+
<button
|
|
2223
|
+
type="button"
|
|
2224
|
+
class="mushi-option-btn mushi-feature-entry"
|
|
2225
|
+
data-action="feature-request"
|
|
2226
|
+
aria-label="${escapeHtml(label)}"
|
|
2227
|
+
>
|
|
2228
|
+
<span class="mushi-option-icon" aria-hidden="true">\u2728</span>
|
|
2229
|
+
<div class="mushi-option-text">
|
|
2230
|
+
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2231
|
+
<span class="mushi-option-desc">${escapeHtml(desc)}</span>
|
|
2232
|
+
</div>
|
|
2233
|
+
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2234
|
+
</button>
|
|
2235
|
+
`;
|
|
2236
|
+
}
|
|
2237
|
+
function renderBetaChangelog(ctx) {
|
|
2238
|
+
const entries = ctx.config.betaMode?.changelogItems;
|
|
2239
|
+
if (!entries?.length) return "";
|
|
2240
|
+
const latest = entries[0];
|
|
2241
|
+
const items = latest.items.map((item) => `<li>\u2022 ${escapeHtml(item)}</li>`).join("");
|
|
2242
|
+
const label = latest.date ? `What\u2019s new in ${escapeHtml(latest.version)} \xB7 ${escapeHtml(latest.date)}` : `What\u2019s new in ${escapeHtml(latest.version)}`;
|
|
2243
|
+
return `
|
|
2244
|
+
<details class="mushi-changelog">
|
|
2245
|
+
<summary class="mushi-changelog-summary">${label}</summary>
|
|
2246
|
+
<ul class="mushi-changelog-list">${items}</ul>
|
|
2247
|
+
</details>
|
|
2248
|
+
`;
|
|
2249
|
+
}
|
|
2250
|
+
function renderBetaStrip(ctx) {
|
|
2251
|
+
const beta = ctx.config.betaMode;
|
|
2252
|
+
const appName = escapeHtml(beta.appName ?? "This app");
|
|
2253
|
+
const message = beta.message ? escapeHtml(beta.message) : `${appName} is in early development \u2014 updates ship weekly`;
|
|
2254
|
+
const email = beta.contactEmail ? escapeHtml(beta.contactEmail) : null;
|
|
2255
|
+
const perks = beta.perks ?? [];
|
|
2256
|
+
return `
|
|
2257
|
+
<div class="mushi-beta-strip" role="note" aria-label="Beta status">
|
|
2258
|
+
<div class="mushi-beta-strip-row">
|
|
2259
|
+
<span class="mushi-beta-tag" aria-hidden="true">BETA</span>
|
|
2260
|
+
<span class="mushi-beta-msg">${message}</span>
|
|
2261
|
+
</div>
|
|
2262
|
+
${email ? `<div class="mushi-beta-contact-hint">Reports go to ${email} \xB7 reviewed by the team</div>` : ""}
|
|
2263
|
+
${perks.length > 0 ? `
|
|
2264
|
+
<ul class="mushi-beta-perks" aria-label="Beta tester perks">
|
|
2265
|
+
${perks.map((p) => `<li>\u2713 ${escapeHtml(p)}</li>`).join("")}
|
|
2266
|
+
</ul>
|
|
2267
|
+
` : ""}
|
|
2268
|
+
${renderBetaChangelog(ctx)}
|
|
2269
|
+
</div>
|
|
2270
|
+
`;
|
|
2271
|
+
}
|
|
2272
|
+
function renderReportsStep(ctx) {
|
|
2273
|
+
const reports = ctx.reporterReports.map((report) => {
|
|
2274
|
+
const title = report.summary ?? report.description ?? `Report ${report.id.slice(0, 8)}`;
|
|
2275
|
+
const tone = reporterStatusTone(report.status);
|
|
2276
|
+
const when = formatRelativeTime(report.created_at);
|
|
2277
|
+
const unread = report.unread_count && report.unread_count > 0 ? `<span class="mushi-unread-badge" aria-label="${report.unread_count} unread">${report.unread_count}</span>` : "";
|
|
2278
|
+
return `
|
|
2279
|
+
<button type="button" class="mushi-report-row" data-report-id="${escapeHtml(report.id)}" aria-label="View report: ${escapeHtml(title)}">
|
|
2280
|
+
<div class="mushi-report-main">
|
|
2281
|
+
<span class="mushi-report-title">${escapeHtml(title)}</span>
|
|
2282
|
+
<span class="mushi-report-meta">
|
|
2283
|
+
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusShort(report.status))}</span>
|
|
2284
|
+
${when ? `<span class="mushi-report-when">${escapeHtml(when)}</span>` : ""}
|
|
2285
|
+
${unread}
|
|
2286
|
+
</span>
|
|
2287
|
+
</div>
|
|
2288
|
+
<span class="mushi-report-chevron" aria-hidden="true">\u203A</span>
|
|
2289
|
+
</button>`;
|
|
2290
|
+
}).join("");
|
|
2291
|
+
const leaderboardBtn = ctx.rewardsState ? `<button type="button" class="mushi-leaderboard-link" data-action="open-leaderboard">\u{1F3C6} Leaderboard</button>` : "";
|
|
2292
|
+
return `
|
|
2293
|
+
${renderHeader(ctx, { title: "Your reports", showBack: true, eyebrow: "Mushi \xB7 Inbox" })}
|
|
2294
|
+
<div class="mushi-body">
|
|
2295
|
+
${ctx.reporterLoading ? '<p class="mushi-muted">Loading reports\u2026</p>' : ""}
|
|
2296
|
+
${ctx.reporterError ? `<p class="mushi-error-inline">${escapeHtml(ctx.reporterError)}</p>` : ""}
|
|
2297
|
+
${reports || (!ctx.reporterLoading ? '<p class="mushi-muted">No reports from this browser yet.</p>' : "")}
|
|
2298
|
+
${leaderboardBtn}
|
|
2299
|
+
</div>
|
|
2300
|
+
`;
|
|
2301
|
+
}
|
|
2302
|
+
function renderRoadmapStep(ctx) {
|
|
2303
|
+
const rows = ctx.featureBoard.map((ticket) => {
|
|
2304
|
+
const id = String(ticket.id ?? "");
|
|
2305
|
+
const subject = escapeHtml(String(ticket.subject ?? "Untitled idea"));
|
|
2306
|
+
const votes = Number(ticket.vote_count ?? 0);
|
|
2307
|
+
const shipped = Boolean(ticket.shipped_at);
|
|
2308
|
+
const voted = Boolean(ticket.my_vote);
|
|
2309
|
+
const status = shipped ? "Shipped" : String(ticket.status_label ?? ticket.status ?? "open");
|
|
2310
|
+
return `
|
|
2311
|
+
<div class="mushi-report-row mushi-roadmap-row">
|
|
2312
|
+
<div class="mushi-report-main">
|
|
2313
|
+
<span class="mushi-report-title">${subject}</span>
|
|
2314
|
+
<span class="mushi-report-meta">
|
|
2315
|
+
<span class="mushi-report-status">${escapeHtml(status)}</span>
|
|
2316
|
+
<span class="mushi-report-when">${votes} vote${votes === 1 ? "" : "s"}</span>
|
|
2317
|
+
</span>
|
|
2318
|
+
</div>
|
|
2319
|
+
${ctx.callbacks.onFeatureBoardVote ? `
|
|
2320
|
+
<button type="button" class="mushi-vote-btn" data-vote-id="${escapeHtml(id)}" aria-pressed="${voted}">
|
|
2321
|
+
${voted ? "Voted" : "Vote"}
|
|
2322
|
+
</button>` : ""}
|
|
2323
|
+
</div>`;
|
|
2324
|
+
}).join("");
|
|
2325
|
+
return `
|
|
2326
|
+
${renderHeader(ctx, { title: "Community ideas", showBack: true, eyebrow: "Mushi \xB7 Roadmap" })}
|
|
2327
|
+
<div class="mushi-body">
|
|
2328
|
+
${ctx.reporterLoading ? '<p class="mushi-muted">Loading ideas\u2026</p>' : ""}
|
|
2329
|
+
${ctx.reporterError ? `<p class="mushi-error-inline">${escapeHtml(ctx.reporterError)}</p>` : ""}
|
|
2330
|
+
${rows || (!ctx.reporterLoading ? '<p class="mushi-muted">No community ideas yet. Be the first to suggest one.</p>' : "")}
|
|
2331
|
+
</div>
|
|
2332
|
+
`;
|
|
2333
|
+
}
|
|
2334
|
+
function renderLeaderboardStep(ctx) {
|
|
2335
|
+
const isGlobal = ctx.globalLeaderboard !== null || ctx.globalLeaderboardLoading;
|
|
2336
|
+
const entries = isGlobal ? ctx.globalLeaderboard ?? [] : (ctx.leaderboardEntries ?? []).map((e) => ({
|
|
2337
|
+
tester_id: "",
|
|
2338
|
+
public_handle: null,
|
|
2339
|
+
display_name: e.display_name,
|
|
2340
|
+
rank: 0,
|
|
2341
|
+
points_30d: e.points_30d,
|
|
2342
|
+
total_points: e.total_points
|
|
2343
|
+
}));
|
|
2344
|
+
const loading = isGlobal ? ctx.globalLeaderboardLoading : ctx.leaderboardLoading;
|
|
2345
|
+
const myRank = ctx.testerReputation?.rank ?? null;
|
|
2346
|
+
const rows = entries.map((e, i) => {
|
|
2347
|
+
const rank = e.rank || i + 1;
|
|
2348
|
+
const isMe = ctx.testerReputation && e.tester_id === ctx.testerReputation.tester_id;
|
|
2349
|
+
return `
|
|
2350
|
+
<div class="mushi-lb-row ${rank === 1 ? "mushi-lb-top" : ""}${isMe ? " mushi-lb-me" : ""}">
|
|
2351
|
+
<span class="mushi-lb-rank">#${rank}</span>
|
|
2352
|
+
<span class="mushi-lb-name">${escapeHtml(e.public_handle ?? e.display_name ?? "Anon")}</span>
|
|
2353
|
+
<span class="mushi-lb-pts">${(e.points_30d ?? e.total_points).toLocaleString()} pts</span>
|
|
2354
|
+
</div>
|
|
2355
|
+
`;
|
|
2356
|
+
}).join("");
|
|
2357
|
+
const myRankBadge = myRank ? `<div class="mushi-lb-myrank">You are ranked <strong>#${myRank}</strong> this month</div>` : !ctx.testerJwt ? `<button type="button" class="mushi-link-btn" data-action="open-account">Sign in to see your rank \u2192</button>` : "";
|
|
2358
|
+
return `
|
|
2359
|
+
${renderHeader(ctx, { title: "\u{1F3C6} Global Leaderboard", showBack: true, eyebrow: "Mushi \xB7 Community" })}
|
|
2360
|
+
<div class="mushi-body">
|
|
2361
|
+
${loading ? '<p class="mushi-muted">Loading leaderboard\u2026</p>' : ""}
|
|
2362
|
+
${!loading && !entries.length ? '<p class="mushi-muted">No contributors yet \u2014 be the first!</p>' : ""}
|
|
2363
|
+
<div class="mushi-lb-list">${rows}</div>
|
|
2364
|
+
${myRankBadge}
|
|
2365
|
+
<p class="mushi-lb-note">Global contributors this month \xB7 Points refresh monthly</p>
|
|
2366
|
+
</div>
|
|
2367
|
+
`;
|
|
2368
|
+
}
|
|
2369
|
+
function renderAccountStep(ctx) {
|
|
2370
|
+
const tester = ctx.testerInfo;
|
|
2371
|
+
if (tester) {
|
|
2372
|
+
const handle = tester.public_handle ?? tester.display_name ?? "Tester";
|
|
2373
|
+
const rep = ctx.testerReputation;
|
|
2374
|
+
return `
|
|
2375
|
+
${renderHeader(ctx, { title: "\u866B Mushi Account", showBack: true, eyebrow: "Mushi \xB7 Identity" })}
|
|
2376
|
+
<div class="mushi-body">
|
|
2377
|
+
<div class="mushi-account-card">
|
|
2378
|
+
<div class="mushi-account-avatar">${escapeHtml(handle.charAt(0).toUpperCase())}</div>
|
|
2379
|
+
<div class="mushi-account-info">
|
|
2380
|
+
<strong>${escapeHtml(handle)}</strong>
|
|
2381
|
+
${rep ? `<span class="mushi-account-rank">Rank #${rep.rank ?? "\u2014"} \xB7 ${(rep.points_30d ?? 0).toLocaleString()} pts this month</span>` : ""}
|
|
2382
|
+
</div>
|
|
2383
|
+
</div>
|
|
2384
|
+
<button type="button" class="mushi-nav-item" data-action="open-cross-app-reports">
|
|
2385
|
+
My reports across all apps \u2192
|
|
2386
|
+
</button>
|
|
2387
|
+
<button type="button" class="mushi-nav-item" data-action="open-global-leaderboard">
|
|
2388
|
+
View global leaderboard \u2192
|
|
2389
|
+
</button>
|
|
2390
|
+
<button type="button" class="mushi-link-btn" data-action="sign-out-tester">Sign out</button>
|
|
2391
|
+
</div>
|
|
2392
|
+
`;
|
|
2452
2393
|
}
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2394
|
+
if (ctx.magicLinkSent) {
|
|
2395
|
+
return `
|
|
2396
|
+
${renderHeader(ctx, { title: "\u866B Check your email", showBack: true, eyebrow: "Mushi \xB7 Sign in" })}
|
|
2397
|
+
<div class="mushi-body">
|
|
2398
|
+
<p class="mushi-muted">We sent a sign-in link to <strong>${escapeHtml(ctx.magicLinkEmail)}</strong>. Click it to connect your reports across apps and join the community.</p>
|
|
2399
|
+
<button type="button" class="mushi-link-btn" data-action="resend-magic-link">Resend email</button>
|
|
2400
|
+
${ctx.magicLinkError ? `<p class="mushi-error">${escapeHtml(ctx.magicLinkError)}</p>` : ""}
|
|
2401
|
+
</div>
|
|
2402
|
+
`;
|
|
2457
2403
|
}
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2404
|
+
return `
|
|
2405
|
+
${renderHeader(ctx, { title: "\u866B Join the community", showBack: true, eyebrow: "Mushi \xB7 Sign in" })}
|
|
2406
|
+
<div class="mushi-body">
|
|
2407
|
+
<p class="mushi-muted">Sign in to see your reports across all apps and climb the global leaderboard. No password needed.</p>
|
|
2408
|
+
<label class="mushi-label" for="mushi-email-input">Email address</label>
|
|
2409
|
+
<input
|
|
2410
|
+
id="mushi-email-input"
|
|
2411
|
+
type="email"
|
|
2412
|
+
class="mushi-textarea"
|
|
2413
|
+
data-role="magic-link-email"
|
|
2414
|
+
placeholder="you@example.com"
|
|
2415
|
+
autocomplete="email"
|
|
2416
|
+
value="${escapeHtml(ctx.magicLinkEmail)}"
|
|
2417
|
+
style="padding: 10px 12px; height: auto; resize: none;"
|
|
2418
|
+
/>
|
|
2419
|
+
${ctx.magicLinkError ? `<p class="mushi-error">${escapeHtml(ctx.magicLinkError)}</p>` : ""}
|
|
2420
|
+
<button type="button" class="mushi-submit" data-action="send-magic-link"${ctx.magicLinkSending ? ' disabled aria-disabled="true"' : ""}>
|
|
2421
|
+
<span>${ctx.magicLinkSending ? "Sending\u2026" : "Send sign-in link"}</span><span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
2422
|
+
</button>
|
|
2423
|
+
</div>
|
|
2424
|
+
`;
|
|
2425
|
+
}
|
|
2426
|
+
function renderCrossAppReportsStep(ctx) {
|
|
2427
|
+
const reports = ctx.crossAppReports ?? [];
|
|
2428
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
2429
|
+
for (const r of reports) {
|
|
2430
|
+
const key = r.project_id ?? "unknown";
|
|
2431
|
+
if (!grouped.has(key)) grouped.set(key, { name: r.app_name ?? "Unknown App", reports: [] });
|
|
2432
|
+
grouped.get(key).reports.push(r);
|
|
2433
|
+
}
|
|
2434
|
+
const rows = [...grouped.entries()].map(([, group]) => `
|
|
2435
|
+
<div class="mushi-xapp-group">
|
|
2436
|
+
<h4 class="mushi-xapp-app-name">${escapeHtml(group.name)}</h4>
|
|
2437
|
+
${group.reports.map((r) => {
|
|
2438
|
+
const tone = reporterStatusTone(r.status);
|
|
2439
|
+
return `
|
|
2440
|
+
<div class="mushi-report-row" data-report-id="${escapeHtml(r.id)}" tabindex="0" role="button">
|
|
2441
|
+
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusShort(r.status))}</span>
|
|
2442
|
+
<span class="mushi-report-title">${escapeHtml(r.title ?? r.category)}</span>
|
|
2443
|
+
<span class="mushi-report-when">${escapeHtml(formatRelativeTime(r.created_at))}</span>
|
|
2444
|
+
</div>
|
|
2445
|
+
`;
|
|
2446
|
+
}).join("")}
|
|
2447
|
+
</div>
|
|
2448
|
+
`).join("");
|
|
2449
|
+
return `
|
|
2450
|
+
${renderHeader(ctx, { title: "My reports", showBack: true, eyebrow: "Mushi \xB7 All apps" })}
|
|
2451
|
+
<div class="mushi-body">
|
|
2452
|
+
${ctx.crossAppLoading ? '<p class="mushi-muted">Loading your reports\u2026</p>' : ""}
|
|
2453
|
+
${!ctx.crossAppLoading && !reports.length ? '<p class="mushi-muted">No reports filed yet.</p>' : ""}
|
|
2454
|
+
${rows}
|
|
2455
|
+
</div>
|
|
2456
|
+
`;
|
|
2457
|
+
}
|
|
2458
|
+
function renderReportDetailStep(ctx) {
|
|
2459
|
+
const report = ctx.reporterReports.find((r) => r.id === ctx.selectedReportId);
|
|
2460
|
+
const status = report?.status ?? "unknown";
|
|
2461
|
+
const tone = reporterStatusTone(status);
|
|
2462
|
+
const when = report?.created_at ? formatRelativeTime(report.created_at) : "";
|
|
2463
|
+
const comments = ctx.reporterComments.map((comment) => `
|
|
2464
|
+
<div class="mushi-thread-comment ${comment.author_kind}">
|
|
2465
|
+
<strong>${escapeHtml(comment.author_kind === "reporter" ? "You" : comment.author_name ?? "Developer")}</strong>
|
|
2466
|
+
<p>${escapeHtml(comment.body)}</p>
|
|
2467
|
+
</div>
|
|
2468
|
+
`).join("");
|
|
2469
|
+
return `
|
|
2470
|
+
${renderHeader(ctx, { title: "Report thread", showBack: true, eyebrow: "Mushi \xB7 Inbox" })}
|
|
2471
|
+
<div class="mushi-body">
|
|
2472
|
+
<div class="mushi-thread-summary">
|
|
2473
|
+
<div class="mushi-thread-summary-meta">
|
|
2474
|
+
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusLabel(status))}</span>
|
|
2475
|
+
${when ? `<span class="mushi-report-when">Reported ${escapeHtml(when)}</span>` : ""}
|
|
2476
|
+
</div>
|
|
2477
|
+
<p>${escapeHtml(report?.summary ?? report?.description ?? "Report details")}</p>
|
|
2478
|
+
</div>
|
|
2479
|
+
<div class="mushi-thread">
|
|
2480
|
+
${ctx.reporterLoading ? '<p class="mushi-muted">Loading thread\u2026</p>' : comments || '<p class="mushi-muted">No developer replies yet.</p>'}
|
|
2481
|
+
</div>
|
|
2482
|
+
${["fixed", "resolved", "verified"].includes(status) ? `
|
|
2483
|
+
<div class="mushi-verify-actions" role="group" aria-label="Fix verification">
|
|
2484
|
+
<button type="button" class="mushi-intent-btn" data-action="reporter-confirms">Yes, fixed for me</button>
|
|
2485
|
+
<button type="button" class="mushi-intent-btn" data-action="reporter-not-fixed">Not fixed yet</button>
|
|
2486
|
+
</div>
|
|
2487
|
+
` : ""}
|
|
2488
|
+
<textarea class="mushi-textarea" data-role="reporter-reply" rows="3" placeholder="Reply to the developer\u2026"></textarea>
|
|
2489
|
+
<button type="button" class="mushi-submit" data-action="reporter-reply">
|
|
2490
|
+
<span>Reply</span><span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
2491
|
+
</button>
|
|
2492
|
+
</div>
|
|
2493
|
+
`;
|
|
2494
|
+
}
|
|
2495
|
+
function renderIntentStep(ctx) {
|
|
2496
|
+
const t = ctx.locale;
|
|
2497
|
+
const catId = ctx.selectedCategory;
|
|
2498
|
+
const customEntry = ctx.resolveCustomCategory(catId);
|
|
2499
|
+
const intents = customEntry?.intents ?? (t.step2.intents[catId] || []);
|
|
2500
|
+
const options = intents.map((intent) => `
|
|
2501
|
+
<button type="button" class="mushi-intent-btn" data-intent="${escapeHtml(intent)}">
|
|
2502
|
+
${escapeHtml(intent)}
|
|
2503
|
+
</button>
|
|
2504
|
+
`).join("");
|
|
2505
|
+
const icon = ctx.categoryIcon(catId);
|
|
2506
|
+
const label = ctx.categoryLabel(catId);
|
|
2507
|
+
return `
|
|
2508
|
+
${renderHeader(ctx, { title: t.step2.heading, showBack: true, step: STEP_NUMBER.intent })}
|
|
2509
|
+
<div class="mushi-body">
|
|
2510
|
+
<div class="mushi-selected-category">
|
|
2511
|
+
<span aria-hidden="true">${escapeHtml(icon)}</span>
|
|
2512
|
+
<span>${escapeHtml(label)}</span>
|
|
2513
|
+
</div>
|
|
2514
|
+
<div class="mushi-intents">
|
|
2515
|
+
${options}
|
|
2516
|
+
</div>
|
|
2517
|
+
</div>
|
|
2518
|
+
${renderStepIndicator(ctx, STEP_NUMBER.intent)}
|
|
2519
|
+
`;
|
|
2520
|
+
}
|
|
2521
|
+
function renderDetailsStep(ctx) {
|
|
2522
|
+
const t = ctx.locale;
|
|
2523
|
+
const minLen = ctx.effectiveMinLength();
|
|
2524
|
+
const screenshotLabel = ctx.screenshotCapturing ? t.step3.screenshotCapturing : ctx.screenshotError ? t.step3.screenshotFailed : ctx.screenshotAttached ? t.step3.screenshotAttached : t.step3.screenshotButton;
|
|
2525
|
+
const screenshotClass = [
|
|
2526
|
+
"mushi-attach-btn",
|
|
2527
|
+
ctx.screenshotAttached ? "active" : "",
|
|
2528
|
+
ctx.screenshotError ? "error" : "",
|
|
2529
|
+
ctx.screenshotCapturing ? "loading" : ""
|
|
2530
|
+
].filter(Boolean).join(" ");
|
|
2531
|
+
const elementLabel = ctx.elementCapturing ? t.step3.elementCapturing : ctx.elementSelected ? t.step3.elementSelected : t.step3.elementButton;
|
|
2532
|
+
const elementClass = [
|
|
2533
|
+
"mushi-attach-btn",
|
|
2534
|
+
ctx.elementSelected ? "active" : "",
|
|
2535
|
+
ctx.elementCapturing ? "loading" : ""
|
|
2536
|
+
].filter(Boolean).join(" ");
|
|
2537
|
+
const exampleChips = t.step3.examplePrompts.map((p) => `<button type="button" class="mushi-example-chip" data-example="${escapeHtml(p)}">${escapeHtml(p)}</button>`).join("");
|
|
2538
|
+
return `
|
|
2539
|
+
${renderHeader(ctx, { title: t.step3.heading, showBack: true, step: STEP_NUMBER.details })}
|
|
2540
|
+
<div class="mushi-body">
|
|
2541
|
+
<div class="mushi-example-chips" aria-label="Example prompts">${exampleChips}</div>
|
|
2542
|
+
<div class="mushi-textarea-wrap">
|
|
2543
|
+
<textarea
|
|
2544
|
+
class="mushi-textarea"
|
|
2545
|
+
placeholder="${t.step3.descriptionPlaceholder}"
|
|
2546
|
+
rows="4"
|
|
2547
|
+
aria-label="${t.step3.heading}"
|
|
2548
|
+
autofocus
|
|
2549
|
+
></textarea>
|
|
2550
|
+
<div class="mushi-char-counter" data-role="char-counter" aria-hidden="true">
|
|
2551
|
+
<span data-role="char-current">0</span>/<span data-role="char-min">${minLen}</span>
|
|
2552
|
+
</div>
|
|
2553
|
+
</div>
|
|
2554
|
+
<div class="mushi-attachments">
|
|
2555
|
+
<button type="button" class="${screenshotClass}"
|
|
2556
|
+
data-action="screenshot"
|
|
2557
|
+
${ctx.screenshotCapturing ? "disabled" : ""}
|
|
2558
|
+
aria-label="${escapeHtml(screenshotLabel)}"
|
|
2559
|
+
>
|
|
2560
|
+
${ctx.screenshotCapturing ? '<span class="mushi-spinner" aria-hidden="true"></span>' : "\u{1F4F8}"}
|
|
2561
|
+
${escapeHtml(screenshotLabel)}
|
|
2562
|
+
</button>
|
|
2563
|
+
${ctx.screenshotAttached && ctx.allowScreenshotRemove ? '<button type="button" class="mushi-attach-btn danger" data-action="remove-screenshot" aria-label="Remove screenshot">\u2715 Remove</button>' : ""}
|
|
2564
|
+
${ctx.screenshotAttached ? '<button type="button" class="mushi-attach-btn" data-action="annotate-screenshot" aria-label="Mark up screenshot">\u270F Mark up</button><div class="mushi-annotate-host" data-role="annotate-host"></div>' : ""}
|
|
2565
|
+
<button type="button" class="${elementClass}"
|
|
2566
|
+
data-action="element"
|
|
2567
|
+
${ctx.elementCapturing ? "disabled" : ""}
|
|
2568
|
+
aria-label="${escapeHtml(elementLabel)}"
|
|
2569
|
+
>
|
|
2570
|
+
${ctx.elementCapturing ? '<span class="mushi-spinner" aria-hidden="true"></span>' : "\u{1F3AF}"}
|
|
2571
|
+
${escapeHtml(elementLabel)}
|
|
2572
|
+
</button>
|
|
2573
|
+
</div>
|
|
2574
|
+
<div class="mushi-error" style="display:none" role="alert"></div>
|
|
2575
|
+
</div>
|
|
2576
|
+
<div class="mushi-footer">
|
|
2577
|
+
<span class="mushi-footer-hint" aria-hidden="true">\u2318 + ENTER \u2192 send</span>
|
|
2578
|
+
<button type="button" class="mushi-submit" data-action="submit"${ctx.submitting ? " disabled" : ""}>
|
|
2579
|
+
<span>${ctx.submitting ? t.widget.submitting : t.widget.submit}</span>
|
|
2580
|
+
<span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
2581
|
+
</button>
|
|
2582
|
+
</div>
|
|
2583
|
+
${renderStepIndicator(ctx, STEP_NUMBER.details)}
|
|
2584
|
+
`;
|
|
2585
|
+
}
|
|
2586
|
+
function renderSuccessStep(ctx) {
|
|
2587
|
+
const t = ctx.locale;
|
|
2588
|
+
const stamp = ctx.submittedAt ?? /* @__PURE__ */ new Date();
|
|
2589
|
+
const time = stamp.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit", second: "2-digit", hour12: false });
|
|
2590
|
+
return `
|
|
2591
|
+
${renderHeader(ctx, { title: t.widget.title, eyebrow: "Mushi \xB7 Receipt" })}
|
|
2592
|
+
<div class="mushi-body">
|
|
2593
|
+
<div class="mushi-success">
|
|
2594
|
+
<div class="mushi-success-stamp" aria-hidden="true">
|
|
2595
|
+
<svg viewBox="0 0 100 100" preserveAspectRatio="xMidYMid meet"><circle cx="50" cy="50" r="44"/></svg>
|
|
2596
|
+
<span class="mushi-success-stamp-label">\u53D7</span>
|
|
2597
|
+
</div>
|
|
2598
|
+
<div class="mushi-success-headline">${t.widget.submitted}</div>
|
|
2599
|
+
<div class="mushi-success-meta">REPORT \xB7 ${time}</div>
|
|
2600
|
+
${renderSuccessReceipt(ctx)}
|
|
2601
|
+
${ctx.rewardsState ? renderSuccessRewards(ctx) : ""}
|
|
2602
|
+
${ctx.config.betaMode?.enabled ? renderBetaSuccessFooter(ctx) : ""}
|
|
2603
|
+
</div>
|
|
2604
|
+
</div>
|
|
2605
|
+
`;
|
|
2606
|
+
}
|
|
2607
|
+
function renderSuccessReceipt(ctx) {
|
|
2608
|
+
if (ctx.lastSubmitQueuedOffline) {
|
|
2609
|
+
return `
|
|
2610
|
+
<div class="mushi-success-receipt" role="status">
|
|
2611
|
+
<div class="mushi-success-receipt-row mushi-success-receipt-warn">
|
|
2612
|
+
<span class="mushi-success-receipt-label">Queued offline</span>
|
|
2613
|
+
<span class="mushi-success-receipt-hint">We’ll send it the moment you’re back online.</span>
|
|
2614
|
+
</div>
|
|
2615
|
+
</div>
|
|
2616
|
+
`;
|
|
2463
2617
|
}
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2618
|
+
if (!ctx.lastReportId) {
|
|
2619
|
+
return `
|
|
2620
|
+
<div class="mushi-success-receipt" role="status">
|
|
2621
|
+
<div class="mushi-success-receipt-row">
|
|
2622
|
+
<span class="mushi-success-receipt-spinner" aria-hidden="true"></span>
|
|
2623
|
+
<span class="mushi-success-receipt-hint">Delivering to the team\u2026</span>
|
|
2624
|
+
</div>
|
|
2625
|
+
${renderSlaLine(ctx)}
|
|
2626
|
+
</div>
|
|
2627
|
+
`;
|
|
2468
2628
|
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2629
|
+
const idShort = `#${ctx.lastReportId.slice(0, 8)}`;
|
|
2630
|
+
const dashboard = (ctx.config.dashboardUrl ?? "").replace(/\/$/, "");
|
|
2631
|
+
const trackHref = dashboard ? `${dashboard}/reports/${encodeURIComponent(ctx.lastReportId)}` : "";
|
|
2632
|
+
return `
|
|
2633
|
+
<div class="mushi-success-receipt" role="status">
|
|
2634
|
+
<div class="mushi-success-receipt-row">
|
|
2635
|
+
<span class="mushi-success-receipt-label">Receipt</span>
|
|
2636
|
+
<button
|
|
2637
|
+
type="button"
|
|
2638
|
+
class="mushi-success-receipt-id"
|
|
2639
|
+
data-action="copy-report-id"
|
|
2640
|
+
data-copy-id="${escapeHtml(ctx.lastReportId)}"
|
|
2641
|
+
title="Copy report id ${escapeHtml(ctx.lastReportId)}"
|
|
2642
|
+
aria-label="Copy report id ${escapeHtml(ctx.lastReportId)}"
|
|
2643
|
+
>${escapeHtml(idShort)}<span class="mushi-success-receipt-copy" aria-hidden="true">\u2398</span></button>
|
|
2644
|
+
</div>
|
|
2645
|
+
${trackHref ? `
|
|
2646
|
+
<a
|
|
2647
|
+
class="mushi-success-receipt-track"
|
|
2648
|
+
href="${escapeHtml(trackHref)}"
|
|
2649
|
+
target="_blank"
|
|
2650
|
+
rel="noopener noreferrer"
|
|
2651
|
+
>Track on Mushi <span aria-hidden="true">\u2197</span></a>
|
|
2652
|
+
` : ""}
|
|
2653
|
+
${renderSlaLine(ctx)}
|
|
2654
|
+
</div>
|
|
2655
|
+
`;
|
|
2656
|
+
}
|
|
2657
|
+
function renderSlaLine(ctx) {
|
|
2658
|
+
const sla = (ctx.config.responseSlaLabel ?? "").trim();
|
|
2659
|
+
if (sla) {
|
|
2660
|
+
return `<div class="mushi-success-sla">${escapeHtml(sla)}</div>`;
|
|
2473
2661
|
}
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2662
|
+
return `<div class="mushi-success-sla mushi-success-sla-default">A human will look at this within a working day.</div>`;
|
|
2663
|
+
}
|
|
2664
|
+
function renderBetaSuccessFooter(ctx) {
|
|
2665
|
+
const beta = ctx.config.betaMode;
|
|
2666
|
+
const email = beta.contactEmail ? escapeHtml(beta.contactEmail) : null;
|
|
2667
|
+
const appName = escapeHtml(beta.appName ?? "the team");
|
|
2668
|
+
return `
|
|
2669
|
+
<div class="mushi-beta-success-footer" role="note" aria-label="Beta feedback acknowledgement">
|
|
2670
|
+
${email ? `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${email}</div>` : `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${appName}</div>`}
|
|
2671
|
+
<div class="mushi-beta-success-line mushi-beta-success-dim">We aim to review within 48h \xB7 thank you for helping build this</div>
|
|
2672
|
+
</div>
|
|
2673
|
+
`;
|
|
2674
|
+
}
|
|
2675
|
+
function renderRewardsNudge(ctx) {
|
|
2676
|
+
const { tier, nextTier, totalPoints, pointsForReport } = ctx.rewardsState;
|
|
2677
|
+
const tierName = tier?.displayName ?? "Free";
|
|
2678
|
+
const tierSlug = tier?.slug ?? "free";
|
|
2679
|
+
const color = ctx.tierColor(tierSlug);
|
|
2680
|
+
let pct = 100;
|
|
2681
|
+
let nextLabel = "";
|
|
2682
|
+
if (nextTier) {
|
|
2683
|
+
const base = tier?.pointsThreshold ?? 0;
|
|
2684
|
+
const ceiling = nextTier.pointsThreshold;
|
|
2685
|
+
pct = ceiling > base ? Math.round(Math.min(1, (totalPoints - base) / (ceiling - base)) * 100) : 100;
|
|
2686
|
+
const remaining = Math.max(0, ceiling - totalPoints);
|
|
2687
|
+
nextLabel = `${remaining.toLocaleString()} pts to ${escapeHtml(nextTier.displayName)}`;
|
|
2477
2688
|
}
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2689
|
+
return `
|
|
2690
|
+
<div class="mushi-rewards-nudge" aria-label="Rewards progress">
|
|
2691
|
+
<div class="mushi-rewards-row">
|
|
2692
|
+
<span class="mushi-tier-pip" style="background:${color}" aria-hidden="true"></span>
|
|
2693
|
+
<span class="mushi-rewards-tier-name">${escapeHtml(tierName)}</span>
|
|
2694
|
+
<span class="mushi-rewards-pts-count">${totalPoints.toLocaleString()} pts</span>
|
|
2695
|
+
<span class="mushi-rewards-pts-earn">+${pointsForReport} pts for a report</span>
|
|
2696
|
+
</div>
|
|
2697
|
+
${nextTier ? `
|
|
2698
|
+
<div class="mushi-tier-bar-track" role="progressbar" aria-valuenow="${pct}" aria-valuemin="0" aria-valuemax="100" aria-label="Progress to ${escapeHtml(nextTier.displayName)}">
|
|
2699
|
+
<div class="mushi-tier-bar-fill" style="width:${pct}%"></div>
|
|
2700
|
+
</div>
|
|
2701
|
+
<div class="mushi-rewards-next-label">${nextLabel}</div>
|
|
2702
|
+
` : ""}
|
|
2703
|
+
</div>
|
|
2704
|
+
`;
|
|
2705
|
+
}
|
|
2706
|
+
function renderSuccessRewards(ctx) {
|
|
2707
|
+
const { tier, nextTier, totalPoints, pointsForReport } = ctx.rewardsState;
|
|
2708
|
+
const projected = totalPoints + pointsForReport;
|
|
2709
|
+
let pctAfter = 100;
|
|
2710
|
+
let nextLabel = "";
|
|
2711
|
+
if (nextTier) {
|
|
2712
|
+
const base = tier?.pointsThreshold ?? 0;
|
|
2713
|
+
const ceiling = nextTier.pointsThreshold;
|
|
2714
|
+
pctAfter = ceiling > base ? Math.round(Math.min(1, (projected - base) / (ceiling - base)) * 100) : 100;
|
|
2715
|
+
const remaining = Math.max(0, ceiling - projected);
|
|
2716
|
+
nextLabel = remaining > 0 ? `${remaining.toLocaleString()} pts to ${escapeHtml(nextTier.displayName)}` : `\u{1F389} ${escapeHtml(nextTier.displayName)} reached!`;
|
|
2500
2717
|
}
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2718
|
+
return `
|
|
2719
|
+
<div class="mushi-success-rewards">
|
|
2720
|
+
<div class="mushi-success-pts-award">+${pointsForReport} pts</div>
|
|
2721
|
+
${nextTier ? `
|
|
2722
|
+
<div class="mushi-tier-bar-track success-bar" role="progressbar" aria-valuenow="${pctAfter}" aria-valuemin="0" aria-valuemax="100" aria-label="Progress to ${escapeHtml(nextTier.displayName)}">
|
|
2723
|
+
<div class="mushi-tier-bar-fill" style="width:${pctAfter}%"></div>
|
|
2724
|
+
</div>
|
|
2725
|
+
<div class="mushi-rewards-next-label">${nextLabel}</div>
|
|
2726
|
+
` : ""}
|
|
2727
|
+
</div>
|
|
2728
|
+
`;
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
// src/widget.ts
|
|
2732
|
+
var MushiWidget = class _MushiWidget {
|
|
2733
|
+
constructor(config = {}, callbacks, sdkVersion = MUSHI_SDK_VERSION) {
|
|
2734
|
+
this.sdkVersion = sdkVersion;
|
|
2735
|
+
this.config = {
|
|
2736
|
+
position: config.position ?? "bottom-right",
|
|
2737
|
+
anchor: config.anchor ?? {},
|
|
2738
|
+
theme: config.theme ?? "auto",
|
|
2739
|
+
// Falsy-OR (NOT `??`) on purpose: `triggerText: ''` is semantically
|
|
2740
|
+
// nonsense — it would render a labelless, glyphless trigger button
|
|
2741
|
+
// that users can't see or aim at. Treat empty string the same as
|
|
2742
|
+
// omitted so any caller that wires this to a cleared form input or
|
|
2743
|
+
// pastes a legacy snippet that emitted `triggerText: ""` (see
|
|
2744
|
+
// apps/admin/src/lib/sdkSnippets.ts widgetLines history) still gets
|
|
2745
|
+
// the default 🐛 and a visible button.
|
|
2746
|
+
triggerText: config.triggerText || "\u{1F41B}",
|
|
2747
|
+
expandedTitle: config.expandedTitle ?? "",
|
|
2748
|
+
mode: config.mode ?? "conversational",
|
|
2749
|
+
locale: config.locale ?? "auto",
|
|
2750
|
+
zIndex: config.zIndex ?? 99999,
|
|
2751
|
+
trigger: config.trigger ?? "auto",
|
|
2752
|
+
bannerConfig: config.bannerConfig ?? {},
|
|
2753
|
+
attachToSelector: config.attachToSelector ?? "",
|
|
2754
|
+
inset: config.inset ?? {},
|
|
2755
|
+
respectSafeArea: config.respectSafeArea ?? true,
|
|
2756
|
+
hideOnSelector: config.hideOnSelector ?? "",
|
|
2757
|
+
hideOnRoutes: config.hideOnRoutes ?? [],
|
|
2758
|
+
environments: config.environments ?? {},
|
|
2759
|
+
smartHide: config.smartHide ?? false,
|
|
2760
|
+
draggable: config.draggable ?? false,
|
|
2761
|
+
brandFooter: config.brandFooter ?? true,
|
|
2762
|
+
outdatedBanner: config.outdatedBanner ?? "auto",
|
|
2763
|
+
betaMode: config.betaMode ?? {},
|
|
2764
|
+
minDescriptionLength: config.minDescriptionLength ?? 20,
|
|
2765
|
+
dashboardUrl: config.dashboardUrl ?? "",
|
|
2766
|
+
responseSlaLabel: config.responseSlaLabel ?? "",
|
|
2767
|
+
featureRequestCard: config.featureRequestCard ?? true,
|
|
2768
|
+
featureRequestLabel: config.featureRequestLabel || "Feature request",
|
|
2769
|
+
featureRequestDescription: config.featureRequestDescription || "Suggest something new \u2014 even rough ideas help us prioritise",
|
|
2770
|
+
avoidSelectors: config.avoidSelectors ?? [],
|
|
2771
|
+
categories: config.categories ?? [],
|
|
2772
|
+
accent: config.accent ?? "",
|
|
2773
|
+
accentText: config.accentText ?? ""
|
|
2774
|
+
};
|
|
2775
|
+
this.callbacks = callbacks;
|
|
2776
|
+
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2777
|
+
this.host = document.createElement("div");
|
|
2778
|
+
this.host.id = "mushi-mushi-widget";
|
|
2779
|
+
this.shadow = this.host.attachShadow({ mode: "closed" });
|
|
2526
2780
|
}
|
|
2781
|
+
sdkVersion;
|
|
2782
|
+
host;
|
|
2783
|
+
shadow;
|
|
2784
|
+
config;
|
|
2785
|
+
callbacks;
|
|
2786
|
+
locale;
|
|
2787
|
+
isOpen = false;
|
|
2788
|
+
step = "category";
|
|
2527
2789
|
/**
|
|
2528
|
-
*
|
|
2529
|
-
*
|
|
2530
|
-
*
|
|
2531
|
-
* surfaces. Invalid selectors are swallowed silently (non-fatal).
|
|
2790
|
+
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
2791
|
+
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
2792
|
+
* after resolving through `resolveBaseCategory()`.
|
|
2532
2793
|
*/
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
try {
|
|
2536
|
-
return Boolean(document.querySelector(this.config.hideOnSelector));
|
|
2537
|
-
} catch {
|
|
2538
|
-
return false;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2794
|
+
selectedCategory = null;
|
|
2795
|
+
selectedIntent = null;
|
|
2541
2796
|
/**
|
|
2542
|
-
*
|
|
2543
|
-
* `
|
|
2544
|
-
*
|
|
2797
|
+
* True when the user took the "Feature request" shortcut. We track this
|
|
2798
|
+
* separately from `selectedCategory='other'` so the Back button on the
|
|
2799
|
+
* details step jumps straight back to the category picker instead of
|
|
2800
|
+
* landing on the intent picker the user explicitly skipped.
|
|
2545
2801
|
*/
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2802
|
+
viaFeatureRequest = false;
|
|
2803
|
+
screenshotAttached = false;
|
|
2804
|
+
screenshotCapturing = false;
|
|
2805
|
+
screenshotError = false;
|
|
2806
|
+
allowScreenshotRemove = true;
|
|
2807
|
+
elementSelected = false;
|
|
2808
|
+
elementCapturing = false;
|
|
2809
|
+
submitting = false;
|
|
2810
|
+
/** Hint element injected outside the shadow DOM during element selection. */
|
|
2811
|
+
selectorHint = null;
|
|
2812
|
+
triggerVisible = true;
|
|
2813
|
+
triggerShrunk = false;
|
|
2814
|
+
triggerHiddenByScroll = false;
|
|
2815
|
+
/** Milliseconds since mount — used for the 30s first-time nudge gate. */
|
|
2816
|
+
mountedAt = null;
|
|
2817
|
+
nudgeShown = false;
|
|
2818
|
+
nudgeEl = null;
|
|
2819
|
+
nudgeTimer = null;
|
|
2820
|
+
sdkFreshness = null;
|
|
2821
|
+
reporterReports = [];
|
|
2822
|
+
featureBoard = [];
|
|
2823
|
+
reporterComments = [];
|
|
2824
|
+
selectedReportId = null;
|
|
2825
|
+
reporterLoading = false;
|
|
2826
|
+
reporterError = null;
|
|
2827
|
+
attachedLaunchers = [];
|
|
2828
|
+
smartHideCleanup = null;
|
|
2829
|
+
smartHideTimer = null;
|
|
2830
|
+
/** Captured at the moment of submit so the success ledger metadata
|
|
2831
|
+
* ("REPORT · 14:23:07 JST") doesn't drift while the success step
|
|
2832
|
+
* is on screen. */
|
|
2833
|
+
submittedAt = null;
|
|
2834
|
+
/** Pending success-state + auto-close timers. Tracked so destroy()
|
|
2835
|
+
* can clear them — otherwise a host that unmounts mid-submit leaks
|
|
2836
|
+
* this MushiWidget reference (and re-renders into a detached shadow
|
|
2837
|
+
* root) for up to ~3.3s after destroy. */
|
|
2838
|
+
successTimer = null;
|
|
2839
|
+
autoCloseTimer = null;
|
|
2840
|
+
rewardsState = null;
|
|
2841
|
+
leaderboardEntries = null;
|
|
2842
|
+
leaderboardLoading = false;
|
|
2843
|
+
/** Server-confirmed id for the just-submitted report. Surfaces in
|
|
2844
|
+
* the success step as a copyable receipt + optional deep link to
|
|
2845
|
+
* the Mushi console (when `dashboardUrl` is configured). Cleared
|
|
2846
|
+
* on every new `open()` so a re-opened widget never reuses a
|
|
2847
|
+
* stale id from the previous session. */
|
|
2848
|
+
lastReportId = null;
|
|
2849
|
+
/** True when the just-submitted report was queued offline (no
|
|
2850
|
+
* network, or the API errored and went into the retry queue).
|
|
2851
|
+
* Drives a different success copy so the user knows the report
|
|
2852
|
+
* hasn't actually reached the console yet. */
|
|
2853
|
+
lastSubmitQueuedOffline = false;
|
|
2854
|
+
/** Whether the user has clicked ✕ on the header banner this session. */
|
|
2855
|
+
bannerDismissed = false;
|
|
2856
|
+
/** Persisted FAB position when draggable is enabled. */
|
|
2857
|
+
fabPos = null;
|
|
2858
|
+
/** Cleanup fn for visualViewport keyboard listener. */
|
|
2859
|
+
vvCleanup = null;
|
|
2860
|
+
/** Mushi tester session JWT — set after in-widget sign-in or by mushi.ts. */
|
|
2861
|
+
testerJwt = null;
|
|
2862
|
+
/** Tester identity (public_handle, display_name). */
|
|
2863
|
+
testerInfo = null;
|
|
2864
|
+
/** Cross-app reports for the signed-in tester. */
|
|
2865
|
+
crossAppReports = null;
|
|
2866
|
+
crossAppLoading = false;
|
|
2867
|
+
/** Global leaderboard entries (from mushi_testers, not org-scoped). */
|
|
2868
|
+
globalLeaderboard = null;
|
|
2869
|
+
globalLeaderboardLoading = false;
|
|
2870
|
+
/** Reputation for the signed-in tester. */
|
|
2871
|
+
testerReputation = null;
|
|
2872
|
+
/** Whether an in-widget magic-link email was just sent. */
|
|
2873
|
+
magicLinkSent = false;
|
|
2874
|
+
magicLinkEmail = "";
|
|
2875
|
+
magicLinkError = "";
|
|
2876
|
+
magicLinkSending = false;
|
|
2877
|
+
// double-submit guard
|
|
2878
|
+
// ─── Assistant tab (P5) ──────────────────────────────────────────
|
|
2879
|
+
assistantTurns = [];
|
|
2880
|
+
assistantThreadId = null;
|
|
2881
|
+
assistantSending = false;
|
|
2882
|
+
assistantError = null;
|
|
2883
|
+
mount() {
|
|
2884
|
+
if (this.host.isConnected) return;
|
|
2885
|
+
this.syncHostChromeState();
|
|
2886
|
+
document.body.appendChild(this.host);
|
|
2887
|
+
this.syncAttachedLaunchers();
|
|
2888
|
+
this.syncSmartHide();
|
|
2889
|
+
this.render();
|
|
2890
|
+
this.mountedAt = Date.now();
|
|
2597
2891
|
}
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
/** CSS property applied to document.body so host-app content doesn't slide under the banner. */
|
|
2601
|
-
static BODY_NUDGE_PROP = "--mushi-banner-offset";
|
|
2602
|
-
applyBodyNudge(position) {
|
|
2603
|
-
const h = `${_MushiWidget.BANNER_HEIGHT}px`;
|
|
2604
|
-
if (position === "top") {
|
|
2605
|
-
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
2606
|
-
if (!document.body.style.paddingTop) {
|
|
2607
|
-
document.body.style.paddingTop = h;
|
|
2608
|
-
document.body.dataset.mushiBannerNudged = "top";
|
|
2609
|
-
}
|
|
2610
|
-
} else {
|
|
2611
|
-
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
2612
|
-
if (!document.body.style.paddingBottom) {
|
|
2613
|
-
document.body.style.paddingBottom = h;
|
|
2614
|
-
document.body.dataset.mushiBannerNudged = "bottom";
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2892
|
+
getIsMounted() {
|
|
2893
|
+
return this.host.isConnected;
|
|
2617
2894
|
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2895
|
+
updateConfig(config = {}) {
|
|
2896
|
+
this.config = {
|
|
2897
|
+
...this.config,
|
|
2898
|
+
...config.position ? { position: config.position } : {},
|
|
2899
|
+
...config.anchor !== void 0 ? { anchor: config.anchor } : {},
|
|
2900
|
+
...config.theme ? { theme: config.theme } : {},
|
|
2901
|
+
...config.triggerText !== void 0 ? { triggerText: config.triggerText || "\u{1F41B}" } : {},
|
|
2902
|
+
...config.expandedTitle !== void 0 ? { expandedTitle: config.expandedTitle } : {},
|
|
2903
|
+
...config.mode ? { mode: config.mode } : {},
|
|
2904
|
+
...config.locale ? { locale: config.locale } : {},
|
|
2905
|
+
...config.zIndex !== void 0 ? { zIndex: config.zIndex } : {},
|
|
2906
|
+
...config.trigger ? { trigger: config.trigger } : {},
|
|
2907
|
+
...config.attachToSelector !== void 0 ? { attachToSelector: config.attachToSelector } : {},
|
|
2908
|
+
...config.inset !== void 0 ? { inset: config.inset } : {},
|
|
2909
|
+
...config.respectSafeArea !== void 0 ? { respectSafeArea: config.respectSafeArea } : {},
|
|
2910
|
+
...config.hideOnSelector !== void 0 ? { hideOnSelector: config.hideOnSelector } : {},
|
|
2911
|
+
...config.hideOnRoutes !== void 0 ? { hideOnRoutes: config.hideOnRoutes } : {},
|
|
2912
|
+
...config.environments !== void 0 ? { environments: config.environments } : {},
|
|
2913
|
+
...config.smartHide !== void 0 ? { smartHide: config.smartHide } : {},
|
|
2914
|
+
...config.draggable !== void 0 ? { draggable: config.draggable } : {},
|
|
2915
|
+
...config.brandFooter !== void 0 ? { brandFooter: config.brandFooter } : {},
|
|
2916
|
+
...config.outdatedBanner !== void 0 ? { outdatedBanner: config.outdatedBanner } : {},
|
|
2917
|
+
...config.betaMode !== void 0 ? { betaMode: config.betaMode } : {},
|
|
2918
|
+
...config.minDescriptionLength !== void 0 ? { minDescriptionLength: config.minDescriptionLength } : {},
|
|
2919
|
+
...config.dashboardUrl !== void 0 ? { dashboardUrl: config.dashboardUrl } : {},
|
|
2920
|
+
...config.responseSlaLabel !== void 0 ? { responseSlaLabel: config.responseSlaLabel } : {},
|
|
2921
|
+
...config.featureRequestCard !== void 0 ? { featureRequestCard: config.featureRequestCard } : {},
|
|
2922
|
+
...config.featureRequestLabel !== void 0 ? { featureRequestLabel: config.featureRequestLabel || "Feature request" } : {},
|
|
2923
|
+
...config.featureRequestDescription !== void 0 ? { featureRequestDescription: config.featureRequestDescription || "Suggest something new \u2014 even rough ideas help us prioritise" } : {},
|
|
2924
|
+
// Runtime/dashboard config delivers bannerMessage/bannerLabel via
|
|
2925
|
+
// mergeRuntimeConfig → bannerConfig. The widget is constructed before
|
|
2926
|
+
// that fetch resolves, so this pass-through is what makes server-driven
|
|
2927
|
+
// banner copy actually render.
|
|
2928
|
+
...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {},
|
|
2929
|
+
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2930
|
+
};
|
|
2931
|
+
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2932
|
+
if (this.host.isConnected) this.syncHostChromeState();
|
|
2933
|
+
this.syncAttachedLaunchers();
|
|
2934
|
+
this.syncSmartHide();
|
|
2935
|
+
this.render();
|
|
2628
2936
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
return;
|
|
2634
|
-
}
|
|
2635
|
-
if (!this.triggerVisible) {
|
|
2636
|
-
this.removeBodyNudge();
|
|
2637
|
-
return;
|
|
2638
|
-
}
|
|
2639
|
-
if (this.isRouteHidden()) {
|
|
2640
|
-
this.removeBodyNudge();
|
|
2641
|
-
return;
|
|
2642
|
-
}
|
|
2643
|
-
if (this.isSuppressedByHost()) {
|
|
2644
|
-
this.removeBodyNudge();
|
|
2645
|
-
return;
|
|
2646
|
-
}
|
|
2647
|
-
const bc = this.config.bannerConfig ?? {};
|
|
2648
|
-
const variant = bc.variant ?? "brand";
|
|
2649
|
-
const position = bc.position ?? "top";
|
|
2650
|
-
const message = bc.message?.trim() ?? "";
|
|
2651
|
-
const richLayout = message.length > 0;
|
|
2652
|
-
const bugLabel = bc.bugCta ?? "\u{1F41B} Report a bug";
|
|
2653
|
-
const showFeat = bc.featureCta !== false;
|
|
2654
|
-
const featLabel = bc.featureCtaLabel ?? "\u2728 Request feature";
|
|
2655
|
-
const zIdx = bc.zIndex ?? (this.config.zIndex ?? 99999) - 1;
|
|
2656
|
-
const banner = document.createElement("div");
|
|
2657
|
-
banner.className = `mushi-banner ${variant} ${position}${richLayout ? " mushi-banner--rich" : ""}`;
|
|
2658
|
-
banner.style.setProperty("--mushi-banner-z", String(zIdx));
|
|
2659
|
-
banner.setAttribute("role", "banner");
|
|
2660
|
-
const dismissBtn = document.createElement("button");
|
|
2661
|
-
dismissBtn.className = "mushi-banner-dismiss";
|
|
2662
|
-
dismissBtn.textContent = "\u2715";
|
|
2663
|
-
dismissBtn.setAttribute("aria-label", "Dismiss feedback banner");
|
|
2664
|
-
dismissBtn.addEventListener("click", () => {
|
|
2665
|
-
this.bannerDismissed = true;
|
|
2666
|
-
this.removeBodyNudge();
|
|
2667
|
-
this.render();
|
|
2668
|
-
});
|
|
2669
|
-
if (richLayout) {
|
|
2670
|
-
const body = document.createElement("div");
|
|
2671
|
-
body.className = "mushi-banner-body";
|
|
2672
|
-
const labelText = bc.label === false ? null : bc.label ?? "Beta";
|
|
2673
|
-
if (labelText) {
|
|
2674
|
-
const pill = document.createElement("span");
|
|
2675
|
-
pill.className = "mushi-banner-pill";
|
|
2676
|
-
pill.textContent = labelText;
|
|
2677
|
-
body.appendChild(pill);
|
|
2678
|
-
}
|
|
2679
|
-
const msg = document.createElement("span");
|
|
2680
|
-
msg.className = "mushi-banner-message";
|
|
2681
|
-
msg.textContent = message;
|
|
2682
|
-
body.appendChild(msg);
|
|
2683
|
-
banner.appendChild(body);
|
|
2684
|
-
const nav = document.createElement("nav");
|
|
2685
|
-
nav.className = "mushi-banner-actions";
|
|
2686
|
-
nav.setAttribute("aria-label", "Feedback banner actions");
|
|
2687
|
-
const appendDivider = (extra = false) => {
|
|
2688
|
-
const sep = document.createElement("span");
|
|
2689
|
-
sep.className = `mushi-banner-divider${extra ? " mushi-banner-extra" : ""}`;
|
|
2690
|
-
sep.setAttribute("aria-hidden", "true");
|
|
2691
|
-
sep.textContent = "|";
|
|
2692
|
-
nav.appendChild(sep);
|
|
2693
|
-
};
|
|
2694
|
-
const appendAction = (label, onClick, extra = false) => {
|
|
2695
|
-
const btn = document.createElement("button");
|
|
2696
|
-
btn.type = "button";
|
|
2697
|
-
btn.className = `mushi-banner-link${extra ? " mushi-banner-extra" : ""}`;
|
|
2698
|
-
btn.textContent = label;
|
|
2699
|
-
btn.addEventListener("click", onClick);
|
|
2700
|
-
nav.appendChild(btn);
|
|
2701
|
-
};
|
|
2702
|
-
appendAction(bugLabel, () => this.open());
|
|
2703
|
-
if (showFeat) {
|
|
2704
|
-
appendDivider(true);
|
|
2705
|
-
appendAction(featLabel, () => this.open({ featureRequest: true }), true);
|
|
2706
|
-
}
|
|
2707
|
-
for (const link of bc.links ?? []) {
|
|
2708
|
-
const linkLabel = link.label?.trim();
|
|
2709
|
-
if (!linkLabel) continue;
|
|
2710
|
-
const href = link.href && (/^https?:\/\//i.test(link.href) || link.href.startsWith("/")) ? link.href : void 0;
|
|
2711
|
-
appendDivider(true);
|
|
2712
|
-
if (href) {
|
|
2713
|
-
const anchor = document.createElement("a");
|
|
2714
|
-
anchor.className = "mushi-banner-link mushi-banner-extra";
|
|
2715
|
-
anchor.href = href;
|
|
2716
|
-
anchor.textContent = linkLabel;
|
|
2717
|
-
anchor.target = "_blank";
|
|
2718
|
-
anchor.rel = "noopener noreferrer";
|
|
2719
|
-
nav.appendChild(anchor);
|
|
2720
|
-
} else {
|
|
2721
|
-
appendAction(linkLabel, () => {
|
|
2722
|
-
if (link.featureRequest) this.open({ featureRequest: true });
|
|
2723
|
-
else this.open();
|
|
2724
|
-
}, true);
|
|
2725
|
-
}
|
|
2726
|
-
}
|
|
2727
|
-
banner.appendChild(nav);
|
|
2728
|
-
banner.appendChild(dismissBtn);
|
|
2729
|
-
} else {
|
|
2730
|
-
const bugBtn = document.createElement("button");
|
|
2731
|
-
bugBtn.className = "mushi-banner-btn";
|
|
2732
|
-
bugBtn.textContent = bugLabel;
|
|
2733
|
-
bugBtn.addEventListener("click", () => this.open());
|
|
2734
|
-
banner.appendChild(bugBtn);
|
|
2735
|
-
if (showFeat) {
|
|
2736
|
-
const featBtn = document.createElement("button");
|
|
2737
|
-
featBtn.className = "mushi-banner-btn";
|
|
2738
|
-
featBtn.textContent = featLabel;
|
|
2739
|
-
featBtn.addEventListener("click", () => this.open({ featureRequest: true }));
|
|
2740
|
-
banner.appendChild(featBtn);
|
|
2741
|
-
}
|
|
2742
|
-
banner.appendChild(dismissBtn);
|
|
2743
|
-
}
|
|
2744
|
-
this.shadow.appendChild(banner);
|
|
2745
|
-
this.applyBodyNudge(position);
|
|
2937
|
+
// ─── Custom category helpers ──────────────────────────────────────────────
|
|
2938
|
+
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
2939
|
+
resolveCustomCategory(id) {
|
|
2940
|
+
return this.config.categories?.find((c) => c.id === id);
|
|
2746
2941
|
}
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
return
|
|
2942
|
+
/**
|
|
2943
|
+
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
2944
|
+
* used for the report wire format. Falls back to `'other'`.
|
|
2945
|
+
*/
|
|
2946
|
+
resolveBaseCategory(id) {
|
|
2947
|
+
const BUILTIN = ["bug", "slow", "visual", "confusing", "other"];
|
|
2948
|
+
if (BUILTIN.includes(id)) return id;
|
|
2949
|
+
const custom = this.resolveCustomCategory(id);
|
|
2950
|
+
return custom?.baseCategory ?? "other";
|
|
2754
2951
|
}
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
const
|
|
2758
|
-
|
|
2952
|
+
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
2953
|
+
categoryIcon(id) {
|
|
2954
|
+
const custom = this.resolveCustomCategory(id);
|
|
2955
|
+
if (custom?.icon) return custom.icon;
|
|
2956
|
+
return CATEGORY_ICONS[id] ?? "\u{1F4AC}";
|
|
2759
2957
|
}
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
if (
|
|
2764
|
-
|
|
2958
|
+
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
2959
|
+
categoryLabel(id) {
|
|
2960
|
+
const custom = this.resolveCustomCategory(id);
|
|
2961
|
+
if (custom) return custom.label;
|
|
2962
|
+
const t = this.locale;
|
|
2963
|
+
return t.step1.categories[id] ?? id;
|
|
2964
|
+
}
|
|
2965
|
+
// ─── Open / close ─────────────────────────────────────────────────────────
|
|
2966
|
+
open(options) {
|
|
2967
|
+
if (this.isOpen) return;
|
|
2968
|
+
this.isOpen = true;
|
|
2969
|
+
this.screenshotAttached = false;
|
|
2970
|
+
this.screenshotCapturing = false;
|
|
2971
|
+
this.screenshotError = false;
|
|
2972
|
+
this.elementSelected = false;
|
|
2973
|
+
this.elementCapturing = false;
|
|
2974
|
+
this.submitting = false;
|
|
2975
|
+
this.submittedAt = null;
|
|
2976
|
+
this.removeSelectorHint();
|
|
2977
|
+
this.lastReportId = null;
|
|
2978
|
+
this.lastSubmitQueuedOffline = false;
|
|
2979
|
+
this.viaFeatureRequest = false;
|
|
2980
|
+
if (options?.featureRequest) {
|
|
2981
|
+
this.selectedCategory = "other";
|
|
2982
|
+
this.selectedIntent = FEATURE_REQUEST_INTENT;
|
|
2983
|
+
this.viaFeatureRequest = true;
|
|
2984
|
+
this.step = "details";
|
|
2985
|
+
} else if (options?.category) {
|
|
2986
|
+
const custom = this.resolveCustomCategory(options.category);
|
|
2987
|
+
const builtIn = ["bug", "slow", "visual", "confusing", "other"];
|
|
2988
|
+
const isKnown = builtIn.includes(options.category) || custom !== void 0;
|
|
2989
|
+
if (!isKnown) {
|
|
2990
|
+
this.selectedCategory = null;
|
|
2991
|
+
this.selectedIntent = null;
|
|
2992
|
+
this.step = "category";
|
|
2993
|
+
} else {
|
|
2994
|
+
this.selectedCategory = options.category;
|
|
2995
|
+
this.selectedIntent = null;
|
|
2996
|
+
this.step = custom && (!custom.intents || custom.intents.length === 0) ? "details" : "intent";
|
|
2997
|
+
}
|
|
2998
|
+
} else {
|
|
2999
|
+
this.selectedCategory = null;
|
|
3000
|
+
this.selectedIntent = null;
|
|
3001
|
+
this.step = "category";
|
|
3002
|
+
}
|
|
3003
|
+
this.render();
|
|
3004
|
+
this.callbacks.onOpen();
|
|
2765
3005
|
}
|
|
2766
|
-
|
|
2767
|
-
if (!this.
|
|
2768
|
-
|
|
3006
|
+
close() {
|
|
3007
|
+
if (!this.isOpen) return;
|
|
3008
|
+
this.isOpen = false;
|
|
3009
|
+
this.render();
|
|
3010
|
+
this.callbacks.onClose();
|
|
2769
3011
|
}
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
if (
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
const colorScheme = root.getAttribute("data-color-scheme") || root.getAttribute("data-theme") || root.getAttribute("color-scheme") || "";
|
|
2776
|
-
if (/dark/i.test(colorScheme)) return "dark";
|
|
2777
|
-
if (/light/i.test(colorScheme)) return "light";
|
|
2778
|
-
if (root.classList.contains("dark")) return "dark";
|
|
2779
|
-
if (root.classList.contains("light")) return "light";
|
|
2780
|
-
try {
|
|
2781
|
-
const bg = getComputedStyle(root).backgroundColor;
|
|
2782
|
-
const m = bg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
2783
|
-
if (m) {
|
|
2784
|
-
const L = 0.299 * +m[1] + 0.587 * +m[2] + 0.114 * +m[3];
|
|
2785
|
-
return L < 128 ? "dark" : "light";
|
|
2786
|
-
}
|
|
2787
|
-
} catch {
|
|
2788
|
-
}
|
|
3012
|
+
/** Open the panel directly on the assistant ("Ask") tab. */
|
|
3013
|
+
openAssistantTab() {
|
|
3014
|
+
if (!this.callbacks.assistantEnabled) {
|
|
3015
|
+
this.open();
|
|
3016
|
+
return;
|
|
2789
3017
|
}
|
|
2790
|
-
if (
|
|
2791
|
-
|
|
3018
|
+
if (!this.isOpen) {
|
|
3019
|
+
this.isOpen = true;
|
|
3020
|
+
this.callbacks.onOpen();
|
|
2792
3021
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
this.
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
this.removeNudge();
|
|
2821
|
-
if (this.isOpen) this.close();
|
|
2822
|
-
else this.open();
|
|
2823
|
-
});
|
|
2824
|
-
trigger.addEventListener("mouseenter", () => {
|
|
2825
|
-
const onPageMs = this.mountedAt ? Date.now() - this.mountedAt : 0;
|
|
2826
|
-
if (!this.nudgeShown && !this.isOpen && onPageMs >= 3e4) {
|
|
2827
|
-
this.showNudge();
|
|
2828
|
-
}
|
|
2829
|
-
});
|
|
2830
|
-
trigger.addEventListener("mouseleave", () => {
|
|
2831
|
-
if (this.nudgeEl) {
|
|
2832
|
-
if (this.nudgeTimer !== null) clearTimeout(this.nudgeTimer);
|
|
2833
|
-
this.nudgeTimer = setTimeout(() => this.removeNudge(), 2e3);
|
|
2834
|
-
}
|
|
2835
|
-
});
|
|
2836
|
-
trigger.addEventListener("keydown", (e) => {
|
|
2837
|
-
const draggableConfig = this.config.draggable;
|
|
2838
|
-
if (!draggableConfig) return;
|
|
2839
|
-
const STEP = 8;
|
|
2840
|
-
const axis = typeof draggableConfig === "object" ? draggableConfig.axis ?? "both" : "both";
|
|
2841
|
-
let dx = 0, dy = 0;
|
|
2842
|
-
if (axis !== "y") {
|
|
2843
|
-
if (e.key === "ArrowLeft") dx = -STEP;
|
|
2844
|
-
else if (e.key === "ArrowRight") dx = STEP;
|
|
2845
|
-
}
|
|
2846
|
-
if (axis !== "x") {
|
|
2847
|
-
if (e.key === "ArrowUp") dy = -STEP;
|
|
2848
|
-
else if (e.key === "ArrowDown") dy = STEP;
|
|
2849
|
-
}
|
|
2850
|
-
if (dx !== 0 || dy !== 0) {
|
|
2851
|
-
e.preventDefault();
|
|
2852
|
-
const cur = this.fabPos ?? { x: 0, y: 0 };
|
|
2853
|
-
this.moveFab(trigger, cur.x + dx, cur.y + dy, false);
|
|
3022
|
+
this.step = "assistant";
|
|
3023
|
+
this.assistantError = null;
|
|
3024
|
+
this.render();
|
|
3025
|
+
setTimeout(() => {
|
|
3026
|
+
this.shadow.querySelector(".mushi-assistant-input")?.focus();
|
|
3027
|
+
}, 0);
|
|
3028
|
+
}
|
|
3029
|
+
/** Send one assistant turn and re-render as the reply streams back. */
|
|
3030
|
+
async sendAssistantMessage(message) {
|
|
3031
|
+
const text = message.trim();
|
|
3032
|
+
if (!text || this.assistantSending || !this.callbacks.onAssistantAsk) return;
|
|
3033
|
+
this.assistantSending = true;
|
|
3034
|
+
this.assistantError = null;
|
|
3035
|
+
this.assistantTurns.push({ role: "user", text });
|
|
3036
|
+
this.render();
|
|
3037
|
+
try {
|
|
3038
|
+
const reply = await this.callbacks.onAssistantAsk(text, this.assistantThreadId);
|
|
3039
|
+
if (reply) {
|
|
3040
|
+
if (reply.threadId) this.assistantThreadId = reply.threadId;
|
|
3041
|
+
if (reply.kind === "clarify") {
|
|
3042
|
+
this.assistantTurns.push({
|
|
3043
|
+
role: "assistant",
|
|
3044
|
+
text: reply.question ?? "Could you tell me a bit more?",
|
|
3045
|
+
...reply.options && reply.options.length ? { options: reply.options } : {}
|
|
3046
|
+
});
|
|
3047
|
+
} else {
|
|
3048
|
+
this.assistantTurns.push({ role: "assistant", text: reply.text ?? "\u2026" });
|
|
2854
3049
|
}
|
|
2855
|
-
}
|
|
2856
|
-
|
|
2857
|
-
this.attachDragHandlers(trigger);
|
|
3050
|
+
} else {
|
|
3051
|
+
this.assistantError = "No response \u2014 please try again.";
|
|
2858
3052
|
}
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
if (this.isOpen) {
|
|
2869
|
-
panel.innerHTML = `${this.renderOutdatedBanner()}${this.renderStep()}${this.renderBrandFooter()}`;
|
|
2870
|
-
this.shadow.appendChild(panel);
|
|
2871
|
-
this.attachHandlers(panel);
|
|
2872
|
-
this.trapFocus(panel);
|
|
2873
|
-
this.attachViewportHandlers(panel);
|
|
2874
|
-
} else {
|
|
2875
|
-
this.teardownViewportHandlers();
|
|
3053
|
+
} catch {
|
|
3054
|
+
this.assistantError = "Something went wrong. Please try again.";
|
|
3055
|
+
} finally {
|
|
3056
|
+
this.assistantSending = false;
|
|
3057
|
+
this.render();
|
|
3058
|
+
setTimeout(() => {
|
|
3059
|
+
const log = this.shadow.querySelector(".mushi-assistant-log");
|
|
3060
|
+
if (log) log.scrollTop = log.scrollHeight;
|
|
3061
|
+
}, 0);
|
|
2876
3062
|
}
|
|
2877
3063
|
}
|
|
2878
3064
|
/**
|
|
2879
|
-
*
|
|
2880
|
-
* the
|
|
2881
|
-
*
|
|
2882
|
-
*
|
|
2883
|
-
*
|
|
2884
|
-
* Runs in the host document (not shadow DOM) so it can reach fixed headers,
|
|
2885
|
-
* sticky nav bars, and sign-in CTAs.
|
|
3065
|
+
* Briefly highlight the trigger button (a soft pulse + tooltip) without
|
|
3066
|
+
* opening the full reporter panel. Use for first-session welcome nudges
|
|
3067
|
+
* and other "by the way, this exists" prompts where forcing the panel
|
|
3068
|
+
* open would feel aggressive. Honours `position: 'none'` (no-op when
|
|
3069
|
+
* the trigger button is hidden).
|
|
2886
3070
|
*/
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
const r = el.getBoundingClientRect();
|
|
2896
|
-
if (r.bottom > maxBottom && r.width > 0 && r.height > 0) {
|
|
2897
|
-
maxBottom = r.bottom;
|
|
2898
|
-
}
|
|
2899
|
-
} catch {
|
|
2900
|
-
}
|
|
2901
|
-
}
|
|
2902
|
-
return maxBottom > 0 ? Math.ceil(maxBottom) + gap : null;
|
|
3071
|
+
pulseTrigger() {
|
|
3072
|
+
if (this.isOpen) return;
|
|
3073
|
+
const trigger = this.shadow.querySelector(".mushi-trigger");
|
|
3074
|
+
if (!trigger) return;
|
|
3075
|
+
trigger.classList.add("mushi-trigger-pulse");
|
|
3076
|
+
window.setTimeout(() => {
|
|
3077
|
+
trigger.classList.remove("mushi-trigger-pulse");
|
|
3078
|
+
}, 2400);
|
|
2903
3079
|
}
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
3080
|
+
getIsOpen() {
|
|
3081
|
+
return this.isOpen;
|
|
3082
|
+
}
|
|
3083
|
+
showTrigger() {
|
|
3084
|
+
this.triggerVisible = true;
|
|
3085
|
+
this.render();
|
|
3086
|
+
}
|
|
3087
|
+
hideTrigger() {
|
|
3088
|
+
this.triggerVisible = false;
|
|
3089
|
+
this.render();
|
|
3090
|
+
}
|
|
3091
|
+
setTrigger(trigger) {
|
|
3092
|
+
this.updateConfig({ trigger });
|
|
3093
|
+
}
|
|
3094
|
+
attachTo(selectorOrElement, options = {}) {
|
|
3095
|
+
const elements = typeof selectorOrElement === "string" ? Array.from(document.querySelectorAll(selectorOrElement)) : [selectorOrElement];
|
|
3096
|
+
const cleanups = elements.map((el) => {
|
|
3097
|
+
const onClick = (event) => {
|
|
3098
|
+
event.preventDefault();
|
|
3099
|
+
this.updateConfig(options);
|
|
3100
|
+
this.open();
|
|
3101
|
+
};
|
|
3102
|
+
el.addEventListener("click", onClick);
|
|
3103
|
+
return () => el.removeEventListener("click", onClick);
|
|
3104
|
+
});
|
|
3105
|
+
return () => cleanups.forEach((cleanup) => cleanup());
|
|
3106
|
+
}
|
|
3107
|
+
setScreenshotAttached(attached) {
|
|
3108
|
+
this.screenshotAttached = attached;
|
|
3109
|
+
if (this.isOpen) this.render();
|
|
3110
|
+
}
|
|
3111
|
+
setAllowScreenshotRemove(allow) {
|
|
3112
|
+
this.allowScreenshotRemove = allow;
|
|
3113
|
+
if (this.isOpen) this.render();
|
|
3114
|
+
}
|
|
3115
|
+
setElementSelected(selected) {
|
|
3116
|
+
this.elementSelected = selected;
|
|
3117
|
+
this.elementCapturing = false;
|
|
3118
|
+
this.removeSelectorHint();
|
|
3119
|
+
if (this.isOpen) this.render();
|
|
3120
|
+
}
|
|
3121
|
+
setScreenshotCapturing(capturing) {
|
|
3122
|
+
this.screenshotCapturing = capturing;
|
|
3123
|
+
this.screenshotError = false;
|
|
3124
|
+
if (this.isOpen) this.render();
|
|
3125
|
+
}
|
|
3126
|
+
setScreenshotError(failed) {
|
|
3127
|
+
this.screenshotError = failed;
|
|
3128
|
+
this.screenshotCapturing = false;
|
|
3129
|
+
if (this.isOpen) this.render();
|
|
3130
|
+
}
|
|
3131
|
+
setElementCapturing(capturing) {
|
|
3132
|
+
this.elementCapturing = capturing;
|
|
3133
|
+
if (capturing) {
|
|
3134
|
+
this.showSelectorHint();
|
|
2912
3135
|
} else {
|
|
2913
|
-
|
|
2914
|
-
if (!this.config.respectSafeArea) {
|
|
2915
|
-
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
2916
|
-
if (inset[edge] === void 0) el.style.setProperty(`--mushi-${edge}`, "24px");
|
|
2917
|
-
});
|
|
2918
|
-
}
|
|
2919
|
-
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
2920
|
-
const value = inset[edge];
|
|
2921
|
-
if (value === void 0) return;
|
|
2922
|
-
el.style.setProperty(`--mushi-${edge}`, value === "auto" ? "auto" : `${value}px`);
|
|
2923
|
-
});
|
|
2924
|
-
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
2925
|
-
}
|
|
2926
|
-
const isTopAnchored = anchor?.top !== void 0 || this.config.position?.startsWith("top") || !this.config.position && !anchor?.bottom;
|
|
2927
|
-
if (isTopAnchored) {
|
|
2928
|
-
const avoidPx = this.computeAvoidTopPx();
|
|
2929
|
-
if (avoidPx !== null) {
|
|
2930
|
-
el.style.setProperty("--mushi-top", `${avoidPx}px`);
|
|
2931
|
-
}
|
|
3136
|
+
this.removeSelectorHint();
|
|
2932
3137
|
}
|
|
3138
|
+
if (this.isOpen) this.render();
|
|
3139
|
+
}
|
|
3140
|
+
/** Hide the widget panel (but keep the host element) during element selection
|
|
3141
|
+
* so the user can click any element on the page without the panel
|
|
3142
|
+
* intercepting the event. */
|
|
3143
|
+
hidePanel() {
|
|
3144
|
+
const panel = this.shadow.querySelector(".mushi-panel");
|
|
3145
|
+
if (panel) panel.style.display = "none";
|
|
3146
|
+
}
|
|
3147
|
+
showPanel() {
|
|
3148
|
+
const panel = this.shadow.querySelector(".mushi-panel");
|
|
3149
|
+
if (panel) panel.style.display = "";
|
|
3150
|
+
}
|
|
3151
|
+
showSelectorHint() {
|
|
3152
|
+
this.removeSelectorHint();
|
|
3153
|
+
const hint = document.createElement("div");
|
|
3154
|
+
hint.id = "mushi-selector-hint";
|
|
3155
|
+
hint.setAttribute("role", "status");
|
|
3156
|
+
hint.setAttribute("aria-live", "polite");
|
|
3157
|
+
hint.style.cssText = `
|
|
3158
|
+
position: fixed;
|
|
3159
|
+
bottom: 24px;
|
|
3160
|
+
left: 50%;
|
|
3161
|
+
transform: translateX(-50%);
|
|
3162
|
+
z-index: 2147483646;
|
|
3163
|
+
background: rgba(17,17,17,0.92);
|
|
3164
|
+
color: #fff;
|
|
3165
|
+
font-family: ui-monospace, SFMono-Regular, monospace;
|
|
3166
|
+
font-size: 12px;
|
|
3167
|
+
letter-spacing: 0.04em;
|
|
3168
|
+
padding: 8px 16px;
|
|
3169
|
+
border-radius: 20px;
|
|
3170
|
+
pointer-events: none;
|
|
3171
|
+
white-space: nowrap;
|
|
3172
|
+
backdrop-filter: blur(4px);
|
|
3173
|
+
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
3174
|
+
`;
|
|
3175
|
+
hint.textContent = this.locale.step3.elementSelectorHint;
|
|
3176
|
+
document.body.appendChild(hint);
|
|
3177
|
+
this.selectorHint = hint;
|
|
2933
3178
|
}
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
return `mushi_fab_pos${id ? `_${id}` : ""}`;
|
|
3179
|
+
removeSelectorHint() {
|
|
3180
|
+
this.selectorHint?.remove();
|
|
3181
|
+
this.selectorHint = null;
|
|
3182
|
+
document.getElementById("mushi-selector-hint")?.remove();
|
|
2939
3183
|
}
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
const
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
const newX = axis === "y" ? 0 : Math.max(minX, Math.min(maxX, x));
|
|
2972
|
-
const newY = axis === "x" ? 0 : Math.max(minY, Math.min(maxY, y));
|
|
2973
|
-
let finalX = newX;
|
|
2974
|
-
if (snap) {
|
|
2975
|
-
const d2 = this.config.draggable;
|
|
2976
|
-
const shouldSnap = d2 === true || typeof d2 === "object" && (d2.snapToEdge ?? true);
|
|
2977
|
-
if (shouldSnap && axis !== "y") {
|
|
2978
|
-
const center = rect.left + btnW / 2;
|
|
2979
|
-
finalX = center < W / 2 ? safeL + margin - baseLeft : W - safeR - margin - btnW - baseLeft;
|
|
2980
|
-
}
|
|
2981
|
-
}
|
|
2982
|
-
this.fabPos = { x: finalX, y: newY };
|
|
2983
|
-
trigger.style.setProperty("--mushi-drag-x", `${finalX}px`);
|
|
2984
|
-
trigger.style.setProperty("--mushi-drag-y", `${newY}px`);
|
|
2985
|
-
trigger.style.setProperty("--mushi-drag-active", "1");
|
|
2986
|
-
const d = this.config.draggable;
|
|
2987
|
-
const shouldPersist = d === true || typeof d === "object" && (d.persist ?? true);
|
|
2988
|
-
if (shouldPersist) {
|
|
2989
|
-
try {
|
|
2990
|
-
localStorage.setItem(this.fabStorageKey(), JSON.stringify(this.fabPos));
|
|
2991
|
-
} catch {
|
|
2992
|
-
}
|
|
2993
|
-
}
|
|
3184
|
+
showNudge() {
|
|
3185
|
+
if (this.nudgeShown || this.nudgeEl) return;
|
|
3186
|
+
this.nudgeShown = true;
|
|
3187
|
+
const trigger = this.shadow.querySelector(".mushi-trigger");
|
|
3188
|
+
const rect = trigger?.getBoundingClientRect();
|
|
3189
|
+
const nudge = document.createElement("div");
|
|
3190
|
+
nudge.id = "mushi-nudge-bubble";
|
|
3191
|
+
nudge.setAttribute("role", "tooltip");
|
|
3192
|
+
const isRight = this.config.position.includes("right");
|
|
3193
|
+
nudge.style.cssText = `
|
|
3194
|
+
position: fixed;
|
|
3195
|
+
z-index: 2147483645;
|
|
3196
|
+
${rect ? `bottom: ${window.innerHeight - rect.top + 8}px; ${isRight ? `right: ${window.innerWidth - rect.right}px;` : `left: ${rect.left}px;`}` : "bottom: 80px; right: 24px;"}
|
|
3197
|
+
background: rgba(17,17,17,0.92);
|
|
3198
|
+
color: #fff;
|
|
3199
|
+
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
3200
|
+
font-size: 12px;
|
|
3201
|
+
line-height: 1.4;
|
|
3202
|
+
padding: 8px 12px;
|
|
3203
|
+
border-radius: 8px;
|
|
3204
|
+
max-width: 200px;
|
|
3205
|
+
pointer-events: none;
|
|
3206
|
+
backdrop-filter: blur(4px);
|
|
3207
|
+
box-shadow: 0 2px 12px rgba(0,0,0,0.35);
|
|
3208
|
+
animation: mushi-fade-in 0.15s ease forwards;
|
|
3209
|
+
`;
|
|
3210
|
+
nudge.textContent = this.locale.step3.tooShort.startsWith("A bit") ? "Found a bug? One sentence is enough \u{1F41B}" : "\u30D0\u30B0\u3092\u898B\u3064\u3051\u305F\uFF1F\u4E00\u884C\u3067\u5927\u4E08\u592B\u3067\u3059 \u{1F41B}";
|
|
3211
|
+
document.body.appendChild(nudge);
|
|
3212
|
+
this.nudgeEl = nudge;
|
|
3213
|
+
if (this.nudgeTimer !== null) clearTimeout(this.nudgeTimer);
|
|
3214
|
+
this.nudgeTimer = setTimeout(() => this.removeNudge(), 5e3);
|
|
2994
3215
|
}
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
const shouldPersist = d === true || typeof d === "object" && (d.persist ?? true);
|
|
3000
|
-
if (!shouldPersist) return;
|
|
3001
|
-
try {
|
|
3002
|
-
const raw = localStorage.getItem(this.fabStorageKey());
|
|
3003
|
-
if (raw) {
|
|
3004
|
-
const parsed = JSON.parse(raw);
|
|
3005
|
-
if (typeof parsed?.x === "number" && typeof parsed?.y === "number") {
|
|
3006
|
-
this.fabPos = parsed;
|
|
3007
|
-
}
|
|
3008
|
-
}
|
|
3009
|
-
} catch {
|
|
3216
|
+
removeNudge() {
|
|
3217
|
+
if (this.nudgeTimer !== null) {
|
|
3218
|
+
clearTimeout(this.nudgeTimer);
|
|
3219
|
+
this.nudgeTimer = null;
|
|
3010
3220
|
}
|
|
3221
|
+
this.nudgeEl?.remove();
|
|
3222
|
+
this.nudgeEl = null;
|
|
3223
|
+
document.getElementById("mushi-nudge-bubble")?.remove();
|
|
3011
3224
|
}
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
if (this.
|
|
3015
|
-
let startX = 0, startY = 0;
|
|
3016
|
-
let originX = 0, originY = 0;
|
|
3017
|
-
let dragging = false;
|
|
3018
|
-
let moved = false;
|
|
3019
|
-
const onPointerDown = (e) => {
|
|
3020
|
-
if (e.button !== 0 && e.pointerType !== "touch") return;
|
|
3021
|
-
trigger.setPointerCapture(e.pointerId);
|
|
3022
|
-
startX = e.clientX;
|
|
3023
|
-
startY = e.clientY;
|
|
3024
|
-
const cur = this.fabPos ?? { x: 0, y: 0 };
|
|
3025
|
-
originX = cur.x;
|
|
3026
|
-
originY = cur.y;
|
|
3027
|
-
dragging = true;
|
|
3028
|
-
moved = false;
|
|
3029
|
-
};
|
|
3030
|
-
const DRAG_THRESHOLD = 6;
|
|
3031
|
-
const onPointerMove = (e) => {
|
|
3032
|
-
if (!dragging) return;
|
|
3033
|
-
const dx = e.clientX - startX;
|
|
3034
|
-
const dy = e.clientY - startY;
|
|
3035
|
-
if (!moved && Math.hypot(dx, dy) > DRAG_THRESHOLD) {
|
|
3036
|
-
moved = true;
|
|
3037
|
-
trigger.classList.add("dragging");
|
|
3038
|
-
trigger.setAttribute("aria-grabbed", "true");
|
|
3039
|
-
}
|
|
3040
|
-
if (moved) {
|
|
3041
|
-
e.preventDefault();
|
|
3042
|
-
this.moveFab(trigger, originX + dx, originY + dy, false);
|
|
3043
|
-
}
|
|
3044
|
-
};
|
|
3045
|
-
const onPointerUp = (e) => {
|
|
3046
|
-
if (!dragging) return;
|
|
3047
|
-
dragging = false;
|
|
3048
|
-
trigger.classList.remove("dragging");
|
|
3049
|
-
trigger.removeAttribute("aria-grabbed");
|
|
3050
|
-
if (moved) {
|
|
3051
|
-
const dx = e.clientX - startX;
|
|
3052
|
-
const dy = e.clientY - startY;
|
|
3053
|
-
this.moveFab(trigger, originX + dx, originY + dy, true);
|
|
3054
|
-
const suppressClick = (ev) => {
|
|
3055
|
-
ev.stopImmediatePropagation();
|
|
3056
|
-
trigger.removeEventListener("click", suppressClick, { capture: true });
|
|
3057
|
-
};
|
|
3058
|
-
trigger.addEventListener("click", suppressClick, { capture: true });
|
|
3059
|
-
}
|
|
3060
|
-
moved = false;
|
|
3061
|
-
};
|
|
3062
|
-
trigger.addEventListener("pointerdown", onPointerDown);
|
|
3063
|
-
trigger.addEventListener("pointermove", onPointerMove);
|
|
3064
|
-
trigger.addEventListener("pointerup", onPointerUp);
|
|
3065
|
-
trigger.addEventListener("pointercancel", onPointerUp);
|
|
3225
|
+
setSdkFreshness(info) {
|
|
3226
|
+
this.sdkFreshness = info;
|
|
3227
|
+
if (this.isOpen) this.render();
|
|
3066
3228
|
}
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
this.teardownViewportHandlers();
|
|
3071
|
-
const vv = window.visualViewport;
|
|
3072
|
-
if (!vv) return;
|
|
3073
|
-
const update = () => {
|
|
3074
|
-
const keyboardInset = window.innerHeight - vv.height - vv.offsetTop;
|
|
3075
|
-
if (keyboardInset > 50) {
|
|
3076
|
-
panel.style.setProperty("--mushi-keyboard-inset", `${Math.round(keyboardInset)}px`);
|
|
3077
|
-
panel.classList.add("keyboard-open");
|
|
3078
|
-
const ta = panel.querySelector('textarea, input[type="text"]');
|
|
3079
|
-
ta?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
3080
|
-
} else {
|
|
3081
|
-
panel.style.setProperty("--mushi-keyboard-inset", "0px");
|
|
3082
|
-
panel.classList.remove("keyboard-open");
|
|
3083
|
-
}
|
|
3084
|
-
};
|
|
3085
|
-
vv.addEventListener("resize", update, { passive: true });
|
|
3086
|
-
vv.addEventListener("scroll", update, { passive: true });
|
|
3087
|
-
const onFocus = () => requestAnimationFrame(update);
|
|
3088
|
-
panel.addEventListener("focusin", onFocus);
|
|
3089
|
-
this.vvCleanup = () => {
|
|
3090
|
-
vv.removeEventListener("resize", update);
|
|
3091
|
-
vv.removeEventListener("scroll", update);
|
|
3092
|
-
panel.removeEventListener("focusin", onFocus);
|
|
3093
|
-
};
|
|
3229
|
+
setRewardsState(state) {
|
|
3230
|
+
this.rewardsState = state;
|
|
3231
|
+
if (this.isOpen) this.render();
|
|
3094
3232
|
}
|
|
3095
|
-
|
|
3096
|
-
this.
|
|
3097
|
-
this.
|
|
3233
|
+
setLeaderboard(entries, loading = false) {
|
|
3234
|
+
this.leaderboardEntries = entries;
|
|
3235
|
+
this.leaderboardLoading = loading;
|
|
3236
|
+
if (this.isOpen && this.step === "leaderboard") this.render();
|
|
3098
3237
|
}
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
return this.renderAccountStep();
|
|
3119
|
-
case "cross-app-reports":
|
|
3120
|
-
return this.renderCrossAppReportsStep();
|
|
3121
|
-
}
|
|
3122
|
-
}
|
|
3123
|
-
renderOutdatedBanner() {
|
|
3124
|
-
if (!this.sdkFreshness) return "";
|
|
3125
|
-
if (this.config.outdatedBanner === "off" || this.config.outdatedBanner === "console-only") return "";
|
|
3126
|
-
const { latest, current, deprecated, message } = this.sdkFreshness;
|
|
3127
|
-
if (!latest && !deprecated) return "";
|
|
3128
|
-
return `
|
|
3129
|
-
<div class="mushi-outdated" role="status">
|
|
3130
|
-
<strong>Mushi SDK ${escapeHtml(current)}</strong>
|
|
3131
|
-
${latest ? `latest is ${escapeHtml(latest)}.` : "needs attention."}
|
|
3132
|
-
${message ? `<span>${escapeHtml(message)}</span>` : ""}
|
|
3133
|
-
</div>
|
|
3134
|
-
`;
|
|
3238
|
+
// ── Community public setters (called by mushi.ts after API calls) ──────────
|
|
3239
|
+
setTesterSession(jwt, info) {
|
|
3240
|
+
this.testerJwt = jwt;
|
|
3241
|
+
this.testerInfo = info;
|
|
3242
|
+
if (this.isOpen) this.render();
|
|
3243
|
+
}
|
|
3244
|
+
setGlobalLeaderboard(entries, loading = false) {
|
|
3245
|
+
this.globalLeaderboard = entries;
|
|
3246
|
+
this.globalLeaderboardLoading = loading;
|
|
3247
|
+
if (this.isOpen && (this.step === "leaderboard" || this.step === "account")) this.render();
|
|
3248
|
+
}
|
|
3249
|
+
setCrossAppReports(reports, loading = false) {
|
|
3250
|
+
this.crossAppReports = reports;
|
|
3251
|
+
this.crossAppLoading = loading;
|
|
3252
|
+
if (this.isOpen && this.step === "cross-app-reports") this.render();
|
|
3253
|
+
}
|
|
3254
|
+
setTesterReputation(rep) {
|
|
3255
|
+
this.testerReputation = rep;
|
|
3256
|
+
if (this.isOpen && (this.step === "account" || this.step === "leaderboard")) this.render();
|
|
3135
3257
|
}
|
|
3136
|
-
|
|
3137
|
-
if (this.
|
|
3138
|
-
|
|
3258
|
+
destroy() {
|
|
3259
|
+
if (this.successTimer !== null) {
|
|
3260
|
+
clearTimeout(this.successTimer);
|
|
3261
|
+
this.successTimer = null;
|
|
3262
|
+
}
|
|
3263
|
+
if (this.autoCloseTimer !== null) {
|
|
3264
|
+
clearTimeout(this.autoCloseTimer);
|
|
3265
|
+
this.autoCloseTimer = null;
|
|
3266
|
+
}
|
|
3267
|
+
if (this.smartHideTimer !== null) {
|
|
3268
|
+
clearTimeout(this.smartHideTimer);
|
|
3269
|
+
this.smartHideTimer = null;
|
|
3270
|
+
}
|
|
3271
|
+
this.smartHideCleanup?.();
|
|
3272
|
+
this.smartHideCleanup = null;
|
|
3273
|
+
this.teardownViewportHandlers();
|
|
3274
|
+
this.attachedLaunchers.forEach((cleanup) => cleanup());
|
|
3275
|
+
this.attachedLaunchers = [];
|
|
3276
|
+
this.removeSelectorHint();
|
|
3277
|
+
this.removeNudge();
|
|
3278
|
+
this.removeBodyNudge();
|
|
3279
|
+
this.host.remove();
|
|
3139
3280
|
}
|
|
3281
|
+
/* ── Host chrome contract ────────────────────────────────────────────────
|
|
3282
|
+
The host element must never create an invisible full-screen touch blocker.
|
|
3283
|
+
We own these inline styles — consumer CSS can only win with `!important`,
|
|
3284
|
+
which is explicitly banned by the SDK contract. Calling this at mount()
|
|
3285
|
+
and after every zIndex update is the only safe invariant. */
|
|
3140
3286
|
/**
|
|
3141
|
-
*
|
|
3142
|
-
*
|
|
3143
|
-
*
|
|
3144
|
-
*
|
|
3145
|
-
*
|
|
3146
|
-
* On sub-steps it additionally renders a back button (replacing the
|
|
3147
|
-
* "MUSHI" eyebrow with a "← BACK" mono link) and a step counter
|
|
3148
|
-
* ledger ("02 / 03") on the far right.
|
|
3287
|
+
* Apply the SDK-owned pass-through layout to the host element so it is
|
|
3288
|
+
* always zero-sized and click/touch-transparent. Only the shadow-root
|
|
3289
|
+
* internals (`.mushi-trigger`, `.mushi-banner`, `.mushi-panel`) opt back
|
|
3290
|
+
* into pointer events. This is idempotent and safe to call repeatedly.
|
|
3149
3291
|
*/
|
|
3150
|
-
|
|
3151
|
-
const
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
<button type="button" class="mushi-close" data-action="close" aria-label="${t.widget.close}">\u2715</button>
|
|
3165
|
-
</div>
|
|
3166
|
-
</div>
|
|
3167
|
-
`;
|
|
3292
|
+
syncHostChromeState() {
|
|
3293
|
+
const s = this.host.style;
|
|
3294
|
+
s.setProperty("position", "fixed");
|
|
3295
|
+
s.setProperty("top", "0");
|
|
3296
|
+
s.setProperty("left", "0");
|
|
3297
|
+
s.setProperty("width", "0");
|
|
3298
|
+
s.setProperty("height", "0");
|
|
3299
|
+
s.setProperty("overflow", "visible");
|
|
3300
|
+
s.setProperty("pointer-events", "none");
|
|
3301
|
+
s.setProperty("z-index", String(this.config.zIndex));
|
|
3302
|
+
s.setProperty("margin", "0");
|
|
3303
|
+
s.setProperty("padding", "0");
|
|
3304
|
+
s.setProperty("border", "none");
|
|
3305
|
+
s.setProperty("background", "none");
|
|
3168
3306
|
}
|
|
3169
3307
|
/**
|
|
3170
|
-
*
|
|
3171
|
-
*
|
|
3172
|
-
*
|
|
3308
|
+
* Returns true when a DOM element matching `hideOnSelector` is currently
|
|
3309
|
+
* present in the host document. Used by both the trigger and the banner
|
|
3310
|
+
* so a single selector consistently hides ALL SDK-injected launcher
|
|
3311
|
+
* surfaces. Invalid selectors are swallowed silently (non-fatal).
|
|
3173
3312
|
*/
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3313
|
+
isSuppressedByHost() {
|
|
3314
|
+
if (!this.config.hideOnSelector || typeof document === "undefined") return false;
|
|
3315
|
+
try {
|
|
3316
|
+
return Boolean(document.querySelector(this.config.hideOnSelector));
|
|
3317
|
+
} catch {
|
|
3318
|
+
return false;
|
|
3180
3319
|
}
|
|
3181
|
-
return `<div class="mushi-step-indicator" aria-hidden="true">${segments.join("")}</div>`;
|
|
3182
|
-
}
|
|
3183
|
-
renderCategoryStep() {
|
|
3184
|
-
const t = this.locale;
|
|
3185
|
-
const categoryEntries = this.config.categories && this.config.categories.length > 0 ? this.config.categories.map((c) => ({
|
|
3186
|
-
id: c.id,
|
|
3187
|
-
icon: c.icon ?? "\u{1F4AC}",
|
|
3188
|
-
label: c.label,
|
|
3189
|
-
desc: c.description ?? ""
|
|
3190
|
-
})) : ["bug", "slow", "visual", "confusing", "other"].map((id) => ({
|
|
3191
|
-
id,
|
|
3192
|
-
icon: CATEGORY_ICONS[id],
|
|
3193
|
-
label: t.step1.categories[id],
|
|
3194
|
-
desc: t.step1.categoryDescriptions[id]
|
|
3195
|
-
}));
|
|
3196
|
-
const categories = categoryEntries.map(({ id, icon, label, desc }) => `
|
|
3197
|
-
<button type="button" class="mushi-option-btn" data-category="${escapeHtml(id)}" role="radio" aria-checked="false">
|
|
3198
|
-
<span class="mushi-option-icon" aria-hidden="true">${escapeHtml(icon)}</span>
|
|
3199
|
-
<div class="mushi-option-text">
|
|
3200
|
-
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
3201
|
-
${desc ? `<span class="mushi-option-desc">${escapeHtml(desc)}</span>` : ""}
|
|
3202
|
-
</div>
|
|
3203
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
3204
|
-
</button>
|
|
3205
|
-
`).join("");
|
|
3206
|
-
return `
|
|
3207
|
-
${this.renderHeader({ title: t.step1.heading, step: STEP_NUMBER.category })}
|
|
3208
|
-
${this.config.betaMode?.enabled ? this.renderBetaStrip() : ""}
|
|
3209
|
-
<div class="mushi-body" role="radiogroup" aria-label="${t.step1.heading}">
|
|
3210
|
-
<button type="button" class="mushi-option-btn mushi-reports-entry" data-action="reports">
|
|
3211
|
-
<span class="mushi-option-icon" aria-hidden="true">\u{1F4EC}</span>
|
|
3212
|
-
<div class="mushi-option-text">
|
|
3213
|
-
<span class="mushi-option-label">Your reports${this.unreadCount() ? ` (${this.unreadCount()} new)` : ""}</span>
|
|
3214
|
-
<span class="mushi-option-desc">See status, developer replies, and respond</span>
|
|
3215
|
-
</div>
|
|
3216
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
3217
|
-
</button>
|
|
3218
|
-
${this.renderFeatureRequestEntry()}
|
|
3219
|
-
${this.callbacks.onFeatureBoardRequest ? `
|
|
3220
|
-
<button type="button" class="mushi-option-btn" data-action="roadmap">
|
|
3221
|
-
<span class="mushi-option-icon" aria-hidden="true">\u{1F5F3}\uFE0F</span>
|
|
3222
|
-
<div class="mushi-option-text">
|
|
3223
|
-
<span class="mushi-option-label">Community ideas</span>
|
|
3224
|
-
<span class="mushi-option-desc">Vote on features and see what shipped</span>
|
|
3225
|
-
</div>
|
|
3226
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
3227
|
-
</button>` : ""}
|
|
3228
|
-
${categories}
|
|
3229
|
-
${this.rewardsState ? this.renderRewardsNudge() : ""}
|
|
3230
|
-
<div class="mushi-community-footer">
|
|
3231
|
-
<button type="button" class="mushi-link-btn mushi-community-btn" data-action="open-account">
|
|
3232
|
-
${this.testerInfo ? `\u{1F464} ${escapeHtml(this.testerInfo.public_handle ?? this.testerInfo.display_name ?? "My account")}` : "\u{1F310} Join community \xB7 Track reports across apps"}
|
|
3233
|
-
</button>
|
|
3234
|
-
${this.rewardsState ? `<button type="button" class="mushi-link-btn" data-action="open-leaderboard">\u{1F3C6} Leaderboard</button>` : ""}
|
|
3235
|
-
</div>
|
|
3236
|
-
</div>
|
|
3237
|
-
${this.renderStepIndicator(STEP_NUMBER.category)}
|
|
3238
|
-
`;
|
|
3239
3320
|
}
|
|
3240
3321
|
/**
|
|
3241
|
-
*
|
|
3242
|
-
*
|
|
3243
|
-
*
|
|
3244
|
-
* it as an intent under the "Other" category drops feature submissions
|
|
3245
|
-
* by ~40% in industry studies (Userpilot, Usersnap 2025).
|
|
3246
|
-
*
|
|
3247
|
-
* Wire format: still routes through the standard `other` category with
|
|
3248
|
-
* a `user_category = 'Feature request'` stamp, so we don't need a DB
|
|
3249
|
-
* migration. The admin console filters on that string to surface the
|
|
3250
|
-
* Feature-request swimlane.
|
|
3322
|
+
* Returns a snapshot of the widget's host-layer health for use in
|
|
3323
|
+
* `Mushi.diagnose()`. Callers check this to know whether the widget
|
|
3324
|
+
* could ever block host-app UI without opening a browser devtools.
|
|
3251
3325
|
*/
|
|
3252
|
-
|
|
3253
|
-
const
|
|
3254
|
-
|
|
3255
|
-
const
|
|
3256
|
-
const
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
type="button"
|
|
3260
|
-
class="mushi-option-btn mushi-feature-entry"
|
|
3261
|
-
data-action="feature-request"
|
|
3262
|
-
aria-label="${escapeHtml(label)}"
|
|
3263
|
-
>
|
|
3264
|
-
<span class="mushi-option-icon" aria-hidden="true">\u2728</span>
|
|
3265
|
-
<div class="mushi-option-text">
|
|
3266
|
-
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
3267
|
-
<span class="mushi-option-desc">${escapeHtml(desc)}</span>
|
|
3268
|
-
</div>
|
|
3269
|
-
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
3270
|
-
</button>
|
|
3271
|
-
`;
|
|
3272
|
-
}
|
|
3273
|
-
/** Collapsible "What's new" changelog row. Closes the reporter feedback loop. */
|
|
3274
|
-
renderBetaChangelog() {
|
|
3275
|
-
const entries = this.config.betaMode?.changelogItems;
|
|
3276
|
-
if (!entries?.length) return "";
|
|
3277
|
-
const latest = entries[0];
|
|
3278
|
-
const items = latest.items.map((item) => `<li>\u2022 ${escapeHtml(item)}</li>`).join("");
|
|
3279
|
-
const label = latest.date ? `What\u2019s new in ${escapeHtml(latest.version)} \xB7 ${escapeHtml(latest.date)}` : `What\u2019s new in ${escapeHtml(latest.version)}`;
|
|
3280
|
-
return `
|
|
3281
|
-
<details class="mushi-changelog">
|
|
3282
|
-
<summary class="mushi-changelog-summary">${label}</summary>
|
|
3283
|
-
<ul class="mushi-changelog-list">${items}</ul>
|
|
3284
|
-
</details>
|
|
3285
|
-
`;
|
|
3326
|
+
getWidgetDiagnostics() {
|
|
3327
|
+
const s = this.host.style;
|
|
3328
|
+
const widgetHostPointerSafe = s.pointerEvents === "none" && (s.width === "0" || s.width === "0px") && (s.height === "0" || s.height === "0px");
|
|
3329
|
+
const widgetHostBounds = this.host.isConnected ? { width: this.host.offsetWidth, height: this.host.offsetHeight } : null;
|
|
3330
|
+
const widgetSuppressed = this.isSuppressedByHost() || this.isRouteHidden() || !this.triggerVisible;
|
|
3331
|
+
const bannerRendered = this.config.trigger === "banner" && !this.bannerDismissed && !this.isSuppressedByHost() && !this.isRouteHidden() && this.triggerVisible;
|
|
3332
|
+
return { widgetHostPointerSafe, widgetHostBounds, widgetSuppressed, bannerRendered };
|
|
3286
3333
|
}
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
const beta = this.config.betaMode;
|
|
3294
|
-
const appName = escapeHtml(beta.appName ?? "This app");
|
|
3295
|
-
const message = beta.message ? escapeHtml(beta.message) : `${appName} is in early development \u2014 updates ship weekly`;
|
|
3296
|
-
const email = beta.contactEmail ? escapeHtml(beta.contactEmail) : null;
|
|
3297
|
-
const perks = beta.perks ?? [];
|
|
3298
|
-
return `
|
|
3299
|
-
<div class="mushi-beta-strip" role="note" aria-label="Beta status">
|
|
3300
|
-
<div class="mushi-beta-strip-row">
|
|
3301
|
-
<span class="mushi-beta-tag" aria-hidden="true">BETA</span>
|
|
3302
|
-
<span class="mushi-beta-msg">${message}</span>
|
|
3303
|
-
</div>
|
|
3304
|
-
${email ? `<div class="mushi-beta-contact-hint">Reports go to ${email} \xB7 reviewed by the team</div>` : ""}
|
|
3305
|
-
${perks.length > 0 ? `
|
|
3306
|
-
<ul class="mushi-beta-perks" aria-label="Beta tester perks">
|
|
3307
|
-
${perks.map((p) => `<li>\u2713 ${escapeHtml(p)}</li>`).join("")}
|
|
3308
|
-
</ul>
|
|
3309
|
-
` : ""}
|
|
3310
|
-
${this.renderBetaChangelog()}
|
|
3311
|
-
</div>
|
|
3312
|
-
`;
|
|
3334
|
+
syncAttachedLaunchers() {
|
|
3335
|
+
this.attachedLaunchers.forEach((cleanup) => cleanup());
|
|
3336
|
+
this.attachedLaunchers = [];
|
|
3337
|
+
if (this.config.trigger !== "attach" || !this.config.attachToSelector) return;
|
|
3338
|
+
if (typeof document === "undefined") return;
|
|
3339
|
+
this.attachedLaunchers.push(this.attachTo(this.config.attachToSelector));
|
|
3313
3340
|
}
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
${this.reporterError ? `<p class="mushi-error-inline">${escapeHtml(this.reporterError)}</p>` : ""}
|
|
3339
|
-
${reports || (!this.reporterLoading ? '<p class="mushi-muted">No reports from this browser yet.</p>' : "")}
|
|
3340
|
-
${leaderboardBtn}
|
|
3341
|
-
</div>
|
|
3342
|
-
`;
|
|
3341
|
+
syncSmartHide() {
|
|
3342
|
+
this.smartHideCleanup?.();
|
|
3343
|
+
this.smartHideCleanup = null;
|
|
3344
|
+
this.triggerShrunk = false;
|
|
3345
|
+
this.triggerHiddenByScroll = false;
|
|
3346
|
+
if (!this.config.smartHide || typeof window === "undefined") return;
|
|
3347
|
+
const smart = this.config.smartHide === true ? { onScroll: "shrink", onIdleMs: 900 } : this.config.smartHide;
|
|
3348
|
+
if (!smart.onScroll) return;
|
|
3349
|
+
const onScroll = () => {
|
|
3350
|
+
if (smart.onScroll === "hide") {
|
|
3351
|
+
this.triggerHiddenByScroll = true;
|
|
3352
|
+
} else {
|
|
3353
|
+
this.triggerShrunk = true;
|
|
3354
|
+
}
|
|
3355
|
+
this.render();
|
|
3356
|
+
if (this.smartHideTimer !== null) clearTimeout(this.smartHideTimer);
|
|
3357
|
+
this.smartHideTimer = setTimeout(() => {
|
|
3358
|
+
this.triggerHiddenByScroll = false;
|
|
3359
|
+
this.triggerShrunk = false;
|
|
3360
|
+
this.render();
|
|
3361
|
+
}, smart.onIdleMs ?? 900);
|
|
3362
|
+
};
|
|
3363
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
3364
|
+
this.smartHideCleanup = () => window.removeEventListener("scroll", onScroll);
|
|
3343
3365
|
}
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
<span class="mushi-report-title">${subject}</span>
|
|
3356
|
-
<span class="mushi-report-meta">
|
|
3357
|
-
<span class="mushi-report-status">${escapeHtml(status)}</span>
|
|
3358
|
-
<span class="mushi-report-when">${votes} vote${votes === 1 ? "" : "s"}</span>
|
|
3359
|
-
</span>
|
|
3360
|
-
</div>
|
|
3361
|
-
${this.callbacks.onFeatureBoardVote ? `
|
|
3362
|
-
<button type="button" class="mushi-vote-btn" data-vote-id="${escapeHtml(id)}" aria-pressed="${voted}">
|
|
3363
|
-
${voted ? "Voted" : "Vote"}
|
|
3364
|
-
</button>` : ""}
|
|
3365
|
-
</div>`;
|
|
3366
|
-
}).join("");
|
|
3367
|
-
return `
|
|
3368
|
-
${this.renderHeader({ title: "Community ideas", showBack: true, eyebrow: "Mushi \xB7 Roadmap" })}
|
|
3369
|
-
<div class="mushi-body">
|
|
3370
|
-
${this.reporterLoading ? '<p class="mushi-muted">Loading ideas\u2026</p>' : ""}
|
|
3371
|
-
${this.reporterError ? `<p class="mushi-error-inline">${escapeHtml(this.reporterError)}</p>` : ""}
|
|
3372
|
-
${rows || (!this.reporterLoading ? '<p class="mushi-muted">No community ideas yet. Be the first to suggest one.</p>' : "")}
|
|
3373
|
-
</div>
|
|
3374
|
-
`;
|
|
3366
|
+
shouldRenderTrigger() {
|
|
3367
|
+
if (!this.triggerVisible) return false;
|
|
3368
|
+
if (this.triggerHiddenByScroll) return false;
|
|
3369
|
+
if (this.config.trigger === "manual" || this.config.trigger === "hidden" || this.config.trigger === "attach" || this.config.trigger === "banner") {
|
|
3370
|
+
return false;
|
|
3371
|
+
}
|
|
3372
|
+
if (this.isMobileSmartHidden()) return false;
|
|
3373
|
+
if (this.isRouteHidden()) return false;
|
|
3374
|
+
if (this.isSuppressedByHost()) return false;
|
|
3375
|
+
const action = this.config.environments[this.detectEnvironment()];
|
|
3376
|
+
return action !== "never" && action !== "manual";
|
|
3375
3377
|
}
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
<span class="mushi-lb-pts">${(e.points_30d ?? e.total_points).toLocaleString()} pts</span>
|
|
3396
|
-
</div>
|
|
3397
|
-
`;
|
|
3398
|
-
}).join("");
|
|
3399
|
-
const myRankBadge = myRank ? `<div class="mushi-lb-myrank">You are ranked <strong>#${myRank}</strong> this month</div>` : !this.testerJwt ? `<button type="button" class="mushi-link-btn" data-action="open-account">Sign in to see your rank \u2192</button>` : "";
|
|
3400
|
-
return `
|
|
3401
|
-
${this.renderHeader({ title: "\u{1F3C6} Global Leaderboard", showBack: true, eyebrow: "Mushi \xB7 Community" })}
|
|
3402
|
-
<div class="mushi-body">
|
|
3403
|
-
${loading ? '<p class="mushi-muted">Loading leaderboard\u2026</p>' : ""}
|
|
3404
|
-
${!loading && !entries.length ? '<p class="mushi-muted">No contributors yet \u2014 be the first!</p>' : ""}
|
|
3405
|
-
<div class="mushi-lb-list">${rows}</div>
|
|
3406
|
-
${myRankBadge}
|
|
3407
|
-
<p class="mushi-lb-note">Global contributors this month \xB7 Points refresh monthly</p>
|
|
3408
|
-
</div>
|
|
3409
|
-
`;
|
|
3378
|
+
/** Height of the banner in px — kept in sync with the CSS `.mushi-banner` height (36px). */
|
|
3379
|
+
static BANNER_HEIGHT = 36;
|
|
3380
|
+
/** CSS property applied to document.body so host-app content doesn't slide under the banner. */
|
|
3381
|
+
static BODY_NUDGE_PROP = "--mushi-banner-offset";
|
|
3382
|
+
applyBodyNudge(position) {
|
|
3383
|
+
const h = `${_MushiWidget.BANNER_HEIGHT}px`;
|
|
3384
|
+
if (position === "top") {
|
|
3385
|
+
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
3386
|
+
if (!document.body.style.paddingTop) {
|
|
3387
|
+
document.body.style.paddingTop = h;
|
|
3388
|
+
document.body.dataset.mushiBannerNudged = "top";
|
|
3389
|
+
}
|
|
3390
|
+
} else {
|
|
3391
|
+
document.documentElement.style.setProperty(_MushiWidget.BODY_NUDGE_PROP, h);
|
|
3392
|
+
if (!document.body.style.paddingBottom) {
|
|
3393
|
+
document.body.style.paddingBottom = h;
|
|
3394
|
+
document.body.dataset.mushiBannerNudged = "bottom";
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3410
3397
|
}
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
<div class="mushi-account-avatar">${escapeHtml(handle.charAt(0).toUpperCase())}</div>
|
|
3421
|
-
<div class="mushi-account-info">
|
|
3422
|
-
<strong>${escapeHtml(handle)}</strong>
|
|
3423
|
-
${rep ? `<span class="mushi-account-rank">Rank #${rep.rank ?? "\u2014"} \xB7 ${(rep.points_30d ?? 0).toLocaleString()} pts this month</span>` : ""}
|
|
3424
|
-
</div>
|
|
3425
|
-
</div>
|
|
3426
|
-
<button type="button" class="mushi-nav-item" data-action="open-cross-app-reports">
|
|
3427
|
-
My reports across all apps \u2192
|
|
3428
|
-
</button>
|
|
3429
|
-
<button type="button" class="mushi-nav-item" data-action="open-global-leaderboard">
|
|
3430
|
-
View global leaderboard \u2192
|
|
3431
|
-
</button>
|
|
3432
|
-
<button type="button" class="mushi-link-btn" data-action="sign-out-tester">Sign out</button>
|
|
3433
|
-
</div>
|
|
3434
|
-
`;
|
|
3398
|
+
removeBodyNudge() {
|
|
3399
|
+
document.documentElement.style.removeProperty(_MushiWidget.BODY_NUDGE_PROP);
|
|
3400
|
+
const nudged = document.body.dataset.mushiBannerNudged;
|
|
3401
|
+
if (nudged === "top") {
|
|
3402
|
+
document.body.style.paddingTop = "";
|
|
3403
|
+
delete document.body.dataset.mushiBannerNudged;
|
|
3404
|
+
} else if (nudged === "bottom") {
|
|
3405
|
+
document.body.style.paddingBottom = "";
|
|
3406
|
+
delete document.body.dataset.mushiBannerNudged;
|
|
3435
3407
|
}
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
${this.magicLinkError ? `<p class="mushi-error">${escapeHtml(this.magicLinkError)}</p>` : ""}
|
|
3443
|
-
</div>
|
|
3444
|
-
`;
|
|
3408
|
+
}
|
|
3409
|
+
renderBanner() {
|
|
3410
|
+
if (this.config.trigger !== "banner") return;
|
|
3411
|
+
if (this.bannerDismissed) {
|
|
3412
|
+
this.removeBodyNudge();
|
|
3413
|
+
return;
|
|
3445
3414
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3415
|
+
if (!this.triggerVisible) {
|
|
3416
|
+
this.removeBodyNudge();
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
if (this.isRouteHidden()) {
|
|
3420
|
+
this.removeBodyNudge();
|
|
3421
|
+
return;
|
|
3422
|
+
}
|
|
3423
|
+
if (this.isSuppressedByHost()) {
|
|
3424
|
+
this.removeBodyNudge();
|
|
3425
|
+
return;
|
|
3426
|
+
}
|
|
3427
|
+
const bc = this.config.bannerConfig ?? {};
|
|
3428
|
+
const variant = bc.variant ?? "brand";
|
|
3429
|
+
const position = bc.position ?? "top";
|
|
3430
|
+
const message = bc.message?.trim() ?? "";
|
|
3431
|
+
const richLayout = message.length > 0;
|
|
3432
|
+
const bugLabel = bc.bugCta ?? "\u{1F41B} Report a bug";
|
|
3433
|
+
const showFeat = bc.featureCta !== false;
|
|
3434
|
+
const featLabel = bc.featureCtaLabel ?? "Request feature";
|
|
3435
|
+
const zIdx = bc.zIndex ?? (this.config.zIndex ?? 99999) - 1;
|
|
3436
|
+
const banner = document.createElement("div");
|
|
3437
|
+
banner.className = `mushi-banner ${variant} ${position}${richLayout ? " mushi-banner--rich" : ""}`;
|
|
3438
|
+
banner.style.setProperty("--mushi-banner-z", String(zIdx));
|
|
3439
|
+
banner.setAttribute("role", "banner");
|
|
3440
|
+
const dismissBtn = document.createElement("button");
|
|
3441
|
+
dismissBtn.className = "mushi-banner-dismiss";
|
|
3442
|
+
dismissBtn.textContent = "\u2715";
|
|
3443
|
+
dismissBtn.setAttribute("aria-label", "Dismiss feedback banner");
|
|
3444
|
+
dismissBtn.addEventListener("click", () => {
|
|
3445
|
+
this.bannerDismissed = true;
|
|
3446
|
+
this.removeBodyNudge();
|
|
3447
|
+
this.render();
|
|
3448
|
+
});
|
|
3449
|
+
if (richLayout) {
|
|
3450
|
+
const body = document.createElement("div");
|
|
3451
|
+
body.className = "mushi-banner-body";
|
|
3452
|
+
const labelText = bc.label === false ? null : bc.label ?? "Beta";
|
|
3453
|
+
if (labelText) {
|
|
3454
|
+
const pill = document.createElement("span");
|
|
3455
|
+
pill.className = "mushi-banner-pill";
|
|
3456
|
+
pill.textContent = labelText;
|
|
3457
|
+
body.appendChild(pill);
|
|
3458
|
+
}
|
|
3459
|
+
const msg = document.createElement("span");
|
|
3460
|
+
msg.className = "mushi-banner-message";
|
|
3461
|
+
msg.textContent = message;
|
|
3462
|
+
body.appendChild(msg);
|
|
3463
|
+
banner.appendChild(body);
|
|
3464
|
+
const nav = document.createElement("nav");
|
|
3465
|
+
nav.className = "mushi-banner-actions";
|
|
3466
|
+
nav.setAttribute("aria-label", "Feedback banner actions");
|
|
3467
|
+
const appendDivider = (extra = false) => {
|
|
3468
|
+
const sep = document.createElement("span");
|
|
3469
|
+
sep.className = `mushi-banner-divider${extra ? " mushi-banner-extra" : ""}`;
|
|
3470
|
+
sep.setAttribute("aria-hidden", "true");
|
|
3471
|
+
sep.textContent = "|";
|
|
3472
|
+
nav.appendChild(sep);
|
|
3473
|
+
};
|
|
3474
|
+
const appendAction = (label, onClick, extra = false) => {
|
|
3475
|
+
const btn = document.createElement("button");
|
|
3476
|
+
btn.type = "button";
|
|
3477
|
+
btn.className = `mushi-banner-link${extra ? " mushi-banner-extra" : ""}`;
|
|
3478
|
+
btn.textContent = label;
|
|
3479
|
+
btn.addEventListener("click", onClick);
|
|
3480
|
+
nav.appendChild(btn);
|
|
3481
|
+
};
|
|
3482
|
+
appendAction(bugLabel, () => this.open());
|
|
3483
|
+
if (showFeat) {
|
|
3484
|
+
appendDivider(true);
|
|
3485
|
+
appendAction(featLabel, () => this.open({ featureRequest: true }), true);
|
|
3486
|
+
}
|
|
3487
|
+
for (const link of bc.links ?? []) {
|
|
3488
|
+
const linkLabel = link.label?.trim();
|
|
3489
|
+
if (!linkLabel) continue;
|
|
3490
|
+
const href = link.href && (/^https?:\/\//i.test(link.href) || link.href.startsWith("/")) ? link.href : void 0;
|
|
3491
|
+
appendDivider(true);
|
|
3492
|
+
if (href) {
|
|
3493
|
+
const anchor = document.createElement("a");
|
|
3494
|
+
anchor.className = "mushi-banner-link mushi-banner-extra";
|
|
3495
|
+
anchor.href = href;
|
|
3496
|
+
anchor.textContent = linkLabel;
|
|
3497
|
+
anchor.target = "_blank";
|
|
3498
|
+
anchor.rel = "noopener noreferrer";
|
|
3499
|
+
nav.appendChild(anchor);
|
|
3500
|
+
} else {
|
|
3501
|
+
appendAction(linkLabel, () => {
|
|
3502
|
+
if (link.featureRequest) this.open({ featureRequest: true });
|
|
3503
|
+
else this.open();
|
|
3504
|
+
}, true);
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
banner.appendChild(nav);
|
|
3508
|
+
banner.appendChild(dismissBtn);
|
|
3509
|
+
} else {
|
|
3510
|
+
const bugBtn = document.createElement("button");
|
|
3511
|
+
bugBtn.className = "mushi-banner-btn";
|
|
3512
|
+
bugBtn.textContent = bugLabel;
|
|
3513
|
+
bugBtn.addEventListener("click", () => this.open());
|
|
3514
|
+
banner.appendChild(bugBtn);
|
|
3515
|
+
if (showFeat) {
|
|
3516
|
+
const featBtn = document.createElement("button");
|
|
3517
|
+
featBtn.className = "mushi-banner-btn";
|
|
3518
|
+
featBtn.textContent = featLabel;
|
|
3519
|
+
featBtn.addEventListener("click", () => this.open({ featureRequest: true }));
|
|
3520
|
+
banner.appendChild(featBtn);
|
|
3521
|
+
}
|
|
3522
|
+
banner.appendChild(dismissBtn);
|
|
3523
|
+
}
|
|
3524
|
+
this.shadow.appendChild(banner);
|
|
3525
|
+
this.applyBodyNudge(position);
|
|
3467
3526
|
}
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
const
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
if (!grouped.has(key)) grouped.set(key, { name: r.app_name ?? "Unknown App", reports: [] });
|
|
3474
|
-
grouped.get(key).reports.push(r);
|
|
3527
|
+
effectiveTrigger() {
|
|
3528
|
+
if (!this.config.smartHide || typeof window === "undefined") return this.config.trigger;
|
|
3529
|
+
const smart = this.config.smartHide === true ? { onMobile: "edge-tab" } : this.config.smartHide;
|
|
3530
|
+
if (window.matchMedia("(max-width: 768px)").matches && smart.onMobile === "edge-tab") {
|
|
3531
|
+
return "edge-tab";
|
|
3475
3532
|
}
|
|
3476
|
-
|
|
3477
|
-
<div class="mushi-xapp-group">
|
|
3478
|
-
<h4 class="mushi-xapp-app-name">${escapeHtml(group.name)}</h4>
|
|
3479
|
-
${group.reports.map((r) => {
|
|
3480
|
-
const tone = reporterStatusTone(r.status);
|
|
3481
|
-
return `
|
|
3482
|
-
<div class="mushi-report-row" data-report-id="${escapeHtml(r.id)}" tabindex="0" role="button">
|
|
3483
|
-
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusShort(r.status))}</span>
|
|
3484
|
-
<span class="mushi-report-title">${escapeHtml(r.title ?? r.category)}</span>
|
|
3485
|
-
<span class="mushi-report-when">${escapeHtml(formatRelativeTime(r.created_at))}</span>
|
|
3486
|
-
</div>
|
|
3487
|
-
`;
|
|
3488
|
-
}).join("")}
|
|
3489
|
-
</div>
|
|
3490
|
-
`).join("");
|
|
3491
|
-
return `
|
|
3492
|
-
${this.renderHeader({ title: "My reports", showBack: true, eyebrow: "Mushi \xB7 All apps" })}
|
|
3493
|
-
<div class="mushi-body">
|
|
3494
|
-
${this.crossAppLoading ? '<p class="mushi-muted">Loading your reports\u2026</p>' : ""}
|
|
3495
|
-
${!this.crossAppLoading && !reports.length ? '<p class="mushi-muted">No reports filed yet.</p>' : ""}
|
|
3496
|
-
${rows}
|
|
3497
|
-
</div>
|
|
3498
|
-
`;
|
|
3533
|
+
return this.config.trigger;
|
|
3499
3534
|
}
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
const
|
|
3503
|
-
|
|
3504
|
-
const when = report?.created_at ? formatRelativeTime(report.created_at) : "";
|
|
3505
|
-
const comments = this.reporterComments.map((comment) => `
|
|
3506
|
-
<div class="mushi-thread-comment ${comment.author_kind}">
|
|
3507
|
-
<strong>${escapeHtml(comment.author_kind === "reporter" ? "You" : comment.author_name ?? "Developer")}</strong>
|
|
3508
|
-
<p>${escapeHtml(comment.body)}</p>
|
|
3509
|
-
</div>
|
|
3510
|
-
`).join("");
|
|
3511
|
-
return `
|
|
3512
|
-
${this.renderHeader({ title: "Report thread", showBack: true, eyebrow: "Mushi \xB7 Inbox" })}
|
|
3513
|
-
<div class="mushi-body">
|
|
3514
|
-
<div class="mushi-thread-summary">
|
|
3515
|
-
<div class="mushi-thread-summary-meta">
|
|
3516
|
-
<span class="mushi-report-status mushi-status-${tone}">${escapeHtml(reporterStatusLabel(status))}</span>
|
|
3517
|
-
${when ? `<span class="mushi-report-when">Reported ${escapeHtml(when)}</span>` : ""}
|
|
3518
|
-
</div>
|
|
3519
|
-
<p>${escapeHtml(report?.summary ?? report?.description ?? "Report details")}</p>
|
|
3520
|
-
</div>
|
|
3521
|
-
<div class="mushi-thread">
|
|
3522
|
-
${this.reporterLoading ? '<p class="mushi-muted">Loading thread\u2026</p>' : comments || '<p class="mushi-muted">No developer replies yet.</p>'}
|
|
3523
|
-
</div>
|
|
3524
|
-
${["fixed", "resolved", "verified"].includes(status) ? `
|
|
3525
|
-
<div class="mushi-verify-actions" role="group" aria-label="Fix verification">
|
|
3526
|
-
<button type="button" class="mushi-intent-btn" data-action="reporter-confirms">Yes, fixed for me</button>
|
|
3527
|
-
<button type="button" class="mushi-intent-btn" data-action="reporter-not-fixed">Not fixed yet</button>
|
|
3528
|
-
</div>
|
|
3529
|
-
` : ""}
|
|
3530
|
-
<textarea class="mushi-textarea" data-role="reporter-reply" rows="3" placeholder="Reply to the developer\u2026"></textarea>
|
|
3531
|
-
<button type="button" class="mushi-submit" data-action="reporter-reply">
|
|
3532
|
-
<span>Reply</span><span class="mushi-submit-arrow" aria-hidden="true">\u2192</span>
|
|
3533
|
-
</button>
|
|
3534
|
-
</div>
|
|
3535
|
-
`;
|
|
3535
|
+
isMobileSmartHidden() {
|
|
3536
|
+
if (!this.config.smartHide || typeof window === "undefined") return false;
|
|
3537
|
+
const smart = this.config.smartHide === true ? { onMobile: "edge-tab" } : this.config.smartHide;
|
|
3538
|
+
return window.matchMedia("(max-width: 768px)").matches && smart.onMobile === "hide";
|
|
3536
3539
|
}
|
|
3537
|
-
|
|
3538
|
-
const
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
const options = intents.map((intent) => `
|
|
3543
|
-
<button type="button" class="mushi-intent-btn" data-intent="${escapeHtml(intent)}">
|
|
3544
|
-
${escapeHtml(intent)}
|
|
3545
|
-
</button>
|
|
3546
|
-
`).join("");
|
|
3547
|
-
const icon = this.categoryIcon(catId);
|
|
3548
|
-
const label = this.categoryLabel(catId);
|
|
3549
|
-
return `
|
|
3550
|
-
${this.renderHeader({ title: t.step2.heading, showBack: true, step: STEP_NUMBER.intent })}
|
|
3551
|
-
<div class="mushi-body">
|
|
3552
|
-
<div class="mushi-selected-category">
|
|
3553
|
-
<span aria-hidden="true">${escapeHtml(icon)}</span>
|
|
3554
|
-
<span>${escapeHtml(label)}</span>
|
|
3555
|
-
</div>
|
|
3556
|
-
<div class="mushi-intents">
|
|
3557
|
-
${options}
|
|
3558
|
-
</div>
|
|
3559
|
-
</div>
|
|
3560
|
-
${this.renderStepIndicator(STEP_NUMBER.intent)}
|
|
3561
|
-
`;
|
|
3540
|
+
detectEnvironment() {
|
|
3541
|
+
const host = typeof location !== "undefined" ? location.hostname : "";
|
|
3542
|
+
if (host === "localhost" || host === "127.0.0.1" || host.endsWith(".local")) return "development";
|
|
3543
|
+
if (/\b(staging|stage|preview|dev)\b/i.test(host)) return "staging";
|
|
3544
|
+
return "production";
|
|
3562
3545
|
}
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3546
|
+
isRouteHidden() {
|
|
3547
|
+
if (!this.config.hideOnRoutes.length || typeof location === "undefined") return false;
|
|
3548
|
+
return this.config.hideOnRoutes.some((route) => location.pathname.includes(route));
|
|
3549
|
+
}
|
|
3550
|
+
getTheme() {
|
|
3551
|
+
const t = this.config.theme;
|
|
3552
|
+
if (t === "light" || t === "dark") return t;
|
|
3553
|
+
if (t === "inherit") {
|
|
3554
|
+
const root = document.documentElement;
|
|
3555
|
+
const colorScheme = root.getAttribute("data-color-scheme") || root.getAttribute("data-theme") || root.getAttribute("color-scheme") || "";
|
|
3556
|
+
if (/dark/i.test(colorScheme)) return "dark";
|
|
3557
|
+
if (/light/i.test(colorScheme)) return "light";
|
|
3558
|
+
if (root.classList.contains("dark")) return "dark";
|
|
3559
|
+
if (root.classList.contains("light")) return "light";
|
|
3560
|
+
try {
|
|
3561
|
+
const bg = getComputedStyle(root).backgroundColor;
|
|
3562
|
+
const m = bg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
|
|
3563
|
+
if (m) {
|
|
3564
|
+
const L = 0.299 * +m[1] + 0.587 * +m[2] + 0.114 * +m[3];
|
|
3565
|
+
return L < 128 ? "dark" : "light";
|
|
3566
|
+
}
|
|
3567
|
+
} catch {
|
|
3568
|
+
}
|
|
3569
|
+
}
|
|
3570
|
+
if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
3571
|
+
return "dark";
|
|
3572
|
+
}
|
|
3573
|
+
return "light";
|
|
3568
3574
|
}
|
|
3569
|
-
|
|
3575
|
+
render() {
|
|
3576
|
+
const theme = this.getTheme();
|
|
3577
|
+
const pos = this.config.position;
|
|
3570
3578
|
const t = this.locale;
|
|
3571
|
-
|
|
3572
|
-
const
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
"
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3579
|
+
this.shadow.innerHTML = "";
|
|
3580
|
+
const style = document.createElement("style");
|
|
3581
|
+
style.textContent = getWidgetStyles(theme, this.config.accent ?? "", this.config.accentText ?? "");
|
|
3582
|
+
this.shadow.appendChild(style);
|
|
3583
|
+
this.renderBanner();
|
|
3584
|
+
if (this.shouldRenderTrigger()) {
|
|
3585
|
+
const effectiveTrigger = this.effectiveTrigger();
|
|
3586
|
+
const trigger = document.createElement("button");
|
|
3587
|
+
trigger.className = `mushi-trigger ${pos}${effectiveTrigger === "edge-tab" ? " edge-tab" : ""}${this.triggerShrunk ? " shrunk" : ""}`;
|
|
3588
|
+
trigger.textContent = this.config.triggerText;
|
|
3589
|
+
trigger.setAttribute("aria-label", t.widget.trigger);
|
|
3590
|
+
trigger.setAttribute("aria-haspopup", "dialog");
|
|
3591
|
+
trigger.setAttribute("aria-expanded", String(this.isOpen));
|
|
3592
|
+
trigger.style.zIndex = String(this.config.zIndex);
|
|
3593
|
+
this.applyInsetVars(trigger);
|
|
3594
|
+
trigger.addEventListener("click", () => {
|
|
3595
|
+
this.removeNudge();
|
|
3596
|
+
if (this.isOpen) this.close();
|
|
3597
|
+
else this.open();
|
|
3598
|
+
});
|
|
3599
|
+
trigger.addEventListener("mouseenter", () => {
|
|
3600
|
+
const onPageMs = this.mountedAt ? Date.now() - this.mountedAt : 0;
|
|
3601
|
+
if (!this.nudgeShown && !this.isOpen && onPageMs >= 3e4) {
|
|
3602
|
+
this.showNudge();
|
|
3603
|
+
}
|
|
3604
|
+
});
|
|
3605
|
+
trigger.addEventListener("mouseleave", () => {
|
|
3606
|
+
if (this.nudgeEl) {
|
|
3607
|
+
if (this.nudgeTimer !== null) clearTimeout(this.nudgeTimer);
|
|
3608
|
+
this.nudgeTimer = setTimeout(() => this.removeNudge(), 2e3);
|
|
3609
|
+
}
|
|
3610
|
+
});
|
|
3611
|
+
trigger.addEventListener("keydown", (e) => {
|
|
3612
|
+
const draggableConfig = this.config.draggable;
|
|
3613
|
+
if (!draggableConfig) return;
|
|
3614
|
+
const STEP = 8;
|
|
3615
|
+
const axis = typeof draggableConfig === "object" ? draggableConfig.axis ?? "both" : "both";
|
|
3616
|
+
let dx = 0, dy = 0;
|
|
3617
|
+
if (axis !== "y") {
|
|
3618
|
+
if (e.key === "ArrowLeft") dx = -STEP;
|
|
3619
|
+
else if (e.key === "ArrowRight") dx = STEP;
|
|
3620
|
+
}
|
|
3621
|
+
if (axis !== "x") {
|
|
3622
|
+
if (e.key === "ArrowUp") dy = -STEP;
|
|
3623
|
+
else if (e.key === "ArrowDown") dy = STEP;
|
|
3624
|
+
}
|
|
3625
|
+
if (dx !== 0 || dy !== 0) {
|
|
3626
|
+
e.preventDefault();
|
|
3627
|
+
const cur = this.fabPos ?? { x: 0, y: 0 };
|
|
3628
|
+
this.moveFab(trigger, cur.x + dx, cur.y + dy, false);
|
|
3629
|
+
}
|
|
3630
|
+
});
|
|
3631
|
+
if (this.config.draggable) {
|
|
3632
|
+
this.attachDragHandlers(trigger);
|
|
3633
|
+
}
|
|
3634
|
+
this.shadow.appendChild(trigger);
|
|
3635
|
+
if (this.fabPos && this.config.draggable) {
|
|
3636
|
+
const savedPos = this.fabPos;
|
|
3637
|
+
this.fabPos = { x: 0, y: 0 };
|
|
3638
|
+
this.moveFab(trigger, savedPos.x, savedPos.y, false);
|
|
3639
|
+
}
|
|
3640
|
+
}
|
|
3641
|
+
const panel = document.createElement("div");
|
|
3642
|
+
panel.className = `mushi-panel ${pos}${this.isOpen ? " open" : " closed"}`;
|
|
3643
|
+
panel.setAttribute("role", "dialog");
|
|
3644
|
+
panel.setAttribute("aria-modal", "true");
|
|
3645
|
+
panel.setAttribute("aria-label", t.widget.title);
|
|
3646
|
+
panel.style.zIndex = String(this.config.zIndex + 1);
|
|
3647
|
+
this.applyInsetVars(panel);
|
|
3648
|
+
if (this.isOpen) {
|
|
3649
|
+
const ctx = this.renderCtx();
|
|
3650
|
+
panel.innerHTML = `${renderOutdatedBanner(ctx)}${renderStep(ctx)}${renderBrandFooter(ctx)}`;
|
|
3651
|
+
this.shadow.appendChild(panel);
|
|
3652
|
+
this.attachHandlers(panel);
|
|
3653
|
+
this.trapFocus(panel);
|
|
3654
|
+
this.attachViewportHandlers(panel);
|
|
3655
|
+
} else {
|
|
3656
|
+
this.teardownViewportHandlers();
|
|
3657
|
+
}
|
|
3633
3658
|
}
|
|
3634
3659
|
/**
|
|
3635
|
-
*
|
|
3636
|
-
*
|
|
3637
|
-
*
|
|
3638
|
-
*
|
|
3639
|
-
*
|
|
3640
|
-
*
|
|
3660
|
+
* Queries each `avoidSelectors` element in the host document and returns
|
|
3661
|
+
* the minimum top-offset in px so that a top-anchored element clears all
|
|
3662
|
+
* of them by `gap` pixels. Returns `null` when no selectors are provided
|
|
3663
|
+
* or no matching elements have a non-zero bounding rect.
|
|
3664
|
+
*
|
|
3665
|
+
* Runs in the host document (not shadow DOM) so it can reach fixed headers,
|
|
3666
|
+
* sticky nav bars, and sign-in CTAs.
|
|
3641
3667
|
*/
|
|
3642
|
-
|
|
3643
|
-
const
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
${this.config.betaMode?.enabled ? this.renderBetaSuccessFooter() : ""}
|
|
3659
|
-
</div>
|
|
3660
|
-
</div>
|
|
3661
|
-
`;
|
|
3668
|
+
computeAvoidTopPx(gap = 8) {
|
|
3669
|
+
const sels = this.config.avoidSelectors;
|
|
3670
|
+
if (!sels?.length) return null;
|
|
3671
|
+
let maxBottom = 0;
|
|
3672
|
+
for (const sel of sels) {
|
|
3673
|
+
try {
|
|
3674
|
+
const el = document.querySelector(sel);
|
|
3675
|
+
if (!el) continue;
|
|
3676
|
+
const r = el.getBoundingClientRect();
|
|
3677
|
+
if (r.bottom > maxBottom && r.width > 0 && r.height > 0) {
|
|
3678
|
+
maxBottom = r.bottom;
|
|
3679
|
+
}
|
|
3680
|
+
} catch {
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
return maxBottom > 0 ? Math.ceil(maxBottom) + gap : null;
|
|
3662
3684
|
}
|
|
3663
3685
|
/**
|
|
3664
|
-
*
|
|
3665
|
-
*
|
|
3666
|
-
* the user knows their submission is still in flight. Once we have the
|
|
3667
|
-
* id, we surface a short monospaced id + a copy button + an optional
|
|
3668
|
-
* "Track on Mushi" deep link to `dashboardUrl/reports/<id>` so the user
|
|
3669
|
-
* can watch the status walk through queued -> classified -> fixed in
|
|
3670
|
-
* real time (Peak-End rule: the last impression sticks). If we never
|
|
3671
|
-
* get an id (offline retry queue), we say so explicitly rather than
|
|
3672
|
-
* pretending everything is fine.
|
|
3686
|
+
* Minimum bottom-offset in px so a bottom-anchored trigger clears avoided
|
|
3687
|
+
* elements (tab bars, fixed CTAs). Mirrors {@link computeAvoidTopPx}.
|
|
3673
3688
|
*/
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3689
|
+
computeAvoidBottomPx(gap = 8) {
|
|
3690
|
+
const sels = this.config.avoidSelectors;
|
|
3691
|
+
if (!sels?.length) return null;
|
|
3692
|
+
let maxClearance = 0;
|
|
3693
|
+
for (const sel of sels) {
|
|
3694
|
+
try {
|
|
3695
|
+
const el = document.querySelector(sel);
|
|
3696
|
+
if (!el) continue;
|
|
3697
|
+
const r = el.getBoundingClientRect();
|
|
3698
|
+
if (r.width > 0 && r.height > 0) {
|
|
3699
|
+
const clearance = window.innerHeight - r.top + gap;
|
|
3700
|
+
if (clearance > maxClearance) maxClearance = clearance;
|
|
3701
|
+
}
|
|
3702
|
+
} catch {
|
|
3703
|
+
}
|
|
3704
|
+
}
|
|
3705
|
+
return maxClearance > 0 ? Math.ceil(maxClearance) : null;
|
|
3706
|
+
}
|
|
3707
|
+
applyInsetVars(el) {
|
|
3708
|
+
const { anchor } = this.config;
|
|
3709
|
+
if (anchor && Object.keys(anchor).length > 0) {
|
|
3710
|
+
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
3711
|
+
const value = anchor[edge];
|
|
3712
|
+
if (value !== void 0) el.style.setProperty(`--mushi-${edge}`, value);
|
|
3713
|
+
});
|
|
3714
|
+
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
3715
|
+
} else {
|
|
3716
|
+
const { inset } = this.config;
|
|
3717
|
+
if (!this.config.respectSafeArea) {
|
|
3718
|
+
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
3719
|
+
if (inset[edge] === void 0) el.style.setProperty(`--mushi-${edge}`, "24px");
|
|
3720
|
+
});
|
|
3721
|
+
}
|
|
3722
|
+
["top", "right", "bottom", "left"].forEach((edge) => {
|
|
3723
|
+
const value = inset[edge];
|
|
3724
|
+
if (value === void 0) return;
|
|
3725
|
+
el.style.setProperty(`--mushi-${edge}`, value === "auto" ? "auto" : `${value}px`);
|
|
3726
|
+
});
|
|
3727
|
+
el.style.setProperty("--mushi-safe-area", this.config.respectSafeArea ? "1" : "0");
|
|
3728
|
+
}
|
|
3729
|
+
const isTopAnchored = anchor?.top !== void 0 || this.config.position?.startsWith("top");
|
|
3730
|
+
const isBottomAnchored = anchor?.bottom !== void 0 || this.config.position?.startsWith("bottom") || !this.config.position;
|
|
3731
|
+
if (isTopAnchored) {
|
|
3732
|
+
const avoidPx = this.computeAvoidTopPx();
|
|
3733
|
+
if (avoidPx !== null) {
|
|
3734
|
+
el.style.setProperty("--mushi-top", `${avoidPx}px`);
|
|
3735
|
+
}
|
|
3736
|
+
}
|
|
3737
|
+
if (isBottomAnchored) {
|
|
3738
|
+
const avoidBottomPx = this.computeAvoidBottomPx();
|
|
3739
|
+
if (avoidBottomPx !== null) {
|
|
3740
|
+
el.style.setProperty("--mushi-bottom", `${avoidBottomPx}px`);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
}
|
|
3744
|
+
// ─── Draggable FAB ──────────────────────────────────────────────────────────
|
|
3745
|
+
/** Storage key for the FAB position, scoped to projectId when available. */
|
|
3746
|
+
fabStorageKey() {
|
|
3747
|
+
const id = this.config["projectId"] ?? "";
|
|
3748
|
+
return `mushi_fab_pos${id ? `_${id}` : ""}`;
|
|
3749
|
+
}
|
|
3750
|
+
/** Move the FAB to the given translated offset (relative to the inset origin),
|
|
3751
|
+
* clamping inside viewport safe area, and optionally snap to nearest edge.
|
|
3752
|
+
*
|
|
3753
|
+
* The FAB's CSS anchor can be any corner (bottom-right, bottom-left, …) so we
|
|
3754
|
+
* must derive the *base* position (CSS anchor with zero drag offset) to compute
|
|
3755
|
+
* correct clamp bounds and snap targets. We do this by subtracting the
|
|
3756
|
+
* already-applied drag offset from the live getBoundingClientRect() value. */
|
|
3757
|
+
moveFab(trigger, x, y, snap) {
|
|
3758
|
+
const axis = (() => {
|
|
3759
|
+
const d2 = this.config.draggable;
|
|
3760
|
+
if (!d2) return "both";
|
|
3761
|
+
return typeof d2 === "object" ? d2.axis ?? "both" : "both";
|
|
3762
|
+
})();
|
|
3763
|
+
const W = window.innerWidth;
|
|
3764
|
+
const H = window.innerHeight;
|
|
3765
|
+
const btnW = trigger.offsetWidth || 52;
|
|
3766
|
+
const btnH = trigger.offsetHeight || 52;
|
|
3767
|
+
const safeL = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-left") || "0") || 0;
|
|
3768
|
+
const safeR = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-right") || "0") || 0;
|
|
3769
|
+
const safeT = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-top") || "0") || 0;
|
|
3770
|
+
const safeB = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--sai-bottom") || "0") || 0;
|
|
3771
|
+
const margin = 8;
|
|
3772
|
+
const rect = trigger.getBoundingClientRect();
|
|
3773
|
+
const prevDragX = this.fabPos?.x ?? 0;
|
|
3774
|
+
const prevDragY = this.fabPos?.y ?? 0;
|
|
3775
|
+
const baseLeft = rect.left - prevDragX;
|
|
3776
|
+
const baseTop = rect.top - prevDragY;
|
|
3777
|
+
const minX = safeL + margin - baseLeft;
|
|
3778
|
+
const maxX = W - safeR - margin - btnW - baseLeft;
|
|
3779
|
+
const minY = safeT + margin - baseTop;
|
|
3780
|
+
const maxY = H - safeB - margin - btnH - baseTop;
|
|
3781
|
+
const newX = axis === "y" ? 0 : Math.max(minX, Math.min(maxX, x));
|
|
3782
|
+
const newY = axis === "x" ? 0 : Math.max(minY, Math.min(maxY, y));
|
|
3783
|
+
let finalX = newX;
|
|
3784
|
+
if (snap) {
|
|
3785
|
+
const d2 = this.config.draggable;
|
|
3786
|
+
const shouldSnap = d2 === true || typeof d2 === "object" && (d2.snapToEdge ?? true);
|
|
3787
|
+
if (shouldSnap && axis !== "y") {
|
|
3788
|
+
const center = rect.left + btnW / 2;
|
|
3789
|
+
finalX = center < W / 2 ? safeL + margin - baseLeft : W - safeR - margin - btnW - baseLeft;
|
|
3790
|
+
}
|
|
3684
3791
|
}
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3792
|
+
this.fabPos = { x: finalX, y: newY };
|
|
3793
|
+
trigger.style.setProperty("--mushi-drag-x", `${finalX}px`);
|
|
3794
|
+
trigger.style.setProperty("--mushi-drag-y", `${newY}px`);
|
|
3795
|
+
trigger.style.setProperty("--mushi-drag-active", "1");
|
|
3796
|
+
const d = this.config.draggable;
|
|
3797
|
+
const shouldPersist = d === true || typeof d === "object" && (d.persist ?? true);
|
|
3798
|
+
if (shouldPersist) {
|
|
3799
|
+
try {
|
|
3800
|
+
localStorage.setItem(this.fabStorageKey(), JSON.stringify(this.fabPos));
|
|
3801
|
+
} catch {
|
|
3802
|
+
}
|
|
3695
3803
|
}
|
|
3696
|
-
const idShort = `#${this.lastReportId.slice(0, 8)}`;
|
|
3697
|
-
const dashboard = (this.config.dashboardUrl ?? "").replace(/\/$/, "");
|
|
3698
|
-
const trackHref = dashboard ? `${dashboard}/reports/${encodeURIComponent(this.lastReportId)}` : "";
|
|
3699
|
-
return `
|
|
3700
|
-
<div class="mushi-success-receipt" role="status">
|
|
3701
|
-
<div class="mushi-success-receipt-row">
|
|
3702
|
-
<span class="mushi-success-receipt-label">Receipt</span>
|
|
3703
|
-
<button
|
|
3704
|
-
type="button"
|
|
3705
|
-
class="mushi-success-receipt-id"
|
|
3706
|
-
data-action="copy-report-id"
|
|
3707
|
-
data-copy-id="${escapeHtml(this.lastReportId)}"
|
|
3708
|
-
title="Copy report id ${escapeHtml(this.lastReportId)}"
|
|
3709
|
-
aria-label="Copy report id ${escapeHtml(this.lastReportId)}"
|
|
3710
|
-
>${escapeHtml(idShort)}<span class="mushi-success-receipt-copy" aria-hidden="true">\u2398</span></button>
|
|
3711
|
-
</div>
|
|
3712
|
-
${trackHref ? `
|
|
3713
|
-
<a
|
|
3714
|
-
class="mushi-success-receipt-track"
|
|
3715
|
-
href="${escapeHtml(trackHref)}"
|
|
3716
|
-
target="_blank"
|
|
3717
|
-
rel="noopener noreferrer"
|
|
3718
|
-
>Track on Mushi <span aria-hidden="true">\u2197</span></a>
|
|
3719
|
-
` : ""}
|
|
3720
|
-
${this.renderSlaLine()}
|
|
3721
|
-
</div>
|
|
3722
|
-
`;
|
|
3723
3804
|
}
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3805
|
+
/** Load previously persisted FAB position. */
|
|
3806
|
+
loadFabPos() {
|
|
3807
|
+
const d = this.config.draggable;
|
|
3808
|
+
if (!d) return;
|
|
3809
|
+
const shouldPersist = d === true || typeof d === "object" && (d.persist ?? true);
|
|
3810
|
+
if (!shouldPersist) return;
|
|
3811
|
+
try {
|
|
3812
|
+
const raw = localStorage.getItem(this.fabStorageKey());
|
|
3813
|
+
if (raw) {
|
|
3814
|
+
const parsed = JSON.parse(raw);
|
|
3815
|
+
if (typeof parsed?.x === "number" && typeof parsed?.y === "number") {
|
|
3816
|
+
this.fabPos = parsed;
|
|
3817
|
+
}
|
|
3818
|
+
}
|
|
3819
|
+
} catch {
|
|
3728
3820
|
}
|
|
3729
|
-
|
|
3821
|
+
}
|
|
3822
|
+
/** Attach Pointer Events-based drag to the trigger element. */
|
|
3823
|
+
attachDragHandlers(trigger) {
|
|
3824
|
+
if (this.fabPos === null) this.loadFabPos();
|
|
3825
|
+
let startX = 0, startY = 0;
|
|
3826
|
+
let originX = 0, originY = 0;
|
|
3827
|
+
let dragging = false;
|
|
3828
|
+
let moved = false;
|
|
3829
|
+
const onPointerDown = (e) => {
|
|
3830
|
+
if (e.button !== 0 && e.pointerType !== "touch") return;
|
|
3831
|
+
trigger.setPointerCapture(e.pointerId);
|
|
3832
|
+
startX = e.clientX;
|
|
3833
|
+
startY = e.clientY;
|
|
3834
|
+
const cur = this.fabPos ?? { x: 0, y: 0 };
|
|
3835
|
+
originX = cur.x;
|
|
3836
|
+
originY = cur.y;
|
|
3837
|
+
dragging = true;
|
|
3838
|
+
moved = false;
|
|
3839
|
+
};
|
|
3840
|
+
const DRAG_THRESHOLD = 6;
|
|
3841
|
+
const onPointerMove = (e) => {
|
|
3842
|
+
if (!dragging) return;
|
|
3843
|
+
const dx = e.clientX - startX;
|
|
3844
|
+
const dy = e.clientY - startY;
|
|
3845
|
+
if (!moved && Math.hypot(dx, dy) > DRAG_THRESHOLD) {
|
|
3846
|
+
moved = true;
|
|
3847
|
+
trigger.classList.add("dragging");
|
|
3848
|
+
trigger.setAttribute("aria-grabbed", "true");
|
|
3849
|
+
}
|
|
3850
|
+
if (moved) {
|
|
3851
|
+
e.preventDefault();
|
|
3852
|
+
this.moveFab(trigger, originX + dx, originY + dy, false);
|
|
3853
|
+
}
|
|
3854
|
+
};
|
|
3855
|
+
const onPointerUp = (e) => {
|
|
3856
|
+
if (!dragging) return;
|
|
3857
|
+
dragging = false;
|
|
3858
|
+
trigger.classList.remove("dragging");
|
|
3859
|
+
trigger.removeAttribute("aria-grabbed");
|
|
3860
|
+
if (moved) {
|
|
3861
|
+
const dx = e.clientX - startX;
|
|
3862
|
+
const dy = e.clientY - startY;
|
|
3863
|
+
this.moveFab(trigger, originX + dx, originY + dy, true);
|
|
3864
|
+
const suppressClick = (ev) => {
|
|
3865
|
+
ev.stopImmediatePropagation();
|
|
3866
|
+
trigger.removeEventListener("click", suppressClick, { capture: true });
|
|
3867
|
+
};
|
|
3868
|
+
trigger.addEventListener("click", suppressClick, { capture: true });
|
|
3869
|
+
}
|
|
3870
|
+
moved = false;
|
|
3871
|
+
};
|
|
3872
|
+
trigger.addEventListener("pointerdown", onPointerDown);
|
|
3873
|
+
trigger.addEventListener("pointermove", onPointerMove);
|
|
3874
|
+
trigger.addEventListener("pointerup", onPointerUp);
|
|
3875
|
+
trigger.addEventListener("pointercancel", onPointerUp);
|
|
3876
|
+
}
|
|
3877
|
+
// ─── Keyboard / visualViewport ──────────────────────────────────────────────
|
|
3878
|
+
/** Lift the panel above the software keyboard using visualViewport. */
|
|
3879
|
+
attachViewportHandlers(panel) {
|
|
3880
|
+
this.teardownViewportHandlers();
|
|
3881
|
+
const vv = window.visualViewport;
|
|
3882
|
+
if (!vv) return;
|
|
3883
|
+
const update = () => {
|
|
3884
|
+
const keyboardInset = window.innerHeight - vv.height - vv.offsetTop;
|
|
3885
|
+
if (keyboardInset > 50) {
|
|
3886
|
+
panel.style.setProperty("--mushi-keyboard-inset", `${Math.round(keyboardInset)}px`);
|
|
3887
|
+
panel.classList.add("keyboard-open");
|
|
3888
|
+
const ta = panel.querySelector('textarea, input[type="text"]');
|
|
3889
|
+
ta?.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
3890
|
+
} else {
|
|
3891
|
+
panel.style.setProperty("--mushi-keyboard-inset", "0px");
|
|
3892
|
+
panel.classList.remove("keyboard-open");
|
|
3893
|
+
}
|
|
3894
|
+
};
|
|
3895
|
+
vv.addEventListener("resize", update, { passive: true });
|
|
3896
|
+
vv.addEventListener("scroll", update, { passive: true });
|
|
3897
|
+
const onFocus = () => requestAnimationFrame(update);
|
|
3898
|
+
panel.addEventListener("focusin", onFocus);
|
|
3899
|
+
this.vvCleanup = () => {
|
|
3900
|
+
vv.removeEventListener("resize", update);
|
|
3901
|
+
vv.removeEventListener("scroll", update);
|
|
3902
|
+
panel.removeEventListener("focusin", onFocus);
|
|
3903
|
+
};
|
|
3904
|
+
}
|
|
3905
|
+
teardownViewportHandlers() {
|
|
3906
|
+
this.vvCleanup?.();
|
|
3907
|
+
this.vvCleanup = null;
|
|
3730
3908
|
}
|
|
3731
3909
|
/**
|
|
3732
|
-
*
|
|
3733
|
-
*
|
|
3734
|
-
*
|
|
3735
|
-
* the user sees shapes their entire impression of the interaction).
|
|
3910
|
+
* Minimum description length, lowered for CJK locales where each character
|
|
3911
|
+
* carries more meaning. Used by both the view layer (via renderCtx) and the
|
|
3912
|
+
* details-step input validation in attachHandlers.
|
|
3736
3913
|
*/
|
|
3737
|
-
|
|
3738
|
-
const
|
|
3739
|
-
const
|
|
3740
|
-
const
|
|
3741
|
-
return
|
|
3742
|
-
<div class="mushi-beta-success-footer" role="note" aria-label="Beta feedback acknowledgement">
|
|
3743
|
-
${email ? `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${email}</div>` : `<div class="mushi-beta-success-line">\u{1F4EC} Sent to ${appName}</div>`}
|
|
3744
|
-
<div class="mushi-beta-success-line mushi-beta-success-dim">We aim to review within 48h \xB7 thank you for helping build this</div>
|
|
3745
|
-
</div>
|
|
3746
|
-
`;
|
|
3914
|
+
effectiveMinLength() {
|
|
3915
|
+
const base = this.config.minDescriptionLength ?? 20;
|
|
3916
|
+
const lang = this.config.locale === "auto" ? typeof navigator !== "undefined" ? navigator.language ?? "" : "" : this.config.locale ?? "";
|
|
3917
|
+
const isCjk = /^(ja|zh|ko)/i.test(lang);
|
|
3918
|
+
return isCjk ? Math.max(4, Math.floor(base / 2)) : base;
|
|
3747
3919
|
}
|
|
3920
|
+
/** Tier accent colour for the rewards UI. */
|
|
3748
3921
|
tierColor(slug) {
|
|
3749
3922
|
const colors = {
|
|
3750
3923
|
free: "#6b7280",
|
|
@@ -3754,62 +3927,60 @@ var MushiWidget = class _MushiWidget {
|
|
|
3754
3927
|
};
|
|
3755
3928
|
return colors[slug] ?? "#6c47ff";
|
|
3756
3929
|
}
|
|
3757
|
-
/**
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
</div>
|
|
3812
|
-
`;
|
|
3930
|
+
/**
|
|
3931
|
+
* Build the read-only snapshot + bound helper closures the stateless view
|
|
3932
|
+
* layer (widget-render.ts) renders from. Rebuilt once per render() pass so
|
|
3933
|
+
* the HTML always reflects current state.
|
|
3934
|
+
*/
|
|
3935
|
+
renderCtx() {
|
|
3936
|
+
return {
|
|
3937
|
+
config: this.config,
|
|
3938
|
+
rewardsState: this.rewardsState,
|
|
3939
|
+
lastReportId: this.lastReportId,
|
|
3940
|
+
reporterLoading: this.reporterLoading,
|
|
3941
|
+
locale: this.locale,
|
|
3942
|
+
testerReputation: this.testerReputation,
|
|
3943
|
+
testerInfo: this.testerInfo,
|
|
3944
|
+
screenshotCapturing: this.screenshotCapturing,
|
|
3945
|
+
screenshotAttached: this.screenshotAttached,
|
|
3946
|
+
reporterError: this.reporterError,
|
|
3947
|
+
magicLinkError: this.magicLinkError,
|
|
3948
|
+
elementCapturing: this.elementCapturing,
|
|
3949
|
+
submitting: this.submitting,
|
|
3950
|
+
sdkFreshness: this.sdkFreshness,
|
|
3951
|
+
screenshotError: this.screenshotError,
|
|
3952
|
+
reporterReports: this.reporterReports,
|
|
3953
|
+
magicLinkSending: this.magicLinkSending,
|
|
3954
|
+
magicLinkEmail: this.magicLinkEmail,
|
|
3955
|
+
globalLeaderboardLoading: this.globalLeaderboardLoading,
|
|
3956
|
+
globalLeaderboard: this.globalLeaderboard,
|
|
3957
|
+
elementSelected: this.elementSelected,
|
|
3958
|
+
crossAppLoading: this.crossAppLoading,
|
|
3959
|
+
callbacks: this.callbacks,
|
|
3960
|
+
testerJwt: this.testerJwt,
|
|
3961
|
+
submittedAt: this.submittedAt,
|
|
3962
|
+
step: this.step,
|
|
3963
|
+
selectedReportId: this.selectedReportId,
|
|
3964
|
+
selectedCategory: this.selectedCategory,
|
|
3965
|
+
sdkVersion: this.sdkVersion,
|
|
3966
|
+
reporterComments: this.reporterComments,
|
|
3967
|
+
magicLinkSent: this.magicLinkSent,
|
|
3968
|
+
leaderboardLoading: this.leaderboardLoading,
|
|
3969
|
+
leaderboardEntries: this.leaderboardEntries,
|
|
3970
|
+
lastSubmitQueuedOffline: this.lastSubmitQueuedOffline,
|
|
3971
|
+
featureBoard: this.featureBoard,
|
|
3972
|
+
crossAppReports: this.crossAppReports,
|
|
3973
|
+
allowScreenshotRemove: this.allowScreenshotRemove,
|
|
3974
|
+
unreadCount: () => this.unreadCount(),
|
|
3975
|
+
tierColor: (slug) => this.tierColor(slug),
|
|
3976
|
+
resolveCustomCategory: (id) => this.resolveCustomCategory(id),
|
|
3977
|
+
effectiveMinLength: () => this.effectiveMinLength(),
|
|
3978
|
+
categoryLabel: (id) => this.categoryLabel(id),
|
|
3979
|
+
categoryIcon: (id) => this.categoryIcon(id),
|
|
3980
|
+
assistantTurns: this.assistantTurns,
|
|
3981
|
+
assistantSending: this.assistantSending,
|
|
3982
|
+
assistantError: this.assistantError
|
|
3983
|
+
};
|
|
3813
3984
|
}
|
|
3814
3985
|
attachHandlers(panel) {
|
|
3815
3986
|
const t = this.locale;
|
|
@@ -3837,9 +4008,38 @@ var MushiWidget = class _MushiWidget {
|
|
|
3837
4008
|
this.step = "reports";
|
|
3838
4009
|
} else if (this.step === "roadmap") {
|
|
3839
4010
|
this.step = "category";
|
|
4011
|
+
} else if (this.step === "assistant") {
|
|
4012
|
+
this.step = "category";
|
|
3840
4013
|
}
|
|
3841
4014
|
this.render();
|
|
3842
4015
|
});
|
|
4016
|
+
panel.querySelector('[data-action="assistant"]')?.addEventListener("click", () => {
|
|
4017
|
+
this.openAssistantTab();
|
|
4018
|
+
});
|
|
4019
|
+
panel.querySelectorAll('[data-action="assistant-suggest"]').forEach((btn) => {
|
|
4020
|
+
btn.addEventListener("click", () => {
|
|
4021
|
+
const value = btn.dataset.value;
|
|
4022
|
+
if (value) void this.sendAssistantMessage(value);
|
|
4023
|
+
});
|
|
4024
|
+
});
|
|
4025
|
+
{
|
|
4026
|
+
const form = panel.querySelector('[data-action="assistant-send"]');
|
|
4027
|
+
if (form) {
|
|
4028
|
+
const input = form.querySelector(".mushi-assistant-input");
|
|
4029
|
+
form.addEventListener("submit", (e) => {
|
|
4030
|
+
e.preventDefault();
|
|
4031
|
+
const value = input?.value ?? "";
|
|
4032
|
+
if (input) input.value = "";
|
|
4033
|
+
void this.sendAssistantMessage(value);
|
|
4034
|
+
});
|
|
4035
|
+
input?.addEventListener("keydown", (e) => {
|
|
4036
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
4037
|
+
e.preventDefault();
|
|
4038
|
+
form.requestSubmit();
|
|
4039
|
+
}
|
|
4040
|
+
});
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
3843
4043
|
panel.querySelector('[data-action="reports"]')?.addEventListener("click", () => {
|
|
3844
4044
|
void this.loadReporterReports();
|
|
3845
4045
|
});
|
|
@@ -3880,12 +4080,26 @@ var MushiWidget = class _MushiWidget {
|
|
|
3880
4080
|
this.crossAppLoading = true;
|
|
3881
4081
|
this.crossAppReports = null;
|
|
3882
4082
|
this.render();
|
|
3883
|
-
this.callbacks.onCrossAppReportsOpen
|
|
4083
|
+
if (this.callbacks.onCrossAppReportsOpen) {
|
|
4084
|
+
this.callbacks.onCrossAppReportsOpen();
|
|
4085
|
+
} else {
|
|
4086
|
+
this.crossAppLoading = false;
|
|
4087
|
+
this.crossAppReports = [];
|
|
4088
|
+
this.render();
|
|
4089
|
+
}
|
|
3884
4090
|
});
|
|
3885
4091
|
panel.querySelector('[data-action="open-global-leaderboard"]')?.addEventListener("click", () => {
|
|
3886
4092
|
this.step = "leaderboard";
|
|
3887
|
-
this.
|
|
4093
|
+
this.globalLeaderboard = null;
|
|
4094
|
+
this.globalLeaderboardLoading = true;
|
|
3888
4095
|
this.render();
|
|
4096
|
+
if (this.callbacks.onGlobalLeaderboardOpen) {
|
|
4097
|
+
this.callbacks.onGlobalLeaderboardOpen();
|
|
4098
|
+
} else {
|
|
4099
|
+
this.globalLeaderboardLoading = false;
|
|
4100
|
+
this.globalLeaderboard = [];
|
|
4101
|
+
this.render();
|
|
4102
|
+
}
|
|
3889
4103
|
});
|
|
3890
4104
|
panel.querySelector('[data-action="send-magic-link"]')?.addEventListener("click", () => {
|
|
3891
4105
|
void this.handleMagicLinkSend(panel);
|
|
@@ -3903,6 +4117,7 @@ var MushiWidget = class _MushiWidget {
|
|
|
3903
4117
|
this.magicLinkSent = false;
|
|
3904
4118
|
this.magicLinkEmail = "";
|
|
3905
4119
|
this.step = "category";
|
|
4120
|
+
this.callbacks.onTesterSignOut?.();
|
|
3906
4121
|
this.render();
|
|
3907
4122
|
});
|
|
3908
4123
|
panel.querySelector('[data-action="reporter-reply"]')?.addEventListener("click", () => {
|
|
@@ -4190,6 +4405,7 @@ var MushiWidget = class _MushiWidget {
|
|
|
4190
4405
|
}
|
|
4191
4406
|
/* ── Community: magic-link sign-in ───────────────────────────────── */
|
|
4192
4407
|
async handleMagicLinkSend(panel) {
|
|
4408
|
+
if (this.magicLinkSending) return;
|
|
4193
4409
|
const emailInput = panel.querySelector('[data-role="magic-link-email"]');
|
|
4194
4410
|
const email = (emailInput?.value ?? this.magicLinkEmail).trim();
|
|
4195
4411
|
if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
@@ -4199,13 +4415,15 @@ var MushiWidget = class _MushiWidget {
|
|
|
4199
4415
|
}
|
|
4200
4416
|
this.magicLinkEmail = email;
|
|
4201
4417
|
this.magicLinkError = "";
|
|
4418
|
+
this.magicLinkSending = true;
|
|
4202
4419
|
this.render();
|
|
4203
4420
|
try {
|
|
4204
4421
|
await this.callbacks.onMushiSignIn?.(email);
|
|
4205
4422
|
this.magicLinkSent = true;
|
|
4206
|
-
this.render();
|
|
4207
4423
|
} catch (err) {
|
|
4208
4424
|
this.magicLinkError = err instanceof Error ? err.message : "Could not send sign-in link. Try again.";
|
|
4425
|
+
} finally {
|
|
4426
|
+
this.magicLinkSending = false;
|
|
4209
4427
|
this.render();
|
|
4210
4428
|
}
|
|
4211
4429
|
}
|
|
@@ -4709,16 +4927,10 @@ function matchesUrl(url, matcher) {
|
|
|
4709
4927
|
}
|
|
4710
4928
|
function normalizeUrlPrefix(url) {
|
|
4711
4929
|
if (!url) return null;
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
try {
|
|
4717
|
-
const parsed = new URL(url);
|
|
4718
|
-
return parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "::1" || parsed.hostname.endsWith(".localhost");
|
|
4719
|
-
} catch {
|
|
4720
|
-
return /\blocalhost\b|127\.0\.0\.1/.test(url);
|
|
4721
|
-
}
|
|
4930
|
+
const normalized = normalizeComparableUrl(url);
|
|
4931
|
+
let end = normalized.length;
|
|
4932
|
+
while (end > 0 && normalized.charCodeAt(end - 1) === 47) end--;
|
|
4933
|
+
return normalized.slice(0, end);
|
|
4722
4934
|
}
|
|
4723
4935
|
function normalizeComparableUrl(url) {
|
|
4724
4936
|
try {
|
|
@@ -6291,10 +6503,6 @@ function createProactiveManager(config = {}) {
|
|
|
6291
6503
|
return { shouldShow, recordDismissal, recordSubmission, reset };
|
|
6292
6504
|
}
|
|
6293
6505
|
|
|
6294
|
-
// src/version.ts
|
|
6295
|
-
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
6296
|
-
var MUSHI_SDK_VERSION = "1.14.0" ;
|
|
6297
|
-
|
|
6298
6506
|
// src/mushi.ts
|
|
6299
6507
|
var instance = null;
|
|
6300
6508
|
var Mushi = class {
|
|
@@ -6305,16 +6513,17 @@ var Mushi = class {
|
|
|
6305
6513
|
core.createLogger({ scope: "mushi", level: "warn", format: "pretty" }).warn("Already initialized \u2014 call destroy() first to reinitialize");
|
|
6306
6514
|
return instance;
|
|
6307
6515
|
}
|
|
6308
|
-
|
|
6309
|
-
|
|
6516
|
+
const resolved = { ...core.resolveEnvConfig(), ...config };
|
|
6517
|
+
if (!resolved.projectId) {
|
|
6518
|
+
throw new Error("[mushi] projectId is required \u2014 set NEXT_PUBLIC_MUSHI_PROJECT_ID / VITE_MUSHI_PROJECT_ID / MUSHI_PROJECT_ID or pass it explicitly");
|
|
6310
6519
|
}
|
|
6311
|
-
if (!
|
|
6312
|
-
throw new Error("[mushi] apiKey is required");
|
|
6520
|
+
if (!resolved.apiKey) {
|
|
6521
|
+
throw new Error("[mushi] apiKey is required \u2014 set NEXT_PUBLIC_MUSHI_API_KEY / VITE_MUSHI_API_KEY / MUSHI_API_KEY or pass it explicitly");
|
|
6313
6522
|
}
|
|
6314
|
-
if (
|
|
6523
|
+
if (resolved.enabled === false) {
|
|
6315
6524
|
return createNoopInstance();
|
|
6316
6525
|
}
|
|
6317
|
-
instance = createInstance(
|
|
6526
|
+
instance = createInstance(resolved);
|
|
6318
6527
|
return instance;
|
|
6319
6528
|
}
|
|
6320
6529
|
static getInstance() {
|
|
@@ -6332,10 +6541,13 @@ function createInstance(config) {
|
|
|
6332
6541
|
const bootstrapConfig = applyPresetConfig(config);
|
|
6333
6542
|
let activeConfig = bootstrapConfig;
|
|
6334
6543
|
const log = config.debug ?? false ? core.createLogger({ scope: "mushi", level: "debug", format: "pretty" }) : core.noopLogger;
|
|
6544
|
+
let userToken = null;
|
|
6545
|
+
let currentPageContext = null;
|
|
6335
6546
|
const apiClient2 = core.createApiClient({
|
|
6336
6547
|
projectId: bootstrapConfig.projectId,
|
|
6337
6548
|
apiKey: bootstrapConfig.apiKey,
|
|
6338
|
-
...bootstrapConfig.apiEndpoint ? { apiEndpoint: bootstrapConfig.apiEndpoint } : {}
|
|
6549
|
+
...bootstrapConfig.apiEndpoint ? { apiEndpoint: bootstrapConfig.apiEndpoint } : {},
|
|
6550
|
+
getUserToken: () => userToken
|
|
6339
6551
|
});
|
|
6340
6552
|
const preFilter = core.createPreFilter(bootstrapConfig.preFilter);
|
|
6341
6553
|
const offlineQueue = core.createOfflineQueue(bootstrapConfig.offline);
|
|
@@ -6396,12 +6608,12 @@ function createInstance(config) {
|
|
|
6396
6608
|
return;
|
|
6397
6609
|
}
|
|
6398
6610
|
const status = statusResult.data;
|
|
6399
|
-
if (!status.is_tester) {
|
|
6611
|
+
if (!status.is_tester || !status.tester_id) {
|
|
6400
6612
|
clearTesterJwt();
|
|
6401
6613
|
return;
|
|
6402
6614
|
}
|
|
6403
6615
|
widget.setTesterSession(jwt, {
|
|
6404
|
-
id:
|
|
6616
|
+
id: status.tester_id,
|
|
6405
6617
|
public_handle: status.public_handle ?? null,
|
|
6406
6618
|
display_name: status.display_name ?? null
|
|
6407
6619
|
});
|
|
@@ -6713,25 +6925,29 @@ function createInstance(config) {
|
|
|
6713
6925
|
},
|
|
6714
6926
|
async onGlobalLeaderboardOpen() {
|
|
6715
6927
|
widget.setGlobalLeaderboard(null, true);
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6928
|
+
try {
|
|
6929
|
+
const jwt = readTesterJwt();
|
|
6930
|
+
const res = await apiClient2.getPublicLeaderboard(50);
|
|
6931
|
+
const rawEntries = res.ok ? res.data?.leaderboard ?? [] : [];
|
|
6932
|
+
const entries = rawEntries.map((e) => ({
|
|
6933
|
+
tester_id: e.tester_id,
|
|
6934
|
+
rank: e.rank,
|
|
6935
|
+
public_handle: e.public_handle,
|
|
6936
|
+
display_name: e.display_name,
|
|
6937
|
+
points_30d: e.points_30d,
|
|
6938
|
+
total_points: e.total_points ?? 0,
|
|
6939
|
+
badge: e.badge_slug
|
|
6940
|
+
}));
|
|
6941
|
+
widget.setGlobalLeaderboard(entries, false);
|
|
6942
|
+
if (jwt) {
|
|
6943
|
+
const repRes = await apiClient2.getMyReputation(jwt);
|
|
6944
|
+
if (repRes.ok && repRes.data) {
|
|
6945
|
+
const repData = repRes.data;
|
|
6946
|
+
if (repData.reputation) widget.setTesterReputation(repData.reputation);
|
|
6947
|
+
}
|
|
6734
6948
|
}
|
|
6949
|
+
} catch {
|
|
6950
|
+
widget.setGlobalLeaderboard([], false);
|
|
6735
6951
|
}
|
|
6736
6952
|
},
|
|
6737
6953
|
async onCrossAppReportsOpen() {
|
|
@@ -6740,9 +6956,29 @@ function createInstance(config) {
|
|
|
6740
6956
|
widget.setCrossAppReports([], false);
|
|
6741
6957
|
return;
|
|
6742
6958
|
}
|
|
6743
|
-
|
|
6744
|
-
|
|
6745
|
-
|
|
6959
|
+
try {
|
|
6960
|
+
const res = await apiClient2.getCrossAppReports(jwt);
|
|
6961
|
+
const reports = res.ok ? res.data?.reports ?? [] : [];
|
|
6962
|
+
widget.setCrossAppReports(reports, false);
|
|
6963
|
+
} catch {
|
|
6964
|
+
widget.setCrossAppReports([], false);
|
|
6965
|
+
}
|
|
6966
|
+
},
|
|
6967
|
+
onTesterSignOut() {
|
|
6968
|
+
clearTesterJwt();
|
|
6969
|
+
},
|
|
6970
|
+
// ── Assistant tab (P5) ───────────────────────────────────────────────
|
|
6971
|
+
assistantEnabled: bootstrapConfig.assistant?.enabled === true,
|
|
6972
|
+
...bootstrapConfig.assistant?.label ? { assistantLabel: bootstrapConfig.assistant.label } : {},
|
|
6973
|
+
...bootstrapConfig.assistant?.greeting ? { assistantGreeting: bootstrapConfig.assistant.greeting } : {},
|
|
6974
|
+
...bootstrapConfig.assistant?.suggestions ? { assistantSuggestions: bootstrapConfig.assistant.suggestions } : {},
|
|
6975
|
+
async onAssistantAsk(message, threadId) {
|
|
6976
|
+
const res = await apiClient2.askAssistant({
|
|
6977
|
+
message,
|
|
6978
|
+
threadId,
|
|
6979
|
+
context: currentPageContext
|
|
6980
|
+
});
|
|
6981
|
+
return res.ok ? res.data ?? null : null;
|
|
6746
6982
|
}
|
|
6747
6983
|
}, MUSHI_SDK_VERSION);
|
|
6748
6984
|
syncCaptureModules();
|
|
@@ -6832,8 +7068,8 @@ function createInstance(config) {
|
|
|
6832
7068
|
}).catch((err) => {
|
|
6833
7069
|
log.debug("Runtime SDK config fetch failed", { error: err instanceof Error ? err.message : String(err) });
|
|
6834
7070
|
});
|
|
6835
|
-
} else
|
|
6836
|
-
log.debug("Runtime SDK config
|
|
7071
|
+
} else {
|
|
7072
|
+
log.debug("Runtime SDK config disabled via runtimeConfig:false; using static bootstrap config");
|
|
6837
7073
|
}
|
|
6838
7074
|
void checkSdkFreshness();
|
|
6839
7075
|
log.info("Initialized", { projectId: config.projectId });
|
|
@@ -7288,6 +7524,28 @@ function createInstance(config) {
|
|
|
7288
7524
|
}
|
|
7289
7525
|
}
|
|
7290
7526
|
},
|
|
7527
|
+
identifyWithToken(token) {
|
|
7528
|
+
userToken = token && typeof token === "string" ? token : null;
|
|
7529
|
+
if (userToken) {
|
|
7530
|
+
const claims = core.parseIdentityToken(userToken);
|
|
7531
|
+
if (claims?.sub) {
|
|
7532
|
+
userInfo = {
|
|
7533
|
+
id: claims.sub,
|
|
7534
|
+
...claims.email ? { email: claims.email } : {},
|
|
7535
|
+
...claims.name ? { name: claims.name } : {}
|
|
7536
|
+
};
|
|
7537
|
+
}
|
|
7538
|
+
breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken()" });
|
|
7539
|
+
} else {
|
|
7540
|
+
breadcrumbs.add({ category: "lifecycle", level: "info", message: "Mushi.identifyWithToken(null)" });
|
|
7541
|
+
}
|
|
7542
|
+
},
|
|
7543
|
+
publishPageContext(context) {
|
|
7544
|
+
currentPageContext = context && context.route ? context : null;
|
|
7545
|
+
},
|
|
7546
|
+
openAssistant() {
|
|
7547
|
+
widget.openAssistantTab();
|
|
7548
|
+
},
|
|
7291
7549
|
addBreadcrumb(crumb) {
|
|
7292
7550
|
breadcrumbs.add(crumb);
|
|
7293
7551
|
},
|
|
@@ -7411,6 +7669,9 @@ function mergeRuntimeConfig(config, runtime) {
|
|
|
7411
7669
|
const nativeTrigger = runtime.native?.triggerMode;
|
|
7412
7670
|
const runtimeLauncher = runtime.widget?.launcher;
|
|
7413
7671
|
const widgetTrigger = runtimeLauncher ?? runtime.widget?.trigger ?? (nativeTrigger === "none" || nativeTrigger === "shake" ? "manual" : void 0);
|
|
7672
|
+
const explicitHidden = runtimeLauncher === "hidden" || runtime.widget?.trigger === "hidden";
|
|
7673
|
+
const hostTrigger = config.widget?.trigger;
|
|
7674
|
+
const safeWidgetTrigger = widgetTrigger === "hidden" && !explicitHidden && hostTrigger && hostTrigger !== "hidden" ? hostTrigger : widgetTrigger;
|
|
7414
7675
|
const runtimeWidget = runtime.widget;
|
|
7415
7676
|
const runtimeBannerVariant = runtimeWidget?.bannerVariant;
|
|
7416
7677
|
const runtimeBannerPosition = runtimeWidget?.bannerPosition;
|
|
@@ -7434,7 +7695,7 @@ function mergeRuntimeConfig(config, runtime) {
|
|
|
7434
7695
|
widget: {
|
|
7435
7696
|
...config.widget,
|
|
7436
7697
|
...runtime.widget,
|
|
7437
|
-
...
|
|
7698
|
+
...safeWidgetTrigger ? { trigger: safeWidgetTrigger } : {},
|
|
7438
7699
|
...derivedBannerConfig ? { bannerConfig: derivedBannerConfig } : {},
|
|
7439
7700
|
// betaMode is local-only: set by the host app, not the dashboard.
|
|
7440
7701
|
// Restore it after the runtime spread so it is never silently cleared.
|
|
@@ -7510,9 +7771,7 @@ function resolveApiEndpoint(config) {
|
|
|
7510
7771
|
return config.apiEndpoint ?? core.DEFAULT_API_ENDPOINT;
|
|
7511
7772
|
}
|
|
7512
7773
|
function shouldUseRuntimeConfig(config) {
|
|
7513
|
-
|
|
7514
|
-
if (config.runtimeConfig === true) return true;
|
|
7515
|
-
return !isLocalhostEndpoint(resolveApiEndpoint(config));
|
|
7774
|
+
return config.runtimeConfig !== false;
|
|
7516
7775
|
}
|
|
7517
7776
|
async function runDiagnostics(options) {
|
|
7518
7777
|
const endpoint = await probeApiEndpoint(options.apiEndpoint);
|
|
@@ -7674,6 +7933,12 @@ function createNoopInstance() {
|
|
|
7674
7933
|
captureException: async () => null,
|
|
7675
7934
|
identify: () => {
|
|
7676
7935
|
},
|
|
7936
|
+
identifyWithToken: () => {
|
|
7937
|
+
},
|
|
7938
|
+
publishPageContext: () => {
|
|
7939
|
+
},
|
|
7940
|
+
openAssistant: () => {
|
|
7941
|
+
},
|
|
7677
7942
|
addBreadcrumb: () => {
|
|
7678
7943
|
},
|
|
7679
7944
|
getBreadcrumbs: () => [],
|