sanity-plugin-mux-input 2.3.4 → 2.3.5

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.
@@ -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
- import { ErrorOutlineIcon, RetrieveIcon, RetryIcon, CheckmarkCircleIcon, SortIcon, WarningOutlineIcon, EditIcon, PublishIcon, DocumentIcon, TrashIcon, CheckmarkIcon, RevertIcon, SearchIcon, ClockIcon, CropIcon, CalendarIcon, TagIcon, LockIcon, PlayIcon, PlugIcon, UploadIcon, ResetIcon, EllipsisHorizontalIcon, AddIcon, 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, Radio, Autocomplete, rem } from "@sanity/ui";
5
- import React, { useState, useMemo, useEffect, useRef, useId, memo, isValidElement, useCallback, useReducer, PureComponent, createElement, forwardRef, Suspense } from "react";
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";
6
6
  import compact from "lodash/compact.js";
7
7
  import toLower from "lodash/toLower.js";
8
8
  import trim from "lodash/trim.js";
@@ -21,6 +21,7 @@ import isString from "lodash/isString.js";
21
21
  import { useMemoObservable } 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";
24
25
  import { UpChunk } from "@mux/upchunk";
25
26
  import { isValidElementType } from "react-is";
26
27
  import LanguagesList from "iso-639-1";
@@ -143,7 +144,7 @@ function accumulateIntermediateState(currentState, pageResult) {
143
144
  ...currentData,
144
145
  ...("data" in pageResult && pageResult.data || []).filter(
145
146
  // De-duplicate assets for safety
146
- (asset) => !currentData.some((a2) => a2.id === asset.id)
147
+ (asset) => !currentData.some((a) => a.id === asset.id)
147
148
  )
148
149
  ],
