@usero/sdk 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vanilla.cjs CHANGED
@@ -1037,21 +1037,22 @@ function initUseroFeedbackWidget(props) {
1037
1037
  screenshotError = null;
1038
1038
  if (!file.type.startsWith("image/")) {
1039
1039
  screenshotError = "Image files only";
1040
- render();
1040
+ updateUploadExtras();
1041
1041
  return;
1042
1042
  }
1043
1043
  if (file.size > MAX_SCREENSHOT_BYTES) {
1044
1044
  screenshotError = "Max 10MB";
1045
- render();
1045
+ updateUploadExtras();
1046
1046
  return;
1047
1047
  }
1048
1048
  if (screenshots.length >= MAX_SCREENSHOTS) {
1049
1049
  screenshotError = `Max ${MAX_SCREENSHOTS} screenshots`;
1050
- render();
1050
+ updateUploadExtras();
1051
1051
  return;
1052
1052
  }
1053
1053
  isUploadingScreenshot = true;
1054
- render();
1054
+ updateUploadButton();
1055
+ updateUploadExtras();
1055
1056
  try {
1056
1057
  const uploaded = await apiClient.uploadScreenshot(file, clientId);
1057
1058
  screenshots = [...screenshots, uploaded];
@@ -1059,12 +1060,14 @@ function initUseroFeedbackWidget(props) {
1059
1060
  screenshotError = err instanceof Error ? err.message : "Upload failed";
1060
1061
  } finally {
1061
1062
  isUploadingScreenshot = false;
1062
- render();
1063
+ updateUploadButton();
1064
+ updateUploadExtras();
1063
1065
  }
1064
1066
  }
1065
1067
  function removeScreenshot(index) {
1066
1068
  screenshots = screenshots.filter((_, i) => i !== index);
1067
- render();
1069
+ updateUploadButton();
1070
+ updateUploadExtras();
1068
1071
  }
1069
1072
  function close() {
1070
1073
  if (!isOpen) return;
@@ -1072,6 +1075,57 @@ function initUseroFeedbackWidget(props) {
1072
1075
  onClose?.();
1073
1076
  render();
1074
1077
  }
1078
+ function buildUploadButtonInner() {
1079
+ return isUploadingScreenshot ? '<span class="fb-ups"></span> Uploading...' : "\u{1F4F7} Add screenshot";
1080
+ }
1081
+ function buildUploadButtonHtml() {
1082
+ const atMax = screenshots.length >= MAX_SCREENSHOTS;
1083
+ const btnDisabled = isUploadingScreenshot || atMax;
1084
+ return `
1085
+ <input type="file" accept="image/*" data-role="screenshot-input" style="display:none;" aria-label="Choose screenshot" />
1086
+ <button type="button" class="fb-upb ${btnDisabled ? "fb-upb--dis" : ""}" data-role="screenshot-pick" ${btnDisabled ? "disabled" : ""} style="border:1px solid ${theme.border};color:${theme.text};">
1087
+ ${buildUploadButtonInner()}
1088
+ </button>
1089
+ `;
1090
+ }
1091
+ function buildUploadExtrasHtml() {
1092
+ const atMax = screenshots.length >= MAX_SCREENSHOTS;
1093
+ const previewsHtml = screenshots.map(
1094
+ (shot, i) => `
1095
+ <div class="fb-sp">
1096
+ <img src="${escapeHtml(shot.url)}" alt="Screenshot ${i + 1}" class="fb-si" />
1097
+ <button type="button" class="fb-sr" data-role="screenshot-remove" data-index="${i}" aria-label="Remove screenshot">\u2715</button>
1098
+ </div>
1099
+ `
1100
+ ).join("");
1101
+ const errorHtml = screenshotError ? `<div class="fb-upe">\u26A0 ${escapeHtml(screenshotError)}</div>` : "";
1102
+ const limitHtml = atMax ? `<div class="fb-sl">Max ${MAX_SCREENSHOTS}</div>` : "";
1103
+ return screenshotError || screenshots.length > 0 || atMax ? `<div class="fb-up-extras">${errorHtml}${screenshots.length > 0 ? `<div class="fb-ss">${previewsHtml}</div>` : ""}${limitHtml}</div>` : "";
1104
+ }
1105
+ function updateUploadButton() {
1106
+ if (!showScreenshotOption) return;
1107
+ const pickBtn = panelEl.querySelector(
1108
+ 'button[data-role="screenshot-pick"]'
1109
+ );
1110
+ if (!pickBtn) return;
1111
+ const atMax = screenshots.length >= MAX_SCREENSHOTS;
1112
+ const btnDisabled = isUploadingScreenshot || atMax;
1113
+ pickBtn.disabled = btnDisabled;
1114
+ pickBtn.classList.toggle("fb-upb--dis", btnDisabled);
1115
+ pickBtn.innerHTML = buildUploadButtonInner();
1116
+ }
1117
+ function updateUploadExtras() {
1118
+ if (!showScreenshotOption) return;
1119
+ const container = panelEl.querySelector(".fb-up");
1120
+ if (!container) return;
1121
+ container.innerHTML = buildUploadExtrasHtml();
1122
+ container.querySelectorAll('button[data-role="screenshot-remove"]').forEach((btn) => {
1123
+ btn.addEventListener("click", () => {
1124
+ const idx = Number(btn.dataset.index);
1125
+ if (Number.isInteger(idx)) removeScreenshot(idx);
1126
+ });
1127
+ });
1128
+ }
1075
1129
  async function submitForm() {
1076
1130
  if (isSubmitting) return;
1077
1131
  isSubmitting = true;
@@ -1189,30 +1243,8 @@ function initUseroFeedbackWidget(props) {
1189
1243
  `;
1190
1244
  }).join("");
1191
1245
  const messageHtml = submitMessage ? `<div class="fb-msg fb-msg--header ${submitMessage.type === "success" ? "fb-msg--ok" : "fb-msg--err"}">${submitMessage.type === "success" ? "\u2713" : "\u26A0"} ${escapeHtml(submitMessage.text)}</div>` : "";
1192
- const uploadBtnHtml = showScreenshotOption ? (() => {
1193
- const atMax = screenshots.length >= MAX_SCREENSHOTS;
1194
- const btnDisabled = isUploadingScreenshot || atMax;
1195
- return `
1196
- <input type="file" accept="image/*" data-role="screenshot-input" style="display:none;" aria-label="Choose screenshot" />
1197
- <button type="button" class="fb-upb ${btnDisabled ? "fb-upb--dis" : ""}" data-role="screenshot-pick" ${btnDisabled ? "disabled" : ""} style="border:1px solid ${theme.border};color:${theme.text};">
1198
- ${isUploadingScreenshot ? '<span class="fb-ups"></span> Uploading...' : "\u{1F4F7} Add screenshot"}
1199
- </button>
1200
- `;
1201
- })() : "";
1202
- const uploadExtrasHtml = showScreenshotOption ? (() => {
1203
- const atMax = screenshots.length >= MAX_SCREENSHOTS;
1204
- const previewsHtml = screenshots.map(
1205
- (shot, i) => `
1206
- <div class="fb-sp">
1207
- <img src="${escapeHtml(shot.url)}" alt="Screenshot ${i + 1}" class="fb-si" />
1208
- <button type="button" class="fb-sr" data-role="screenshot-remove" data-index="${i}" aria-label="Remove screenshot">\u2715</button>
1209
- </div>
1210
- `
1211
- ).join("");
1212
- const errorHtml = screenshotError ? `<div class="fb-upe">\u26A0 ${escapeHtml(screenshotError)}</div>` : "";
1213
- const limitHtml = atMax ? `<div class="fb-sl">Max ${MAX_SCREENSHOTS}</div>` : "";
1214
- return screenshotError || screenshots.length > 0 || atMax ? `<div class="fb-up-extras">${errorHtml}${screenshots.length > 0 ? `<div class="fb-ss">${previewsHtml}</div>` : ""}${limitHtml}</div>` : "";
1215
- })() : "";
1246
+ const uploadBtnHtml = showScreenshotOption ? buildUploadButtonHtml() : "";
1247
+ const uploadExtrasHtml = showScreenshotOption ? buildUploadExtrasHtml() : "";
1216
1248
  const emailBlockHtml = showEmailOption ? `
1217
1249
  <div class="fb-email">
1218
1250
  <label class="fb-email-lbl" style="color:${theme.text}">
@@ -1238,7 +1270,7 @@ function initUseroFeedbackWidget(props) {
1238
1270
  ${uploadBtnHtml}
1239
1271
  <div class="fb-charcount${lowChars ? " fb-charcount--low" : ""}" data-role="charcount" style="color:${lowChars ? "#dc2626" : theme.text};opacity:${lowChars ? 1 : 0.6};">${remaining} chars remaining</div>
1240
1272
  </div>
1241
- ${uploadExtrasHtml ? `<div class="fb-up">${uploadExtrasHtml}</div>` : ""}
1273
+ ${showScreenshotOption ? `<div class="fb-up">${uploadExtrasHtml}</div>` : ""}
1242
1274
  ${emailBlockHtml}
1243
1275
  <button class="fb-sub ${submitDisabled ? "fb-sub--dis" : ""}" type="submit" aria-label="Submit" ${submitDisabled ? "disabled" : ""} style="${submitStyle}">
1244
1276
  ${isSubmitting ? '<span class="fb-spin"></span>' : ""}
@@ -1335,10 +1367,16 @@ function initUseroFeedbackWidget(props) {
1335
1367
  if (isOpen) close();
1336
1368
  else open();
1337
1369
  });
1338
- backdropEl.addEventListener("click", close);
1370
+ backdropEl.addEventListener("click", () => {
1371
+ if (isUploadingScreenshot || isSubmitting) return;
1372
+ close();
1373
+ });
1339
1374
  const onKeyDown = (e) => {
1340
1375
  if (!isOpen) return;
1341
- if (e.key === "Escape") close();
1376
+ if (e.key === "Escape") {
1377
+ if (isUploadingScreenshot || isSubmitting) return;
1378
+ close();
1379
+ }
1342
1380
  if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
1343
1381
  e.preventDefault();
1344
1382
  void submitForm();