@adoptai/genui-components 0.1.67 → 0.1.69
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/composites/document-preview/PdfViewer.d.ts +2 -1
- package/dist/composites/document-preview/PdfViewer.d.ts.map +1 -1
- package/dist/composites/document-preview/resolver.cjs +90 -11
- package/dist/composites/document-preview/resolver.cjs.map +1 -1
- package/dist/composites/document-preview/resolver.d.ts.map +1 -1
- package/dist/composites/document-preview/resolver.js +90 -11
- package/dist/composites/document-preview/resolver.js.map +1 -1
- package/dist/composites/download-card/resolver.cjs +244 -69
- package/dist/composites/download-card/resolver.cjs.map +1 -1
- package/dist/composites/download-card/resolver.js +189 -14
- package/dist/composites/download-card/resolver.js.map +1 -1
- package/dist/index.cjs +472 -289
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +265 -82
- package/dist/index.js.map +1 -1
- package/dist/renderer.cjs +404 -221
- package/dist/renderer.cjs.map +1 -1
- package/dist/renderer.js +259 -76
- package/dist/renderer.js.map +1 -1
- package/dist/resolver.cjs +403 -220
- package/dist/resolver.cjs.map +1 -1
- package/dist/resolver.js +259 -76
- package/dist/resolver.js.map +1 -1
- package/dist/shared/fileType.d.ts +1 -1
- package/dist/shared/fileType.d.ts.map +1 -1
- package/dist/shared/viewers/HtmlViewer.d.ts +12 -0
- package/dist/shared/viewers/HtmlViewer.d.ts.map +1 -0
- package/dist/shared/viewers/PreviewHost.d.ts.map +1 -1
- package/dist/shared/viewers/pdfWorkerProbe.d.ts +31 -0
- package/dist/shared/viewers/pdfWorkerProbe.d.ts.map +1 -0
- package/dist/tool-definitions.json +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import
|
|
2
|
+
import React11, { lazy, createContext, useState, useCallback, useEffect, useRef, useContext, Suspense } from 'react';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
4
|
import { Document, Page, pdfjs } from 'react-pdf';
|
|
5
5
|
import 'react-pdf/dist/Page/AnnotationLayer.css';
|
|
@@ -443,13 +443,73 @@ var init_Markdown = __esm({
|
|
|
443
443
|
init_theme();
|
|
444
444
|
}
|
|
445
445
|
});
|
|
446
|
+
function resolvePdfWorkerSrc(pdfjs2) {
|
|
447
|
+
const override = typeof window !== "undefined" ? window.__GENUI_PDF_WORKER_SRC__ : void 0;
|
|
448
|
+
const current = pdfjs2.GlobalWorkerOptions.workerSrc;
|
|
449
|
+
const isConfigured = !!current && current !== "pdf.worker.mjs";
|
|
450
|
+
if (override) {
|
|
451
|
+
pdfjs2.GlobalWorkerOptions.workerSrc = override;
|
|
452
|
+
} else if (!isConfigured) {
|
|
453
|
+
pdfjs2.GlobalWorkerOptions.workerSrc = `https://cdn.jsdelivr.net/npm/pdfjs-dist@${pdfjs2.version}/build/pdf.worker.min.mjs`;
|
|
454
|
+
}
|
|
455
|
+
return pdfjs2.GlobalWorkerOptions.workerSrc;
|
|
456
|
+
}
|
|
457
|
+
function probePdfWorker() {
|
|
458
|
+
if (probe) return probe;
|
|
459
|
+
probe = (async () => {
|
|
460
|
+
if (typeof window === "undefined") return false;
|
|
461
|
+
try {
|
|
462
|
+
const { pdfjs: pdfjs2 } = await import('react-pdf');
|
|
463
|
+
resolvePdfWorkerSrc(pdfjs2);
|
|
464
|
+
const task = pdfjs2.getDocument({ data: new TextEncoder().encode(TINY_PDF) });
|
|
465
|
+
const doc = await Promise.race([
|
|
466
|
+
task.promise,
|
|
467
|
+
new Promise(
|
|
468
|
+
(_, reject) => setTimeout(() => reject(new Error("pdf worker probe timed out")), PROBE_TIMEOUT_MS)
|
|
469
|
+
)
|
|
470
|
+
]);
|
|
471
|
+
await doc.destroy();
|
|
472
|
+
return true;
|
|
473
|
+
} catch (e) {
|
|
474
|
+
probe = null;
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
})();
|
|
478
|
+
return probe;
|
|
479
|
+
}
|
|
480
|
+
function usePdfWorkerReady(enabled) {
|
|
481
|
+
const [ready, setReady] = useState(null);
|
|
482
|
+
useEffect(() => {
|
|
483
|
+
let cancelled = false;
|
|
484
|
+
probePdfWorker().then((ok) => {
|
|
485
|
+
if (!cancelled) setReady(ok);
|
|
486
|
+
});
|
|
487
|
+
return () => {
|
|
488
|
+
cancelled = true;
|
|
489
|
+
};
|
|
490
|
+
}, [enabled]);
|
|
491
|
+
return ready ;
|
|
492
|
+
}
|
|
493
|
+
var TINY_PDF, PROBE_TIMEOUT_MS, probe;
|
|
494
|
+
var init_pdfWorkerProbe = __esm({
|
|
495
|
+
"src/shared/viewers/pdfWorkerProbe.ts"() {
|
|
496
|
+
"use client";
|
|
497
|
+
TINY_PDF = `%PDF-1.1
|
|
498
|
+
1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj
|
|
499
|
+
2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj
|
|
500
|
+
3 0 obj<</Type/Page/Parent 2 0 R/MediaBox[0 0 3 3]>>endobj
|
|
501
|
+
trailer<</Root 1 0 R>>`;
|
|
502
|
+
PROBE_TIMEOUT_MS = 5e3;
|
|
503
|
+
probe = null;
|
|
504
|
+
}
|
|
505
|
+
});
|
|
446
506
|
|
|
447
507
|
// src/composites/document-preview/PdfViewer.tsx
|
|
448
508
|
var PdfViewer_exports = {};
|
|
449
509
|
__export(PdfViewer_exports, {
|
|
450
510
|
PdfViewer: () => PdfViewer
|
|
451
511
|
});
|
|
452
|
-
function PdfViewer({ url, base64, onLoadSuccess }) {
|
|
512
|
+
function PdfViewer({ url, base64, onLoadSuccess, onLoadError }) {
|
|
453
513
|
const { BORDER: BORDER2, MUTED: MUTED2, SURFACE: SURFACE2 } = useTheme();
|
|
454
514
|
const [numPages, setNumPages] = useState(0);
|
|
455
515
|
const [currentPage, setCurrentPage] = useState(1);
|
|
@@ -529,23 +589,34 @@ function PdfViewer({ url, base64, onLoadSuccess }) {
|
|
|
529
589
|
] }),
|
|
530
590
|
/* @__PURE__ */ jsxs("div", { style: { overflow: "auto", width: "100%", display: "flex", justifyContent: "center", padding: "16px" }, children: [
|
|
531
591
|
loading && /* @__PURE__ */ jsx("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "200px", color: MUTED2, fontSize: "13px" }, children: "Loading PDF..." }),
|
|
532
|
-
/* @__PURE__ */ jsx(
|
|
533
|
-
|
|
592
|
+
/* @__PURE__ */ jsx(
|
|
593
|
+
Document,
|
|
534
594
|
{
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
595
|
+
file: base64 ? `data:application/pdf;base64,${base64}` : url,
|
|
596
|
+
onLoadSuccess: handleLoad,
|
|
597
|
+
onLoadError,
|
|
598
|
+
loading: "",
|
|
599
|
+
error: "",
|
|
600
|
+
children: /* @__PURE__ */ jsx(
|
|
601
|
+
Page,
|
|
602
|
+
{
|
|
603
|
+
pageNumber: currentPage,
|
|
604
|
+
width: 540,
|
|
605
|
+
renderTextLayer: true,
|
|
606
|
+
renderAnnotationLayer: true
|
|
607
|
+
}
|
|
608
|
+
)
|
|
539
609
|
}
|
|
540
|
-
)
|
|
610
|
+
)
|
|
541
611
|
] })
|
|
542
612
|
] });
|
|
543
613
|
}
|
|
544
614
|
var init_PdfViewer = __esm({
|
|
545
615
|
"src/composites/document-preview/PdfViewer.tsx"() {
|
|
546
616
|
"use client";
|
|
617
|
+
init_pdfWorkerProbe();
|
|
547
618
|
init_ThemeContext();
|
|
548
|
-
pdfjs
|
|
619
|
+
resolvePdfWorkerSrc(pdfjs);
|
|
549
620
|
}
|
|
550
621
|
});
|
|
551
622
|
|
|
@@ -1052,6 +1123,89 @@ var init_DocxViewer = __esm({
|
|
|
1052
1123
|
}
|
|
1053
1124
|
});
|
|
1054
1125
|
|
|
1126
|
+
// src/shared/viewers/HtmlViewer.tsx
|
|
1127
|
+
var HtmlViewer_exports = {};
|
|
1128
|
+
__export(HtmlViewer_exports, {
|
|
1129
|
+
HtmlViewer: () => HtmlViewer
|
|
1130
|
+
});
|
|
1131
|
+
function HtmlViewer({ url, base64, height = 480 }) {
|
|
1132
|
+
const { MUTED: MUTED2 } = useTheme();
|
|
1133
|
+
const [html, setHtml] = useState("");
|
|
1134
|
+
const [loading, setLoading] = useState(true);
|
|
1135
|
+
const [error, setError] = useState(null);
|
|
1136
|
+
useEffect(() => {
|
|
1137
|
+
let cancelled = false;
|
|
1138
|
+
setLoading(true);
|
|
1139
|
+
setError(null);
|
|
1140
|
+
if (base64) {
|
|
1141
|
+
try {
|
|
1142
|
+
if (!cancelled) {
|
|
1143
|
+
setHtml(base64ToText(base64));
|
|
1144
|
+
setLoading(false);
|
|
1145
|
+
}
|
|
1146
|
+
} catch (e) {
|
|
1147
|
+
if (!cancelled) {
|
|
1148
|
+
setError(e instanceof Error ? e.message : "Failed to decode HTML");
|
|
1149
|
+
setLoading(false);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
return () => {
|
|
1153
|
+
cancelled = true;
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
if (!url) {
|
|
1157
|
+
setError("No file source provided");
|
|
1158
|
+
setLoading(false);
|
|
1159
|
+
return () => {
|
|
1160
|
+
cancelled = true;
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
fetch(url).then((r) => {
|
|
1164
|
+
if (!r.ok) throw new Error(`Failed to fetch: ${r.status}`);
|
|
1165
|
+
return r.text();
|
|
1166
|
+
}).then((t) => {
|
|
1167
|
+
if (cancelled) return;
|
|
1168
|
+
setHtml(t);
|
|
1169
|
+
setLoading(false);
|
|
1170
|
+
}).catch((e) => {
|
|
1171
|
+
if (cancelled) return;
|
|
1172
|
+
setError(e.message);
|
|
1173
|
+
setLoading(false);
|
|
1174
|
+
});
|
|
1175
|
+
return () => {
|
|
1176
|
+
cancelled = true;
|
|
1177
|
+
};
|
|
1178
|
+
}, [url, base64]);
|
|
1179
|
+
if (loading) {
|
|
1180
|
+
return /* @__PURE__ */ jsx("div", { style: { padding: "24px", color: MUTED2, fontSize: "13px", textAlign: "center" }, children: "Loading\u2026" });
|
|
1181
|
+
}
|
|
1182
|
+
if (error) {
|
|
1183
|
+
return /* @__PURE__ */ jsx("div", { style: { padding: "24px", color: "#dc2626", fontSize: "13px", textAlign: "center" }, children: error });
|
|
1184
|
+
}
|
|
1185
|
+
return /* @__PURE__ */ jsx(
|
|
1186
|
+
"iframe",
|
|
1187
|
+
{
|
|
1188
|
+
title: "HTML preview",
|
|
1189
|
+
sandbox: "",
|
|
1190
|
+
srcDoc: html,
|
|
1191
|
+
style: {
|
|
1192
|
+
width: "100%",
|
|
1193
|
+
height: `${height}px`,
|
|
1194
|
+
border: "none",
|
|
1195
|
+
background: "white",
|
|
1196
|
+
display: "block"
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
);
|
|
1200
|
+
}
|
|
1201
|
+
var init_HtmlViewer = __esm({
|
|
1202
|
+
"src/shared/viewers/HtmlViewer.tsx"() {
|
|
1203
|
+
"use client";
|
|
1204
|
+
init_ThemeContext();
|
|
1205
|
+
init_decode();
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1055
1209
|
// src/shared/ColumnSettingsPanel.tsx
|
|
1056
1210
|
init_ThemeContext();
|
|
1057
1211
|
function ColumnSettingsPanel({ columns, hidden, onToggle, onShowAll, onHideAll }) {
|
|
@@ -1257,7 +1411,7 @@ init_theme();
|
|
|
1257
1411
|
var FAMILIES = [
|
|
1258
1412
|
{ exts: ["csv", "tsv", "xls", "xlsx", "numbers"], fg: SEMANTIC.success.color, bg: SEMANTIC.success.bg },
|
|
1259
1413
|
{ exts: ["pdf"], fg: SEMANTIC.error.color, bg: SEMANTIC.error.bg },
|
|
1260
|
-
{ exts: ["doc", "docx", "txt", "md", "rtf", "pages"], fg: SEMANTIC.info.color, bg: SEMANTIC.info.bg },
|
|
1414
|
+
{ exts: ["doc", "docx", "txt", "md", "rtf", "pages", "html", "htm"], fg: SEMANTIC.info.color, bg: SEMANTIC.info.bg },
|
|
1261
1415
|
{ exts: ["json", "yaml", "yml", "xml", "toml"], fg: SEMANTIC.purple.color, bg: SEMANTIC.purple.bg },
|
|
1262
1416
|
{ exts: ["zip", "tar", "gz", "rar", "7z"], fg: SEMANTIC.warning.color, bg: SEMANTIC.warning.bg },
|
|
1263
1417
|
{ exts: ["png", "jpg", "jpeg", "gif", "svg", "webp", "bmp"], fg: SEMANTIC.info.color, bg: SEMANTIC.info.bg }
|
|
@@ -1284,7 +1438,9 @@ var PREVIEW_EXTS = {
|
|
|
1284
1438
|
txt: "text",
|
|
1285
1439
|
log: "text",
|
|
1286
1440
|
text: "text",
|
|
1287
|
-
docx: "docx"
|
|
1441
|
+
docx: "docx",
|
|
1442
|
+
html: "html",
|
|
1443
|
+
htm: "html"
|
|
1288
1444
|
};
|
|
1289
1445
|
function extOf(fileType, filename) {
|
|
1290
1446
|
var _a;
|
|
@@ -1295,6 +1451,7 @@ function extOf(fileType, filename) {
|
|
|
1295
1451
|
if (mime.includes("csv")) return "csv";
|
|
1296
1452
|
if (mime.includes("markdown")) return "md";
|
|
1297
1453
|
if (mime.includes("wordprocessing") || mime.includes("msword")) return "docx";
|
|
1454
|
+
if (mime.includes("html")) return "html";
|
|
1298
1455
|
if (mime.startsWith("text/")) return "txt";
|
|
1299
1456
|
} else if (fileType) {
|
|
1300
1457
|
const t = fileType.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
@@ -1328,6 +1485,7 @@ function isExpirySoon(expiresAt) {
|
|
|
1328
1485
|
|
|
1329
1486
|
// src/shared/viewers/PreviewHost.tsx
|
|
1330
1487
|
init_ThemeContext();
|
|
1488
|
+
init_pdfWorkerProbe();
|
|
1331
1489
|
var PdfViewer2 = lazy(
|
|
1332
1490
|
() => Promise.resolve().then(() => (init_PdfViewer(), PdfViewer_exports)).then((m) => ({ default: m.PdfViewer }))
|
|
1333
1491
|
);
|
|
@@ -1337,8 +1495,22 @@ var ExcelViewer2 = lazy(
|
|
|
1337
1495
|
var CsvViewer2 = lazy(() => Promise.resolve().then(() => (init_CsvViewer(), CsvViewer_exports)).then((m) => ({ default: m.CsvViewer })));
|
|
1338
1496
|
var TextViewer2 = lazy(() => Promise.resolve().then(() => (init_TextViewer(), TextViewer_exports)).then((m) => ({ default: m.TextViewer })));
|
|
1339
1497
|
var DocxViewer2 = lazy(() => Promise.resolve().then(() => (init_DocxViewer(), DocxViewer_exports)).then((m) => ({ default: m.DocxViewer })));
|
|
1498
|
+
var HtmlViewer2 = lazy(() => Promise.resolve().then(() => (init_HtmlViewer(), HtmlViewer_exports)).then((m) => ({ default: m.HtmlViewer })));
|
|
1340
1499
|
var PEEK_ROWS = 20;
|
|
1341
1500
|
var PEEK_LINES = 40;
|
|
1501
|
+
function GatedPdfViewer({ source }) {
|
|
1502
|
+
const { MUTED: MUTED2 } = useTheme();
|
|
1503
|
+
const [failed, setFailed] = useState(false);
|
|
1504
|
+
const workerReady = usePdfWorkerReady(true);
|
|
1505
|
+
const ready = failed ? false : workerReady;
|
|
1506
|
+
if (ready === null) {
|
|
1507
|
+
return /* @__PURE__ */ jsx("div", { style: { padding: "24px", color: MUTED2, fontSize: "13px", textAlign: "center" }, children: "Loading preview\u2026" });
|
|
1508
|
+
}
|
|
1509
|
+
if (ready === false) {
|
|
1510
|
+
return /* @__PURE__ */ jsx("div", { style: { padding: "24px", color: MUTED2, fontSize: "13px", textAlign: "center" }, children: "Preview unavailable \u2014 download the file to view it." });
|
|
1511
|
+
}
|
|
1512
|
+
return /* @__PURE__ */ jsx(PdfViewer2, { url: source.url, base64: source.base64, onLoadError: () => setFailed(true) });
|
|
1513
|
+
}
|
|
1342
1514
|
function PreviewHost({ kind, source, mode = "full" }) {
|
|
1343
1515
|
const { MUTED: MUTED2 } = useTheme();
|
|
1344
1516
|
const peek = mode === "peek";
|
|
@@ -1346,7 +1518,7 @@ function PreviewHost({ kind, source, mode = "full" }) {
|
|
|
1346
1518
|
let viewer = null;
|
|
1347
1519
|
switch (kind) {
|
|
1348
1520
|
case "pdf":
|
|
1349
|
-
viewer = /* @__PURE__ */ jsx(
|
|
1521
|
+
viewer = /* @__PURE__ */ jsx(GatedPdfViewer, { source });
|
|
1350
1522
|
break;
|
|
1351
1523
|
case "excel":
|
|
1352
1524
|
viewer = /* @__PURE__ */ jsx(ExcelViewer2, { url: source.url, base64: source.base64 });
|
|
@@ -1363,6 +1535,9 @@ function PreviewHost({ kind, source, mode = "full" }) {
|
|
|
1363
1535
|
case "docx":
|
|
1364
1536
|
viewer = /* @__PURE__ */ jsx(DocxViewer2, { url: source.url, base64: source.base64 });
|
|
1365
1537
|
break;
|
|
1538
|
+
case "html":
|
|
1539
|
+
viewer = /* @__PURE__ */ jsx(HtmlViewer2, { url: source.url, base64: source.base64, height: peek ? 240 : 480 });
|
|
1540
|
+
break;
|
|
1366
1541
|
default:
|
|
1367
1542
|
return null;
|
|
1368
1543
|
}
|
|
@@ -1714,7 +1889,7 @@ function FileCard({
|
|
|
1714
1889
|
whiteSpace: "nowrap"
|
|
1715
1890
|
},
|
|
1716
1891
|
children: [
|
|
1717
|
-
metaTokens.map((t, i) => /* @__PURE__ */ jsxs(
|
|
1892
|
+
metaTokens.map((t, i) => /* @__PURE__ */ jsxs(React11.Fragment, { children: [
|
|
1718
1893
|
i > 0 && /* @__PURE__ */ jsx("span", { style: { color: MUTED2 }, children: "\xB7" }),
|
|
1719
1894
|
/* @__PURE__ */ jsx("span", { children: t })
|
|
1720
1895
|
] }, i)),
|