sanity-plugin-mux-input 2.10.1 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1488,14 +1488,18 @@ function VideoPlayer({
1488
1488
  children,
1489
1489
  ...props
1490
1490
  }) {
1491
- const client = useClient(), { dialogState } = useDialogStateContext(), isAudio = assetIsAudio(asset), muxPlayer = useRef(null), thumbnail = getPosterSrc({ asset, client, width: thumbnailWidth }), { src: videoSrc, error } = useMemo(() => {
1491
+ const client = useClient(), { dialogState } = useDialogStateContext(), isAudio = assetIsAudio(asset), muxPlayer = useRef(null), {
1492
+ src: videoSrc,
1493
+ thumbnail: thumbnailSrc,
1494
+ error
1495
+ } = useMemo(() => {
1492
1496
  try {
1493
- const src = asset?.playbackId && getVideoSrc({ client, asset });
1494
- return src ? { src } : { error: new TypeError("Asset has no playback ID") };
1497
+ const thumbnail = getPosterSrc({ asset, client, width: thumbnailWidth }), src = asset?.playbackId && getVideoSrc({ client, asset });
1498
+ return src ? { src, thumbnail } : { error: new TypeError("Asset has no playback ID") };
1495
1499
  } catch (error2) {
1496
1500
  return { error: error2 };
1497
1501
  }
1498
- }, [asset, client]), signedToken = useMemo(() => {
1502
+ }, [asset, client, thumbnailWidth]), signedToken = useMemo(() => {
1499
1503
  try {
1500
1504
  return new URL(videoSrc).searchParams.get("token");
1501
1505
  } catch {
@@ -1512,7 +1516,7 @@ function VideoPlayer({
1512
1516
  /* @__PURE__ */ jsx(
1513
1517
  MuxPlayer,
1514
1518
  {
1515
- poster: thumbnail,
1519
+ poster: thumbnailSrc,
1516
1520
  ref: muxPlayer,
1517
1521
  ...props,
1518
1522
  playsInline: !0,
@@ -1522,7 +1526,7 @@ function VideoPlayer({
1522
1526
  crossOrigin: "anonymous",
1523
1527
  metadata: {
1524
1528
  player_name: "Sanity Admin Dashboard",
1525
- player_version: "2.10.1",
1529
+ player_version: "2.11.0",
1526
1530
  page_type: "Preview Player"
1527
1531
  },
1528
1532
  audio: isAudio,
@@ -2899,25 +2903,29 @@ const TopControls = styled.div`
2899
2903
  onCancel,
2900
2904
  filename,
2901
2905
  text = "Uploading"
2902
- }) => /* @__PURE__ */ jsx(CardWrapper, { tone: "primary", padding: 4, border: !0, height: "fill", children: /* @__PURE__ */ jsxs(FlexWrapper, { align: "center", justify: "space-between", height: "fill", direction: "row", gap: 2, children: [
2903
- /* @__PURE__ */ jsxs(LeftSection, { children: [
2904
- /* @__PURE__ */ jsx(Flex, { justify: "center", gap: [3, 3, 2, 2], direction: ["column", "column", "row"], children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsxs(Inline, { space: 2, children: [
2905
- text,
2906
- /* @__PURE__ */ jsx(CodeWrapper, { size: 1, children: filename || "..." })
2907
- ] }) }) }),
2908
- /* @__PURE__ */ jsx(Card, { marginTop: 3, radius: 5, shadow: 1, children: /* @__PURE__ */ jsx(LinearProgress, { value: progress }) })
2909
- ] }),
2910
- onCancel ? /* @__PURE__ */ jsx(
2911
- Button,
2912
- {
2913
- fontSize: 2,
2914
- text: "Cancel upload",
2915
- mode: "ghost",
2916
- tone: "critical",
2917
- onClick: onCancel
2918
- }
2919
- ) : null
2920
- ] }) }), Player = ({ asset, buttons, readOnly, onChange }) => {
2906
+ }) => {
2907
+ const isCancelDisabled = progress >= 90;
2908
+ return /* @__PURE__ */ jsx(CardWrapper, { tone: "primary", padding: 4, border: !0, height: "fill", children: /* @__PURE__ */ jsxs(FlexWrapper, { align: "center", justify: "space-between", height: "fill", direction: "row", gap: 2, children: [
2909
+ /* @__PURE__ */ jsxs(LeftSection, { children: [
2910
+ /* @__PURE__ */ jsx(Flex, { justify: "center", gap: [3, 3, 2, 2], direction: ["column", "column", "row"], children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsxs(Inline, { space: 2, children: [
2911
+ text,
2912
+ /* @__PURE__ */ jsx(CodeWrapper, { size: 1, children: filename || "..." })
2913
+ ] }) }) }),
2914
+ /* @__PURE__ */ jsx(Card, { marginTop: 3, radius: 5, shadow: 1, children: /* @__PURE__ */ jsx(LinearProgress, { value: progress }) })
2915
+ ] }),
2916
+ onCancel ? /* @__PURE__ */ jsx(
2917
+ Button,
2918
+ {
2919
+ fontSize: 2,
2920
+ text: "Cancel upload",
2921
+ mode: "ghost",
2922
+ tone: "critical",
2923
+ onClick: onCancel,
2924
+ disabled: isCancelDisabled
2925
+ }
2926
+ ) : null
2927
+ ] }) });
2928
+ }, Player = ({ asset, buttons, readOnly, onChange }) => {
2921
2929
  const isLoading = useMemo(() => asset?.status === "preparing" ? "Preparing the video" : asset?.status === "waiting_for_upload" ? "Waiting for upload to start" : asset?.status === "waiting" ? "Processing upload" : !(asset?.status === "ready" || typeof asset?.status > "u"), [asset]), isPreparingStaticRenditions = useMemo(() => asset?.data?.static_renditions?.status === "preparing", [asset?.data?.static_renditions?.status]), playRef = useRef(null), muteRef = useRef(null), handleCancelUpload = useCancelUpload(asset, onChange);
2922
2930
  return useEffect(() => {
2923
2931
  const style = document.createElement("style");
@@ -3414,7 +3422,7 @@ function UploadConfiguration({
3414
3422
  max_resolution_tier: pluginConfig.max_resolution_tier,
3415
3423
  mp4_support: pluginConfig.mp4_support,
3416
3424
  signed_policy: secrets.enableSignedUrls && pluginConfig.defaultSigned,
3417
- public_policy: !0,
3425
+ public_policy: pluginConfig.defaultPublic,
3418
3426
  normalize_audio: pluginConfig.normalize_audio,
3419
3427
  text_tracks: autoTextTracks
3420
3428
  }
@@ -3784,7 +3792,7 @@ function Uploader(props) {
3784
3792
  handleClick: (event) => events$.next(event)
3785
3793
  };
3786
3794
  })()
3787
- ).current, uploadRef = useRef(null), [state, dispatch] = useReducer(
3795
+ ).current, uploadRef = useRef(null), uploadingDocumentId = useRef(null), [state, dispatch] = useReducer(
3788
3796
  (prev, action) => {
3789
3797
  switch (action.action) {
3790
3798
  case "stageUpload":
@@ -3810,9 +3818,9 @@ function Uploader(props) {
3810
3818
  });
3811
3819
  case "reset":
3812
3820
  case "complete":
3813
- return uploadRef.current?.unsubscribe(), uploadRef.current = null, INITIAL_STATE;
3821
+ return uploadRef.current?.unsubscribe(), uploadRef.current = null, uploadingDocumentId.current = null, INITIAL_STATE;
3814
3822
  case "error":
3815
- return uploadRef.current?.unsubscribe(), uploadRef.current = null, Object.assign({}, INITIAL_STATE, { error: action.error });
3823
+ return uploadRef.current?.unsubscribe(), uploadRef.current = null, uploadingDocumentId.current = null, Object.assign({}, INITIAL_STATE, { error: action.error });
3816
3824
  default:
3817
3825
  return prev;
3818
3826
  }
@@ -3823,9 +3831,21 @@ function Uploader(props) {
3823
3831
  error: null
3824
3832
  }
3825
3833
  );
3826
- useEffect(() => () => {
3827
- uploadRef.current && !uploadRef.current.closed && uploadRef.current.unsubscribe();
3828
- }, []);
3834
+ useEffect(() => {
3835
+ const cleanup = () => {
3836
+ if (uploadRef.current && !uploadRef.current.closed && uploadRef.current.unsubscribe(), uploadingDocumentId.current && props.asset?._id !== uploadingDocumentId.current) {
3837
+ const docId = uploadingDocumentId.current;
3838
+ uploadingDocumentId.current = null, props.client.delete(docId).catch((err) => {
3839
+ console.warn("Failed to cleanup orphaned upload document:", err);
3840
+ });
3841
+ }
3842
+ }, handleBeforeUnload = () => {
3843
+ cleanup();
3844
+ };
3845
+ return window.addEventListener("beforeunload", handleBeforeUnload), window.addEventListener("pagehide", handleBeforeUnload), () => {
3846
+ window.removeEventListener("beforeunload", handleBeforeUnload), window.removeEventListener("pagehide", handleBeforeUnload), cleanup();
3847
+ };
3848
+ }, [props.client, props.asset?._id]);
3829
3849
  const startUpload = (settings) => {
3830
3850
  const { stagedUpload } = state;
3831
3851
  if (!stagedUpload || uploadRef.current) return;
@@ -3848,7 +3868,7 @@ function Uploader(props) {
3848
3868
  takeUntil(
3849
3869
  cancelUploadButton.observable.pipe(
3850
3870
  tap(() => {
3851
- state.uploadStatus?.uuid && props.client.delete(state.uploadStatus.uuid);
3871
+ uploadingDocumentId.current && (props.client.delete(uploadingDocumentId.current), uploadingDocumentId.current = null);
3852
3872
  })
3853
3873
  )
3854
3874
  )
@@ -3859,6 +3879,8 @@ function Uploader(props) {
3859
3879
  next: (event) => {
3860
3880
  switch (event.type) {
3861
3881
  case "uuid":
3882
+ uploadingDocumentId.current = event.uuid, dispatch({ action: "progressInfo", ...event });
3883
+ break;
3862
3884
  case "file":
3863
3885
  case "url":
3864
3886
  dispatch({ action: "progressInfo", ...event });
@@ -3867,7 +3889,7 @@ function Uploader(props) {
3867
3889
  dispatch({ action: "progress", percent: event.percent });
3868
3890
  break;
3869
3891
  case "success":
3870
- dispatch({ action: "progress", percent: 100 }), props.onChange(
3892
+ dispatch({ action: "progress", percent: 100 }), uploadingDocumentId.current = null, props.onChange(
3871
3893
  PatchEvent.from([
3872
3894
  setIfMissing({ asset: {} }),
3873
3895
  set({ _type: "reference", _weak: !0, _ref: event.asset._id }, ["asset"])
@@ -4232,6 +4254,7 @@ const muxVideoSchema = {
4232
4254
  video_quality: "plus",
4233
4255
  max_resolution_tier: "1080p",
4234
4256
  normalize_audio: !1,
4257
+ defaultPublic: !0,
4235
4258
  defaultSigned: !1,
4236
4259
  tool: DEFAULT_TOOL_CONFIG,
4237
4260
  allowedRolesForConfiguration: []