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