sanity-plugin-iframe-pane 3.1.3 → 3.1.5

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.
package/lib/index.js CHANGED
@@ -1,24 +1,20 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import { MobileDeviceIcon, RefreshIcon, CopyIcon, LaunchIcon, WarningOutlineIcon } from '@sanity/icons';
3
- import { createPreviewSecret } from '@sanity/preview-url-secret/create-secret';
4
- import { definePreviewUrl } from '@sanity/preview-url-secret/define-preview-url';
5
- import { Text, useToast, Card, Flex, Tooltip, Button, Box, usePrefersReducedMotion, Spinner, Container, Stack } from '@sanity/ui';
6
- import { motion, MotionConfig, AnimatePresence } from 'framer-motion';
7
- import { useMemo, useRef, memo, useState, useCallback, forwardRef, useEffect, useTransition, Suspense } from 'react';
8
- import { useCurrentUser, useClient } from 'sanity';
9
- import { suspend } from 'suspend-react';
10
- import { useCopyToClipboard } from 'usehooks-ts';
11
- import { getRedirectTo } from '@sanity/preview-url-secret/get-redirect-to';
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { MobileDeviceIcon, RefreshIcon, CopyIcon, LaunchIcon, WarningOutlineIcon } from "@sanity/icons";
3
+ import { createPreviewSecret } from "@sanity/preview-url-secret/create-secret";
4
+ import { definePreviewUrl } from "@sanity/preview-url-secret/define-preview-url";
5
+ import { Text, useToast, Card, Flex, Tooltip, Button, Box, usePrefersReducedMotion, Spinner, Container, Stack } from "@sanity/ui";
6
+ import { motion, MotionConfig, AnimatePresence } from "framer-motion";
7
+ import { useMemo, useRef, memo, useState, useCallback, forwardRef, useEffect, useTransition, Suspense } from "react";
8
+ import { useCurrentUser, useClient } from "sanity";
9
+ import { suspend } from "suspend-react";
10
+ import { useCopyToClipboard } from "usehooks-ts";
11
+ import { getRedirectTo } from "@sanity/preview-url-secret/get-redirect-to";
12
12
  function DisplayUrl(props) {
13
13
  const truncatedUrl = useMemo(() => {
14
14
  const url = getRedirectTo(props.url);
15
- return "".concat(url.origin === location.origin ? "" : url.origin).concat(url.pathname).concat(url.search);
15
+ return `${url.origin === location.origin ? "" : url.origin}${url.pathname}${url.search}`;
16
16
  }, [props.url]);
17
- return /* @__PURE__ */jsx(Text, {
18
- size: 0,
19
- textOverflow: "ellipsis",
20
- children: truncatedUrl
21
- });
17
+ return /* @__PURE__ */ jsx(Text, { size: 0, textOverflow: "ellipsis", children: truncatedUrl });
22
18
  }
