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