sanity-plugin-mux-input 2.3.5 → 2.4.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.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { useClient as useClient$1, createHookFromObservableFactory, useDocumentStore, collate, useDocumentValues, truncateString, useFormattedDuration, SanityDefaultPreview, useTimeAgo, TextWithTone, isRecord, getPreviewStateObservable, getPreviewValueWithFallback, DocumentPreviewPresence, useDocumentPreviewStore, useSchema, useDocumentPresence, PreviewCard, isReference, useProjectId, useDataset, PatchEvent, unset, setIfMissing, set, LinearProgress, FormField as FormField$2, definePlugin } from "sanity";
2
2
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
3
3
  import { ErrorOutlineIcon, RetrieveIcon, RetryIcon, CheckmarkCircleIcon, SortIcon, WarningOutlineIcon, EditIcon, PublishIcon, DocumentIcon, TrashIcon, CheckmarkIcon, RevertIcon, SearchIcon, ClockIcon, CropIcon, CalendarIcon, TagIcon, LockIcon, PlayIcon, PlugIcon, UploadIcon, ResetIcon, EllipsisHorizontalIcon, TranslateIcon, DocumentVideoIcon } from "@sanity/icons";
4
- import { Card, Box, Spinner, Stack, Text, Checkbox, Button, Dialog, Flex, Heading, Code, MenuButton, Menu, MenuItem, Tooltip, Inline, useToast, TabList, Tab, TabPanel, TextInput, Label as Label$1, Grid, useClickOutside, Popover, MenuDivider, Autocomplete, Radio, rem } from "@sanity/ui";
5
- import React, { useState, useMemo, useEffect, useRef, useId, memo, isValidElement, useCallback, useReducer, createElement, forwardRef, Suspense } from "react";
4
+ import { Card, Box, Spinner, Stack, Text, Checkbox, Button, Dialog, Flex, Heading, Code, MenuButton, Menu, MenuItem, Tooltip, Inline, useToast, TabList, Tab, TabPanel, TextInput, Label as Label$1, Grid, useClickOutsideEvent, Popover, MenuDivider, Autocomplete, Radio, rem } from "@sanity/ui";
5
+ import React, { useState, useMemo, useEffect, useRef, useId, memo, isValidElement, useCallback, useReducer, PureComponent, createElement, forwardRef, Suspense } from "react";
6
6
  import compact from "lodash/compact.js";
7
7
  import toLower from "lodash/toLower.js";
8
8
  import trim from "lodash/trim.js";
@@ -18,10 +18,9 @@ import { usePaneRouter } from "sanity/desk";
18
18
  import { IntentLink } from "sanity/router";
19
19
  import isNumber from "lodash/isNumber.js";
20
20
  import isString from "lodash/isString.js";
21
- import { useMemoObservable } from "react-rx";
21
+ import { useObservable } from "react-rx";
22
22
  import useSWR from "swr";
23
23
  import scrollIntoView from "scroll-into-view-if-needed";
24
- import { useErrorBoundary } from "use-error-boundary";
25
24
  import { UpChunk } from "@mux/upchunk";
26
25
  import { isValidElementType } from "react-is";
27
26
  import LanguagesList from "iso-639-1";
@@ -144,7 +143,7 @@ function accumulateIntermediateState(currentState, pageResult) {
144
143
  ...currentData,
145
144
  ...("data" in pageResult && pageResult.data || []).filter(
146
145
  // De-duplicate assets for safety
147
- (asset) => !currentData.some((a) => a.id === asset.id)
146
+ (asset) => !currentData.some((a2) => a2.id === asset.id)
148
147
  )
149
148
  ],
150
149
  error: "error" in pageResult ? pageResult.error : (
@@ -196,28 +195,27 @@ const name = "mux-input", cacheNs = "sanity-plugin-mux-input", muxSecretsDocumen
196
195
  path$1
197
196
  ), cache = useMemo(() => {
198
197
  const exists = !!value, secrets = {
199
- token: (value == null ? void 0 : value.token) || null,
200
- secretKey: (value == null ? void 0 : value.secretKey) || null,
201
- enableSignedUrls: (value == null ? void 0 : value.enableSignedUrls) || !1,
202
- signingKeyId: (value == null ? void 0 : value.signingKeyId) || null,
203
- signingKeyPrivate: (value == null ? void 0 : value.signingKeyPrivate) || null
198
+ token: value?.token || null,
199
+ secretKey: value?.secretKey || null,
200
+ enableSignedUrls: value?.enableSignedUrls || !1,
201
+ signingKeyId: value?.signingKeyId || null,
202
+ signingKeyPrivate: value?.signingKeyPrivate || null
204
203
  };
205
204
  return {
206
205
  isInitialSetup: !exists,
207
- needsSetup: !(secrets != null && secrets.token) || !(secrets != null && secrets.secretKey),
206
+ needsSetup: !secrets?.token || !secrets?.secretKey,
208
207
  secrets
209
208
  };
210
209
  }, [value]);
211
210
  return { error, isLoading, value: cache };
212
211
  };
213
212
  function useImportMuxAssets() {
214
- var _a;
215
213
  const documentStore = useDocumentStore(), client = useClient$1({
216
214
  apiVersion: SANITY_API_VERSION
217
- }), [assetsInSanity, assetsInSanityLoading] = useAssetsInSanity(documentStore), secretDocumentValues = useSecretsDocumentValues(), hasSecrets = !!((_a = secretDocumentValues.value.secrets) != null && _a.secretKey), [importError, setImportError] = useState(), [importState, setImportState] = useState("closed"), dialogOpen = importState !== "closed", muxAssets = useMuxAssets({
215
+ }), [assetsInSanity, assetsInSanityLoading] = useAssetsInSanity(documentStore), secretDocumentValues = useSecretsDocumentValues(), hasSecrets = !!secretDocumentValues.value.secrets?.secretKey, [importError, setImportError] = useState(), [importState, setImportState] = useState("closed"), dialogOpen = importState !== "closed", muxAssets = useMuxAssets({
218
216
  secrets: secretDocumentValues.value.secrets,
219
217
  enabled: hasSecrets && dialogOpen
220
- }), missingAssets = useMemo(() => assetsInSanity && muxAssets.data ? muxAssets.data.filter((a) => !assetExistsInSanity(a, assetsInSanity)) : void 0, [assetsInSanity, muxAssets.data]), [selectedAssets, setSelectedAssets] = useState([]), closeDialog = () => {
218
+ }), missingAssets = useMemo(() => assetsInSanity && muxAssets.data ? muxAssets.data.filter((a2) => !assetExistsInSanity(a2, assetsInSanity)) : void 0, [assetsInSanity, muxAssets.data]), [selectedAssets, setSelectedAssets] = useState([]), closeDialog = () => {
221
219
  importState !== "importing" && setImportState("closed");
222
220
  }, openDialog = () => {
223
221
  importState === "closed" && setImportState("idle");
@@ -248,8 +246,7 @@ function useImportMuxAssets() {
248
246
  };
249
247
  }
