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