sanity-plugin-mux-input 2.0.2 → 2.0.3

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