@livo-tv/blocks 1.6.0 → 1.7.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
@@ -4783,79 +4783,85 @@ function FileDropzone({
4783
4783
  inputRef.current?.click();
4784
4784
  }
4785
4785
  }
4786
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("grid gap-2", className), children: [
4787
- /* @__PURE__ */ jsxRuntime.jsxs(
4788
- "div",
4789
- {
4790
- role: "button",
4791
- tabIndex: disabled ? -1 : 0,
4792
- "aria-disabled": disabled,
4793
- "aria-describedby": message ? `${inputId}-message` : `${inputId}-hint`,
4794
- "aria-controls": inputId,
4795
- "data-dragging": dragging || void 0,
4796
- className: cn(
4797
- "border-input bg-background focus-visible:border-ring focus-visible:ring-ring/50 rounded-lg border border-dashed px-4 py-8 text-center outline-none focus-visible:ring-[3px]",
4798
- dragging && "border-primary bg-primary/5",
4799
- disabled && "pointer-events-none opacity-50"
4800
- ),
4801
- onClick: () => {
4802
- if (!disabled) inputRef.current?.click();
4803
- },
4804
- onKeyDown,
4805
- onDragEnter: (event) => {
4806
- event.preventDefault();
4807
- if (!disabled) setDragging(true);
4808
- },
4809
- onDragOver: (event) => {
4810
- event.preventDefault();
4811
- },
4812
- onDragLeave: (event) => {
4813
- if (event.currentTarget.contains(event.relatedTarget)) {
4814
- return;
4786
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4787
+ "div",
4788
+ {
4789
+ className: cn("relative flex w-full min-w-0 flex-col gap-2", className),
4790
+ children: [
4791
+ /* @__PURE__ */ jsxRuntime.jsxs(
4792
+ "div",
4793
+ {
4794
+ role: "button",
4795
+ tabIndex: disabled ? -1 : 0,
4796
+ "aria-disabled": disabled,
4797
+ "aria-describedby": message ? `${inputId}-message` : `${inputId}-hint`,
4798
+ "aria-controls": inputId,
4799
+ "data-dragging": dragging || void 0,
4800
+ className: cn(
4801
+ "border-input bg-background focus-visible:border-ring focus-visible:ring-ring/50 w-full min-w-0 rounded-lg border border-dashed px-4 py-8 text-center outline-none focus-visible:ring-[3px]",
4802
+ dragging && "border-primary bg-primary/5",
4803
+ disabled && "pointer-events-none opacity-50"
4804
+ ),
4805
+ onClick: () => {
4806
+ if (!disabled) inputRef.current?.click();
4807
+ },
4808
+ onKeyDown,
4809
+ onDragEnter: (event) => {
4810
+ event.preventDefault();
4811
+ if (!disabled) setDragging(true);
4812
+ },
4813
+ onDragOver: (event) => {
4814
+ event.preventDefault();
4815
+ },
4816
+ onDragLeave: (event) => {
4817
+ if (event.currentTarget.contains(event.relatedTarget)) {
4818
+ return;
4819
+ }
4820
+ setDragging(false);
4821
+ },
4822
+ onDrop,
4823
+ children: [
4824
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: labels.idle }),
4825
+ /* @__PURE__ */ jsxRuntime.jsx(
4826
+ "p",
4827
+ {
4828
+ id: `${inputId}-hint`,
4829
+ className: "text-muted-foreground mt-1 text-xs",
4830
+ children: labels.hint
4831
+ }
4832
+ ),
4833
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-primary mt-3 inline-flex text-sm font-medium underline-offset-4", children: labels.browse })
4834
+ ]
4815
4835
  }
4816
- setDragging(false);
4817
- },
4818
- onDrop,
4819
- children: [
4820
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: labels.idle }),
4821
- /* @__PURE__ */ jsxRuntime.jsx(
4822
- "p",
4823
- {
4824
- id: `${inputId}-hint`,
4825
- className: "text-muted-foreground mt-1 text-xs",
4826
- children: labels.hint
4836
+ ),
4837
+ /* @__PURE__ */ jsxRuntime.jsx(
4838
+ "input",
4839
+ {
4840
+ id: inputId,
4841
+ ref: inputRef,
4842
+ type: "file",
4843
+ accept,
4844
+ disabled,
4845
+ "aria-label": labels.browse,
4846
+ className: "sr-only",
4847
+ onChange: (event) => {
4848
+ takeFile(event.target.files?.[0]);
4849
+ event.target.value = "";
4827
4850
  }
4828
- ),
4829
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-primary mt-3 inline-flex text-sm font-medium underline-offset-4", children: labels.browse })
4830
- ]
4831
- }
4832
- ),
4833
- /* @__PURE__ */ jsxRuntime.jsx(
4834
- "input",
4835
- {
4836
- id: inputId,
4837
- ref: inputRef,
4838
- type: "file",
4839
- accept,
4840
- disabled,
4841
- "aria-label": labels.browse,
4842
- className: "sr-only",
4843
- onChange: (event) => {
4844
- takeFile(event.target.files?.[0]);
4845
- event.target.value = "";
4846
- }
4847
- }
4848
- ),
4849
- message ? /* @__PURE__ */ jsxRuntime.jsx(
4850
- "p",
4851
- {
4852
- id: `${inputId}-message`,
4853
- role: "alert",
4854
- className: "text-destructive text-sm",
4855
- children: message
4856
- }
4857
- ) : null
4858
- ] });
4851
+ }
4852
+ ),
4853
+ message ? /* @__PURE__ */ jsxRuntime.jsx(
4854
+ "p",
4855
+ {
4856
+ id: `${inputId}-message`,
4857
+ role: "alert",
4858
+ className: "text-destructive text-sm",
4859
+ children: message
4860
+ }
4861
+ ) : null
4862
+ ]
4863
+ }
4864
+ );
4859
4865
  }
