sanity-plugin-mux-input 2.0.16 → 2.1.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.
Files changed (36) hide show
  1. package/lib/_chunks/Player-d8f163ed.cjs +474 -0
  2. package/lib/_chunks/Player-d8f163ed.cjs.map +1 -0
  3. package/lib/_chunks/Player-fb9712c0.js +465 -0
  4. package/lib/_chunks/Player-fb9712c0.js.map +1 -0
  5. package/lib/_chunks/index-0656ede8.js +3229 -0
  6. package/lib/_chunks/index-0656ede8.js.map +1 -0
  7. package/lib/_chunks/index-9cd542f1.cjs +3271 -0
  8. package/lib/_chunks/index-9cd542f1.cjs.map +1 -0
  9. package/lib/index.cjs +1 -1
  10. package/lib/index.d.ts +97 -0
  11. package/lib/index.js +1 -1
  12. package/package.json +16 -17
  13. package/src/components/Input.tsx +34 -29
  14. package/src/components/__legacy__Uploader.tsx +7 -2
  15. package/src/index.ts +8 -49
  16. package/src/plugin.tsx +31 -0
  17. package/src/schema.tsx +42 -0
  18. package/lib/_chunks/Input-509c8fa5.cjs +0 -189
  19. package/lib/_chunks/Input-509c8fa5.cjs.map +0 -1
  20. package/lib/_chunks/Input-9ddeac65.js +0 -189
  21. package/lib/_chunks/Input-9ddeac65.js.map +0 -1
  22. package/lib/_chunks/Preview-04fe7cde.js +0 -26
  23. package/lib/_chunks/Preview-04fe7cde.js.map +0 -1
  24. package/lib/_chunks/Preview-442a88cd.cjs +0 -28
  25. package/lib/_chunks/Preview-442a88cd.cjs.map +0 -1
  26. package/lib/_chunks/VideoSource.styled-45ab4b64.js +0 -318
  27. package/lib/_chunks/VideoSource.styled-45ab4b64.js.map +0 -1
  28. package/lib/_chunks/VideoSource.styled-cb41adac.cjs +0 -336
  29. package/lib/_chunks/VideoSource.styled-cb41adac.cjs.map +0 -1
  30. package/lib/_chunks/index-d360f7ae.cjs +0 -265
  31. package/lib/_chunks/index-d360f7ae.cjs.map +0 -1
  32. package/lib/_chunks/index-f8b48f62.js +0 -248
  33. package/lib/_chunks/index-f8b48f62.js.map +0 -1
  34. package/src/components/FormInput.tsx +0 -26
  35. package/src/components/FormPreview.tsx +0 -19
  36. package/src/components/Preview.tsx +0 -33
package/lib/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import type {PartialDeep} from 'type-fest'
1
2
  import {Plugin as Plugin_2} from 'sanity'
3
+ import type {SanityDocument} from 'sanity'
2
4
 
