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