sanity-plugin-mux-input 2.0.3 → 2.0.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.
Files changed (35) hide show
  1. package/lib/_chunks/{Input-aa6d929b.js → Input-235cb658.js} +77 -66
  2. package/lib/_chunks/Input-235cb658.js.map +1 -0
  3. package/lib/_chunks/{Input-4ec3c050.js → Input-b9334416.js} +78 -66
  4. package/lib/_chunks/Input-b9334416.js.map +1 -0
  5. package/lib/_chunks/{Preview-1664b7d5.js → Preview-85174edf.js} +2 -2
  6. package/lib/_chunks/{Preview-1664b7d5.js.map → Preview-85174edf.js.map} +1 -1
  7. package/lib/_chunks/{Preview-43ce9c72.js → Preview-ced24517.js} +2 -2
  8. package/lib/_chunks/{Preview-43ce9c72.js.map → Preview-ced24517.js.map} +1 -1
  9. package/lib/_chunks/{VideoSource.styled-99ffa712.js → VideoSource.styled-11786b3a.js} +3 -3
  10. package/lib/_chunks/VideoSource.styled-11786b3a.js.map +1 -0
  11. package/lib/_chunks/{VideoSource.styled-24577ec8.js → VideoSource.styled-f1b98975.js} +3 -3
  12. package/lib/_chunks/VideoSource.styled-f1b98975.js.map +1 -0
  13. package/lib/_chunks/{index-9933dea2.js → index-5a70abdc.js} +14 -13
  14. package/lib/_chunks/{index-9933dea2.js.map → index-5a70abdc.js.map} +1 -1
  15. package/lib/_chunks/{index-c54f5393.js → index-7260e0df.js} +14 -13
  16. package/lib/_chunks/{index-c54f5393.js.map → index-7260e0df.js.map} +1 -1
  17. package/lib/index.esm.js +1 -1
  18. package/lib/index.js +1 -1
  19. package/package.json +33 -33
  20. package/src/actions/assets.ts +1 -1
  21. package/src/actions/secrets.ts +12 -3
  22. package/src/actions/upload.ts +1 -1
  23. package/src/components/Player.tsx +15 -24
  24. package/src/components/__legacy__Uploader.tsx +1 -1
  25. package/src/hooks/useSaveSecrets.ts +1 -1
  26. package/src/util/generateJwt.ts +1 -1
  27. package/src/util/getAnimatedPosterSrc.ts +1 -1
  28. package/src/util/getPosterSrc.ts +1 -1
  29. package/src/util/getStoryboardSrc.ts +1 -1
  30. package/src/util/getVideoSrc.ts +1 -1
  31. package/src/util/readSecrets.ts +1 -1
  32. package/lib/_chunks/Input-4ec3c050.js.map +0 -1
  33. package/lib/_chunks/Input-aa6d929b.js.map +0 -1
  34. package/lib/_chunks/VideoSource.styled-24577ec8.js.map +0 -1
  35. package/lib/_chunks/VideoSource.styled-99ffa712.js.map +0 -1
@@ -1,20 +1,11 @@
1
- const _excluded = ["icon", "id", "accept", "capture", "fontSize", "multiple", "onSelect", "padding", "space", "textAlign", "text", "disabled"],
2
- _excluded2 = ["onSelect"];
3
1
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19;
4
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
5
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
7
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
11
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
13
4
  import React, { useState, useMemo, memo, useRef, useLayoutEffect, useCallback, useId, useEffect, isValidElement, createElement, forwardRef, Component, useReducer } from 'react';
14
- import { useClient, VideoThumbnail, AnimatedVideoThumbnail, ThumbGrid, CardLoadMore, getPlaybackId, getPlaybackPolicy, generateJwt, getPosterSrc, _id, useAssetDocumentValues } from './VideoSource.styled-24577ec8.js';
5
+ import { useClient, VideoThumbnail, AnimatedVideoThumbnail, ThumbGrid, CardLoadMore, getPlaybackId, getPlaybackPolicy, generateJwt, getPosterSrc, _id, useAssetDocumentValues } from './VideoSource.styled-f1b98975.js';
15
6
  import { useProjectId, useDataset, useDocumentValues, PatchEvent, setIfMissing, set, unset, LinearProgress } from 'sanity';