3
5
  declare interface Config {
4
6
  /**
@@ -11,6 +13,101 @@ declare interface Config {
11
13
 
12
14
  export declare const defaultConfig: Config
13
15
 
16
+ declare interface MuxAsset {
17
+ id: string
18
+ created_at: string
19
+ status: 'preparing' | 'ready' | 'errored'
20
+ duration: number
21
+ max_stored_resolution: 'Audio only' | 'SD' | 'HD' | 'FHD' | 'UHD'
22
+ max_stored_frame_rate: -1 | number
23
+ aspect_ratio: `${number}:${number}`
24
+ playback_ids: MuxPlaybackId[]
25
+ tracks: MuxTrack[]
26
+ errors?: MuxErrors
27
+ upload_id: string
28
+ is_live?: boolean
29
+ passthrough: string
30
+ live_stream_id?: string
31
+ master?: {
32
+ status: 'ready' | 'preparing' | 'errored'
33
+ url: string
34
+ }
35
+ master_access: 'temporary' | 'none'
36
+ mp4_support: 'standard' | 'none'
37
+ source_asset_id?: string
38
+ normalize_audio?: boolean
39
+ static_renditions?: {
40
+ status: 'ready' | 'preparing' | 'disabled' | 'errored'
41
+ files: {
42
+ name: 'low.mp4' | 'medium.mp4' | 'high.mp4' | 'audio.m4a'
43
+ ext: 'mp4' | 'm4a'
44
+ height: number
45
+ width: number
46
+ bitrate: number
47
+ filesize: number
48
+ }[]
49
+ }
50
+ recording_times?: {
51
+ started_at: string
52
+ duration: number
53
+ type: 'content' | 'slate'
54
+ }[]
55
+ non_standard_input_reasons?: {
56
+ video_codec?: string
57
+ audio_codec?: string
58
+ video_gop_size?: 'high'
59
+ video_frame_rate?: string
60
+ video_resolution?: string
61
+ video_bitrate?: 'high'
62
+ pixel_aspect_ratio?: string
63
+ video_edit_list?: 'non-standard'
64
+ audio_edit_list?: 'non-standard'
65
+ unexpected_media_file_parameters?: 'non-standard'
66
+ test?: boolean
67
+ }
68
+ }
69
+
70
+ declare interface MuxAudioTrack {
71
+ type: 'audio'
72
+ id: string
73
+ duration?: number
74
+ max_channels: number
75
+ max_channel_layout: 'stereo' | string
76
+ }
77
+
78
+ declare interface MuxErrors {
79
+ type: string
80
+ messages: string[]
81
+ }
82
+
14
83
  export declare const muxInput: Plugin_2<void | Partial<Config>>
15
84
 
85
+ declare interface MuxPlaybackId {
86
+ id: string
87
+ policy: PlaybackPolicy
88
+ }
89
+
90
+ declare type MuxTrack = MuxVideoTrack | MuxAudioTrack
91
+
92
+ declare interface MuxVideoTrack {
93
+ type: 'video'
94
+ id: string
95
+ max_width: number
96
+ max_height: number
97
+ max_frame_rate: -1 | number
98
+ duration?: number
99
+ }
100
+
101
+ declare type PlaybackPolicy = 'signed' | 'public'
102
+
103
+ export declare interface VideoAssetDocument extends Partial<SanityDocument> {
104
+ type?: 'mux.videoAsset'
105
+ status?: string
106
+ assetId?: string
107
+ playbackId?: string
108
+ filename?: string
109
+ thumbTime?: number
110
+ data?: PartialDeep<MuxAsset>
111
+ }
112
+
16
113
  export {}
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import 'sanity';
2
- export { defaultConfig, muxInput } from './_chunks/index-f8b48f62.js';
2
+ export { defaultConfig, muxInput } from './_chunks/index-0656ede8.js';
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanity-plugin-mux-input",
3
- "version": "2.0.16",
3
+ "version": "2.1.0",
4
4
  "description": "An input component that integrates Sanity Studio with Mux video encoding/hosting service.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -42,23 +42,23 @@
42
42
  "source": "./src/index.ts",
43
43
  "types": "./lib/index.d.ts",
44
44
  "files": [
45
+ "src",
45
46
  "lib",
46
47
  "sanity.json",
47
- "src",
48
48
  "v2-incompatible.js"
49
49
  ],
50
50
  "scripts": {
51
51
  "build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
52
52
  "clean": "rimraf lib",
53
53
  "dev": "next dev",
54
+ "format": "prettier --write --cache --ignore-unknown .",
54
55
  "link-watch": "plugin-kit link-watch",
55
56
  "lint": "eslint .",
56
57
  "prepare": "husky install || true",
57
58
  "prepublishOnly": "run-s build",
58
59
  "test": "npm run lint && npm run type-check && npm run build",
59
60
  "type-check": "tsc --noEmit",
60
- "watch": "pkg-utils watch --strict",
61
- "format": "prettier --write --cache --ignore-unknown ."
61
+ "watch": "pkg-utils watch --strict"
62
62
  },
63
63
  "dependencies": {
64
64
  "@mux/mux-video-react": "^0.7.7",
@@ -68,12 +68,12 @@
68
68
  "@sanity/ui": "^1",
69
69
  "@sanity/uuid": "^3",
70
70
  "classnames": "^2.3.2",
71
- "jsonwebtoken-esm": "^2.0.1",
72
- "media-chrome": "^0.18.6",
71
+ "jsonwebtoken-esm": "^1.0.5",
72
+ "media-chrome": "^0.21.0",
73
73
  "motion": "^10",
74
74
  "rxjs": "^7",
75
75
  "scroll-into-view-if-needed": "^3",
76
- "suspend-react": "^0.0.9",
76
+ "suspend-react": "^0.0.10",
77
77
  "swr": "^2.1.0",
78
78
  "use-device-pixel-ratio": "^1.1.2",
79
79
  "use-error-boundary": "^2.0.6"
@@ -81,16 +81,16 @@
81
81
  "devDependencies": {
82
82
  "@commitlint/cli": "^17.4.4",
83
83
  "@commitlint/config-conventional": "^17.4.4",
84
- "@sanity/pkg-utils": "^2.2.8",
84
+ "@sanity/pkg-utils": "^2.2.13",
85
85
  "@sanity/plugin-kit": "^3.1.7",
86
86
  "@sanity/semantic-release-preset": "^4.0.0",
87
- "@sanity/vision": "^3.5.1",
87
+ "@sanity/vision": "^3.6.0",
88
88
  "@types/react": "^18.0.28",
89
89
  "@types/styled-components": "^5.1.26",
90
90
  "@typescript-eslint/eslint-plugin": "^5.54.1",
91
91
  "@typescript-eslint/parser": "^5.54.1",
92
92
  "cz-conventional-changelog": "^3.3.0",
93
- "eslint": "^8.35.0",
93
+ "eslint": "^8.36.0",
94
94
  "eslint-config-prettier": "^8.7.0",
95
95
  "eslint-config-react-app": "^7.0.1",
96
96
  "eslint-config-sanity": "^6.0.0",
@@ -100,8 +100,8 @@
100
100
  "eslint-plugin-react-hooks": "^4.6.0",
101
101
  "eslint-plugin-simple-import-sort": "^10.0.0",
102
102
  "husky": "^8.0.3",
103
- "lint-staged": "^13.1.2",
104
- "next": "^13.2.3",
103
+ "lint-staged": "^13.2.0",
104
+ "next": "^13.2.4",
105
105
  "next-sanity": "^4.1.5",
106
106
  "npm-run-all": "^4.1.5",
107
107
  "prettier": "^2.8.4",
@@ -109,15 +109,14 @@
109
109
  "react": "^18.2.0",
110
110
  "react-dom": "^18.2.0",
111
111
  "react-is": "^18.2.0",
112
- "rimraf": "^4.1.2",
113
- "sanity": "^3.5.1",
114
- "styled-components": "^5.3.8",
112
+ "rimraf": "^5.0.0",
113
+ "sanity": "^3.6.0",
114
+ "styled-components": "^5.3.9",
115
115
  "type-fest": "^3.6.1",
116
- "typescript": "^4.9.5"
116
+ "typescript": "^5.0.2"
117
117
  },
118
118
  "peerDependencies": {
119
119
  "react": "^18",
120
- "react-is": "^18",
121
120
  "sanity": "^3",
122
121
  "styled-components": "^5.2"
123
122
  },
@@ -1,4 +1,4 @@
1
- import React, {memo} from 'react'
1
+ import React, {memo, Suspense} from 'react'
2
2
 
3
3
  import {useAssetDocumentValues} from '../hooks/useAssetDocumentValues'
4
4
  import {useClient} from '../hooks/useClient'
@@ -8,7 +8,8 @@ import {useSecretsDocumentValues} from '../hooks/useSecretsDocumentValues'
8
8
  import type {Config, MuxInputProps} from '../util/types'
9
9
  import Uploader from './__legacy__Uploader'
10
10
  import ConfigureApi from './ConfigureApi'
11
- import {InputFallback} from './Input.styled'
11
+ import ErrorBoundaryCard from './ErrorBoundaryCard'
12
+ import {AspectRatioCard, InputFallback} from './Input.styled'
12
13
  import Onboard from './Onboard'
13
14
 
14
15
  export interface InputProps extends MuxInputProps {
@@ -34,36 +35,40 @@ const Input = (props: InputProps) => {
34
35
  const isLoading = secretDocumentValues.isLoading || assetDocumentValues.isLoading
35
36
 
36
37
  return (
37
- <>
38
- {isLoading ? (
39
- <InputFallback />
40
- ) : (
41
- <>
42
- {secretDocumentValues.value.needsSetup && !assetDocumentValues.value ? (
43
- <Onboard setDialogState={setDialogState} />
38
+ <AspectRatioCard>
39
+ <ErrorBoundaryCard schemaType={props.schemaType}>
40
+ <Suspense fallback={<InputFallback />}>
41
+ {isLoading ? (
42
+ <InputFallback />
44
43
  ) : (
45
- <Uploader
46
- {...props}
47
- config={props.config}
48
- onChange={props.onChange}
49
- client={client}
50
- secrets={secretDocumentValues.value.secrets}
51
- asset={assetDocumentValues.value}
52
- dialogState={dialogState}
53
- setDialogState={setDialogState}
54
- needsSetup={secretDocumentValues.value.needsSetup}
55
- />
56
- )}
44
+ <>
45
+ {secretDocumentValues.value.needsSetup && !assetDocumentValues.value ? (
46
+ <Onboard setDialogState={setDialogState} />
47
+ ) : (
48
+ <Uploader
49
+ {...props}
50
+ config={props.config}
51
+ onChange={props.onChange}
52
+ client={client}
53
+ secrets={secretDocumentValues.value.secrets}
54
+ asset={assetDocumentValues.value}
55
+ dialogState={dialogState}
56
+ setDialogState={setDialogState}
57
+ needsSetup={secretDocumentValues.value.needsSetup}
58
+ />
59
+ )}
57
60
 
58
- {dialogState === 'secrets' && (
59
- <ConfigureApi
60
- setDialogState={setDialogState}
61
- secrets={secretDocumentValues.value.secrets}
62
- />
61
+ {dialogState === 'secrets' && (
62
+ <ConfigureApi
63
+ setDialogState={setDialogState}
64
+ secrets={secretDocumentValues.value.secrets}
65
+ />
66
+ )}
67
+ </>
63
68
  )}
64
- </>
65
- )}
66
- </>
69
+ </Suspense>
70
+ </ErrorBoundaryCard>
71
+ </AspectRatioCard>
67
72
  )
68
73
  }
69
74
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
  // This component needs to be refactored into a functional component
3
3
 
4
- import React, {Component} from 'react'
4
+ import React, {lazy, Component} from 'react'
5
5
  import {type Observable, Subject} from 'rxjs'
6
6
  import {takeUntil, tap} from 'rxjs/operators'
7
7
  import type {SanityClient} from 'sanity'
@@ -12,12 +12,17 @@ import {type DialogState, type SetDialogState} from '../hooks/useDialogState'
12
12
  import {extractDroppedFiles} from '../util/extractFiles'
13
13
  import type {Config, MuxInputProps, Secrets, VideoAssetDocument} from '../util/types'
14
14
  import InputBrowser from './InputBrowser'
15
- import Player from './Player'
16
15
  import PlayerActionsMenu from './PlayerActionsMenu'
17
16
  import {UploadCard} from './Uploader.styled'
18
17
  import UploadPlaceholder from './UploadPlaceholder'
19
18
  import {UploadProgress} from './UploadProgress'
20
19
 
20
+ // TODO: Without this lazy load call a build error occurs in the Player component from the import
21
+ // of media-chrome components. media-chrome ships separate ESM and CJS compatible modules in versions >=1.0.0.
22
+ // Once the plugin is updated to media-chrome >= 1.0.0, remove this lazy load.
23
+ // import Player from './Player'
24
+ const Player = lazy(() => import('./Player'))
25
+
21
26
  interface Props extends Pick<MuxInputProps, 'onChange' | 'readOnly'> {
22
27
  config: Config
23
28
  client: SanityClient
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import {definePlugin} from 'sanity'
2
2
 
3
- import createFormInput from './components/FormInput'
4
- import FormPreview from './components/FormPreview'
5
- import {type Config} from './util/types'
3
+ import {muxVideoCustomRendering} from './plugin'
4
+ import {muxVideo, muxVideoAsset} from './schema'
5
+ import type {Config} from './util/types'
6
+
7
+ export type {VideoAssetDocument} from './util/types'
6
8
 
7
9
  export const defaultConfig: Config = {
8
10
  mp4_support: 'none',
@@ -10,57 +12,14 @@ export const defaultConfig: Config = {
10
12
 
11
13
  export const muxInput = definePlugin<Partial<Config> | void>((userConfig) => {
12
14
  const config: Config = {...defaultConfig, ...userConfig}
13
- const InputComponent = createFormInput(config)
14
15
  return {
15
16
  name: 'mux-input',
16
- form: {
17
- components: {
18
- input: InputComponent,
19
- preview: FormPreview,
20
- },
21
- },
22
17
  schema: {
23
18
  types: [
19
+ muxVideoAsset,
24
20
  {
25
- name: 'mux.video',
26
- type: 'object',
27
- title: 'Video asset reference',
28
- fields: [
29
- {
30
- title: 'Video',
31
- name: 'asset',
32
- type: 'reference',
33
- weak: true,
34
- to: [{type: 'mux.videoAsset'}],
35
- },
36
- ],
37
- },
38
- {
39
- name: 'mux.videoAsset',
40
- type: 'object',
41
- title: 'Video asset',
42
- fields: [
43
- {
44
- type: 'string',
45
- name: 'status',
46
- },
47
- {
48
- type: 'string',
49
- name: 'assetId',
50
- },
51
- {
52
- type: 'string',
53
- name: 'playbackId',
54
- },
55
- {
56
- type: 'string',
57
- name: 'filename',
58
- },
59
- {
60
- type: 'number',
61
- name: 'thumbTime',
62
- },
63
- ],
21
+ ...muxVideo,
22
+ ...muxVideoCustomRendering(config),
64
23
  },
65
24
  ],
66
25
  },
package/src/plugin.tsx ADDED
@@ -0,0 +1,31 @@
1
+ import React from 'react'
2
+
3
+ import Input from './components/Input'
4
+ import {VideoThumbnail} from './components/VideoSource.styled'
5
+ import type {Config, MuxInputProps, VideoAssetDocument} from './util/types'
6
+
7
+ export function muxVideoCustomRendering(config: Config) {
8
+ return {
9
+ components: {
10
+ input: (props: MuxInputProps) => <Input config={config} {...props} />,
11
+ },
12
+ preview: {
13
+ select: {
14
+ filename: 'asset.filename',
15
+ playbackId: 'asset.playbackId',
16
+ status: 'asset.status',
17
+ assetId: 'asset.assetId',
18
+ thumbTime: 'asset.thumbTime',
19
+ data: 'asset.data',
20
+ },
21
+ prepare: (asset: Partial<VideoAssetDocument>) => {
22
+ const {filename, playbackId, status} = asset
23
+ return {
24
+ title: filename || playbackId || '',
25
+ subtitle: status ? `status: ${status}` : null,
26
+ media: asset.playbackId ? <VideoThumbnail asset={asset} width={64} /> : null,
27
+ }
28
+ },
29
+ },
30
+ }
31
+ }
package/src/schema.tsx ADDED
@@ -0,0 +1,42 @@
1
+ export const muxVideo = {
2
+ name: 'mux.video',
3
+ type: 'object',
4
+ title: 'Video asset reference',
5
+ fields: [
6
+ {
7
+ title: 'Video',
8
+ name: 'asset',
9
+ type: 'reference',
10
+ weak: true,
11
+ to: [{type: 'mux.videoAsset'}],
12
+ },
13
+ ],
14
+ }
15
+
16
+ export const muxVideoAsset = {
17
+ name: 'mux.videoAsset',
18
+ type: 'object',
19
+ title: 'Video asset',
20
+ fields: [
21
+ {
22
+ type: 'string',
23
+ name: 'status',
24
+ },
25
+ {
26
+ type: 'string',
27
+ name: 'assetId',
28
+ },
29
+ {
30
+ type: 'string',
31
+ name: 'playbackId',
32
+ },
33
+ {
34
+ type: 'string',
35
+ name: 'filename',
36
+ },
37
+ {
38
+ type: 'number',
39
+ name: 'thumbTime',
40
+ },
41
+ ],
42
+ }