23
19
  const sizes = {
24
20
  desktop: {
@@ -29,241 +25,179 @@ const sizes = {
29
25
  width: 414,
30
26
  height: 746
31
27
  }
32
- };
33
- const DEFAULT_SIZE = "desktop";
28
+ }, DEFAULT_SIZE = "desktop";
34
29
  function Toolbar(props) {
35
- const {
36
- url,
37
- iframeSize,
38
- setIframeSize,
39
- reloading,
40
- showUrl,
41
- reloadButton,
42
- handleReload
43
- } = props;
44
- const validUrl = url instanceof URL;
45
- const input = useRef(null);
46
- const {
47
- push: pushToast
48
- } = useToast();
49
- const [, copy] = useCopyToClipboard();
50
- return /* @__PURE__ */jsxs(Fragment, {
51
- children: [/* @__PURE__ */jsx("textarea", {
52
- style: {
53
- position: "absolute",
54
- pointerEvents: "none",
55
- opacity: 0
56
- },
57
- ref: input,
58
- value: validUrl ? url.toString() : "",
59
- readOnly: true,
60
- tabIndex: -1
61
- }), /* @__PURE__ */jsx(Card, {
62
- padding: 2,
63
- borderBottom: true,
64
- children: /* @__PURE__ */jsxs(Flex, {
65
- align: "center",
66
- gap: 2,
67
- children: [/* @__PURE__ */jsx(Flex, {
68
- align: "center",
69
- gap: 1,
70
- children: /* @__PURE__ */jsx(Tooltip, {
71
- content: /* @__PURE__ */jsx(Text, {
72
- size: 1,
73
- style: {
74
- whiteSpace: "nowrap"
75
- },
76
- children: iframeSize === "mobile" ? "Exit mobile preview" : "Preview mobile viewport"
77
- }),
78
- padding: 2,
79
- placement: "bottom-start",
80
- children: /* @__PURE__ */jsx(Button, {
30
+ const { url, iframeSize, setIframeSize, reloading, showUrl, reloadButton, handleReload } = props, validUrl = url instanceof URL, input = useRef(null), { push: pushToast } = useToast(), [, copy] = useCopyToClipboard();
31
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
32
+ /* @__PURE__ */ jsx(
33
+ "textarea",
34
+ {
35
+ style: { position: "absolute", pointerEvents: "none", opacity: 0 },
36
+ ref: input,
37
+ value: validUrl ? url.toString() : "",
38
+ readOnly: !0,
39
+ tabIndex: -1
40
+ }
41
+ ),
42
+ /* @__PURE__ */ jsx(Card, { padding: 2, borderBottom: !0, children: /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
43
+ /* @__PURE__ */ jsx(Flex, { align: "center", gap: 1, children: /* @__PURE__ */ jsx(
44
+ Tooltip,
45
+ {
46
+ animate: !0,
47
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: iframeSize === "mobile" ? "Exit mobile preview" : "Preview mobile viewport" }),
48
+ padding: 2,
49
+ placement: "bottom-start",
50
+ children: /* @__PURE__ */ jsx(
51
+ Button,
52
+ {
81
53
  disabled: !validUrl,
82
54
  fontSize: [1],
83
55
  padding: 2,
84
56
  mode: iframeSize === "mobile" ? "default" : "ghost",
85
57
  icon: MobileDeviceIcon,
86
58
  onClick: () => setIframeSize(iframeSize === "mobile" ? "desktop" : "mobile")
87
- })
88
- })
89
- }), /* @__PURE__ */jsx(Box, {
90
- flex: 1,
91
- children: showUrl && validUrl && /* @__PURE__ */jsx(DisplayUrl, {
92
- url
93
- })
94
- }), /* @__PURE__ */jsxs(Flex, {
95
- align: "center",
96
- gap: 1,
97
- children: [reloadButton ? /* @__PURE__ */jsx(Tooltip, {
98
- content: /* @__PURE__ */jsx(Text, {
99
- size: 1,
100
- style: {
101
- whiteSpace: "nowrap"
102
- },
103
- children: reloading ? "Reloading\u2026" : "Reload"
104
- }),
59
+ }
60
+ )
61
+ }
62
+ ) }),
63
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: showUrl && validUrl && /* @__PURE__ */ jsx(DisplayUrl, { url }) }),
64
+ /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 1, children: [
65
+ reloadButton ? /* @__PURE__ */ jsx(
66
+ Tooltip,
67
+ {
68
+ animate: !0,
69
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: reloading ? "Reloading\u2026" : "Reload" }),
105
70
  padding: 2,
106
- children: /* @__PURE__ */jsx(Button, {
107
- disabled: !validUrl,
108
- mode: "bleed",
109
- fontSize: [1],
110
- padding: 2,
111
- icon: RefreshIcon,
112
- loading: reloading,
113
- "aria-label": "Reload",
114
- onClick: () => handleReload()
115
- })
116
- }) : null, /* @__PURE__ */jsx(Tooltip, {
117
- content: /* @__PURE__ */jsx(Text, {
118
- size: 1,
119
- style: {
120
- whiteSpace: "nowrap"
121
- },
122
- children: "Copy URL"
123
- }),
71
+ children: /* @__PURE__ */ jsx(
72
+ Button,
73
+ {
74
+ disabled: !validUrl,
75
+ mode: "bleed",
76
+ fontSize: [1],
77
+ padding: 2,
78
+ icon: RefreshIcon,
79
+ loading: reloading,
80
+ "aria-label": "Reload",
81
+ onClick: () => handleReload()
82
+ }
83
+ )
84
+ }
85
+ ) : null,
86
+ /* @__PURE__ */ jsx(
87
+ Tooltip,
88
+ {
89
+ animate: !0,
90
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Copy URL" }),
124
91
  padding: 2,
125
- children: /* @__PURE__ */jsx(Button, {
126
- mode: "bleed",
127
- disabled: !validUrl,
128
- fontSize: [1],
129
- icon: CopyIcon,
130
- padding: [2],
131
- "aria-label": "Copy URL",
132
- onClick: () => {
133
- var _a;
134
- if (!((_a = input == null ? void 0 : input.current) == null ? void 0 : _a.value)) return;
135
- copy(input.current.value);
136
- pushToast({
137
- closable: true,
138
- status: "success",
139
- title: "The URL is copied to the clipboard"
140
- });
92
+ children: /* @__PURE__ */ jsx(
93
+ Button,
94
+ {
95
+ mode: "bleed",
96
+ disabled: !validUrl,
97
+ fontSize: [1],
98
+ icon: CopyIcon,
99
+ padding: [2],
100
+ "aria-label": "Copy URL",
101
+ onClick: () => {
102
+ var _a;
103
+ (_a = input == null ? void 0 : input.current) != null && _a.value && (copy(input.current.value), pushToast({
104
+ closable: !0,
105
+ status: "success",
106
+ title: "The URL is copied to the clipboard"
107
+ }));
108
+ }
141
109
  }
142
- })
143
- }), /* @__PURE__ */jsx(Tooltip, {
144
- content: /* @__PURE__ */jsx(Text, {
145
- size: 1,
146
- style: {
147
- whiteSpace: "nowrap"
148
- },
149
- children: "Open URL in a new tab"
150
- }),
110
+ )
111
+ }
112
+ ),
113
+ /* @__PURE__ */ jsx(
114
+ Tooltip,
115
+ {
116
+ animate: !0,
117
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Open URL in a new tab" }),
151
118
  padding: 2,
152
119
  placement: "bottom-end",
153
- children: /* @__PURE__ */jsx(Button, {
154
- disabled: !validUrl,
155
- fontSize: [1],
156
- icon: LaunchIcon,
157
- mode: "ghost",
158
- paddingY: [2],
159
- text: "Open",
160
- "aria-label": "Open URL in a new tab",
161
- onClick: validUrl ? () => window.open(url.toString()) : void 0
162
- })
163
- })]
164
- })]
165
- })
166
- })]
167
- });
120
+ children: /* @__PURE__ */ jsx(
121
+ Button,
122
+ {
123
+ disabled: !validUrl,
124
+ fontSize: [1],
125
+ icon: LaunchIcon,
126
+ mode: "ghost",
127
+ paddingY: [2],
128
+ text: "Open",
129
+ "aria-label": "Open URL in a new tab",
130
+ onClick: validUrl ? () => window.open(url.toString()) : void 0
131
+ }
132
+ )
133
+ }
134
+ )
135
+ ] })
136
+ ] }) })
137
+ ] });
168
138
  }