250
248
  function muxAssetToSanityDocument(asset) {
251
- var _a;
252
- const playbackId = (_a = (asset.playback_ids || []).find((p) => p.id)) == null ? void 0 : _a.id;
249
+ const playbackId = (asset.playback_ids || []).find((p) => p.id)?.id;
253
250
  if (playbackId)
254
251
  return {
255
252
  _id: uuid(),
@@ -286,9 +283,8 @@ function useInView(options = {}) {
286
283
  return useEffect(() => {
287
284
  if (!ref.current) return;
288
285
  const observer = new IntersectionObserver(([entry], obs) => {
289
- var _a;
290
286
  const nowInView = entry.isIntersecting && obs.thresholds.some((threshold) => entry.intersectionRatio >= threshold);
291
- setInView(nowInView), (_a = options == null ? void 0 : options.onChange) == null || _a.call(options, nowInView);
287
+ setInView(nowInView), options?.onChange?.(nowInView);
292
288
  }, options), toObserve = ref.current;
293
289
  return observer.observe(toObserve), () => {
294
290
  toObserve && observer.unobserve(toObserve);
@@ -311,11 +307,11 @@ function readSecrets(client) {
311
307
  { _id }
312
308
  );
313
309
  return {
314
- token: (data == null ? void 0 : data.token) || null,
315
- secretKey: (data == null ? void 0 : data.secretKey) || null,
316
- enableSignedUrls: !!(data != null && data.enableSignedUrls) || !1,
317
- signingKeyId: (data == null ? void 0 : data.signingKeyId) || null,
318
- signingKeyPrivate: (data == null ? void 0 : data.signingKeyPrivate) || null
310
+ token: data?.token || null,
311
+ secretKey: data?.secretKey || null,
312
+ enableSignedUrls: !!data?.enableSignedUrls || !1,
313
+ signingKeyId: data?.signingKeyId || null,
314
+ signingKeyPrivate: data?.signingKeyPrivate || null
319
315
  };
320
316
  }, [cacheNs, _id, projectId, dataset]);
321
317
  }
@@ -327,7 +323,7 @@ function generateJwt(client, playbackId, aud, payload) {
327
323
  throw new TypeError("Missing `signingKeyPrivate`.\n Check your plugin's configuration");
328
324
  const { default: sign } = suspend(() => import("jsonwebtoken-esm/sign"), ["jsonwebtoken-esm/sign"]);
329
325
  return sign(
330
- payload ? JSON.parse(JSON.stringify(payload, (_, v) => v != null ? v : void 0)) : {},
326
+ payload ? JSON.parse(JSON.stringify(payload, (_, v) => v ?? void 0)) : {},
331
327
  atob(signingKeyPrivate),
332
328
  {
333
329
  algorithm: "RS256",
@@ -340,13 +336,12 @@ function generateJwt(client, playbackId, aud, payload) {
340
336
  );
341
337
  }
342
338
  function getPlaybackId(asset) {
343
- if (!(asset != null && asset.playbackId))
339
+ if (!asset?.playbackId)
344
340
  throw console.error("Asset is missing a playbackId", { asset }), new TypeError("Missing playbackId");
345
341
  return asset.playbackId;
346
342
  }
347
343
  function getPlaybackPolicy(asset) {
348
- var _a, _b, _c, _d;
349
- return (_d = (_c = (_b = (_a = asset.data) == null ? void 0 : _a.playback_ids) == null ? void 0 : _b[0]) == null ? void 0 : _c.policy) != null ? _d : "public";
344
+ return asset.data?.playback_ids?.find((playbackId) => asset.playbackId === playbackId.id)?.policy ?? "public";
350
345
  }
351
346
  function getAnimatedPosterSrc({
352
347
  asset,
@@ -359,7 +354,7 @@ function getAnimatedPosterSrc({
359
354
  }) {
360
355
  const params = { height, width, start, end, fps }, playbackId = getPlaybackId(asset);
361
356
  let searchParams = new URLSearchParams(
362
- JSON.parse(JSON.stringify(params, (_, v) => v != null ? v : void 0))
357
+ JSON.parse(JSON.stringify(params, (_, v) => v ?? void 0))
363
358
  );
364
359
  if (getPlaybackPolicy(asset) === "signed") {
365
360
  const token = generateJwt(client, playbackId, "g", params);
@@ -390,7 +385,7 @@ function VideoThumbnail({
390
385
  status !== "error" && setStatus("error");
391
386
  return;
392
387
  }
393
- }, [asset, client, width, status, setStatus]);
388
+ }, [asset, client, posterWidth, status]);
394
389
  function handleLoad() {
395
390
  setStatus("loaded");
396
391
  }
@@ -475,7 +470,6 @@ function MissingAsset({
475
470
  selectAsset,
476
471
  selected
477
472
  }) {
478
- var _a;
479
473
  const duration = useFormattedDuration(asset.duration * 1e3);
480
474
  return /* @__PURE__ */ jsx(
481
475
  Card,
@@ -504,7 +498,7 @@ function MissingAsset({
504
498
  assetId: asset.id,
505
499
  data: asset,
506
500
  filename: asset.id,
507
- playbackId: (_a = asset.playback_ids.find((p) => p.id)) == null ? void 0 : _a.id
501
+ playbackId: asset.playback_ids.find((p) => p.id)?.id
508
502
  },
509
503
  width: 150
510
504
  }
@@ -535,8 +529,7 @@ function MissingAsset({
535
529
  );
536
530
  }
537
531
  function ImportVideosDialog(props) {
538
- var _a, _b;
539
- const { importState } = props, canTriggerImport = (importState === "idle" || importState === "error") && props.selectedAssets.length > 0, isImporting = importState === "importing", noAssetsToImport = ((_a = props.missingAssets) == null ? void 0 : _a.length) === 0 && !props.muxAssets.loading && !props.assetsInSanityLoading;
532
+ const { importState } = props, canTriggerImport = (importState === "idle" || importState === "error") && props.selectedAssets.length > 0, isImporting = importState === "importing", noAssetsToImport = props.missingAssets?.length === 0 && !props.muxAssets.loading && !props.assetsInSanityLoading;
540
533
  return /* @__PURE__ */ jsx(
541
534
  Dialog,
542
535
  {
@@ -568,7 +561,7 @@ function ImportVideosDialog(props) {
568
561
  fontSize: 2,
569
562
  padding: 3,
570
563
  mode: "ghost",
571
- text: ((_b = props.selectedAssets) == null ? void 0 : _b.length) > 0 ? `Import ${props.selectedAssets.length} video(s)` : "No video(s) selected",
564
+ text: props.selectedAssets?.length > 0 ? `Import ${props.selectedAssets.length} video(s)` : "No video(s) selected",
572
565
  tone: "positive",
573
566
  onClick: props.importAssets,
574
567
  iconRight: isImporting && Spinner,
@@ -654,9 +647,9 @@ function ImportVideosDialog(props) {
654
647
  {
655
648
  asset,
656
649
  selectAsset: (selected) => {
657
- selected ? props.setSelectedAssets([...props.selectedAssets, asset]) : props.setSelectedAssets(props.selectedAssets.filter((a) => a.id !== asset.id));
650
+ selected ? props.setSelectedAssets([...props.selectedAssets, asset]) : props.setSelectedAssets(props.selectedAssets.filter((a2) => a2.id !== asset.id));
658
651
  },
659
- selected: props.selectedAssets.some((a) => a.id === asset.id)
652
+ selected: props.selectedAssets.some((a2) => a2.id === asset.id)
660
653
  },
661
654
  asset.id
662
655
  ))
@@ -774,10 +767,9 @@ function VideoPlayer({
774
767
  children,
775
768
  ...props
776
769
  }) {
777
- var _a, _b;
778
770
  const client = useClient(), isAudio = assetIsAudio(asset), { src: videoSrc, error } = useMemo(() => {
779
771
  try {
780
- const src = (asset == null ? void 0 : asset.playbackId) && getVideoSrc({ client, asset });
772
+ const src = asset?.playbackId && getVideoSrc({ client, asset });
781
773
  return src ? { src } : { error: new TypeError("Asset has no playback ID") };
782
774
  } catch (error2) {
783
775
  return { error: error2 };
@@ -788,7 +780,7 @@ function VideoPlayer({
788
780
  } catch {
789
781
  return !1;
790
782
  }
791
- }, [videoSrc]), [width, height] = ((_b = (_a = asset == null ? void 0 : asset.data) == null ? void 0 : _a.aspect_ratio) != null ? _b : "16:9").split(":").map(Number), targetAspectRatio = props.forceAspectRatio || (Number.isNaN(width) ? 16 / 9 : width / height);
783
+ }, [videoSrc]), [width, height] = (asset?.data?.aspect_ratio ?? "16:9").split(":").map(Number), targetAspectRatio = props.forceAspectRatio || (Number.isNaN(width) ? 16 / 9 : width / height);
792
784
  let aspectRatio = Math.max(MIN_ASPECT_RATIO, targetAspectRatio);
793
785
  return isAudio && (aspectRatio = props.forceAspectRatio ? (
794
786
  // Make it wider when forcing aspect ratio to balance with videos' rendering height (audio players overflow a bit)
@@ -806,7 +798,7 @@ function VideoPlayer({
806
798
  crossOrigin: "anonymous",
807
799
  metadata: {
808
800
  player_name: "Sanity Admin Dashboard",
809
- player_version: "2.3.5",
801
+ player_version: "2.4.0",
810
802
  page_type: "Preview Player"
811
803
  },
812
804
  audio: isAudio,
@@ -839,8 +831,7 @@ function VideoPlayer({
839
831
  ] });
840
832
  }
841
833
  function assetIsAudio(asset) {
842
- var _a;
843
- return ((_a = asset.data) == null ? void 0 : _a.max_stored_resolution) === "Audio only";
834
+ return asset.data?.max_stored_resolution === "Audio only";
844
835
  }
845
836
  function deleteAssetOnMux(client, assetId) {
846
837
  const { dataset } = client.config();
@@ -855,13 +846,13 @@ async function deleteAsset({
855
846
  asset,
856
847
  deleteOnMux
857
848
  }) {
858
- if (!(asset != null && asset._id)) return !0;
849
+ if (!asset?._id) return !0;
859
850
  try {
860
851
  await client.delete(asset._id);
861
852
  } catch {
862
853
  return "failed-sanity";
863
854
  }
864
- if (deleteOnMux && asset != null && asset.assetId)
855
+ if (deleteOnMux && asset?.assetId)
865
856
  try {
866
857
  await deleteAssetOnMux(client, asset.assetId);
867
858
  } catch {
@@ -930,10 +921,14 @@ function PublishedStatus(props) {
930
921
  );
931
922
  }
932
923
  function PaneItemPreview(props) {
933
- const { icon, layout, presence, schemaType, value } = props, title = isRecord(value.title) && isValidElement(value.title) || isString(value.title) || isNumber(value.title) ? value.title : null, { draft, published, isLoading } = useMemoObservable(
924
+ const { icon, layout, presence, schemaType, value } = props, title = isRecord(value.title) && isValidElement(value.title) || isString(value.title) || isNumber(value.title) ? value.title : null, observable = useMemo(
934
925
  () => getPreviewStateObservable(props.documentPreviewStore, schemaType, value._id, title),
935
- [props.documentPreviewStore, schemaType, value._id, title]
936
- ), status = isLoading ? null : /* @__PURE__ */ jsxs(Inline, { space: 4, children: [
926
+ [props.documentPreviewStore, schemaType, title, value._id]
927
+ ), { draft, published, isLoading } = useObservable(observable, {
928
+ draft: null,
929
+ published: null,
930
+ isLoading: !0
931
+ }), status = isLoading ? null : /* @__PURE__ */ jsxs(Inline, { space: 4, children: [
937
932
  presence && presence.length > 0 && /* @__PURE__ */ jsx(DocumentPreviewPresence, { presence }),
938
933
  /* @__PURE__ */ jsx(PublishedStatus, { document: published }),
939
934
  /* @__PURE__ */ jsx(DraftStatus, { document: draft })
@@ -967,7 +962,7 @@ function DocumentPreviewInRool(props) {
967
962
  return (linkProps) => /* @__PURE__ */ jsx(IntentLink, { intent: "edit", params: { id: props.documentPair.id }, children: linkProps.children });
968
963
  }
969
964
  function DocumentPreview(props) {
970
- const { schemaType, documentPair } = props, doc = (documentPair == null ? void 0 : documentPair.draft) || (documentPair == null ? void 0 : documentPair.published), id = documentPair.id || "", documentPreviewStore = useDocumentPreviewStore(), schema = useSchema(), documentPresence = useDocumentPresence(id), hasSchemaType = !!(schemaType && schemaType.name && schema.get(schemaType.name)), PreviewComponent = useMemo(() => doc ? !schemaType || !hasSchemaType ? /* @__PURE__ */ jsx(MissingSchemaType, { value: doc }) : /* @__PURE__ */ jsx(
965
+ const { schemaType, documentPair } = props, doc = documentPair?.draft || documentPair?.published, id = documentPair.id || "", documentPreviewStore = useDocumentPreviewStore(), schema = useSchema(), documentPresence = useDocumentPresence(id), hasSchemaType = !!(schemaType && schemaType.name && schema.get(schemaType.name)), PreviewComponent = useMemo(() => doc ? !schemaType || !hasSchemaType ? /* @__PURE__ */ jsx(MissingSchemaType, { value: doc }) : /* @__PURE__ */ jsx(
971
966
  PaneItemPreview,
972
967
  {
973
968
  documentPreviewStore,
@@ -1003,14 +998,13 @@ const Container = styled(Box)`
1003
998
  font-size: ${(props) => props.theme.sanity.fonts.text.sizes[1]};
1004
999
  }
1005
1000
  `, VideoReferences = (props) => {
1006
- var _a;
1007
1001
  const schema = useSchema();
1008
1002
  if (!props.isLoaded)
1009
1003
  return /* @__PURE__ */ jsx(SpinnerBox, {});
1010
- if (!((_a = props.references) != null && _a.length))
1004
+ if (!props.references?.length)
1011
1005
  return /* @__PURE__ */ jsx(Card, { border: !0, radius: 3, padding: 3, children: /* @__PURE__ */ jsx(Text, { size: 2, children: "No documents are using this video" }) });
1012
1006
  const documentPairs = collate(props.references || []);
1013
- return /* @__PURE__ */ jsx(Container, { children: documentPairs == null ? void 0 : documentPairs.map((documentPair) => {
1007
+ return /* @__PURE__ */ jsx(Container, { children: documentPairs?.map((documentPair) => {
1014
1008
  const schemaType = schema.get(documentPair.type);
1015
1009
  return /* @__PURE__ */ jsx(
1016
1010
  Card,
@@ -1043,7 +1037,7 @@ function DeleteDialog({
1043
1037
  }) {
1044
1038
  const client = useClient(), [state, setState] = useState("checkingReferences"), [deleteOnMux, setDeleteOnMux] = useState(!0), toast = useToast();
1045
1039
  useEffect(() => {
1046
- state !== "checkingReferences" || referencesLoading || setState(references != null && references.length ? "cantDelete" : "confirm");
1040
+ state !== "checkingReferences" || referencesLoading || setState(references?.length ? "cantDelete" : "confirm");
1047
1041
  }, [state, references, referencesLoading]);
1048
1042
  async function confirmDelete() {
1049
1043
  if (state !== "confirm") return;
@@ -1085,7 +1079,7 @@ function DeleteDialog({
1085
1079
  /* @__PURE__ */ jsx(Heading, { size: 2, children: "Video can't be deleted" }),
1086
1080
  /* @__PURE__ */ jsxs(Text, { size: 2, style: { marginBottom: "2rem" }, children: [
1087
1081
  "There are ",
1088
- references == null ? void 0 : references.length,
1082
+ references?.length,
1089
1083
  " document",
1090
1084
  references && references.length > 0 && "s",
1091
1085
  " ",
@@ -1164,16 +1158,16 @@ function formatSeconds(seconds) {
1164
1158
  return hrs > 0 && (ret += "" + hrs + ":" + (mins < 10 ? "0" : "")), ret += "" + mins + ":" + (secs < 10 ? "0" : ""), ret += "" + secs, ret;
1165
1159
  }
1166
1160
  function getVideoMetadata(doc) {
1167
- var _a, _b, _c, _d, _e, _f;
1168
- const id = doc.assetId || doc._id || "", date = (_a = doc.data) != null && _a.created_at ? new Date(Number(doc.data.created_at) * 1e3) : new Date(doc._createdAt || doc._updatedAt || Date.now());
1161
+ const id = doc.assetId || doc._id || "", date = doc.data?.created_at ? new Date(Number(doc.data.created_at) * 1e3) : new Date(doc._createdAt || doc._updatedAt || Date.now());
1169
1162
  return {
1170
1163
  title: doc.filename || id.slice(0, 12),
1171
1164
  id,
1165
+ playbackId: doc.playbackId,
1172
1166
  createdAt: date,
1173
- duration: (_b = doc.data) != null && _b.duration ? formatSeconds((_c = doc.data) == null ? void 0 : _c.duration) : void 0,
1174
- aspect_ratio: (_d = doc.data) == null ? void 0 : _d.aspect_ratio,
1175
- max_stored_resolution: (_e = doc.data) == null ? void 0 : _e.max_stored_resolution,
1176
- max_stored_frame_rate: (_f = doc.data) == null ? void 0 : _f.max_stored_frame_rate
1167
+ duration: doc.data?.duration ? formatSeconds(doc.data?.duration) : void 0,
1168
+ aspect_ratio: doc.data?.aspect_ratio,
1169
+ max_stored_resolution: doc.data?.max_stored_resolution,
1170
+ max_stored_frame_rate: doc.data?.max_stored_frame_rate
1177
1171
  };
1178
1172
  }
1179
1173
  function useVideoDetails(props) {
@@ -1412,7 +1406,7 @@ const AssetInput = (props) => /* @__PURE__ */ jsx(FormField$1, { title: props.la
1412
1406
  }
1413
1407
  ),
1414
1408
  /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
1415
- (displayInfo == null ? void 0 : displayInfo.duration) && /* @__PURE__ */ jsx(
1409
+ displayInfo?.duration && /* @__PURE__ */ jsx(
1416
1410
  IconInfo,
1417
1411
  {
1418
1412
  text: `Duration: ${displayInfo.duration}`,
@@ -1420,7 +1414,7 @@ const AssetInput = (props) => /* @__PURE__ */ jsx(FormField$1, { title: props.la
1420
1414
  size: 2
1421
1415
  }
1422
1416
  ),
1423
- (displayInfo == null ? void 0 : displayInfo.max_stored_resolution) && /* @__PURE__ */ jsx(
1417
+ displayInfo?.max_stored_resolution && /* @__PURE__ */ jsx(
1424
1418
  IconInfo,
1425
1419
  {
1426
1420
  text: `Max Resolution: ${displayInfo.max_stored_resolution}`,
@@ -1428,7 +1422,7 @@ const AssetInput = (props) => /* @__PURE__ */ jsx(FormField$1, { title: props.la
1428
1422
  size: 2
1429
1423
  }
1430
1424
  ),
1431
- (displayInfo == null ? void 0 : displayInfo.max_stored_frame_rate) && /* @__PURE__ */ jsx(
1425
+ displayInfo?.max_stored_frame_rate && /* @__PURE__ */ jsx(
1432
1426
  IconInfo,
1433
1427
  {
1434
1428
  text: `Frame rate: ${displayInfo.max_stored_frame_rate}`,
@@ -1436,7 +1430,7 @@ const AssetInput = (props) => /* @__PURE__ */ jsx(FormField$1, { title: props.la
1436
1430
  size: 2
1437
1431
  }
1438
1432
  ),
1439
- (displayInfo == null ? void 0 : displayInfo.aspect_ratio) && /* @__PURE__ */ jsx(
1433
+ displayInfo?.aspect_ratio && /* @__PURE__ */ jsx(
1440
1434
  IconInfo,
1441
1435
  {
1442
1436
  text: `Aspect Ratio: ${displayInfo.aspect_ratio}`,
@@ -1460,7 +1454,15 @@ const AssetInput = (props) => /* @__PURE__ */ jsx(FormField$1, { title: props.la
1460
1454
  }
1461
1455
  ),
1462
1456
  /* @__PURE__ */ jsx(IconInfo, { text: `Mux ID:
1463
- ${displayInfo.id}`, icon: TagIcon, size: 2 })
1457
+ ${displayInfo.id}`, icon: TagIcon, size: 2 }),
1458
+ displayInfo?.playbackId && /* @__PURE__ */ jsx(
1459
+ IconInfo,
1460
+ {
1461
+ text: `Playback ID: ${displayInfo.playbackId}`,
1462
+ icon: TagIcon,
1463
+ size: 2
1464
+ }
1465
+ )
1464
1466
  ] })
1465
1467
  ] })
1466
1468
  }
@@ -1507,7 +1509,7 @@ ${displayInfo.id}`, icon: TagIcon, size: 2 })
1507
1509
  }
1508
1510
  ),
1509
1511
  /* @__PURE__ */ jsxs(Inline, { space: 3, children: [
1510
- (displayInfo == null ? void 0 : displayInfo.duration) && /* @__PURE__ */ jsx(IconInfo, { text: displayInfo.duration, icon: ClockIcon, size: 1, muted: !0 }),
1512
+ displayInfo?.duration && /* @__PURE__ */ jsx(IconInfo, { text: displayInfo.duration, icon: ClockIcon, size: 1, muted: !0 }),
1511
1513
  /* @__PURE__ */ jsx(
1512
1514
  IconInfo,
1513
1515
  {
@@ -1583,7 +1585,7 @@ function VideoInBrowser({
1583
1585
  onEdit,
1584
1586
  asset
1585
1587
  }) {
1586
- const [renderVideo, setRenderVideo] = useState(!1), select = React.useCallback(() => onSelect == null ? void 0 : onSelect(asset), [onSelect, asset]), edit = React.useCallback(() => onEdit == null ? void 0 : onEdit(asset), [onEdit, asset]);
1588
+ const [renderVideo, setRenderVideo] = useState(!1), select = React.useCallback(() => onSelect?.(asset), [onSelect, asset]), edit = React.useCallback(() => onEdit?.(asset), [onEdit, asset]);
1587
1589
  if (!asset)
1588
1590
  return null;
1589
1591
  const playbackPolicy = getPlaybackPolicy(asset);
@@ -1704,7 +1706,7 @@ function VideoInBrowser({
1704
1706
  }
1705
1707
  function VideosBrowser({ onSelect }) {
1706
1708
  const { assets, isLoading, searchQuery, setSearchQuery, setSort, sort } = useAssets(), [editedAsset, setEditedAsset] = useState(null), freshEditedAsset = useMemo(
1707
- () => assets.find((a) => a._id === (editedAsset == null ? void 0 : editedAsset._id)) || editedAsset,
1709
+ () => assets.find((a2) => a2._id === editedAsset?._id) || editedAsset,
1708
1710
  [editedAsset, assets]
1709
1711
  ), placement = onSelect ? "input" : "tool";
1710
1712
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -1725,7 +1727,7 @@ function VideosBrowser({ onSelect }) {
1725
1727
  placement === "tool" && /* @__PURE__ */ jsx(ImportVideosFromMux, {})
1726
1728
  ] }),
1727
1729
  /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
1728
- (assets == null ? void 0 : assets.length) > 0 && /* @__PURE__ */ jsxs(Label$1, { muted: !0, children: [
1730
+ assets?.length > 0 && /* @__PURE__ */ jsxs(Label$1, { muted: !0, children: [
1729
1731
  assets.length,
1730
1732
  " video",
1731
1733
  assets.length > 1 ? "s" : null,
@@ -1785,16 +1787,12 @@ function useDialogState() {
1785
1787
  return useState(!1);
1786
1788
  }
1787
1789
  const useMuxPolling = (asset) => {
1788
- var _a, _b;
1789
1790
  const client = useClient(), projectId = useProjectId(), dataset = useDataset(), shouldFetch = useMemo(
1790
- () => {
1791
- var _a2, _b2;
1792
- return !!(asset != null && asset.assetId) && ((asset == null ? void 0 : asset.status) === "preparing" || ((_b2 = (_a2 = asset == null ? void 0 : asset.data) == null ? void 0 : _a2.static_renditions) == null ? void 0 : _b2.status) === "preparing");
1793
- },
1794
- [asset == null ? void 0 : asset.assetId, (_b = (_a = asset == null ? void 0 : asset.data) == null ? void 0 : _a.static_renditions) == null ? void 0 : _b.status, asset == null ? void 0 : asset.status]
1791
+ () => !!asset?.assetId && (asset?.status === "preparing" || asset?.data?.static_renditions?.status === "preparing"),
1792
+ [asset?.assetId, asset?.data?.static_renditions?.status, asset?.status]
1795
1793
  );
1796
1794
  return useSWR(
1797
- shouldFetch ? `/${projectId}/addons/mux/assets/${dataset}/data/${asset == null ? void 0 : asset.assetId}` : null,
1795
+ shouldFetch ? `/${projectId}/addons/mux/assets/${dataset}/data/${asset?.assetId}` : null,
1798
1796
  async () => {
1799
1797
  const { data } = await client.request({
1800
1798
  url: `/addons/mux/assets/${dataset}/data/${asset.assetId}`,
@@ -1867,16 +1865,14 @@ const useSaveSecrets = (client, secrets) => useCallback(
1867
1865
  }) => {
1868
1866
  let { signingKeyId, signingKeyPrivate } = secrets;
1869
1867
  try {
1870
- await saveSecrets(
1868
+ if (await saveSecrets(
1871
1869
  client,
1872
1870
  token,
1873
1871
  secretKey,
1874
1872
  enableSignedUrls,
1875
1873
  signingKeyId,
1876
1874
  signingKeyPrivate
1877
- );
1878
- const valid = await testSecrets(client);
1879
- if (!(valid != null && valid.status) && token && secretKey)
1875
+ ), !(await testSecrets(client))?.status && token && secretKey)
1880
1876
  throw new Error("Invalid secrets");
1881
1877
  } catch (err) {
1882
1878
  throw console.error("Error while trying to save secrets:", err), err;
@@ -1897,7 +1893,7 @@ const useSaveSecrets = (client, secrets) => useCallback(
1897
1893
  signingKeyPrivate
1898
1894
  );
1899
1895
  } catch (err) {
1900
- throw console.log("Error while creating and saving signing key:", err == null ? void 0 : err.message), err;
1896
+ throw console.log("Error while creating and saving signing key:", err?.message), err;
1901
1897
  }
1902
1898
  return {
1903
1899
  token,
@@ -1915,13 +1911,13 @@ function init({ token, secretKey, enableSignedUrls }) {
1915
1911
  error: null,
1916
1912
  // Form inputs don't set the state back to null when clearing a field, but uses empty strings
1917
1913
  // This ensures the `dirty` check works correctly
1918
- token: token != null ? token : "",
1919
- secretKey: secretKey != null ? secretKey : "",
1920
- enableSignedUrls: enableSignedUrls != null ? enableSignedUrls : !1
1914
+ token: token ?? "",
1915
+ secretKey: secretKey ?? "",
1916
+ enableSignedUrls: enableSignedUrls ?? !1
1921
1917
  };
1922
1918
  }
1923
1919
  function reducer(state, action) {
1924
- switch (action == null ? void 0 : action.type) {
1920
+ switch (action?.type) {
1925
1921
  case "submit":
1926
1922
  return { ...state, submitting: !0, error: null };
1927
1923
  case "error":
@@ -1931,7 +1927,7 @@ function reducer(state, action) {
1931
1927
  case "change":
1932
1928
  return { ...state, [action.payload.name]: action.payload.value };
1933
1929
  default:
1934
- throw new Error(`Unknown action type: ${action == null ? void 0 : action.type}`);
1930
+ throw new Error(`Unknown action type: ${action?.type}`);
1935
1931
  }
1936
1932
  }
1937
1933
  const useSecretsFormState = (secrets) => useReducer(reducer, secrets, init), ids = [
@@ -1956,7 +1952,7 @@ const useSecretsFormState = (secrets) => useReducer(reducer, secrets, init), ids
1956
1952
  "r"
1957
1953
  ];
1958
1954
  function MuxLogo({ height = 26 }) {
1959
- const id = useId(), [titleId, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = useMemo(
1955
+ const id = useId(), [titleId, a2, b, c2, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = useMemo(
1960
1956
  () => ids.map((field) => `${id}-${field}`),
1961
1957
  [id]
1962
1958
  );
@@ -1975,7 +1971,7 @@ function MuxLogo({ height = 26 }) {
1975
1971
  /* @__PURE__ */ jsxs(
1976
1972
  "linearGradient",
1977
1973
  {
1978
- id: c,
1974
+ id: c2,
1979
1975
  spreadMethod: "pad",
1980
1976
  gradientTransform: "matrix(528.38055 0 0 -528.38055 63.801 159.5)",
1981
1977
  gradientUnits: "userSpaceOnUse",
@@ -2357,7 +2353,7 @@ function MuxLogo({ height = 26 }) {
2357
2353
  ]
2358
2354
  }
2359
2355
  ),
2360
- /* @__PURE__ */ jsx("clipPath", { id: a, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2356
+ /* @__PURE__ */ jsx("clipPath", { id: a2, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2361
2357
  /* @__PURE__ */ jsx("clipPath", { id: b, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M423.64 242h164.999V77H423.64Z" }) }),
2362
2358
  /* @__PURE__ */ jsx("clipPath", { id: e, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2363
2359
  /* @__PURE__ */ jsx("clipPath", { id: f, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M311.3 242h93.031V77H311.3Z" }) }),
@@ -2365,7 +2361,7 @@ function MuxLogo({ height = 26 }) {
2365
2361
  /* @__PURE__ */ jsx("clipPath", { id: n, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2366
2362
  /* @__PURE__ */ jsx("clipPath", { id: o, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M69.067 242H169.12V141.947H69.067Z" }) })
2367
2363
  ] }),
2368
- /* @__PURE__ */ jsx("g", { clipPath: `url(#${a})`, transform: "matrix(1.33333 0 0 -1.33333 0 425.333)", children: /* @__PURE__ */ jsx(
2364
+ /* @__PURE__ */ jsx("g", { clipPath: `url(#${a2})`, transform: "matrix(1.33333 0 0 -1.33333 0 425.333)", children: /* @__PURE__ */ jsx(
2369
2365
  "g",
2370
2366
  {
2371
2367
  style: {
@@ -2376,7 +2372,7 @@ function MuxLogo({ height = 26 }) {
2376
2372
  "path",
2377
2373
  {
2378
2374
  style: {
2379
- fill: `url(#${c})`,
2375
+ fill: `url(#${c2})`,
2380
2376
  stroke: "none"
2381
2377
  },
2382
2378
  d: "M558.674 82.142c6.855-6.855 17.969-6.855 24.824 0 6.854 6.855 6.854 17.969 0 24.823L453.605 236.858c-6.855 6.855-17.969 6.855-24.824 0s-6.855-17.969 0-24.823z"
@@ -2534,7 +2530,6 @@ const Logo = styled.span`
2534
2530
  "API Credentials"
2535
2531
  ] }), fieldNames = ["token", "secretKey", "enableSignedUrls"];
2536
2532
  function ConfigureApi({ secrets, setDialogState }) {
2537
- var _a, _b;
2538
2533
  const client = useClient(), [state, dispatch] = useSecretsFormState(secrets), hasSecretsInitially = useMemo(() => secrets.token && secrets.secretKey, [secrets]), handleClose = useCallback(() => setDialogState(!1), [setDialogState]), dirty = useMemo(
2539
2534
  () => secrets.token !== state.token || secrets.secretKey !== state.secretKey || secrets.enableSignedUrls !== state.enableSignedUrls,
2540
2535
  [secrets, state]
@@ -2626,7 +2621,7 @@ function ConfigureApi({ secrets, setDialogState }) {
2626
2621
  ref: firstField,
2627
2622
  onChange: handleChangeToken,
2628
2623
  type: "text",
2629
- value: (_a = state.token) != null ? _a : "",
2624
+ value: state.token ?? "",
2630
2625
  required: !!state.secretKey || state.enableSignedUrls
2631
2626
  }
2632
2627
  ) }),
@@ -2636,7 +2631,7 @@ function ConfigureApi({ secrets, setDialogState }) {
2636
2631
  id: secretKeyId,
2637
2632
  onChange: handleChangeSecretKey,
2638
2633
  type: "text",
2639
- value: (_b = state.secretKey) != null ? _b : "",
2634
+ value: state.secretKey ?? "",
2640
2635
  required: !!state.token || state.enableSignedUrls
2641
2636
  }
2642
2637
  ) }),
@@ -2690,11 +2685,51 @@ function ConfigureApi({ secrets, setDialogState }) {
2690
2685
  }
2691
2686
  );
2692
2687
  }
2693
- var ConfigureApi$1 = memo(ConfigureApi);
2688
+ var ConfigureApi$1 = memo(ConfigureApi), c = function(r) {
2689
+ var t, e;
2690
+ function n(t2) {
2691
+ var e2;
2692
+ return (e2 = r.call(this, t2) || this).state = { hasError: !1, error: null }, e2;
2693
+ }
2694
+ e = r, (t = n).prototype = Object.create(e.prototype), t.prototype.constructor = t, t.__proto__ = e, n.getDerivedStateFromError = function(r2) {
2695
+ return { hasError: !0, error: r2 };
2696
+ };
2697
+ var o = n.prototype;
2698
+ return o.componentDidCatch = function(r2, t2) {
2699
+ return this.props.onDidCatch(r2, t2);
2700
+ }, o.render = function() {
2701
+ var r2 = this.state, t2 = this.props, e2 = t2.render, n2 = t2.children, o2 = t2.renderError;
2702
+ return r2.hasError ? o2 ? o2({ error: r2.error }) : null : e2 ? e2() : n2 || null;
2703
+ }, n;
2704
+ }(PureComponent), u = function(r, t) {
2705
+ switch (t.type) {
2706
+ case "catch":
2707
+ return { didCatch: !0, error: t.error };
2708
+ case "reset":
2709
+ return { didCatch: !1, error: null };
2710
+ default:
2711
+ return r;
2712
+ }
2713
+ };
2714
+ function a(t) {
2715
+ var a2 = useReducer(u, { didCatch: !1, error: null }), i = a2[0], d = a2[1], h = useRef(null);
2716
+ function l() {
2717
+ return e = function(r, e2) {
2718
+ d({ type: "catch", error: r }), t && t.onDidCatch && t.onDidCatch(r, e2);
2719
+ }, function(t2) {
2720
+ return React.createElement(c, { onDidCatch: e, children: t2.children, render: t2.render, renderError: t2.renderError });
2721
+ };
2722
+ var e;
2723
+ }
2724
+ var p, s = useCallback(function() {
2725
+ h.current = l(), d({ type: "reset" });
2726
+ }, []);
2727
+ return { ErrorBoundary: (p = h.current, p !== null ? p : (h.current = l(), h.current)), didCatch: i.didCatch, error: i.error, reset: s };
2728
+ }
2694
2729
  function ErrorBoundaryCard(props) {
2695
- const { children, schemaType } = props, { push: pushToast } = useToast(), errorRef = useRef(null), { ErrorBoundary, didCatch, error, reset } = useErrorBoundary({
2730
+ const { children, schemaType } = props, { push: pushToast } = useToast(), errorRef = useRef(null), { ErrorBoundary, didCatch, error, reset } = a({
2696
2731
  onDidCatch: (err, errorInfo) => {
2697
- console.group(err.toString()), console.groupCollapsed("console.error"), console.error(err), console.groupEnd(), err.stack && (console.groupCollapsed("error.stack"), console.log(err.stack), console.groupEnd()), errorInfo != null && errorInfo.componentStack && (console.groupCollapsed("errorInfo.componentStack"), console.log(errorInfo.componentStack), console.groupEnd()), console.groupEnd(), pushToast({
2732
+ console.group(err.toString()), console.groupCollapsed("console.error"), console.error(err), console.groupEnd(), err.stack && (console.groupCollapsed("error.stack"), console.log(err.stack), console.groupEnd()), errorInfo?.componentStack && (console.groupCollapsed("errorInfo.componentStack"), console.log(errorInfo.componentStack), console.groupEnd()), console.groupEnd(), pushToast({
2698
2733
  status: "error",
2699
2734
  title: "Plugin crashed",
2700
2735
  description: /* @__PURE__ */ jsx(Flex, { align: "center", children: /* @__PURE__ */ jsxs(Inline, { space: 1, children: [
@@ -2728,7 +2763,7 @@ function ErrorBoundaryCard(props) {
2728
2763
  /* @__PURE__ */ jsx("code", { children: name }),
2729
2764
  " plugin crashed"
2730
2765
  ] }),
2731
- (error == null ? void 0 : error.message) && /* @__PURE__ */ jsx(Card, { padding: 3, tone: "critical", shadow: 1, radius: 2, children: /* @__PURE__ */ jsx(Text, { children: error.message }) }),
2766
+ error?.message && /* @__PURE__ */ jsx(Card, { padding: 3, tone: "critical", shadow: 1, radius: 2, children: /* @__PURE__ */ jsx(Text, { children: error.message }) }),
2732
2767
  /* @__PURE__ */ jsx(Inline, { children: /* @__PURE__ */ jsx(Button, { onClick: handleRetry, text: "Retry" }) })
2733
2768
  ] }) }) }) : /* @__PURE__ */ jsx(ErrorBoundary, { children });
2734
2769
  }
@@ -3009,7 +3044,7 @@ function walk(entry) {
3009
3044
  function SelectAssets({ asset: selectedAsset, onChange, setDialogState }) {
3010
3045
  const handleSelect = useCallback(
3011
3046
  (chosenAsset) => {
3012
- chosenAsset != null && chosenAsset._id || onChange(PatchEvent.from([unset(["asset"])])), chosenAsset._id !== (selectedAsset == null ? void 0 : selectedAsset._id) && onChange(
3047
+ chosenAsset?._id || onChange(PatchEvent.from([unset(["asset"])])), chosenAsset._id !== selectedAsset?._id && onChange(
3013
3048
  PatchEvent.from([
3014
3049
  setIfMissing({ asset: {}, _type: "mux.video" }),
3015
3050
  set({ _type: "reference", _weak: !0, _ref: chosenAsset._id }, ["asset"])
@@ -3119,24 +3154,18 @@ const TopControls = styled.div`
3119
3154
  }
3120
3155
  ) : null
3121
3156
  ] }) }), Player = ({ asset, buttons, readOnly, onChange }) => {
3122
- var _a, _b, _c, _d;
3123
- const isLoading = useMemo(() => (asset == null ? void 0 : asset.status) === "preparing" ? "Preparing the video" : (asset == null ? void 0 : asset.status) === "waiting_for_upload" ? "Waiting for upload to start" : (asset == null ? void 0 : asset.status) === "waiting" ? "Processing upload" : !((asset == null ? void 0 : asset.status) === "ready" || typeof (asset == null ? void 0 : asset.status) > "u"), [asset]), isPreparingStaticRenditions = useMemo(() => {
3124
- var _a2, _b2;
3125
- return ((_b2 = (_a2 = asset == null ? void 0 : asset.data) == null ? void 0 : _a2.static_renditions) == null ? void 0 : _b2.status) === "preparing";
3126
- }, [(_b = (_a = asset == null ? void 0 : asset.data) == null ? void 0 : _a.static_renditions) == null ? void 0 : _b.status]), playRef = useRef(null), muteRef = useRef(null), handleCancelUpload = useCancelUpload(asset, onChange);
3157
+ const isLoading = useMemo(() => asset?.status === "preparing" ? "Preparing the video" : asset?.status === "waiting_for_upload" ? "Waiting for upload to start" : asset?.status === "waiting" ? "Processing upload" : !(asset?.status === "ready" || typeof asset?.status > "u"), [asset]), isPreparingStaticRenditions = useMemo(() => asset?.data?.static_renditions?.status === "preparing", [asset?.data?.static_renditions?.status]), playRef = useRef(null), muteRef = useRef(null), handleCancelUpload = useCancelUpload(asset, onChange);
3127
3158
  return useEffect(() => {
3128
- var _a2, _b2;
3129
3159
  const style = document.createElement("style");
3130
- style.innerHTML = "button svg { vertical-align: middle; }", (_a2 = playRef.current) != null && _a2.shadowRoot && playRef.current.shadowRoot.appendChild(style), (_b2 = muteRef == null ? void 0 : muteRef.current) != null && _b2.shadowRoot && muteRef.current.shadowRoot.appendChild(style.cloneNode(!0));
3160
+ style.innerHTML = "button svg { vertical-align: middle; }", playRef.current?.shadowRoot && playRef.current.shadowRoot.appendChild(style), muteRef?.current?.shadowRoot && muteRef.current.shadowRoot.appendChild(style.cloneNode(!0));
3131
3161
  }, []), useEffect(() => {
3132
- var _a2, _b2, _c2;
3133
- if ((asset == null ? void 0 : asset.status) === "errored")
3134
- throw handleCancelUpload(), new Error((_c2 = (_b2 = (_a2 = asset.data) == null ? void 0 : _a2.errors) == null ? void 0 : _b2.messages) == null ? void 0 : _c2.join(" "));
3135
- }, [(_d = (_c = asset.data) == null ? void 0 : _c.errors) == null ? void 0 : _d.messages, asset == null ? void 0 : asset.status, handleCancelUpload]), !asset || !asset.status ? null : isLoading ? /* @__PURE__ */ jsx(
3162
+ if (asset?.status === "errored")
3163
+ throw handleCancelUpload(), new Error(asset.data?.errors?.messages?.join(" "));
3164
+ }, [asset.data?.errors?.messages, asset?.status, handleCancelUpload]), !asset || !asset.status ? null : isLoading ? /* @__PURE__ */ jsx(
3136
3165
  UploadProgress,
3137
3166
  {
3138
3167
  progress: 100,
3139
- filename: asset == null ? void 0 : asset.filename,
3168
+ filename: asset?.filename,
3140
3169
  text: isLoading !== !0 && isLoading || "Waiting for Mux to complete the upload",
3141
3170
  onCancel: readOnly ? void 0 : () => handleCancelUpload()
3142
3171
  }
@@ -3255,9 +3284,9 @@ function PlayerActionsMenu(props) {
3255
3284
  const { asset, readOnly, dialogState, setDialogState, onChange, onSelect } = props, [open, setOpen] = useState(!1), [menuElement, setMenuRef] = useState(null), isSigned = useMemo(() => getPlaybackPolicy(asset) === "signed", [asset]), onReset = useCallback(() => onChange(PatchEvent.from(unset([]))), [onChange]);
3256
3285
  return useEffect(() => {
3257
3286
  open && dialogState && setOpen(!1);
3258
- }, [dialogState, open]), useClickOutside(
3259
- useCallback(() => setOpen(!1), []),
3260
- [menuElement]
3287
+ }, [dialogState, open]), useClickOutsideEvent(
3288
+ () => setOpen(!1),
3289
+ () => [menuElement]
3261
3290
  ), /* @__PURE__ */ jsxs(Inline, { space: 1, padding: 2, children: [
3262
3291
  isSigned && /* @__PURE__ */ jsx(
3263
3292
  Tooltip,
@@ -3338,12 +3367,12 @@ function formatBytes(bytes, si = !1, dp = 1) {
3338
3367
  if (Math.abs(bytes) < thresh)
3339
3368
  return bytes + " B";
3340
3369
  const units = si ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
3341
- let u = -1;
3370
+ let u2 = -1;
3342
3371
  const r = 10 ** dp;
3343
3372
  do
3344
- bytes /= thresh, ++u;
3345
- while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
3346
- return bytes.toFixed(dp) + " " + units[u];
3373
+ bytes /= thresh, ++u2;
3374
+ while (Math.round(Math.abs(bytes) * r) / r >= thresh && u2 < units.length - 1);
3375
+ return bytes.toFixed(dp) + " " + units[u2];
3347
3376
  }
3348
3377
  const SUPPORTED_MUX_LANGUAGES = [
3349
3378
  { label: "English", code: "en", state: "Stable" },
@@ -3399,7 +3428,7 @@ function TextTracksEditor({
3399
3428
  {
3400
3429
  id: "include-autogenerated-track",
3401
3430
  style: { display: "block" },
3402
- checked: !!(track != null && track.language_code),
3431
+ checked: !!track?.language_code,
3403
3432
  onChange: () => {
3404
3433
  dispatch(track ? { action: "track", id: track._id, subAction: "delete" } : {
3405
3434
  action: "track",
@@ -3435,10 +3464,7 @@ function TextTracksEditor({
3435
3464
  placeholder: "Select language",
3436
3465
  filterOption: (query, option) => option.label.toLowerCase().indexOf(query.toLowerCase()) > -1 || option.value.toLowerCase().indexOf(query.toLowerCase()) > -1,
3437
3466
  openButton: !0,
3438
- renderValue: (value) => {
3439
- var _a;
3440
- return ((_a = SUBTITLE_LANGUAGES[track.type].find((l) => l.value === value)) == null ? void 0 : _a.label) || value;
3441
- },
3467
+ renderValue: (value) => SUBTITLE_LANGUAGES[track.type].find((l) => l.value === value)?.label || value,
3442
3468
  renderOption: (option) => /* @__PURE__ */ jsx(Card, { "data-as": "button", padding: 3, radius: 2, tone: "inherit", children: /* @__PURE__ */ jsxs(Text, { size: 2, textOverflow: "ellipsis", children: [
3443
3469
  option.label,
3444
3470
  " (",
@@ -3475,14 +3501,13 @@ function UploadConfiguration({
3475
3501
  ] : []
3476
3502
  ).current, [config, dispatch] = useReducer(
3477
3503
  (prev, action) => {
3478
- var _a;
3479
3504
  switch (action.action) {
3480
3505
  case "encoding_tier":
3481
3506
  return action.value === "baseline" ? Object.assign({}, prev, {
3482
3507
  encoding_tier: action.value,
3483
3508
  mp4_support: "none",
3484
3509
  max_resolution_tier: "1080p",
3485
- text_tracks: (_a = prev.text_tracks) == null ? void 0 : _a.filter(({ type }) => type !== "autogenerated")
3510
+ text_tracks: prev.text_tracks?.filter(({ type }) => type !== "autogenerated")
3486
3511
  }) : Object.assign({}, prev, {
3487
3512
  encoding_tier: action.value,
3488
3513
  mp4_support: pluginConfig.mp4_support,
@@ -3494,6 +3519,7 @@ function UploadConfiguration({
3494
3519
  case "normalize_audio":
3495
3520
  case "signed":
3496
3521
  return Object.assign({}, prev, { [action.action]: action.value });
3522
+ // Updating individual tracks
3497
3523
  case "track": {
3498
3524
  const text_tracks = [...prev.text_tracks], target_track_i = text_tracks.findIndex(({ _id: _id2 }) => _id2 === action.id);
3499
3525
  switch (action.subAction) {
@@ -3810,10 +3836,7 @@ const ctrlKey = 17, cmdKey = 91, UploadCardWithFocusRing = withFocusRing(Card),
3810
3836
  onSelect && onSelect(event.target.files);
3811
3837
  },
3812
3838
  [onSelect]
3813
- ), handleButtonClick = useCallback(() => {
3814
- var _a;
3815
- return (_a = inputRef.current) == null ? void 0 : _a.click();
3816
- }, []);
3839
+ ), handleButtonClick = useCallback(() => inputRef.current?.click(), []);
3817
3840
  return /* @__PURE__ */ jsxs(Label, { htmlFor: inputId, children: [
3818
3841
  /* @__PURE__ */ jsx(
3819
3842
  HiddenInput,
@@ -3902,7 +3925,6 @@ const INITIAL_STATE = {
3902
3925
  error: null
3903
3926
  };
3904
3927
  function Uploader(props) {
3905
- var _a;
3906
3928
  const toast = useToast(), containerRef = useRef(null), dragEnteredEls = useRef([]), [dragState, setDragState] = useState(null), cancelUploadButton = useRef(
3907
3929
  (() => {
3908
3930
  const events$ = new Subject();
@@ -3913,7 +3935,6 @@ function Uploader(props) {
3913
3935
  })()
3914
3936
  ).current, uploadRef = useRef(null), [state, dispatch] = useReducer(
3915
3937
  (prev, action) => {
3916
- var _a2, _b;
3917
3938
  switch (action.action) {
3918
3939
  case "stageUpload":
3919
3940
  return Object.assign({}, INITIAL_STATE, { stagedUpload: action.input });
@@ -3938,9 +3959,9 @@ function Uploader(props) {
3938
3959
  });
3939
3960
  case "reset":
3940
3961
  case "complete":
3941
- return (_a2 = uploadRef.current) == null || _a2.unsubscribe(), uploadRef.current = null, INITIAL_STATE;
3962
+ return uploadRef.current?.unsubscribe(), uploadRef.current = null, INITIAL_STATE;
3942
3963
  case "error":
3943
- return (_b = uploadRef.current) == null || _b.unsubscribe(), uploadRef.current = null, Object.assign({}, INITIAL_STATE, { error: action.error });
3964
+ return uploadRef.current?.unsubscribe(), uploadRef.current = null, Object.assign({}, INITIAL_STATE, { error: action.error });
3944
3965
  default:
3945
3966
  return prev;
3946
3967
  }
@@ -3976,8 +3997,7 @@ function Uploader(props) {
3976
3997
  takeUntil(
3977
3998
  cancelUploadButton.observable.pipe(
3978
3999
  tap(() => {
3979
- var _a2;
3980
- (_a2 = state.uploadStatus) != null && _a2.uuid && props.client.delete(state.uploadStatus.uuid);
4000
+ state.uploadStatus?.uuid && props.client.delete(state.uploadStatus.uuid);
3981
4001
  })
3982
4002
  )
3983
4003
  )
@@ -4031,10 +4051,9 @@ function Uploader(props) {
4031
4051
  }, handleDragOver = (event) => {
4032
4052
  event.preventDefault(), event.stopPropagation();
4033
4053
  }, handleDragEnter = (event) => {
4034
- var _a2, _b;
4035
4054
  event.stopPropagation(), dragEnteredEls.current.push(event.target);
4036
- const type = (_b = (_a2 = event.dataTransfer.items) == null ? void 0 : _a2[0]) == null ? void 0 : _b.type;
4037
- setDragState(type != null && type.startsWith("video/") ? "valid" : "invalid");
4055
+ const type = event.dataTransfer.items?.[0]?.type;
4056
+ setDragState(type?.startsWith("video/") ? "valid" : "invalid");
4038
4057
  }, handleDragLeave = (event) => {
4039
4058
  event.stopPropagation();
4040
4059
  const idx = dragEnteredEls.current.indexOf(event.target);
@@ -4056,7 +4075,7 @@ function Uploader(props) {
4056
4075
  {
4057
4076
  onCancel: cancelUploadButton.handleClick,
4058
4077
  progress: uploadStatus.progress,
4059
- filename: ((_a = uploadStatus.file) == null ? void 0 : _a.name) || uploadStatus.url
4078
+ filename: uploadStatus.file?.name || uploadStatus.url
4060
4079
  }
4061
4080
  );
4062
4081
  }
@@ -4124,8 +4143,7 @@ function Uploader(props) {
4124
4143
  ] });
4125
4144
  }
4126
4145
  const Input = (props) => {
4127
- var _a;
4128
- const client = useClient(), secretDocumentValues = useSecretsDocumentValues(), assetDocumentValues = useAssetDocumentValues((_a = props.value) == null ? void 0 : _a.asset), poll = useMuxPolling(props.readOnly ? void 0 : (assetDocumentValues == null ? void 0 : assetDocumentValues.value) || void 0), [dialogState, setDialogState] = useDialogState(), error = secretDocumentValues.error || assetDocumentValues.error || poll.error;
4146
+ const client = useClient(), secretDocumentValues = useSecretsDocumentValues(), assetDocumentValues = useAssetDocumentValues(props.value?.asset), poll = useMuxPolling(props.readOnly ? void 0 : assetDocumentValues?.value || void 0), [dialogState, setDialogState] = useDialogState(), error = secretDocumentValues.error || assetDocumentValues.error || poll.error;
4129
4147
  if (error)
4130
4148
  throw error;
4131
4149
  const isLoading = secretDocumentValues.isLoading || assetDocumentValues.isLoading;