@adoptai/genui-components 0.1.66 → 0.1.68

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.cjs CHANGED
@@ -1299,13 +1299,74 @@ var init_FlowGraph = __esm({
1299
1299
  renderSeq = 0;
1300
1300
  }
1301
1301
  });
1302
+ function resolvePdfWorkerSrc(pdfjs2) {
1303
+ const override = typeof window !== "undefined" ? window.__GENUI_PDF_WORKER_SRC__ : void 0;
1304
+ const current = pdfjs2.GlobalWorkerOptions.workerSrc;
1305
+ const isConfigured = !!current && current !== "pdf.worker.mjs";
1306
+ if (override) {
1307
+ pdfjs2.GlobalWorkerOptions.workerSrc = override;
1308
+ } else if (!isConfigured) {
1309
+ pdfjs2.GlobalWorkerOptions.workerSrc = `https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjs2.version}/build/pdf.worker.min.mjs`;
1310
+ }
1311
+ return pdfjs2.GlobalWorkerOptions.workerSrc;
1312
+ }
1313
+ function probePdfWorker() {
1314
+ if (probe) return probe;
1315
+ probe = (async () => {
1316
+ if (typeof window === "undefined") return false;
1317
+ try {
1318
+ const { pdfjs: pdfjs2 } = await import('react-pdf');
1319
+ resolvePdfWorkerSrc(pdfjs2);
1320
+ const task = pdfjs2.getDocument({ data: new TextEncoder().encode(TINY_PDF) });
1321
+ const doc = await Promise.race([
1322
+ task.promise,
1323
+ new Promise(
1324
+ (_, reject) => setTimeout(() => reject(new Error("pdf worker probe timed out")), PROBE_TIMEOUT_MS)
1325
+ )
1326
+ ]);
1327
+ await doc.destroy();
1328
+ return true;
1329
+ } catch (e) {
1330
+ probe = null;
1331
+ return false;
1332
+ }
1333
+ })();
1334
+ return probe;
1335
+ }
1336
+ function usePdfWorkerReady(enabled) {
1337
+ const [ready, setReady] = React45.useState(null);
1338
+ React45.useEffect(() => {
1339
+ if (!enabled) return;
1340
+ let cancelled = false;
1341
+ probePdfWorker().then((ok) => {
1342
+ if (!cancelled) setReady(ok);
1343
+ });
1344
+ return () => {
1345
+ cancelled = true;
1346
+ };
1347
+ }, [enabled]);
1348
+ return enabled ? ready : null;
1349
+ }
1350
+ var TINY_PDF, PROBE_TIMEOUT_MS, probe;
1351
+ var init_pdfWorkerProbe = __esm({
1352
+ "src/shared/viewers/pdfWorkerProbe.ts"() {
1353
+ "use client";
1354
+ TINY_PDF = `%PDF-1.1
1355
+ 1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
1356
+ 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj
1357
+ 3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 3 3]>>endobj
1358
+ trailer<</Root 1 0 R>>`;
1359
+ PROBE_TIMEOUT_MS = 5e3;
1360
+ probe = null;
1361
+ }
1362
+ });
1302
1363
 
1303
1364
  // src/composites/document-preview/PdfViewer.tsx
1304
1365
  var PdfViewer_exports = {};
1305
1366
  __export(PdfViewer_exports, {
1306
1367
  PdfViewer: () => PdfViewer
1307
1368
  });
1308
- function PdfViewer({ url, base64, onLoadSuccess }) {
1369
+ function PdfViewer({ url, base64, onLoadSuccess, onLoadError }) {
1309
1370
  const { BORDER: BORDER3, MUTED: MUTED2, SURFACE: SURFACE2 } = useTheme();
1310
1371
  const [numPages, setNumPages] = React45.useState(0);
1311
1372
  const [currentPage, setCurrentPage] = React45.useState(1);
@@ -1385,23 +1446,34 @@ function PdfViewer({ url, base64, onLoadSuccess }) {
1385
1446
  ] }),
1386
1447
  /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { overflow: "auto", width: "100%", display: "flex", justifyContent: "center", padding: "16px" }, children: [
1387
1448
  loading && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "200px", color: MUTED2, fontSize: "13px" }, children: "Loading PDF..." }),
1388
- /* @__PURE__ */ jsxRuntime.jsx(reactPdf.Document, { file: base64 ? `data:application/pdf;base64,${base64}` : url, onLoadSuccess: handleLoad, loading: "", children: /* @__PURE__ */ jsxRuntime.jsx(
1389
- reactPdf.Page,
1449
+ /* @__PURE__ */ jsxRuntime.jsx(
1450
+ reactPdf.Document,
1390
1451
  {
1391
- pageNumber: currentPage,
1392
- width: 540,
1393
- renderTextLayer: true,
1394
- renderAnnotationLayer: true
1452
+ file: base64 ? `data:application/pdf;base64,${base64}` : url,
1453
+ onLoadSuccess: handleLoad,
1454
+ onLoadError,
1455
+ loading: "",
1456
+ error: "",
1457
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1458
+ reactPdf.Page,
1459
+ {
1460
+ pageNumber: currentPage,
1461
+ width: 540,
1462
+ renderTextLayer: true,
1463
+ renderAnnotationLayer: true
1464
+ }
1465
+ )
1395
1466
  }
1396
- ) })
1467
+ )
1397
1468
  ] })