4860
4866
  function statusLabel(status, labels) {
4861
4867
  switch (status) {
@@ -4888,73 +4894,90 @@ function FileUploadTray({
4888
4894
  const labels = { ...DEFAULT_FILE_UPLOAD_TRAY_LABELS, ...labelOverrides };
4889
4895
  const visible = jobs.filter((job) => job.status !== "cancelled");
4890
4896
  if (visible.length === 0) return null;
4891
- return /* @__PURE__ */ jsxRuntime.jsx("section", { "aria-label": labels.title, className: cn("grid gap-3", className), children: /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid gap-3", children: visible.map((job) => {
4892
- const active = job.status === "uploading" || job.status === "completing";
4893
- const canPause = job.status === "uploading";
4894
- const canResume = job.status === "paused";
4895
- const canCancel = job.status === "uploading" || job.status === "paused" || job.status === "error";
4896
- return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "grid gap-1.5", children: [
4897
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
4898
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "min-w-0 flex-1 truncate text-sm font-medium", children: job.name }),
4899
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: statusLabel(job.status, labels) }),
4900
- canPause ? /* @__PURE__ */ jsxRuntime.jsx(
4901
- Button,
4902
- {
4903
- type: "button",
4904
- variant: "ghost",
4905
- size: "icon-sm",
4906
- "aria-label": `${labels.pause} ${job.name}`,
4907
- onClick: () => onPause(job.id),
4908
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, {})
4909
- }
4910
- ) : null,
4911
- canResume ? /* @__PURE__ */ jsxRuntime.jsx(
4912
- Button,
4913
- {
4914
- type: "button",
4915
- variant: "ghost",
4916
- size: "icon-sm",
4917
- "aria-label": `${labels.resume} ${job.name}`,
4918
- onClick: () => onResume(job.id),
4919
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, {})
4920
- }
4921
- ) : null,
4922
- canCancel ? /* @__PURE__ */ jsxRuntime.jsx(
4923
- Button,
4924
- {
4925
- type: "button",
4926
- variant: "ghost",
4927
- size: "icon-sm",
4928
- "aria-label": `${labels.cancel} ${job.name}`,
4929
- onClick: () => onCancel(job.id),
4930
- children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, {})
4931
- }
4932
- ) : null
4933
- ] }),
4934
- /* @__PURE__ */ jsxRuntime.jsx(
4935
- "div",
4936
- {
4937
- role: "progressbar",
4938
- "aria-valuemin": 0,
4939
- "aria-valuemax": 100,
4940
- "aria-valuenow": job.percent,
4941
- "aria-label": job.name,
4942
- className: "bg-muted h-2 overflow-hidden rounded-full",
4943
- children: /* @__PURE__ */ jsxRuntime.jsx(
4897
+ return /* @__PURE__ */ jsxRuntime.jsx(
4898
+ "section",
4899
+ {
4900
+ "aria-label": labels.title,
4901
+ className: cn("grid min-w-0 gap-3", className),
4902
+ children: /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid min-w-0 gap-3", children: visible.map((job) => {
4903
+ const active = job.status === "uploading" || job.status === "completing";
4904
+ const canPause = job.status === "uploading";
4905
+ const canResume = job.status === "paused";
4906
+ const canCancel = job.status === "uploading" || job.status === "paused" || job.status === "error";
4907
+ return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "grid min-w-0 gap-1.5", children: [
4908
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
4909
+ /* @__PURE__ */ jsxRuntime.jsx(
4910
+ "p",
4911
+ {
4912
+ className: "min-w-0 flex-1 truncate text-sm font-medium",
4913
+ title: job.name,
4914
+ children: job.name
4915
+ }
4916
+ ),
4917
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground shrink-0 text-xs", children: statusLabel(job.status, labels) }),
4918
+ canPause ? /* @__PURE__ */ jsxRuntime.jsx(
4919
+ Button,
4920
+ {
4921
+ type: "button",
4922
+ variant: "ghost",
4923
+ size: "icon-sm",
4924
+ className: "shrink-0",
4925
+ "aria-label": `${labels.pause} ${job.name}`,
4926
+ onClick: () => onPause(job.id),
4927
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, {})
4928
+ }
4929
+ ) : null,
4930
+ canResume ? /* @__PURE__ */ jsxRuntime.jsx(
4931
+ Button,
4932
+ {
4933
+ type: "button",
4934
+ variant: "ghost",
4935
+ size: "icon-sm",
4936
+ className: "shrink-0",
4937
+ "aria-label": `${labels.resume} ${job.name}`,
4938
+ onClick: () => onResume(job.id),
4939
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, {})
4940
+ }
4941
+ ) : null,
4942
+ canCancel ? /* @__PURE__ */ jsxRuntime.jsx(
4943
+ Button,
4944
+ {
4945
+ type: "button",
4946
+ variant: "ghost",
4947
+ size: "icon-sm",
4948
+ className: "shrink-0",
4949
+ "aria-label": `${labels.cancel} ${job.name}`,
4950
+ onClick: () => onCancel(job.id),
4951
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, {})
4952
+ }
4953
+ ) : null
4954
+ ] }),
4955
+ /* @__PURE__ */ jsxRuntime.jsx(
4944
4956
  "div",
4945
4957
  {
4946
- className: cn(
4947
- "bg-primary h-full",
4948
- active && "motion-safe:transition-[width]"
4949
- ),
4950
- style: { width: `${job.percent}%` }
4958
+ role: "progressbar",
4959
+ "aria-valuemin": 0,
4960
+ "aria-valuemax": 100,
4961
+ "aria-valuenow": job.percent,
4962
+ "aria-label": job.name,
4963
+ className: "bg-muted h-2 overflow-hidden rounded-full",
4964
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4965
+ "div",
4966
+ {
4967
+ className: cn(
4968
+ "bg-primary h-full",
4969
+ active && "motion-safe:transition-[width]"
4970
+ ),
4971
+ style: { width: `${job.percent}%` }
4972
+ }
4973
+ )
4951
4974
  }
