sanity-plugin-mux-input 2.0.16 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/lib/_chunks/Player-d8f163ed.cjs +474 -0
  2. package/lib/_chunks/Player-d8f163ed.cjs.map +1 -0
  3. package/lib/_chunks/Player-fb9712c0.js +465 -0
  4. package/lib/_chunks/Player-fb9712c0.js.map +1 -0
  5. package/lib/_chunks/index-0656ede8.js +3229 -0
  6. package/lib/_chunks/index-0656ede8.js.map +1 -0
  7. package/lib/_chunks/index-9cd542f1.cjs +3271 -0
  8. package/lib/_chunks/index-9cd542f1.cjs.map +1 -0
  9. package/lib/index.cjs +1 -1
  10. package/lib/index.d.ts +97 -0
  11. package/lib/index.js +1 -1
  12. package/package.json +16 -17
  13. package/src/components/Input.tsx +34 -29
  14. package/src/components/__legacy__Uploader.tsx +7 -2
  15. package/src/index.ts +8 -49
  16. package/src/plugin.tsx +31 -0
  17. package/src/schema.tsx +42 -0
  18. package/lib/_chunks/Input-509c8fa5.cjs +0 -189
  19. package/lib/_chunks/Input-509c8fa5.cjs.map +0 -1
  20. package/lib/_chunks/Input-9ddeac65.js +0 -189
  21. package/lib/_chunks/Input-9ddeac65.js.map +0 -1
  22. package/lib/_chunks/Preview-04fe7cde.js +0 -26
  23. package/lib/_chunks/Preview-04fe7cde.js.map +0 -1
  24. package/lib/_chunks/Preview-442a88cd.cjs +0 -28
  25. package/lib/_chunks/Preview-442a88cd.cjs.map +0 -1
  26. package/lib/_chunks/VideoSource.styled-45ab4b64.js +0 -318
  27. package/lib/_chunks/VideoSource.styled-45ab4b64.js.map +0 -1
  28. package/lib/_chunks/VideoSource.styled-cb41adac.cjs +0 -336
  29. package/lib/_chunks/VideoSource.styled-cb41adac.cjs.map +0 -1
  30. package/lib/_chunks/index-d360f7ae.cjs +0 -265
  31. package/lib/_chunks/index-d360f7ae.cjs.map +0 -1
  32. package/lib/_chunks/index-f8b48f62.js +0 -248
  33. package/lib/_chunks/index-f8b48f62.js.map +0 -1
  34. package/src/components/FormInput.tsx +0 -26
  35. package/src/components/FormPreview.tsx +0 -19
  36. package/src/components/Preview.tsx +0 -33
