@mindbill/react 0.27.0 → 0.27.1

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.js CHANGED
@@ -3190,15 +3190,6 @@ import {
3190
3190
  import { createBillLifecycleClient as createBillLifecycleClient2 } from "@mindbill/browser";
3191
3191
  import { Fragment as Fragment5, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
3192
3192
  var DEFAULT_REFRESH_INTERVAL2 = 6e4;
3193
- function downloadBlob(blob, filename) {
3194
- const url = URL.createObjectURL(blob);
3195
- const link = document.createElement("a");
3196
- link.href = url;
3197
- link.rel = "noopener noreferrer";
3198
- link.download = filename;
3199
- link.click();
3200
- window.setTimeout(() => URL.revokeObjectURL(url), 6e4);
3201
- }
3202
3193
  function reservePreviewWindow() {
3203
3194
  const preview = window.open("about:blank", "_blank");
3204
3195
  if (preview) preview.opener = null;
@@ -3216,6 +3207,15 @@ function previewBlob(blob, preview) {
3216
3207
  }
3217
3208
  window.setTimeout(() => URL.revokeObjectURL(url), 3e5);
3218
3209
  }
3210
+ async function openPdfFromUserGesture(loadPdf) {
3211
+ const preview = reservePreviewWindow();
3212
+ try {
3213
+ previewBlob(await loadPdf(), preview);
3214
+ } catch (error) {
3215
+ preview?.close();
3216
+ throw error;
3217
+ }
3218
+ }
3219
3219
  function useBillLifecycle({
3220
3220
  billId: providedBillId,
3221
3221
  sessionEndpoint = DEFAULT_SESSION_ENDPOINT2,
@@ -3294,27 +3294,21 @@ function useBillLifecycle({
3294
3294
  }
3295
3295
  }, []);
3296
3296
  const openAttachment = useCallback3(async (attachment) => {
3297
- const preview = reservePreviewWindow();
3298
- try {
3299
- previewBlob(await client.getAttachment(attachment.id), preview);
3300
- } catch (error2) {
3301
- preview?.close();
3302
- throw error2;
3303
- }
3297
+ await openPdfFromUserGesture(() => client.getAttachment(attachment.id));
3304
3298
  }, [client]);
3305
3299
  const openEor = useCallback3(async (document2) => {
3306
- const preview = reservePreviewWindow();
3300
+ await openPdfFromUserGesture(() => client.getEor(document2.id));
3301
+ }, [client]);
3302
+ const downloadPacket = useCallback3(async () => {
3303
+ setError(null);
3307
3304
  try {
3308
- previewBlob(await client.getEor(document2.id), preview);
3309
- } catch (error2) {
3310
- preview?.close();
3311
- throw error2;
3305
+ await openPdfFromUserGesture(() => client.getPacket());
3306
+ } catch (cause) {
3307
+ const nextError = cause instanceof Error ? cause : new Error("Submission packet could not be opened.");
3308
+ if (mounted.current) setError(nextError);
3309
+ throw nextError;
3312
3310
  }
3313
3311
  }, [client]);
3314
- const downloadPacket = useCallback3(async () => {
3315
- const packet = await client.getPacket();
3316
- downloadBlob(packet, `mindbill-${data?.bill.billNumber ?? providedBillId}-submission-packet.pdf`);
3317
- }, [client, data?.bill.billNumber, providedBillId]);
3318
3312
  return {
3319
3313
  billId: providedBillId,
3320
3314
  data,