169
139
  const MotionFlex = motion(Flex);
170
140
  function Iframe(props) {
171
- const {
172
- document,
173
- options
174
- } = props;
175
- const draft = document.draft || document.published;
176
- const {
177
- defaultSize = DEFAULT_SIZE,
178
- reload,
179
- attributes,
180
- showDisplayUrl = true,
181
- key
182
- } = options;
183
- const urlRef = useRef(options.url);
184
- const [draftSnapshot, setDraftSnapshot] = useState(() => ({
185
- key,
186
- draft
187
- }));
141
+ const { document, options } = props, draft = document.draft || document.published || document.displayed, { defaultSize = DEFAULT_SIZE, reload, attributes, showDisplayUrl = !0, key } = options, urlRef = useRef(options.url), [draftSnapshot, setDraftSnapshot] = useState(() => ({ key, draft }));
188
142
  useEffect(() => {
189
143
  urlRef.current = options.url;
190
- }, [options.url]);
191
- useEffect(() => {
192
- if (JSON.stringify({
193
- key,
194
- draft
195
- }) !== JSON.stringify(draftSnapshot)) {
196
- startTransition(() => setDraftSnapshot({
197
- key,
198
- draft
199
- }));
200
- }
144
+ }, [options.url]), useEffect(() => {
145
+ JSON.stringify({ key, draft }) !== JSON.stringify(draftSnapshot) && startTransition(() => setDraftSnapshot({ key, draft }));
201
146
  }, [draft, draftSnapshot, key]);
202
- const currentUser = useCurrentUser();
203
- const client = useClient({
204
- apiVersion: "2023-10-16"
205
- });
206
- const [expiresAt, setExpiresAt] = useState();
207
- const previewSecretRef = useRef();
208
- const [isResolvingUrl, startTransition] = useTransition();
209
- const url = useCallback(
210
- // eslint-disable-next-line @typescript-eslint/no-shadow
211
- async draft2 => {
212
- if (typeof location === "undefined") {
213
- return void 0;
214
- }
215
- const urlProp = urlRef.current;
216
- if (typeof urlProp === "string") {
217
- return new URL(urlProp, location.origin);
218
- }
219
- if (typeof urlProp === "function") {
220
- const url2 = await urlProp(draft2);
221
- return typeof url2 === "string" ? new URL(url2, location.origin) : url2;
222
- }
223
- if (typeof urlProp === "object") {
224
- const preview = typeof urlProp.preview === "function" ? await urlProp.preview(draft2) : urlProp.preview;
225
- if (typeof preview !== "string") {
226
- return preview;
227
- }
228
- if (!previewSecretRef.current) {
229
- const {
230
- secret,
231
- expiresAt: expiresAt2
232
- } = await createPreviewSecret(client, "sanity-plugin-iframe-pane", location.href, currentUser == null ? void 0 : currentUser.id);
233
- previewSecretRef.current = secret;
234
- startTransition(() => setExpiresAt(expiresAt2.getTime()));
147
+ const currentUser = useCurrentUser(), client = useClient({ apiVersion: "2023-10-16" }), [expiresAt, setExpiresAt] = useState(), previewSecretRef = useRef(), [isResolvingUrl, startTransition] = useTransition(), url = useCallback(
148
+ // eslint-disable-next-line @typescript-eslint/no-shadow
149
+ async (draft2) => {
150
+ if (typeof location > "u")
151
+ return;
152
+ const urlProp = urlRef.current;
153
+ if (typeof urlProp == "string")
154
+ return new URL(urlProp, location.origin);
155
+ if (typeof urlProp == "function") {
156
+ const url2 = await urlProp(draft2);
157
+ return typeof url2 == "string" ? new URL(url2, location.origin) : url2;
235
158
  }
236
- const resolvePreviewUrl = definePreviewUrl({
237
- origin: urlProp.origin === "same-origin" ? location.origin : urlProp.origin,
238
- preview,
239
- draftMode: {
240
- enable: urlProp.draftMode
159
+ if (typeof urlProp == "object") {
160
+ const preview = typeof urlProp.preview == "function" ? await urlProp.preview(draft2) : urlProp.preview;
161
+ if (typeof preview != "string")
162
+ return preview;
163
+ if (!previewSecretRef.current) {
164
+ const { secret, expiresAt: expiresAt2 } = await createPreviewSecret(
165
+ client,
166
+ "sanity-plugin-iframe-pane",
167
+ location.href,
168
+ currentUser == null ? void 0 : currentUser.id
169
+ );
170
+ previewSecretRef.current = secret, startTransition(() => setExpiresAt(expiresAt2.getTime()));
241
171
  }
242
- });
243
- const url2 = await resolvePreviewUrl({
244
- client,
245
- previewUrlSecret: previewSecretRef.current,
246
- previewSearchParam: null
247
- });
248
- return new URL(url2, location.origin);
249
- }
250
- return void 0;
251
- }, [client, currentUser == null ? void 0 : currentUser.id]);
252
- useEffect(() => {
172
+ const url2 = await definePreviewUrl({
173
+ origin: urlProp.origin === "same-origin" ? location.origin : urlProp.origin,
174
+ preview,
175
+ draftMode: {
176
+ enable: urlProp.draftMode
177
+ }
178
+ })({
179
+ client,
180
+ previewUrlSecret: previewSecretRef.current,
181
+ previewSearchParam: null
182
+ });
183
+ return new URL(url2, location.origin);
184
+ }
185
+ },
186
+ [client, currentUser == null ? void 0 : currentUser.id]
187
+ );
188
+ return useEffect(() => {
253
189
  if (expiresAt) {
254
- const timeout = setTimeout(() => {
255
- startTransition(() => setExpiresAt(void 0));
256
- previewSecretRef.current = void 0;
257
- }, Math.max(0, expiresAt - Date.now()));
190
+ const timeout = setTimeout(
191
+ () => {
192
+ startTransition(() => setExpiresAt(void 0)), previewSecretRef.current = void 0;
193
+ },
194
+ Math.max(0, expiresAt - Date.now())
195
+ );
258
196
  return () => clearTimeout(timeout);
259
197
  }
260
- return void 0;
261
- }, [expiresAt]);
262
- return /* @__PURE__ */jsx(Suspense, {
263
- fallback: /* @__PURE__ */jsx(Loading, {
264
- iframeSize: "desktop"
265
- }),
266
- children: /* @__PURE__ */jsx(IframeInner, {
198
+ }, [expiresAt]), /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Loading, { iframeSize: "desktop" }), children: /* @__PURE__ */ jsx(
199
+ IframeInner,
200
+ {
267
201
  _key: draftSnapshot.key,
268
202
  draftSnapshot: draftSnapshot.draft,
269
203
  url,
@@ -273,144 +207,107 @@ function Iframe(props) {
273
207
  reload,
274
208
  showDisplayUrl,
275
209
  userId: currentUser == null ? void 0 : currentUser.id
276
- }, draftSnapshot.key)
277
- });
210
+ },
211
+ draftSnapshot.key
212
+ ) });
278
213
  }