4952
- )
4953
- }
4954
- ),
4955
- job.error ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", className: "text-destructive text-xs", children: job.error }) : null
4956
- ] }, job.id);
4957
- }) }) });
4975
+ ),
4976
+ job.error ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", className: "text-destructive text-xs", children: job.error }) : null
4977
+ ] }, job.id);
4978
+ }) })
4979
+ }
4980
+ );
4958
4981
  }
4959
4982
  function formatActiveBadge(count) {
4960
4983
  return count > 9 ? "9+" : String(count);
@@ -5007,25 +5030,63 @@ function FileUploadMenu({
5007
5030
  ]
5008
5031
  }
5009
5032
  ) }),
5010
- /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuContent, { align, className: "w-80 p-0", children: [
5011
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between border-b px-4 py-3", children: /* @__PURE__ */ jsxRuntime.jsx("h4", { className: "font-semibold", children: labels.title }) }),
5012
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-h-80 overflow-y-auto p-3", children: /* @__PURE__ */ jsxRuntime.jsx(
5013
- FileUploadTray,
5014
- {
5015
- jobs: visible,
5016
- labels,
5017
- onPause,
5018
- onResume,
5019
- onCancel
5020
- }
5021
- ) })
5022
- ] })
5033
+ /* @__PURE__ */ jsxRuntime.jsxs(
5034
+ DropdownMenuContent,
5035
+ {
5036
+ align,
5037
+ className: "w-80 min-w-0 max-w-[calc(100vw-2rem)] overflow-x-hidden p-0",
5038
+ children: [
5039
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between border-b px-4 py-3", children: /* @__PURE__ */ jsxRuntime.jsx("h4", { className: "font-semibold", children: labels.title }) }),
5040
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "max-h-80 min-w-0 overflow-x-hidden overflow-y-auto p-3", children: /* @__PURE__ */ jsxRuntime.jsx(
5041
+ FileUploadTray,
5042
+ {
5043
+ jobs: visible,
5044
+ labels,
5045
+ onPause,
5046
+ onResume,
5047
+ onCancel
5048
+ }
5049
+ ) })
5050
+ ]
5051
+ }
5052
+ )
5023
5053
  ]