16
7
  import useSWR from 'swr';
17
- import { muxSecretsDocumentId, cacheNs, InputFallback } from './index-c54f5393.js';
8
+ import { muxSecretsDocumentId, cacheNs, InputFallback } from './index-7260e0df.js';
18
9
  import { Observable, defer, concat, of, throwError, from, Subject } from 'rxjs';
19
10
  import { switchMap, mergeMap, catchError, mergeMapTo, takeUntil, tap } from 'rxjs/operators';
20
11
  import { uuid } from '@sanity/uuid';
@@ -24,7 +15,7 @@ import { DownloadIcon, EllipsisVerticalIcon, TrashIcon, LockIcon, EditIcon, Uplo
24
15
  import { animate } from 'motion';
25
16
  import styled, { css } from 'styled-components';
26
17
  import { getDevicePixelRatio } from 'use-device-pixel-ratio';
27
- import { generatePlayerInitTime, initialize } from '@mux/playback-core';
18
+ import MuxVideo from '@mux/mux-video-react';
28
19
  import { MediaControlBar, MediaPosterImage, MediaController, MediaLoadingIndicator, MediaPlayButton, MediaMuteButton, MediaTimeDisplay, MediaTimeRange, MediaDurationDisplay, MediaFullscreenButton } from 'media-chrome/dist/react';
29
20
  import { isValidElementType } from 'react-is';
30
21
  import { clear, preload } from 'suspend-react';
@@ -94,7 +85,9 @@ function createUpChunkObservable(uuid, uploadUrl, source) {
94
85
  endpoint: uploadUrl,
95
86
  file: source,
96
87
  dynamicChunkSize: true
88
+ // changes the chunk size based on network speeds
97
89
  });