279
- const IframeInner = memo(function IframeInner2(props) {
214
+ const IframeInner = memo(function(props) {
280
215
  var _a;
281
216
  const {
282
217
  isResolvingUrl,
283
218
  defaultSize = DEFAULT_SIZE,
284
219
  reload,
285
220
  attributes = {},
286
- showDisplayUrl = true,
221
+ showDisplayUrl = !0,
287
222
  draftSnapshot,
288
223
  userId,
289
224
  expiresAt,
290
225
  _key
291
- } = props;
292
- const [iframeSize, setIframeSize] = useState(((_a = sizes) == null ? void 0 : _a[defaultSize]) ? defaultSize : DEFAULT_SIZE);
293
- const prefersReducedMotion = usePrefersReducedMotion();
294
- const url = suspend(() => props.url(draftSnapshot), [
295
- // Cache based on a few specific conditions
296
- "sanity-plugin-iframe-pane", draftSnapshot, userId, expiresAt, _key, resolveUUID]);
297
- const [loading, setLoading] = useState(true);
298
- const [_reloading, setReloading] = useState(false);
299
- const reloading = _reloading || isResolvingUrl;
300
- const iframe = useRef(null);
301
- const handleReload = useCallback(() => {
302
- if (!(iframe == null ? void 0 : iframe.current)) {
303
- return;
304
- }
305
- iframe.current.src = iframe.current.src;
306
- setReloading(true);
226
+ } = props, [iframeSize, setIframeSize] = useState((_a = sizes) != null && _a[defaultSize] ? defaultSize : DEFAULT_SIZE), prefersReducedMotion = usePrefersReducedMotion(), url = suspend(
227
+ () => props.url(draftSnapshot),
228
+ [
229
+ // Cache based on a few specific conditions
230
+ "sanity-plugin-iframe-pane",
231
+ draftSnapshot,
232
+ userId,
233
+ expiresAt,
234
+ _key,
235
+ resolveUUID
236
+ ]
237
+ ), [loading, setLoading] = useState(!0), [_reloading, setReloading] = useState(!1), reloading = _reloading || isResolvingUrl, iframe = useRef(null), handleReload = useCallback(() => {
238
+ iframe != null && iframe.current && (iframe.current.src = iframe.current.src, setReloading(!0));
307
239
  }, []);
308
- return /* @__PURE__ */jsx(MotionConfig, {
309
- transition: prefersReducedMotion ? {
310
- duration: 0
311
- } : void 0,
312
- children: /* @__PURE__ */jsxs(Flex, {
313
- direction: "column",
314
- style: {
315
- height: "100%"
316
- },
317
- children: [/* @__PURE__ */jsx(Toolbar, {
240
+ return /* @__PURE__ */ jsx(MotionConfig, { transition: prefersReducedMotion ? { duration: 0 } : void 0, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", style: { height: "100%" }, children: [
241
+ /* @__PURE__ */ jsx(
242
+ Toolbar,
243
+ {
318
244
  url,
319
245
  iframeSize,
320
246
  reloading,
321
247
  setIframeSize,
322
248
  showUrl: showDisplayUrl,
323
- reloadButton: !!(reload == null ? void 0 : reload.button),
249
+ reloadButton: !!(reload != null && reload.button),
324
250
  handleReload
325
- }), url instanceof Error ? /* @__PURE__ */jsx(ErrorCard, {
326
- error: url
327
- }) : /* @__PURE__ */jsx(Card, {
328
- tone: "transparent",
329
- style: {
330
- height: "100%"
331
- },
332
- children: /* @__PURE__ */jsx(Frame, {
333
- ref: iframe,
334
- loading,
335
- reloading,
336
- iframeSize,
337
- setReloading,
338
- setLoading,
339
- url,
340
- attributes
341
- })
342
- })]
343
- })
344
- });
345
- });
346
- const Frame = forwardRef(function Frame2(props, iframe) {
347
- const {
348
- loading,
349
- setLoading,
350
- iframeSize,
351
- attributes,
352
- reloading,
353
- url,
354
- setReloading
355
- } = props;
251
+ }
252
+ ),
253
+ url instanceof Error ? /* @__PURE__ */ jsx(ErrorCard, { error: url }) : /* @__PURE__ */ jsx(Card, { tone: "transparent", style: { height: "100%" }, children: /* @__PURE__ */ jsx(
254
+ Frame,
255
+ {
256
+ ref: iframe,
257
+ loading,
258
+ reloading,
259
+ iframeSize,
260
+ setReloading,
261
+ setLoading,
262
+ url,
263
+ attributes
264
+ }
265
+ ) })
266
+ ] }) });
267
+ }), Frame = forwardRef(function(props, iframe) {
268
+ const { loading, setLoading, iframeSize, attributes, reloading, url, setReloading } = props;
356
269
  function handleIframeLoad() {
357
- setLoading(false);
358
- setReloading(false);
359
- if (attributes.onLoad && typeof attributes.onLoad === "function") {
360
- attributes.onLoad();
361
- }
270
+ setLoading(!1), setReloading(!1), attributes.onLoad && typeof attributes.onLoad == "function" && attributes.onLoad();
362
271
  }
363
- return /* @__PURE__ */jsxs(Flex, {
364
- align: "center",
365
- justify: "center",
366
- style: {
367
- height: "100%",
368
- position: "relative"
369
- },
370
- children: [/* @__PURE__ */jsx(AnimatePresence, {
371
- children: !url || loading && /* @__PURE__ */jsx(MotionFlex, {
272
+ return /* @__PURE__ */ jsxs(Flex, { align: "center", justify: "center", style: { height: "100%", position: "relative" }, children: [
273
+ /* @__PURE__ */ jsx(AnimatePresence, { children: !url || loading && /* @__PURE__ */ jsx(
274
+ MotionFlex,
275
+ {
372
276
  initial: "initial",
373
277
  animate: "animate",
374
278
  exit: "exit",
375
279
  variants: spinnerVariants,
376
280
  justify: "center",
377
281
  align: "center",
378
- style: {
379
- inset: "0",
380
- position: "absolute"
381
- },
382
- children: /* @__PURE__ */jsx(Loading, {
282
+ style: { inset: "0", position: "absolute" },
283
+ children: /* @__PURE__ */ jsx(Loading, { iframeSize })
284
+ }
285
+ ) }),
286
+ url && /* @__PURE__ */ jsx(
287
+ motion.iframe,
288
+ {
289
+ ref: iframe,
290
+ title: "preview",
291
+ frameBorder: "0",
292
+ style: { maxHeight: "100%" },
293
+ src: url.toString(),
294
+ initial: ["background", iframeSize],
295
+ variants: iframeVariants,
296
+ animate: [
297
+ loading ? "background" : "active",
298
+ reloading ? "reloading" : "idle",
383
299
  iframeSize
384
- })
385
- })
386
- }), url && /* @__PURE__ */jsx(motion.iframe, {
387
- ref: iframe,
388
- title: "preview",
389
- frameBorder: "0",
390
- style: {
391
- maxHeight: "100%"
392
- },
393
- src: url.toString(),
394
- initial: ["background", iframeSize],
395
- variants: iframeVariants,
396
- animate: [loading ? "background" : "active", reloading ? "reloading" : "idle", iframeSize],
397
- ...attributes,
398
- onLoad: handleIframeLoad
399
- })]
400
- });
401
- });
402
- const spinnerVariants = {
403
- initial: {
404
- opacity: 1
405
- },
406
- animate: {
407
- opacity: [0, 0, 1]
408
- },
409
- exit: {
410
- opacity: [1, 0, 0]
411
- }
412
- };
413
- const iframeVariants = {
300
+ ],
301
+ ...attributes,
302
+ onLoad: handleIframeLoad
303
+ }
304
+ )
305
+ ] });
306
+ }), spinnerVariants = {
307
+ initial: { opacity: 1 },
308
+ animate: { opacity: [0, 0, 1] },
309
+ exit: { opacity: [1, 0, 0] }
310
+ }, iframeVariants = {
414
311
  ...sizes,
415
312
  desktop: {
416
313
  ...sizes.desktop,
@@ -435,74 +332,23 @@ const iframeVariants = {
435
332
  scale: 1
436
333
  }
437
334
  };
438
- function Loading(_ref) {
439
- let {
440
- iframeSize
441
- } = _ref;
442
- return /* @__PURE__ */jsxs(Flex, {
443
- style: {
444
- ...sizes[iframeSize]
445
- },
446
- justify: "center",
447
- align: "center",
448
- direction: "column",
449
- gap: 4,
450
- children: [/* @__PURE__ */jsx(Spinner, {
451
- muted: true
452
- }), /* @__PURE__ */jsx(Text, {
453
- muted: true,
454
- size: 1,
455
- children: "Loading\u2026"
456
- })]
457
- });
335
+ function Loading({ iframeSize }) {
336
+ return /* @__PURE__ */ jsxs(Flex, { style: { ...sizes[iframeSize] }, justify: "center", align: "center", direction: "column", gap: 4, children: [
337
+ /* @__PURE__ */ jsx(Spinner, { muted: !0 }),
338
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Loading\u2026" })
339
+ ] });
458
340
  }
459
- function ErrorCard(_ref2) {
460
- let {
461
- error
462
- } = _ref2;
463
- return /* @__PURE__ */jsx(Card, {
464
- height: "fill",
465
- children: /* @__PURE__ */jsx(Flex, {
466
- align: "center",
467
- height: "fill",
468
- justify: "center",
469
- padding: 4,
470
- sizing: "border",
471
- children: /* @__PURE__ */jsx(Container, {
472
- width: 0,
473
- children: /* @__PURE__ */jsx(Card, {
474
- padding: 4,
475
- radius: 2,
476
- shadow: 1,
477
- tone: "caution",
478
- children: /* @__PURE__ */jsxs(Flex, {
479
- children: [/* @__PURE__ */jsx(Box, {
480
- children: /* @__PURE__ */jsx(Text, {
481
- size: 1,
482
- children: /* @__PURE__ */jsx(WarningOutlineIcon, {})
483
- })
484
- }), /* @__PURE__ */jsxs(Stack, {
485
- flex: 1,
486
- marginLeft: 3,
487
- space: 3,
488
- children: [/* @__PURE__ */jsx(Text, {
489
- as: "h1",
490
- size: 1,
491
- weight: "bold",
492
- children: error.name
493
- }), /* @__PURE__ */jsx(Text, {
494
- as: "p",
495
- muted: true,
496
- size: 1,
497
- children: error.message
498
- })]
499
- })]
500
- })
501
- })
502
- })
503
- })
504
- });
341
+ function ErrorCard({ error }) {
342
+ return /* @__PURE__ */ jsx(Card, { height: "fill", children: /* @__PURE__ */ jsx(Flex, { align: "center", height: "fill", justify: "center", padding: 4, sizing: "border", children: /* @__PURE__ */ jsx(Container, { width: 0, children: /* @__PURE__ */ jsx(Card, { padding: 4, radius: 2, shadow: 1, tone: "caution", children: /* @__PURE__ */ jsxs(Flex, { children: [
343
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }),
344
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, marginLeft: 3, space: 3, children: [
345
+ /* @__PURE__ */ jsx(Text, { as: "h1", size: 1, weight: "bold", children: error.name }),
346
+ /* @__PURE__ */ jsx(Text, { as: "p", muted: !0, size: 1, children: error.message })
347
+ ] })
348
+ ] }) }) }) }) });
505
349
  }
506
350
  const resolveUUID = Symbol();
507
- export { Iframe };
351
+ export {
352
+ Iframe
353
+ };
508
354
  //# sourceMappingURL=index.js.map