sanity-plugin-mux-input 2.0.1 → 2.0.3

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 (38) hide show
  1. package/LICENSE +1 -1
  2. package/lib/_chunks/Input-4ec3c050.js +2666 -0
  3. package/lib/_chunks/Input-4ec3c050.js.map +1 -0
  4. package/lib/_chunks/Input-aa6d929b.js +2636 -0
  5. package/lib/_chunks/Input-aa6d929b.js.map +1 -0
  6. package/lib/_chunks/Preview-1664b7d5.js +28 -0
  7. package/lib/_chunks/Preview-1664b7d5.js.map +1 -0
  8. package/lib/_chunks/Preview-43ce9c72.js +26 -0
  9. package/lib/_chunks/{Preview-3195237b.js.map → Preview-43ce9c72.js.map} +1 -1
  10. package/lib/_chunks/VideoSource.styled-24577ec8.js +318 -0
  11. package/lib/_chunks/VideoSource.styled-24577ec8.js.map +1 -0
  12. package/lib/_chunks/VideoSource.styled-99ffa712.js +336 -0
  13. package/lib/_chunks/VideoSource.styled-99ffa712.js.map +1 -0
  14. package/lib/_chunks/index-9933dea2.js +264 -0
  15. package/lib/_chunks/index-9933dea2.js.map +1 -0
  16. package/lib/_chunks/index-c54f5393.js +247 -0
  17. package/lib/_chunks/index-c54f5393.js.map +1 -0
  18. package/lib/{src/index.d.ts → index.d.ts} +0 -0
  19. package/lib/index.esm.js +2 -1
  20. package/lib/index.esm.js.map +1 -1
  21. package/lib/index.js +9 -1
  22. package/lib/index.js.map +1 -1
  23. package/package.json +27 -34
  24. package/lib/_chunks/Input-2ba004d3.js +0 -2
  25. package/lib/_chunks/Input-2ba004d3.js.map +0 -1
  26. package/lib/_chunks/Input-af5a0a66.esm.js +0 -2
  27. package/lib/_chunks/Input-af5a0a66.esm.js.map +0 -1
  28. package/lib/_chunks/Preview-3195237b.js +0 -2
  29. package/lib/_chunks/Preview-bb256342.esm.js +0 -2
  30. package/lib/_chunks/Preview-bb256342.esm.js.map +0 -1
  31. package/lib/_chunks/VideoSource.styled-1b994d90.js +0 -2
  32. package/lib/_chunks/VideoSource.styled-1b994d90.js.map +0 -1
  33. package/lib/_chunks/VideoSource.styled-f92259cd.esm.js +0 -2
  34. package/lib/_chunks/VideoSource.styled-f92259cd.esm.js.map +0 -1
  35. package/lib/_chunks/index-3d8d7583.esm.js +0 -2
  36. package/lib/_chunks/index-3d8d7583.esm.js.map +0 -1
  37. package/lib/_chunks/index-efe6ce48.js +0 -2
  38. package/lib/_chunks/index-efe6ce48.js.map +0 -1
