@geomak/ui 7.16.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 CHANGED
@@ -11181,6 +11181,36 @@ 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
+ }
11184
11214
  var INVALID_WS_CHARS = /[:\\/?\*[\]]/g;
11185
11215
  function sanitizeName(name) {
11186
11216
  return name.replace(INVALID_WS_CHARS, "_").slice(0, 31) || "Sheet";
@@ -11189,6 +11219,7 @@ var xlsxPromise2 = null;
11189
11219
  var loadXlsx2 = () => xlsxPromise2 ??= import('xlsx');
11190
11220
  function useExcel() {
11191
11221
  const [isExporting, setIsExporting] = React36.useState(false);
11222
+ const { saveBlob } = useDownload();
11192
11223
  const exportSheets = React36.useCallback(async (sheets, options = {}) => {
11193
11224
  const { fileName = "export", onSave } = options;
11194
11225
  setIsExporting(true);
@@ -11240,12 +11271,12 @@ function useExcel() {
11240
11271
  if (onSave) {
11241
11272
  await onSave(blob, name);
11242
11273
  } else {
11243
- downloadBlob(blob, name);
11274
+ saveBlob(blob, name);
11244
11275
  }
11245
11276
  } finally {
11246
11277
  setIsExporting(false);
11247
11278
  }
11248
- }, []);
11279
+ }, [saveBlob]);
11249
11280
  const readWorkbook = React36.useCallback(async (source) => {
11250
11281
  const XLSX = await loadXlsx2();
11251
11282
  let bytes;
@@ -11281,6 +11312,7 @@ var jspdfPromise2 = null;
11281
11312
  var loadJspdf2 = () => jspdfPromise2 ??= import('jspdf');
11282
11313
  function usePdf() {
11283
11314
  const [isExporting, setIsExporting] = React36.useState(false);
11315
+ const { saveBlob } = useDownload();
11284
11316
  const exportCanvases = React36.useCallback(async (pages, options = {}) => {
11285
11317
  const { fileName = "report", onSave, orientation = "landscape" } = options;
11286
11318
  const validPages = pages.filter((p) => p.canvas.width !== 0 && p.canvas.height !== 0);
@@ -11315,17 +11347,12 @@ function usePdf() {
11315
11347
  if (onSave) {
11316
11348
  await onSave(blob, name);
11317
11349
  } else {
11318
- const url = URL.createObjectURL(blob);
11319
- const a = document.createElement("a");
11320
- a.href = url;
11321
- a.download = name;
11322
- a.click();
11323
- URL.revokeObjectURL(url);
11350
+ saveBlob(blob, name);
11324
11351
  }
11325
11352
  } finally {
11326
11353
  setIsExporting(false);
11327
11354
  }
11328
- }, []);
11355
+ }, [saveBlob]);
11329
11356
  return { exportCanvases, isExporting };
11330
11357
  }
11331
11358
  var GRADIENT = "radial-gradient(ellipse 80% 60% at 50% 0%, color-mix(in oklab, var(--color-accent) 12%, transparent), transparent 70%)";
@@ -12015,6 +12042,7 @@ exports.runFieldRules = runFieldRules;
12015
12042
  exports.scorePassword = scorePassword;
12016
12043
  exports.useBreakpoint = useBreakpoint;
12017
12044
  exports.useCart = useCart;
12045
+ exports.useDownload = useDownload;
12018
12046
  exports.useExcel = useExcel;
12019
12047
  exports.useFieldArray = useFieldArray;
12020
12048
  exports.useForm = useForm;