@geomak/ui 7.15.0 → 7.17.0
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 +177 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -1
- package/dist/index.d.ts +51 -1
- package/dist/index.js +175 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -11181,6 +11181,180 @@ function useJwt(token) {
|
|
|
11181
11181
|
const isValid = decoded.payload != null && !isExpired;
|
|
11182
11182
|
return { payload: decoded.payload, header: decoded.header, expiresAt, isExpired, isValid, raw: token ?? null };
|
|
11183
11183
|
}
|
|
11184
|
+
function useDownload() {
|
|
11185
|
+
const saveBlob = React36.useCallback((blob, fileName) => {
|
|
11186
|
+
if (typeof window === "undefined") return;
|
|
11187
|
+
const url = URL.createObjectURL(blob);
|
|
11188
|
+
const a = document.createElement("a");
|
|
11189
|
+
a.href = url;
|
|
11190
|
+
a.download = fileName;
|
|
11191
|
+
a.click();
|
|
11192
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
11193
|
+
}, []);
|
|
11194
|
+
const saveFromBase64 = React36.useCallback((base64, fileName, mimeType) => {
|
|
11195
|
+
let payload = base64;
|
|
11196
|
+
let inferredMime;
|
|
11197
|
+
if (base64.startsWith("data:")) {
|
|
11198
|
+
const commaIdx = base64.indexOf(",");
|
|
11199
|
+
if (commaIdx !== -1) {
|
|
11200
|
+
const header = base64.slice(5, commaIdx);
|
|
11201
|
+
const semiIdx = header.indexOf(";");
|
|
11202
|
+
if (semiIdx !== -1) inferredMime = header.slice(0, semiIdx);
|
|
11203
|
+
payload = base64.slice(commaIdx + 1);
|
|
11204
|
+
}
|
|
11205
|
+
}
|
|
11206
|
+
const binary = atob(payload);
|
|
11207
|
+
const bytes = new Uint8Array(binary.length);
|
|
11208
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
11209
|
+
const blob = new Blob([bytes], { type: mimeType ?? inferredMime ?? "application/octet-stream" });
|
|
11210
|
+
saveBlob(blob, fileName);
|
|
11211
|
+
}, [saveBlob]);
|
|
11212
|
+
return { saveBlob, saveFromBase64 };
|
|
11213
|
+
}
|
|
11214
|
+
var INVALID_WS_CHARS = /[:\\/?\*[\]]/g;
|
|
11215
|
+
function sanitizeName(name) {
|
|
11216
|
+
return name.replace(INVALID_WS_CHARS, "_").slice(0, 31) || "Sheet";
|
|
11217
|
+
}
|
|
11218
|
+
var xlsxPromise2 = null;
|
|
11219
|
+
var loadXlsx2 = () => xlsxPromise2 ??= import('xlsx');
|
|
11220
|
+
function useExcel() {
|
|
11221
|
+
const [isExporting, setIsExporting] = React36.useState(false);
|
|
11222
|
+
const { saveBlob } = useDownload();
|
|
11223
|
+
const exportSheets = React36.useCallback(async (sheets, options = {}) => {
|
|
11224
|
+
const { fileName = "export", onSave } = options;
|
|
11225
|
+
setIsExporting(true);
|
|
11226
|
+
try {
|
|
11227
|
+
const XLSX = await loadXlsx2();
|
|
11228
|
+
const wb = XLSX.utils.book_new();
|
|
11229
|
+
for (const sheet of sheets) {
|
|
11230
|
+
let headers;
|
|
11231
|
+
if (sheet.columns) {
|
|
11232
|
+
headers = sheet.columns;
|
|
11233
|
+
} else {
|
|
11234
|
+
const seen = /* @__PURE__ */ new Set();
|
|
11235
|
+
for (const row of sheet.rows) {
|
|
11236
|
+
if (!Array.isArray(row)) {
|
|
11237
|
+
for (const k of Object.keys(row)) seen.add(k);
|
|
11238
|
+
}
|
|
11239
|
+
}
|
|
11240
|
+
headers = Array.from(seen);
|
|
11241
|
+
}
|
|
11242
|
+
const aoa = [];
|
|
11243
|
+
if (headers.length > 0) aoa.push(headers);
|
|
11244
|
+
for (const row of sheet.rows) {
|
|
11245
|
+
if (Array.isArray(row)) {
|
|
11246
|
+
aoa.push(row);
|
|
11247
|
+
} else {
|
|
11248
|
+
aoa.push(headers.map((h) => row[h] ?? null));
|
|
11249
|
+
}
|
|
11250
|
+
}
|
|
11251
|
+
const ws = XLSX.utils.aoa_to_sheet(aoa);
|
|
11252
|
+
if (headers.length > 0) {
|
|
11253
|
+
for (let ci = 0; ci < headers.length; ci++) {
|
|
11254
|
+
const addr = XLSX.utils.encode_cell({ r: 0, c: ci });
|
|
11255
|
+
if (ws[addr]) ws[addr].s = { font: { bold: true } };
|
|
11256
|
+
}
|
|
11257
|
+
}
|
|
11258
|
+
const colWidths = headers.map((h) => Math.min(h.length, 40));
|
|
11259
|
+
for (const row of aoa.slice(1)) {
|
|
11260
|
+
row.forEach((cell, ci) => {
|
|
11261
|
+
const len = cell == null ? 0 : String(cell).length;
|
|
11262
|
+
if (len > (colWidths[ci] ?? 0)) colWidths[ci] = Math.min(len, 40);
|
|
11263
|
+
});
|
|
11264
|
+
}
|
|
11265
|
+
ws["!cols"] = colWidths.map((w) => ({ wch: w + 2 }));
|
|
11266
|
+
XLSX.utils.book_append_sheet(wb, ws, sanitizeName(sheet.name));
|
|
11267
|
+
}
|
|
11268
|
+
const out = XLSX.write(wb, { bookType: "xlsx", type: "array" });
|
|
11269
|
+
const blob = new Blob([out], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
|
|
11270
|
+
const name = `${fileName}.xlsx`;
|
|
11271
|
+
if (onSave) {
|
|
11272
|
+
await onSave(blob, name);
|
|
11273
|
+
} else {
|
|
11274
|
+
saveBlob(blob, name);
|
|
11275
|
+
}
|
|
11276
|
+
} finally {
|
|
11277
|
+
setIsExporting(false);
|
|
11278
|
+
}
|
|
11279
|
+
}, [saveBlob]);
|
|
11280
|
+
const readWorkbook = React36.useCallback(async (source) => {
|
|
11281
|
+
const XLSX = await loadXlsx2();
|
|
11282
|
+
let bytes;
|
|
11283
|
+
if (source instanceof Uint8Array) {
|
|
11284
|
+
bytes = source;
|
|
11285
|
+
} else if (source instanceof ArrayBuffer) {
|
|
11286
|
+
bytes = new Uint8Array(source);
|
|
11287
|
+
} else {
|
|
11288
|
+
bytes = new Uint8Array(await source.arrayBuffer());
|
|
11289
|
+
}
|
|
11290
|
+
const wb = XLSX.read(bytes, { type: "array" });
|
|
11291
|
+
return wb.SheetNames.map((name) => {
|
|
11292
|
+
const ws = wb.Sheets[name];
|
|
11293
|
+
const aoa = XLSX.utils.sheet_to_json(ws, { header: 1, blankrows: false, defval: null });
|
|
11294
|
+
if (aoa.length === 0) return { name, rows: [] };
|
|
11295
|
+
const headerRow = aoa[0] ?? [];
|
|
11296
|
+
const headers = headerRow.map(
|
|
11297
|
+
(h, i) => h != null && String(h).length ? String(h) : `col_${i}`
|
|
11298
|
+
);
|
|
11299
|
+
const rows = aoa.slice(1).map((row) => {
|
|
11300
|
+
const rec = {};
|
|
11301
|
+
headers.forEach((h, i) => {
|
|
11302
|
+
rec[h] = row[i] ?? null;
|
|
11303
|
+
});
|
|
11304
|
+
return rec;
|
|
11305
|
+
});
|
|
11306
|
+
return { name, rows };
|
|
11307
|
+
});
|
|
11308
|
+
}, []);
|
|
11309
|
+
return { exportSheets, readWorkbook, isExporting };
|
|
11310
|
+
}
|
|
11311
|
+
var jspdfPromise2 = null;
|
|
11312
|
+
var loadJspdf2 = () => jspdfPromise2 ??= import('jspdf');
|
|
11313
|
+
function usePdf() {
|
|
11314
|
+
const [isExporting, setIsExporting] = React36.useState(false);
|
|
11315
|
+
const { saveBlob } = useDownload();
|
|
11316
|
+
const exportCanvases = React36.useCallback(async (pages, options = {}) => {
|
|
11317
|
+
const { fileName = "report", onSave, orientation = "landscape" } = options;
|
|
11318
|
+
const validPages = pages.filter((p) => p.canvas.width !== 0 && p.canvas.height !== 0);
|
|
11319
|
+
if (validPages.length === 0) return;
|
|
11320
|
+
setIsExporting(true);
|
|
11321
|
+
try {
|
|
11322
|
+
const { jsPDF } = await loadJspdf2();
|
|
11323
|
+
const pdf = new jsPDF({ orientation, unit: "px", compress: true });
|
|
11324
|
+
const pageW = pdf.internal.pageSize.getWidth();
|
|
11325
|
+
const pageH = pdf.internal.pageSize.getHeight();
|
|
11326
|
+
const TITLE_H = 28;
|
|
11327
|
+
for (let i = 0; i < validPages.length; i++) {
|
|
11328
|
+
const { canvas, title } = validPages[i];
|
|
11329
|
+
if (i > 0) pdf.addPage();
|
|
11330
|
+
let contentY = 0;
|
|
11331
|
+
const contentH = title ? pageH - TITLE_H : pageH;
|
|
11332
|
+
if (title) {
|
|
11333
|
+
pdf.setFontSize(12);
|
|
11334
|
+
pdf.setFont("helvetica", "bold");
|
|
11335
|
+
pdf.text(title, pageW / 2, TITLE_H / 2 + 6, { align: "center" });
|
|
11336
|
+
contentY = TITLE_H;
|
|
11337
|
+
}
|
|
11338
|
+
const scale = Math.min(pageW / canvas.width, contentH / canvas.height);
|
|
11339
|
+
const w = canvas.width * scale;
|
|
11340
|
+
const h = canvas.height * scale;
|
|
11341
|
+
const x = (pageW - w) / 2;
|
|
11342
|
+
const y = contentY + (contentH - h) / 2;
|
|
11343
|
+
pdf.addImage(canvas.toDataURL("image/png", 1), "PNG", x, y, w, h);
|
|
11344
|
+
}
|
|
11345
|
+
const blob = pdf.output("blob");
|
|
11346
|
+
const name = `${fileName}.pdf`;
|
|
11347
|
+
if (onSave) {
|
|
11348
|
+
await onSave(blob, name);
|
|
11349
|
+
} else {
|
|
11350
|
+
saveBlob(blob, name);
|
|
11351
|
+
}
|
|
11352
|
+
} finally {
|
|
11353
|
+
setIsExporting(false);
|
|
11354
|
+
}
|
|
11355
|
+
}, [saveBlob]);
|
|
11356
|
+
return { exportCanvases, isExporting };
|
|
11357
|
+
}
|
|
11184
11358
|
var GRADIENT = "radial-gradient(ellipse 80% 60% at 50% 0%, color-mix(in oklab, var(--color-accent) 12%, transparent), transparent 70%)";
|
|
11185
11359
|
function Jumbotron({
|
|
11186
11360
|
eyebrow,
|
|
@@ -11868,6 +12042,8 @@ exports.runFieldRules = runFieldRules;
|
|
|
11868
12042
|
exports.scorePassword = scorePassword;
|
|
11869
12043
|
exports.useBreakpoint = useBreakpoint;
|
|
11870
12044
|
exports.useCart = useCart;
|
|
12045
|
+
exports.useDownload = useDownload;
|
|
12046
|
+
exports.useExcel = useExcel;
|
|
11871
12047
|
exports.useFieldArray = useFieldArray;
|
|
11872
12048
|
exports.useForm = useForm;
|
|
11873
12049
|
exports.useFormField = useFormField;
|
|
@@ -11876,5 +12052,6 @@ exports.useJwt = useJwt;
|
|
|
11876
12052
|
exports.useLocalStorage = useLocalStorage;
|
|
11877
12053
|
exports.useMediaQuery = useMediaQuery;
|
|
11878
12054
|
exports.useNotification = useNotification;
|
|
12055
|
+
exports.usePdf = usePdf;
|
|
11879
12056
|
//# sourceMappingURL=index.cjs.map
|
|
11880
12057
|
//# sourceMappingURL=index.cjs.map
|