@@ -0,0 +1,2636 @@
1
+ const _excluded = ["icon", "id", "accept", "capture", "fontSize", "multiple", "onSelect", "padding", "space", "textAlign", "text", "disabled"],
2
+ _excluded2 = ["onSelect"];
3
+ 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
+ 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
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
13
+ 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';
15
+ import { useProjectId, useDataset, useDocumentValues, PatchEvent, setIfMissing, set, unset, LinearProgress } from 'sanity';
16
+ import useSWR from 'swr';
17
+ import { muxSecretsDocumentId, cacheNs, InputFallback } from './index-c54f5393.js';
18
+ import { Observable, defer, concat, of, throwError, from, Subject } from 'rxjs';
19
+ import { switchMap, mergeMap, catchError, mergeMapTo, takeUntil, tap } from 'rxjs/operators';
20
+ import { uuid } from '@sanity/uuid';
21
+ import * as UpChunk from '@mux/upchunk';
22
+ import { Card, Box, Flex, Spinner, Text, Button, useClickOutside, MenuButton, Menu, MenuItem, useToast, Dialog, Grid, Stack, Checkbox, Code, Inline, Tooltip, Popover, Label as Label$1, MenuDivider, rem, TextInput, Heading } from '@sanity/ui';
23
+ import { DownloadIcon, EllipsisVerticalIcon, TrashIcon, LockIcon, EditIcon, UploadIcon, SearchIcon, PlugIcon, ResetIcon, DocumentVideoIcon } from '@sanity/icons';
24
+ import { animate } from 'motion';
25
+ import styled, { css } from 'styled-components';
26
+ import { getDevicePixelRatio } from 'use-device-pixel-ratio';
27
+ import { generatePlayerInitTime, initialize } from '@mux/playback-core';
28
+ import { MediaControlBar, MediaPosterImage, MediaController, MediaLoadingIndicator, MediaPlayButton, MediaMuteButton, MediaTimeDisplay, MediaTimeRange, MediaDurationDisplay, MediaFullscreenButton } from 'media-chrome/dist/react';
29
+ import { isValidElementType } from 'react-is';
30
+ import { clear, preload } from 'suspend-react';
31
+ function useDialogState() {
32
+ return useState(false);
33
+ }
34
+ const useMuxPolling = asset => {
35
+ var _a, _b;
36
+ const client = useClient();
37
+ const projectId = useProjectId();
38
+ const dataset = useDataset();
39
+ const shouldFetch = useMemo(() => {
40
+ var _a2, _b2;
41
+ return !!(asset == null ? void 0 : asset.assetId) && ((asset == null ? void 0 : asset.status) === "preparing" || ((_b2 = (_a2 = asset == null ? void 0 : asset.data) == null ? void 0 : _a2.static_renditions) == null ? void 0 : _b2.status) === "preparing");
42
+ }, [asset == null ? void 0 : asset.assetId, (_b = (_a = asset == null ? void 0 : asset.data) == null ? void 0 : _a.static_renditions) == null ? void 0 : _b.status, asset == null ? void 0 : asset.status]);
43
+ return useSWR(shouldFetch ? "/".concat(projectId, "/addons/mux/assets/").concat(dataset, "/data/").concat(asset == null ? void 0 : asset.assetId) : null, async () => {
44
+ const {
45
+ data
46
+ } = await client.request({
47
+ url: "/addons/mux/assets/".concat(dataset, "/data/").concat(asset.assetId),
48
+ withCredentials: true,
49
+ method: "GET"
50
+ });
51
+ client.patch(asset._id).set({
52
+ status: data.status,
53
+ data
54
+ }).commit({
55
+ returnDocuments: false
56
+ });
57
+ }, {
58
+ refreshInterval: 2e3,
59
+ refreshWhenHidden: true,
60
+ dedupingInterval: 1e3
61
+ });
62
+ };
63
+ const path = ["token", "secretKey", "enableSignedUrls", "signingKeyId", "signingKeyPrivate"];
64
+ const useSecretsDocumentValues = () => {
65
+ const {
66
+ error,
67
+ isLoading,
68
+ value
69
+ } = useDocumentValues(muxSecretsDocumentId, path);
70
+ const cache = useMemo(() => {
71
+ const exists = Boolean(value);
72
+ const secrets = {
73
+ token: (value == null ? void 0 : value.token) || null,
74
+ secretKey: (value == null ? void 0 : value.secretKey) || null,
75
+ enableSignedUrls: (value == null ? void 0 : value.enableSignedUrls) || false,
76
+ signingKeyId: (value == null ? void 0 : value.signingKeyId) || null,
77
+ signingKeyPrivate: (value == null ? void 0 : value.signingKeyPrivate) || null
78
+ };
79
+ return {
80
+ isInitialSetup: !exists,
81
+ needsSetup: !(secrets == null ? void 0 : secrets.token) || !(secrets == null ? void 0 : secrets.secretKey),
82
+ secrets
83
+ };
84
+ }, [value]);
85
+ return {
86
+ error,
87
+ isLoading,
88
+ value: cache
89
+ };
90
+ };
91
+ function createUpChunkObservable(uuid, uploadUrl, source) {
92
+ return new Observable(subscriber => {
93
+ const upchunk = UpChunk.createUpload({
94
+ endpoint: uploadUrl,
95
+ file: source,
96
+ dynamicChunkSize: true
97
+ });
98
+ const successHandler = () => {
99
+ subscriber.next({
100
+ type: "success",
101
+ id: uuid
102
+ });
103
+ subscriber.complete();
104
+ };
105
+ const errorHandler = data => subscriber.error(new Error(data.detail.message));
106
+ const progressHandler = data => {
107
+ return subscriber.next({
108
+ type: "progress",
109
+ percent: data.detail
110
+ });
111
+ };
112
+ const offlineHandler = () => {
113
+ upchunk.pause();
114
+ subscriber.next({
115
+ type: "pause",
116
+ id: uuid
117
+ });
118
+ };
119
+ const onlineHandler = () => {
120
+ upchunk.resume();
121
+ subscriber.next({
122
+ type: "resume",
123
+ id: uuid
124
+ });
125
+ };
126
+ upchunk.on("success", successHandler);
127
+ upchunk.on("error", errorHandler);
128
+ upchunk.on("progress", progressHandler);
129
+ upchunk.on("offline", offlineHandler);
130
+ upchunk.on("online", onlineHandler);
131
+ return () => upchunk.abort();
132
+ });
133
+ }
134
+ function deleteAsset(client, assetId) {
135
+ const {
136
+ dataset
137
+ } = client.config();
138
+ return client.request({
139
+ url: "/addons/mux/assets/".concat(dataset, "/").concat(assetId),
140
+ withCredentials: true,
141
+ method: "DELETE"
142
+ });
143
+ }
144
+ function getAsset(client, assetId) {
145
+ const {
146
+ dataset
147
+ } = client.config();
148
+ return client.request({
149
+ url: "/addons/mux/assets/".concat(dataset, "/data/").concat(assetId),
150
+ withCredentials: true,
151
+ method: "GET"
152
+ });
153
+ }
154
+ function saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate) {
155
+ const doc = {
156
+ _id: "secrets.mux",
157
+ _type: "mux.apiKey",
158
+ token,
159
+ secretKey,
160
+ enableSignedUrls,
161
+ signingKeyId,
162
+ signingKeyPrivate
163
+ };
164
+ return client.createOrReplace(doc);
165
+ }
166
+ function createSigningKeys(client) {
167
+ const {
168
+ dataset
169
+ } = client.config();
170
+ return client.request({
171
+ url: "/addons/mux/signing-keys/".concat(dataset),
172
+ withCredentials: true,
173
+ method: "POST"
174
+ });
175
+ }
176
+ function testSecrets(client) {
177
+ const {
178
+ dataset
179
+ } = client.config();
180
+ return client.request({
181
+ url: "/addons/mux/secrets/".concat(dataset, "/test"),
182
+ withCredentials: true,
183
+ method: "GET"
184
+ });
185
+ }
186
+ async function haveValidSigningKeys(client, signingKeyId, signingKeyPrivate) {
187
+ if (!(signingKeyId && signingKeyPrivate)) {
188
+ return false;
189
+ }
190
+ const {
191
+ dataset
192
+ } = client.config();
193
+ try {
194
+ const res = await client.request({
195
+ url: "/addons/mux/signing-keys/".concat(dataset, "/").concat(signingKeyId),
196
+ withCredentials: true,
197
+ method: "GET"
198
+ });
199
+ return !!(res.data && res.data.id);
200
+ } catch (e) {
201
+ console.error("Error fetching signingKeyId", signingKeyId, "assuming it is not valid");
202
+ return false;
203
+ }
204
+ }
205
+ function testSecretsObservable(client) {
206
+ const {
207
+ dataset
208
+ } = client.config();
209
+ return defer(() => client.observable.request({
210
+ url: "/addons/mux/secrets/".concat(dataset, "/test"),
211
+ withCredentials: true,
212
+ method: "GET"
213
+ }));
214
+ }
215
+ function cancelUpload(client, uuid) {
216
+ return client.observable.request({
217
+ url: "/addons/mux/uploads/".concat(client.clientConfig.dataset, "/").concat(uuid),
218
+ withCredentials: true,
219
+ method: "DELETE"
220
+ });
221
+ }
222
+ function uploadUrl(config, client, url) {
223
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
224
+ return testUrl(url).pipe(switchMap(validUrl => {
225
+ return concat(of({
226
+ type: "url",
227
+ url: validUrl
228
+ }), testSecretsObservable(client).pipe(switchMap(json => {
229
+ if (!json || !json.status) {
230
+ return throwError(new Error("Invalid credentials"));
231
+ }
232
+ const uuid$1 = uuid();
233
+ const {
234
+ enableSignedUrls
235
+ } = options;
236
+ const muxBody = {
237
+ input: validUrl,
238
+ playback_policy: [enableSignedUrls ? "signed" : "public"],
239
+ mp4_support: config.mp4_support
240
+ };
241
+ const query = {
242
+ muxBody: JSON.stringify(muxBody),
243
+ filename: validUrl.split("/").slice(-1)[0]
244
+ };
245
+ const dataset = client.clientConfig.dataset;
246
+ return defer(() => client.observable.request({
247
+ url: "/addons/mux/assets/".concat(dataset),
248
+ withCredentials: true,
249
+ method: "POST",
250
+ headers: {
251
+ "MUX-Proxy-UUID": uuid$1,
252
+ "Content-Type": "application/json"
253
+ },
254
+ query
255
+ })).pipe(mergeMap(result => {
256
+ const asset = result && result.results && result.results[0] && result.results[0].document || null;
257
+ if (!asset) {
258
+ return throwError(new Error("No asset document returned"));
259
+ }
260
+ return of({
261
+ type: "success",
262
+ id: uuid$1,
263
+ asset
264
+ });
265
+ }));
266
+ })));
267
+ }));
268
+ }
269
+ function uploadFile(config, client, file) {
270
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
271
+ return testFile(file).pipe(switchMap(fileOptions => {
272
+ return concat(of({
273
+ type: "file",
274
+ file: fileOptions
275
+ }), testSecretsObservable(client).pipe(switchMap(json => {
276
+ if (!json || !json.status) {
277
+ return throwError(new Error("Invalid credentials"));
278
+ }
279
+ const uuid$1 = uuid();
280
+ const {
281
+ enableSignedUrls
282
+ } = options;
283
+ const body = {
284
+ mp4_support: config.mp4_support,
285
+ playback_policy: [enableSignedUrls ? "signed" : "public"]
286
+ };
287
+ return concat(of({
288
+ type: "uuid",
289
+ uuid: uuid$1
290
+ }), defer(() => client.observable.request({
291
+ url: "/addons/mux/uploads/".concat(client.clientConfig.dataset),
292
+ withCredentials: true,
293
+ method: "POST",
294
+ headers: {
295
+ "MUX-Proxy-UUID": uuid$1,
296
+ "Content-Type": "application/json"
297
+ },
298
+ body
299
+ })).pipe(mergeMap(result => {
300
+ return createUpChunkObservable(uuid$1, result.upload.url, file).pipe(mergeMap(event => {
301
+ if (event.type !== "success") {
302
+ return of(event);
303
+ }
304
+ return from(updateAssetDocumentFromUpload(client, uuid$1)).pipe(mergeMap(doc => of(_objectSpread(_objectSpread({}, event), {}, {
305
+ asset: doc
306
+ }))));
307
+ }), catchError(err => {
308
+ return cancelUpload(client, uuid$1).pipe(mergeMapTo(throwError(err)));
309
+ }));
310
+ })));
311
+ })));
312
+ }));
313
+ }
314
+ function getUpload(client, assetId) {
315
+ const {
316
+ dataset
317
+ } = client.config();
318
+ return client.request({
319
+ url: "/addons/mux/uploads/".concat(dataset, "/").concat(assetId),
320
+ withCredentials: true,
321
+ method: "GET"
322
+ });
323
+ }
324
+ function pollUpload(client, uuid) {
325
+ const maxTries = 10;
326
+ let pollInterval;
327
+ let tries = 0;
328
+ let assetId;
329
+ let upload;
330
+ return new Promise((resolve, reject) => {
331
+ pollInterval = setInterval(async () => {
332
+ try {
333
+ upload = await getUpload(client, uuid);
334
+ } catch (err) {
335
+ reject(err);
336
+ return;
337
+ }
338
+ assetId = upload && upload.data && upload.data.asset_id;
339
+ if (assetId) {
340
+ clearInterval(pollInterval);
341
+ resolve(upload);
342
+ }
343
+ if (tries > maxTries) {
344
+ clearInterval(pollInterval);
345
+ reject(new Error("Upload did not finish"));
346
+ }
347
+ tries++;
348
+ }, 2e3);
349
+ });
350
+ }
351
+ async function updateAssetDocumentFromUpload(client, uuid) {
352
+ let upload;
353
+ let asset;
354
+ try {
355
+ upload = await pollUpload(client, uuid);
356
+ } catch (err) {
357
+ return Promise.reject(err);
358
+ }
359
+ try {
360
+ asset = await getAsset(client, upload.data.asset_id);
361
+ } catch (err) {
362
+ return Promise.reject(err);
363
+ }
364
+ const doc = {
365
+ _id: uuid,
366
+ _type: "mux.videoAsset",
367
+ status: asset.data.status,
368
+ data: asset.data,
369
+ assetId: asset.data.id,
370
+ playbackId: asset.data.playback_ids[0].id,
371
+ uploadId: upload.data.id
372
+ };
373
+ return client.createOrReplace(doc).then(() => {
374
+ return doc;
375
+ });
376
+ }
377
+ function testFile(file) {
378
+ if (typeof window !== "undefined" && file instanceof window.File) {
379
+ const fileOptions = optionsFromFile({}, file);
380
+ return of(fileOptions);
381
+ }
382
+ return throwError(new Error("Invalid file"));
383
+ }
384
+ function testUrl(url) {
385
+ const error = new Error("Invalid URL");
386
+ if (typeof url !== "string") {
387
+ return throwError(error);
388
+ }
389
+ let parsed;
390
+ try {
391
+ parsed = new URL(url);
392
+ } catch (err) {
393
+ return throwError(error);
394
+ }
395
+ if (parsed && !parsed.protocol.match(/http:|https:/)) {
396
+ return throwError(error);
397
+ }
398
+ return of(url);
399
+ }
400
+ function optionsFromFile(opts, file) {
401
+ if (typeof window === "undefined" || !(file instanceof window.File)) {
402
+ return opts;
403
+ }
404
+ return {
405
+ name: opts.preserveFilename === false ? void 0 : file.name,
406
+ type: file.type
407
+ };
408
+ }
409
+ function extractDroppedFiles(dataTransfer) {
410
+ const files = Array.from(dataTransfer.files || []);
411
+ const items = Array.from(dataTransfer.items || []);
412
+ if (files && files.length > 0) {
413
+ return Promise.resolve(files);
414
+ }
415
+ return normalizeItems(items).then(arr => arr.flat());
416
+ }
417
+ function normalizeItems(items) {
418
+ return Promise.all(items.map(item => {
419
+ if (item.kind === "file" && item.webkitGetAsEntry) {
420
+ let entry;
421
+ try {
422
+ entry = item.webkitGetAsEntry();
423
+ } catch (err) {
424
+ return [item.getAsFile()];
425
+ }
426
+ if (!entry) {
427
+ return [];
428
+ }
429
+ return entry.isDirectory ? walk(entry) : [item.getAsFile()];
430
+ }
431
+ if (item.kind === "file") {
432
+ const file = item.getAsFile();
433
+ return Promise.resolve(file ? [file] : []);
434
+ }
435
+ return new Promise(resolve => item.getAsString(resolve)).then(str => str ? [new File([str], "unknown.txt", {
436
+ type: item.type
437
+ })] : []);
438
+ }));
439
+ }
440
+ function isFile(entry) {
441
+ return entry.isFile;
442
+ }
443
+ function isDirectory(entry) {
444
+ return entry.isDirectory;
445
+ }
446
+ function walk(entry) {
447
+ if (isFile(entry)) {
448
+ return new Promise(resolve => entry.file(resolve)).then(file => [file]);
449
+ }
450
+ if (isDirectory(entry)) {
451
+ const dir = entry.createReader();
452
+ return new Promise(resolve => dir.readEntries(resolve)).then(entries => entries.filter(entr => !entr.name.startsWith("."))).then(entries => Promise.all(entries.map(walk)).then(arr => arr.flat()));
453
+ }
454
+ return Promise.resolve([]);
455
+ }
456
+ function AssetActionsMenu(props) {
457
+ const {
458
+ asset
459
+ } = props;
460
+ const id = useId();
461
+ const [dialogState, setDialogState] = useState();
462
+ const [open, setOpen] = useState(false);
463
+ const [menuElement, setMenuRef] = useState(null);
464
+ const handleDelete = useCallback(() => setDialogState("confirm-delete"), []);
465
+ const handleClick = useCallback(() => {
466
+ setDialogState(false);
467
+ setOpen(true);
468
+ }, [setDialogState]);
469
+ const handleClose = useCallback(() => {
470
+ setDialogState(false);
471
+ setOpen(false);
472
+ }, [setDialogState]);
473
+ useEffect(() => {
474
+ if (open && dialogState) {
475
+ setOpen(false);
476
+ }
477
+ }, [dialogState, open]);
478
+ useClickOutside(useCallback(() => setOpen(false), []), [menuElement]);
479
+ return /* @__PURE__ */jsxs(Fragment, {
480
+ children: [/* @__PURE__ */jsx(MenuButton, {
481
+ id: "".concat(id, "-asset-menu"),
482
+ button: /* @__PURE__ */jsx(Button, {
483
+ icon: EllipsisVerticalIcon,
484
+ mode: "ghost",
485
+ onClick: handleClick,
486
+ padding: 2
487
+ }),
488
+ menu: /* @__PURE__ */jsx(Menu, {
489
+ ref: setMenuRef,
490
+ children: /* @__PURE__ */jsx(MenuItem, {
491
+ tone: "critical",
492
+ icon: TrashIcon,
493
+ text: "Delete",
494
+ onClick: handleDelete
495
+ })
496
+ }),
497
+ portal: true,
498
+ placement: "right"
499
+ }), dialogState === "confirm-delete" && /* @__PURE__ */jsx(DeleteDialog, {
500
+ asset,
501
+ onClose: handleClose
502
+ })]
503
+ });
504
+ }
505
+ function DeleteDialog(props) {
506
+ const {
507
+ asset,
508
+ onClose
509
+ } = props;
510
+ const client = useClient();
511
+ const {
512
+ push: pushToast
513
+ } = useToast();
514
+ const [deleting, setDeleting] = useState(false);
515
+ const [deleteOnMux, setDeleteOnMux] = useState(false);
516
+ const id = useId();
517
+ const width = 200 * getDevicePixelRatio({
518
+ maxDpr: 2
519
+ });
520
+ const handleDelete = useCallback(async () => {
521
+ var _a, _b, _c;
522
+ setDeleting(true);
523
+ try {
524
+ if (asset == null ? void 0 : asset._id) {
525
+ await client.delete(asset._id);
526
+ }
527
+ if (deleteOnMux && (asset == null ? void 0 : asset.assetId)) {
528
+ await deleteAsset(client, asset.assetId);
529
+ }
530
+ (_c = (_b = (_a = document.querySelector("[data-id=\"".concat(asset._id, "\"]"))) == null ? void 0 : _a.parentElement) == null ? void 0 : _b.setAttribute) == null ? void 0 : _c.call(_b, "hidden", "true");
531
+ } catch (err) {
532
+ console.error("Failed during delete", err);
533
+ pushToast({
534
+ closable: true,
535
+ description: err == null ? void 0 : err.message,
536
+ duration: 5e3,
537
+ title: "Uncaught error",
538
+ status: "error"
539
+ });
540
+ } finally {
541
+ setDeleting(false);
542
+ onClose();
543
+ }
544
+ }, [asset._id, asset.assetId, client, deleteOnMux, onClose, pushToast]);
545
+ return /* @__PURE__ */jsx(Dialog, {
546
+ onClose,
547
+ id: "".concat(id, "-confirm-delete"),
548
+ header: "Delete video",
549
+ footer: /* @__PURE__ */jsxs(Grid, {
550
+ padding: 2,
551
+ gap: 2,
552
+ columns: 2,
553
+ children: [/* @__PURE__ */jsx(Button, {
554
+ mode: "bleed",
555
+ text: "Cancel",
556
+ onClick: onClose
557
+ }), /* @__PURE__ */jsx(Button, {
558
+ text: "Delete",
559
+ tone: "critical",
560
+ icon: TrashIcon,
561
+ onClick: handleDelete,
562
+ loading: deleting
563
+ })]
564
+ }),
565
+ width: 1,
566
+ children: /* @__PURE__ */jsx(Stack, {
567
+ paddingX: 0,
568
+ paddingY: 0,
569
+ space: 1,
570
+ children: /* @__PURE__ */jsx(Card, {
571
+ paddingX: [2, 3, 4],
572
+ paddingY: [3, 3, 3, 4],
573
+ children: /* @__PURE__ */jsxs(Grid, {
574
+ columns: 3,
575
+ gap: 3,
576
+ children: [/* @__PURE__ */jsx(Flex, {
577
+ style: {
578
+ gridColumn: "span 2"
579
+ },
580
+ align: "center",
581
+ children: /* @__PURE__ */jsx(Box, {
582
+ padding: 4,
583
+ children: /* @__PURE__ */jsxs(Stack, {
584
+ space: 4,
585
+ children: [/* @__PURE__ */jsxs(Flex, {
586
+ align: "center",
587
+ as: "label",
588
+ children: [/* @__PURE__ */jsx(Checkbox, {
589
+ checked: deleteOnMux,
590
+ onChange: () => setDeleteOnMux(prev => !prev)
591
+ }), /* @__PURE__ */jsx(Text, {
592
+ style: {
593
+ margin: "0 10px"
594
+ },
595
+ children: "Delete asset on Mux"
596
+ })]
597
+ }), /* @__PURE__ */jsxs(Flex, {
598
+ align: "center",
599
+ as: "label",
600
+ children: [/* @__PURE__ */jsx(Checkbox, {
601
+ disabled: true,
602
+ checked: true
603
+ }), /* @__PURE__ */jsx(Text, {
604
+ style: {
605
+ margin: "0 10px"
606
+ },
607
+ children: "Delete video from dataset"
608
+ })]
609
+ })]
610
+ })
611
+ })
612
+ }), /* @__PURE__ */jsx(VideoThumbnail, {
613
+ asset,
614
+ width,
615
+ showTip: true
616
+ })]
617
+ })
618
+ })
619
+ })
620
+ });
621
+ }
622
+ function VideoSource(_ref) {
623
+ let {
624
+ assets,
625
+ isLoading,
626
+ isLastPage,
627
+ onSelect,
628
+ onLoadMore
629
+ } = _ref;
630
+ const handleClick = useCallback(event => onSelect(event.currentTarget.dataset.id), [onSelect]);
631
+ const handleKeyPress = useCallback(event => {
632
+ if (event.key === "Enter") {
633
+ onSelect(event.currentTarget.dataset.id);
634
+ }
635
+ }, [onSelect]);
636
+ const width = 200 * getDevicePixelRatio({
637
+ maxDpr: 2
638
+ });
639
+ return /* @__PURE__ */jsxs(Fragment, {
640
+ children: [/* @__PURE__ */jsxs(Box, {
641
+ padding: 4,
642
+ children: [/* @__PURE__ */jsx(ThumbGrid, {
643
+ gap: 2,
644
+ children: assets.map(asset => /* @__PURE__ */jsx(VideoSourceItem, {
645
+ asset,
646
+ onClick: handleClick,
647
+ onKeyPress: handleKeyPress,
648
+ width
649
+ }, asset._id))
650
+ }), isLoading && assets.length === 0 && /* @__PURE__ */jsx(Flex, {
651
+ justify: "center",
652
+ children: /* @__PURE__ */jsx(Spinner, {
653
+ muted: true
654
+ })
655
+ }), !isLoading && assets.length === 0 && /* @__PURE__ */jsx(Text, {
656
+ align: "center",
657
+ muted: true,
658
+ children: "No videos"
659
+ })]
660
+ }), assets.length > 0 && !isLastPage && /* @__PURE__ */jsx(CardLoadMore, {
661
+ tone: "default",
662
+ padding: 4,
663
+ children: /* @__PURE__ */jsx(Flex, {
664
+ direction: "column",
665
+ children: /* @__PURE__ */jsx(Button, {
666
+ type: "button",
667
+ icon: DownloadIcon,
668
+ loading: isLoading,
669
+ onClick: onLoadMore,
670
+ text: "Load more",
671
+ tone: "primary"
672
+ })
673
+ })
674
+ })]
675
+ });
676
+ }
677
+ const _VideoSourceItem = _ref2 => {
678
+ let {
679
+ asset,
680
+ onClick,
681
+ onKeyPress,
682
+ width
683
+ } = _ref2;
684
+ const [hover, setHover] = useState(null);
685
+ const ref = useRef(null);
686
+ useLayoutEffect(() => {
687
+ if (!ref.current || hover === null) {
688
+ return;
689
+ }
690
+ if (hover) {
691
+ animate(ref.current, {
692
+ opacity: 1
693
+ });
694
+ } else {
695
+ animate(ref.current, {
696
+ opacity: 0
697
+ });
698
+ }
699
+ }, [hover]);
700
+ return /* @__PURE__ */jsxs(Box, {
701
+ height: "fill",
702
+ style: {
703
+ position: "relative"
704
+ },
705
+ children: [/* @__PURE__ */jsxs(Card, {
706
+ as: "button",
707
+ "data-id": asset._id,
708
+ onClick,
709
+ onKeyPress,
710
+ tabIndex: 0,
711
+ radius: 2,
712
+ padding: 1,
713
+ style: {
714
+ lineHeight: 0,
715
+ position: "relative"
716
+ },
717
+ __unstable_focusRing: true,
718
+ onMouseEnter: () => setHover(true),
719
+ onMouseLeave: () => setHover(false),
720
+ children: [/* @__PURE__ */jsx(VideoThumbnail, {
721
+ asset,
722
+ width,
723
+ showTip: true
724
+ }), (asset == null ? void 0 : asset.playbackId) && /* @__PURE__ */jsx(AnimateWrapper, {
725
+ tone: "transparent",
726
+ ref,
727
+ margin: 1,
728
+ radius: 1,
729
+ children: hover !== null && /* @__PURE__ */jsx(AnimatedVideoThumbnail, {
730
+ asset,
731
+ width
732
+ })
733
+ })]
734
+ }), /* @__PURE__ */jsx(ActionsAssetsContainer, {
735
+ children: /* @__PURE__ */jsx(AssetActionsMenu, {
736
+ asset
737
+ })
738
+ })]
739
+ });
740
+ };
741
+ const VideoSourceItem = memo(_VideoSourceItem);
742
+ const AnimateWrapper = styled(Card)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n will-change: opacity;\n background: transparent;\n background-color: hsl(0deg 0% 0% / 33%);\n opacity: 0;\n pointer-events: none;\n"])));
743
+ const ActionsAssetsContainer = styled.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n box-sizing: border-box;\n position: absolute;\n z-index: 300;\n opacity: 0;\n top: 7px;\n right: 7px;\n\n button:hover + &,\n button:focus-visible + &,\n &:hover,\n &:focus-visible {\n opacity: 1;\n }\n"])));
744
+ const PER_PAGE = 200;
745
+ function createQuery() {
746
+ let start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
747
+ let end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PER_PAGE;
748
+ return "*[_type == \"mux.videoAsset\"] | order(_updatedAt desc) [".concat(start, "...").concat(end, "]");
749
+ }
750
+ function SelectAssets(_ref3) {
751
+ let {
752
+ asset,
753
+ onChange,
754
+ setDialogState
755
+ } = _ref3;
756
+ const client = useClient();
757
+ const pageNoRef = useRef(0);
758
+ const [isLastPage, setLastPage] = useState(false);
759
+ const [isLoading, setLoading] = useState(false);
760
+ const [assets, setAssets] = useState([]);
761
+ const fetchPage = useCallback(pageNo => {
762
+ const start = pageNo * PER_PAGE;
763
+ const end = start + PER_PAGE;
764
+ setLoading(true);
765
+ return client.fetch(createQuery(start, end)).then(result => {
766
+ setLastPage(result.length < PER_PAGE);
767
+ setAssets(prev => prev.concat(result));
768
+ }).finally(() => setLoading(false));
769
+ }, [client]);
770
+ const handleSelect = useCallback(id => {
771
+ const selected = assets.find(doc => doc._id === id);
772
+ if (!selected) {
773
+ throw new TypeError("Failed to find video asset with id: ".concat(id));
774
+ }
775
+ onChange(PatchEvent.from([setIfMissing({
776
+ asset: {}
777
+ }), set({
778
+ _type: "reference",
779
+ _weak: true,
780
+ _ref: selected._id
781
+ }, ["asset"])]));
782
+ setDialogState(false);
783
+ }, [assets, onChange, setDialogState]);
784
+ const handleLoadMore = useCallback(() => {
785
+ fetchPage(++pageNoRef.current);
786
+ }, [fetchPage]);
787
+ useEffect(() => void fetchPage(pageNoRef.current), [fetchPage]);
788
+ return /* @__PURE__ */jsx(VideoSource, {
789
+ onSelect: handleSelect,
790
+ assets,
791
+ isLastPage,
792
+ isLoading,
793
+ onLoadMore: handleLoadMore
794
+ });
795
+ }
796
+ function InputBrowser(_ref4) {
797
+ let {
798
+ setDialogState,
799
+ asset,
800
+ onChange
801
+ } = _ref4;
802
+ const id = "InputBrowser".concat(useId());
803
+ const handleClose = useCallback(() => setDialogState(false), [setDialogState]);
804
+ return /* @__PURE__ */jsx(Dialog, {
805
+ scheme: "dark",
806
+ __unstable_autoFocus: true,
807
+ header: "Select video",
808
+ id,
809
+ onClose: handleClose,
810
+ width: 2,
811
+ children: /* @__PURE__ */jsx(SelectAssets, {
812
+ asset,
813
+ onChange,
814
+ setDialogState
815
+ })
816
+ });
817
+ }
818
+ const useCancelUpload = (asset, onChange) => {
819
+ const client = useClient();
820
+ return useCallback(() => {
821
+ if (!asset) {
822
+ return;
823
+ }
824
+ onChange(PatchEvent.from(unset()));
825
+ if (asset.assetId) {
826
+ deleteAsset(client, asset.assetId);
827
+ }
828
+ if (asset._id) {
829
+ client.delete(asset._id);
830
+ }
831
+ }, [asset, client, onChange]);
832
+ };
833
+ function getVideoSrc(_ref5) {
834
+ let {
835
+ asset,
836
+ client
837
+ } = _ref5;
838
+ const playbackId = getPlaybackId(asset);
839
+ const searchParams = new URLSearchParams();
840
+ if (getPlaybackPolicy(asset) === "signed") {
841
+ const token = generateJwt(client, playbackId, "v");
842
+ searchParams.set("token", token);
843
+ }
844
+ return "https://stream.mux.com/".concat(playbackId, ".m3u8?").concat(searchParams);
845
+ }
846
+ function EditThumbnailDialog(_ref6) {
847
+ let {
848
+ asset,
849
+ getCurrentTime,
850
+ setDialogState
851
+ } = _ref6;
852
+ const client = useClient();
853
+ const dialogId = "EditThumbnailDialog".concat(useId());
854
+ const nextTime = useMemo(() => getCurrentTime(), [getCurrentTime]);
855
+ const assetWithNewThumbnail = useMemo(() => _objectSpread(_objectSpread({}, asset), {}, {
856
+ thumbTime: nextTime
857
+ }), [asset, nextTime]);
858
+ const [saving, setSaving] = useState(false);
859
+ const [error, setError] = useState(null);
860
+ const handleSave = useCallback(() => {
861
+ setSaving(true);
862
+ client.patch(asset._id).set({
863
+ thumbTime: nextTime
864
+ }).commit({
865
+ returnDocuments: false
866
+ }).then(() => void setDialogState(false)).catch(setError).finally(() => void setSaving(false));
867
+ }, [client, asset._id, nextTime, setDialogState]);
868
+ const width = 300 * getDevicePixelRatio({
869
+ maxDpr: 2
870
+ });
871
+ if (error) {
872
+ throw error;
873
+ }
874
+ return /* @__PURE__ */jsx(Dialog, {
875
+ id: dialogId,
876
+ header: "Edit thumbnail",
877
+ onClose: () => setDialogState(false),
878
+ footer: /* @__PURE__ */jsx(Stack, {
879
+ padding: 3,
880
+ children: /* @__PURE__ */jsx(Button, {
881
+ mode: "ghost",
882
+ tone: "primary",
883
+ loading: saving,
884
+ onClick: handleSave,
885
+ text: "Set new thumbnail"
886
+ }, "thumbnail")
887
+ }),
888
+ children: /* @__PURE__ */jsxs(Stack, {
889
+ space: 3,
890
+ padding: 3,
891
+ children: [/* @__PURE__ */jsxs(Stack, {
892
+ space: 2,
893
+ children: [/* @__PURE__ */jsx(Text, {
894
+ size: 1,
895
+ weight: "semibold",
896
+ children: "Current:"
897
+ }), /* @__PURE__ */jsx(VideoThumbnail, {
898
+ asset,
899
+ width
900
+ })]
901
+ }), /* @__PURE__ */jsxs(Stack, {
902
+ space: 2,
903
+ children: [/* @__PURE__ */jsx(Text, {
904
+ size: 1,
905
+ weight: "semibold",
906
+ children: "New:"
907
+ }), /* @__PURE__ */jsx(VideoThumbnail, {
908
+ asset: assetWithNewThumbnail,
909
+ width
910
+ })]
911
+ })]
912
+ })
913
+ });
914
+ }
915
+ function getStoryboardSrc(_ref7) {
916
+ let {
917
+ asset,
918
+ client
919
+ } = _ref7;
920
+ const playbackId = getPlaybackId(asset);
921
+ const searchParams = new URLSearchParams();
922
+ if (getPlaybackPolicy(asset) === "signed") {
923
+ const token = generateJwt(client, playbackId, "s");
924
+ searchParams.set("token", token);
925
+ }
926
+ return "https://image.mux.com/".concat(playbackId, "/storyboard.vtt?").concat(searchParams);
927
+ }
928
+ const VideoContainer = styled(Card)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n min-height: 150px;\n aspect-ratio: 16 / 9;\n overflow: hidden;\n border-radius: 1px;\n media-airplay-button[media-airplay-unavailable] {\n display: none;\n }\n media-volume-range[media-volume-unavailable] {\n display: none;\n }\n media-pip-button[media-pip-unavailable] {\n display: none;\n }\n media-controller {\n --media-control-background: transparent;\n --media-control-hover-background: transparent;\n --media-range-track-background-color: rgba(255, 255, 255, 0.5);\n --media-range-track-border-radius: 3px;\n width: 100%;\n height: 100%;\n background-color: transparent;\n }\n media-control-bar {\n --media-button-icon-width: 18px;\n --media-preview-time-margin: 0px;\n }\n media-control-bar:not([slot]) :is([role='button'], [role='switch'], button) {\n height: 44px;\n }\n .size-extra-small media-control-bar [role='button'],\n .size-extra-small media-control-bar [role='switch'] {\n height: auto;\n padding: 4.4% 3.2%;\n }\n .mxp-spacer {\n flex-grow: 1;\n height: 100%;\n background-color: var(--media-control-background, rgba(20, 20, 30, 0.7));\n }\n media-controller::part(vertical-layer) {\n transition: background-color 1s;\n }\n media-controller:is([media-paused], :not([user-inactive]))::part(vertical-layer) {\n background-color: rgba(0, 0, 0, 0.6);\n transition: background-color 0.25s;\n }\n .mxp-center-controls {\n --media-background-color: transparent;\n --media-button-icon-width: 100%;\n --media-button-icon-height: auto;\n pointer-events: none;\n width: 100%;\n display: flex;\n flex-flow: row;\n align-items: center;\n justify-content: center;\n }\n .mxp-center-controls media-play-button {\n --media-control-background: transparent;\n --media-control-hover-background: transparent;\n padding: 0;\n width: max(27px, min(9%, 90px));\n }\n .mxp-center-controls media-seek-backward-button,\n .mxp-center-controls media-seek-forward-button {\n --media-control-background: transparent;\n --media-control-hover-background: transparent;\n padding: 0;\n margin: 0 10%;\n width: min(7%, 70px);\n }\n media-loading-indicator {\n --media-loading-icon-width: 100%;\n --media-button-icon-height: auto;\n pointer-events: none;\n position: absolute;\n width: min(15%, 150px);\n display: flex;\n flex-flow: row;\n align-items: center;\n justify-content: center;\n }\n /* Intentionally don't target the div for transition but the children\n of the div. Prevents messing with media-chrome's autohide feature. */\n media-loading-indicator + div * {\n transition: opacity 0.15s;\n opacity: 1;\n }\n media-loading-indicator[media-loading]:not([media-paused]) ~ div > * {\n opacity: 0;\n transition-delay: 400ms;\n }\n media-volume-range {\n width: min(100%, 100px);\n }\n media-time-display {\n white-space: nowrap;\n }\n :is(media-time-display, media-text-display, media-playback-rate-button) {\n color: inherit;\n }\n media-controller:fullscreen media-control-bar[slot='top-chrome'] {\n /* Hide menus and buttons that trigger modals when in full-screen */\n display: none;\n }\n video {\n background: transparent;\n }\n media-controller:not(:fullscreen) video {\n aspect-ratio: 16 / 9;\n }\n media-controller:not(:-webkit-full-screen) video {\n aspect-ratio: 16 / 9;\n }\n"])));
929
+ const StyledCenterControls = styled.div(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n && {\n --media-background-color: transparent;\n --media-button-icon-width: 100%;\n --media-button-icon-height: auto;\n pointer-events: none;\n width: 100%;\n display: flex;\n flex-flow: row;\n align-items: center;\n justify-content: center;\n media-play-button {\n --media-control-background: transparent;\n --media-control-hover-background: transparent;\n padding: 0;\n width: max(27px, min(9%, 90px));\n }\n }\n"])));
930
+ const TopControls = styled(MediaControlBar)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n justify-content: flex-end;\n button {\n height: auto;\n }\n"])));
931
+ function PosterImage(_ref8) {
932
+ let {
933
+ asset
934
+ } = _ref8;
935
+ const client = useClient();
936
+ const ref = useRef(null);
937
+ const src = useMemo(() => getPosterSrc({
938
+ client,
939
+ asset,
940
+ width: 1920,
941
+ height: 1080
942
+ }), [client, asset]);
943
+ useEffect(() => {
944
+ var _a;
945
+ if (ref.current) {
946
+ const style = document.createElement("style");
947
+ style.innerHTML = "img { object-fit: contain; }";
948
+ if ((_a = ref.current) == null ? void 0 : _a.shadowRoot) {
949
+ ref.current.shadowRoot.appendChild(style);
950
+ }
951
+ }
952
+ }, []);
953
+ return /* @__PURE__ */jsx(MediaPosterImage, {
954
+ ref,
955
+ slot: "poster",
956
+ src
957
+ });
958
+ }
959
+ function ThumbnailsMetadataTrack(_ref9) {
960
+ let {
961
+ asset
962
+ } = _ref9;
963
+ const client = useClient();
964
+ const [src] = useState(() => getStoryboardSrc({
965
+ asset,
966
+ client
967
+ }));
968
+ return /* @__PURE__ */jsx("track", {
969
+ label: "thumbnails",
970
+ default: true,
971
+ kind: "metadata",
972
+ src
973
+ });
974
+ }
975
+ const CardWrapper = styled(Card)(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n min-height: 82px;\n box-sizing: border-box;\n"])));
976
+ const FlexWrapper = styled(Flex)(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n text-overflow: ellipsis;\n overflow: hidden;\n"])));
977
+ const LeftSection = styled(Stack)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n position: relative;\n width: 60%;\n"])));
978
+ const CodeWrapper = styled(Code)(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n\n code {\n overflow: hidden;\n text-overflow: ellipsis;\n position: relative;\n max-width: 200px;\n }\n"])));
979
+ const UploadProgress = _ref10 => {
980
+ let {
981
+ progress = 100,
982
+ onCancel,
983
+ filename,
984
+ text = "Uploading"
985
+ } = _ref10;
986
+ return /* @__PURE__ */jsx(CardWrapper, {
987
+ tone: "primary",
988
+ padding: 4,
989
+ border: true,
990
+ height: "fill",
991
+ children: /* @__PURE__ */jsxs(FlexWrapper, {
992
+ align: "center",
993
+ justify: "space-between",
994
+ height: "fill",
995
+ direction: "row",
996
+ gap: 2,
997
+ children: [/* @__PURE__ */jsxs(LeftSection, {
998
+ children: [/* @__PURE__ */jsx(Flex, {
999
+ justify: "center",
1000
+ gap: [3, 3, 2, 2],
1001
+ direction: ["column", "column", "row"],
1002
+ children: /* @__PURE__ */jsx(Text, {
1003
+ size: 1,
1004
+ children: /* @__PURE__ */jsxs(Inline, {
1005
+ space: 2,
1006
+ children: [text, /* @__PURE__ */jsx(CodeWrapper, {
1007
+ size: 1,
1008
+ children: filename ? filename : "..."
1009
+ })]
1010
+ })
1011
+ })
1012
+ }), /* @__PURE__ */jsx(Card, {
1013
+ marginTop: 3,
1014
+ radius: 5,
1015
+ shadow: 1,
1016
+ children: /* @__PURE__ */jsx(LinearProgress, {
1017
+ value: progress
1018
+ })
1019
+ })]
1020
+ }), onCancel ? /* @__PURE__ */jsx(Button, {
1021
+ fontSize: 2,
1022
+ text: "Cancel upload",
1023
+ mode: "ghost",
1024
+ tone: "critical",
1025
+ onClick: onCancel
1026
+ }) : null]
1027
+ })
1028
+ });
1029
+ };
1030
+ const MuxVideo = _ref11 => {
1031
+ let {
1032
+ asset,
1033
+ buttons,
1034
+ readOnly,
1035
+ onChange,
1036
+ dialogState,
1037
+ setDialogState
1038
+ } = _ref11;
1039
+ var _a, _b, _c, _d;
1040
+ const client = useClient();
1041
+ const isLoading = useMemo(() => {
1042
+ if ((asset == null ? void 0 : asset.status) === "preparing") {
1043
+ return "Preparing the video";
1044
+ }
1045
+ if ((asset == null ? void 0 : asset.status) === "waiting_for_upload") {
1046
+ return "Waiting for upload to start";
1047
+ }
1048
+ if ((asset == null ? void 0 : asset.status) === "waiting") {
1049
+ return "Processing upload";
1050
+ }
1051
+ if ((asset == null ? void 0 : asset.status) === "ready") {
1052
+ return false;
1053
+ }
1054
+ if (typeof (asset == null ? void 0 : asset.status) === "undefined") {
1055
+ return false;
1056
+ }
1057
+ return true;
1058
+ }, [asset]);
1059
+ const isPreparingStaticRenditions = useMemo(() => {
1060
+ var _a2, _b2, _c2, _d2;
1061
+ if (((_b2 = (_a2 = asset == null ? void 0 : asset.data) == null ? void 0 : _a2.static_renditions) == null ? void 0 : _b2.status) === "preparing") {
1062
+ return true;
1063
+ }
1064
+ if (((_d2 = (_c2 = asset == null ? void 0 : asset.data) == null ? void 0 : _c2.static_renditions) == null ? void 0 : _d2.status) === "ready") {
1065
+ return false;
1066
+ }
1067
+ return false;
1068
+ }, [(_b = (_a = asset == null ? void 0 : asset.data) == null ? void 0 : _a.static_renditions) == null ? void 0 : _b.status]);
1069
+ const videoSrc = useMemo(() => asset.playbackId && getVideoSrc({
1070
+ client,
1071
+ asset
1072
+ }), [asset, client]);
1073
+ const [error, setError] = useState(null);
1074
+ const handleError = useCallback(event => setError(event.currentTarget.error), []);
1075
+ const playRef = useRef(null);
1076
+ const muteRef = useRef(null);
1077
+ const video = useRef(null);
1078
+ const getCurrentTime = useCallback(() => {
1079
+ var _a2, _b2;
1080
+ return (_b2 = (_a2 = video.current) == null ? void 0 : _a2.currentTime) != null ? _b2 : 0;
1081
+ }, [video]);
1082
+ const handleCancelUpload = useCancelUpload(asset, onChange);
1083
+ useEffect(() => {
1084
+ var _a2, _b2;
1085
+ const style = document.createElement("style");
1086
+ style.innerHTML = "button svg { vertical-align: middle; }";
1087
+ if ((_a2 = playRef.current) == null ? void 0 : _a2.shadowRoot) {
1088
+ playRef.current.shadowRoot.appendChild(style);
1089
+ }
1090
+ if ((_b2 = muteRef == null ? void 0 : muteRef.current) == null ? void 0 : _b2.shadowRoot) {
1091
+ muteRef.current.shadowRoot.appendChild(style.cloneNode(true));
1092
+ }
1093
+ }, []);
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
+ useEffect(() => {
1109
+ var _a2, _b2, _c2;
1110
+ if ((asset == null ? void 0 : asset.status) === "errored") {
1111
+ handleCancelUpload();
1112
+ throw new Error((_c2 = (_b2 = (_a2 = asset.data) == null ? void 0 : _a2.errors) == null ? void 0 : _b2.messages) == null ? void 0 : _c2.join(" "));
1113
+ }
1114
+ }, [(_d = (_c = asset.data) == null ? void 0 : _c.errors) == null ? void 0 : _d.messages, asset == null ? void 0 : asset.status, handleCancelUpload]);
1115
+ if (error) {
1116
+ throw error;
1117
+ }
1118
+ if (!asset || !asset.status) {
1119
+ return null;
1120
+ }
1121
+ if (isLoading) {
1122
+ return /* @__PURE__ */jsx(UploadProgress, {
1123
+ progress: 100,
1124
+ filename: asset == null ? void 0 : asset.filename,
1125
+ text: isLoading !== true && isLoading || "Waiting for Mux to complete the file",
1126
+ onCancel: readOnly ? void 0 : () => handleCancelUpload()
1127
+ });
1128
+ }
1129
+ return /* @__PURE__ */jsxs(Fragment, {
1130
+ children: [/* @__PURE__ */jsxs(VideoContainer, {
1131
+ shadow: 1,
1132
+ tone: "transparent",
1133
+ scheme: "dark",
1134
+ children: [/* @__PURE__ */jsxs(MediaController, {
1135
+ children: [/* @__PURE__ */jsx("video", {
1136
+ playsInline: true,
1137
+ ref: video,
1138
+ onError: handleError,
1139
+ slot: "media",
1140
+ preload: "metadata",
1141
+ crossOrigin: "anonomous",
1142
+ children: /* @__PURE__ */jsx(ThumbnailsMetadataTrack, {
1143
+ asset
1144
+ })
1145
+ }), /* @__PURE__ */jsx(PosterImage, {
1146
+ asset
1147
+ }), /* @__PURE__ */jsx(MediaLoadingIndicator, {
1148
+ slot: "centered-chrome",
1149
+ noAutoHide: true
1150
+ }), /* @__PURE__ */jsx(StyledCenterControls, {
1151
+ slot: "centered-chrome",
1152
+ children: /* @__PURE__ */jsx(MediaPlayButton, {})
1153
+ }), buttons && /* @__PURE__ */jsx(TopControls, {
1154
+ slot: "top-chrome",
1155
+ children: buttons
1156
+ }), /* @__PURE__ */jsxs(MediaControlBar, {
1157
+ children: [/* @__PURE__ */jsx(MediaMuteButton, {}), /* @__PURE__ */jsx(MediaTimeDisplay, {}), /* @__PURE__ */jsx(MediaTimeRange, {}), /* @__PURE__ */jsx(MediaDurationDisplay, {}), /* @__PURE__ */jsx(MediaFullscreenButton, {})]
1158
+ })]
1159
+ }), isPreparingStaticRenditions && /* @__PURE__ */jsx(Card, {
1160
+ padding: 2,
1161
+ radius: 1,
1162
+ style: {
1163
+ background: "var(--card-fg-color)",
1164
+ position: "absolute",
1165
+ top: "0.5em",
1166
+ left: "0.5em"
1167
+ },
1168
+ children: /* @__PURE__ */jsx(Text, {
1169
+ size: 1,
1170
+ style: {
1171
+ color: "var(--card-bg-color)"
1172
+ },
1173
+ children: "MUX is preparing static renditions, please stand by"
1174
+ })
1175
+ })]
1176
+ }), dialogState === "edit-thumbnail" && /* @__PURE__ */jsx(EditThumbnailDialog, {
1177
+ asset,
1178
+ getCurrentTime,
1179
+ setDialogState
1180
+ })]
1181
+ });
1182
+ };
1183
+ function focusRingBorderStyle(border) {
1184
+ return "inset 0 0 0 ".concat(border.width, "px ").concat(border.color);
1185
+ }
1186
+ function focusRingStyle(opts) {
1187
+ const {
1188
+ base,
1189
+ border,
1190
+ focusRing
1191
+ } = opts;
1192
+ const focusRingOutsetWidth = focusRing.offset + focusRing.width;
1193
+ const focusRingInsetWidth = 0 - focusRing.offset;
1194
+ const bgColor = base ? base.bg : "var(--card-bg-color)";
1195
+ return [focusRingInsetWidth > 0 && "inset 0 0 0 ".concat(focusRingInsetWidth, "px var(--card-focus-ring-color)"), border && focusRingBorderStyle(border), focusRingInsetWidth < 0 && "0 0 0 ".concat(0 - focusRingInsetWidth, "px ").concat(bgColor), focusRingOutsetWidth > 0 && "0 0 0 ".concat(focusRingOutsetWidth, "px var(--card-focus-ring-color)")].filter(Boolean).join(",");
1196
+ }
1197
+ const FileButton = styled(MenuItem)(_ref12 => {
1198
+ let {
1199
+ theme
1200
+ } = _ref12;
1201
+ const {
1202
+ focusRing
1203
+ } = theme.sanity;
1204
+ const base = theme.sanity.color.base;
1205
+ const border = {
1206
+ width: 1,
1207
+ color: "var(--card-border-color)"
1208
+ };
1209
+ return css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n position: relative;\n\n &:not([data-disabled='true']) {\n &:focus-within {\n box-shadow: ", ";\n }\n }\n\n & input {\n overflow: hidden;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n position: absolute;\n min-width: 0;\n display: block;\n appearance: none;\n padding: 0;\n margin: 0;\n border: 0;\n opacity: 0;\n }\n "])), focusRingStyle({
1210
+ base,
1211
+ border,
1212
+ focusRing
1213
+ }));
1214
+ });
1215
+ const FileInputMenuItem = React.forwardRef(function FileInputMenuItem2(props, forwardedRef) {
1216
+ 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);
1231
+ const idHook = useId();
1232
+ const id = idProp || idHook;
1233
+ const handleChange = React.useCallback(event => {
1234
+ if (onSelect && event.target.files) {
1235
+ onSelect(Array.from(event.target.files));
1236
+ }
1237
+ }, [onSelect]);
1238
+ const content = /* @__PURE__ */jsxs(Flex, {
1239
+ align: "center",
1240
+ justify: "flex-start",
1241
+ padding,
1242
+ children: [icon && /* @__PURE__ */jsx(Box, {
1243
+ marginRight: text ? space : void 0,
1244
+ children: /* @__PURE__ */jsxs(Text, {
1245
+ size: fontSize,
1246
+ children: [isValidElement(icon) && icon, isValidElementType(icon) && createElement(icon)]
1247
+ })
1248
+ }), text && /* @__PURE__ */jsx(Text, {
1249
+ align: textAlign,
1250
+ size: fontSize,
1251
+ textOverflow: "ellipsis",
1252
+ children: text
1253
+ })]
1254
+ });
1255
+ return /* @__PURE__ */jsxs(FileButton, _objectSpread(_objectSpread({}, rest), {}, {
1256
+ htmlFor: id,
1257
+ padding: 0,
1258
+ fontSize: 2,
1259
+ disabled,
1260
+ ref: forwardedRef,
1261
+ children: [content, /* @__PURE__ */jsx("input", {
1262
+ "data-testid": "file-button-input",
1263
+ accept,
1264
+ capture,
1265
+ id,
1266
+ multiple,
1267
+ onChange: handleChange,
1268
+ type: "file",
1269
+ value: "",
1270
+ disabled
1271
+ })]
1272
+ }));
1273
+ });
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
+ const LockButton = styled(Button)(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n background: transparent;\n color: white;\n"])));
1276
+ function PlayerActionsMenu(props) {
1277
+ const {
1278
+ asset,
1279
+ readOnly,
1280
+ dialogState,
1281
+ setDialogState,
1282
+ onChange,
1283
+ onUpload
1284
+ } = props;
1285
+ const [open, setOpen] = useState(false);
1286
+ const [menuElement, setMenuRef] = useState(null);
1287
+ const isSigned = useMemo(() => getPlaybackPolicy(asset) === "signed", [asset]);
1288
+ const onReset = useCallback(() => onChange(PatchEvent.from(unset([]))), [onChange]);
1289
+ useEffect(() => {
1290
+ if (open && dialogState) {
1291
+ setOpen(false);
1292
+ }
1293
+ }, [dialogState, open]);
1294
+ useClickOutside(useCallback(() => setOpen(false), []), [menuElement]);
1295
+ return /* @__PURE__ */jsxs(Inline, {
1296
+ space: 1,
1297
+ padding: 2,
1298
+ children: [isSigned && /* @__PURE__ */jsx(Tooltip, {
1299
+ content: /* @__PURE__ */jsx(Box, {
1300
+ padding: 2,
1301
+ children: /* @__PURE__ */jsx(Text, {
1302
+ muted: true,
1303
+ size: 1,
1304
+ children: "Signed playback policy"
1305
+ })
1306
+ }),
1307
+ placement: "right",
1308
+ portal: true,
1309
+ children: /* @__PURE__ */jsx(LockCard, {
1310
+ radius: 2,
1311
+ margin: 2,
1312
+ scheme: "dark",
1313
+ tone: "positive",
1314
+ children: /* @__PURE__ */jsx(LockButton, {
1315
+ icon: LockIcon,
1316
+ mode: "bleed",
1317
+ tone: "positive"
1318
+ })
1319
+ })
1320
+ }), !readOnly && /* @__PURE__ */jsx(Button, {
1321
+ icon: EditIcon,
1322
+ mode: "ghost",
1323
+ onClick: () => setDialogState("edit-thumbnail")
1324
+ }), /* @__PURE__ */jsx(Popover, {
1325
+ content: /* @__PURE__ */jsxs(Menu, {
1326
+ ref: setMenuRef,
1327
+ children: [/* @__PURE__ */jsx(Box, {
1328
+ padding: 2,
1329
+ children: /* @__PURE__ */jsx(Label$1, {
1330
+ muted: true,
1331
+ size: 1,
1332
+ children: "Replace"
1333
+ })
1334
+ }), /* @__PURE__ */jsx(FileInputMenuItem, {
1335
+ accept: "video/*",
1336
+ icon: UploadIcon,
1337
+ mode: "bleed",
1338
+ onSelect: onUpload,
1339
+ text: "Upload",
1340
+ disabled: readOnly,
1341
+ fontSize: 2
1342
+ }), /* @__PURE__ */jsx(MenuItem, {
1343
+ icon: SearchIcon,
1344
+ text: "Browse",
1345
+ onClick: () => setDialogState("select-video")
1346
+ }), /* @__PURE__ */jsx(MenuDivider, {}), /* @__PURE__ */jsx(MenuItem, {
1347
+ icon: PlugIcon,
1348
+ text: "Configure API",
1349
+ onClick: () => setDialogState("secrets")
1350
+ }), /* @__PURE__ */jsx(MenuDivider, {}), /* @__PURE__ */jsx(MenuItem, {
1351
+ tone: "critical",
1352
+ icon: ResetIcon,
1353
+ text: "Clear field",
1354
+ onClick: onReset,
1355
+ disabled: readOnly
1356
+ })]
1357
+ }),
1358
+ portal: true,
1359
+ open,
1360
+ children: /* @__PURE__ */jsx(Button, {
1361
+ icon: EllipsisVerticalIcon,
1362
+ mode: "ghost",
1363
+ onClick: () => {
1364
+ setDialogState(false);
1365
+ setOpen(true);
1366
+ }
1367
+ })
1368
+ })]
1369
+ });
1370
+ }
1371
+ var PlayerActionsMenu$1 = memo(PlayerActionsMenu);
1372
+ function withFocusRing(component) {
1373
+ return styled(component)(props => {
1374
+ const border = {
1375
+ width: props.$border ? 1 : 0,
1376
+ color: "var(--card-border-color)"
1377
+ };
1378
+ return css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n --card-focus-box-shadow: ", ";\n\n border-radius: ", ";\n outline: none;\n box-shadow: var(--card-focus-box-shadow);\n\n &:focus {\n --card-focus-box-shadow: ", ";\n }\n "])), focusRingBorderStyle(border), rem(props.theme.sanity.radius[1]), focusRingStyle({
1379
+ base: props.theme.sanity.color.base,
1380
+ border,
1381
+ focusRing: props.theme.sanity.focusRing
1382
+ }));
1383
+ });
1384
+ }
1385
+ const ctrlKey = 17;
1386
+ const cmdKey = 91;
1387
+ const UploadCardWithFocusRing = withFocusRing(Card);
1388
+ const UploadCard$1 = forwardRef((_ref13, forwardedRef) => {
1389
+ let {
1390
+ children,
1391
+ tone,
1392
+ onPaste,
1393
+ onDrop,
1394
+ onDragEnter,
1395
+ onDragLeave,
1396
+ onDragOver
1397
+ } = _ref13;
1398
+ const ctrlDown = useRef(false);
1399
+ const inputRef = useRef(null);
1400
+ const handleKeyDown = useCallback(event => {
1401
+ if (event.keyCode == ctrlKey || event.keyCode == cmdKey) {
1402
+ ctrlDown.current = true;
1403
+ }
1404
+ const vKey = 86;
1405
+ if (ctrlDown.current && event.keyCode == vKey) {
1406
+ inputRef.current.focus();
1407
+ }
1408
+ }, []);
1409
+ const handleKeyUp = useCallback(event => {
1410
+ if (event.keyCode == ctrlKey || event.keyCode == cmdKey) {
1411
+ ctrlDown.current = false;
1412
+ }
1413
+ }, []);
1414
+ return /* @__PURE__ */jsxs(UploadCardWithFocusRing, {
1415
+ tone,
1416
+ height: "fill",
1417
+ ref: forwardedRef,
1418
+ padding: 0,
1419
+ radius: 2,
1420
+ shadow: 0,
1421
+ tabIndex: 0,
1422
+ onKeyDown: handleKeyDown,
1423
+ onKeyUp: handleKeyUp,
1424
+ onPaste,
1425
+ onDrop,
1426
+ onDragEnter,
1427
+ onDragLeave,
1428
+ onDragOver,
1429
+ children: [/* @__PURE__ */jsx(HiddenInput$1, {
1430
+ ref: inputRef,
1431
+ onPaste
1432
+ }), children]
1433
+ });
1434
+ });
1435
+ const HiddenInput$1 = styled.input.attrs({
1436
+ type: "text"
1437
+ })(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n border: 0;\n color: white;\n opacity: 0;\n\n &:focus {\n outline: none;\n }\n"])));
1438
+ const HiddenInput = styled.input(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n overflow: hidden;\n width: 0.1px;\n height: 0.1px;\n opacity: 0;\n position: absolute;\n z-index: -1;\n"])));
1439
+ const Label = styled.label(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n"])));
1440
+ const FileInputButton = _ref14 => {
1441
+ let {
1442
+ onSelect
1443
+ } = _ref14,
1444
+ props = _objectWithoutProperties(_ref14, _excluded2);
1445
+ const inputId = "FileSelect".concat(useId());
1446
+ const inputRef = useRef(null);
1447
+ const handleSelect = useCallback(event => {
1448
+ if (onSelect) {
1449
+ onSelect(event.target.files);
1450
+ }
1451
+ }, [onSelect]);
1452
+ const handleButtonClick = useCallback(() => {
1453
+ var _a;
1454
+ return (_a = inputRef.current) == null ? void 0 : _a.click();
1455
+ }, []);
1456
+ return /* @__PURE__ */jsxs(Label, {
1457
+ htmlFor: inputId,
1458
+ children: [/* @__PURE__ */jsx(HiddenInput, {
1459
+ accept: "video/*",
1460
+ ref: inputRef,
1461
+ tabIndex: 0,
1462
+ type: "file",
1463
+ id: inputId,
1464
+ onChange: handleSelect,
1465
+ value: ""
1466
+ }), /* @__PURE__ */jsx(Button, _objectSpread({
1467
+ onClick: handleButtonClick,
1468
+ mode: "default",
1469
+ tone: "primary",
1470
+ style: {
1471
+ width: "100%"
1472
+ }
1473
+ }, props))]
1474
+ });
1475
+ };
1476
+ const UploadCard = styled(Card)(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n && {\n border-style: dashed;\n }\n"])));
1477
+ const ConfigureApiBox = styled(Box)(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n right: 0;\n"])));
1478
+ function UploadPlaceholder(props) {
1479
+ const {
1480
+ setDialogState,
1481
+ readOnly,
1482
+ onSelect,
1483
+ hovering,
1484
+ needsSetup
1485
+ } = props;
1486
+ const handleBrowse = useCallback(() => setDialogState("select-video"), [setDialogState]);
1487
+ const handleConfigureApi = useCallback(() => setDialogState("secrets"), [setDialogState]);
1488
+ return /* @__PURE__ */jsx(Box, {
1489
+ style: {
1490
+ padding: 1,
1491
+ position: "relative"
1492
+ },
1493
+ height: "stretch",
1494
+ children: /* @__PURE__ */jsxs(UploadCard, {
1495
+ sizing: "border",
1496
+ height: "fill",
1497
+ tone: readOnly ? "transparent" : "inherit",
1498
+ border: true,
1499
+ padding: 3,
1500
+ style: hovering ? {
1501
+ borderColor: "transparent"
1502
+ } : void 0,
1503
+ children: [/* @__PURE__ */jsx(ConfigureApiBox, {
1504
+ padding: 3,
1505
+ children: /* @__PURE__ */jsx(Button, {
1506
+ padding: 3,
1507
+ radius: 3,
1508
+ tone: needsSetup ? "critical" : void 0,
1509
+ onClick: handleConfigureApi,
1510
+ icon: PlugIcon,
1511
+ mode: "bleed"
1512
+ })
1513
+ }), /* @__PURE__ */jsxs(Flex, {
1514
+ align: "center",
1515
+ justify: "space-between",
1516
+ gap: 4,
1517
+ direction: ["column", "column", "row"],
1518
+ paddingY: [2, 2, 0],
1519
+ sizing: "border",
1520
+ height: "fill",
1521
+ children: [/* @__PURE__ */jsxs(Flex, {
1522
+ align: "center",
1523
+ justify: "center",
1524
+ gap: 2,
1525
+ flex: 1,
1526
+ children: [/* @__PURE__ */jsx(Flex, {
1527
+ justify: "center",
1528
+ children: /* @__PURE__ */jsx(Text, {
1529
+ muted: true,
1530
+ children: /* @__PURE__ */jsx(DocumentVideoIcon, {})
1531
+ })
1532
+ }), /* @__PURE__ */jsx(Flex, {
1533
+ justify: "center",
1534
+ children: /* @__PURE__ */jsx(Text, {
1535
+ size: 1,
1536
+ muted: true,
1537
+ children: "Drag video or paste URL here"
1538
+ })
1539
+ })]
1540
+ }), /* @__PURE__ */jsxs(Inline, {
1541
+ space: 2,
1542
+ children: [/* @__PURE__ */jsx(FileInputButton, {
1543
+ mode: "ghost",
1544
+ tone: "default",
1545
+ icon: UploadIcon,
1546
+ text: "Upload",
1547
+ onSelect
1548
+ }), /* @__PURE__ */jsx(Button, {
1549
+ mode: "ghost",
1550
+ icon: SearchIcon,
1551
+ text: "Select",
1552
+ onClick: handleBrowse
1553
+ })]
1554
+ })]
1555
+ })]
1556
+ })
1557
+ });
1558
+ }
1559
+ class MuxVideoInputUploader extends Component {
1560
+ constructor() {
1561
+ super(...arguments);
1562
+ this.state = {
1563
+ isDraggingOver: false,
1564
+ invalidPaste: false,
1565
+ invalidFile: false,
1566
+ uploadProgress: null,
1567
+ fileInfo: null,
1568
+ uuid: null,
1569
+ error: null,
1570
+ url: null
1571
+ };
1572
+ this.dragEnteredEls = [];
1573
+ this.ctrlDown = false;
1574
+ this.upload = null;
1575
+ this.container = React.createRef();
1576
+ this.handleProgress = evt => {
1577
+ this.setState({
1578
+ uploadProgress: evt.percent
1579
+ });
1580
+ };
1581
+ this.onUpload = files => {
1582
+ this.setState({
1583
+ uploadProgress: 0,
1584
+ fileInfo: null,
1585
+ uuid: null
1586
+ });
1587
+ this.upload = uploadFile(this.props.config, this.props.client, files[0], {
1588
+ enableSignedUrls: this.props.secrets.enableSignedUrls
1589
+ }).pipe(takeUntil(this.onCancelUploadButtonClick$.pipe(tap(() => {
1590
+ if (this.state.uuid) {
1591
+ this.props.client.delete(this.state.uuid);
1592
+ }
1593
+ })))).subscribe({
1594
+ complete: () => {
1595
+ this.setState({
1596
+ error: null,
1597
+ uploadProgress: null,
1598
+ uuid: null
1599
+ });
1600
+ },
1601
+ next: event => {
1602
+ this.handleUploadEvent(event);
1603
+ },
1604
+ error: err => {
1605
+ this.setState({
1606
+ error: err,
1607
+ uploadProgress: null,
1608
+ uuid: null
1609
+ });
1610
+ }
1611
+ });
1612
+ };
1613
+ this.handleUploadEvent = event => {
1614
+ switch (event.type) {
1615
+ case "success":
1616
+ return this.handleUploadSuccess(event.asset);
1617
+ case "progress":
1618
+ return this.handleProgress(event);
1619
+ case "file":
1620
+ return this.setState({
1621
+ fileInfo: event.file
1622
+ });
1623
+ case "uuid":
1624
+ return this.setState({
1625
+ uuid: event.uuid
1626
+ });
1627
+ case "url":
1628
+ return this.setState({
1629
+ url: event.url,
1630
+ uploadProgress: 100
1631
+ });
1632
+ default:
1633
+ return null;
1634
+ }
1635
+ };
1636
+ this.handleUploadSuccess = asset => {
1637
+ this.setState({
1638
+ uploadProgress: 100
1639
+ });
1640
+ this.props.onChange(PatchEvent.from([setIfMissing({
1641
+ asset: {}
1642
+ }), set({
1643
+ _type: "reference",
1644
+ _weak: true,
1645
+ _ref: asset._id
1646
+ }, ["asset"])]));
1647
+ };
1648
+ this.handlePaste = event => {
1649
+ const clipboardData = event.clipboardData || window.clipboardData;
1650
+ const url = clipboardData.getData("text");
1651
+ const options = {
1652
+ enableSignedUrls: this.props.secrets.enableSignedUrls
1653
+ };
1654
+ this.upload = uploadUrl(this.props.config, this.props.client, url, options).subscribe({
1655
+ complete: () => {
1656
+ this.setState({
1657
+ error: null,
1658
+ uploadProgress: null,
1659
+ url: null
1660
+ });
1661
+ },
1662
+ next: sEvent => {
1663
+ this.handleUploadEvent(sEvent);
1664
+ },
1665
+ error: err => {
1666
+ let error;
1667
+ if (!err.message.toLowerCase().match("invalid url")) {
1668
+ error = err;
1669
+ }
1670
+ this.setState({
1671
+ invalidPaste: true,
1672
+ error
1673
+ }, () => {
1674
+ setTimeout(() => {
1675
+ this.setState({
1676
+ invalidPaste: false,
1677
+ uploadProgress: null
1678
+ });
1679
+ }, 2e3);
1680
+ });
1681
+ }
1682
+ });
1683
+ };
1684
+ this.handleDrop = event => {
1685
+ this.setState({
1686
+ isDraggingOver: false
1687
+ });
1688
+ event.preventDefault();
1689
+ event.stopPropagation();
1690
+ extractDroppedFiles(event.nativeEvent.dataTransfer).then(files => {
1691
+ if (files) {
1692
+ this.onUpload(files);
1693
+ }
1694
+ });
1695
+ };
1696
+ this.handleDragOver = event => {
1697
+ event.preventDefault();
1698
+ event.stopPropagation();
1699
+ };
1700
+ this.handleDragEnter = event => {
1701
+ var _a, _b;
1702
+ event.stopPropagation();
1703
+ this.dragEnteredEls.push(event.target);
1704
+ this.setState({
1705
+ isDraggingOver: true
1706
+ });
1707
+ const type = (_b = (_a = event.dataTransfer.items) == null ? void 0 : _a[0]) == null ? void 0 : _b.type;
1708
+ this.setState({
1709
+ invalidFile: !type.startsWith("video/")
1710
+ });
1711
+ };
1712
+ this.handleDragLeave = event => {
1713
+ event.stopPropagation();
1714
+ const idx = this.dragEnteredEls.indexOf(event.target);
1715
+ if (idx > -1) {
1716
+ this.dragEnteredEls.splice(idx, 1);
1717
+ }
1718
+ if (this.dragEnteredEls.length === 0) {
1719
+ this.setState({
1720
+ isDraggingOver: false
1721
+ });
1722
+ }
1723
+ };
1724
+ }
1725
+ componentWillUnmount() {
1726
+ this.unSubscribeToUpload();
1727
+ }
1728
+ componentDidMount() {
1729
+ const events$ = new Subject();
1730
+ this.onCancelUploadButtonClick$ = events$.asObservable();
1731
+ this.handleCancelUploadButtonClick = event => events$.next(event);
1732
+ }
1733
+ unSubscribeToUpload() {
1734
+ if (this.upload && !this.upload.closed) {
1735
+ this.upload.unsubscribe();
1736
+ }
1737
+ }
1738
+ render() {
1739
+ var _a;
1740
+ if (this.state.uploadProgress !== null) {
1741
+ return /* @__PURE__ */jsx(UploadProgress, {
1742
+ onCancel: this.handleCancelUploadButtonClick,
1743
+ progress: this.state.uploadProgress,
1744
+ filename: ((_a = this.state.fileInfo) == null ? void 0 : _a.name) || this.state.url
1745
+ });
1746
+ }
1747
+ if (this.state.error) {
1748
+ throw this.state.error;
1749
+ }
1750
+ return /* @__PURE__ */jsxs(Fragment, {
1751
+ children: [/* @__PURE__ */jsx(UploadCard$1, {
1752
+ tone: this.state.isDraggingOver && (this.state.invalidPaste || this.state.invalidFile) ? "critical" : this.state.isDraggingOver ? "positive" : void 0,
1753
+ onDrop: this.handleDrop,
1754
+ onDragOver: this.handleDragOver,
1755
+ onDragLeave: this.handleDragLeave,
1756
+ onDragEnter: this.handleDragEnter,
1757
+ onPaste: this.handlePaste,
1758
+ ref: this.container,
1759
+ children: this.props.asset ? /* @__PURE__ */jsx(MuxVideo, {
1760
+ readOnly: this.props.readOnly,
1761
+ asset: this.props.asset,
1762
+ onChange: this.props.onChange,
1763
+ dialogState: this.props.dialogState,
1764
+ setDialogState: this.props.setDialogState,
1765
+ buttons: /* @__PURE__ */jsx(PlayerActionsMenu$1, {
1766
+ asset: this.props.asset,
1767
+ dialogState: this.props.dialogState,
1768
+ setDialogState: this.props.setDialogState,
1769
+ onChange: this.props.onChange,
1770
+ onUpload: this.onUpload,
1771
+ readOnly: this.props.readOnly
1772
+ })
1773
+ }) : /* @__PURE__ */jsx(UploadPlaceholder, {
1774
+ hovering: this.state.isDraggingOver,
1775
+ onSelect: this.onUpload,
1776
+ readOnly: this.props.readOnly,
1777
+ setDialogState: this.props.setDialogState,
1778
+ needsSetup: this.props.needsSetup
1779
+ })
1780
+ }), this.props.dialogState === "select-video" && /* @__PURE__ */jsx(InputBrowser, {
1781
+ asset: this.props.asset,
1782
+ onChange: this.props.onChange,
1783
+ setDialogState: this.props.setDialogState
1784
+ })]
1785
+ });
1786
+ }
1787
+ }
1788
+ const useSaveSecrets = (client, secrets) => {
1789
+ return useCallback(async _ref15 => {
1790
+ let {
1791
+ token,
1792
+ secretKey,
1793
+ enableSignedUrls
1794
+ } = _ref15;
1795
+ let {
1796
+ signingKeyId,
1797
+ signingKeyPrivate
1798
+ } = secrets;
1799
+ try {
1800
+ await saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate);
1801
+ const valid = await testSecrets(client);
1802
+ if (!(valid == null ? void 0 : valid.status) && token && secretKey) {
1803
+ throw new Error("Invalid secrets");
1804
+ }
1805
+ } catch (err) {
1806
+ console.error("Error while trying to save secrets:", err);
1807
+ throw err;
1808
+ }
1809
+ if (enableSignedUrls) {
1810
+ const hasValidSigningKeys = await haveValidSigningKeys(client, signingKeyId, signingKeyPrivate);
1811
+ if (!hasValidSigningKeys) {
1812
+ try {
1813
+ const {
1814
+ data
1815
+ } = await createSigningKeys(client);
1816
+ signingKeyId = data.id;
1817
+ signingKeyPrivate = data.private_key;
1818
+ await saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate);
1819
+ } catch (err) {
1820
+ console.log("Error while creating and saving signing key:", err == null ? void 0 : err.message);
1821
+ throw err;
1822
+ }
1823
+ }
1824
+ }
1825
+ return {
1826
+ token,
1827
+ secretKey,
1828
+ enableSignedUrls,
1829
+ signingKeyId,
1830
+ signingKeyPrivate
1831
+ };
1832
+ }, [client, secrets]);
1833
+ };
1834
+ function init(_ref16) {
1835
+ let {
1836
+ token,
1837
+ secretKey,
1838
+ enableSignedUrls
1839
+ } = _ref16;
1840
+ return {
1841
+ submitting: false,
1842
+ error: null,
1843
+ token: token != null ? token : "",
1844
+ secretKey: secretKey != null ? secretKey : "",
1845
+ enableSignedUrls: enableSignedUrls != null ? enableSignedUrls : false
1846
+ };
1847
+ }
1848
+ function reducer(state, action) {
1849
+ switch (action == null ? void 0 : action.type) {
1850
+ case "submit":
1851
+ return _objectSpread(_objectSpread({}, state), {}, {
1852
+ submitting: true,
1853
+ error: null
1854
+ });
1855
+ case "error":
1856
+ return _objectSpread(_objectSpread({}, state), {}, {
1857
+ submitting: false,
1858
+ error: action.payload
1859
+ });
1860
+ case "reset":
1861
+ return init(action.payload);
1862
+ case "change":
1863
+ return _objectSpread(_objectSpread({}, state), {}, {
1864
+ [action.payload.name]: action.payload.value
1865
+ });
1866
+ default:
1867
+ throw new Error("Unknown action type: ".concat(action == null ? void 0 : action.type));
1868
+ }
1869
+ }
1870
+ const useSecretsFormState = secrets => useReducer(reducer, secrets, init);
1871
+ const ids = ["title", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"];
1872
+ function MuxLogo(_ref17) {
1873
+ let {
1874
+ height = 26
1875
+ } = _ref17;
1876
+ const id = useId();
1877
+ const [titleId, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r] = useMemo(() => ids.map(field => "".concat(id, "-").concat(field)), [id]);
1878
+ return /* @__PURE__ */jsxs("svg", {
1879
+ "aria-labelledby": titleId,
1880
+ role: "img",
1881
+ xmlns: "http://www.w3.org/2000/svg",
1882
+ xmlSpace: "preserve",
1883
+ viewBox: "92.08878326416016 102.66712188720703 692.76123046875 219.99948120117188",
1884
+ style: {
1885
+ height: "".concat(height, "px")
1886
+ },
1887
+ children: [/* @__PURE__ */jsx("title", {
1888
+ id: titleId,
1889
+ children: "Mux Logo"
1890
+ }), /* @__PURE__ */jsxs("defs", {
1891
+ children: [/* @__PURE__ */jsxs("linearGradient", {
1892
+ id: c,
1893
+ spreadMethod: "pad",
1894
+ gradientTransform: "matrix(528.38055 0 0 -528.38055 63.801 159.5)",
1895
+ gradientUnits: "userSpaceOnUse",
1896
+ y2: 0,
1897
+ x2: 1,
1898
+ y1: 0,
1899
+ x1: 0,
1900
+ children: [/* @__PURE__ */jsx("stop", {
1901
+ offset: 0,
1902
+ style: {
1903
+ stopOpacity: 1,
1904
+ stopColor: "#ff4e00"
1905
+ }
1906
+ }), /* @__PURE__ */jsx("stop", {
1907
+ offset: 1,
1908
+ style: {
1909
+ stopOpacity: 1,
1910
+ stopColor: "#ff1791"
1911
+ }
1912
+ })]
1913
+ }), /* @__PURE__ */jsxs("linearGradient", {
1914
+ id: d,
1915
+ spreadMethod: "pad",
1916
+ gradientTransform: "matrix(523.66766 0 0 -523.66766 67.897 159.5)",
1917
+ gradientUnits: "userSpaceOnUse",
1918
+ y2: 0,
1919
+ x2: 1,
1920
+ y1: 0,
1921
+ x1: 0,
1922
+ children: [/* @__PURE__ */jsx("stop", {
1923
+ offset: 0,
1924
+ style: {
1925
+ stopOpacity: 1,
1926
+ stopColor: "#ff4e00"
1927
+ }
1928
+ }), /* @__PURE__ */jsx("stop", {
1929
+ offset: 1,
1930
+ style: {
1931
+ stopOpacity: 1,
1932
+ stopColor: "#ff1791"
1933
+ }
1934
+ })]
1935
+ }), /* @__PURE__ */jsxs("linearGradient", {
1936
+ id: g,
1937
+ spreadMethod: "pad",
1938
+ gradientTransform: "rotate(180 296.075 79.75) scale(524.84045)",
1939
+ gradientUnits: "userSpaceOnUse",
1940
+ y2: 0,
1941
+ x2: 1,
1942
+ y1: 0,
1943
+ x1: 0,
1944
+ children: [/* @__PURE__ */jsx("stop", {
1945
+ offset: 0,
1946
+ style: {
1947
+ stopOpacity: 1,
1948
+ stopColor: "#ff4e00"
1949
+ }
1950
+ }), /* @__PURE__ */jsx("stop", {
1951
+ offset: 1,
1952
+ style: {
1953
+ stopOpacity: 1,
1954
+ stopColor: "#ff1791"
1955
+ }
1956
+ })]
1957
+ }), /* @__PURE__ */jsxs("linearGradient", {
1958
+ id: i,
1959
+ spreadMethod: "pad",
1960
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 159.5)",
1961
+ gradientUnits: "userSpaceOnUse",
1962
+ y2: 0,
1963
+ x2: 1,
1964
+ y1: 0,
1965
+ x1: 0,
1966
+ children: [/* @__PURE__ */jsx("stop", {
1967
+ offset: 0,
1968
+ style: {
1969
+ stopOpacity: 1,
1970
+ stopColor: "#ff4e00"
1971
+ }
1972
+ }), /* @__PURE__ */jsx("stop", {
1973
+ offset: 1,
1974
+ style: {
1975
+ stopOpacity: 1,
1976
+ stopColor: "#ff1791"
1977
+ }
1978
+ })]
1979
+ }), /* @__PURE__ */jsxs("linearGradient", {
1980
+ id: j,
1981
+ spreadMethod: "pad",
1982
+ gradientTransform: "matrix(523.08514 0 0 -523.08514 67.897 224.446)",
1983
+ gradientUnits: "userSpaceOnUse",
1984
+ y2: 0,
1985
+ x2: 1,
1986
+ y1: 0,
1987
+ x1: 0,
1988
+ children: [/* @__PURE__ */jsx("stop", {
1989
+ offset: 0,
1990
+ style: {
1991
+ stopOpacity: 1,
1992
+ stopColor: "#ff4e00"
1993
+ }
1994
+ }), /* @__PURE__ */jsx("stop", {
1995
+ offset: 1,
1996
+ style: {
1997
+ stopOpacity: 1,
1998
+ stopColor: "#ff1791"
1999
+ }
2000
+ })]
2001
+ }), /* @__PURE__ */jsxs("linearGradient", {
2002
+ id: k,
2003
+ spreadMethod: "pad",
2004
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 94.553)",
2005
+ gradientUnits: "userSpaceOnUse",
2006
+ y2: 0,
2007
+ x2: 1,
2008
+ y1: 0,
2009
+ x1: 0,
2010
+ children: [/* @__PURE__ */jsx("stop", {
2011
+ offset: 0,
2012
+ style: {
2013
+ stopOpacity: 1,
2014
+ stopColor: "#ff4e00"
2015
+ }
2016
+ }), /* @__PURE__ */jsx("stop", {
2017
+ offset: 1,
2018
+ style: {
2019
+ stopOpacity: 1,
2020
+ stopColor: "#ff1791"
2021
+ }
2022
+ })]
2023
+ }), /* @__PURE__ */jsxs("linearGradient", {
2024
+ id: l,
2025
+ spreadMethod: "pad",
2026
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 159.5)",
2027
+ gradientUnits: "userSpaceOnUse",
2028
+ y2: 0,
2029
+ x2: 1,
2030
+ y1: 0,
2031
+ x1: 0,
2032
+ children: [/* @__PURE__ */jsx("stop", {
2033
+ offset: 0,
2034
+ style: {
2035
+ stopOpacity: 1,
2036
+ stopColor: "#ff4e00"
2037
+ }
2038
+ }), /* @__PURE__ */jsx("stop", {
2039
+ offset: 1,
2040
+ style: {
2041
+ stopOpacity: 1,
2042
+ stopColor: "#ff1791"
2043
+ }
2044
+ })]
2045
+ }), /* @__PURE__ */jsxs("linearGradient", {
2046
+ id: m,
2047
+ spreadMethod: "pad",
2048
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 94.554)",
2049
+ gradientUnits: "userSpaceOnUse",
2050
+ y2: 0,
2051
+ x2: 1,
2052
+ y1: 0,
2053
+ x1: 0,
2054
+ children: [/* @__PURE__ */jsx("stop", {
2055
+ offset: 0,
2056
+ style: {
2057
+ stopOpacity: 1,
2058
+ stopColor: "#ff4e00"
2059
+ }
2060
+ }), /* @__PURE__ */jsx("stop", {
2061
+ offset: 1,
2062
+ style: {
2063
+ stopOpacity: 1,
2064
+ stopColor: "#ff1791"
2065
+ }
2066
+ })]
2067
+ }), /* @__PURE__ */jsxs("linearGradient", {
2068
+ id: p,
2069
+ spreadMethod: "pad",
2070
+ gradientTransform: "matrix(521.97632 0 0 -521.97632 69.067 191.973)",
2071
+ gradientUnits: "userSpaceOnUse",
2072
+ y2: 0,
2073
+ x2: 1,
2074
+ y1: 0,
2075
+ x1: 0,
2076
+ children: [/* @__PURE__ */jsx("stop", {
2077
+ offset: 0,
2078
+ style: {
2079
+ stopOpacity: 1,
2080
+ stopColor: "#ff4e00"
2081
+ }
2082
+ }), /* @__PURE__ */jsx("stop", {
2083
+ offset: 1,
2084
+ style: {
2085
+ stopOpacity: 1,
2086
+ stopColor: "#ff1791"
2087
+ }
2088
+ })]
2089
+ }), /* @__PURE__ */jsxs("linearGradient", {
2090
+ id: q,
2091
+ spreadMethod: "pad",
2092
+ gradientTransform: "matrix(523.09039 0 0 -523.09039 67.312 191.973)",
2093
+ gradientUnits: "userSpaceOnUse",
2094
+ y2: 0,
2095
+ x2: 1,
2096
+ y1: 0,
2097
+ x1: 0,
2098
+ children: [/* @__PURE__ */jsx("stop", {
2099
+ offset: 0,
2100
+ style: {
2101
+ stopOpacity: 1,
2102
+ stopColor: "#ff4e00"
2103
+ }
2104
+ }), /* @__PURE__ */jsx("stop", {
2105
+ offset: 1,
2106
+ style: {
2107
+ stopOpacity: 1,
2108
+ stopColor: "#ff1791"
2109
+ }
2110
+ })]
2111
+ }), /* @__PURE__ */jsxs("linearGradient", {
2112
+ id: r,
2113
+ spreadMethod: "pad",
2114
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 159.5)",
2115
+ gradientUnits: "userSpaceOnUse",
2116
+ y2: 0,
2117
+ x2: 1,
2118
+ y1: 0,
2119
+ x1: 0,
2120
+ children: [/* @__PURE__ */jsx("stop", {
2121
+ offset: 0,
2122
+ style: {
2123
+ stopOpacity: 1,
2124
+ stopColor: "#ff4e00"
2125
+ }
2126
+ }), /* @__PURE__ */jsx("stop", {
2127
+ offset: 1,
2128
+ style: {
2129
+ stopOpacity: 1,
2130
+ stopColor: "#ff1791"
2131
+ }
2132
+ })]
2133
+ }), /* @__PURE__ */jsx("clipPath", {
2134
+ id: a,
2135
+ clipPathUnits: "userSpaceOnUse",
2136
+ children: /* @__PURE__ */jsx("path", {
2137
+ d: "M0 319h657.706V0H0Z"
2138
+ })
2139
+ }), /* @__PURE__ */jsx("clipPath", {
2140
+ id: b,
2141
+ clipPathUnits: "userSpaceOnUse",
2142
+ children: /* @__PURE__ */jsx("path", {
2143
+ d: "M423.64 242h164.999V77H423.64Z"
2144
+ })
2145
+ }), /* @__PURE__ */jsx("clipPath", {
2146
+ id: e,
2147
+ clipPathUnits: "userSpaceOnUse",
2148
+ children: /* @__PURE__ */jsx("path", {
2149
+ d: "M0 319h657.706V0H0Z"
2150
+ })
2151
+ }), /* @__PURE__ */jsx("clipPath", {
2152
+ id: f,
2153
+ clipPathUnits: "userSpaceOnUse",
2154
+ children: /* @__PURE__ */jsx("path", {
2155
+ d: "M311.3 242h93.031V77H311.3Z"
2156
+ })
2157
+ }), /* @__PURE__ */jsx("clipPath", {
2158
+ id: h,
2159
+ clipPathUnits: "userSpaceOnUse",
2160
+ children: /* @__PURE__ */jsx("path", {
2161
+ d: "M198.96 242h35.106V77H198.96Z"
2162
+ })
2163
+ }), /* @__PURE__ */jsx("clipPath", {
2164
+ id: n,
2165
+ clipPathUnits: "userSpaceOnUse",
2166
+ children: /* @__PURE__ */jsx("path", {
2167
+ d: "M0 319h657.706V0H0Z"
2168
+ })
2169
+ }), /* @__PURE__ */jsx("clipPath", {
2170
+ id: o,
2171
+ clipPathUnits: "userSpaceOnUse",
2172
+ children: /* @__PURE__ */jsx("path", {
2173
+ d: "M69.067 242H169.12V141.947H69.067Z"
2174
+ })
2175
+ })]
2176
+ }), /* @__PURE__ */jsx("g", {
2177
+ clipPath: "url(#".concat(a, ")"),
2178
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)",
2179
+ children: /* @__PURE__ */jsx("g", {
2180
+ style: {
2181
+ opacity: 0.69999701
2182
+ },
2183
+ clipPath: "url(#".concat(b, ")"),
2184
+ children: /* @__PURE__ */jsx("path", {
2185
+ style: {
2186
+ fill: "url(#".concat(c, ")"),
2187
+ stroke: "none"
2188
+ },
2189
+ 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"
2190
+ })
2191
+ })
2192
+ }), /* @__PURE__ */jsx("path", {
2193
+ style: {
2194
+ fill: "url(#".concat(d, ")"),
2195
+ stroke: "none"
2196
+ },
2197
+ d: "M558.674 236.858 428.781 106.966c-6.855-6.855-6.855-17.969 0-24.825 6.855-6.854 17.969-6.854 24.823 0l129.894 129.894c6.854 6.855 6.854 17.968 0 24.823A17.498 17.498 0 0 1 571.086 242a17.495 17.495 0 0 1-12.412-5.142",
2198
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2199
+ }), /* @__PURE__ */jsxs("g", {
2200
+ clipPath: "url(#".concat(e, ")"),
2201
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)",
2202
+ children: [/* @__PURE__ */jsx("g", {
2203
+ style: {
2204
+ opacity: 0.69999701
2205
+ },
2206
+ clipPath: "url(#".concat(f, ")"),
2207
+ children: /* @__PURE__ */jsx("path", {
2208
+ style: {
2209
+ fill: "url(#".concat(g, ")"),
2210
+ stroke: "none"
2211
+ },
2212
+ d: "M328.853 112.107c22.297 0 40.372 18.075 40.372 40.372v71.315c0 10.054 7.505 18.206 17.554 18.206 10.048 0 17.552-8.152 17.552-18.206v-71.315c0-41.686-33.793-75.479-75.478-75.479-9.694 0-17.553 7.859-17.553 17.554 0 9.694 7.859 17.553 17.553 17.553"
2213
+ })
2214
+ }), /* @__PURE__ */jsx("g", {
2215
+ style: {
2216
+ opacity: 0.69999701
2217
+ },
2218
+ clipPath: "url(#".concat(h, ")"),
2219
+ children: /* @__PURE__ */jsx("path", {
2220
+ style: {
2221
+ fill: "url(#".concat(i, ")"),
2222
+ stroke: "none"
2223
+ },
2224
+ d: "M216.513 242c-10.049 0-17.553-8.152-17.553-18.206V95.206c0-10.054 7.504-18.206 17.553-18.206 10.048 0 17.553 8.152 17.553 18.206v128.588c0 10.054-7.505 18.206-17.553 18.206"
2225
+ })
2226
+ })]
2227
+ }), /* @__PURE__ */jsx("path", {
2228
+ style: {
2229
+ fill: "url(#".concat(j, ")"),
2230
+ stroke: "none"
2231
+ },
2232
+ d: "M369.225 224.447c0-9.694 7.859-17.553 17.553-17.553 9.695 0 17.553 7.859 17.553 17.553s-7.858 17.552-17.553 17.552c-9.694 0-17.553-7.858-17.553-17.552",
2233
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2234
+ }), /* @__PURE__ */jsx("path", {
2235
+ style: {
2236
+ fill: "url(#".concat(k, ")"),
2237
+ stroke: "none"
2238
+ },
2239
+ d: "M553.532 94.554c0-9.695 7.859-17.554 17.553-17.554 9.695 0 17.554 7.859 17.554 17.554 0 9.694-7.859 17.552-17.554 17.552-9.694 0-17.553-7.858-17.553-17.552",
2240
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2241
+ }), /* @__PURE__ */jsx("path", {
2242
+ style: {
2243
+ fill: "url(#".concat(l, ")"),
2244
+ stroke: "none"
2245
+ },
2246
+ d: "M69.067 223.794V95.206C69.067 85.152 76.571 77 86.62 77c10.048 0 17.553 8.152 17.553 18.206v128.588c0 10.055-7.505 18.205-17.553 18.205-10.049 0-17.553-8.15-17.553-18.205",
2247
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2248
+ }), /* @__PURE__ */jsx("path", {
2249
+ style: {
2250
+ fill: "url(#".concat(m, ")"),
2251
+ stroke: "none"
2252
+ },
2253
+ d: "M198.96 94.554c0-9.695 7.859-17.554 17.553-17.554 9.695 0 17.554 7.859 17.554 17.554 0 9.694-7.859 17.553-17.554 17.553-9.694 0-17.553-7.859-17.553-17.553",
2254
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2255
+ }), /* @__PURE__ */jsx("g", {
2256
+ clipPath: "url(#".concat(n, ")"),
2257
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)",
2258
+ children: /* @__PURE__ */jsx("g", {
2259
+ style: {
2260
+ opacity: 0.69999701
2261
+ },
2262
+ clipPath: "url(#".concat(o, ")"),
2263
+ children: /* @__PURE__ */jsx("path", {
2264
+ style: {
2265
+ fill: "url(#".concat(p, ")"),
2266
+ stroke: "none"
2267
+ },
2268
+ d: "M139.155 147.088c6.855-6.855 17.969-6.855 24.824 0s6.855 17.969 0 24.824l-64.947 64.946c-6.855 6.855-17.969 6.855-24.824 0s-6.855-17.969 0-24.823z"
2269
+ })
2270
+ })
2271
+ }), /* @__PURE__ */jsx("path", {
2272
+ style: {
2273
+ fill: "url(#".concat(q, ")"),
2274
+ stroke: "none"
2275
+ },
2276
+ d: "m204.101 236.858-64.947-64.946c-6.854-6.855-6.854-17.969 0-24.824 6.856-6.855 17.97-6.855 24.824 0l64.947 64.947c6.855 6.855 6.855 17.968 0 24.823A17.495 17.495 0 0 1 216.513 242a17.498 17.498 0 0 1-12.412-5.142",
2277
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2278
+ }), /* @__PURE__ */jsx("path", {
2279
+ style: {
2280
+ fill: "url(#".concat(r, ")"),
2281
+ stroke: "none"
2282
+ },
2283
+ d: "M253.374 223.794v-71.315c0-41.685 33.793-75.479 75.479-75.479 9.695 0 17.553 7.859 17.553 17.554 0 9.694-7.858 17.553-17.553 17.553-22.297 0-40.372 18.075-40.372 40.372v71.315c0 10.055-7.505 18.205-17.554 18.205s-17.553-8.15-17.553-18.205",
2284
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2285
+ })]
2286
+ });
2287
+ }
2288
+ const Logo = styled.span(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n display: inline-block;\n height: 0.8em;\n margin-right: 1em;\n transform: translate(0.3em, -0.2em);\n"])));
2289
+ const Header = () => /* @__PURE__ */jsxs(Fragment, {
2290
+ children: [/* @__PURE__ */jsx(Logo, {
2291
+ children: /* @__PURE__ */jsx(MuxLogo, {
2292
+ height: 13
2293
+ })
2294
+ }), "API Credentials"]
2295
+ });
2296
+ function FormField(props) {
2297
+ const {
2298
+ children,
2299
+ title,
2300
+ description,
2301
+ inputId
2302
+ } = props;
2303
+ return /* @__PURE__ */jsxs(Stack, {
2304
+ space: 1,
2305
+ children: [/* @__PURE__ */jsx(Flex, {
2306
+ align: "flex-end",
2307
+ children: /* @__PURE__ */jsx(Box, {
2308
+ flex: 1,
2309
+ paddingY: 2,
2310
+ children: /* @__PURE__ */jsx(Stack, {
2311
+ space: 2,
2312
+ children: /* @__PURE__ */jsxs(Flex, {
2313
+ children: [/* @__PURE__ */jsx(Text, {
2314
+ as: "label",
2315
+ htmlFor: inputId,
2316
+ weight: "semibold",
2317
+ size: 1,
2318
+ children: title || /* @__PURE__ */jsx("em", {
2319
+ children: "Untitled"
2320
+ })
2321
+ }), description && /* @__PURE__ */jsx(Text, {
2322
+ muted: true,
2323
+ size: 1,
2324
+ children: description
2325
+ })]
2326
+ })
2327
+ })
2328
+ })
2329
+ }), /* @__PURE__ */jsx("div", {
2330
+ children
2331
+ })]
2332
+ });
2333
+ }
2334
+ var FormField$1 = memo(FormField);
2335
+ const fieldNames = ["token", "secretKey", "enableSignedUrls"];
2336
+ function ConfigureApi(_ref18) {
2337
+ let {
2338
+ secrets,
2339
+ setDialogState
2340
+ } = _ref18;
2341
+ var _a, _b;
2342
+ const client = useClient();
2343
+ const [state, dispatch] = useSecretsFormState(secrets);
2344
+ const hasSecretsInitially = useMemo(() => secrets.token && secrets.secretKey, [secrets]);
2345
+ const handleClose = useCallback(() => setDialogState(false), [setDialogState]);
2346
+ const dirty = useMemo(() => secrets.token !== state.token || secrets.secretKey !== state.secretKey || secrets.enableSignedUrls !== state.enableSignedUrls, [secrets, state]);
2347
+ const id = "ConfigureApi".concat(useId());
2348
+ const [tokenId, secretKeyId, enableSignedUrlsId] = useMemo(() => fieldNames.map(field => "".concat(id, "-").concat(field)), [id]);
2349
+ const firstField = useRef(null);
2350
+ const handleSaveSecrets = useSaveSecrets(client, secrets);
2351
+ const saving = useRef(false);
2352
+ const handleSubmit = useCallback(event => {
2353
+ event.preventDefault();
2354
+ if (!saving.current && event.currentTarget.reportValidity()) {
2355
+ saving.current = true;
2356
+ dispatch({
2357
+ type: "submit"
2358
+ });
2359
+ const {
2360
+ token,
2361
+ secretKey,
2362
+ enableSignedUrls
2363
+ } = state;
2364
+ handleSaveSecrets({
2365
+ token,
2366
+ secretKey,
2367
+ enableSignedUrls
2368
+ }).then(savedSecrets => {
2369
+ const {
2370
+ projectId,
2371
+ dataset
2372
+ } = client.config();
2373
+ clear([cacheNs, _id, projectId, dataset]);
2374
+ preload(() => Promise.resolve(savedSecrets), [cacheNs, _id, projectId, dataset]);
2375
+ setDialogState(false);
2376
+ }).catch(err => dispatch({
2377
+ type: "error",
2378
+ payload: err.message
2379
+ })).finally(() => {
2380
+ saving.current = false;
2381
+ });
2382
+ }
2383
+ }, [client, dispatch, handleSaveSecrets, setDialogState, state]);
2384
+ const handleChangeToken = useCallback(event => {
2385
+ dispatch({
2386
+ type: "change",
2387
+ payload: {
2388
+ name: "token",
2389
+ value: event.currentTarget.value
2390
+ }
2391
+ });
2392
+ }, [dispatch]);
2393
+ const handleChangeSecretKey = useCallback(event => {
2394
+ dispatch({
2395
+ type: "change",
2396
+ payload: {
2397
+ name: "secretKey",
2398
+ value: event.currentTarget.value
2399
+ }
2400
+ });
2401
+ }, [dispatch]);
2402
+ const handleChangeEnableSignedUrls = useCallback(event => {
2403
+ dispatch({
2404
+ type: "change",
2405
+ payload: {
2406
+ name: "enableSignedUrls",
2407
+ value: event.currentTarget.checked
2408
+ }
2409
+ });
2410
+ }, [dispatch]);
2411
+ useEffect(() => {
2412
+ if (firstField.current) {
2413
+ firstField.current.focus();
2414
+ }
2415
+ }, [firstField]);
2416
+ return /* @__PURE__ */jsx(Dialog, {
2417
+ id,
2418
+ onClose: handleClose,
2419
+ header: /* @__PURE__ */jsx(Header, {}),
2420
+ width: 0,
2421
+ children: /* @__PURE__ */jsx(Box, {
2422
+ padding: 4,
2423
+ style: {
2424
+ position: "relative"
2425
+ },
2426
+ children: /* @__PURE__ */jsx("form", {
2427
+ onSubmit: handleSubmit,
2428
+ noValidate: true,
2429
+ children: /* @__PURE__ */jsxs(Stack, {
2430
+ space: 4,
2431
+ children: [!hasSecretsInitially && /* @__PURE__ */jsx(Card, {
2432
+ padding: [3, 3, 3],
2433
+ radius: 2,
2434
+ shadow: 1,
2435
+ tone: "primary",
2436
+ children: /* @__PURE__ */jsxs(Stack, {
2437
+ space: 3,
2438
+ children: [/* @__PURE__ */jsxs(Text, {
2439
+ size: 1,
2440
+ children: ["To set up a new access token, go to your", " ", /* @__PURE__ */jsx("a", {
2441
+ href: "https://dashboard.mux.com/settings/access-tokens",
2442
+ target: "_blank",
2443
+ rel: "noreferrer noopener",
2444
+ children: "account on mux.com"
2445
+ }), "."]
2446
+ }), /* @__PURE__ */jsxs(Text, {
2447
+ size: 1,
2448
+ children: ["The access token needs permissions: ", /* @__PURE__ */jsx("strong", {
2449
+ children: "Mux Video "
2450
+ }), "(Full Access) and ", /* @__PURE__ */jsx("strong", {
2451
+ children: "Mux Data"
2452
+ }), " (Read)", /* @__PURE__ */jsx("br", {}), "The credentials will be stored safely in a hidden document only available to editors."]
2453
+ })]
2454
+ })
2455
+ }), /* @__PURE__ */jsx(FormField$1, {
2456
+ title: "Access Token",
2457
+ inputId: tokenId,
2458
+ children: /* @__PURE__ */jsx(TextInput, {
2459
+ id: tokenId,
2460
+ ref: firstField,
2461
+ onChange: handleChangeToken,
2462
+ type: "text",
2463
+ value: (_a = state.token) != null ? _a : "",
2464
+ required: !!state.secretKey || state.enableSignedUrls
2465
+ })
2466
+ }), /* @__PURE__ */jsx(FormField$1, {
2467
+ title: "Secret Key",
2468
+ inputId: secretKeyId,
2469
+ children: /* @__PURE__ */jsx(TextInput, {
2470
+ id: secretKeyId,
2471
+ onChange: handleChangeSecretKey,
2472
+ type: "text",
2473
+ value: (_b = state.secretKey) != null ? _b : "",
2474
+ required: !!state.token || state.enableSignedUrls
2475
+ })
2476
+ }), /* @__PURE__ */jsxs(Stack, {
2477
+ space: 4,
2478
+ children: [/* @__PURE__ */jsxs(Flex, {
2479
+ align: "center",
2480
+ children: [/* @__PURE__ */jsx(Checkbox, {
2481
+ id: enableSignedUrlsId,
2482
+ onChange: handleChangeEnableSignedUrls,
2483
+ checked: state.enableSignedUrls,
2484
+ style: {
2485
+ display: "block"
2486
+ }
2487
+ }), /* @__PURE__ */jsx(Box, {
2488
+ flex: 1,
2489
+ paddingLeft: 3,
2490
+ children: /* @__PURE__ */jsx(Text, {
2491
+ children: /* @__PURE__ */jsx("label", {
2492
+ htmlFor: enableSignedUrlsId,
2493
+ children: "Enable Signed Urls"
2494
+ })
2495
+ })
2496
+ })]
2497
+ }), secrets.signingKeyId && state.enableSignedUrls ? /* @__PURE__ */jsx(Card, {
2498
+ padding: [3, 3, 3],
2499
+ radius: 2,
2500
+ shadow: 1,
2501
+ tone: "caution",
2502
+ children: /* @__PURE__ */jsxs(Stack, {
2503
+ space: 3,
2504
+ children: [/* @__PURE__ */jsx(Text, {
2505
+ size: 1,
2506
+ children: "The signing key ID that Sanity will use is:"
2507
+ }), /* @__PURE__ */jsx(Code, {
2508
+ size: 1,
2509
+ children: secrets.signingKeyId
2510
+ }), /* @__PURE__ */jsxs(Text, {
2511
+ size: 1,
2512
+ children: ["This key is only used for previewing content in the Sanity UI.", /* @__PURE__ */jsx("br", {}), "You should generate a different key to use in your application server."]
2513
+ })]
2514
+ })
2515
+ }) : null]
2516
+ }), /* @__PURE__ */jsxs(Inline, {
2517
+ space: 2,
2518
+ children: [/* @__PURE__ */jsx(Button, {
2519
+ text: "Save",
2520
+ disabled: !dirty,
2521
+ loading: state.submitting,
2522
+ tone: "primary",
2523
+ mode: "default",
2524
+ type: "submit"
2525
+ }), /* @__PURE__ */jsx(Button, {
2526
+ disabled: state.submitting,
2527
+ text: "Cancel",
2528
+ mode: "bleed",
2529
+ onClick: handleClose
2530
+ })]
2531
+ }), state.error && /* @__PURE__ */jsx(Card, {
2532
+ padding: [3, 3, 3],
2533
+ radius: 2,
2534
+ shadow: 1,
2535
+ tone: "critical",
2536
+ children: /* @__PURE__ */jsx(Text, {
2537
+ children: state.error
2538
+ })
2539
+ })]
2540
+ })
2541
+ })
2542
+ })
2543
+ });
2544
+ }
2545
+ var ConfigureApi$1 = memo(ConfigureApi);
2546
+ function Onboard(props) {
2547
+ const {
2548
+ setDialogState
2549
+ } = props;
2550
+ const handleOpen = useCallback(() => setDialogState("secrets"), [setDialogState]);
2551
+ return /* @__PURE__ */jsx(Fragment, {
2552
+ children: /* @__PURE__ */jsx("div", {
2553
+ style: {
2554
+ padding: 2
2555
+ },
2556
+ children: /* @__PURE__ */jsx(Card, {
2557
+ display: "flex",
2558
+ sizing: "border",
2559
+ style: {
2560
+ aspectRatio: "16/9",
2561
+ width: "100%",
2562
+ boxShadow: "var(--card-bg-color) 0 0 0 2px"
2563
+ },
2564
+ paddingX: [2, 3, 4, 4],
2565
+ radius: 1,
2566
+ tone: "transparent",
2567
+ children: /* @__PURE__ */jsx(Flex, {
2568
+ justify: "flex-start",
2569
+ align: "center",
2570
+ children: /* @__PURE__ */jsxs(Grid, {
2571
+ columns: 1,
2572
+ gap: [2, 3, 4, 4],
2573
+ children: [/* @__PURE__ */jsx(Inline, {
2574
+ paddingY: 1,
2575
+ children: /* @__PURE__ */jsx("div", {
2576
+ style: {
2577
+ height: "32px"
2578
+ },
2579
+ children: /* @__PURE__ */jsx(MuxLogo, {})
2580
+ })
2581
+ }), /* @__PURE__ */jsx(Inline, {
2582
+ paddingY: 1,
2583
+ children: /* @__PURE__ */jsx(Heading, {
2584
+ size: [0, 1, 2, 2],
2585
+ children: "Upload and preview videos directly from your studio."
2586
+ })
2587
+ }), /* @__PURE__ */jsx(Inline, {
2588
+ paddingY: 1,
2589
+ children: /* @__PURE__ */jsx(Button, {
2590
+ mode: "ghost",
2591
+ icon: PlugIcon,
2592
+ text: "Configure API",
2593
+ onClick: handleOpen
2594
+ })
2595
+ })]
2596
+ })
2597
+ })
2598
+ })
2599
+ })
2600
+ });
2601
+ }
2602
+ const Input = props => {
2603
+ var _a;
2604
+ const client = useClient();
2605
+ const secretDocumentValues = useSecretsDocumentValues();
2606
+ const assetDocumentValues = useAssetDocumentValues((_a = props.value) == null ? void 0 : _a.asset);
2607
+ const poll = useMuxPolling(props.readOnly ? void 0 : (assetDocumentValues == null ? void 0 : assetDocumentValues.value) || void 0);
2608
+ const [dialogState, setDialogState] = useDialogState();
2609
+ const error = secretDocumentValues.error || assetDocumentValues.error || poll.error;
2610
+ if (error) {
2611
+ throw error;
2612
+ }
2613
+ const isLoading = secretDocumentValues.isLoading || assetDocumentValues.isLoading;
2614
+ return /* @__PURE__ */jsx(Fragment, {
2615
+ children: isLoading ? /* @__PURE__ */jsx(InputFallback, {}) : /* @__PURE__ */jsxs(Fragment, {
2616
+ children: [secretDocumentValues.value.needsSetup && !assetDocumentValues.value ? /* @__PURE__ */jsx(Onboard, {
2617
+ setDialogState
2618
+ }) : /* @__PURE__ */jsx(MuxVideoInputUploader, _objectSpread(_objectSpread({}, props), {}, {
2619
+ config: props.config,
2620
+ onChange: props.onChange,
2621
+ client,
2622
+ secrets: secretDocumentValues.value.secrets,
2623
+ asset: assetDocumentValues.value,
2624
+ dialogState,
2625
+ setDialogState,
2626
+ needsSetup: secretDocumentValues.value.needsSetup
2627
+ })), dialogState === "secrets" && /* @__PURE__ */jsx(ConfigureApi$1, {
2628
+ setDialogState,
2629
+ secrets: secretDocumentValues.value.secrets
2630
+ })]
2631
+ })
2632
+ });
2633
+ };
2634
+ var Input$1 = memo(Input);
2635
+ export { Input$1 as default };
2636
+ //# sourceMappingURL=Input-aa6d929b.js.map