sanity-plugin-mux-input 2.1.1 → 2.2.1

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