1398
1469
  ] });
1399
1470
  }
1400
1471
  var init_PdfViewer = __esm({
1401
1472
  "src/composites/document-preview/PdfViewer.tsx"() {
1402
1473
  "use client";
1474
+ init_pdfWorkerProbe();
1403
1475
  init_ThemeContext();
1404
- reactPdf.pdfjs.GlobalWorkerOptions.workerSrc = `https://unpkg.com/pdfjs-dist@${reactPdf.pdfjs.version}/build/pdf.worker.min.mjs`;
1476
+ resolvePdfWorkerSrc(reactPdf.pdfjs);
1405
1477
  }
1406
1478
  });
1407
1479
 
@@ -9064,6 +9136,7 @@ function useFullscreen(ref) {
9064
9136
  // src/composites/document-preview/resolver.tsx
9065
9137
  init_theme();
9066
9138
  init_ThemeContext();
9139
+ init_pdfWorkerProbe();
9067
9140
  var PdfViewer2 = React45__default.default.lazy(
9068
9141
  () => Promise.resolve().then(() => (init_PdfViewer(), PdfViewer_exports)).then((m) => ({ default: m.PdfViewer }))
9069
9142
  );
@@ -9127,8 +9200,14 @@ function DocumentPreviewResolver(p) {
9127
9200
  const totalPages = ((_c = p.pages) != null ? _c : []).length;
9128
9201
  const page = p.pages[currentPage];
9129
9202
  const pageHighlights = ((_d = p.highlights) != null ? _d : []).filter((h) => h.pageIndex === currentPage);
9203
+ const [pdfFailed, setPdfFailed] = React45.useState(false);
9204
+ const pdfWorkerReady = usePdfWorkerReady(hasRealFile && isPdf);
9205
+ const pdfReady = pdfFailed ? false : pdfWorkerReady;
9206
+ const showPdfViewer = hasRealFile && isPdf && pdfReady === true;
9207
+ const pdfPending = hasRealFile && isPdf && pdfReady === null;
9130
9208
  const handlePdfLoad = React45.useCallback(() => {
9131
9209
  }, []);
9210
+ const handlePdfError = React45.useCallback(() => setPdfFailed(true), []);
9132
9211
  const handleExcelLoad = React45.useCallback(() => {
9133
9212
  }, []);
9134
9213
  return /* @__PURE__ */ jsxRuntime.jsx(ComponentActions, { filename: (_e = p.title) != null ? _e : "document-preview", children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -9222,7 +9301,7 @@ function DocumentPreviewResolver(p) {
9222
9301
  children: pg.label
9223
9302
  },
9224
9303
  i
9225
- )) }) : !hasRealFile && totalPages > 1 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "6px 14px", borderLeft: `1px solid ${BORDER3}`, borderRight: `1px solid ${BORDER3}`, background: SURFACE2 }, children: [
9304
+ )) }) : (!hasRealFile || pdfReady === false) && totalPages > 1 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: "8px", padding: "6px 14px", borderLeft: `1px solid ${BORDER3}`, borderRight: `1px solid ${BORDER3}`, background: SURFACE2 }, children: [
9226
9305
  /* @__PURE__ */ jsxRuntime.jsx("button", { onClick: () => setCurrentPage(Math.max(0, currentPage - 1)), disabled: currentPage === 0, style: { border: `1px solid ${BORDER3}`, borderRadius: "4px", padding: "2px 8px", background: SURFACE2, cursor: "pointer", fontSize: "12px", color: currentPage === 0 ? BORDER3 : MUTED2 }, children: "\u2190" }),
9227
9306
  /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { fontSize: "12px", color: MUTED2 }, children: [
9228
9307
  currentPage + 1,
@@ -9242,7 +9321,7 @@ function DocumentPreviewResolver(p) {
9242
9321
  display: "flex",
9243
9322
  flexDirection: "column"
9244
9323
  }, children: [
9245
- hasRealFile && isPdf ? /* @__PURE__ */ jsxRuntime.jsx(React45.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(PdfViewer2, { url: (_q = p.source) == null ? void 0 : _q.url, base64: (_r = p.source) == null ? void 0 : _r.base64, onLoadSuccess: handlePdfLoad }) }) : hasRealFile && isExcel ? /* @__PURE__ */ jsxRuntime.jsx(React45.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(ExcelViewer2, { url: (_s = p.source) == null ? void 0 : _s.url, base64: (_t = p.source) == null ? void 0 : _t.base64, onLoadSuccess: handleExcelLoad }) }) : (page == null ? void 0 : page.imageUrl) ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "20px" }, children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: page.imageUrl, alt: page.label, style: { maxWidth: "100%", borderRadius: "4px" } }) }) : (page == null ? void 0 : page.content) ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontFamily: "var(--font-sans, system-ui)", fontSize: "13px", color: "var(--foreground)", lineHeight: 1.6, margin: 0, padding: "20px" }, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { content: page.content }) }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "120px", color: MUTED2, fontSize: "13px" }, children: [
9324
+ showPdfViewer ? /* @__PURE__ */ jsxRuntime.jsx(React45.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(PdfViewer2, { url: (_q = p.source) == null ? void 0 : _q.url, base64: (_r = p.source) == null ? void 0 : _r.base64, onLoadSuccess: handlePdfLoad, onLoadError: handlePdfError }) }) : pdfPending ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "200px", color: MUTED2, fontSize: "13px" }, children: "Loading preview\u2026" }) : hasRealFile && isExcel ? /* @__PURE__ */ jsxRuntime.jsx(React45.Suspense, { fallback: null, children: /* @__PURE__ */ jsxRuntime.jsx(ExcelViewer2, { url: (_s = p.source) == null ? void 0 : _s.url, base64: (_t = p.source) == null ? void 0 : _t.base64, onLoadSuccess: handleExcelLoad }) }) : (page == null ? void 0 : page.imageUrl) ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "20px" }, children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: page.imageUrl, alt: page.label, style: { maxWidth: "100%", borderRadius: "4px" } }) }) : (page == null ? void 0 : page.content) ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontFamily: "var(--font-sans, system-ui)", fontSize: "13px", color: "var(--foreground)", lineHeight: 1.6, margin: 0, padding: "20px" }, children: /* @__PURE__ */ jsxRuntime.jsx(Markdown, { content: page.content }) }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "120px", color: MUTED2, fontSize: "13px" }, children: [
9246
9325
  "No content available for ",
9247
9326
  (_u = page == null ? void 0 : page.label) != null ? _u : "this page"
9248
9327
  ] }),
