@mushi-mushi/web 1.12.0 → 1.13.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/dist/index.cjs +80 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -1
- package/dist/index.d.ts +19 -1
- package/dist/index.js +80 -22
- package/dist/index.js.map +1 -1
- package/package.json +8 -18
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,8 @@ interface WidgetCallbacks {
|
|
|
54
54
|
*/
|
|
55
55
|
onSubmit(data: {
|
|
56
56
|
category: MushiReportCategory;
|
|
57
|
+
/** Set when the host configured `widget.categories` — the raw custom id chosen by the user. */
|
|
58
|
+
userCategory?: string;
|
|
57
59
|
description: string;
|
|
58
60
|
intent?: string;
|
|
59
61
|
}): void | Promise<WidgetSubmitOutcome | void>;
|
|
@@ -85,6 +87,11 @@ declare class MushiWidget {
|
|
|
85
87
|
private locale;
|
|
86
88
|
private isOpen;
|
|
87
89
|
private step;
|
|
90
|
+
/**
|
|
91
|
+
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
92
|
+
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
93
|
+
* after resolving through `resolveBaseCategory()`.
|
|
94
|
+
*/
|
|
88
95
|
private selectedCategory;
|
|
89
96
|
private selectedIntent;
|
|
90
97
|
/**
|
|
@@ -151,8 +158,19 @@ declare class MushiWidget {
|
|
|
151
158
|
mount(): void;
|
|
152
159
|
getIsMounted(): boolean;
|
|
153
160
|
updateConfig(config?: MushiWidgetConfig): void;
|
|
161
|
+
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
162
|
+
private resolveCustomCategory;
|
|
163
|
+
/**
|
|
164
|
+
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
165
|
+
* used for the report wire format. Falls back to `'other'`.
|
|
166
|
+
*/
|
|
167
|
+
private resolveBaseCategory;
|
|
168
|
+
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
169
|
+
private categoryIcon;
|
|
170
|
+
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
171
|
+
private categoryLabel;
|
|
154
172
|
open(options?: {
|
|
155
|
-
category?: MushiReportCategory;
|
|
173
|
+
category?: MushiReportCategory | string;
|
|
156
174
|
featureRequest?: boolean;
|
|
157
175
|
}): void;
|
|
158
176
|
close(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,8 @@ interface WidgetCallbacks {
|
|
|
54
54
|
*/
|
|
55
55
|
onSubmit(data: {
|
|
56
56
|
category: MushiReportCategory;
|
|
57
|
+
/** Set when the host configured `widget.categories` — the raw custom id chosen by the user. */
|
|
58
|
+
userCategory?: string;
|
|
57
59
|
description: string;
|
|
58
60
|
intent?: string;
|
|
59
61
|
}): void | Promise<WidgetSubmitOutcome | void>;
|
|
@@ -85,6 +87,11 @@ declare class MushiWidget {
|
|
|
85
87
|
private locale;
|
|
86
88
|
private isOpen;
|
|
87
89
|
private step;
|
|
90
|
+
/**
|
|
91
|
+
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
92
|
+
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
93
|
+
* after resolving through `resolveBaseCategory()`.
|
|
94
|
+
*/
|
|
88
95
|
private selectedCategory;
|
|
89
96
|
private selectedIntent;
|
|
90
97
|
/**
|
|
@@ -151,8 +158,19 @@ declare class MushiWidget {
|
|
|
151
158
|
mount(): void;
|
|
152
159
|
getIsMounted(): boolean;
|
|
153
160
|
updateConfig(config?: MushiWidgetConfig): void;
|
|
161
|
+
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
162
|
+
private resolveCustomCategory;
|
|
163
|
+
/**
|
|
164
|
+
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
165
|
+
* used for the report wire format. Falls back to `'other'`.
|
|
166
|
+
*/
|
|
167
|
+
private resolveBaseCategory;
|
|
168
|
+
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
169
|
+
private categoryIcon;
|
|
170
|
+
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
171
|
+
private categoryLabel;
|
|
154
172
|
open(options?: {
|
|
155
|
-
category?: MushiReportCategory;
|
|
173
|
+
category?: MushiReportCategory | string;
|
|
156
174
|
featureRequest?: boolean;
|
|
157
175
|
}): void;
|
|
158
176
|
close(): void;
|
package/dist/index.js
CHANGED
|
@@ -1987,7 +1987,8 @@ var MushiWidget = class _MushiWidget {
|
|
|
1987
1987
|
featureRequestCard: config.featureRequestCard ?? true,
|
|
1988
1988
|
featureRequestLabel: config.featureRequestLabel ?? "",
|
|
1989
1989
|
featureRequestDescription: config.featureRequestDescription ?? "",
|
|
1990
|
-
avoidSelectors: config.avoidSelectors ?? []
|
|
1990
|
+
avoidSelectors: config.avoidSelectors ?? [],
|
|
1991
|
+
categories: config.categories ?? []
|
|
1991
1992
|
};
|
|
1992
1993
|
this.callbacks = callbacks;
|
|
1993
1994
|
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
@@ -2003,6 +2004,11 @@ var MushiWidget = class _MushiWidget {
|
|
|
2003
2004
|
locale;
|
|
2004
2005
|
isOpen = false;
|
|
2005
2006
|
step = "category";
|
|
2007
|
+
/**
|
|
2008
|
+
* The selected category id. May be a built-in `MushiReportCategory` or a
|
|
2009
|
+
* custom id from `config.categories`. Cast to `MushiReportCategory` only
|
|
2010
|
+
* after resolving through `resolveBaseCategory()`.
|
|
2011
|
+
*/
|
|
2006
2012
|
selectedCategory = null;
|
|
2007
2013
|
selectedIntent = null;
|
|
2008
2014
|
/**
|
|
@@ -2110,7 +2116,8 @@ var MushiWidget = class _MushiWidget {
|
|
|
2110
2116
|
// mergeRuntimeConfig → bannerConfig. The widget is constructed before
|
|
2111
2117
|
// that fetch resolves, so this pass-through is what makes server-driven
|
|
2112
2118
|
// banner copy actually render.
|
|
2113
|
-
...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {}
|
|
2119
|
+
...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {},
|
|
2120
|
+
...config.categories !== void 0 ? { categories: config.categories } : {}
|
|
2114
2121
|
};
|
|
2115
2122
|
this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
|
|
2116
2123
|
if (this.host.isConnected) this.syncHostChromeState();
|
|
@@ -2118,6 +2125,35 @@ var MushiWidget = class _MushiWidget {
|
|
|
2118
2125
|
this.syncSmartHide();
|
|
2119
2126
|
this.render();
|
|
2120
2127
|
}
|
|
2128
|
+
// ─── Custom category helpers ──────────────────────────────────────────────
|
|
2129
|
+
/** Find a custom category entry by id. Returns undefined for built-in ids. */
|
|
2130
|
+
resolveCustomCategory(id) {
|
|
2131
|
+
return this.config.categories?.find((c) => c.id === id);
|
|
2132
|
+
}
|
|
2133
|
+
/**
|
|
2134
|
+
* Map a (possibly custom) category id to the built-in `MushiReportCategory`
|
|
2135
|
+
* used for the report wire format. Falls back to `'other'`.
|
|
2136
|
+
*/
|
|
2137
|
+
resolveBaseCategory(id) {
|
|
2138
|
+
const BUILTIN = ["bug", "slow", "visual", "confusing", "other"];
|
|
2139
|
+
if (BUILTIN.includes(id)) return id;
|
|
2140
|
+
const custom = this.resolveCustomCategory(id);
|
|
2141
|
+
return custom?.baseCategory ?? "other";
|
|
2142
|
+
}
|
|
2143
|
+
/** Icon for the selected category — custom entry's icon or built-in emoji. */
|
|
2144
|
+
categoryIcon(id) {
|
|
2145
|
+
const custom = this.resolveCustomCategory(id);
|
|
2146
|
+
if (custom?.icon) return custom.icon;
|
|
2147
|
+
return CATEGORY_ICONS[id] ?? "\u{1F4AC}";
|
|
2148
|
+
}
|
|
2149
|
+
/** Label for the selected category — custom entry label or built-in i18n string. */
|
|
2150
|
+
categoryLabel(id) {
|
|
2151
|
+
const custom = this.resolveCustomCategory(id);
|
|
2152
|
+
if (custom) return custom.label;
|
|
2153
|
+
const t = this.locale;
|
|
2154
|
+
return t.step1.categories[id] ?? id;
|
|
2155
|
+
}
|
|
2156
|
+
// ─── Open / close ─────────────────────────────────────────────────────────
|
|
2121
2157
|
open(options) {
|
|
2122
2158
|
if (this.isOpen) return;
|
|
2123
2159
|
this.isOpen = true;
|
|
@@ -2140,7 +2176,8 @@ var MushiWidget = class _MushiWidget {
|
|
|
2140
2176
|
} else if (options?.category) {
|
|
2141
2177
|
this.selectedCategory = options.category;
|
|
2142
2178
|
this.selectedIntent = null;
|
|
2143
|
-
|
|
2179
|
+
const custom = this.resolveCustomCategory(options.category);
|
|
2180
|
+
this.step = custom && (!custom.intents || custom.intents.length === 0) ? "details" : "intent";
|
|
2144
2181
|
} else {
|
|
2145
2182
|
this.selectedCategory = null;
|
|
2146
2183
|
this.selectedIntent = null;
|
|
@@ -2817,12 +2854,23 @@ var MushiWidget = class _MushiWidget {
|
|
|
2817
2854
|
}
|
|
2818
2855
|
renderCategoryStep() {
|
|
2819
2856
|
const t = this.locale;
|
|
2820
|
-
const
|
|
2821
|
-
|
|
2822
|
-
|
|
2857
|
+
const categoryEntries = this.config.categories && this.config.categories.length > 0 ? this.config.categories.map((c) => ({
|
|
2858
|
+
id: c.id,
|
|
2859
|
+
icon: c.icon ?? "\u{1F4AC}",
|
|
2860
|
+
label: c.label,
|
|
2861
|
+
desc: c.description ?? ""
|
|
2862
|
+
})) : ["bug", "slow", "visual", "confusing", "other"].map((id) => ({
|
|
2863
|
+
id,
|
|
2864
|
+
icon: CATEGORY_ICONS[id],
|
|
2865
|
+
label: t.step1.categories[id],
|
|
2866
|
+
desc: t.step1.categoryDescriptions[id]
|
|
2867
|
+
}));
|
|
2868
|
+
const categories = categoryEntries.map(({ id, icon, label, desc }) => `
|
|
2869
|
+
<button type="button" class="mushi-option-btn" data-category="${escapeHtml(id)}" role="radio" aria-checked="false">
|
|
2870
|
+
<span class="mushi-option-icon" aria-hidden="true">${escapeHtml(icon)}</span>
|
|
2823
2871
|
<div class="mushi-option-text">
|
|
2824
|
-
<span class="mushi-option-label">${
|
|
2825
|
-
|
|
2872
|
+
<span class="mushi-option-label">${escapeHtml(label)}</span>
|
|
2873
|
+
${desc ? `<span class="mushi-option-desc">${escapeHtml(desc)}</span>` : ""}
|
|
2826
2874
|
</div>
|
|
2827
2875
|
<span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
|
|
2828
2876
|
</button>
|
|
@@ -3051,19 +3099,22 @@ var MushiWidget = class _MushiWidget {
|
|
|
3051
3099
|
}
|
|
3052
3100
|
renderIntentStep() {
|
|
3053
3101
|
const t = this.locale;
|
|
3054
|
-
const
|
|
3055
|
-
const
|
|
3102
|
+
const catId = this.selectedCategory;
|
|
3103
|
+
const customEntry = this.resolveCustomCategory(catId);
|
|
3104
|
+
const intents = customEntry?.intents ?? (t.step2.intents[catId] || []);
|
|
3056
3105
|
const options = intents.map((intent) => `
|
|
3057
|
-
<button type="button" class="mushi-intent-btn" data-intent="${intent}">
|
|
3058
|
-
${intent}
|
|
3106
|
+
<button type="button" class="mushi-intent-btn" data-intent="${escapeHtml(intent)}">
|
|
3107
|
+
${escapeHtml(intent)}
|
|
3059
3108
|
</button>
|
|
3060
3109
|
`).join("");
|
|
3110
|
+
const icon = this.categoryIcon(catId);
|
|
3111
|
+
const label = this.categoryLabel(catId);
|
|
3061
3112
|
return `
|
|
3062
3113
|
${this.renderHeader({ title: t.step2.heading, showBack: true, step: STEP_NUMBER.intent })}
|
|
3063
3114
|
<div class="mushi-body">
|
|
3064
3115
|
<div class="mushi-selected-category">
|
|
3065
|
-
<span aria-hidden="true">${
|
|
3066
|
-
<span>${
|
|
3116
|
+
<span aria-hidden="true">${escapeHtml(icon)}</span>
|
|
3117
|
+
<span>${escapeHtml(label)}</span>
|
|
3067
3118
|
</div>
|
|
3068
3119
|
<div class="mushi-intents">
|
|
3069
3120
|
${options}
|
|
@@ -3414,8 +3465,10 @@ var MushiWidget = class _MushiWidget {
|
|
|
3414
3465
|
});
|
|
3415
3466
|
panel.querySelectorAll("[data-category]").forEach((btn) => {
|
|
3416
3467
|
btn.addEventListener("click", () => {
|
|
3417
|
-
|
|
3418
|
-
this.
|
|
3468
|
+
const catId = btn.dataset.category ?? "other";
|
|
3469
|
+
this.selectedCategory = catId;
|
|
3470
|
+
const custom = this.resolveCustomCategory(catId);
|
|
3471
|
+
this.step = custom && (!custom.intents || custom.intents.length === 0) ? "details" : "intent";
|
|
3419
3472
|
this.render();
|
|
3420
3473
|
});
|
|
3421
3474
|
});
|
|
@@ -3486,8 +3539,12 @@ var MushiWidget = class _MushiWidget {
|
|
|
3486
3539
|
this.render();
|
|
3487
3540
|
const outcomeP = (async () => {
|
|
3488
3541
|
try {
|
|
3542
|
+
const catId = this.selectedCategory;
|
|
3543
|
+
const baseCategory = this.resolveBaseCategory(catId);
|
|
3544
|
+
const isCustomCat = this.config.categories && this.config.categories.length > 0;
|
|
3489
3545
|
const ret = this.callbacks.onSubmit({
|
|
3490
|
-
category:
|
|
3546
|
+
category: baseCategory,
|
|
3547
|
+
...isCustomCat ? { userCategory: catId } : {},
|
|
3491
3548
|
description,
|
|
3492
3549
|
intent: this.selectedIntent ?? void 0
|
|
3493
3550
|
});
|
|
@@ -5743,7 +5800,7 @@ function createProactiveManager(config = {}) {
|
|
|
5743
5800
|
|
|
5744
5801
|
// src/version.ts
|
|
5745
5802
|
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
5746
|
-
var MUSHI_SDK_VERSION = "1.
|
|
5803
|
+
var MUSHI_SDK_VERSION = "1.13.0" ;
|
|
5747
5804
|
|
|
5748
5805
|
// src/mushi.ts
|
|
5749
5806
|
var instance = null;
|
|
@@ -5977,11 +6034,11 @@ function createInstance(config) {
|
|
|
5977
6034
|
widget.setScreenshotAttached(pendingScreenshot !== null);
|
|
5978
6035
|
}
|
|
5979
6036
|
widget = new MushiWidget(bootstrapConfig.widget, {
|
|
5980
|
-
onSubmit: async ({ category, description, intent }) => {
|
|
5981
|
-
log.info("Report submitted", { category, intent });
|
|
6037
|
+
onSubmit: async ({ category, userCategory, description, intent }) => {
|
|
6038
|
+
log.info("Report submitted", { category, userCategory, intent });
|
|
5982
6039
|
proactiveManager?.recordSubmission();
|
|
5983
6040
|
await autoCaptureScreenshot("submit");
|
|
5984
|
-
const outcome = await submitReport(category, description, intent);
|
|
6041
|
+
const outcome = await submitReport(category, description, intent, userCategory);
|
|
5985
6042
|
return outcome ?? { reportId: null, queuedOffline: true };
|
|
5986
6043
|
},
|
|
5987
6044
|
onOpen: () => {
|
|
@@ -6238,7 +6295,7 @@ function createInstance(config) {
|
|
|
6238
6295
|
});
|
|
6239
6296
|
}
|
|
6240
6297
|
}
|
|
6241
|
-
async function submitReport(category, description, intent) {
|
|
6298
|
+
async function submitReport(category, description, intent, userCategory) {
|
|
6242
6299
|
const filterResult = preFilter.check(description);
|
|
6243
6300
|
if (!filterResult.passed) {
|
|
6244
6301
|
log.info("Report blocked by pre-filter", { reason: filterResult.reason });
|
|
@@ -6298,6 +6355,7 @@ function createInstance(config) {
|
|
|
6298
6355
|
id: newUuid(),
|
|
6299
6356
|
projectId: config.projectId,
|
|
6300
6357
|
category,
|
|
6358
|
+
...userCategory ? { userCategory } : {},
|
|
6301
6359
|
description: scrubbedDescription,
|
|
6302
6360
|
userIntent: intent,
|
|
6303
6361
|
environment: captureEnvironment(),
|