sanity-plugin-mux-input 2.11.2 → 2.12.1
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/README.md +49 -5
- package/dist/index.d.mts +36 -2
- package/dist/index.d.ts +36 -2
- package/dist/index.js +169 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +169 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/_exports/index.ts +26 -2
- package/src/actions/upload.ts +1 -1
- package/src/components/Player.tsx +14 -5
- package/src/components/UploadConfiguration.tsx +190 -30
- package/src/hooks/useMuxPolling.ts +20 -4
- package/src/schema.ts +9 -3
- package/src/util/types.ts +47 -10
package/dist/index.mjs
CHANGED
|
@@ -1526,7 +1526,7 @@ function VideoPlayer({
|
|
|
1526
1526
|
crossOrigin: "anonymous",
|
|
1527
1527
|
metadata: {
|
|
1528
1528
|
player_name: "Sanity Admin Dashboard",
|
|
1529
|
-
player_version: "2.
|
|
1529
|
+
player_version: "2.12.1",
|
|
1530
1530
|
page_type: "Preview Player"
|
|
1531
1531
|
},
|
|
1532
1532
|
audio: isAudio,
|
|
@@ -2436,9 +2436,14 @@ const useAccessControl = (config) => {
|
|
|
2436
2436
|
isReference(asset) ? asset._ref : "",
|
|
2437
2437
|
path
|
|
2438
2438
|
), useMuxPolling = (asset) => {
|
|
2439
|
-
const client = useClient(), projectId = useProjectId(), dataset = useDataset(),
|
|
2440
|
-
|
|
2441
|
-
|
|
2439
|
+
const client = useClient(), projectId = useProjectId(), dataset = useDataset(), isPreparingStaticRenditions = useMemo(() => {
|
|
2440
|
+
if (asset?.data?.static_renditions?.status && asset?.data?.static_renditions?.status !== "disabled")
|
|
2441
|
+
return !1;
|
|
2442
|
+
const files = asset?.data?.static_renditions?.files;
|
|
2443
|
+
return !files || files.length === 0 ? !1 : files.some((file) => file.status === "preparing");
|
|
2444
|
+
}, [asset?.data?.static_renditions?.status, asset?.data?.static_renditions?.files]), shouldFetch = useMemo(
|
|
2445
|
+
() => !!asset?.assetId && (asset?.status === "preparing" || isPreparingStaticRenditions),
|
|
2446
|
+
[asset?.assetId, asset?.status, isPreparingStaticRenditions]
|
|
2442
2447
|
);
|
|
2443
2448
|
return useSWR(
|
|
2444
2449
|
shouldFetch ? `/${projectId}/addons/mux/assets/${dataset}/data/${asset?.assetId}` : null,
|
|
@@ -2927,7 +2932,12 @@ const TopControls = styled.div`
|
|
|
2927
2932
|
) : null
|
|
2928
2933
|
] }) });
|
|
2929
2934
|
}, Player = ({ asset, buttons, readOnly, onChange }) => {
|
|
2930
|
-
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(() =>
|
|
2935
|
+
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(() => {
|
|
2936
|
+
if (asset?.data?.static_renditions?.status && asset?.data?.static_renditions?.status !== "disabled")
|
|
2937
|
+
return !1;
|
|
2938
|
+
const files = asset?.data?.static_renditions?.files;
|
|
2939
|
+
return !files || files.length === 0 ? !1 : files.some((file) => file.status === "preparing");
|
|
2940
|
+
}, [asset?.data?.static_renditions?.status, asset?.data?.static_renditions?.files]), playRef = useRef(null), muteRef = useRef(null), handleCancelUpload = useCancelUpload(asset, onChange);
|
|
2931
2941
|
return useEffect(() => {
|
|
2932
2942
|
const style = document.createElement("style");
|
|
2933
2943
|
style.innerHTML = "button svg { vertical-align: middle; }", playRef.current?.shadowRoot && playRef.current.shadowRoot.appendChild(style), muteRef?.current?.shadowRoot && muteRef.current.shadowRoot.appendChild(style.cloneNode(!0));
|
|
@@ -3348,7 +3358,20 @@ const VIDEO_QUALITY_LEVELS = [
|
|
|
3348
3358
|
{ value: "1080p", label: "1080p" },
|
|
3349
3359
|
{ value: "1440p", label: "1440p (2k)" },
|
|
3350
3360
|
{ value: "2160p", label: "2160p (4k)" }
|
|
3361
|
+
], ADVANCED_RESOLUTIONS = [
|
|
3362
|
+
{ value: "270p", label: "270p" },
|
|
3363
|
+
{ value: "360p", label: "360p" },
|
|
3364
|
+
{ value: "480p", label: "480p" },
|
|
3365
|
+
{ value: "540p", label: "540p" },
|
|
3366
|
+
{ value: "720p", label: "720p" },
|
|
3367
|
+
{ value: "1080p", label: "1080p" },
|
|
3368
|
+
{ value: "1440p", label: "1440p" },
|
|
3369
|
+
{ value: "2160p", label: "2160p" }
|
|
3351
3370
|
];
|
|
3371
|
+
function sanitizeStaticRenditions(renditions) {
|
|
3372
|
+
const hasHighest = renditions.includes("highest"), hasSpecificResolutions = renditions.some((r) => r !== "highest" && r !== "audio-only");
|
|
3373
|
+
return hasHighest && hasSpecificResolutions ? renditions.filter((r) => r === "highest" || r === "audio-only") : renditions;
|
|
3374
|
+
}
|
|
3352
3375
|
function UploadConfiguration({
|
|
3353
3376
|
stagedUpload,
|
|
3354
3377
|
secrets,
|
|
@@ -3371,18 +3394,18 @@ function UploadConfiguration({
|
|
|
3371
3394
|
case "video_quality":
|
|
3372
3395
|
return action.value === "basic" ? Object.assign({}, prev, {
|
|
3373
3396
|
video_quality: action.value,
|
|
3374
|
-
|
|
3397
|
+
static_renditions: [],
|
|
3375
3398
|
max_resolution_tier: "1080p",
|
|
3376
3399
|
text_tracks: prev.text_tracks?.filter(({ type }) => type !== "autogenerated"),
|
|
3377
3400
|
public_policy: !0,
|
|
3378
3401
|
signed_policy: !1
|
|
3379
3402
|
}) : Object.assign({}, prev, {
|
|
3380
3403
|
video_quality: action.value,
|
|
3381
|
-
|
|
3404
|
+
static_renditions: sanitizeStaticRenditions(pluginConfig.static_renditions || []),
|
|
3382
3405
|
max_resolution_tier: pluginConfig.max_resolution_tier,
|
|
3383
3406
|
text_tracks: [...autoTextTracks, ...prev.text_tracks || []]
|
|
3384
3407
|
});
|
|
3385
|
-
case "
|
|
3408
|
+
case "static_renditions":
|
|
3386
3409
|
case "max_resolution_tier":
|
|
3387
3410
|
case "normalize_audio":
|
|
3388
3411
|
case "signed_policy":
|
|
@@ -3421,13 +3444,34 @@ function UploadConfiguration({
|
|
|
3421
3444
|
{
|
|
3422
3445
|
video_quality: pluginConfig.video_quality,
|
|
3423
3446
|
max_resolution_tier: pluginConfig.max_resolution_tier,
|
|
3424
|
-
|
|
3447
|
+
static_renditions: sanitizeStaticRenditions(pluginConfig.static_renditions || []),
|
|
3425
3448
|
signed_policy: secrets.enableSignedUrls && pluginConfig.defaultSigned,
|
|
3426
3449
|
public_policy: pluginConfig.defaultPublic,
|
|
3427
3450
|
normalize_audio: pluginConfig.normalize_audio,
|
|
3428
3451
|
text_tracks: autoTextTracks
|
|
3429
3452
|
}
|
|
3430
|
-
),
|
|
3453
|
+
), isAdvancedMode = useMemo(() => config.static_renditions.filter(
|
|
3454
|
+
(r) => r !== "highest" && r !== "audio-only"
|
|
3455
|
+
).length > 0, [config.static_renditions]), [renditionMode, setRenditionMode] = useState(
|
|
3456
|
+
isAdvancedMode ? "advanced" : "standard"
|
|
3457
|
+
), toggleRendition = (rendition) => {
|
|
3458
|
+
const current = config.static_renditions, hasRendition = current.includes(rendition);
|
|
3459
|
+
dispatch(hasRendition ? {
|
|
3460
|
+
action: "static_renditions",
|
|
3461
|
+
value: current.filter((r) => r !== rendition)
|
|
3462
|
+
} : {
|
|
3463
|
+
action: "static_renditions",
|
|
3464
|
+
value: [...current, rendition]
|
|
3465
|
+
});
|
|
3466
|
+
}, handleModeChange = (mode) => {
|
|
3467
|
+
setRenditionMode(mode), dispatch(mode === "standard" ? {
|
|
3468
|
+
action: "static_renditions",
|
|
3469
|
+
value: config.static_renditions.filter((r) => r === "highest" || r === "audio-only")
|
|
3470
|
+
} : {
|
|
3471
|
+
action: "static_renditions",
|
|
3472
|
+
value: config.static_renditions.filter((r) => r !== "highest")
|
|
3473
|
+
});
|
|
3474
|
+
}, { disableTextTrackConfig, disableUploadConfig } = pluginConfig, skipConfig = disableTextTrackConfig && disableUploadConfig;
|
|
3431
3475
|
if (useEffect(() => {
|
|
3432
3476
|
skipConfig && startUpload(formatUploadConfig(config));
|
|
3433
3477
|
}, []), skipConfig) return null;
|
|
@@ -3542,25 +3586,101 @@ function UploadConfiguration({
|
|
|
3542
3586
|
}) })
|
|
3543
3587
|
}
|
|
3544
3588
|
),
|
|
3545
|
-
!basicConfig && /* @__PURE__ */ jsx(FormField$2, { title: "Additional Configuration", children: /* @__PURE__ */ jsxs(Stack, { space:
|
|
3589
|
+
!basicConfig && /* @__PURE__ */ jsx(FormField$2, { title: "Additional Configuration", children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
3546
3590
|
/* @__PURE__ */ jsx(PlaybackPolicy, { id, config, secrets, dispatch }),
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3555
|
-
|
|
3556
|
-
|
|
3557
|
-
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3591
|
+
/* @__PURE__ */ jsx(Stack, { space: 3, children: /* @__PURE__ */ jsx(
|
|
3592
|
+
FormField$2,
|
|
3593
|
+
{
|
|
3594
|
+
title: "Static Renditions",
|
|
3595
|
+
description: "Generate downloadable MP4 or M4A files. Note: Mux will not upscale to produce MP4 renditions - renditions that would cause upscaling are skipped.",
|
|
3596
|
+
children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
3597
|
+
/* @__PURE__ */ jsxs(Flex, { gap: 3, children: [
|
|
3598
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3599
|
+
/* @__PURE__ */ jsx(
|
|
3600
|
+
Radio,
|
|
3601
|
+
{
|
|
3602
|
+
checked: renditionMode === "standard",
|
|
3603
|
+
name: "rendition-mode",
|
|
3604
|
+
onChange: () => handleModeChange("standard"),
|
|
3605
|
+
value: "standard",
|
|
3606
|
+
id: `${id}--mode-standard`
|
|
3607
|
+
}
|
|
3608
|
+
),
|
|
3609
|
+
/* @__PURE__ */ jsx(Text, { as: "label", htmlFor: `${id}--mode-standard`, children: "Standard" })
|
|
3610
|
+
] }),
|
|
3611
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3612
|
+
/* @__PURE__ */ jsx(
|
|
3613
|
+
Radio,
|
|
3614
|
+
{
|
|
3615
|
+
checked: renditionMode === "advanced",
|
|
3616
|
+
name: "rendition-mode",
|
|
3617
|
+
onChange: () => handleModeChange("advanced"),
|
|
3618
|
+
value: "advanced",
|
|
3619
|
+
id: `${id}--mode-advanced`
|
|
3620
|
+
}
|
|
3621
|
+
),
|
|
3622
|
+
/* @__PURE__ */ jsx(Text, { as: "label", htmlFor: `${id}--mode-advanced`, children: "Advanced" })
|
|
3623
|
+
] })
|
|
3624
|
+
] }),
|
|
3625
|
+
renditionMode === "standard" && /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
3626
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, padding: [0, 2], children: [
|
|
3627
|
+
/* @__PURE__ */ jsx(
|
|
3628
|
+
Checkbox,
|
|
3629
|
+
{
|
|
3630
|
+
id: `${id}--highest`,
|
|
3631
|
+
style: { display: "block" },
|
|
3632
|
+
checked: config.static_renditions.includes("highest"),
|
|
3633
|
+
onChange: () => toggleRendition("highest")
|
|
3634
|
+
}
|
|
3635
|
+
),
|
|
3636
|
+
/* @__PURE__ */ jsx(Text, { as: "label", htmlFor: `${id}--highest`, children: "Highest Resolution (up to 4K)" })
|
|
3637
|
+
] }),
|
|
3638
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, padding: [0, 2], children: [
|
|
3639
|
+
/* @__PURE__ */ jsx(
|
|
3640
|
+
Checkbox,
|
|
3641
|
+
{
|
|
3642
|
+
id: `${id}--audio-only-standard`,
|
|
3643
|
+
style: { display: "block" },
|
|
3644
|
+
checked: config.static_renditions.includes("audio-only"),
|
|
3645
|
+
onChange: () => toggleRendition("audio-only")
|
|
3646
|
+
}
|
|
3647
|
+
),
|
|
3648
|
+
/* @__PURE__ */ jsx(Text, { as: "label", htmlFor: `${id}--audio-only-standard`, children: "Audio Only (M4A)" })
|
|
3649
|
+
] })
|
|
3650
|
+
] }),
|
|
3651
|
+
renditionMode === "advanced" && /* @__PURE__ */ jsxs(Stack, { space: 2, children: [
|
|
3652
|
+
/* @__PURE__ */ jsx(Label$1, { size: 1, muted: !0, children: "Select specific resolutions:" }),
|
|
3653
|
+
/* @__PURE__ */ jsx(Flex, { gap: 2, wrap: "wrap", children: ADVANCED_RESOLUTIONS.map(({ value, label }) => {
|
|
3654
|
+
const inputId = `${id}--resolution-${value}`;
|
|
3655
|
+
return /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3656
|
+
/* @__PURE__ */ jsx(
|
|
3657
|
+
Checkbox,
|
|
3658
|
+
{
|
|
3659
|
+
id: inputId,
|
|
3660
|
+
style: { display: "block" },
|
|
3661
|
+
checked: config.static_renditions.includes(value),
|
|
3662
|
+
onChange: () => toggleRendition(value)
|
|
3663
|
+
}
|
|
3664
|
+
),
|
|
3665
|
+
/* @__PURE__ */ jsx(Text, { as: "label", htmlFor: inputId, size: 1, children: label })
|
|
3666
|
+
] }, value);
|
|
3667
|
+
}) }),
|
|
3668
|
+
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, padding: [2, 2, 0, 2], children: [
|
|
3669
|
+
/* @__PURE__ */ jsx(
|
|
3670
|
+
Checkbox,
|
|
3671
|
+
{
|
|
3672
|
+
id: `${id}--audio-only-advanced`,
|
|
3673
|
+
style: { display: "block" },
|
|
3674
|
+
checked: config.static_renditions.includes("audio-only"),
|
|
3675
|
+
onChange: () => toggleRendition("audio-only")
|
|
3676
|
+
}
|
|
3677
|
+
),
|
|
3678
|
+
/* @__PURE__ */ jsx(Text, { as: "label", htmlFor: `${id}--audio-only-advanced`, children: "Audio Only (M4A)" })
|
|
3679
|
+
] })
|
|
3680
|
+
] })
|
|
3681
|
+
] })
|
|
3682
|
+
}
|
|
3683
|
+
) })
|
|
3564
3684
|
] }) })
|
|
3565
3685
|
] }),
|
|
3566
3686
|
!disableTextTrackConfig && !basicConfig && /* @__PURE__ */ jsx(
|
|
@@ -3612,7 +3732,7 @@ function formatUploadConfig(config) {
|
|
|
3612
3732
|
[]
|
|
3613
3733
|
)
|
|
3614
3734
|
],
|
|
3615
|
-
|
|
3735
|
+
static_renditions: config.static_renditions.length > 0 ? config.static_renditions.map((resolution) => ({ resolution })) : void 0,
|
|
3616
3736
|
playback_policy: setPlaybackPolicy(config),
|
|
3617
3737
|
max_resolution_tier: config.max_resolution_tier,
|
|
3618
3738
|
video_quality: config.video_quality,
|
|
@@ -4115,12 +4235,18 @@ const muxVideoSchema = {
|
|
|
4115
4235
|
name: "mux.staticRenditionFile",
|
|
4116
4236
|
type: "object",
|
|
4117
4237
|
fields: [
|
|
4118
|
-
{ type: "string", name: "ext" },
|
|
4119
4238
|
{ type: "string", name: "name" },
|
|
4239
|
+
{ type: "string", name: "ext" },
|
|
4240
|
+
{ type: "number", name: "height" },
|
|
4120
4241
|
{ type: "number", name: "width" },
|
|
4121
4242
|
{ type: "number", name: "bitrate" },
|
|
4122
|
-
{ type: "
|
|
4123
|
-
{ type: "
|
|
4243
|
+
{ type: "string", name: "filesize" },
|
|
4244
|
+
{ type: "string", name: "type" },
|
|
4245
|
+
{ type: "string", name: "status" },
|
|
4246
|
+
{ type: "string", name: "resolution_tier" },
|
|
4247
|
+
{ type: "string", name: "resolution" },
|
|
4248
|
+
{ type: "string", name: "id" },
|
|
4249
|
+
{ type: "string", name: "passthrough" }
|
|
4124
4250
|
]
|
|
4125
4251
|
}, muxStaticRenditions = {
|
|
4126
4252
|
name: "mux.staticRenditions",
|
|
@@ -4251,6 +4377,7 @@ const muxVideoSchema = {
|
|
|
4251
4377
|
muxAssetData,
|
|
4252
4378
|
muxVideoAsset
|
|
4253
4379
|
], defaultConfig = {
|
|
4380
|
+
static_renditions: [],
|
|
4254
4381
|
mp4_support: "none",
|
|
4255
4382
|
video_quality: "plus",
|
|
4256
4383
|
max_resolution_tier: "1080p",
|
|
@@ -4259,12 +4386,20 @@ const muxVideoSchema = {
|
|
|
4259
4386
|
defaultSigned: !1,
|
|
4260
4387
|
tool: DEFAULT_TOOL_CONFIG,
|
|
4261
4388
|
allowedRolesForConfiguration: []
|
|
4262
|
-
}
|
|
4389
|
+
};
|
|
4390
|
+
function convertLegacyConfig(config) {
|
|
4391
|
+
return config.static_renditions && config.static_renditions.length > 0 ? { static_renditions: config.static_renditions } : config.mp4_support === "standard" ? { static_renditions: ["highest"] } : { static_renditions: [] };
|
|
4392
|
+
}
|
|
4393
|
+
const muxInput = definePlugin((userConfig) => {
|
|
4263
4394
|
if (typeof userConfig == "object" && "encoding_tier" in userConfig) {
|
|
4264
4395
|
const deprecated_encoding_tier = userConfig.encoding_tier;
|
|
4265
4396
|
userConfig.video_quality || (deprecated_encoding_tier === "baseline" && (userConfig.video_quality = "basic"), deprecated_encoding_tier === "smart" && (userConfig.video_quality = "plus"));
|
|
4266
4397
|
}
|
|
4267
|
-
const config = {
|
|
4398
|
+
const config = {
|
|
4399
|
+
...defaultConfig,
|
|
4400
|
+
...userConfig || {},
|
|
4401
|
+
...convertLegacyConfig(userConfig || {})
|
|
4402
|
+
};
|
|
4268
4403
|
return {
|
|
4269
4404
|
name: "mux-input",
|
|
4270
4405
|
schema: {
|