@@ -11824,6 +11903,7 @@ function isExpirySoon(expiresAt) {
11824
11903
 
11825
11904
  // src/shared/viewers/PreviewHost.tsx
11826
11905
  init_ThemeContext();
11906
+ init_pdfWorkerProbe();
11827
11907
  var PdfViewer3 = React45.lazy(
11828
11908
  () => Promise.resolve().then(() => (init_PdfViewer(), PdfViewer_exports)).then((m) => ({ default: m.PdfViewer }))
11829
11909
  );
@@ -11835,6 +11915,19 @@ var TextViewer2 = React45.lazy(() => Promise.resolve().then(() => (init_TextView
11835
11915
  var DocxViewer2 = React45.lazy(() => Promise.resolve().then(() => (init_DocxViewer(), DocxViewer_exports)).then((m) => ({ default: m.DocxViewer })));
11836
11916
  var PEEK_ROWS = 20;
11837
11917
  var PEEK_LINES = 40;
11918
+ function GatedPdfViewer({ source }) {
11919
+ const { MUTED: MUTED2 } = useTheme();
11920
+ const [failed, setFailed] = React45.useState(false);
11921
+ const workerReady = usePdfWorkerReady(true);
11922
+ const ready = failed ? false : workerReady;
11923
+ if (ready === null) {
11924
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "24px", color: MUTED2, fontSize: "13px", textAlign: "center" }, children: "Loading preview\u2026" });
11925
+ }
11926
+ if (ready === false) {
11927
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { padding: "24px", color: MUTED2, fontSize: "13px", textAlign: "center" }, children: "Preview unavailable \u2014 download the file to view it." });
11928
+ }
11929
+ return /* @__PURE__ */ jsxRuntime.jsx(PdfViewer3, { url: source.url, base64: source.base64, onLoadError: () => setFailed(true) });
11930
+ }
11838
11931
  function PreviewHost({ kind, source, mode = "full" }) {
11839
11932
  const { MUTED: MUTED2 } = useTheme();
11840
11933
  const peek = mode === "peek";
@@ -11842,7 +11935,7 @@ function PreviewHost({ kind, source, mode = "full" }) {
11842
11935
  let viewer = null;
11843
11936
  switch (kind) {
11844
11937
  case "pdf":
11845
- viewer = /* @__PURE__ */ jsxRuntime.jsx(PdfViewer3, { url: source.url, base64: source.base64 });
11938
+ viewer = /* @__PURE__ */ jsxRuntime.jsx(GatedPdfViewer, { source });
11846
11939
  break;
11847
11940
  case "excel":
11848
11941
  viewer = /* @__PURE__ */ jsxRuntime.jsx(ExcelViewer3, { url: source.url, base64: source.base64 });
@@ -23681,6 +23774,7 @@ exports.DocumentFieldExtractionResolver = DocumentFieldExtractionResolver;
23681
23774
  exports.DocumentFieldExtractionSkeleton = DocumentFieldExtractionSkeleton;
23682
23775
  exports.DocumentPreviewResolver = DocumentPreviewResolver;
23683
23776
  exports.EngagementPipelineResolver = EngagementPipelineResolver;
23777
+ exports.EscalationCardResolver = EscalationCardResolver;
23684
23778
  exports.FIELD_REGISTRY = FIELD_REGISTRY;
23685
23779
  exports.FieldAuditLog = FieldAuditLog;
23686
23780
  exports.FieldDetails = FieldDetails;