5024
5054
  }
5025
5055
  );
5026
5056
  }
5027
5057
 
5028
5058
  // src/components/upload/createMultipartUploadController.ts
5059
+ var PART_ATTEMPTS = 3;
5060
+ var PART_RETRY_BACKOFF_MS = [500, 1500];
5061
+ function defaultSleep(ms) {
5062
+ return new Promise((resolve) => {
5063
+ setTimeout(resolve, ms);
5064
+ });
5065
+ }
5066
+ function isAbortError(error) {
5067
+ return error instanceof DOMException && error.name === "AbortError";
5068
+ }
5069
+ function isMissingEtagError(error) {
5070
+ return error instanceof Error && error.message.includes("missing ETag");
5071
+ }
5072
+ function isRetryableStatus(status) {
5073
+ return status === 0 || status === 403 || status === 408 || status === 429 || status >= 500;
5074
+ }
5075
+ function putPartFailure(partNumber, status) {
5076
+ return new Error(`Upload failed (part ${partNumber}, status ${status})`);
5077
+ }
5078
+ function parsePutStatus(error) {
5079
+ if (!(error instanceof Error)) return null;
5080
+ const match = error.message.match(/status (\d+)\)$/);
5081
+ if (!match?.[1]) return null;
5082
+ return Number(match[1]);
5083
+ }
5084
+ function isRetryablePutError(error) {
5085
+ if (isAbortError(error) || isMissingEtagError(error)) return false;
5086
+ const status = parsePutStatus(error);
5087
+ if (status === null) return false;
5088
+ return isRetryableStatus(status);
5089
+ }
5029
5090
  function readEtag(xhr) {
5030
5091
  const raw = xhr.getResponseHeader("ETag") ?? xhr.getResponseHeader("etag") ?? "";
5031
5092
  const etag = raw.trim();
@@ -5049,10 +5110,10 @@ function putPart(input) {
5049
5110
  }
5050
5111
  return;
5051
5112
  }
5052
- reject(new Error(`Upload failed (${input.xhr.status})`));
5113
+ reject(putPartFailure(input.partNumber, input.xhr.status));
5053
5114
  };
5054
5115
  input.xhr.onerror = () => {
5055
- reject(new Error("Upload failed"));
5116
+ reject(putPartFailure(input.partNumber, 0));
5056
5117
  };