90
+
98
91
  const successHandler = () => {
99
92
  subscriber.next({
100
93
  type: "success",
@@ -297,14 +290,23 @@ function uploadFile(config, client, file) {
297
290
  },
298
291
  body
299
292
  })).pipe(mergeMap(result => {
300
- return createUpChunkObservable(uuid$1, result.upload.url, file).pipe(mergeMap(event => {
293
+ return createUpChunkObservable(uuid$1, result.upload.url, file).pipe(
294
+ // eslint-disable-next-line no-warning-comments
295
+ // @TODO type the observable events
296
+ // eslint-disable-next-line max-nested-callbacks
297
+ mergeMap(event => {
301
298
  if (event.type !== "success") {
302
299
  return of(event);
303
300
  }
304
- return from(updateAssetDocumentFromUpload(client, uuid$1)).pipe(mergeMap(doc => of(_objectSpread(_objectSpread({}, event), {}, {
301
+ return from(updateAssetDocumentFromUpload(client, uuid$1)).pipe(
302
+ // eslint-disable-next-line max-nested-callbacks
303
+ mergeMap(doc => of({
304
+ ...event,
305
305
  asset: doc
306
- }))));
307
- }), catchError(err => {
306
+ })));
307
+ }),
308
+ // eslint-disable-next-line max-nested-callbacks
309
+ catchError(err => {
308
310
  return cancelUpload(client, uuid$1).pipe(mergeMapTo(throwError(err)));
309
311
  }));
310
312
  })));
@@ -745,7 +747,8 @@ const PER_PAGE = 200;
745
747
  function createQuery() {
746
748
  let start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
747
749
  let end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PER_PAGE;
748
- return "*[_type == \"mux.videoAsset\"] | order(_updatedAt desc) [".concat(start, "...").concat(end, "]");
750
+ return (/* groq */"*[_type == \"mux.videoAsset\"] | order(_updatedAt desc) [".concat(start, "...").concat(end, "]")
751
+ );
749
752
  }
750
753
  function SelectAssets(_ref3) {
751
754
  let {
@@ -852,7 +855,8 @@ function EditThumbnailDialog(_ref6) {
852
855
  const client = useClient();
853
856
  const dialogId = "EditThumbnailDialog".concat(useId());
854
857
  const nextTime = useMemo(() => getCurrentTime(), [getCurrentTime]);
855
- const assetWithNewThumbnail = useMemo(() => _objectSpread(_objectSpread({}, asset), {}, {
858
+ const assetWithNewThumbnail = useMemo(() => ({
859
+ ...asset,
856
860
  thumbTime: nextTime
857
861
  }), [asset, nextTime]);
858
862
  const [saving, setSaving] = useState(false);
@@ -1027,7 +1031,7 @@ const UploadProgress = _ref10 => {
1027
1031
  })
1028
1032
  });
1029
1033
  };
1030
- const MuxVideo = _ref11 => {
1034
+ const MuxVideoOld = _ref11 => {
1031
1035
  let {
1032
1036
  asset,
1033
1037
  buttons,
@@ -1091,20 +1095,6 @@ const MuxVideo = _ref11 => {
1091
1095
  muteRef.current.shadowRoot.appendChild(style.cloneNode(true));
1092
1096
  }
1093
1097
  }, []);
1094
- const [playerInitTime] = useState(() => generatePlayerInitTime());
1095
- const playbackEngineRef = useRef(void 0);
1096
- useEffect(() => {
1097
- if (isLoading || !videoSrc) {
1098
- return;
1099
- }
1100
- const nextPlaybackEngineRef = initialize({
1101
- src: videoSrc,
1102
- playerInitTime,
1103
- playerSoftwareName: "sanity-plugin-mux-input",
1104
- playerSoftwareVersion: "dev-preview"
1105
- }, video.current, playbackEngineRef.current);
1106
- playbackEngineRef.current = nextPlaybackEngineRef;
1107
- }, [videoSrc, isLoading, playerInitTime]);
1108
1098
  useEffect(() => {
1109
1099
  var _a2, _b2, _c2;
1110
1100
  if ((asset == null ? void 0 : asset.status) === "errored") {
@@ -1112,6 +1102,14 @@ const MuxVideo = _ref11 => {
1112
1102
  throw new Error((_c2 = (_b2 = (_a2 = asset.data) == null ? void 0 : _a2.errors) == null ? void 0 : _b2.messages) == null ? void 0 : _c2.join(" "));
1113
1103
  }
1114
1104
  }, [(_d = (_c = asset.data) == null ? void 0 : _c.errors) == null ? void 0 : _d.messages, asset == null ? void 0 : asset.status, handleCancelUpload]);
1105
+ const signedToken = useMemo(() => {
1106
+ try {
1107
+ const url = new URL(videoSrc);
1108
+ return url.searchParams.get("token");
1109
+ } catch {
1110
+ return false;
1111
+ }
1112
+ }, [videoSrc]);
1115
1113
  if (error) {
1116
1114
  throw error;
1117
1115
  }
@@ -1132,9 +1130,10 @@ const MuxVideo = _ref11 => {
1132
1130
  tone: "transparent",
1133
1131
  scheme: "dark",
1134
1132
  children: [/* @__PURE__ */jsxs(MediaController, {
1135
- children: [/* @__PURE__ */jsx("video", {
1133
+ children: [/* @__PURE__ */jsx(MuxVideo, {
1136
1134
  playsInline: true,
1137
1135
  ref: video,
1136
+ playbackId: "".concat(asset.playbackId).concat(signedToken ? "?token=".concat(signedToken) : ""),
1138
1137
  onError: handleError,
1139
1138
  slot: "media",
1140
1139
  preload: "metadata",
@@ -1214,20 +1213,20 @@ const FileButton = styled(MenuItem)(_ref12 => {
1214
1213
  });
1215
1214
  const FileInputMenuItem = React.forwardRef(function FileInputMenuItem2(props, forwardedRef) {
1216
1215
  const {
1217
- icon,
1218
- id: idProp,
1219
- accept,
1220
- capture,
1221
- fontSize,
1222
- multiple,
1223
- onSelect,
1224
- padding = 3,
1225
- space = 3,
1226
- textAlign,
1227
- text,
1228
- disabled
1229
- } = props,
1230
- rest = _objectWithoutProperties(props, _excluded);
1216
+ icon,
1217
+ id: idProp,
1218
+ accept,
1219
+ capture,
1220
+ fontSize,
1221
+ multiple,
1222
+ onSelect,
1223
+ padding = 3,
1224
+ space = 3,
1225
+ textAlign,
1226
+ text,
1227
+ disabled,
1228
+ ...rest
1229
+ } = props;
1231
1230
  const idHook = useId();
1232
1231
  const id = idProp || idHook;
1233
1232
  const handleChange = React.useCallback(event => {
@@ -1252,7 +1251,8 @@ const FileInputMenuItem = React.forwardRef(function FileInputMenuItem2(props, fo
1252
1251
  children: text
1253
1252
  })]
1254
1253
  });
1255
- return /* @__PURE__ */jsxs(FileButton, _objectSpread(_objectSpread({}, rest), {}, {
1254
+ return /* @__PURE__ */jsxs(FileButton, {
1255
+ ...rest,
1256
1256
  htmlFor: id,
1257
1257
  padding: 0,
1258
1258
  fontSize: 2,
@@ -1269,7 +1269,7 @@ const FileInputMenuItem = React.forwardRef(function FileInputMenuItem2(props, fo
1269
1269
  value: "",
1270
1270
  disabled
1271
1271
  })]
1272
- }));
1272
+ });
1273
1273
  });
1274
1274
  const LockCard = styled(Card)(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n opacity: 0.6;\n mix-blend-mode: screen;\n background: transparent;\n"])));
1275
1275
  const LockButton = styled(Button)(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n background: transparent;\n color: white;\n"])));
@@ -1439,9 +1439,9 @@ const HiddenInput = styled.input(_templateObject15 || (_templateObject15 = _tagg
1439
1439
  const Label = styled.label(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n"])));
1440
1440
  const FileInputButton = _ref14 => {
1441
1441
  let {
1442
- onSelect
1443
- } = _ref14,
1444
- props = _objectWithoutProperties(_ref14, _excluded2);
1442
+ onSelect,
1443
+ ...props
1444
+ } = _ref14;
1445
1445
  const inputId = "FileSelect".concat(useId());
1446
1446
  const inputRef = useRef(null);
1447
1447
  const handleSelect = useCallback(event => {
@@ -1463,14 +1463,15 @@ const FileInputButton = _ref14 => {
1463
1463
  id: inputId,
1464
1464
  onChange: handleSelect,
1465
1465
  value: ""
1466
- }), /* @__PURE__ */jsx(Button, _objectSpread({
1466
+ }), /* @__PURE__ */jsx(Button, {
1467
1467
  onClick: handleButtonClick,
1468
1468
  mode: "default",
1469
1469
  tone: "primary",
1470
1470
  style: {
1471
1471
  width: "100%"
1472
- }
1473
- }, props))]
1472
+ },
1473
+ ...props
1474
+ })]
1474
1475
  });
1475
1476
  };
1476
1477
  const UploadCard = styled(Card)(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n && {\n border-style: dashed;\n }\n"])));
@@ -1571,6 +1572,8 @@ class MuxVideoInputUploader extends Component {
1571
1572
  };
1572
1573
  this.dragEnteredEls = [];
1573
1574
  this.ctrlDown = false;
1575
+ // eslint-disable-next-line no-warning-comments
1576
+ // @TODO add proper typings for the return values of uploadFile and uploadUrl
1574
1577
  this.upload = null;
1575
1578
  this.container = React.createRef();
1576
1579
  this.handleProgress = evt => {
@@ -1610,6 +1613,8 @@ class MuxVideoInputUploader extends Component {
1610
1613
  }
1611
1614
  });
1612
1615
  };
1616
+ // eslint-disable-next-line no-warning-comments
1617
+ // @TODO add proper typings for the Observable events
1613
1618
  this.handleUploadEvent = event => {
1614
1619
  switch (event.type) {
1615
1620
  case "success":
@@ -1756,7 +1761,7 @@ class MuxVideoInputUploader extends Component {
1756
1761
  onDragEnter: this.handleDragEnter,
1757
1762
  onPaste: this.handlePaste,
1758
1763
  ref: this.container,
1759
- children: this.props.asset ? /* @__PURE__ */jsx(MuxVideo, {
1764
+ children: this.props.asset ? /* @__PURE__ */jsx(MuxVideoOld, {
1760
1765
  readOnly: this.props.readOnly,
1761
1766
  asset: this.props.asset,
1762
1767
  onChange: this.props.onChange,
@@ -1840,6 +1845,8 @@ function init(_ref16) {
1840
1845
  return {
1841
1846
  submitting: false,
1842
1847
  error: null,
1848
+ // Form inputs don't set the state back to null when clearing a field, but uses empty strings
1849
+ // This ensures the `dirty` check works correctly
1843
1850
  token: token != null ? token : "",
1844
1851
  secretKey: secretKey != null ? secretKey : "",
1845
1852
  enableSignedUrls: enableSignedUrls != null ? enableSignedUrls : false
@@ -1848,21 +1855,24 @@ function init(_ref16) {
1848
1855
  function reducer(state, action) {
1849
1856
  switch (action == null ? void 0 : action.type) {
1850
1857
  case "submit":
1851
- return _objectSpread(_objectSpread({}, state), {}, {
1858
+ return {
1859
+ ...state,
1852
1860
  submitting: true,
1853
1861
  error: null
1854
- });
1862
+ };
1855
1863
  case "error":
1856
- return _objectSpread(_objectSpread({}, state), {}, {
1864
+ return {
1865
+ ...state,
1857
1866
  submitting: false,
1858
1867
  error: action.payload
1859
- });
1868
+ };
1860
1869
  case "reset":
1861
1870
  return init(action.payload);
1862
1871
  case "change":
1863
- return _objectSpread(_objectSpread({}, state), {}, {
1872
+ return {
1873
+ ...state,
1864
1874
  [action.payload.name]: action.payload.value
1865
- });
1875
+ };
1866
1876
  default:
1867
1877
  throw new Error("Unknown action type: ".concat(action == null ? void 0 : action.type));
1868
1878
  }
@@ -2615,7 +2625,8 @@ const Input = props => {
2615
2625
  children: isLoading ? /* @__PURE__ */jsx(InputFallback, {}) : /* @__PURE__ */jsxs(Fragment, {
2616
2626
  children: [secretDocumentValues.value.needsSetup && !assetDocumentValues.value ? /* @__PURE__ */jsx(Onboard, {
2617
2627
  setDialogState
2618
- }) : /* @__PURE__ */jsx(MuxVideoInputUploader, _objectSpread(_objectSpread({}, props), {}, {
2628
+ }) : /* @__PURE__ */jsx(MuxVideoInputUploader, {
2629
+ ...props,
2619
2630
  config: props.config,
2620
2631
  onChange: props.onChange,
2621
2632
  client,
@@ -2624,7 +2635,7 @@ const Input = props => {
2624
2635
  dialogState,
2625
2636
  setDialogState,
2626
2637
  needsSetup: secretDocumentValues.value.needsSetup
2627
- })), dialogState === "secrets" && /* @__PURE__ */jsx(ConfigureApi$1, {
2638
+ }), dialogState === "secrets" && /* @__PURE__ */jsx(ConfigureApi$1, {
2628
2639
  setDialogState,
2629
2640
  secrets: secretDocumentValues.value.secrets
2630
2641
  })]
@@ -2633,4 +2644,4 @@ const Input = props => {
2633
2644
  };
2634
2645
  var Input$1 = memo(Input);
2635
2646
  export { Input$1 as default };
2636
- //# sourceMappingURL=Input-aa6d929b.js.map
2647
+ //# sourceMappingURL=Input-235cb658.js.map