sanity-plugin-mux-input 2.0.2 → 2.0.4

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