5057
5118
  input.xhr.onabort = () => {
5058
5119
  reject(new DOMException("The operation was aborted.", "AbortError"));
@@ -5062,8 +5123,9 @@ function putPart(input) {
5062
5123
  }
5063
5124
  function createMultipartUploadController(options) {
5064
5125
  const ranges = partRanges(options.file.size, options.partSize);
5065
- const completed = [];
5126
+ const sleep = options.sleep ?? defaultSleep;
5066
5127
  const state = { status: "idle" };
5128
+ const completed = [];
5067
5129
  let currentXhr = null;
5068
5130
  let run = null;
5069
5131
  let resumeIndex = 0;
@@ -5083,6 +5145,40 @@ function createMultipartUploadController(options) {
5083
5145
  progressFromBytes(completedBytes + currentPartLoaded, options.file.size)
5084
5146
  );
5085
5147
  }
5148
+ async function putPartWithRetry(partNumber, body) {
5149
+ let lastError;
5150
+ for (let attempt = 1; attempt <= PART_ATTEMPTS; attempt += 1) {
5151
+ if (state.status !== "uploading") {
5152
+ throw lastError ?? new DOMException("The operation was aborted.", "AbortError");
5153
+ }
5154
+ const url = await options.adapter.requestPartUrl(partNumber);
5155
+ if (state.status !== "uploading") {
5156
+ throw new DOMException("The operation was aborted.", "AbortError");
5157
+ }
5158
+ const xhr = options.xhrFactory ? options.xhrFactory() : new XMLHttpRequest();
5159
+ currentXhr = xhr;
5160
+ try {
5161
+ return await putPart({
5162
+ url,
5163
+ body,
5164
+ xhr,
5165
+ partNumber,
5166
+ onProgress: (loaded) => emitProgress(loaded)
5167
+ });
5168
+ } catch (error) {
5169
+ lastError = error;
5170
+ if (currentXhr === xhr) currentXhr = null;
5171
+ if (isStopped() || !isRetryablePutError(error) || attempt === PART_ATTEMPTS) {
5172
+ throw error;
5173
+ }
5174
+ const delay = PART_RETRY_BACKOFF_MS[attempt - 1] ?? PART_RETRY_BACKOFF_MS[PART_RETRY_BACKOFF_MS.length - 1];
5175
+ await sleep(delay);
5176
+ } finally {
5177
+ if (currentXhr === xhr) currentXhr = null;
5178
+ }
5179
+ }
5180
+ throw lastError;
5181
+ }
5086
5182
  async function uploadFrom(startIndex) {
5087
5183
  state.status = "uploading";
5088
5184
  for (let index = startIndex; index < ranges.length; index += 1) {
@@ -5090,18 +5186,10 @@ function createMultipartUploadController(options) {
5090
5186
  resumeIndex = index;
5091
5187
  const range = ranges[index];
5092
5188
  if (!range) continue;
5093
- const url = await options.adapter.requestPartUrl(range.partNumber);
5094
- if (state.status !== "uploading") return;
5095
- const xhr = options.xhrFactory ? options.xhrFactory() : new XMLHttpRequest();
5096
- currentXhr = xhr;
5097
5189
  const body = options.file.slice(range.start, range.end);
5098
5190
  try {
5099
- const etag = await putPart({
5100
- url,
5101
- body,
5102
- xhr,
5103
- onProgress: (loaded) => emitProgress(loaded)
5104
- });
5191
+ const etag = await putPartWithRetry(range.partNumber, body);
5192
+ if (state.status !== "uploading") return;
5105
5193
  completed.push({ partNumber: range.partNumber, etag });
5106
5194
  emitProgress(0);
5107
5195
  } catch (error) {
@@ -5109,8 +5197,6 @@ function createMultipartUploadController(options) {
5109
5197
  if (isStopped()) return;
5110
5198
  state.status = "error";
5111
5199
  throw error;
5112
- } finally {
5113
- if (currentXhr === xhr) currentXhr = null;
5114
5200
  }
5115
5201
  }
5116
5202
  if (state.status !== "uploading") return;