@mushi-mushi/web 1.12.1 → 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 CHANGED
@@ -1989,7 +1989,8 @@ var MushiWidget = class _MushiWidget {
1989
1989
  featureRequestCard: config.featureRequestCard ?? true,
1990
1990
  featureRequestLabel: config.featureRequestLabel ?? "",
1991
1991
  featureRequestDescription: config.featureRequestDescription ?? "",
1992
- avoidSelectors: config.avoidSelectors ?? []
1992
+ avoidSelectors: config.avoidSelectors ?? [],
1993
+ categories: config.categories ?? []
1993
1994
  };
1994
1995
  this.callbacks = callbacks;
1995
1996
  this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
@@ -2005,6 +2006,11 @@ var MushiWidget = class _MushiWidget {
2005
2006
  locale;
2006
2007
  isOpen = false;
2007
2008
  step = "category";
2009
+ /**
2010
+ * The selected category id. May be a built-in `MushiReportCategory` or a
2011
+ * custom id from `config.categories`. Cast to `MushiReportCategory` only
2012
+ * after resolving through `resolveBaseCategory()`.
2013
+ */
2008
2014
  selectedCategory = null;
2009
2015
  selectedIntent = null;
2010
2016
  /**
@@ -2112,7 +2118,8 @@ var MushiWidget = class _MushiWidget {
2112
2118
  // mergeRuntimeConfig → bannerConfig. The widget is constructed before
2113
2119
  // that fetch resolves, so this pass-through is what makes server-driven
2114
2120
  // banner copy actually render.
2115
- ...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {}
2121
+ ...config.bannerConfig !== void 0 ? { bannerConfig: config.bannerConfig } : {},
2122
+ ...config.categories !== void 0 ? { categories: config.categories } : {}
2116
2123
  };
2117
2124
  this.locale = getLocale(this.config.locale === "auto" ? void 0 : this.config.locale);
2118
2125
  if (this.host.isConnected) this.syncHostChromeState();
@@ -2120,6 +2127,35 @@ var MushiWidget = class _MushiWidget {
2120
2127
  this.syncSmartHide();
2121
2128
  this.render();
2122
2129
  }
2130
+ // ─── Custom category helpers ──────────────────────────────────────────────
2131
+ /** Find a custom category entry by id. Returns undefined for built-in ids. */
2132
+ resolveCustomCategory(id) {
2133
+ return this.config.categories?.find((c) => c.id === id);
2134
+ }
2135
+ /**
2136
+ * Map a (possibly custom) category id to the built-in `MushiReportCategory`
2137
+ * used for the report wire format. Falls back to `'other'`.
2138
+ */
2139
+ resolveBaseCategory(id) {
2140
+ const BUILTIN = ["bug", "slow", "visual", "confusing", "other"];
2141
+ if (BUILTIN.includes(id)) return id;
2142
+ const custom = this.resolveCustomCategory(id);
2143
+ return custom?.baseCategory ?? "other";
2144
+ }
2145
+ /** Icon for the selected category — custom entry's icon or built-in emoji. */
2146
+ categoryIcon(id) {
2147
+ const custom = this.resolveCustomCategory(id);
2148
+ if (custom?.icon) return custom.icon;
2149
+ return CATEGORY_ICONS[id] ?? "\u{1F4AC}";
2150
+ }
2151
+ /** Label for the selected category — custom entry label or built-in i18n string. */
2152
+ categoryLabel(id) {
2153
+ const custom = this.resolveCustomCategory(id);
2154
+ if (custom) return custom.label;
2155
+ const t = this.locale;
2156
+ return t.step1.categories[id] ?? id;
2157
+ }
2158
+ // ─── Open / close ─────────────────────────────────────────────────────────
2123
2159
  open(options) {
2124
2160
  if (this.isOpen) return;
2125
2161
  this.isOpen = true;
@@ -2142,7 +2178,8 @@ var MushiWidget = class _MushiWidget {
2142
2178
  } else if (options?.category) {
2143
2179
  this.selectedCategory = options.category;
2144
2180
  this.selectedIntent = null;
2145
- this.step = "intent";
2181
+ const custom = this.resolveCustomCategory(options.category);
2182
+ this.step = custom && (!custom.intents || custom.intents.length === 0) ? "details" : "intent";
2146
2183
  } else {
2147
2184
  this.selectedCategory = null;
2148
2185
  this.selectedIntent = null;
@@ -2819,12 +2856,23 @@ var MushiWidget = class _MushiWidget {
2819
2856
  }
2820
2857
  renderCategoryStep() {
2821
2858
  const t = this.locale;
2822
- const categories = ["bug", "slow", "visual", "confusing", "other"].map((id) => `
2823
- <button type="button" class="mushi-option-btn" data-category="${id}" role="radio" aria-checked="false">
2824
- <span class="mushi-option-icon" aria-hidden="true">${CATEGORY_ICONS[id]}</span>
2859
+ const categoryEntries = this.config.categories && this.config.categories.length > 0 ? this.config.categories.map((c) => ({
2860
+ id: c.id,
2861
+ icon: c.icon ?? "\u{1F4AC}",
2862
+ label: c.label,
2863
+ desc: c.description ?? ""
2864
+ })) : ["bug", "slow", "visual", "confusing", "other"].map((id) => ({
2865
+ id,
2866
+ icon: CATEGORY_ICONS[id],
2867
+ label: t.step1.categories[id],
2868
+ desc: t.step1.categoryDescriptions[id]
2869
+ }));
2870
+ const categories = categoryEntries.map(({ id, icon, label, desc }) => `
2871
+ <button type="button" class="mushi-option-btn" data-category="${escapeHtml(id)}" role="radio" aria-checked="false">
2872
+ <span class="mushi-option-icon" aria-hidden="true">${escapeHtml(icon)}</span>
2825
2873
  <div class="mushi-option-text">
2826
- <span class="mushi-option-label">${t.step1.categories[id]}</span>
2827
- <span class="mushi-option-desc">${t.step1.categoryDescriptions[id]}</span>
2874
+ <span class="mushi-option-label">${escapeHtml(label)}</span>
2875
+ ${desc ? `<span class="mushi-option-desc">${escapeHtml(desc)}</span>` : ""}
2828
2876
  </div>
2829
2877
  <span class="mushi-option-arrow" aria-hidden="true">\u2192</span>
2830
2878
  </button>
@@ -3053,19 +3101,22 @@ var MushiWidget = class _MushiWidget {
3053
3101
  }
3054
3102
  renderIntentStep() {
3055
3103
  const t = this.locale;
3056
- const cat = this.selectedCategory;
3057
- const intents = t.step2.intents[cat] || [];
3104
+ const catId = this.selectedCategory;
3105
+ const customEntry = this.resolveCustomCategory(catId);
3106
+ const intents = customEntry?.intents ?? (t.step2.intents[catId] || []);
3058
3107
  const options = intents.map((intent) => `
3059
- <button type="button" class="mushi-intent-btn" data-intent="${intent}">
3060
- ${intent}
3108
+ <button type="button" class="mushi-intent-btn" data-intent="${escapeHtml(intent)}">
3109
+ ${escapeHtml(intent)}
3061
3110
  </button>
3062
3111
  `).join("");
3112
+ const icon = this.categoryIcon(catId);
3113
+ const label = this.categoryLabel(catId);
3063
3114
  return `
3064
3115
  ${this.renderHeader({ title: t.step2.heading, showBack: true, step: STEP_NUMBER.intent })}
3065
3116
  <div class="mushi-body">
3066
3117
  <div class="mushi-selected-category">
3067
- <span aria-hidden="true">${CATEGORY_ICONS[cat]}</span>
3068
- <span>${t.step1.categories[cat]}</span>
3118
+ <span aria-hidden="true">${escapeHtml(icon)}</span>
3119
+ <span>${escapeHtml(label)}</span>
3069
3120
  </div>
3070
3121
  <div class="mushi-intents">
3071
3122
  ${options}
@@ -3416,8 +3467,10 @@ var MushiWidget = class _MushiWidget {
3416
3467
  });
3417
3468
  panel.querySelectorAll("[data-category]").forEach((btn) => {
3418
3469
  btn.addEventListener("click", () => {
3419
- this.selectedCategory = btn.dataset.category;
3420
- this.step = "intent";
3470
+ const catId = btn.dataset.category ?? "other";
3471
+ this.selectedCategory = catId;
3472
+ const custom = this.resolveCustomCategory(catId);
3473
+ this.step = custom && (!custom.intents || custom.intents.length === 0) ? "details" : "intent";
3421
3474
  this.render();
3422
3475
  });
3423
3476
  });
@@ -3488,8 +3541,12 @@ var MushiWidget = class _MushiWidget {
3488
3541
  this.render();
3489
3542
  const outcomeP = (async () => {
3490
3543
  try {
3544
+ const catId = this.selectedCategory;
3545
+ const baseCategory = this.resolveBaseCategory(catId);
3546
+ const isCustomCat = this.config.categories && this.config.categories.length > 0;
3491
3547
  const ret = this.callbacks.onSubmit({
3492
- category: this.selectedCategory,
3548
+ category: baseCategory,
3549
+ ...isCustomCat ? { userCategory: catId } : {},
3493
3550
  description,
3494
3551
  intent: this.selectedIntent ?? void 0
3495
3552
  });
@@ -5745,7 +5802,7 @@ function createProactiveManager(config = {}) {
5745
5802
 
5746
5803
  // src/version.ts
5747
5804
  var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
5748
- var MUSHI_SDK_VERSION = "1.12.1" ;
5805
+ var MUSHI_SDK_VERSION = "1.13.0" ;
5749
5806
 
5750
5807
  // src/mushi.ts
5751
5808
  var instance = null;
@@ -5979,11 +6036,11 @@ function createInstance(config) {
5979
6036
  widget.setScreenshotAttached(pendingScreenshot !== null);
5980
6037
  }
5981
6038
  widget = new MushiWidget(bootstrapConfig.widget, {
5982
- onSubmit: async ({ category, description, intent }) => {
5983
- log.info("Report submitted", { category, intent });
6039
+ onSubmit: async ({ category, userCategory, description, intent }) => {
6040
+ log.info("Report submitted", { category, userCategory, intent });
5984
6041
  proactiveManager?.recordSubmission();
5985
6042
  await autoCaptureScreenshot("submit");
5986
- const outcome = await submitReport(category, description, intent);
6043
+ const outcome = await submitReport(category, description, intent, userCategory);
5987
6044
  return outcome ?? { reportId: null, queuedOffline: true };
5988
6045
  },
5989
6046
  onOpen: () => {
@@ -6240,7 +6297,7 @@ function createInstance(config) {
6240
6297
  });
6241
6298
  }
6242
6299
  }
6243
- async function submitReport(category, description, intent) {
6300
+ async function submitReport(category, description, intent, userCategory) {
6244
6301
  const filterResult = preFilter.check(description);
6245
6302
  if (!filterResult.passed) {
6246
6303
  log.info("Report blocked by pre-filter", { reason: filterResult.reason });
@@ -6300,6 +6357,7 @@ function createInstance(config) {
6300
6357
  id: core.newUuid(),
6301
6358
  projectId: config.projectId,
6302
6359
  category,
6360
+ ...userCategory ? { userCategory } : {},
6303
6361
  description: scrubbedDescription,
6304
6362
  userIntent: intent,
6305
6363
  environment: core.captureEnvironment(),