@@ -0,0 +1,3229 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19, _templateObject20, _templateObject21, _templateObject22;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { useDocumentValues, isReference, useClient as useClient$1, useProjectId, useDataset, MediaPreview, PatchEvent, setIfMissing, set, unset, LinearProgress, definePlugin } from 'sanity';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+ import React, { useState, useMemo, memo, Suspense, useRef, useLayoutEffect, useId, useCallback, useEffect, isValidElement, createElement, forwardRef, lazy, Component, useReducer } from 'react';
6
+ import useSWR from 'swr';
7
+ import { Observable, defer, concat, of, throwError, from, Subject } from 'rxjs';
8
+ import { switchMap, mergeMap, catchError, mergeMapTo, takeUntil, tap } from 'rxjs/operators';
9
+ import { uuid } from '@sanity/uuid';
10
+ import * as UpChunk from '@mux/upchunk';
11
+ import { Card, Box, Spinner, Grid, Inline, useClickOutside, MenuButton, Button, Menu, MenuItem, useToast, Dialog, Stack, Flex, Checkbox, Text, Tooltip, Popover, Label as Label$1, MenuDivider, rem, Code, TextInput, Heading } from '@sanity/ui';
12
+ import { UnknownIcon, LockIcon, EllipsisVerticalIcon, TrashIcon, DownloadIcon, EditIcon, UploadIcon, SearchIcon, PlugIcon, ResetIcon, DocumentVideoIcon } from '@sanity/icons';
13
+ import { animate } from 'motion';
14
+ import styled, { css } from 'styled-components';
15
+ import { getDevicePixelRatio } from 'use-device-pixel-ratio';
16
+ import { suspend, clear, preload } from 'suspend-react';
17
+ import { useErrorBoundary } from 'use-error-boundary';
18
+ import scrollIntoView from 'scroll-into-view-if-needed';
19
+ const path$1 = ["assetId", "data", "playbackId", "status", "thumbTime", "filename"];
20
+ const useAssetDocumentValues = asset => useDocumentValues(isReference(asset) ? asset._ref : "", path$1);
21
+ function useClient() {
22
+ return useClient$1({
23
+ apiVersion: "2022-09-14"
24
+ });
25
+ }
26
+ function useDialogState() {
27
+ return useState(false);
28
+ }
29
+ const useMuxPolling = asset => {
30
+ var _a, _b;
31
+ const client = useClient();
32
+ const projectId = useProjectId();
33
+ const dataset = useDataset();
34
+ const shouldFetch = useMemo(() => {
35
+ var _a2, _b2;
36
+ 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");
37
+ }, [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]);
38
+ return useSWR(shouldFetch ? "/".concat(projectId, "/addons/mux/assets/").concat(dataset, "/data/").concat(asset == null ? void 0 : asset.assetId) : null, async () => {
39
+ const {
40
+ data
41
+ } = await client.request({
42
+ url: "/addons/mux/assets/".concat(dataset, "/data/").concat(asset.assetId),
43
+ withCredentials: true,
44
+ method: "GET"
45
+ });
46
+ client.patch(asset._id).set({
47
+ status: data.status,
48
+ data
49
+ }).commit({
50
+ returnDocuments: false
51
+ });
52
+ }, {
53
+ refreshInterval: 2e3,
54
+ refreshWhenHidden: true,
55
+ dedupingInterval: 1e3
56
+ });
57
+ };
58
+ const name = "mux-input";
59
+ const cacheNs = "sanity-plugin-mux-input";
60
+ const muxSecretsDocumentId = "secrets.mux";
61
+ const path = ["token", "secretKey", "enableSignedUrls", "signingKeyId", "signingKeyPrivate"];
62
+ const useSecretsDocumentValues = () => {
63
+ const {
64
+ error,
65
+ isLoading,
66
+ value
67
+ } = useDocumentValues(muxSecretsDocumentId, path);
68
+ const cache = useMemo(() => {
69
+ const exists = Boolean(value);
70
+ const secrets = {
71
+ token: (value == null ? void 0 : value.token) || null,
72
+ secretKey: (value == null ? void 0 : value.secretKey) || null,
73
+ enableSignedUrls: (value == null ? void 0 : value.enableSignedUrls) || false,
74
+ signingKeyId: (value == null ? void 0 : value.signingKeyId) || null,
75
+ signingKeyPrivate: (value == null ? void 0 : value.signingKeyPrivate) || null
76
+ };
77
+ return {
78
+ isInitialSetup: !exists,
79
+ needsSetup: !(secrets == null ? void 0 : secrets.token) || !(secrets == null ? void 0 : secrets.secretKey),
80
+ secrets
81
+ };
82
+ }, [value]);
83
+ return {
84
+ error,
85
+ isLoading,
86
+ value: cache
87
+ };
88
+ };
89
+ function createUpChunkObservable(uuid, uploadUrl, source) {
90
+ return new Observable(subscriber => {
91
+ const upchunk = UpChunk.createUpload({
92
+ endpoint: uploadUrl,
93
+ file: source,
94
+ dynamicChunkSize: true
95
+ // changes the chunk size based on network speeds
96
+ });
97
+
98
+ const successHandler = () => {
99
+ subscriber.next({
100
+ type: "success",
101
+ id: uuid
102
+ });
103
+ subscriber.complete();
104
+ };
105
+ const errorHandler = data => subscriber.error(new Error(data.detail.message));
106
+ const progressHandler = data => {
107
+ return subscriber.next({
108
+ type: "progress",
109
+ percent: data.detail
110
+ });
111
+ };
112
+ const offlineHandler = () => {
113
+ upchunk.pause();
114
+ subscriber.next({
115
+ type: "pause",
116
+ id: uuid
117
+ });
118
+ };
119
+ const onlineHandler = () => {
120
+ upchunk.resume();
121
+ subscriber.next({
122
+ type: "resume",
123
+ id: uuid
124
+ });
125
+ };
126
+ upchunk.on("success", successHandler);
127
+ upchunk.on("error", errorHandler);
128
+ upchunk.on("progress", progressHandler);
129
+ upchunk.on("offline", offlineHandler);
130
+ upchunk.on("online", onlineHandler);
131
+ return () => upchunk.abort();
132
+ });
133
+ }
134
+ function deleteAsset(client, assetId) {
135
+ const {
136
+ dataset
137
+ } = client.config();
138
+ return client.request({
139
+ url: "/addons/mux/assets/".concat(dataset, "/").concat(assetId),
140
+ withCredentials: true,
141
+ method: "DELETE"
142
+ });
143
+ }
144
+ function getAsset(client, assetId) {
145
+ const {
146
+ dataset
147
+ } = client.config();
148
+ return client.request({
149
+ url: "/addons/mux/assets/".concat(dataset, "/data/").concat(assetId),
150
+ withCredentials: true,
151
+ method: "GET"
152
+ });
153
+ }
154
+ function saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate) {
155
+ const doc = {
156
+ _id: "secrets.mux",
157
+ _type: "mux.apiKey",
158
+ token,
159
+ secretKey,
160
+ enableSignedUrls,
161
+ signingKeyId,
162
+ signingKeyPrivate
163
+ };
164
+ return client.createOrReplace(doc);
165
+ }
166
+ function createSigningKeys(client) {
167
+ const {
168
+ dataset
169
+ } = client.config();
170
+ return client.request({
171
+ url: "/addons/mux/signing-keys/".concat(dataset),
172
+ withCredentials: true,
173
+ method: "POST"
174
+ });
175
+ }
176
+ function testSecrets(client) {
177
+ const {
178
+ dataset
179
+ } = client.config();
180
+ return client.request({
181
+ url: "/addons/mux/secrets/".concat(dataset, "/test"),
182
+ withCredentials: true,
183
+ method: "GET"
184
+ });
185
+ }
186
+ async function haveValidSigningKeys(client, signingKeyId, signingKeyPrivate) {
187
+ if (!(signingKeyId && signingKeyPrivate)) {
188
+ return false;
189
+ }
190
+ const {
191
+ dataset
192
+ } = client.config();
193
+ try {
194
+ const res = await client.request({
195
+ url: "/addons/mux/signing-keys/".concat(dataset, "/").concat(signingKeyId),
196
+ withCredentials: true,
197
+ method: "GET"
198
+ });
199
+ return !!(res.data && res.data.id);
200
+ } catch (e) {
201
+ console.error("Error fetching signingKeyId", signingKeyId, "assuming it is not valid");
202
+ return false;
203
+ }
204
+ }
205
+ function testSecretsObservable(client) {
206
+ const {
207
+ dataset
208
+ } = client.config();
209
+ return defer(() => client.observable.request({
210
+ url: "/addons/mux/secrets/".concat(dataset, "/test"),
211
+ withCredentials: true,
212
+ method: "GET"
213
+ }));
214
+ }
215
+ function cancelUpload(client, uuid) {
216
+ return client.observable.request({
217
+ url: "/addons/mux/uploads/".concat(client.config().dataset, "/").concat(uuid),
218
+ withCredentials: true,
219
+ method: "DELETE"
220
+ });
221
+ }
222
+ function uploadUrl(config, client, url) {
223
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
224
+ return testUrl(url).pipe(switchMap(validUrl => {
225
+ return concat(of({
226
+ type: "url",
227
+ url: validUrl
228
+ }), testSecretsObservable(client).pipe(switchMap(json => {
229
+ if (!json || !json.status) {
230
+ return throwError(new Error("Invalid credentials"));
231
+ }
232
+ const uuid$1 = uuid();
233
+ const {
234
+ enableSignedUrls
235
+ } = options;
236
+ const muxBody = {
237
+ input: validUrl,
238
+ playback_policy: [enableSignedUrls ? "signed" : "public"],
239
+ mp4_support: config.mp4_support
240
+ };
241
+ const query = {
242
+ muxBody: JSON.stringify(muxBody),
243
+ filename: validUrl.split("/").slice(-1)[0]
244
+ };
245
+ const dataset = client.config().dataset;
246
+ return defer(() => client.observable.request({
247
+ url: "/addons/mux/assets/".concat(dataset),
248
+ withCredentials: true,
249
+ method: "POST",
250
+ headers: {
251
+ "MUX-Proxy-UUID": uuid$1,
252
+ "Content-Type": "application/json"
253
+ },
254
+ query
255
+ })).pipe(mergeMap(result => {
256
+ const asset = result && result.results && result.results[0] && result.results[0].document || null;
257
+ if (!asset) {
258
+ return throwError(new Error("No asset document returned"));
259
+ }
260
+ return of({
261
+ type: "success",
262
+ id: uuid$1,
263
+ asset
264
+ });
265
+ }));
266
+ })));
267
+ }));
268
+ }
269
+ function uploadFile(config, client, file) {
270
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
271
+ return testFile(file).pipe(switchMap(fileOptions => {
272
+ return concat(of({
273
+ type: "file",
274
+ file: fileOptions
275
+ }), testSecretsObservable(client).pipe(switchMap(json => {
276
+ if (!json || !json.status) {
277
+ return throwError(new Error("Invalid credentials"));
278
+ }
279
+ const uuid$1 = uuid();
280
+ const {
281
+ enableSignedUrls
282
+ } = options;
283
+ const body = {
284
+ mp4_support: config.mp4_support,
285
+ playback_policy: [enableSignedUrls ? "signed" : "public"]
286
+ };
287
+ return concat(of({
288
+ type: "uuid",
289
+ uuid: uuid$1
290
+ }), defer(() => client.observable.request({
291
+ url: "/addons/mux/uploads/".concat(client.config().dataset),
292
+ withCredentials: true,
293
+ method: "POST",
294
+ headers: {
295
+ "MUX-Proxy-UUID": uuid$1,
296
+ "Content-Type": "application/json"
297
+ },
298
+ body
299
+ })).pipe(mergeMap(result => {
300
+ return createUpChunkObservable(uuid$1, result.upload.url, file).pipe(
301
+ // eslint-disable-next-line no-warning-comments
302
+ // @TODO type the observable events
303
+ // eslint-disable-next-line max-nested-callbacks
304
+ mergeMap(event => {
305
+ if (event.type !== "success") {
306
+ return of(event);
307
+ }
308
+ return from(updateAssetDocumentFromUpload(client, uuid$1)).pipe(
309
+ // eslint-disable-next-line max-nested-callbacks
310
+ mergeMap(doc => of({
311
+ ...event,
312
+ asset: doc
313
+ })));
314
+ }),
315
+ // eslint-disable-next-line max-nested-callbacks
316
+ catchError(err => {
317
+ return cancelUpload(client, uuid$1).pipe(mergeMapTo(throwError(err)));
318
+ }));
319
+ })));
320
+ })));
321
+ }));
322
+ }
323
+ function getUpload(client, assetId) {
324
+ const {
325
+ dataset
326
+ } = client.config();
327
+ return client.request({
328
+ url: "/addons/mux/uploads/".concat(dataset, "/").concat(assetId),
329
+ withCredentials: true,
330
+ method: "GET"
331
+ });
332
+ }
333
+ function pollUpload(client, uuid) {
334
+ const maxTries = 10;
335
+ let pollInterval;
336
+ let tries = 0;
337
+ let assetId;
338
+ let upload;
339
+ return new Promise((resolve, reject) => {
340
+ pollInterval = setInterval(async () => {
341
+ try {
342
+ upload = await getUpload(client, uuid);
343
+ } catch (err) {
344
+ reject(err);
345
+ return;
346
+ }
347
+ assetId = upload && upload.data && upload.data.asset_id;
348
+ if (assetId) {
349
+ clearInterval(pollInterval);
350
+ resolve(upload);
351
+ }
352
+ if (tries > maxTries) {
353
+ clearInterval(pollInterval);
354
+ reject(new Error("Upload did not finish"));
355
+ }
356
+ tries++;
357
+ }, 2e3);
358
+ });
359
+ }
360
+ async function updateAssetDocumentFromUpload(client, uuid) {
361
+ let upload;
362
+ let asset;
363
+ try {
364
+ upload = await pollUpload(client, uuid);
365
+ } catch (err) {
366
+ return Promise.reject(err);
367
+ }
368
+ try {
369
+ asset = await getAsset(client, upload.data.asset_id);
370
+ } catch (err) {
371
+ return Promise.reject(err);
372
+ }
373
+ const doc = {
374
+ _id: uuid,
375
+ _type: "mux.videoAsset",
376
+ status: asset.data.status,
377
+ data: asset.data,
378
+ assetId: asset.data.id,
379
+ playbackId: asset.data.playback_ids[0].id,
380
+ uploadId: upload.data.id
381
+ };
382
+ return client.createOrReplace(doc).then(() => {
383
+ return doc;
384
+ });
385
+ }
386
+ function testFile(file) {
387
+ if (typeof window !== "undefined" && file instanceof window.File) {
388
+ const fileOptions = optionsFromFile({}, file);
389
+ return of(fileOptions);
390
+ }
391
+ return throwError(new Error("Invalid file"));
392
+ }
393
+ function testUrl(url) {
394
+ const error = new Error("Invalid URL");
395
+ if (typeof url !== "string") {
396
+ return throwError(error);
397
+ }
398
+ let parsed;
399
+ try {
400
+ parsed = new URL(url);
401
+ } catch (err) {
402
+ return throwError(error);
403
+ }
404
+ if (parsed && !parsed.protocol.match(/http:|https:/)) {
405
+ return throwError(error);
406
+ }
407
+ return of(url);
408
+ }
409
+ function optionsFromFile(opts, file) {
410
+ if (typeof window === "undefined" || !(file instanceof window.File)) {
411
+ return opts;
412
+ }
413
+ return {
414
+ name: opts.preserveFilename === false ? void 0 : file.name,
415
+ type: file.type
416
+ };
417
+ }
418
+ function extractDroppedFiles(dataTransfer) {
419
+ const files = Array.from(dataTransfer.files || []);
420
+ const items = Array.from(dataTransfer.items || []);
421
+ if (files && files.length > 0) {
422
+ return Promise.resolve(files);
423
+ }
424
+ return normalizeItems(items).then(arr => arr.flat());
425
+ }
426
+ function normalizeItems(items) {
427
+ return Promise.all(items.map(item => {
428
+ if (item.kind === "file" && item.webkitGetAsEntry) {
429
+ let entry;
430
+ try {
431
+ entry = item.webkitGetAsEntry();
432
+ } catch (err) {
433
+ return [item.getAsFile()];
434
+ }
435
+ if (!entry) {
436
+ return [];
437
+ }
438
+ return entry.isDirectory ? walk(entry) : [item.getAsFile()];
439
+ }
440
+ if (item.kind === "file") {
441
+ const file = item.getAsFile();
442
+ return Promise.resolve(file ? [file] : []);
443
+ }
444
+ return new Promise(resolve => item.getAsString(resolve)).then(str => str ? [new File([str], "unknown.txt", {
445
+ type: item.type
446
+ })] : []);
447
+ }));
448
+ }
449
+ function isFile(entry) {
450
+ return entry.isFile;
451
+ }
452
+ function isDirectory(entry) {
453
+ return entry.isDirectory;
454
+ }
455
+ function walk(entry) {
456
+ if (isFile(entry)) {
457
+ return new Promise(resolve => entry.file(resolve)).then(file => [file]);
458
+ }
459
+ if (isDirectory(entry)) {
460
+ const dir = entry.createReader();
461
+ 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()));
462
+ }
463
+ return Promise.resolve([]);
464
+ }
465
+ const _id = "secrets.mux";
466
+ function readSecrets(client) {
467
+ const {
468
+ projectId,
469
+ dataset
470
+ } = client.config();
471
+ return suspend(async () => {
472
+ const data = await client.fetch( /* groq */"*[_id == $_id][0]{\n token,\n secretKey,\n enableSignedUrls,\n signingKeyId,\n signingKeyPrivate\n }", {
473
+ _id
474
+ });
475
+ return {
476
+ token: (data == null ? void 0 : data.token) || null,
477
+ secretKey: (data == null ? void 0 : data.secretKey) || null,
478
+ enableSignedUrls: Boolean(data == null ? void 0 : data.enableSignedUrls) || false,
479
+ signingKeyId: (data == null ? void 0 : data.signingKeyId) || null,
480
+ signingKeyPrivate: (data == null ? void 0 : data.signingKeyPrivate) || null
481
+ };
482
+ }, [cacheNs, _id, projectId, dataset]);
483
+ }
484
+ function generateJwt(client, playbackId, aud, payload) {
485
+ const {
486
+ signingKeyId,
487
+ signingKeyPrivate
488
+ } = readSecrets(client);
489
+ if (!signingKeyId) {
490
+ throw new TypeError("Missing signingKeyId");
491
+ }
492
+ if (!signingKeyPrivate) {
493
+ throw new TypeError("Missing signingKeyPrivate");
494
+ }
495
+ const {
496
+ default: sign
497
+ } = suspend(() => import('jsonwebtoken-esm/sign'), ["jsonwebtoken-esm/sign"]);
498
+ return sign(payload ? JSON.parse(JSON.stringify(payload, (_, v) => v != null ? v : void 0)) : {}, atob(signingKeyPrivate), {
499
+ algorithm: "RS256",
500
+ keyid: signingKeyId,
501
+ audience: aud,
502
+ subject: playbackId,
503
+ noTimestamp: true,
504
+ expiresIn: "12h"
505
+ });
506
+ }
507
+ function getPlaybackId(asset) {
508
+ if (!(asset == null ? void 0 : asset.playbackId)) {
509
+ console.error("Asset is missing a playbackId", {
510
+ asset
511
+ });
512
+ throw new TypeError("Missing playbackId");
513
+ }
514
+ return asset.playbackId;
515
+ }
516
+ function getPlaybackPolicy(asset) {
517
+ var _a, _b, _c, _d;
518
+ return (_d = (_c = (_b = (_a = asset.data) == null ? void 0 : _a.playback_ids) == null ? void 0 : _b[0]) == null ? void 0 : _c.policy) != null ? _d : "public";
519
+ }
520
+ function getAnimatedPosterSrc(_ref) {
521
+ let {
522
+ asset,
523
+ client,
524
+ height,
525
+ width,
526
+ start = asset.thumbTime ? Math.max(0, asset.thumbTime - 2.5) : 0,
527
+ end = start + 5,
528
+ fps = 15
529
+ } = _ref;
530
+ const params = {
531
+ height,
532
+ width,
533
+ start,
534
+ end,
535
+ fps
536
+ };
537
+ const playbackId = getPlaybackId(asset);
538
+ let searchParams = new URLSearchParams(JSON.parse(JSON.stringify(params, (_, v) => v != null ? v : void 0)));
539
+ if (getPlaybackPolicy(asset) === "signed") {
540
+ const token = generateJwt(client, playbackId, "g", params);
541
+ searchParams = new URLSearchParams({
542
+ token
543
+ });
544
+ }
545
+ return "https://image.mux.com/".concat(playbackId, "/animated.gif?").concat(searchParams);
546
+ }
547
+ function getPosterSrc(_ref2) {
548
+ let {
549
+ asset,
550
+ client,
551
+ fit_mode,
552
+ height,
553
+ time = asset.thumbTime,
554
+ width
555
+ } = _ref2;
556
+ const params = {
557
+ fit_mode,
558
+ height,
559
+ time,
560
+ width
561
+ };
562
+ const playbackId = getPlaybackId(asset);
563
+ let searchParams = new URLSearchParams(JSON.parse(JSON.stringify(params, (_, v) => v != null ? v : void 0)));
564
+ if (getPlaybackPolicy(asset) === "signed") {
565
+ const token = generateJwt(client, playbackId, "t", params);
566
+ searchParams = new URLSearchParams({
567
+ token
568
+ });
569
+ }
570
+ return "https://image.mux.com/".concat(playbackId, "/thumbnail.png?").concat(searchParams);
571
+ }
572
+ const mediaDimensions = {
573
+ aspect: 16 / 9
574
+ };
575
+ const ImageLoader = memo(function ImageLoader2(_ref3) {
576
+ let {
577
+ alt,
578
+ src,
579
+ height,
580
+ width,
581
+ aspectRatio
582
+ } = _ref3;
583
+ suspend(async () => {
584
+ const img = new Image(width, height);
585
+ img.decoding = "async";
586
+ img.src = src;
587
+ await img.decode();
588
+ }, ["sanity-plugin-mux-input", "image", src]);
589
+ return /* @__PURE__ */jsx("img", {
590
+ alt,
591
+ src,
592
+ height,
593
+ width,
594
+ style: {
595
+ aspectRatio
596
+ }
597
+ });
598
+ });
599
+ const VideoMediaPreview = styled(MediaPreview)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n img {\n object-fit: cover;\n }\n"])));
600
+ const VideoMediaPreviewSignedSubtitle = _ref4 => {
601
+ let {
602
+ solo
603
+ } = _ref4;
604
+ return /* @__PURE__ */jsxs(Inline, {
605
+ space: 1,
606
+ style: {
607
+ marginTop: solo ? "-1.35em" : void 0,
608
+ marginBottom: solo ? void 0 : "0.35rem"
609
+ },
610
+ children: [/* @__PURE__ */jsx(LockIcon, {}), "Signed playback policy"]
611
+ });
612
+ };
613
+ const PosterImage = _ref5 => {
614
+ let {
615
+ asset,
616
+ height,
617
+ width,
618
+ showTip
619
+ } = _ref5;
620
+ const client = useClient();
621
+ const src = getPosterSrc({
622
+ asset,
623
+ client,
624
+ height,
625
+ width,
626
+ fit_mode: "smartcrop"
627
+ });
628
+ const subtitle = useMemo(() => showTip && getPlaybackPolicy(asset) === "signed" ? /* @__PURE__ */jsx(VideoMediaPreviewSignedSubtitle, {
629
+ solo: true
630
+ }) : void 0, [asset, showTip]);
631
+ return /* @__PURE__ */jsx(VideoMediaPreview, {
632
+ mediaDimensions,
633
+ subtitle,
634
+ title: /* @__PURE__ */jsx(Fragment, {
635
+ children: null
636
+ }),
637
+ media: /* @__PURE__ */jsx(ImageLoader, {
638
+ alt: "",
639
+ src,
640
+ height,
641
+ width
642
+ })
643
+ });
644
+ };
645
+ const VideoThumbnail = memo(function VideoThumbnail2(_ref6) {
646
+ let {
647
+ asset,
648
+ width,
649
+ showTip
650
+ } = _ref6;
651
+ const {
652
+ ErrorBoundary,
653
+ didCatch,
654
+ error
655
+ } = useErrorBoundary();
656
+ const height = Math.round(width * 9 / 16);
657
+ const subtitle = useMemo(() => showTip && getPlaybackPolicy(asset) === "signed" ? /* @__PURE__ */jsx(VideoMediaPreviewSignedSubtitle, {}) : void 0, [showTip, asset]);
658
+ if (didCatch) {
659
+ return /* @__PURE__ */jsx(VideoMediaPreview, {
660
+ subtitle: error.message,
661
+ mediaDimensions,
662
+ title: "Error when loading thumbnail",
663
+ media: /* @__PURE__ */jsx(Card, {
664
+ radius: 2,
665
+ height: "fill",
666
+ style: {
667
+ position: "relative",
668
+ width: "100%"
669
+ },
670
+ children: /* @__PURE__ */jsx(Box, {
671
+ style: {
672
+ display: "flex",
673
+ justifyContent: "center",
674
+ alignItems: "center",
675
+ position: "absolute",
676
+ top: 0,
677
+ left: 0,
678
+ right: 0,
679
+ bottom: 0
680
+ },
681
+ children: /* @__PURE__ */jsx(UnknownIcon, {})
682
+ })
683
+ })
684
+ });
685
+ }
686
+ return /* @__PURE__ */jsx(ErrorBoundary, {
687
+ children: /* @__PURE__ */jsx(Suspense, {
688
+ fallback: /* @__PURE__ */jsx(VideoMediaPreview, {
689
+ isPlaceholder: true,
690
+ title: "Loading thumbnail...",
691
+ subtitle,
692
+ mediaDimensions
693
+ }),
694
+ children: /* @__PURE__ */jsx(PosterImage, {
695
+ showTip,
696
+ asset,
697
+ height,
698
+ width
699
+ })
700
+ })
701
+ });
702
+ });
703
+ const AnimatedVideoMediaPreview = styled(MediaPreview)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n img {\n object-fit: contain;\n }\n"])));
704
+ const AnimatedPosterImage = _ref7 => {
705
+ let {
706
+ asset,
707
+ width
708
+ } = _ref7;
709
+ const client = useClient();
710
+ const src = getAnimatedPosterSrc({
711
+ asset,
712
+ client,
713
+ width
714
+ });
715
+ return /* @__PURE__ */jsx(AnimatedVideoMediaPreview, {
716
+ withBorder: false,
717
+ mediaDimensions,
718
+ media: /* @__PURE__ */jsx(ImageLoader, {
719
+ alt: "",
720
+ src,
721
+ width,
722
+ aspectRatio: "16:9"
723
+ })
724
+ });
725
+ };
726
+ const AnimatedVideoThumbnail = memo(function AnimatedVideoThumbnail2(_ref8) {
727
+ let {
728
+ asset,
729
+ width
730
+ } = _ref8;
731
+ const {
732
+ ErrorBoundary,
733
+ didCatch
734
+ } = useErrorBoundary();
735
+ if (didCatch) {
736
+ return null;
737
+ }
738
+ return /* @__PURE__ */jsx(ErrorBoundary, {
739
+ children: /* @__PURE__ */jsx(Suspense, {
740
+ fallback: /* @__PURE__ */jsx(FancyBackdrop, {
741
+ children: /* @__PURE__ */jsx(VideoMediaPreview, {
742
+ mediaDimensions,
743
+ withBorder: false,
744
+ media: /* @__PURE__ */jsx(Spinner, {
745
+ muted: true
746
+ })
747
+ })
748
+ }),
749
+ children: /* @__PURE__ */jsx(Card, {
750
+ height: "fill",
751
+ tone: "transparent",
752
+ children: /* @__PURE__ */jsx(AnimatedPosterImage, {
753
+ asset,
754
+ width
755
+ })
756
+ })
757
+ })
758
+ });
759
+ });
760
+ const FancyBackdrop = styled(Box)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n backdrop-filter: blur(8px) brightness(0.5) saturate(2);\n mix-blend-mode: color-dodge;\n"])));
761
+ const ThumbGrid = styled(Grid)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));\n"])));
762
+ const CardLoadMore = styled(Card)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n border-top: 1px solid var(--card-border-color);\n position: sticky;\n bottom: 0;\n z-index: 200;\n"])));
763
+ function AssetActionsMenu(props) {
764
+ const {
765
+ asset
766
+ } = props;
767
+ const id = useId();
768
+ const [dialogState, setDialogState] = useState();
769
+ const [open, setOpen] = useState(false);
770
+ const [menuElement, setMenuRef] = useState(null);
771
+ const handleDelete = useCallback(() => setDialogState("confirm-delete"), []);
772
+ const handleClick = useCallback(() => {
773
+ setDialogState(false);
774
+ setOpen(true);
775
+ }, [setDialogState]);
776
+ const handleClose = useCallback(() => {
777
+ setDialogState(false);
778
+ setOpen(false);
779
+ }, [setDialogState]);
780
+ useEffect(() => {
781
+ if (open && dialogState) {
782
+ setOpen(false);
783
+ }
784
+ }, [dialogState, open]);
785
+ useClickOutside(useCallback(() => setOpen(false), []), [menuElement]);
786
+ return /* @__PURE__ */jsxs(Fragment, {
787
+ children: [/* @__PURE__ */jsx(MenuButton, {
788
+ id: "".concat(id, "-asset-menu"),
789
+ button: /* @__PURE__ */jsx(Button, {
790
+ icon: EllipsisVerticalIcon,
791
+ mode: "ghost",
792
+ onClick: handleClick,
793
+ padding: 2
794
+ }),
795
+ menu: /* @__PURE__ */jsx(Menu, {
796
+ ref: setMenuRef,
797
+ children: /* @__PURE__ */jsx(MenuItem, {
798
+ tone: "critical",
799
+ icon: TrashIcon,
800
+ text: "Delete",
801
+ onClick: handleDelete
802
+ })
803
+ }),
804
+ portal: true,
805
+ placement: "right"
806
+ }), dialogState === "confirm-delete" && /* @__PURE__ */jsx(DeleteDialog, {
807
+ asset,
808
+ onClose: handleClose
809
+ })]
810
+ });
811
+ }
812
+ function DeleteDialog(props) {
813
+ const {
814
+ asset,
815
+ onClose
816
+ } = props;
817
+ const client = useClient();
818
+ const {
819
+ push: pushToast
820
+ } = useToast();
821
+ const [deleting, setDeleting] = useState(false);
822
+ const [deleteOnMux, setDeleteOnMux] = useState(false);
823
+ const id = useId();
824
+ const width = 200 * getDevicePixelRatio({
825
+ maxDpr: 2
826
+ });
827
+ const handleDelete = useCallback(async () => {
828
+ var _a, _b, _c;
829
+ setDeleting(true);
830
+ try {
831
+ if (asset == null ? void 0 : asset._id) {
832
+ await client.delete(asset._id);
833
+ }
834
+ if (deleteOnMux && (asset == null ? void 0 : asset.assetId)) {
835
+ await deleteAsset(client, asset.assetId);
836
+ }
837
+ (_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");
838
+ } catch (err) {
839
+ console.error("Failed during delete", err);
840
+ pushToast({
841
+ closable: true,
842
+ description: err == null ? void 0 : err.message,
843
+ duration: 5e3,
844
+ title: "Uncaught error",
845
+ status: "error"
846
+ });
847
+ } finally {
848
+ setDeleting(false);
849
+ onClose();
850
+ }
851
+ }, [asset._id, asset.assetId, client, deleteOnMux, onClose, pushToast]);
852
+ return /* @__PURE__ */jsx(Dialog, {
853
+ onClose,
854
+ id: "".concat(id, "-confirm-delete"),
855
+ header: "Delete video",
856
+ footer: /* @__PURE__ */jsxs(Grid, {
857
+ padding: 2,
858
+ gap: 2,
859
+ columns: 2,
860
+ children: [/* @__PURE__ */jsx(Button, {
861
+ mode: "bleed",
862
+ text: "Cancel",
863
+ onClick: onClose
864
+ }), /* @__PURE__ */jsx(Button, {
865
+ text: "Delete",
866
+ tone: "critical",
867
+ icon: TrashIcon,
868
+ onClick: handleDelete,
869
+ loading: deleting
870
+ })]
871
+ }),
872
+ width: 1,
873
+ children: /* @__PURE__ */jsx(Stack, {
874
+ paddingX: 0,
875
+ paddingY: 0,
876
+ space: 1,
877
+ children: /* @__PURE__ */jsx(Card, {
878
+ paddingX: [2, 3, 4],
879
+ paddingY: [3, 3, 3, 4],
880
+ children: /* @__PURE__ */jsxs(Grid, {
881
+ columns: 3,
882
+ gap: 3,
883
+ children: [/* @__PURE__ */jsx(Flex, {
884
+ style: {
885
+ gridColumn: "span 2"
886
+ },
887
+ align: "center",
888
+ children: /* @__PURE__ */jsx(Box, {
889
+ padding: 4,
890
+ children: /* @__PURE__ */jsxs(Stack, {
891
+ space: 4,
892
+ children: [/* @__PURE__ */jsxs(Flex, {
893
+ align: "center",
894
+ as: "label",
895
+ children: [/* @__PURE__ */jsx(Checkbox, {
896
+ checked: deleteOnMux,
897
+ onChange: () => setDeleteOnMux(prev => !prev)
898
+ }), /* @__PURE__ */jsx(Text, {
899
+ style: {
900
+ margin: "0 10px"
901
+ },
902
+ children: "Delete asset on Mux"
903
+ })]
904
+ }), /* @__PURE__ */jsxs(Flex, {
905
+ align: "center",
906
+ as: "label",
907
+ children: [/* @__PURE__ */jsx(Checkbox, {
908
+ disabled: true,
909
+ checked: true
910
+ }), /* @__PURE__ */jsx(Text, {
911
+ style: {
912
+ margin: "0 10px"
913
+ },
914
+ children: "Delete video from dataset"
915
+ })]
916
+ })]
917
+ })
918
+ })
919
+ }), /* @__PURE__ */jsx(VideoThumbnail, {
920
+ asset,
921
+ width,
922
+ showTip: true
923
+ })]
924
+ })
925
+ })
926
+ })
927
+ });
928
+ }
929
+ function VideoSource(_ref9) {
930
+ let {
931
+ assets,
932
+ isLoading,
933
+ isLastPage,
934
+ onSelect,
935
+ onLoadMore
936
+ } = _ref9;
937
+ const handleClick = useCallback(event => onSelect(event.currentTarget.dataset.id), [onSelect]);
938
+ const handleKeyPress = useCallback(event => {
939
+ if (event.key === "Enter") {
940
+ onSelect(event.currentTarget.dataset.id);
941
+ }
942
+ }, [onSelect]);
943
+ const width = 200 * getDevicePixelRatio({
944
+ maxDpr: 2
945
+ });
946
+ return /* @__PURE__ */jsxs(Fragment, {
947
+ children: [/* @__PURE__ */jsxs(Box, {
948
+ padding: 4,
949
+ children: [/* @__PURE__ */jsx(ThumbGrid, {
950
+ gap: 2,
951
+ children: assets.map(asset => /* @__PURE__ */jsx(VideoSourceItem, {
952
+ asset,
953
+ onClick: handleClick,
954
+ onKeyPress: handleKeyPress,
955
+ width
956
+ }, asset._id))
957
+ }), isLoading && assets.length === 0 && /* @__PURE__ */jsx(Flex, {
958
+ justify: "center",
959
+ children: /* @__PURE__ */jsx(Spinner, {
960
+ muted: true
961
+ })
962
+ }), !isLoading && assets.length === 0 && /* @__PURE__ */jsx(Text, {
963
+ align: "center",
964
+ muted: true,
965
+ children: "No videos"
966
+ })]
967
+ }), assets.length > 0 && !isLastPage && /* @__PURE__ */jsx(CardLoadMore, {
968
+ tone: "default",
969
+ padding: 4,
970
+ children: /* @__PURE__ */jsx(Flex, {
971
+ direction: "column",
972
+ children: /* @__PURE__ */jsx(Button, {
973
+ type: "button",
974
+ icon: DownloadIcon,
975
+ loading: isLoading,
976
+ onClick: onLoadMore,
977
+ text: "Load more",
978
+ tone: "primary"
979
+ })
980
+ })
981
+ })]
982
+ });
983
+ }
984
+ const _VideoSourceItem = _ref10 => {
985
+ let {
986
+ asset,
987
+ onClick,
988
+ onKeyPress,
989
+ width
990
+ } = _ref10;
991
+ const [hover, setHover] = useState(null);
992
+ const ref = useRef(null);
993
+ useLayoutEffect(() => {
994
+ if (!ref.current || hover === null) {
995
+ return;
996
+ }
997
+ if (hover) {
998
+ animate(ref.current, {
999
+ opacity: 1
1000
+ });
1001
+ } else {
1002
+ animate(ref.current, {
1003
+ opacity: 0
1004
+ });
1005
+ }
1006
+ }, [hover]);
1007
+ return /* @__PURE__ */jsxs(Box, {
1008
+ height: "fill",
1009
+ style: {
1010
+ position: "relative"
1011
+ },
1012
+ children: [/* @__PURE__ */jsxs(Card, {
1013
+ as: "button",
1014
+ "data-id": asset._id,
1015
+ onClick,
1016
+ onKeyPress,
1017
+ tabIndex: 0,
1018
+ radius: 2,
1019
+ padding: 1,
1020
+ style: {
1021
+ lineHeight: 0,
1022
+ position: "relative"
1023
+ },
1024
+ __unstable_focusRing: true,
1025
+ onMouseEnter: () => setHover(true),
1026
+ onMouseLeave: () => setHover(false),
1027
+ children: [/* @__PURE__ */jsx(VideoThumbnail, {
1028
+ asset,
1029
+ width,
1030
+ showTip: true
1031
+ }), (asset == null ? void 0 : asset.playbackId) && /* @__PURE__ */jsx(AnimateWrapper, {
1032
+ tone: "transparent",
1033
+ ref,
1034
+ margin: 1,
1035
+ radius: 1,
1036
+ children: hover !== null && /* @__PURE__ */jsx(AnimatedVideoThumbnail, {
1037
+ asset,
1038
+ width
1039
+ })
1040
+ })]
1041
+ }), /* @__PURE__ */jsx(ActionsAssetsContainer, {
1042
+ children: /* @__PURE__ */jsx(AssetActionsMenu, {
1043
+ asset
1044
+ })
1045
+ })]
1046
+ });
1047
+ };
1048
+ const VideoSourceItem = memo(_VideoSourceItem);
1049
+ const AnimateWrapper = styled(Card)(_templateObject6 || (_templateObject6 = _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"])));
1050
+ const ActionsAssetsContainer = styled.div(_templateObject7 || (_templateObject7 = _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"])));
1051
+ const PER_PAGE = 200;
1052
+ function createQuery() {
1053
+ let start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
1054
+ let end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : PER_PAGE;
1055
+ return (/* groq */"*[_type == \"mux.videoAsset\"] | order(_updatedAt desc) [".concat(start, "...").concat(end, "]")
1056
+ );
1057
+ }
1058
+ function SelectAssets(_ref11) {
1059
+ let {
1060
+ asset,
1061
+ onChange,
1062
+ setDialogState
1063
+ } = _ref11;
1064
+ const client = useClient();
1065
+ const pageNoRef = useRef(0);
1066
+ const [isLastPage, setLastPage] = useState(false);
1067
+ const [isLoading, setLoading] = useState(false);
1068
+ const [assets, setAssets] = useState([]);
1069
+ const fetchPage = useCallback(pageNo => {
1070
+ const start = pageNo * PER_PAGE;
1071
+ const end = start + PER_PAGE;
1072
+ setLoading(true);
1073
+ return client.fetch(createQuery(start, end)).then(result => {
1074
+ setLastPage(result.length < PER_PAGE);
1075
+ setAssets(prev => prev.concat(result));
1076
+ }).finally(() => setLoading(false));
1077
+ }, [client]);
1078
+ const handleSelect = useCallback(id => {
1079
+ const selected = assets.find(doc => doc._id === id);
1080
+ if (!selected) {
1081
+ throw new TypeError("Failed to find video asset with id: ".concat(id));
1082
+ }
1083
+ onChange(PatchEvent.from([setIfMissing({
1084
+ asset: {}
1085
+ }), set({
1086
+ _type: "reference",
1087
+ _weak: true,
1088
+ _ref: selected._id
1089
+ }, ["asset"])]));
1090
+ setDialogState(false);
1091
+ }, [assets, onChange, setDialogState]);
1092
+ const handleLoadMore = useCallback(() => {
1093
+ fetchPage(++pageNoRef.current);
1094
+ }, [fetchPage]);
1095
+ useEffect(() => void fetchPage(pageNoRef.current), [fetchPage]);
1096
+ return /* @__PURE__ */jsx(VideoSource, {
1097
+ onSelect: handleSelect,
1098
+ assets,
1099
+ isLastPage,
1100
+ isLoading,
1101
+ onLoadMore: handleLoadMore
1102
+ });
1103
+ }
1104
+ function InputBrowser(_ref12) {
1105
+ let {
1106
+ setDialogState,
1107
+ asset,
1108
+ onChange
1109
+ } = _ref12;
1110
+ const id = "InputBrowser".concat(useId());
1111
+ const handleClose = useCallback(() => setDialogState(false), [setDialogState]);
1112
+ return /* @__PURE__ */jsx(Dialog, {
1113
+ scheme: "dark",
1114
+ __unstable_autoFocus: true,
1115
+ header: "Select video",
1116
+ id,
1117
+ onClose: handleClose,
1118
+ width: 2,
1119
+ children: /* @__PURE__ */jsx(SelectAssets, {
1120
+ asset,
1121
+ onChange,
1122
+ setDialogState
1123
+ })
1124
+ });
1125
+ }
1126
+ var reactIsExports = {};
1127
+ var reactIs = {
1128
+ get exports() {
1129
+ return reactIsExports;
1130
+ },
1131
+ set exports(v) {
1132
+ reactIsExports = v;
1133
+ }
1134
+ };
1135
+ var reactIs_production_min = {};
1136
+
1137
+ /**
1138
+ * @license React
1139
+ * react-is.production.min.js
1140
+ *
1141
+ * Copyright (c) Facebook, Inc. and its affiliates.
1142
+ *
1143
+ * This source code is licensed under the MIT license found in the
1144
+ * LICENSE file in the root directory of this source tree.
1145
+ */
1146
+
1147
+ var hasRequiredReactIs_production_min;
1148
+ function requireReactIs_production_min() {
1149
+ if (hasRequiredReactIs_production_min) return reactIs_production_min;
1150
+ hasRequiredReactIs_production_min = 1;
1151
+ var b = Symbol.for("react.element"),
1152
+ c = Symbol.for("react.portal"),
1153
+ d = Symbol.for("react.fragment"),
1154
+ e = Symbol.for("react.strict_mode"),
1155
+ f = Symbol.for("react.profiler"),
1156
+ g = Symbol.for("react.provider"),
1157
+ h = Symbol.for("react.context"),
1158
+ k = Symbol.for("react.server_context"),
1159
+ l = Symbol.for("react.forward_ref"),
1160
+ m = Symbol.for("react.suspense"),
1161
+ n = Symbol.for("react.suspense_list"),
1162
+ p = Symbol.for("react.memo"),
1163
+ q = Symbol.for("react.lazy"),
1164
+ t = Symbol.for("react.offscreen"),
1165
+ u;
1166
+ u = Symbol.for("react.module.reference");
1167
+ function v(a) {
1168
+ if ("object" === typeof a && null !== a) {
1169
+ var r = a.$$typeof;
1170
+ switch (r) {
1171
+ case b:
1172
+ switch (a = a.type, a) {
1173
+ case d:
1174
+ case f:
1175
+ case e:
1176
+ case m:
1177
+ case n:
1178
+ return a;
1179
+ default:
1180
+ switch (a = a && a.$$typeof, a) {
1181
+ case k:
1182
+ case h:
1183
+ case l:
1184
+ case q:
1185
+ case p:
1186
+ case g:
1187
+ return a;
1188
+ default:
1189
+ return r;
1190
+ }
1191
+ }
1192
+ case c:
1193
+ return r;
1194
+ }
1195
+ }
1196
+ }
1197
+ reactIs_production_min.ContextConsumer = h;
1198
+ reactIs_production_min.ContextProvider = g;
1199
+ reactIs_production_min.Element = b;
1200
+ reactIs_production_min.ForwardRef = l;
1201
+ reactIs_production_min.Fragment = d;
1202
+ reactIs_production_min.Lazy = q;
1203
+ reactIs_production_min.Memo = p;
1204
+ reactIs_production_min.Portal = c;
1205
+ reactIs_production_min.Profiler = f;
1206
+ reactIs_production_min.StrictMode = e;
1207
+ reactIs_production_min.Suspense = m;
1208
+ reactIs_production_min.SuspenseList = n;
1209
+ reactIs_production_min.isAsyncMode = function () {
1210
+ return !1;
1211
+ };
1212
+ reactIs_production_min.isConcurrentMode = function () {
1213
+ return !1;
1214
+ };
1215
+ reactIs_production_min.isContextConsumer = function (a) {
1216
+ return v(a) === h;
1217
+ };
1218
+ reactIs_production_min.isContextProvider = function (a) {
1219
+ return v(a) === g;
1220
+ };
1221
+ reactIs_production_min.isElement = function (a) {
1222
+ return "object" === typeof a && null !== a && a.$$typeof === b;
1223
+ };
1224
+ reactIs_production_min.isForwardRef = function (a) {
1225
+ return v(a) === l;
1226
+ };
1227
+ reactIs_production_min.isFragment = function (a) {
1228
+ return v(a) === d;
1229
+ };
1230
+ reactIs_production_min.isLazy = function (a) {
1231
+ return v(a) === q;
1232
+ };
1233
+ reactIs_production_min.isMemo = function (a) {
1234
+ return v(a) === p;
1235
+ };
1236
+ reactIs_production_min.isPortal = function (a) {
1237
+ return v(a) === c;
1238
+ };
1239
+ reactIs_production_min.isProfiler = function (a) {
1240
+ return v(a) === f;
1241
+ };
1242
+ reactIs_production_min.isStrictMode = function (a) {
1243
+ return v(a) === e;
1244
+ };
1245
+ reactIs_production_min.isSuspense = function (a) {
1246
+ return v(a) === m;
1247
+ };
1248
+ reactIs_production_min.isSuspenseList = function (a) {
1249
+ return v(a) === n;
1250
+ };
1251
+ reactIs_production_min.isValidElementType = function (a) {
1252
+ return "string" === typeof a || "function" === typeof a || a === d || a === f || a === e || a === m || a === n || a === t || "object" === typeof a && null !== a && (a.$$typeof === q || a.$$typeof === p || a.$$typeof === g || a.$$typeof === h || a.$$typeof === l || a.$$typeof === u || void 0 !== a.getModuleId) ? !0 : !1;
1253
+ };
1254
+ reactIs_production_min.typeOf = v;
1255
+ return reactIs_production_min;
1256
+ }
1257
+ var reactIs_development = {};
1258
+
1259
+ /**
1260
+ * @license React
1261
+ * react-is.development.js
1262
+ *
1263
+ * Copyright (c) Facebook, Inc. and its affiliates.
1264
+ *
1265
+ * This source code is licensed under the MIT license found in the
1266
+ * LICENSE file in the root directory of this source tree.
1267
+ */
1268
+
1269
+ var hasRequiredReactIs_development;
1270
+ function requireReactIs_development() {
1271
+ if (hasRequiredReactIs_development) return reactIs_development;
1272
+ hasRequiredReactIs_development = 1;
1273
+ if (process.env.NODE_ENV !== "production") {
1274
+ (function () {
1275
+ // ATTENTION
1276
+ // When adding new symbols to this file,
1277
+ // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
1278
+ // The Symbol used to tag the ReactElement-like types.
1279
+ var REACT_ELEMENT_TYPE = Symbol.for('react.element');
1280
+ var REACT_PORTAL_TYPE = Symbol.for('react.portal');
1281
+ var REACT_FRAGMENT_TYPE = Symbol.for('react.fragment');
1282
+ var REACT_STRICT_MODE_TYPE = Symbol.for('react.strict_mode');
1283
+ var REACT_PROFILER_TYPE = Symbol.for('react.profiler');
1284
+ var REACT_PROVIDER_TYPE = Symbol.for('react.provider');
1285
+ var REACT_CONTEXT_TYPE = Symbol.for('react.context');
1286
+ var REACT_SERVER_CONTEXT_TYPE = Symbol.for('react.server_context');
1287
+ var REACT_FORWARD_REF_TYPE = Symbol.for('react.forward_ref');
1288
+ var REACT_SUSPENSE_TYPE = Symbol.for('react.suspense');
1289
+ var REACT_SUSPENSE_LIST_TYPE = Symbol.for('react.suspense_list');
1290
+ var REACT_MEMO_TYPE = Symbol.for('react.memo');
1291
+ var REACT_LAZY_TYPE = Symbol.for('react.lazy');
1292
+ var REACT_OFFSCREEN_TYPE = Symbol.for('react.offscreen');
1293
+
1294
+ // -----------------------------------------------------------------------------
1295
+
1296
+ var enableScopeAPI = false; // Experimental Create Event Handle API.
1297
+ var enableCacheElement = false;
1298
+ var enableTransitionTracing = false; // No known bugs, but needs performance testing
1299
+
1300
+ var enableLegacyHidden = false; // Enables unstable_avoidThisFallback feature in Fiber
1301
+ // stuff. Intended to enable React core members to more easily debug scheduling
1302
+ // issues in DEV builds.
1303
+
1304
+ var enableDebugTracing = false; // Track which Fiber(s) schedule render work.
1305
+
1306
+ var REACT_MODULE_REFERENCE;
1307
+ {
1308
+ REACT_MODULE_REFERENCE = Symbol.for('react.module.reference');
1309
+ }
1310
+ function isValidElementType(type) {
1311
+ if (typeof type === 'string' || typeof type === 'function') {
1312
+ return true;
1313
+ } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
1314
+
1315
+ if (type === REACT_FRAGMENT_TYPE || type === REACT_PROFILER_TYPE || enableDebugTracing || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || enableLegacyHidden || type === REACT_OFFSCREEN_TYPE || enableScopeAPI || enableCacheElement || enableTransitionTracing) {
1316
+ return true;
1317
+ }
1318
+ if (typeof type === 'object' && type !== null) {
1319
+ if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE ||
1320
+ // This needs to include all possible module reference object
1321
+ // types supported by any Flight configuration anywhere since
1322
+ // we don't know which Flight build this will end up being used
1323
+ // with.
1324
+ type.$$typeof === REACT_MODULE_REFERENCE || type.getModuleId !== undefined) {
1325
+ return true;
1326
+ }
1327
+ }
1328
+ return false;
1329
+ }
1330
+ function typeOf(object) {
1331
+ if (typeof object === 'object' && object !== null) {
1332
+ var $$typeof = object.$$typeof;
1333
+ switch ($$typeof) {
1334
+ case REACT_ELEMENT_TYPE:
1335
+ var type = object.type;
1336
+ switch (type) {
1337
+ case REACT_FRAGMENT_TYPE:
1338
+ case REACT_PROFILER_TYPE:
1339
+ case REACT_STRICT_MODE_TYPE:
1340
+ case REACT_SUSPENSE_TYPE:
1341
+ case REACT_SUSPENSE_LIST_TYPE:
1342
+ return type;
1343
+ default:
1344
+ var $$typeofType = type && type.$$typeof;
1345
+ switch ($$typeofType) {
1346
+ case REACT_SERVER_CONTEXT_TYPE:
1347
+ case REACT_CONTEXT_TYPE:
1348
+ case REACT_FORWARD_REF_TYPE:
1349
+ case REACT_LAZY_TYPE:
1350
+ case REACT_MEMO_TYPE:
1351
+ case REACT_PROVIDER_TYPE:
1352
+ return $$typeofType;
1353
+ default:
1354
+ return $$typeof;
1355
+ }
1356
+ }
1357
+ case REACT_PORTAL_TYPE:
1358
+ return $$typeof;
1359
+ }
1360
+ }
1361
+ return undefined;
1362
+ }
1363
+ var ContextConsumer = REACT_CONTEXT_TYPE;
1364
+ var ContextProvider = REACT_PROVIDER_TYPE;
1365
+ var Element = REACT_ELEMENT_TYPE;
1366
+ var ForwardRef = REACT_FORWARD_REF_TYPE;
1367
+ var Fragment = REACT_FRAGMENT_TYPE;
1368
+ var Lazy = REACT_LAZY_TYPE;
1369
+ var Memo = REACT_MEMO_TYPE;
1370
+ var Portal = REACT_PORTAL_TYPE;
1371
+ var Profiler = REACT_PROFILER_TYPE;
1372
+ var StrictMode = REACT_STRICT_MODE_TYPE;
1373
+ var Suspense = REACT_SUSPENSE_TYPE;
1374
+ var SuspenseList = REACT_SUSPENSE_LIST_TYPE;
1375
+ var hasWarnedAboutDeprecatedIsAsyncMode = false;
1376
+ var hasWarnedAboutDeprecatedIsConcurrentMode = false; // AsyncMode should be deprecated
1377
+
1378
+ function isAsyncMode(object) {
1379
+ {
1380
+ if (!hasWarnedAboutDeprecatedIsAsyncMode) {
1381
+ hasWarnedAboutDeprecatedIsAsyncMode = true; // Using console['warn'] to evade Babel and ESLint
1382
+
1383
+ console['warn']('The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
1384
+ }
1385
+ }
1386
+ return false;
1387
+ }
1388
+ function isConcurrentMode(object) {
1389
+ {
1390
+ if (!hasWarnedAboutDeprecatedIsConcurrentMode) {
1391
+ hasWarnedAboutDeprecatedIsConcurrentMode = true; // Using console['warn'] to evade Babel and ESLint
1392
+
1393
+ console['warn']('The ReactIs.isConcurrentMode() alias has been deprecated, ' + 'and will be removed in React 18+.');
1394
+ }
1395
+ }
1396
+ return false;
1397
+ }
1398
+ function isContextConsumer(object) {
1399
+ return typeOf(object) === REACT_CONTEXT_TYPE;
1400
+ }
1401
+ function isContextProvider(object) {
1402
+ return typeOf(object) === REACT_PROVIDER_TYPE;
1403
+ }
1404
+ function isElement(object) {
1405
+ return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
1406
+ }
1407
+ function isForwardRef(object) {
1408
+ return typeOf(object) === REACT_FORWARD_REF_TYPE;
1409
+ }
1410
+ function isFragment(object) {
1411
+ return typeOf(object) === REACT_FRAGMENT_TYPE;
1412
+ }
1413
+ function isLazy(object) {
1414
+ return typeOf(object) === REACT_LAZY_TYPE;
1415
+ }
1416
+ function isMemo(object) {
1417
+ return typeOf(object) === REACT_MEMO_TYPE;
1418
+ }
1419
+ function isPortal(object) {
1420
+ return typeOf(object) === REACT_PORTAL_TYPE;
1421
+ }
1422
+ function isProfiler(object) {
1423
+ return typeOf(object) === REACT_PROFILER_TYPE;
1424
+ }
1425
+ function isStrictMode(object) {
1426
+ return typeOf(object) === REACT_STRICT_MODE_TYPE;
1427
+ }
1428
+ function isSuspense(object) {
1429
+ return typeOf(object) === REACT_SUSPENSE_TYPE;
1430
+ }
1431
+ function isSuspenseList(object) {
1432
+ return typeOf(object) === REACT_SUSPENSE_LIST_TYPE;
1433
+ }
1434
+ reactIs_development.ContextConsumer = ContextConsumer;
1435
+ reactIs_development.ContextProvider = ContextProvider;
1436
+ reactIs_development.Element = Element;
1437
+ reactIs_development.ForwardRef = ForwardRef;
1438
+ reactIs_development.Fragment = Fragment;
1439
+ reactIs_development.Lazy = Lazy;
1440
+ reactIs_development.Memo = Memo;
1441
+ reactIs_development.Portal = Portal;
1442
+ reactIs_development.Profiler = Profiler;
1443
+ reactIs_development.StrictMode = StrictMode;
1444
+ reactIs_development.Suspense = Suspense;
1445
+ reactIs_development.SuspenseList = SuspenseList;
1446
+ reactIs_development.isAsyncMode = isAsyncMode;
1447
+ reactIs_development.isConcurrentMode = isConcurrentMode;
1448
+ reactIs_development.isContextConsumer = isContextConsumer;
1449
+ reactIs_development.isContextProvider = isContextProvider;
1450
+ reactIs_development.isElement = isElement;
1451
+ reactIs_development.isForwardRef = isForwardRef;
1452
+ reactIs_development.isFragment = isFragment;
1453
+ reactIs_development.isLazy = isLazy;
1454
+ reactIs_development.isMemo = isMemo;
1455
+ reactIs_development.isPortal = isPortal;
1456
+ reactIs_development.isProfiler = isProfiler;
1457
+ reactIs_development.isStrictMode = isStrictMode;
1458
+ reactIs_development.isSuspense = isSuspense;
1459
+ reactIs_development.isSuspenseList = isSuspenseList;
1460
+ reactIs_development.isValidElementType = isValidElementType;
1461
+ reactIs_development.typeOf = typeOf;
1462
+ })();
1463
+ }
1464
+ return reactIs_development;
1465
+ }
1466
+ (function (module) {
1467
+ if (process.env.NODE_ENV === 'production') {
1468
+ module.exports = requireReactIs_production_min();
1469
+ } else {
1470
+ module.exports = requireReactIs_development();
1471
+ }
1472
+ })(reactIs);
1473
+ function focusRingBorderStyle(border) {
1474
+ return "inset 0 0 0 ".concat(border.width, "px ").concat(border.color);
1475
+ }
1476
+ function focusRingStyle(opts) {
1477
+ const {
1478
+ base,
1479
+ border,
1480
+ focusRing
1481
+ } = opts;
1482
+ const focusRingOutsetWidth = focusRing.offset + focusRing.width;
1483
+ const focusRingInsetWidth = 0 - focusRing.offset;
1484
+ const bgColor = base ? base.bg : "var(--card-bg-color)";
1485
+ 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(",");
1486
+ }
1487
+ const FileButton = styled(MenuItem)(_ref13 => {
1488
+ let {
1489
+ theme
1490
+ } = _ref13;
1491
+ const {
1492
+ focusRing
1493
+ } = theme.sanity;
1494
+ const base = theme.sanity.color.base;
1495
+ const border = {
1496
+ width: 1,
1497
+ color: "var(--card-border-color)"
1498
+ };
1499
+ return css(_templateObject8 || (_templateObject8 = _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({
1500
+ base,
1501
+ border,
1502
+ focusRing
1503
+ }));
1504
+ });
1505
+ const FileInputMenuItem = React.forwardRef(function FileInputMenuItem2(props, forwardedRef) {
1506
+ const {
1507
+ icon,
1508
+ id: idProp,
1509
+ accept,
1510
+ capture,
1511
+ fontSize,
1512
+ multiple,
1513
+ onSelect,
1514
+ padding = 3,
1515
+ space = 3,
1516
+ textAlign,
1517
+ text,
1518
+ disabled,
1519
+ ...rest
1520
+ } = props;
1521
+ const idHook = useId();
1522
+ const id = idProp || idHook;
1523
+ const handleChange = React.useCallback(event => {
1524
+ if (onSelect && event.target.files) {
1525
+ onSelect(Array.from(event.target.files));
1526
+ }
1527
+ }, [onSelect]);
1528
+ const content = /* @__PURE__ */jsxs(Flex, {
1529
+ align: "center",
1530
+ justify: "flex-start",
1531
+ padding,
1532
+ children: [icon && /* @__PURE__ */jsx(Box, {
1533
+ marginRight: text ? space : void 0,
1534
+ children: /* @__PURE__ */jsxs(Text, {
1535
+ size: fontSize,
1536
+ children: [isValidElement(icon) && icon, reactIsExports.isValidElementType(icon) && createElement(icon)]
1537
+ })
1538
+ }), text && /* @__PURE__ */jsx(Text, {
1539
+ align: textAlign,
1540
+ size: fontSize,
1541
+ textOverflow: "ellipsis",
1542
+ children: text
1543
+ })]
1544
+ });
1545
+ return /* @__PURE__ */jsxs(FileButton, {
1546
+ ...rest,
1547
+ htmlFor: id,
1548
+ padding: 0,
1549
+ fontSize: 2,
1550
+ disabled,
1551
+ ref: forwardedRef,
1552
+ children: [content, /* @__PURE__ */jsx("input", {
1553
+ "data-testid": "file-button-input",
1554
+ accept,
1555
+ capture,
1556
+ id,
1557
+ multiple,
1558
+ onChange: handleChange,
1559
+ type: "file",
1560
+ value: "",
1561
+ disabled
1562
+ })]
1563
+ });
1564
+ });
1565
+ const LockCard = styled(Card)(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n left: 0;\n opacity: 0.6;\n mix-blend-mode: screen;\n background: transparent;\n"])));
1566
+ const LockButton = styled(Button)(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n background: transparent;\n color: white;\n"])));
1567
+ function PlayerActionsMenu(props) {
1568
+ const {
1569
+ asset,
1570
+ readOnly,
1571
+ dialogState,
1572
+ setDialogState,
1573
+ onChange,
1574
+ onUpload
1575
+ } = props;
1576
+ const [open, setOpen] = useState(false);
1577
+ const [menuElement, setMenuRef] = useState(null);
1578
+ const isSigned = useMemo(() => getPlaybackPolicy(asset) === "signed", [asset]);
1579
+ const onReset = useCallback(() => onChange(PatchEvent.from(unset([]))), [onChange]);
1580
+ useEffect(() => {
1581
+ if (open && dialogState) {
1582
+ setOpen(false);
1583
+ }
1584
+ }, [dialogState, open]);
1585
+ useClickOutside(useCallback(() => setOpen(false), []), [menuElement]);
1586
+ return /* @__PURE__ */jsxs(Inline, {
1587
+ space: 1,
1588
+ padding: 2,
1589
+ children: [isSigned && /* @__PURE__ */jsx(Tooltip, {
1590
+ content: /* @__PURE__ */jsx(Box, {
1591
+ padding: 2,
1592
+ children: /* @__PURE__ */jsx(Text, {
1593
+ muted: true,
1594
+ size: 1,
1595
+ children: "Signed playback policy"
1596
+ })
1597
+ }),
1598
+ placement: "right",
1599
+ portal: true,
1600
+ children: /* @__PURE__ */jsx(LockCard, {
1601
+ radius: 2,
1602
+ margin: 2,
1603
+ scheme: "dark",
1604
+ tone: "positive",
1605
+ children: /* @__PURE__ */jsx(LockButton, {
1606
+ icon: LockIcon,
1607
+ mode: "bleed",
1608
+ tone: "positive"
1609
+ })
1610
+ })
1611
+ }), !readOnly && /* @__PURE__ */jsx(Button, {
1612
+ icon: EditIcon,
1613
+ mode: "ghost",
1614
+ onClick: () => setDialogState("edit-thumbnail")
1615
+ }), /* @__PURE__ */jsx(Popover, {
1616
+ content: /* @__PURE__ */jsxs(Menu, {
1617
+ ref: setMenuRef,
1618
+ children: [/* @__PURE__ */jsx(Box, {
1619
+ padding: 2,
1620
+ children: /* @__PURE__ */jsx(Label$1, {
1621
+ muted: true,
1622
+ size: 1,
1623
+ children: "Replace"
1624
+ })
1625
+ }), /* @__PURE__ */jsx(FileInputMenuItem, {
1626
+ accept: "video/*",
1627
+ icon: UploadIcon,
1628
+ mode: "bleed",
1629
+ onSelect: onUpload,
1630
+ text: "Upload",
1631
+ disabled: readOnly,
1632
+ fontSize: 2
1633
+ }), /* @__PURE__ */jsx(MenuItem, {
1634
+ icon: SearchIcon,
1635
+ text: "Browse",
1636
+ onClick: () => setDialogState("select-video")
1637
+ }), /* @__PURE__ */jsx(MenuDivider, {}), /* @__PURE__ */jsx(MenuItem, {
1638
+ icon: PlugIcon,
1639
+ text: "Configure API",
1640
+ onClick: () => setDialogState("secrets")
1641
+ }), /* @__PURE__ */jsx(MenuDivider, {}), /* @__PURE__ */jsx(MenuItem, {
1642
+ tone: "critical",
1643
+ icon: ResetIcon,
1644
+ text: "Clear field",
1645
+ onClick: onReset,
1646
+ disabled: readOnly
1647
+ })]
1648
+ }),
1649
+ portal: true,
1650
+ open,
1651
+ children: /* @__PURE__ */jsx(Button, {
1652
+ icon: EllipsisVerticalIcon,
1653
+ mode: "ghost",
1654
+ onClick: () => {
1655
+ setDialogState(false);
1656
+ setOpen(true);
1657
+ }
1658
+ })
1659
+ })]
1660
+ });
1661
+ }
1662
+ var PlayerActionsMenu$1 = memo(PlayerActionsMenu);
1663
+ function withFocusRing(component) {
1664
+ return styled(component)(props => {
1665
+ const border = {
1666
+ width: props.$border ? 1 : 0,
1667
+ color: "var(--card-border-color)"
1668
+ };
1669
+ return css(_templateObject11 || (_templateObject11 = _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({
1670
+ base: props.theme.sanity.color.base,
1671
+ border,
1672
+ focusRing: props.theme.sanity.focusRing
1673
+ }));
1674
+ });
1675
+ }
1676
+ const ctrlKey = 17;
1677
+ const cmdKey = 91;
1678
+ const UploadCardWithFocusRing = withFocusRing(Card);
1679
+ const UploadCard$1 = forwardRef((_ref14, forwardedRef) => {
1680
+ let {
1681
+ children,
1682
+ tone,
1683
+ onPaste,
1684
+ onDrop,
1685
+ onDragEnter,
1686
+ onDragLeave,
1687
+ onDragOver
1688
+ } = _ref14;
1689
+ const ctrlDown = useRef(false);
1690
+ const inputRef = useRef(null);
1691
+ const handleKeyDown = useCallback(event => {
1692
+ if (event.keyCode == ctrlKey || event.keyCode == cmdKey) {
1693
+ ctrlDown.current = true;
1694
+ }
1695
+ const vKey = 86;
1696
+ if (ctrlDown.current && event.keyCode == vKey) {
1697
+ inputRef.current.focus();
1698
+ }
1699
+ }, []);
1700
+ const handleKeyUp = useCallback(event => {
1701
+ if (event.keyCode == ctrlKey || event.keyCode == cmdKey) {
1702
+ ctrlDown.current = false;
1703
+ }
1704
+ }, []);
1705
+ return /* @__PURE__ */jsxs(UploadCardWithFocusRing, {
1706
+ tone,
1707
+ height: "fill",
1708
+ ref: forwardedRef,
1709
+ padding: 0,
1710
+ radius: 2,
1711
+ shadow: 0,
1712
+ tabIndex: 0,
1713
+ onKeyDown: handleKeyDown,
1714
+ onKeyUp: handleKeyUp,
1715
+ onPaste,
1716
+ onDrop,
1717
+ onDragEnter,
1718
+ onDragLeave,
1719
+ onDragOver,
1720
+ children: [/* @__PURE__ */jsx(HiddenInput$1, {
1721
+ ref: inputRef,
1722
+ onPaste
1723
+ }), children]
1724
+ });
1725
+ });
1726
+ const HiddenInput$1 = styled.input.attrs({
1727
+ type: "text"
1728
+ })(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n position: absolute;\n border: 0;\n color: white;\n opacity: 0;\n\n &:focus {\n outline: none;\n }\n"])));
1729
+ const HiddenInput = styled.input(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n overflow: hidden;\n width: 0.1px;\n height: 0.1px;\n opacity: 0;\n position: absolute;\n z-index: -1;\n"])));
1730
+ const Label = styled.label(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: relative;\n"])));
1731
+ const FileInputButton = _ref15 => {
1732
+ let {
1733
+ onSelect,
1734
+ ...props
1735
+ } = _ref15;
1736
+ const inputId = "FileSelect".concat(useId());
1737
+ const inputRef = useRef(null);
1738
+ const handleSelect = useCallback(event => {
1739
+ if (onSelect) {
1740
+ onSelect(event.target.files);
1741
+ }
1742
+ }, [onSelect]);
1743
+ const handleButtonClick = useCallback(() => {
1744
+ var _a;
1745
+ return (_a = inputRef.current) == null ? void 0 : _a.click();
1746
+ }, []);
1747
+ return /* @__PURE__ */jsxs(Label, {
1748
+ htmlFor: inputId,
1749
+ children: [/* @__PURE__ */jsx(HiddenInput, {
1750
+ accept: "video/*",
1751
+ ref: inputRef,
1752
+ tabIndex: 0,
1753
+ type: "file",
1754
+ id: inputId,
1755
+ onChange: handleSelect,
1756
+ value: ""
1757
+ }), /* @__PURE__ */jsx(Button, {
1758
+ onClick: handleButtonClick,
1759
+ mode: "default",
1760
+ tone: "primary",
1761
+ style: {
1762
+ width: "100%"
1763
+ },
1764
+ ...props
1765
+ })]
1766
+ });
1767
+ };
1768
+ const UploadCard = styled(Card)(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n && {\n border-style: dashed;\n }\n"])));
1769
+ const ConfigureApiBox = styled(Box)(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n right: 0;\n"])));
1770
+ function UploadPlaceholder(props) {
1771
+ const {
1772
+ setDialogState,
1773
+ readOnly,
1774
+ onSelect,
1775
+ hovering,
1776
+ needsSetup
1777
+ } = props;
1778
+ const handleBrowse = useCallback(() => setDialogState("select-video"), [setDialogState]);
1779
+ const handleConfigureApi = useCallback(() => setDialogState("secrets"), [setDialogState]);
1780
+ return /* @__PURE__ */jsx(Box, {
1781
+ style: {
1782
+ padding: 1,
1783
+ position: "relative"
1784
+ },
1785
+ height: "stretch",
1786
+ children: /* @__PURE__ */jsxs(UploadCard, {
1787
+ sizing: "border",
1788
+ height: "fill",
1789
+ tone: readOnly ? "transparent" : "inherit",
1790
+ border: true,
1791
+ padding: 3,
1792
+ style: hovering ? {
1793
+ borderColor: "transparent"
1794
+ } : void 0,
1795
+ children: [/* @__PURE__ */jsx(ConfigureApiBox, {
1796
+ padding: 3,
1797
+ children: /* @__PURE__ */jsx(Button, {
1798
+ padding: 3,
1799
+ radius: 3,
1800
+ tone: needsSetup ? "critical" : void 0,
1801
+ onClick: handleConfigureApi,
1802
+ icon: PlugIcon,
1803
+ mode: "bleed"
1804
+ })
1805
+ }), /* @__PURE__ */jsxs(Flex, {
1806
+ align: "center",
1807
+ justify: "space-between",
1808
+ gap: 4,
1809
+ direction: ["column", "column", "row"],
1810
+ paddingY: [2, 2, 0],
1811
+ sizing: "border",
1812
+ height: "fill",
1813
+ children: [/* @__PURE__ */jsxs(Flex, {
1814
+ align: "center",
1815
+ justify: "center",
1816
+ gap: 2,
1817
+ flex: 1,
1818
+ children: [/* @__PURE__ */jsx(Flex, {
1819
+ justify: "center",
1820
+ children: /* @__PURE__ */jsx(Text, {
1821
+ muted: true,
1822
+ children: /* @__PURE__ */jsx(DocumentVideoIcon, {})
1823
+ })
1824
+ }), /* @__PURE__ */jsx(Flex, {
1825
+ justify: "center",
1826
+ children: /* @__PURE__ */jsx(Text, {
1827
+ size: 1,
1828
+ muted: true,
1829
+ children: "Drag video or paste URL here"
1830
+ })
1831
+ })]
1832
+ }), /* @__PURE__ */jsxs(Inline, {
1833
+ space: 2,
1834
+ children: [/* @__PURE__ */jsx(FileInputButton, {
1835
+ mode: "ghost",
1836
+ tone: "default",
1837
+ icon: UploadIcon,
1838
+ text: "Upload",
1839
+ onSelect
1840
+ }), /* @__PURE__ */jsx(Button, {
1841
+ mode: "ghost",
1842
+ icon: SearchIcon,
1843
+ text: "Select",
1844
+ onClick: handleBrowse
1845
+ })]
1846
+ })]
1847
+ })]
1848
+ })
1849
+ });
1850
+ }
1851
+ const CardWrapper = styled(Card)(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n min-height: 82px;\n box-sizing: border-box;\n"])));
1852
+ const FlexWrapper = styled(Flex)(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n text-overflow: ellipsis;\n overflow: hidden;\n"])));
1853
+ const LeftSection = styled(Stack)(_templateObject19 || (_templateObject19 = _taggedTemplateLiteral(["\n position: relative;\n width: 60%;\n"])));
1854
+ const CodeWrapper = styled(Code)(_templateObject20 || (_templateObject20 = _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"])));
1855
+ const UploadProgress = _ref16 => {
1856
+ let {
1857
+ progress = 100,
1858
+ onCancel,
1859
+ filename,
1860
+ text = "Uploading"
1861
+ } = _ref16;
1862
+ return /* @__PURE__ */jsx(CardWrapper, {
1863
+ tone: "primary",
1864
+ padding: 4,
1865
+ border: true,
1866
+ height: "fill",
1867
+ children: /* @__PURE__ */jsxs(FlexWrapper, {
1868
+ align: "center",
1869
+ justify: "space-between",
1870
+ height: "fill",
1871
+ direction: "row",
1872
+ gap: 2,
1873
+ children: [/* @__PURE__ */jsxs(LeftSection, {
1874
+ children: [/* @__PURE__ */jsx(Flex, {
1875
+ justify: "center",
1876
+ gap: [3, 3, 2, 2],
1877
+ direction: ["column", "column", "row"],
1878
+ children: /* @__PURE__ */jsx(Text, {
1879
+ size: 1,
1880
+ children: /* @__PURE__ */jsxs(Inline, {
1881
+ space: 2,
1882
+ children: [text, /* @__PURE__ */jsx(CodeWrapper, {
1883
+ size: 1,
1884
+ children: filename ? filename : "..."
1885
+ })]
1886
+ })
1887
+ })
1888
+ }), /* @__PURE__ */jsx(Card, {
1889
+ marginTop: 3,
1890
+ radius: 5,
1891
+ shadow: 1,
1892
+ children: /* @__PURE__ */jsx(LinearProgress, {
1893
+ value: progress
1894
+ })
1895
+ })]
1896
+ }), onCancel ? /* @__PURE__ */jsx(Button, {
1897
+ fontSize: 2,
1898
+ text: "Cancel upload",
1899
+ mode: "ghost",
1900
+ tone: "critical",
1901
+ onClick: onCancel
1902
+ }) : null]
1903
+ })
1904
+ });
1905
+ };
1906
+ const Player = lazy(() => import('./Player-fb9712c0.js'));
1907
+ class MuxVideoInputUploader extends Component {
1908
+ constructor() {
1909
+ super(...arguments);
1910
+ this.state = {
1911
+ isDraggingOver: false,
1912
+ invalidPaste: false,
1913
+ invalidFile: false,
1914
+ uploadProgress: null,
1915
+ fileInfo: null,
1916
+ uuid: null,
1917
+ error: null,
1918
+ url: null
1919
+ };
1920
+ this.dragEnteredEls = [];
1921
+ this.ctrlDown = false;
1922
+ // eslint-disable-next-line no-warning-comments
1923
+ // @TODO add proper typings for the return values of uploadFile and uploadUrl
1924
+ this.upload = null;
1925
+ this.container = React.createRef();
1926
+ this.handleProgress = evt => {
1927
+ this.setState({
1928
+ uploadProgress: evt.percent
1929
+ });
1930
+ };
1931
+ this.onUpload = files => {
1932
+ this.setState({
1933
+ uploadProgress: 0,
1934
+ fileInfo: null,
1935
+ uuid: null
1936
+ });
1937
+ this.upload = uploadFile(this.props.config, this.props.client, files[0], {
1938
+ enableSignedUrls: this.props.secrets.enableSignedUrls
1939
+ }).pipe(takeUntil(this.onCancelUploadButtonClick$.pipe(tap(() => {
1940
+ if (this.state.uuid) {
1941
+ this.props.client.delete(this.state.uuid);
1942
+ }
1943
+ })))).subscribe({
1944
+ complete: () => {
1945
+ this.setState({
1946
+ error: null,
1947
+ uploadProgress: null,
1948
+ uuid: null
1949
+ });
1950
+ },
1951
+ next: event => {
1952
+ this.handleUploadEvent(event);
1953
+ },
1954
+ error: err => {
1955
+ this.setState({
1956
+ error: err,
1957
+ uploadProgress: null,
1958
+ uuid: null
1959
+ });
1960
+ }
1961
+ });
1962
+ };
1963
+ // eslint-disable-next-line no-warning-comments
1964
+ // @TODO add proper typings for the Observable events
1965
+ this.handleUploadEvent = event => {
1966
+ switch (event.type) {
1967
+ case "success":
1968
+ return this.handleUploadSuccess(event.asset);
1969
+ case "progress":
1970
+ return this.handleProgress(event);
1971
+ case "file":
1972
+ return this.setState({
1973
+ fileInfo: event.file
1974
+ });
1975
+ case "uuid":
1976
+ return this.setState({
1977
+ uuid: event.uuid
1978
+ });
1979
+ case "url":
1980
+ return this.setState({
1981
+ url: event.url,
1982
+ uploadProgress: 100
1983
+ });
1984
+ default:
1985
+ return null;
1986
+ }
1987
+ };
1988
+ this.handleUploadSuccess = asset => {
1989
+ this.setState({
1990
+ uploadProgress: 100
1991
+ });
1992
+ this.props.onChange(PatchEvent.from([setIfMissing({
1993
+ asset: {}
1994
+ }), set({
1995
+ _type: "reference",
1996
+ _weak: true,
1997
+ _ref: asset._id
1998
+ }, ["asset"])]));
1999
+ };
2000
+ this.handlePaste = event => {
2001
+ const clipboardData = event.clipboardData || window.clipboardData;
2002
+ const url = clipboardData.getData("text");
2003
+ const options = {
2004
+ enableSignedUrls: this.props.secrets.enableSignedUrls
2005
+ };
2006
+ this.upload = uploadUrl(this.props.config, this.props.client, url, options).subscribe({
2007
+ complete: () => {
2008
+ this.setState({
2009
+ error: null,
2010
+ uploadProgress: null,
2011
+ url: null
2012
+ });
2013
+ },
2014
+ next: sEvent => {
2015
+ this.handleUploadEvent(sEvent);
2016
+ },
2017
+ error: err => {
2018
+ let error;
2019
+ if (!err.message.toLowerCase().match("invalid url")) {
2020
+ error = err;
2021
+ }
2022
+ this.setState({
2023
+ invalidPaste: true,
2024
+ error
2025
+ }, () => {
2026
+ setTimeout(() => {
2027
+ this.setState({
2028
+ invalidPaste: false,
2029
+ uploadProgress: null
2030
+ });
2031
+ }, 2e3);
2032
+ });
2033
+ }
2034
+ });
2035
+ };
2036
+ this.handleDrop = event => {
2037
+ this.setState({
2038
+ isDraggingOver: false
2039
+ });
2040
+ event.preventDefault();
2041
+ event.stopPropagation();
2042
+ extractDroppedFiles(event.nativeEvent.dataTransfer).then(files => {
2043
+ if (files) {
2044
+ this.onUpload(files);
2045
+ }
2046
+ });
2047
+ };
2048
+ this.handleDragOver = event => {
2049
+ event.preventDefault();
2050
+ event.stopPropagation();
2051
+ };
2052
+ this.handleDragEnter = event => {
2053
+ var _a, _b;
2054
+ event.stopPropagation();
2055
+ this.dragEnteredEls.push(event.target);
2056
+ this.setState({
2057
+ isDraggingOver: true
2058
+ });
2059
+ const type = (_b = (_a = event.dataTransfer.items) == null ? void 0 : _a[0]) == null ? void 0 : _b.type;
2060
+ this.setState({
2061
+ invalidFile: !type.startsWith("video/")
2062
+ });
2063
+ };
2064
+ this.handleDragLeave = event => {
2065
+ event.stopPropagation();
2066
+ const idx = this.dragEnteredEls.indexOf(event.target);
2067
+ if (idx > -1) {
2068
+ this.dragEnteredEls.splice(idx, 1);
2069
+ }
2070
+ if (this.dragEnteredEls.length === 0) {
2071
+ this.setState({
2072
+ isDraggingOver: false
2073
+ });
2074
+ }
2075
+ };
2076
+ }
2077
+ componentWillUnmount() {
2078
+ this.unSubscribeToUpload();
2079
+ }
2080
+ componentDidMount() {
2081
+ const events$ = new Subject();
2082
+ this.onCancelUploadButtonClick$ = events$.asObservable();
2083
+ this.handleCancelUploadButtonClick = event => events$.next(event);
2084
+ }
2085
+ unSubscribeToUpload() {
2086
+ if (this.upload && !this.upload.closed) {
2087
+ this.upload.unsubscribe();
2088
+ }
2089
+ }
2090
+ render() {
2091
+ var _a;
2092
+ if (this.state.uploadProgress !== null) {
2093
+ return /* @__PURE__ */jsx(UploadProgress, {
2094
+ onCancel: this.handleCancelUploadButtonClick,
2095
+ progress: this.state.uploadProgress,
2096
+ filename: ((_a = this.state.fileInfo) == null ? void 0 : _a.name) || this.state.url
2097
+ });
2098
+ }
2099
+ if (this.state.error) {
2100
+ throw this.state.error;
2101
+ }
2102
+ return /* @__PURE__ */jsxs(Fragment, {
2103
+ children: [/* @__PURE__ */jsx(UploadCard$1, {
2104
+ tone: this.state.isDraggingOver && (this.state.invalidPaste || this.state.invalidFile) ? "critical" : this.state.isDraggingOver ? "positive" : void 0,
2105
+ onDrop: this.handleDrop,
2106
+ onDragOver: this.handleDragOver,
2107
+ onDragLeave: this.handleDragLeave,
2108
+ onDragEnter: this.handleDragEnter,
2109
+ onPaste: this.handlePaste,
2110
+ ref: this.container,
2111
+ children: this.props.asset ? /* @__PURE__ */jsx(Player, {
2112
+ readOnly: this.props.readOnly,
2113
+ asset: this.props.asset,
2114
+ onChange: this.props.onChange,
2115
+ dialogState: this.props.dialogState,
2116
+ setDialogState: this.props.setDialogState,
2117
+ buttons: /* @__PURE__ */jsx(PlayerActionsMenu$1, {
2118
+ asset: this.props.asset,
2119
+ dialogState: this.props.dialogState,
2120
+ setDialogState: this.props.setDialogState,
2121
+ onChange: this.props.onChange,
2122
+ onUpload: this.onUpload,
2123
+ readOnly: this.props.readOnly
2124
+ })
2125
+ }) : /* @__PURE__ */jsx(UploadPlaceholder, {
2126
+ hovering: this.state.isDraggingOver,
2127
+ onSelect: this.onUpload,
2128
+ readOnly: this.props.readOnly,
2129
+ setDialogState: this.props.setDialogState,
2130
+ needsSetup: this.props.needsSetup
2131
+ })
2132
+ }), this.props.dialogState === "select-video" && /* @__PURE__ */jsx(InputBrowser, {
2133
+ asset: this.props.asset,
2134
+ onChange: this.props.onChange,
2135
+ setDialogState: this.props.setDialogState
2136
+ })]
2137
+ });
2138
+ }
2139
+ }
2140
+ const useSaveSecrets = (client, secrets) => {
2141
+ return useCallback(async _ref17 => {
2142
+ let {
2143
+ token,
2144
+ secretKey,
2145
+ enableSignedUrls
2146
+ } = _ref17;
2147
+ let {
2148
+ signingKeyId,
2149
+ signingKeyPrivate
2150
+ } = secrets;
2151
+ try {
2152
+ await saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate);
2153
+ const valid = await testSecrets(client);
2154
+ if (!(valid == null ? void 0 : valid.status) && token && secretKey) {
2155
+ throw new Error("Invalid secrets");
2156
+ }
2157
+ } catch (err) {
2158
+ console.error("Error while trying to save secrets:", err);
2159
+ throw err;
2160
+ }
2161
+ if (enableSignedUrls) {
2162
+ const hasValidSigningKeys = await haveValidSigningKeys(client, signingKeyId, signingKeyPrivate);
2163
+ if (!hasValidSigningKeys) {
2164
+ try {
2165
+ const {
2166
+ data
2167
+ } = await createSigningKeys(client);
2168
+ signingKeyId = data.id;
2169
+ signingKeyPrivate = data.private_key;
2170
+ await saveSecrets(client, token, secretKey, enableSignedUrls, signingKeyId, signingKeyPrivate);
2171
+ } catch (err) {
2172
+ console.log("Error while creating and saving signing key:", err == null ? void 0 : err.message);
2173
+ throw err;
2174
+ }
2175
+ }
2176
+ }
2177
+ return {
2178
+ token,
2179
+ secretKey,
2180
+ enableSignedUrls,
2181
+ signingKeyId,
2182
+ signingKeyPrivate
2183
+ };
2184
+ }, [client, secrets]);
2185
+ };
2186
+ function init(_ref18) {
2187
+ let {
2188
+ token,
2189
+ secretKey,
2190
+ enableSignedUrls
2191
+ } = _ref18;
2192
+ return {
2193
+ submitting: false,
2194
+ error: null,
2195
+ // Form inputs don't set the state back to null when clearing a field, but uses empty strings
2196
+ // This ensures the `dirty` check works correctly
2197
+ token: token != null ? token : "",
2198
+ secretKey: secretKey != null ? secretKey : "",
2199
+ enableSignedUrls: enableSignedUrls != null ? enableSignedUrls : false
2200
+ };
2201
+ }
2202
+ function reducer(state, action) {
2203
+ switch (action == null ? void 0 : action.type) {
2204
+ case "submit":
2205
+ return {
2206
+ ...state,
2207
+ submitting: true,
2208
+ error: null
2209
+ };
2210
+ case "error":
2211
+ return {
2212
+ ...state,
2213
+ submitting: false,
2214
+ error: action.payload
2215
+ };
2216
+ case "reset":
2217
+ return init(action.payload);
2218
+ case "change":
2219
+ return {
2220
+ ...state,
2221
+ [action.payload.name]: action.payload.value
2222
+ };
2223
+ default:
2224
+ throw new Error("Unknown action type: ".concat(action == null ? void 0 : action.type));
2225
+ }
2226
+ }
2227
+ const useSecretsFormState = secrets => useReducer(reducer, secrets, init);
2228
+ const ids = ["title", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"];
2229
+ function MuxLogo(_ref19) {
2230
+ let {
2231
+ height = 26
2232
+ } = _ref19;
2233
+ const id = useId();
2234
+ 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]);
2235
+ return /* @__PURE__ */jsxs("svg", {
2236
+ "aria-labelledby": titleId,
2237
+ role: "img",
2238
+ xmlns: "http://www.w3.org/2000/svg",
2239
+ xmlSpace: "preserve",
2240
+ viewBox: "92.08878326416016 102.66712188720703 692.76123046875 219.99948120117188",
2241
+ style: {
2242
+ height: "".concat(height, "px")
2243
+ },
2244
+ children: [/* @__PURE__ */jsx("title", {
2245
+ id: titleId,
2246
+ children: "Mux Logo"
2247
+ }), /* @__PURE__ */jsxs("defs", {
2248
+ children: [/* @__PURE__ */jsxs("linearGradient", {
2249
+ id: c,
2250
+ spreadMethod: "pad",
2251
+ gradientTransform: "matrix(528.38055 0 0 -528.38055 63.801 159.5)",
2252
+ gradientUnits: "userSpaceOnUse",
2253
+ y2: 0,
2254
+ x2: 1,
2255
+ y1: 0,
2256
+ x1: 0,
2257
+ children: [/* @__PURE__ */jsx("stop", {
2258
+ offset: 0,
2259
+ style: {
2260
+ stopOpacity: 1,
2261
+ stopColor: "#ff4e00"
2262
+ }
2263
+ }), /* @__PURE__ */jsx("stop", {
2264
+ offset: 1,
2265
+ style: {
2266
+ stopOpacity: 1,
2267
+ stopColor: "#ff1791"
2268
+ }
2269
+ })]
2270
+ }), /* @__PURE__ */jsxs("linearGradient", {
2271
+ id: d,
2272
+ spreadMethod: "pad",
2273
+ gradientTransform: "matrix(523.66766 0 0 -523.66766 67.897 159.5)",
2274
+ gradientUnits: "userSpaceOnUse",
2275
+ y2: 0,
2276
+ x2: 1,
2277
+ y1: 0,
2278
+ x1: 0,
2279
+ children: [/* @__PURE__ */jsx("stop", {
2280
+ offset: 0,
2281
+ style: {
2282
+ stopOpacity: 1,
2283
+ stopColor: "#ff4e00"
2284
+ }
2285
+ }), /* @__PURE__ */jsx("stop", {
2286
+ offset: 1,
2287
+ style: {
2288
+ stopOpacity: 1,
2289
+ stopColor: "#ff1791"
2290
+ }
2291
+ })]
2292
+ }), /* @__PURE__ */jsxs("linearGradient", {
2293
+ id: g,
2294
+ spreadMethod: "pad",
2295
+ gradientTransform: "rotate(180 296.075 79.75) scale(524.84045)",
2296
+ gradientUnits: "userSpaceOnUse",
2297
+ y2: 0,
2298
+ x2: 1,
2299
+ y1: 0,
2300
+ x1: 0,
2301
+ children: [/* @__PURE__ */jsx("stop", {
2302
+ offset: 0,
2303
+ style: {
2304
+ stopOpacity: 1,
2305
+ stopColor: "#ff4e00"
2306
+ }
2307
+ }), /* @__PURE__ */jsx("stop", {
2308
+ offset: 1,
2309
+ style: {
2310
+ stopOpacity: 1,
2311
+ stopColor: "#ff1791"
2312
+ }
2313
+ })]
2314
+ }), /* @__PURE__ */jsxs("linearGradient", {
2315
+ id: i,
2316
+ spreadMethod: "pad",
2317
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 159.5)",
2318
+ gradientUnits: "userSpaceOnUse",
2319
+ y2: 0,
2320
+ x2: 1,
2321
+ y1: 0,
2322
+ x1: 0,
2323
+ children: [/* @__PURE__ */jsx("stop", {
2324
+ offset: 0,
2325
+ style: {
2326
+ stopOpacity: 1,
2327
+ stopColor: "#ff4e00"
2328
+ }
2329
+ }), /* @__PURE__ */jsx("stop", {
2330
+ offset: 1,
2331
+ style: {
2332
+ stopOpacity: 1,
2333
+ stopColor: "#ff1791"
2334
+ }
2335
+ })]
2336
+ }), /* @__PURE__ */jsxs("linearGradient", {
2337
+ id: j,
2338
+ spreadMethod: "pad",
2339
+ gradientTransform: "matrix(523.08514 0 0 -523.08514 67.897 224.446)",
2340
+ gradientUnits: "userSpaceOnUse",
2341
+ y2: 0,
2342
+ x2: 1,
2343
+ y1: 0,
2344
+ x1: 0,
2345
+ children: [/* @__PURE__ */jsx("stop", {
2346
+ offset: 0,
2347
+ style: {
2348
+ stopOpacity: 1,
2349
+ stopColor: "#ff4e00"
2350
+ }
2351
+ }), /* @__PURE__ */jsx("stop", {
2352
+ offset: 1,
2353
+ style: {
2354
+ stopOpacity: 1,
2355
+ stopColor: "#ff1791"
2356
+ }
2357
+ })]
2358
+ }), /* @__PURE__ */jsxs("linearGradient", {
2359
+ id: k,
2360
+ spreadMethod: "pad",
2361
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 94.553)",
2362
+ gradientUnits: "userSpaceOnUse",
2363
+ y2: 0,
2364
+ x2: 1,
2365
+ y1: 0,
2366
+ x1: 0,
2367
+ children: [/* @__PURE__ */jsx("stop", {
2368
+ offset: 0,
2369
+ style: {
2370
+ stopOpacity: 1,
2371
+ stopColor: "#ff4e00"
2372
+ }
2373
+ }), /* @__PURE__ */jsx("stop", {
2374
+ offset: 1,
2375
+ style: {
2376
+ stopOpacity: 1,
2377
+ stopColor: "#ff1791"
2378
+ }
2379
+ })]
2380
+ }), /* @__PURE__ */jsxs("linearGradient", {
2381
+ id: l,
2382
+ spreadMethod: "pad",
2383
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 159.5)",
2384
+ gradientUnits: "userSpaceOnUse",
2385
+ y2: 0,
2386
+ x2: 1,
2387
+ y1: 0,
2388
+ x1: 0,
2389
+ children: [/* @__PURE__ */jsx("stop", {
2390
+ offset: 0,
2391
+ style: {
2392
+ stopOpacity: 1,
2393
+ stopColor: "#ff4e00"
2394
+ }
2395
+ }), /* @__PURE__ */jsx("stop", {
2396
+ offset: 1,
2397
+ style: {
2398
+ stopOpacity: 1,
2399
+ stopColor: "#ff1791"
2400
+ }
2401
+ })]
2402
+ }), /* @__PURE__ */jsxs("linearGradient", {
2403
+ id: m,
2404
+ spreadMethod: "pad",
2405
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 94.554)",
2406
+ gradientUnits: "userSpaceOnUse",
2407
+ y2: 0,
2408
+ x2: 1,
2409
+ y1: 0,
2410
+ x1: 0,
2411
+ children: [/* @__PURE__ */jsx("stop", {
2412
+ offset: 0,
2413
+ style: {
2414
+ stopOpacity: 1,
2415
+ stopColor: "#ff4e00"
2416
+ }
2417
+ }), /* @__PURE__ */jsx("stop", {
2418
+ offset: 1,
2419
+ style: {
2420
+ stopOpacity: 1,
2421
+ stopColor: "#ff1791"
2422
+ }
2423
+ })]
2424
+ }), /* @__PURE__ */jsxs("linearGradient", {
2425
+ id: p,
2426
+ spreadMethod: "pad",
2427
+ gradientTransform: "matrix(521.97632 0 0 -521.97632 69.067 191.973)",
2428
+ gradientUnits: "userSpaceOnUse",
2429
+ y2: 0,
2430
+ x2: 1,
2431
+ y1: 0,
2432
+ x1: 0,
2433
+ children: [/* @__PURE__ */jsx("stop", {
2434
+ offset: 0,
2435
+ style: {
2436
+ stopOpacity: 1,
2437
+ stopColor: "#ff4e00"
2438
+ }
2439
+ }), /* @__PURE__ */jsx("stop", {
2440
+ offset: 1,
2441
+ style: {
2442
+ stopOpacity: 1,
2443
+ stopColor: "#ff1791"
2444
+ }
2445
+ })]
2446
+ }), /* @__PURE__ */jsxs("linearGradient", {
2447
+ id: q,
2448
+ spreadMethod: "pad",
2449
+ gradientTransform: "matrix(523.09039 0 0 -523.09039 67.312 191.973)",
2450
+ gradientUnits: "userSpaceOnUse",
2451
+ y2: 0,
2452
+ x2: 1,
2453
+ y1: 0,
2454
+ x1: 0,
2455
+ children: [/* @__PURE__ */jsx("stop", {
2456
+ offset: 0,
2457
+ style: {
2458
+ stopOpacity: 1,
2459
+ stopColor: "#ff4e00"
2460
+ }
2461
+ }), /* @__PURE__ */jsx("stop", {
2462
+ offset: 1,
2463
+ style: {
2464
+ stopOpacity: 1,
2465
+ stopColor: "#ff1791"
2466
+ }
2467
+ })]
2468
+ }), /* @__PURE__ */jsxs("linearGradient", {
2469
+ id: r,
2470
+ spreadMethod: "pad",
2471
+ gradientTransform: "matrix(524.84045 0 0 -524.84045 63.801 159.5)",
2472
+ gradientUnits: "userSpaceOnUse",
2473
+ y2: 0,
2474
+ x2: 1,
2475
+ y1: 0,
2476
+ x1: 0,
2477
+ children: [/* @__PURE__ */jsx("stop", {
2478
+ offset: 0,
2479
+ style: {
2480
+ stopOpacity: 1,
2481
+ stopColor: "#ff4e00"
2482
+ }
2483
+ }), /* @__PURE__ */jsx("stop", {
2484
+ offset: 1,
2485
+ style: {
2486
+ stopOpacity: 1,
2487
+ stopColor: "#ff1791"
2488
+ }
2489
+ })]
2490
+ }), /* @__PURE__ */jsx("clipPath", {
2491
+ id: a,
2492
+ clipPathUnits: "userSpaceOnUse",
2493
+ children: /* @__PURE__ */jsx("path", {
2494
+ d: "M0 319h657.706V0H0Z"
2495
+ })
2496
+ }), /* @__PURE__ */jsx("clipPath", {
2497
+ id: b,
2498
+ clipPathUnits: "userSpaceOnUse",
2499
+ children: /* @__PURE__ */jsx("path", {
2500
+ d: "M423.64 242h164.999V77H423.64Z"
2501
+ })
2502
+ }), /* @__PURE__ */jsx("clipPath", {
2503
+ id: e,
2504
+ clipPathUnits: "userSpaceOnUse",
2505
+ children: /* @__PURE__ */jsx("path", {
2506
+ d: "M0 319h657.706V0H0Z"
2507
+ })
2508
+ }), /* @__PURE__ */jsx("clipPath", {
2509
+ id: f,
2510
+ clipPathUnits: "userSpaceOnUse",
2511
+ children: /* @__PURE__ */jsx("path", {
2512
+ d: "M311.3 242h93.031V77H311.3Z"
2513
+ })
2514
+ }), /* @__PURE__ */jsx("clipPath", {
2515
+ id: h,
2516
+ clipPathUnits: "userSpaceOnUse",
2517
+ children: /* @__PURE__ */jsx("path", {
2518
+ d: "M198.96 242h35.106V77H198.96Z"
2519
+ })
2520
+ }), /* @__PURE__ */jsx("clipPath", {
2521
+ id: n,
2522
+ clipPathUnits: "userSpaceOnUse",
2523
+ children: /* @__PURE__ */jsx("path", {
2524
+ d: "M0 319h657.706V0H0Z"
2525
+ })
2526
+ }), /* @__PURE__ */jsx("clipPath", {
2527
+ id: o,
2528
+ clipPathUnits: "userSpaceOnUse",
2529
+ children: /* @__PURE__ */jsx("path", {
2530
+ d: "M69.067 242H169.12V141.947H69.067Z"
2531
+ })
2532
+ })]
2533
+ }), /* @__PURE__ */jsx("g", {
2534
+ clipPath: "url(#".concat(a, ")"),
2535
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)",
2536
+ children: /* @__PURE__ */jsx("g", {
2537
+ style: {
2538
+ opacity: 0.69999701
2539
+ },
2540
+ clipPath: "url(#".concat(b, ")"),
2541
+ children: /* @__PURE__ */jsx("path", {
2542
+ style: {
2543
+ fill: "url(#".concat(c, ")"),
2544
+ stroke: "none"
2545
+ },
2546
+ 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"
2547
+ })
2548
+ })
2549
+ }), /* @__PURE__ */jsx("path", {
2550
+ style: {
2551
+ fill: "url(#".concat(d, ")"),
2552
+ stroke: "none"
2553
+ },
2554
+ 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",
2555
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2556
+ }), /* @__PURE__ */jsxs("g", {
2557
+ clipPath: "url(#".concat(e, ")"),
2558
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)",
2559
+ children: [/* @__PURE__ */jsx("g", {
2560
+ style: {
2561
+ opacity: 0.69999701
2562
+ },
2563
+ clipPath: "url(#".concat(f, ")"),
2564
+ children: /* @__PURE__ */jsx("path", {
2565
+ style: {
2566
+ fill: "url(#".concat(g, ")"),
2567
+ stroke: "none"
2568
+ },
2569
+ 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"
2570
+ })
2571
+ }), /* @__PURE__ */jsx("g", {
2572
+ style: {
2573
+ opacity: 0.69999701
2574
+ },
2575
+ clipPath: "url(#".concat(h, ")"),
2576
+ children: /* @__PURE__ */jsx("path", {
2577
+ style: {
2578
+ fill: "url(#".concat(i, ")"),
2579
+ stroke: "none"
2580
+ },
2581
+ 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"
2582
+ })
2583
+ })]
2584
+ }), /* @__PURE__ */jsx("path", {
2585
+ style: {
2586
+ fill: "url(#".concat(j, ")"),
2587
+ stroke: "none"
2588
+ },
2589
+ 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",
2590
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2591
+ }), /* @__PURE__ */jsx("path", {
2592
+ style: {
2593
+ fill: "url(#".concat(k, ")"),
2594
+ stroke: "none"
2595
+ },
2596
+ 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",
2597
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2598
+ }), /* @__PURE__ */jsx("path", {
2599
+ style: {
2600
+ fill: "url(#".concat(l, ")"),
2601
+ stroke: "none"
2602
+ },
2603
+ 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",
2604
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2605
+ }), /* @__PURE__ */jsx("path", {
2606
+ style: {
2607
+ fill: "url(#".concat(m, ")"),
2608
+ stroke: "none"
2609
+ },
2610
+ 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",
2611
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2612
+ }), /* @__PURE__ */jsx("g", {
2613
+ clipPath: "url(#".concat(n, ")"),
2614
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)",
2615
+ children: /* @__PURE__ */jsx("g", {
2616
+ style: {
2617
+ opacity: 0.69999701
2618
+ },
2619
+ clipPath: "url(#".concat(o, ")"),
2620
+ children: /* @__PURE__ */jsx("path", {
2621
+ style: {
2622
+ fill: "url(#".concat(p, ")"),
2623
+ stroke: "none"
2624
+ },
2625
+ 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"
2626
+ })
2627
+ })
2628
+ }), /* @__PURE__ */jsx("path", {
2629
+ style: {
2630
+ fill: "url(#".concat(q, ")"),
2631
+ stroke: "none"
2632
+ },
2633
+ 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",
2634
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2635
+ }), /* @__PURE__ */jsx("path", {
2636
+ style: {
2637
+ fill: "url(#".concat(r, ")"),
2638
+ stroke: "none"
2639
+ },
2640
+ 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",
2641
+ transform: "matrix(1.33333 0 0 -1.33333 0 425.333)"
2642
+ })]
2643
+ });
2644
+ }
2645
+ const Logo = styled.span(_templateObject21 || (_templateObject21 = _taggedTemplateLiteral(["\n display: inline-block;\n height: 0.8em;\n margin-right: 1em;\n transform: translate(0.3em, -0.2em);\n"])));
2646
+ const Header = () => /* @__PURE__ */jsxs(Fragment, {
2647
+ children: [/* @__PURE__ */jsx(Logo, {
2648
+ children: /* @__PURE__ */jsx(MuxLogo, {
2649
+ height: 13
2650
+ })
2651
+ }), "API Credentials"]
2652
+ });
2653
+ function FormField(props) {
2654
+ const {
2655
+ children,
2656
+ title,
2657
+ description,
2658
+ inputId
2659
+ } = props;
2660
+ return /* @__PURE__ */jsxs(Stack, {
2661
+ space: 1,
2662
+ children: [/* @__PURE__ */jsx(Flex, {
2663
+ align: "flex-end",
2664
+ children: /* @__PURE__ */jsx(Box, {
2665
+ flex: 1,
2666
+ paddingY: 2,
2667
+ children: /* @__PURE__ */jsx(Stack, {
2668
+ space: 2,
2669
+ children: /* @__PURE__ */jsxs(Flex, {
2670
+ children: [/* @__PURE__ */jsx(Text, {
2671
+ as: "label",
2672
+ htmlFor: inputId,
2673
+ weight: "semibold",
2674
+ size: 1,
2675
+ children: title || /* @__PURE__ */jsx("em", {
2676
+ children: "Untitled"
2677
+ })
2678
+ }), description && /* @__PURE__ */jsx(Text, {
2679
+ muted: true,
2680
+ size: 1,
2681
+ children: description
2682
+ })]
2683
+ })
2684
+ })
2685
+ })
2686
+ }), /* @__PURE__ */jsx("div", {
2687
+ children
2688
+ })]
2689
+ });
2690
+ }
2691
+ var FormField$1 = memo(FormField);
2692
+ const fieldNames = ["token", "secretKey", "enableSignedUrls"];
2693
+ function ConfigureApi(_ref20) {
2694
+ let {
2695
+ secrets,
2696
+ setDialogState
2697
+ } = _ref20;
2698
+ var _a, _b;
2699
+ const client = useClient();
2700
+ const [state, dispatch] = useSecretsFormState(secrets);
2701
+ const hasSecretsInitially = useMemo(() => secrets.token && secrets.secretKey, [secrets]);
2702
+ const handleClose = useCallback(() => setDialogState(false), [setDialogState]);
2703
+ const dirty = useMemo(() => secrets.token !== state.token || secrets.secretKey !== state.secretKey || secrets.enableSignedUrls !== state.enableSignedUrls, [secrets, state]);
2704
+ const id = "ConfigureApi".concat(useId());
2705
+ const [tokenId, secretKeyId, enableSignedUrlsId] = useMemo(() => fieldNames.map(field => "".concat(id, "-").concat(field)), [id]);
2706
+ const firstField = useRef(null);
2707
+ const handleSaveSecrets = useSaveSecrets(client, secrets);
2708
+ const saving = useRef(false);
2709
+ const handleSubmit = useCallback(event => {
2710
+ event.preventDefault();
2711
+ if (!saving.current && event.currentTarget.reportValidity()) {
2712
+ saving.current = true;
2713
+ dispatch({
2714
+ type: "submit"
2715
+ });
2716
+ const {
2717
+ token,
2718
+ secretKey,
2719
+ enableSignedUrls
2720
+ } = state;
2721
+ handleSaveSecrets({
2722
+ token,
2723
+ secretKey,
2724
+ enableSignedUrls
2725
+ }).then(savedSecrets => {
2726
+ const {
2727
+ projectId,
2728
+ dataset
2729
+ } = client.config();
2730
+ clear([cacheNs, _id, projectId, dataset]);
2731
+ preload(() => Promise.resolve(savedSecrets), [cacheNs, _id, projectId, dataset]);
2732
+ setDialogState(false);
2733
+ }).catch(err => dispatch({
2734
+ type: "error",
2735
+ payload: err.message
2736
+ })).finally(() => {
2737
+ saving.current = false;
2738
+ });
2739
+ }
2740
+ }, [client, dispatch, handleSaveSecrets, setDialogState, state]);
2741
+ const handleChangeToken = useCallback(event => {
2742
+ dispatch({
2743
+ type: "change",
2744
+ payload: {
2745
+ name: "token",
2746
+ value: event.currentTarget.value
2747
+ }
2748
+ });
2749
+ }, [dispatch]);
2750
+ const handleChangeSecretKey = useCallback(event => {
2751
+ dispatch({
2752
+ type: "change",
2753
+ payload: {
2754
+ name: "secretKey",
2755
+ value: event.currentTarget.value
2756
+ }
2757
+ });
2758
+ }, [dispatch]);
2759
+ const handleChangeEnableSignedUrls = useCallback(event => {
2760
+ dispatch({
2761
+ type: "change",
2762
+ payload: {
2763
+ name: "enableSignedUrls",
2764
+ value: event.currentTarget.checked
2765
+ }
2766
+ });
2767
+ }, [dispatch]);
2768
+ useEffect(() => {
2769
+ if (firstField.current) {
2770
+ firstField.current.focus();
2771
+ }
2772
+ }, [firstField]);
2773
+ return /* @__PURE__ */jsx(Dialog, {
2774
+ id,
2775
+ onClose: handleClose,
2776
+ header: /* @__PURE__ */jsx(Header, {}),
2777
+ width: 0,
2778
+ children: /* @__PURE__ */jsx(Box, {
2779
+ padding: 4,
2780
+ style: {
2781
+ position: "relative"
2782
+ },
2783
+ children: /* @__PURE__ */jsx("form", {
2784
+ onSubmit: handleSubmit,
2785
+ noValidate: true,
2786
+ children: /* @__PURE__ */jsxs(Stack, {
2787
+ space: 4,
2788
+ children: [!hasSecretsInitially && /* @__PURE__ */jsx(Card, {
2789
+ padding: [3, 3, 3],
2790
+ radius: 2,
2791
+ shadow: 1,
2792
+ tone: "primary",
2793
+ children: /* @__PURE__ */jsxs(Stack, {
2794
+ space: 3,
2795
+ children: [/* @__PURE__ */jsxs(Text, {
2796
+ size: 1,
2797
+ children: ["To set up a new access token, go to your", " ", /* @__PURE__ */jsx("a", {
2798
+ href: "https://dashboard.mux.com/settings/access-tokens",
2799
+ target: "_blank",
2800
+ rel: "noreferrer noopener",
2801
+ children: "account on mux.com"
2802
+ }), "."]
2803
+ }), /* @__PURE__ */jsxs(Text, {
2804
+ size: 1,
2805
+ children: ["The access token needs permissions: ", /* @__PURE__ */jsx("strong", {
2806
+ children: "Mux Video "
2807
+ }), "(Full Access) and ", /* @__PURE__ */jsx("strong", {
2808
+ children: "Mux Data"
2809
+ }), " (Read)", /* @__PURE__ */jsx("br", {}), "The credentials will be stored safely in a hidden document only available to editors."]
2810
+ })]
2811
+ })
2812
+ }), /* @__PURE__ */jsx(FormField$1, {
2813
+ title: "Access Token",
2814
+ inputId: tokenId,
2815
+ children: /* @__PURE__ */jsx(TextInput, {
2816
+ id: tokenId,
2817
+ ref: firstField,
2818
+ onChange: handleChangeToken,
2819
+ type: "text",
2820
+ value: (_a = state.token) != null ? _a : "",
2821
+ required: !!state.secretKey || state.enableSignedUrls
2822
+ })
2823
+ }), /* @__PURE__ */jsx(FormField$1, {
2824
+ title: "Secret Key",
2825
+ inputId: secretKeyId,
2826
+ children: /* @__PURE__ */jsx(TextInput, {
2827
+ id: secretKeyId,
2828
+ onChange: handleChangeSecretKey,
2829
+ type: "text",
2830
+ value: (_b = state.secretKey) != null ? _b : "",
2831
+ required: !!state.token || state.enableSignedUrls
2832
+ })
2833
+ }), /* @__PURE__ */jsxs(Stack, {
2834
+ space: 4,
2835
+ children: [/* @__PURE__ */jsxs(Flex, {
2836
+ align: "center",
2837
+ children: [/* @__PURE__ */jsx(Checkbox, {
2838
+ id: enableSignedUrlsId,
2839
+ onChange: handleChangeEnableSignedUrls,
2840
+ checked: state.enableSignedUrls,
2841
+ style: {
2842
+ display: "block"
2843
+ }
2844
+ }), /* @__PURE__ */jsx(Box, {
2845
+ flex: 1,
2846
+ paddingLeft: 3,
2847
+ children: /* @__PURE__ */jsx(Text, {
2848
+ children: /* @__PURE__ */jsx("label", {
2849
+ htmlFor: enableSignedUrlsId,
2850
+ children: "Enable Signed Urls"
2851
+ })
2852
+ })
2853
+ })]
2854
+ }), secrets.signingKeyId && state.enableSignedUrls ? /* @__PURE__ */jsx(Card, {
2855
+ padding: [3, 3, 3],
2856
+ radius: 2,
2857
+ shadow: 1,
2858
+ tone: "caution",
2859
+ children: /* @__PURE__ */jsxs(Stack, {
2860
+ space: 3,
2861
+ children: [/* @__PURE__ */jsx(Text, {
2862
+ size: 1,
2863
+ children: "The signing key ID that Sanity will use is:"
2864
+ }), /* @__PURE__ */jsx(Code, {
2865
+ size: 1,
2866
+ children: secrets.signingKeyId
2867
+ }), /* @__PURE__ */jsxs(Text, {
2868
+ size: 1,
2869
+ 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."]
2870
+ })]
2871
+ })
2872
+ }) : null]
2873
+ }), /* @__PURE__ */jsxs(Inline, {
2874
+ space: 2,
2875
+ children: [/* @__PURE__ */jsx(Button, {
2876
+ text: "Save",
2877
+ disabled: !dirty,
2878
+ loading: state.submitting,
2879
+ tone: "primary",
2880
+ mode: "default",
2881
+ type: "submit"
2882
+ }), /* @__PURE__ */jsx(Button, {
2883
+ disabled: state.submitting,
2884
+ text: "Cancel",
2885
+ mode: "bleed",
2886
+ onClick: handleClose
2887
+ })]
2888
+ }), state.error && /* @__PURE__ */jsx(Card, {
2889
+ padding: [3, 3, 3],
2890
+ radius: 2,
2891
+ shadow: 1,
2892
+ tone: "critical",
2893
+ children: /* @__PURE__ */jsx(Text, {
2894
+ children: state.error
2895
+ })
2896
+ })]
2897
+ })
2898
+ })
2899
+ })
2900
+ });
2901
+ }
2902
+ var ConfigureApi$1 = memo(ConfigureApi);
2903
+ function ErrorBoundaryCard(props) {
2904
+ const {
2905
+ children,
2906
+ schemaType
2907
+ } = props;
2908
+ const {
2909
+ push: pushToast
2910
+ } = useToast();
2911
+ const errorRef = useRef(null);
2912
+ const {
2913
+ ErrorBoundary,
2914
+ didCatch,
2915
+ error,
2916
+ reset
2917
+ } = useErrorBoundary({
2918
+ onDidCatch: (err, errorInfo) => {
2919
+ console.group(err.toString());
2920
+ console.groupCollapsed("console.error");
2921
+ console.error(err);
2922
+ console.groupEnd();
2923
+ if (err.stack) {
2924
+ console.groupCollapsed("error.stack");
2925
+ console.log(err.stack);
2926
+ console.groupEnd();
2927
+ }
2928
+ if (errorInfo == null ? void 0 : errorInfo.componentStack) {
2929
+ console.groupCollapsed("errorInfo.componentStack");
2930
+ console.log(errorInfo.componentStack);
2931
+ console.groupEnd();
2932
+ }
2933
+ console.groupEnd();
2934
+ pushToast({
2935
+ status: "error",
2936
+ title: "Plugin crashed",
2937
+ description: /* @__PURE__ */jsx(Flex, {
2938
+ align: "center",
2939
+ children: /* @__PURE__ */jsxs(Inline, {
2940
+ space: 1,
2941
+ children: ["An error happened while rendering", /* @__PURE__ */jsx(Button, {
2942
+ padding: 1,
2943
+ fontSize: 1,
2944
+ style: {
2945
+ transform: "translateY(1px)"
2946
+ },
2947
+ mode: "ghost",
2948
+ text: schemaType.title,
2949
+ onClick: () => {
2950
+ if (errorRef.current) {
2951
+ scrollIntoView(errorRef.current, {
2952
+ behavior: "smooth",
2953
+ scrollMode: "if-needed",
2954
+ block: "center"
2955
+ });
2956
+ }
2957
+ }
2958
+ })]
2959
+ })
2960
+ })
2961
+ });
2962
+ }
2963
+ });
2964
+ const handleRetry = useCallback(() => {
2965
+ clear([name]);
2966
+ reset();
2967
+ }, [reset]);
2968
+ if (didCatch) {
2969
+ return /* @__PURE__ */jsx(Card, {
2970
+ ref: errorRef,
2971
+ paddingX: [2, 3, 4, 4],
2972
+ height: "fill",
2973
+ shadow: 1,
2974
+ overflow: "auto",
2975
+ children: /* @__PURE__ */jsx(Flex, {
2976
+ justify: "flex-start",
2977
+ align: "center",
2978
+ height: "fill",
2979
+ children: /* @__PURE__ */jsxs(Grid, {
2980
+ columns: 1,
2981
+ gap: [2, 3, 4, 4],
2982
+ children: [/* @__PURE__ */jsxs(Heading, {
2983
+ as: "h1",
2984
+ children: ["The ", /* @__PURE__ */jsx("code", {
2985
+ children: name
2986
+ }), " plugin crashed"]
2987
+ }), (error == null ? void 0 : error.message) && /* @__PURE__ */jsx(Card, {
2988
+ padding: 3,
2989
+ tone: "critical",
2990
+ shadow: 1,
2991
+ radius: 2,
2992
+ children: /* @__PURE__ */jsx(Text, {
2993
+ children: error.message
2994
+ })
2995
+ }), /* @__PURE__ */jsx(Inline, {
2996
+ children: /* @__PURE__ */jsx(Button, {
2997
+ onClick: handleRetry,
2998
+ text: "Retry"
2999
+ })
3000
+ })]
3001
+ })
3002
+ })
3003
+ });
3004
+ }
3005
+ return /* @__PURE__ */jsx(ErrorBoundary, {
3006
+ children
3007
+ });
3008
+ }
3009
+ var ErrorBoundaryCard$1 = memo(ErrorBoundaryCard);
3010
+ const AspectRatioCard = styled(Card)(_templateObject22 || (_templateObject22 = _taggedTemplateLiteral(["\n aspect-ratio: 16 / 9;\n position: relative;\n width: 100%;\n"])));
3011
+ const InputFallback = () => {
3012
+ return /* @__PURE__ */jsx("div", {
3013
+ style: {
3014
+ padding: 1
3015
+ },
3016
+ children: /* @__PURE__ */jsx(Card, {
3017
+ shadow: 1,
3018
+ sizing: "border",
3019
+ style: {
3020
+ aspectRatio: "16/9",
3021
+ width: "100%",
3022
+ borderRadius: "1px"
3023
+ },
3024
+ children: /* @__PURE__ */jsxs(Flex, {
3025
+ align: "center",
3026
+ direction: "column",
3027
+ height: "fill",
3028
+ justify: "center",
3029
+ children: [/* @__PURE__ */jsx(Spinner, {
3030
+ muted: true
3031
+ }), /* @__PURE__ */jsx(Box, {
3032
+ marginTop: 3,
3033
+ children: /* @__PURE__ */jsx(Text, {
3034
+ align: "center",
3035
+ muted: true,
3036
+ size: 1,
3037
+ children: "Loading\u2026"
3038
+ })
3039
+ })]
3040
+ })
3041
+ })
3042
+ });
3043
+ };
3044
+ function Onboard(props) {
3045
+ const {
3046
+ setDialogState
3047
+ } = props;
3048
+ const handleOpen = useCallback(() => setDialogState("secrets"), [setDialogState]);
3049
+ return /* @__PURE__ */jsx(Fragment, {
3050
+ children: /* @__PURE__ */jsx("div", {
3051
+ style: {
3052
+ padding: 2
3053
+ },
3054
+ children: /* @__PURE__ */jsx(Card, {
3055
+ display: "flex",
3056
+ sizing: "border",
3057
+ style: {
3058
+ aspectRatio: "16/9",
3059
+ width: "100%",
3060
+ boxShadow: "var(--card-bg-color) 0 0 0 2px"
3061
+ },
3062
+ paddingX: [2, 3, 4, 4],
3063
+ radius: 1,
3064
+ tone: "transparent",
3065
+ children: /* @__PURE__ */jsx(Flex, {
3066
+ justify: "flex-start",
3067
+ align: "center",
3068
+ children: /* @__PURE__ */jsxs(Grid, {
3069
+ columns: 1,
3070
+ gap: [2, 3, 4, 4],
3071
+ children: [/* @__PURE__ */jsx(Inline, {
3072
+ paddingY: 1,
3073
+ children: /* @__PURE__ */jsx("div", {
3074
+ style: {
3075
+ height: "32px"
3076
+ },
3077
+ children: /* @__PURE__ */jsx(MuxLogo, {})
3078
+ })
3079
+ }), /* @__PURE__ */jsx(Inline, {
3080
+ paddingY: 1,
3081
+ children: /* @__PURE__ */jsx(Heading, {
3082
+ size: [0, 1, 2, 2],
3083
+ children: "Upload and preview videos directly from your studio."
3084
+ })
3085
+ }), /* @__PURE__ */jsx(Inline, {
3086
+ paddingY: 1,
3087
+ children: /* @__PURE__ */jsx(Button, {
3088
+ mode: "ghost",
3089
+ icon: PlugIcon,
3090
+ text: "Configure API",
3091
+ onClick: handleOpen
3092
+ })
3093
+ })]
3094
+ })
3095
+ })
3096
+ })
3097
+ })
3098
+ });
3099
+ }
3100
+ const Input = props => {
3101
+ var _a;
3102
+ const client = useClient();
3103
+ const secretDocumentValues = useSecretsDocumentValues();
3104
+ const assetDocumentValues = useAssetDocumentValues((_a = props.value) == null ? void 0 : _a.asset);
3105
+ const poll = useMuxPolling(props.readOnly ? void 0 : (assetDocumentValues == null ? void 0 : assetDocumentValues.value) || void 0);
3106
+ const [dialogState, setDialogState] = useDialogState();
3107
+ const error = secretDocumentValues.error || assetDocumentValues.error || poll.error;
3108
+ if (error) {
3109
+ throw error;
3110
+ }
3111
+ const isLoading = secretDocumentValues.isLoading || assetDocumentValues.isLoading;
3112
+ return /* @__PURE__ */jsx(AspectRatioCard, {
3113
+ children: /* @__PURE__ */jsx(ErrorBoundaryCard$1, {
3114
+ schemaType: props.schemaType,
3115
+ children: /* @__PURE__ */jsx(Suspense, {
3116
+ fallback: /* @__PURE__ */jsx(InputFallback, {}),
3117
+ children: isLoading ? /* @__PURE__ */jsx(InputFallback, {}) : /* @__PURE__ */jsxs(Fragment, {
3118
+ children: [secretDocumentValues.value.needsSetup && !assetDocumentValues.value ? /* @__PURE__ */jsx(Onboard, {
3119
+ setDialogState
3120
+ }) : /* @__PURE__ */jsx(MuxVideoInputUploader, {
3121
+ ...props,
3122
+ config: props.config,
3123
+ onChange: props.onChange,
3124
+ client,
3125
+ secrets: secretDocumentValues.value.secrets,
3126
+ asset: assetDocumentValues.value,
3127
+ dialogState,
3128
+ setDialogState,
3129
+ needsSetup: secretDocumentValues.value.needsSetup
3130
+ }), dialogState === "secrets" && /* @__PURE__ */jsx(ConfigureApi$1, {
3131
+ setDialogState,
3132
+ secrets: secretDocumentValues.value.secrets
3133
+ })]
3134
+ })
3135
+ })
3136
+ })
3137
+ });
3138
+ };
3139
+ var Input$1 = memo(Input);
3140
+ function muxVideoCustomRendering(config) {
3141
+ return {
3142
+ components: {
3143
+ input: props => /* @__PURE__ */jsx(Input$1, {
3144
+ config,
3145
+ ...props
3146
+ })
3147
+ },
3148
+ preview: {
3149
+ select: {
3150
+ filename: "asset.filename",
3151
+ playbackId: "asset.playbackId",
3152
+ status: "asset.status",
3153
+ assetId: "asset.assetId",
3154
+ thumbTime: "asset.thumbTime",
3155
+ data: "asset.data"
3156
+ },
3157
+ prepare: asset => {
3158
+ const {
3159
+ filename,
3160
+ playbackId,
3161
+ status
3162
+ } = asset;
3163
+ return {
3164
+ title: filename || playbackId || "",
3165
+ subtitle: status ? "status: ".concat(status) : null,
3166
+ media: asset.playbackId ? /* @__PURE__ */jsx(VideoThumbnail, {
3167
+ asset,
3168
+ width: 64
3169
+ }) : null
3170
+ };
3171
+ }
3172
+ }
3173
+ };
3174
+ }
3175
+ const muxVideo = {
3176
+ name: "mux.video",
3177
+ type: "object",
3178
+ title: "Video asset reference",
3179
+ fields: [{
3180
+ title: "Video",
3181
+ name: "asset",
3182
+ type: "reference",
3183
+ weak: true,
3184
+ to: [{
3185
+ type: "mux.videoAsset"
3186
+ }]
3187
+ }]
3188
+ };
3189
+ const muxVideoAsset = {
3190
+ name: "mux.videoAsset",
3191
+ type: "object",
3192
+ title: "Video asset",
3193
+ fields: [{
3194
+ type: "string",
3195
+ name: "status"
3196
+ }, {
3197
+ type: "string",
3198
+ name: "assetId"
3199
+ }, {
3200
+ type: "string",
3201
+ name: "playbackId"
3202
+ }, {
3203
+ type: "string",
3204
+ name: "filename"
3205
+ }, {
3206
+ type: "number",
3207
+ name: "thumbTime"
3208
+ }]
3209
+ };
3210
+ const defaultConfig = {
3211
+ mp4_support: "none"
3212
+ };
3213
+ const muxInput = definePlugin(userConfig => {
3214
+ const config = {
3215
+ ...defaultConfig,
3216
+ ...userConfig
3217
+ };
3218
+ return {
3219
+ name: "mux-input",
3220
+ schema: {
3221
+ types: [muxVideoAsset, {
3222
+ ...muxVideo,
3223
+ ...muxVideoCustomRendering(config)
3224
+ }]
3225
+ }
3226
+ };
3227
+ });
3228
+ export { UploadProgress, VideoThumbnail, defaultConfig, deleteAsset, generateJwt, getPlaybackId, getPlaybackPolicy, getPosterSrc, muxInput, useClient };
3229
+ //# sourceMappingURL=index-0656ede8.js.map