149
150
  error: "error" in pageResult ? pageResult.error : (
@@ -160,8 +161,7 @@ function hasMorePages(pageResult) {
160
161
  function useMuxAssets({ secrets, enabled }) {
161
162
  const [state, setState] = useState({ loading: !0, pageNum: FIRST_PAGE });
162
163
  return useEffect(() => {
163
- if (!enabled)
164
- return;
164
+ if (!enabled) return;
165
165
  const subscription = defer(
166
166
  () => fetchMuxAssetsPage(
167
167
  secrets,
@@ -190,7 +190,7 @@ function useMuxAssets({ secrets, enabled }) {
190
190
  return () => subscription.unsubscribe();
191
191
  }, [enabled]), state;
192
192
  }
193
- const name = "mux-input", cacheNs = "sanity-plugin-mux-input", muxSecretsDocumentId = "secrets.mux", DIALOGS_Z_INDEX = 6e4, THUMBNAIL_ASPECT_RATIO = 1.7777777777777777, MIN_ASPECT_RATIO = 5 / 4, path$1 = ["token", "secretKey", "enableSignedUrls", "signingKeyId", "signingKeyPrivate"], useSecretsDocumentValues = () => {
193
+ const name = "mux-input", cacheNs = "sanity-plugin-mux-input", muxSecretsDocumentId = "secrets.mux", DIALOGS_Z_INDEX = 6e4, THUMBNAIL_ASPECT_RATIO = 1.7777777777777777, MIN_ASPECT_RATIO = 5 / 4, AUDIO_ASPECT_RATIO = 5 / 1, path$1 = ["token", "secretKey", "enableSignedUrls", "signingKeyId", "signingKeyPrivate"], useSecretsDocumentValues = () => {
194
194
  const { error, isLoading, value } = useDocumentValues(
195
195
  muxSecretsDocumentId,
196
196
  path$1
@@ -217,14 +217,14 @@ function useImportMuxAssets() {
217
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({
218
218
  secrets: secretDocumentValues.value.secrets,
219
219
  enabled: hasSecrets && dialogOpen
220
- }), missingAssets = useMemo(() => assetsInSanity && muxAssets.data ? muxAssets.data.filter((a2) => !assetExistsInSanity(a2, assetsInSanity)) : void 0, [assetsInSanity, muxAssets.data]), [selectedAssets, setSelectedAssets] = useState([]), closeDialog = () => {
220
+ }), missingAssets = useMemo(() => assetsInSanity && muxAssets.data ? muxAssets.data.filter((a) => !assetExistsInSanity(a, assetsInSanity)) : void 0, [assetsInSanity, muxAssets.data]), [selectedAssets, setSelectedAssets] = useState([]), closeDialog = () => {
221
221
  importState !== "importing" && setImportState("closed");
222
222
  }, openDialog = () => {
223
223
  importState === "closed" && setImportState("idle");
224
224
  };
225
225
  async function importAssets() {
226
226
  setImportState("importing");
227
- const documents = selectedAssets.map(muxAssetToSanityDocument), tx = client.transaction();
227
+ const documents = selectedAssets.flatMap((asset) => muxAssetToSanityDocument(asset) || []), tx = client.transaction();
228
228
  documents.forEach((doc) => tx.create(doc));
229
229
  try {
230
230
  await tx.commit({ returnDocuments: !1 }), setSelectedAssets([]), setImportState("done");
@@ -249,17 +249,19 @@ function useImportMuxAssets() {
249
249
  }
250
250
  function muxAssetToSanityDocument(asset) {
251
251
  var _a;
252
- return {
253
- _id: uuid(),
254
- _type: "mux.videoAsset",
255
- _updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
256
- _createdAt: parseMuxDate(asset.created_at).toISOString(),
257
- assetId: asset.id,
258
- playbackId: (_a = asset.playback_ids.find((p) => p.id)) == null ? void 0 : _a.id,
259
- filename: `Asset #${truncateString(asset.id, 15)}`,
260
- status: asset.status,
261
- data: asset
262
- };
252
+ const playbackId = (_a = (asset.playback_ids || []).find((p) => p.id)) == null ? void 0 : _a.id;
253
+ if (playbackId)
254
+ return {
255
+ _id: uuid(),
256
+ _type: "mux.videoAsset",
257
+ _updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
258
+ _createdAt: parseMuxDate(asset.created_at).toISOString(),
259
+ assetId: asset.id,
260
+ playbackId,
261
+ filename: `Asset #${truncateString(asset.id, 15)}`,
262
+ status: asset.status,
263
+ data: asset
264
+ };
263
265
  }
264
266
  const useAssetsInSanity = createHookFromObservableFactory(
265
267
  (documentStore) => documentStore.listenQuery(
@@ -282,8 +284,7 @@ function assetExistsInSanity(asset, existingAssets) {
282
284
  function useInView(options = {}) {
283
285
  const [inView, setInView] = useState(!1), ref = useRef(null);
284
286
  return useEffect(() => {
285
- if (!ref.current)
286
- return;
287
+ if (!ref.current) return;
287
288
  const observer = new IntersectionObserver(([entry], obs) => {
288
289
  var _a;
289
290
  const nowInView = entry.isIntersecting && obs.thresholds.some((threshold) => entry.intersectionRatio >= threshold);
@@ -321,9 +322,9 @@ function readSecrets(client) {
321
322
  function generateJwt(client, playbackId, aud, payload) {
322
323
  const { signingKeyId, signingKeyPrivate } = readSecrets(client);
323
324
  if (!signingKeyId)
324
- throw new TypeError("Missing signingKeyId");
325
+ throw new TypeError("Missing `signingKeyId`.\n Check your plugin's configuration");
325
326
  if (!signingKeyPrivate)
326
- throw new TypeError("Missing signingKeyPrivate");
327
+ throw new TypeError("Missing `signingKeyPrivate`.\n Check your plugin's configuration");
327
328
  const { default: sign } = suspend(() => import("jsonwebtoken-esm/sign"), ["jsonwebtoken-esm/sign"]);
328
329
  return sign(
329
330
  payload ? JSON.parse(JSON.stringify(payload, (_, v) => v != null ? v : void 0)) : {},
@@ -653,9 +654,9 @@ function ImportVideosDialog(props) {
653
654
  {
654
655
  asset,
655
656
  selectAsset: (selected) => {
656
- selected ? props.setSelectedAssets([...props.selectedAssets, asset]) : props.setSelectedAssets(props.selectedAssets.filter((a2) => a2.id !== asset.id));
657
+ selected ? props.setSelectedAssets([...props.selectedAssets, asset]) : props.setSelectedAssets(props.selectedAssets.filter((a) => a.id !== asset.id));
657
658
  },
658
- selected: props.selectedAssets.some((a2) => a2.id === asset.id)
659
+ selected: props.selectedAssets.some((a) => a.id === asset.id)
659
660
  },
660
661
  asset.id
661
662
  ))
@@ -774,7 +775,7 @@ function VideoPlayer({
774
775
  ...props
775
776
  }) {
776
777
  var _a, _b;
777
- const client = useClient(), { src: videoSrc, error } = useMemo(() => {
778
+ const client = useClient(), isAudio = assetIsAudio(asset), { src: videoSrc, error } = useMemo(() => {
778
779
  try {
779
780
  const src = (asset == null ? void 0 : asset.playbackId) && getVideoSrc({ client, asset });
780
781
  return src ? { src } : { error: new TypeError("Asset has no playback ID") };
@@ -787,8 +788,12 @@ function VideoPlayer({
787
788
  } catch {
788
789
  return !1;
789
790
  }
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), aspectRatio = Math.max(MIN_ASPECT_RATIO, targetAspectRatio);
791
- return /* @__PURE__ */ jsxs(Card, { tone: "transparent", style: { aspectRatio, position: "relative" }, children: [
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);
792
+ let aspectRatio = Math.max(MIN_ASPECT_RATIO, targetAspectRatio);
793
+ return isAudio && (aspectRatio = props.forceAspectRatio ? (
794
+ // Make it wider when forcing aspect ratio to balance with videos' rendering height (audio players overflow a bit)
795
+ props.forceAspectRatio * 1.2
796
+ ) : AUDIO_ASPECT_RATIO), /* @__PURE__ */ jsxs(Card, { tone: "transparent", style: { aspectRatio, position: "relative" }, children: [
792
797
  videoSrc && /* @__PURE__ */ jsxs(Fragment, { children: [
793
798
  /* @__PURE__ */ jsx(
794
799
  MuxPlayer,
@@ -801,9 +806,10 @@ function VideoPlayer({
801
806
  crossOrigin: "anonymous",
802
807
  metadata: {
803
808
  player_name: "Sanity Admin Dashboard",
804
- player_version: "2.3.4",
809
+ player_version: "2.3.5",
805
810
  page_type: "Preview Player"
806
811
  },
812
+ audio: isAudio,
807
813
  style: {
808
814
  height: "100%",
809
815
  width: "100%",
@@ -832,6 +838,10 @@ function VideoPlayer({
832
838
  children
833
839
  ] });
834
840
  }
841
+ function assetIsAudio(asset) {
842
+ var _a;
843
+ return ((_a = asset.data) == null ? void 0 : _a.max_stored_resolution) === "Audio only";
844
+ }
835
845
  function deleteAssetOnMux(client, assetId) {
836
846
  const { dataset } = client.config();
837
847
  return client.request({
@@ -845,8 +855,7 @@ async function deleteAsset({
845
855
  asset,
846
856
  deleteOnMux
847
857
  }) {
848
- if (!(asset != null && asset._id))
849
- return !0;
858
+ if (!(asset != null && asset._id)) return !0;
850
859
  try {
851
860
  await client.delete(asset._id);
852
861
  } catch {
@@ -1037,8 +1046,7 @@ function DeleteDialog({
1037
1046
  state !== "checkingReferences" || referencesLoading || setState(references != null && references.length ? "cantDelete" : "confirm");
1038
1047
  }, [state, references, referencesLoading]);
1039
1048
  async function confirmDelete() {
1040
- if (state !== "confirm")
1041
- return;
1049
+ if (state !== "confirm") return;
1042
1050
  setState("processing_deletion");
1043
1051
  const worked = await deleteAsset({ client, asset, deleteOnMux });
1044
1052
  worked === !0 ? (toast.push({ title: "Successfully deleted video", status: "success" }), succeededDeleting()) : worked === "failed-mux" ? (toast.push({
@@ -1627,7 +1635,25 @@ function VideoInBrowser({
1627
1635
  children: [
1628
1636
  renderVideo ? /* @__PURE__ */ jsx(VideoPlayer, { asset, autoPlay: !0, forceAspectRatio: THUMBNAIL_ASPECT_RATIO }) : /* @__PURE__ */ jsxs(PlayButton, { onClick: () => setRenderVideo(!0), children: [
1629
1637
  /* @__PURE__ */ jsx("div", { "data-play": !0, children: /* @__PURE__ */ jsx(PlayIcon, {}) }),
1630
- /* @__PURE__ */ jsx(VideoThumbnail, { asset })
1638
+ assetIsAudio(asset) ? /* @__PURE__ */ jsx(
1639
+ "div",
1640
+ {
1641
+ style: {
1642
+ aspectRatio: THUMBNAIL_ASPECT_RATIO,
1643
+ display: "flex",
1644
+ alignItems: "center",
1645
+ justifyContent: "center"
1646
+ },
1647
+ children: /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: "3em", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx(
1648
+ "path",
1649
+ {
1650
+ fill: "currentColor",
1651
+ style: { opacity: "0.65" },
1652
+ d: "M10.75 19q.95 0 1.6-.65t.65-1.6V13h3v-2h-4v3.875q-.275-.2-.587-.288t-.663-.087q-.95 0-1.6.65t-.65 1.6t.65 1.6t1.6.65M6 22q-.825 0-1.412-.587T4 20V4q0-.825.588-1.412T6 2h8l6 6v12q0 .825-.587 1.413T18 22zm7-13V4H6v16h12V9zM6 4v5zv16z"
1653
+ }
1654
+ ) })
1655
+ }
1656
+ ) : /* @__PURE__ */ jsx(VideoThumbnail, { asset })
1631
1657
  ] }),
1632
1658
  /* @__PURE__ */ jsx(VideoMetadata, { asset }),
1633
1659
  /* @__PURE__ */ jsxs(
@@ -1678,7 +1704,7 @@ function VideoInBrowser({
1678
1704
  }
1679
1705
  function VideosBrowser({ onSelect }) {
1680
1706
  const { assets, isLoading, searchQuery, setSearchQuery, setSort, sort } = useAssets(), [editedAsset, setEditedAsset] = useState(null), freshEditedAsset = useMemo(
1681
- () => assets.find((a2) => a2._id === (editedAsset == null ? void 0 : editedAsset._id)) || editedAsset,
1707
+ () => assets.find((a) => a._id === (editedAsset == null ? void 0 : editedAsset._id)) || editedAsset,
1682
1708
  [editedAsset, assets]
1683
1709
  ), placement = onSelect ? "input" : "tool";
1684
1710
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -1930,7 +1956,7 @@ const useSecretsFormState = (secrets) => useReducer(reducer, secrets, init), ids
1930
1956
  "r"
1931
1957
  ];
1932
1958
  function MuxLogo({ height = 26 }) {
1933
- const id = useId(), [titleId, a2, b, c2, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = useMemo(
1959
+ const id = useId(), [titleId, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = useMemo(
1934
1960
  () => ids.map((field) => `${id}-${field}`),
1935
1961
  [id]
1936
1962
  );
@@ -1949,7 +1975,7 @@ function MuxLogo({ height = 26 }) {
1949
1975
  /* @__PURE__ */ jsxs(
1950
1976
  "linearGradient",
1951
1977
  {
1952
- id: c2,
1978
+ id: c,
1953
1979
  spreadMethod: "pad",
1954
1980
  gradientTransform: "matrix(528.38055 0 0 -528.38055 63.801 159.5)",
1955
1981
  gradientUnits: "userSpaceOnUse",
@@ -2331,7 +2357,7 @@ function MuxLogo({ height = 26 }) {
2331
2357
  ]
2332
2358
  }
2333
2359
  ),
2334
- /* @__PURE__ */ jsx("clipPath", { id: a2, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2360
+ /* @__PURE__ */ jsx("clipPath", { id: a, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2335
2361
  /* @__PURE__ */ jsx("clipPath", { id: b, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M423.64 242h164.999V77H423.64Z" }) }),
2336
2362
  /* @__PURE__ */ jsx("clipPath", { id: e, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2337
2363
  /* @__PURE__ */ jsx("clipPath", { id: f, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M311.3 242h93.031V77H311.3Z" }) }),
@@ -2339,7 +2365,7 @@ function MuxLogo({ height = 26 }) {
2339
2365
  /* @__PURE__ */ jsx("clipPath", { id: n, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M0 319h657.706V0H0Z" }) }),
2340
2366
  /* @__PURE__ */ jsx("clipPath", { id: o, clipPathUnits: "userSpaceOnUse", children: /* @__PURE__ */ jsx("path", { d: "M69.067 242H169.12V141.947H69.067Z" }) })
2341
2367
  ] }),
2342
- /* @__PURE__ */ jsx("g", { clipPath: `url(#${a2})`, transform: "matrix(1.33333 0 0 -1.33333 0 425.333)", children: /* @__PURE__ */ jsx(
2368
+ /* @__PURE__ */ jsx("g", { clipPath: `url(#${a})`, transform: "matrix(1.33333 0 0 -1.33333 0 425.333)", children: /* @__PURE__ */ jsx(
2343
2369
  "g",
2344
2370
  {
2345
2371
  style: {
@@ -2350,7 +2376,7 @@ function MuxLogo({ height = 26 }) {
2350
2376
  "path",
2351
2377
  {
2352
2378
  style: {
2353
- fill: `url(#${c2})`,
2379
+ fill: `url(#${c})`,
2354
2380
  stroke: "none"
2355
2381
  },
2356
2382
  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"
@@ -2664,49 +2690,9 @@ function ConfigureApi({ secrets, setDialogState }) {
2664
2690
  }
2665
2691
  );
2666
2692
  }
2667
- var ConfigureApi$1 = memo(ConfigureApi), c = function(r) {
2668
- var t, e;
2669
- function n(t2) {
2670
- var e2;
2671
- return (e2 = r.call(this, t2) || this).state = { hasError: !1, error: null }, e2;
2672
- }
2673
- e = r, (t = n).prototype = Object.create(e.prototype), t.prototype.constructor = t, t.__proto__ = e, n.getDerivedStateFromError = function(r2) {
2674
- return { hasError: !0, error: r2 };
2675
- };
2676
- var o = n.prototype;
2677
- return o.componentDidCatch = function(r2, t2) {
2678
- return this.props.onDidCatch(r2, t2);
2679
- }, o.render = function() {
2680
- var r2 = this.state, t2 = this.props, e2 = t2.render, n2 = t2.children, o2 = t2.renderError;
2681
- return r2.hasError ? o2 ? o2({ error: r2.error }) : null : e2 ? e2() : n2 || null;
2682
- }, n;
2683
- }(PureComponent), u = function(r, t) {
2684
- switch (t.type) {
2685
- case "catch":
2686
- return { didCatch: !0, error: t.error };
2687
- case "reset":
2688
- return { didCatch: !1, error: null };
2689
- default:
2690
- return r;
2691
- }
2692
- };
2693
- function a(t) {
2694
- var a2 = useReducer(u, { didCatch: !1, error: null }), i = a2[0], d = a2[1], h = useRef(null);
2695
- function l() {
2696
- return e = function(r, e2) {
2697
- d({ type: "catch", error: r }), t && t.onDidCatch && t.onDidCatch(r, e2);
2698
- }, function(t2) {
2699
- return React.createElement(c, { onDidCatch: e, children: t2.children, render: t2.render, renderError: t2.renderError });
2700
- };
2701
- var e;
2702
- }
2703
- var p, s = useCallback(function() {
2704
- h.current = l(), d({ type: "reset" });
2705
- }, []);
2706
- return { ErrorBoundary: (p = h.current, p !== null ? p : (h.current = l(), h.current)), didCatch: i.didCatch, error: i.error, reset: s };
2707
- }
2693
+ var ConfigureApi$1 = memo(ConfigureApi);
2708
2694
  function ErrorBoundaryCard(props) {
2709
- const { children, schemaType } = props, { push: pushToast } = useToast(), errorRef = useRef(null), { ErrorBoundary, didCatch, error, reset } = a({
2695
+ const { children, schemaType } = props, { push: pushToast } = useToast(), errorRef = useRef(null), { ErrorBoundary, didCatch, error, reset } = useErrorBoundary({
2710
2696
  onDidCatch: (err, errorInfo) => {
2711
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({
2712
2698
  status: "error",
@@ -3352,12 +3338,12 @@ function formatBytes(bytes, si = !1, dp = 1) {
3352
3338
  if (Math.abs(bytes) < thresh)
3353
3339
  return bytes + " B";
3354
3340
  const units = si ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
3355
- let u2 = -1;
3341
+ let u = -1;
3356
3342
  const r = 10 ** dp;
3357
3343
  do
3358
- bytes /= thresh, ++u2;
3359
- while (Math.round(Math.abs(bytes) * r) / r >= thresh && u2 < units.length - 1);
3360
- return bytes.toFixed(dp) + " " + units[u2];
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];
3361
3347
  }
3362
3348
  const SUPPORTED_MUX_LANGUAGES = [
3363
3349
  { label: "English", code: "en", state: "Stable" },
@@ -3399,47 +3385,45 @@ const ALL_LANGUAGE_CODES = LanguagesList.getAllCodes().map((code) => ({
3399
3385
  })),
3400
3386
  subtitles: ALL_LANGUAGE_CODES,
3401
3387
  captions: ALL_LANGUAGE_CODES
3402
- }, TRACK_TYPES = [
3403
- { value: "autogenerated", label: "Auto-generated Subtitles" }
3404
- // {value: 'subtitles', label: 'Subtitles'},
3405
- // {value: 'captions', label: 'Closed Captions'},
3406
- ];
3407
- function TrackEditor({
3408
- canAutoGenerate,
3409
- track,
3410
- dispatch
3388
+ };
3389
+ function TextTracksEditor({
3390
+ tracks,
3391
+ dispatch,
3392
+ defaultLang
3411
3393
  }) {
3412
- const { _id: id, type } = track, dispatchTrackAction = (args) => dispatch({ action: "track", id, ...args }), trackTypes = TRACK_TYPES.filter(
3413
- ({ value }) => !(value === "autogenerated" && !canAutoGenerate)
3414
- );
3415
- return trackTypes.length === 0 ? null : /* @__PURE__ */ jsx(Card, { border: !0, padding: 3, radius: 2, style: { position: "relative" }, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
3416
- trackTypes.length > 1 && /* @__PURE__ */ jsx(FormField$2, { title: "Auto-generated subtitles", children: /* @__PURE__ */ jsx(Flex, { gap: 3, children: trackTypes.map(({ value, label }) => {
3417
- const inputId = `${id}--type-${value}`;
3418
- return /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
3419
- /* @__PURE__ */ jsx(
3420
- Radio,
3421
- {
3422
- checked: type === value,
3423
- name: "track-type",
3424
- onChange: (e) => dispatchTrackAction({
3425
- subAction: "update",
3394
+ const track = tracks[0];
3395
+ return /* @__PURE__ */ jsx(FormField$2, { title: "Auto-generated subtitle or caption", children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
3396
+ /* @__PURE__ */ jsxs(Flex, { align: "center", children: [
3397
+ /* @__PURE__ */ jsx(
3398
+ Checkbox,
3399
+ {
3400
+ id: "include-autogenerated-track",
3401
+ style: { display: "block" },
3402
+ checked: !!(track != null && track.language_code),
3403
+ onChange: () => {
3404
+ dispatch(track ? { action: "track", id: track._id, subAction: "delete" } : {
3405
+ action: "track",
3406
+ id: uuid(),
3407
+ subAction: "add",
3426
3408
  value: {
3427
- type: e.currentTarget.value
3409
+ type: "autogenerated",
3410
+ name: defaultLang || void 0,
3411
+ language_code: defaultLang || void 0
3428
3412
  }
3429
- }),
3430
- value,
3431
- id: inputId
3413
+ });
3432
3414
  }
3433
- ),
3434
- /* @__PURE__ */ jsx(Text, { as: "label", htmlFor: inputId, children: label })
3435
- ] }, value);
3436
- }) }) }),
3437
- /* @__PURE__ */ jsx(
3415
+ }
3416
+ ),
3417
+ /* @__PURE__ */ jsx(Box, { flex: 1, paddingLeft: 3, children: /* @__PURE__ */ jsx(Text, { children: /* @__PURE__ */ jsx("label", { htmlFor: "checkbox", children: "Generate captions" }) }) })
3418
+ ] }),
3419
+ track && /* @__PURE__ */ jsx(
3438
3420
  Autocomplete,
3439
3421
  {
3440
- id: `${id}--language`,
3422
+ id: "text-tract-editor--language",
3441
3423
  value: track.language_code,
3442
- onChange: (newValue) => dispatchTrackAction({
3424
+ onChange: (newValue) => dispatch({
3425
+ action: "track",
3426
+ id: track._id,
3443
3427
  subAction: "update",
3444
3428
  value: {
3445
3429
  language_code: newValue,
@@ -3462,54 +3446,9 @@ function TrackEditor({
3462
3446
  ")"
3463
3447
  ] }) })
3464
3448
  }
3465
- ),
3466
- /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
3467
- Button,
3468
- {
3469
- icon: TrashIcon,
3470
- tone: "critical",
3471
- mode: "ghost",
3472
- onClick: () => dispatchTrackAction({ subAction: "delete" }),
3473
- text: "Delete"
3474
- }
3475
- ) })
3449
+ )
3476
3450
  ] }) });
3477
3451
  }
3478
- function TextTracksEditor({
3479
- canAutoGenerate,
3480
- tracks,
3481
- dispatch
3482
- }) {
3483
- return TRACK_TYPES.filter(
3484
- ({ value }) => !(value === "autogenerated" && !canAutoGenerate)
3485
- ).length === 0 ? null : /* @__PURE__ */ jsx(
3486
- FormField$2,
3487
- {
3488
- title: "Captions & Subtitles",
3489
- description: "Provide text tracks for video accessibility.",
3490
- children: /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
3491
- tracks.map((track) => /* @__PURE__ */ jsx(
3492
- TrackEditor,
3493
- {
3494
- canAutoGenerate,
3495
- track,
3496
- dispatch
3497
- },
3498
- track._id
3499
- )),
3500
- /* @__PURE__ */ jsx(
3501
- Button,
3502
- {
3503
- icon: AddIcon,
3504
- onClick: () => dispatch({ action: "track", id: uuid(), subAction: "add" }),
3505
- text: "New caption/subtitle",
3506
- mode: "ghost"
3507
- }
3508
- )
3509
- ] })
3510
- }
3511
- );
3512
- }
3513
3452
  const ENCODING_OPTIONS = [
3514
3453
  { value: "smart", label: "Smart" },
3515
3454
  { value: "baseline", label: "Baseline" }
@@ -3525,26 +3464,25 @@ function UploadConfiguration({
3525
3464
  startUpload,
3526
3465
  onClose
3527
3466
  }) {
3528
- var _a;
3529
3467
  const id = useId(), autoTextTracks = useRef(
3530
- pluginConfig.encoding_tier === "smart" && ((_a = pluginConfig.defaultAutogeneratedSubtitleLangs) == null ? void 0 : _a.map(
3531
- (language_code) => ({
3468
+ pluginConfig.encoding_tier === "smart" && pluginConfig.defaultAutogeneratedSubtitleLang ? [
3469
+ {
3532
3470
  _id: uuid(),
3533
3471
  type: "autogenerated",
3534
- language_code,
3535
- name: LanguagesList.getNativeName(language_code)
3536
- })
3537
- )) || []
3472
+ language_code: pluginConfig.defaultAutogeneratedSubtitleLang,
3473
+ name: LanguagesList.getNativeName(pluginConfig.defaultAutogeneratedSubtitleLang)
3474
+ }
3475
+ ] : []
3538
3476
  ).current, [config, dispatch] = useReducer(
3539
3477
  (prev, action) => {
3540
- var _a2;
3478
+ var _a;
3541
3479
  switch (action.action) {
3542
3480
  case "encoding_tier":
3543
3481
  return action.value === "baseline" ? Object.assign({}, prev, {
3544
3482
  encoding_tier: action.value,
3545
3483
  mp4_support: "none",
3546
3484
  max_resolution_tier: "1080p",
3547
- text_tracks: (_a2 = prev.text_tracks) == null ? void 0 : _a2.filter(({ type }) => type !== "autogenerated")
3485
+ text_tracks: (_a = prev.text_tracks) == null ? void 0 : _a.filter(({ type }) => type !== "autogenerated")
3548
3486
  }) : Object.assign({}, prev, {
3549
3487
  encoding_tier: action.value,
3550
3488
  mp4_support: pluginConfig.mp4_support,
@@ -3560,23 +3498,21 @@ function UploadConfiguration({
3560
3498
  const text_tracks = [...prev.text_tracks], target_track_i = text_tracks.findIndex(({ _id: _id2 }) => _id2 === action.id);
3561
3499
  switch (action.subAction) {
3562
3500
  case "add":
3563
- if (target_track_i !== -1)
3564
- break;
3565
- text_tracks.push(
3566
- prev.encoding_tier === "smart" ? { _id: action.id, type: "autogenerated" } : { _id: action.id, type: "subtitles" }
3567
- );
3501
+ if (target_track_i !== -1) break;
3502
+ text_tracks.push({
3503
+ _id: action.id,
3504
+ ...action.value
3505
+ });
3568
3506
  break;
3569
3507
  case "update":
3570
- if (target_track_i === -1)
3571
- break;
3508
+ if (target_track_i === -1) break;
3572
3509
  text_tracks[target_track_i] = {
3573
3510
  ...text_tracks[target_track_i],
3574
3511
  ...action.value
3575
3512
  };
3576
3513
  break;
3577
3514
  case "delete":
3578
- if (target_track_i === -1)
3579
- break;
3515
+ if (target_track_i === -1) break;
3580
3516
  text_tracks.splice(target_track_i, 1);
3581
3517
  break;
3582
3518
  }
@@ -3597,8 +3533,7 @@ function UploadConfiguration({
3597
3533
  ), { disableTextTrackConfig, disableUploadConfig } = pluginConfig, skipConfig = disableTextTrackConfig && disableUploadConfig;
3598
3534
  if (useEffect(() => {
3599
3535
  skipConfig && startUpload(formatUploadConfig(config));
3600
- }, []), skipConfig)
3601
- return null;
3536
+ }, []), skipConfig) return null;
3602
3537
  const maxSupportedResolution = RESOLUTION_TIERS.findIndex(
3603
3538
  (rt) => rt.value === pluginConfig.max_resolution_tier
3604
3539
  );
@@ -3747,15 +3682,15 @@ function UploadConfiguration({
3747
3682
  ] })
3748
3683
  ] }) })
3749
3684
  ] }),
3750
- !disableTextTrackConfig && /* @__PURE__ */ jsx(
3685
+ !disableTextTrackConfig && config.encoding_tier === "smart" && /* @__PURE__ */ jsx(
3751
3686
  TextTracksEditor,
3752
3687
  {
3753
- canAutoGenerate: config.encoding_tier === "smart",
3754
3688
  tracks: config.text_tracks,
3755
- dispatch
3689
+ dispatch,
3690
+ defaultLang: pluginConfig.defaultAutogeneratedSubtitleLang
3756
3691
  }
3757
3692
  ),
3758
- /* @__PURE__ */ jsx(
3693
+ /* @__PURE__ */ jsx(Box, { marginTop: 4, children: /* @__PURE__ */ jsx(
3759
3694
  Button,
3760
3695
  {
3761
3696
  icon: UploadIcon,
@@ -3763,7 +3698,7 @@ function UploadConfiguration({
3763
3698
  tone: "positive",
3764
3699
  onClick: () => startUpload(formatUploadConfig(config))
3765
3700
  }
3766
- )
3701
+ ) })
3767
3702
  ] })
3768
3703
  }
3769
3704
  );
@@ -4021,8 +3956,7 @@ function Uploader(props) {
4021
3956
  }, []);
4022
3957
  const startUpload = (settings) => {
4023
3958
  const { stagedUpload } = state;
4024
- if (!stagedUpload || uploadRef.current)
4025
- return;
3959
+ if (!stagedUpload || uploadRef.current) return;
4026
3960
  dispatch({ action: "commitUpload" });
4027
3961
  let uploadObservable;
4028
3962
  switch (stagedUpload.type) {
@@ -4245,7 +4179,7 @@ function muxVideoCustomRendering(config) {
4245
4179
  }
4246
4180
  };
4247
4181
  }
4248
- const muxVideo = {
4182
+ const muxVideoSchema = {
4249
4183
  name: "mux.video",
4250
4184
  type: "object",
4251
4185
  title: "Video asset reference",
@@ -4258,6 +4192,122 @@ const muxVideo = {
4258
4192
  to: [{ type: "mux.videoAsset" }]
4259
4193
  }
4260
4194
  ]
4195
+ }, muxTrack = {
4196
+ name: "mux.track",
4197
+ type: "object",
4198
+ fields: [
4199
+ { type: "string", name: "id" },
4200
+ { type: "string", name: "type" },
4201
+ { type: "number", name: "max_width" },
4202
+ { type: "number", name: "max_frame_rate" },
4203
+ { type: "number", name: "duration" },
4204
+ { type: "number", name: "max_height" }
4205
+ ]
4206
+ }, muxPlaybackId = {
4207
+ name: "mux.playbackId",
4208
+ type: "object",
4209
+ fields: [
4210
+ { type: "string", name: "id" },
4211
+ { type: "string", name: "policy" }
4212
+ ]
4213
+ }, muxStaticRenditionFile = {
4214
+ name: "mux.staticRenditionFile",
4215
+ type: "object",
4216
+ fields: [
4217
+ { type: "string", name: "ext" },
4218
+ { type: "string", name: "name" },
4219
+ { type: "number", name: "width" },
4220
+ { type: "number", name: "bitrate" },
4221
+ { type: "number", name: "filesize" },
4222
+ { type: "number", name: "height" }
4223
+ ]
4224
+ }, muxStaticRenditions = {
4225
+ name: "mux.staticRenditions",
4226
+ type: "object",
4227
+ fields: [
4228
+ { type: "string", name: "status" },
4229
+ {
4230
+ name: "files",
4231
+ type: "array",
4232
+ of: [{ type: "mux.staticRenditionFile" }]
4233
+ }
4234
+ ]
4235
+ }, muxAssetData = {
4236
+ name: "mux.assetData",
4237
+ title: "Mux asset data",
4238
+ type: "object",
4239
+ fields: [
4240
+ {
4241
+ type: "string",
4242
+ name: "resolution_tier"
4243
+ },
4244
+ {
4245
+ type: "string",
4246
+ name: "upload_id"
4247
+ },
4248
+ {
4249
+ type: "string",
4250
+ name: "created_at"
4251
+ },
4252
+ {
4253
+ type: "string",
4254
+ name: "id"
4255
+ },
4256
+ {
4257
+ type: "string",
4258
+ name: "status"
4259
+ },
4260
+ {
4261
+ type: "string",
4262
+ name: "max_stored_resolution"
4263
+ },
4264
+ {
4265
+ type: "string",
4266
+ name: "passthrough"
4267
+ },
4268
+ {
4269
+ type: "string",
4270
+ name: "encoding_tier"
4271
+ },
4272
+ {
4273
+ type: "string",
4274
+ name: "master_access"
4275
+ },
4276
+ {
4277
+ type: "string",
4278
+ name: "aspect_ratio"
4279
+ },
4280
+ {
4281
+ type: "number",
4282
+ name: "duration"
4283
+ },
4284
+ {
4285
+ type: "number",
4286
+ name: "max_stored_frame_rate"
4287
+ },
4288
+ {
4289
+ type: "string",
4290
+ name: "mp4_support"
4291
+ },
4292
+ {
4293
+ type: "string",
4294
+ name: "max_resolution_tier"
4295
+ },
4296
+ {
4297
+ name: "tracks",
4298
+ type: "array",
4299
+ of: [{ type: "mux.track" }]
4300
+ },
4301
+ {
4302
+ name: "playback_ids",
4303
+ type: "array",
4304
+ of: [{ type: "mux.playbackId" }]
4305
+ },
4306
+ {
4307
+ name: "static_renditions",
4308
+ type: "mux.staticRenditions"
4309
+ }
4310
+ ]
4261
4311
  }, muxVideoAsset = {
4262
4312
  name: "mux.videoAsset",
4263
4313
  type: "object",
@@ -4282,9 +4332,20 @@ const muxVideo = {
4282
4332
  {
4283
4333
  type: "number",
4284
4334
  name: "thumbTime"
4335
+ },
4336
+ {
4337
+ type: "mux.assetData",
4338
+ name: "data"
4285
4339
  }
4286
4340
  ]
4287
- }, defaultConfig = {
4341
+ }, schemaTypes = [
4342
+ muxTrack,
4343
+ muxPlaybackId,
4344
+ muxStaticRenditionFile,
4345
+ muxStaticRenditions,
4346
+ muxAssetData,
4347
+ muxVideoAsset
4348
+ ], defaultConfig = {
4288
4349
  mp4_support: "none",
4289
4350
  encoding_tier: "smart",
4290
4351
  max_resolution_tier: "1080p",
@@ -4297,9 +4358,9 @@ const muxVideo = {
4297
4358
  name: "mux-input",
4298
4359
  schema: {
4299
4360
  types: [
4300
- muxVideoAsset,
4361
+ ...schemaTypes,
4301
4362
  {
4302
- ...muxVideo,
4363
+ ...muxVideoSchema,
4303
4364
  ...muxVideoCustomRendering(config)
4304
4365
  }
4305
4366
  ]
@@ -4311,4 +4372,4 @@ export {
4311
4372
  defaultConfig,
4312
4373
  muxInput
4313
4374
  };
4314
- //# sourceMappingURL=index.esm.js.map
4375
+ //# sourceMappingURL=index.mjs.map