sanity-plugin-mux-input 2.0.6-debug.1 → 2.0.6-debug.3

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