@livo-tv/blocks 1.7.0 → 1.8.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.d.cts CHANGED
@@ -977,6 +977,7 @@ type CreateMultipartUploadControllerOptions = {
977
977
  onProgress?: (progress: UploadProgress) => void;
978
978
  xhrFactory?: () => XMLHttpRequest;
979
979
  sleep?: (ms: number) => Promise<void>;
980
+ completedParts?: MultipartUploadPart[];
980
981
  };
981
982
  type MultipartUploadController = {
982
983
  start: () => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -977,6 +977,7 @@ type CreateMultipartUploadControllerOptions = {
977
977
  onProgress?: (progress: UploadProgress) => void;
978
978
  xhrFactory?: () => XMLHttpRequest;
979
979
  sleep?: (ms: number) => Promise<void>;
980
+ completedParts?: MultipartUploadPart[];
980
981
  };
981
982
  type MultipartUploadController = {
982
983
  start: () => Promise<void>;
package/dist/index.js CHANGED
@@ -4669,6 +4669,24 @@ function partRanges(fileSize, partSize) {
4669
4669
  };
4670
4670
  });
4671
4671
  }
4672
+ var BYTE_UNITS = ["B", "KB", "MB", "GB", "TB"];
4673
+ function formatUploadBytes(bytes) {
4674
+ if (!Number.isFinite(bytes) || bytes <= 0) {
4675
+ return "0 B";
4676
+ }
4677
+ let value = bytes;
4678
+ let unit = 0;
4679
+ while (value >= 1024 && unit < BYTE_UNITS.length - 1) {
4680
+ value /= 1024;
4681
+ unit += 1;
4682
+ }
4683
+ if (unit === 0 || value >= 10) {
4684
+ return `${Math.round(value)} ${BYTE_UNITS[unit]}`;
4685
+ }
4686
+ const tenths = Math.round(value * 10) / 10;
4687
+ const label = Number.isInteger(tenths) ? String(tenths) : tenths.toFixed(1);
4688
+ return `${label} ${BYTE_UNITS[unit]}`;
4689
+ }
4672
4690
  function progressFromBytes(loaded, total) {
4673
4691
  const safeTotal = Math.max(0, total);
4674
4692
  const safeLoaded = Math.min(Math.max(0, loaded), safeTotal);
@@ -4857,6 +4875,9 @@ function statusLabel(status, labels) {
4857
4875
  }
4858
4876
  }
4859
4877
  }
4878
+ function progressLabel(job) {
4879
+ return `${job.percent}% \xB7 ${formatUploadBytes(job.loaded)} / ${formatUploadBytes(job.total)}`;
4880
+ }
4860
4881
  function FileUploadTray({
4861
4882
  jobs,
4862
4883
  labels: labelOverrides,
@@ -4879,16 +4900,18 @@ function FileUploadTray({
4879
4900
  const canResume = job.status === "paused";
4880
4901
  const canCancel = job.status === "uploading" || job.status === "paused" || job.status === "error";
4881
4902
  return /* @__PURE__ */ jsxs("li", { className: "grid min-w-0 gap-1.5", children: [
4903
+ /* @__PURE__ */ jsx(
4904
+ "p",
4905
+ {
4906
+ className: "h-[3lh] min-w-0 line-clamp-3 text-sm leading-5 font-medium break-all",
4907
+ title: job.name,
4908
+ children: job.name
4909
+ }
4910
+ ),
4882
4911
  /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
4883
- /* @__PURE__ */ jsx(
4884
- "p",
4885
- {
4886
- className: "min-w-0 flex-1 truncate text-sm font-medium",
4887
- title: job.name,
4888
- children: job.name
4889
- }
4890
- ),
4891
4912
  /* @__PURE__ */ jsx("p", { className: "text-muted-foreground shrink-0 text-xs", children: statusLabel(job.status, labels) }),
4913
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground shrink-0 text-xs tabular-nums", children: progressLabel(job) }),
4914
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1" }),
4892
4915
  canPause ? /* @__PURE__ */ jsx(
4893
4916
  Button,
4894
4917
  {
@@ -5099,10 +5122,19 @@ function createMultipartUploadController(options) {
5099
5122
  const ranges = partRanges(options.file.size, options.partSize);
5100
5123
  const sleep = options.sleep ?? defaultSleep;
5101
5124
  const state = { status: "idle" };
5102
- const completed = [];
5125
+ const seeded = /* @__PURE__ */ new Map();
5126
+ for (const part of options.completedParts ?? []) {
5127
+ if (part.partNumber < 1 || part.partNumber > ranges.length) continue;
5128
+ seeded.set(part.partNumber, part);
5129
+ }
5130
+ const completed = [...seeded.values()].sort(
5131
+ (left, right) => left.partNumber - right.partNumber
5132
+ );
5133
+ const done = new Set(completed.map((part) => part.partNumber));
5103
5134
  let currentXhr = null;
5104
5135
  let run = null;
5105
- let resumeIndex = 0;
5136
+ let resumeIndex = ranges.findIndex((range) => !done.has(range.partNumber));
5137
+ if (resumeIndex < 0) resumeIndex = ranges.length;
5106
5138
  function currentStatus() {
5107
5139
  return state.status;
5108
5140
  }
@@ -5160,11 +5192,13 @@ function createMultipartUploadController(options) {
5160
5192
  resumeIndex = index;
5161
5193
  const range = ranges[index];
5162
5194
  if (!range) continue;
5195
+ if (done.has(range.partNumber)) continue;
5163
5196
  const body = options.file.slice(range.start, range.end);
5164
5197
  try {
5165
5198
  const etag = await putPartWithRetry(range.partNumber, body);
5166
5199
  if (state.status !== "uploading") return;
5167
5200
  completed.push({ partNumber: range.partNumber, etag });
5201
+ done.add(range.partNumber);
5168
5202
  emitProgress(0);
5169
5203
  } catch (error) {
5170
5204
  currentXhr = null;
@@ -5181,7 +5215,8 @@ function createMultipartUploadController(options) {
5181
5215
  }
5182
5216
  async function start() {
5183
5217
  if (run) return run;
5184
- run = uploadFrom(0).catch((error) => {
5218
+ emitProgress(0);
5219
+ run = uploadFrom(resumeIndex).catch((error) => {
5185
5220
  if (isStopped()) return;
5186
5221
  state.status = "error";
5187
5222
  throw error;