@usero/sdk 1.1.2 → 1.1.4

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/react.js CHANGED
@@ -1039,21 +1039,22 @@ function initUseroFeedbackWidget(props) {
1039
1039
  screenshotError = null;
1040
1040
  if (!file.type.startsWith("image/")) {
1041
1041
  screenshotError = "Image files only";
1042
- render();
1042
+ updateUploadExtras();
1043
1043
  return;
1044
1044
  }
1045
1045
  if (file.size > MAX_SCREENSHOT_BYTES) {
1046
1046
  screenshotError = "Max 10MB";
1047
- render();
1047
+ updateUploadExtras();
1048
1048
  return;
1049
1049
  }
1050
1050
  if (screenshots.length >= MAX_SCREENSHOTS) {
1051
1051
  screenshotError = `Max ${MAX_SCREENSHOTS} screenshots`;
1052
- render();
1052
+ updateUploadExtras();
1053
1053
  return;
1054
1054
  }
1055
1055
  isUploadingScreenshot = true;
1056
- render();
1056
+ updateUploadButton();
1057
+ updateUploadExtras();
1057
1058
  try {
1058
1059
  const uploaded = await apiClient.uploadScreenshot(file, clientId);
1059
1060
  screenshots = [...screenshots, uploaded];
@@ -1061,12 +1062,14 @@ function initUseroFeedbackWidget(props) {
1061
1062
  screenshotError = err instanceof Error ? err.message : "Upload failed";
1062
1063
  } finally {
1063
1064
  isUploadingScreenshot = false;
1064
- render();
1065
+ updateUploadButton();
1066
+ updateUploadExtras();
1065
1067
  }
1066
1068
  }
1067
1069
  function removeScreenshot(index) {
1068
1070
  screenshots = screenshots.filter((_, i) => i !== index);
1069
- render();
1071
+ updateUploadButton();
1072
+ updateUploadExtras();
1070
1073
  }
1071
1074
  function close() {
1072
1075
  if (!isOpen) return;
@@ -1074,6 +1077,57 @@ function initUseroFeedbackWidget(props) {
1074
1077
  onClose?.();
1075
1078
  render();
1076
1079
  }
1080
+ function buildUploadButtonInner() {
1081
+ return isUploadingScreenshot ? '<span class="fb-ups"></span> Uploading...' : "\u{1F4F7} Add screenshot";
1082
+ }
1083
+ function buildUploadButtonHtml() {
1084
+ const atMax = screenshots.length >= MAX_SCREENSHOTS;
1085
+ const btnDisabled = isUploadingScreenshot || atMax;
1086
+ return `
1087
+ <input type="file" accept="image/*" data-role="screenshot-input" style="display:none;" aria-label="Choose screenshot" />
1088
+ <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};">
1089
+ ${buildUploadButtonInner()}
1090
+ </button>
1091
+ `;
1092
+ }
1093
+ function buildUploadExtrasHtml() {
1094
+ const atMax = screenshots.length >= MAX_SCREENSHOTS;
1095
+ const previewsHtml = screenshots.map(
1096
+ (shot, i) => `
1097
+ <div class="fb-sp">
1098
+ <img src="${escapeHtml(shot.url)}" alt="Screenshot ${i + 1}" class="fb-si" />
1099
+ <button type="button" class="fb-sr" data-role="screenshot-remove" data-index="${i}" aria-label="Remove screenshot">\u2715</button>
1100
+ </div>
1101
+ `
1102
+ ).join("");
1103
+ const errorHtml = screenshotError ? `<div class="fb-upe">\u26A0 ${escapeHtml(screenshotError)}</div>` : "";
1104
+ const limitHtml = atMax ? `<div class="fb-sl">Max ${MAX_SCREENSHOTS}</div>` : "";
1105
+ return screenshotError || screenshots.length > 0 || atMax ? `<div class="fb-up-extras">${errorHtml}${screenshots.length > 0 ? `<div class="fb-ss">${previewsHtml}</div>` : ""}${limitHtml}</div>` : "";
1106
+ }
1107
+ function updateUploadButton() {
1108
+ if (!showScreenshotOption) return;
1109
+ const pickBtn = panelEl.querySelector(
1110
+ 'button[data-role="screenshot-pick"]'
1111
+ );
1112
+ if (!pickBtn) return;
1113
+ const atMax = screenshots.length >= MAX_SCREENSHOTS;
1114
+ const btnDisabled = isUploadingScreenshot || atMax;
1115
+ pickBtn.disabled = btnDisabled;
1116
+ pickBtn.classList.toggle("fb-upb--dis", btnDisabled);
1117
+ pickBtn.innerHTML = buildUploadButtonInner();
1118
+ }
1119
+ function updateUploadExtras() {
1120
+ if (!showScreenshotOption) return;
1121
+ const container = panelEl.querySelector(".fb-up");
1122
+ if (!container) return;
1123
+ container.innerHTML = buildUploadExtrasHtml();
1124
+ container.querySelectorAll('button[data-role="screenshot-remove"]').forEach((btn) => {
1125
+ btn.addEventListener("click", () => {
1126
+ const idx = Number(btn.dataset.index);
1127
+ if (Number.isInteger(idx)) removeScreenshot(idx);
1128
+ });
1129
+ });
1130
+ }
1077
1131
  async function submitForm() {
1078
1132
  if (isSubmitting) return;
1079
1133
  isSubmitting = true;
@@ -1191,30 +1245,8 @@ function initUseroFeedbackWidget(props) {
1191
1245
  `;
1192
1246
  }).join("");
1193
1247
  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>` : "";
1194
- const uploadBtnHtml = showScreenshotOption ? (() => {
1195
- const atMax = screenshots.length >= MAX_SCREENSHOTS;
1196
- const btnDisabled = isUploadingScreenshot || atMax;
1197
- return `
1198
- <input type="file" accept="image/*" data-role="screenshot-input" style="display:none;" aria-label="Choose screenshot" />
1199
- <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};">
1200
- ${isUploadingScreenshot ? '<span class="fb-ups"></span> Uploading...' : "\u{1F4F7} Add screenshot"}
1201
- </button>
1202
- `;
1203
- })() : "";
1204
- const uploadExtrasHtml = showScreenshotOption ? (() => {
1205
- const atMax = screenshots.length >= MAX_SCREENSHOTS;
1206
- const previewsHtml = screenshots.map(
1207
- (shot, i) => `
1208
- <div class="fb-sp">
1209
- <img src="${escapeHtml(shot.url)}" alt="Screenshot ${i + 1}" class="fb-si" />
1210
- <button type="button" class="fb-sr" data-role="screenshot-remove" data-index="${i}" aria-label="Remove screenshot">\u2715</button>
1211
- </div>
1212
- `
1213
- ).join("");
1214
- const errorHtml = screenshotError ? `<div class="fb-upe">\u26A0 ${escapeHtml(screenshotError)}</div>` : "";
1215
- const limitHtml = atMax ? `<div class="fb-sl">Max ${MAX_SCREENSHOTS}</div>` : "";
1216
- return screenshotError || screenshots.length > 0 || atMax ? `<div class="fb-up-extras">${errorHtml}${screenshots.length > 0 ? `<div class="fb-ss">${previewsHtml}</div>` : ""}${limitHtml}</div>` : "";
1217
- })() : "";
1248
+ const uploadBtnHtml = showScreenshotOption ? buildUploadButtonHtml() : "";
1249
+ const uploadExtrasHtml = showScreenshotOption ? buildUploadExtrasHtml() : "";
1218
1250
  const emailBlockHtml = showEmailOption ? `
1219
1251
  <div class="fb-email">
1220
1252
  <label class="fb-email-lbl" style="color:${theme.text}">
@@ -1240,7 +1272,7 @@ function initUseroFeedbackWidget(props) {
1240
1272
  ${uploadBtnHtml}
1241
1273
  <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>
1242
1274
  </div>
1243
- ${uploadExtrasHtml ? `<div class="fb-up">${uploadExtrasHtml}</div>` : ""}
1275
+ ${showScreenshotOption ? `<div class="fb-up">${uploadExtrasHtml}</div>` : ""}
1244
1276
  ${emailBlockHtml}
1245
1277
  <button class="fb-sub ${submitDisabled ? "fb-sub--dis" : ""}" type="submit" aria-label="Submit" ${submitDisabled ? "disabled" : ""} style="${submitStyle}">
1246
1278
  ${isSubmitting ? '<span class="fb-spin"></span>' : ""}
@@ -1337,10 +1369,16 @@ function initUseroFeedbackWidget(props) {
1337
1369
  if (isOpen) close();
1338
1370
  else open();
1339
1371
  });
1340
- backdropEl.addEventListener("click", close);
1372
+ backdropEl.addEventListener("click", () => {
1373
+ if (isUploadingScreenshot || isSubmitting) return;
1374
+ close();
1375
+ });
1341
1376
  const onKeyDown = (e) => {
1342
1377
  if (!isOpen) return;
1343
- if (e.key === "Escape") close();
1378
+ if (e.key === "Escape") {
1379
+ if (isUploadingScreenshot || isSubmitting) return;
1380
+ close();
1381
+ }
1344
1382
  if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
1345
1383
  e.preventDefault();
1346
1384
  void submitForm();