sanity-plugin-iframe-pane 3.1.2 → 3.1.4

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,175 @@ 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
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: iframeSize === "mobile" ? "Exit mobile preview" : "Preview mobile viewport" }),
47
+ padding: 2,
48
+ placement: "bottom-start",
49
+ children: /* @__PURE__ */ jsx(
50
+ Button,
51
+ {
81
52
  disabled: !validUrl,
82
53
  fontSize: [1],
83
54
  padding: 2,
84
55
  mode: iframeSize === "mobile" ? "default" : "ghost",
85
56
  icon: MobileDeviceIcon,
86
57
  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
- }),
58
+ }
59
+ )
60
+ }
61
+ ) }),
62
+ /* @__PURE__ */ jsx(Box, { flex: 1, children: showUrl && validUrl && /* @__PURE__ */ jsx(DisplayUrl, { url }) }),
63
+ /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 1, children: [
64
+ reloadButton ? /* @__PURE__ */ jsx(
65
+ Tooltip,
66
+ {
67
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: reloading ? "Reloading\u2026" : "Reload" }),
105
68
  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
- }),
69
+ children: /* @__PURE__ */ jsx(
70
+ Button,
71
+ {
72
+ disabled: !validUrl,
73
+ mode: "bleed",
74
+ fontSize: [1],
75
+ padding: 2,
76
+ icon: RefreshIcon,
77
+ loading: reloading,
78
+ "aria-label": "Reload",
79
+ onClick: () => handleReload()
80
+ }
81
+ )
82
+ }
83
+ ) : null,
84
+ /* @__PURE__ */ jsx(
85
+ Tooltip,
86
+ {
87
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Copy URL" }),
124
88
  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
- });
89
+ children: /* @__PURE__ */ jsx(
90
+ Button,
91
+ {
92
+ mode: "bleed",
93
+ disabled: !validUrl,
94
+ fontSize: [1],
95
+ icon: CopyIcon,
96
+ padding: [2],
97
+ "aria-label": "Copy URL",
98
+ onClick: () => {
99
+ var _a;
100
+ (_a = input == null ? void 0 : input.current) != null && _a.value && (copy(input.current.value), pushToast({
101
+ closable: !0,
102
+ status: "success",
103
+ title: "The URL is copied to the clipboard"
104
+ }));
105
+ }
141
106
  }
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
- }),
107
+ )
108
+ }
109
+ ),
110
+ /* @__PURE__ */ jsx(
111
+ Tooltip,
112
+ {
113
+ content: /* @__PURE__ */ jsx(Text, { size: 1, style: { whiteSpace: "nowrap" }, children: "Open URL in a new tab" }),
151
114
  padding: 2,
152
115
  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
- });
116
+ children: /* @__PURE__ */ jsx(
117
+ Button,
118
+ {
119
+ disabled: !validUrl,
120
+ fontSize: [1],
121
+ icon: LaunchIcon,
122
+ mode: "ghost",
123
+ paddingY: [2],
124
+ text: "Open",
125
+ "aria-label": "Open URL in a new tab",
126
+ onClick: validUrl ? () => window.open(url.toString()) : void 0
127
+ }
128
+ )
129
+ }
130
+ )
131
+ ] })
132
+ ] }) })
133
+ ] });
168
134
  }
169
135
  const MotionFlex = motion(Flex);
170
136
  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
- }));
137
+ 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
138
  useEffect(() => {
189
139
  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
- }
140
+ }, [options.url]), useEffect(() => {
141
+ JSON.stringify({ key, draft }) !== JSON.stringify(draftSnapshot) && startTransition(() => setDraftSnapshot({ key, draft }));
201
142
  }, [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()));
143
+ const currentUser = useCurrentUser(), client = useClient({ apiVersion: "2023-10-16" }), [expiresAt, setExpiresAt] = useState(), previewSecretRef = useRef(), [isResolvingUrl, startTransition] = useTransition(), url = useCallback(
144
+ // eslint-disable-next-line @typescript-eslint/no-shadow
145
+ async (draft2) => {
146
+ if (typeof location > "u")
147
+ return;
148
+ const urlProp = urlRef.current;
149
+ if (typeof urlProp == "string")
150
+ return new URL(urlProp, location.origin);
151
+ if (typeof urlProp == "function") {
152
+ const url2 = await urlProp(draft2);
153
+ return typeof url2 == "string" ? new URL(url2, location.origin) : url2;
235
154
  }
236
- const resolvePreviewUrl = definePreviewUrl({
237
- origin: urlProp.origin === "same-origin" ? location.origin : urlProp.origin,
238
- preview,
239
- draftMode: {
240
- enable: urlProp.draftMode
155
+ if (typeof urlProp == "object") {
156
+ const preview = typeof urlProp.preview == "function" ? await urlProp.preview(draft2) : urlProp.preview;
157
+ if (typeof preview != "string")
158
+ return preview;
159
+ if (!previewSecretRef.current) {
160
+ const { secret, expiresAt: expiresAt2 } = await createPreviewSecret(
161
+ client,
162
+ "sanity-plugin-iframe-pane",
163
+ location.href,
164
+ currentUser == null ? void 0 : currentUser.id
165
+ );
166
+ previewSecretRef.current = secret, startTransition(() => setExpiresAt(expiresAt2.getTime()));
241
167
  }
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(() => {
168
+ const url2 = await definePreviewUrl({
169
+ origin: urlProp.origin === "same-origin" ? location.origin : urlProp.origin,
170
+ preview,
171
+ draftMode: {
172
+ enable: urlProp.draftMode
173
+ }
174
+ })({
175
+ client,
176
+ previewUrlSecret: previewSecretRef.current,
177
+ previewSearchParam: null
178
+ });
179
+ return new URL(url2, location.origin);
180
+ }
181
+ },
182
+ [client, currentUser == null ? void 0 : currentUser.id]
183
+ );
184
+ return useEffect(() => {
253
185
  if (expiresAt) {
254
- const timeout = setTimeout(() => {
255
- startTransition(() => setExpiresAt(void 0));
256
- previewSecretRef.current = void 0;
257
- }, Math.max(0, expiresAt - Date.now()));
186
+ const timeout = setTimeout(
187
+ () => {
188
+ startTransition(() => setExpiresAt(void 0)), previewSecretRef.current = void 0;
189
+ },
190
+ Math.max(0, expiresAt - Date.now())
191
+ );
258
192
  return () => clearTimeout(timeout);
259
193
  }
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, {
194
+ }, [expiresAt]), /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(Loading, { iframeSize: "desktop" }), children: /* @__PURE__ */ jsx(
195
+ IframeInner,
196
+ {
267
197
  _key: draftSnapshot.key,
268
198
  draftSnapshot: draftSnapshot.draft,
269
199
  url,
@@ -273,144 +203,107 @@ function Iframe(props) {
273
203
  reload,
274
204
  showDisplayUrl,
275
205
  userId: currentUser == null ? void 0 : currentUser.id
276
- }, draftSnapshot.key)
277
- });
206
+ },
207
+ draftSnapshot.key
208
+ ) });
278
209
  }
279
- const IframeInner = memo(function IframeInner2(props) {
210
+ const IframeInner = memo(function(props) {
280
211
  var _a;
281
212
  const {
282
213
  isResolvingUrl,
283
214
  defaultSize = DEFAULT_SIZE,
284
215
  reload,
285
216
  attributes = {},
286
- showDisplayUrl = true,
217
+ showDisplayUrl = !0,
287
218
  draftSnapshot,
288
219
  userId,
289
220
  expiresAt,
290
221
  _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);
222
+ } = props, [iframeSize, setIframeSize] = useState((_a = sizes) != null && _a[defaultSize] ? defaultSize : DEFAULT_SIZE), prefersReducedMotion = usePrefersReducedMotion(), url = suspend(
223
+ () => props.url(draftSnapshot),
224
+ [
225
+ // Cache based on a few specific conditions
226
+ "sanity-plugin-iframe-pane",
227
+ draftSnapshot,
228
+ userId,
229
+ expiresAt,
230
+ _key,
231
+ resolveUUID
232
+ ]
233
+ ), [loading, setLoading] = useState(!0), [_reloading, setReloading] = useState(!1), reloading = _reloading || isResolvingUrl, iframe = useRef(null), handleReload = useCallback(() => {
234
+ iframe != null && iframe.current && (iframe.current.src = iframe.current.src, setReloading(!0));
307
235
  }, []);
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, {
236
+ return /* @__PURE__ */ jsx(MotionConfig, { transition: prefersReducedMotion ? { duration: 0 } : void 0, children: /* @__PURE__ */ jsxs(Flex, { direction: "column", style: { height: "100%" }, children: [
237
+ /* @__PURE__ */ jsx(
238
+ Toolbar,
239
+ {
318
240
  url,
319
241
  iframeSize,
320
242
  reloading,
321
243
  setIframeSize,
322
244
  showUrl: showDisplayUrl,
323
- reloadButton: !!(reload == null ? void 0 : reload.button),
245
+ reloadButton: !!(reload != null && reload.button),
324
246
  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;
247
+ }
248
+ ),
249
+ url instanceof Error ? /* @__PURE__ */ jsx(ErrorCard, { error: url }) : /* @__PURE__ */ jsx(Card, { tone: "transparent", style: { height: "100%" }, children: /* @__PURE__ */ jsx(
250
+ Frame,
251
+ {
252
+ ref: iframe,
253
+ loading,
254
+ reloading,
255
+ iframeSize,
256
+ setReloading,
257
+ setLoading,
258
+ url,
259
+ attributes
260
+ }
261
+ ) })
262
+ ] }) });
263
+ }), Frame = forwardRef(function(props, iframe) {
264
+ const { loading, setLoading, iframeSize, attributes, reloading, url, setReloading } = props;
356
265
  function handleIframeLoad() {
357
- setLoading(false);
358
- setReloading(false);
359
- if (attributes.onLoad && typeof attributes.onLoad === "function") {
360
- attributes.onLoad();
361
- }
266
+ setLoading(!1), setReloading(!1), attributes.onLoad && typeof attributes.onLoad == "function" && attributes.onLoad();
362
267
  }
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, {
268
+ return /* @__PURE__ */ jsxs(Flex, { align: "center", justify: "center", style: { height: "100%", position: "relative" }, children: [
269
+ /* @__PURE__ */ jsx(AnimatePresence, { children: !url || loading && /* @__PURE__ */ jsx(
270
+ MotionFlex,
271
+ {
372
272
  initial: "initial",
373
273
  animate: "animate",
374
274
  exit: "exit",
375
275
  variants: spinnerVariants,
376
276
  justify: "center",
377
277
  align: "center",
378
- style: {
379
- inset: "0",
380
- position: "absolute"
381
- },
382
- children: /* @__PURE__ */jsx(Loading, {
278
+ style: { inset: "0", position: "absolute" },
279
+ children: /* @__PURE__ */ jsx(Loading, { iframeSize })
280
+ }
281
+ ) }),
282
+ url && /* @__PURE__ */ jsx(
283
+ motion.iframe,
284
+ {
285
+ ref: iframe,
286
+ title: "preview",
287
+ frameBorder: "0",
288
+ style: { maxHeight: "100%" },
289
+ src: url.toString(),
290
+ initial: ["background", iframeSize],
291
+ variants: iframeVariants,
292
+ animate: [
293
+ loading ? "background" : "active",
294
+ reloading ? "reloading" : "idle",
383
295
  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 = {
296
+ ],
297
+ ...attributes,
298
+ onLoad: handleIframeLoad
299
+ }
300
+ )
301
+ ] });
302
+ }), spinnerVariants = {
303
+ initial: { opacity: 1 },
304
+ animate: { opacity: [0, 0, 1] },
305
+ exit: { opacity: [1, 0, 0] }
306
+ }, iframeVariants = {
414
307
  ...sizes,
415
308
  desktop: {
416
309
  ...sizes.desktop,
@@ -435,74 +328,23 @@ const iframeVariants = {
435
328
  scale: 1
436
329
  }
437
330
  };
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
- });
331
+ function Loading({ iframeSize }) {
332
+ return /* @__PURE__ */ jsxs(Flex, { style: { ...sizes[iframeSize] }, justify: "center", align: "center", direction: "column", gap: 4, children: [
333
+ /* @__PURE__ */ jsx(Spinner, { muted: !0 }),
334
+ /* @__PURE__ */ jsx(Text, { muted: !0, size: 1, children: "Loading\u2026" })
335
+ ] });
458
336
  }
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
- });
337
+ function ErrorCard({ error }) {
338
+ 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: [
339
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(Text, { size: 1, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }) }),
340
+ /* @__PURE__ */ jsxs(Stack, { flex: 1, marginLeft: 3, space: 3, children: [
341
+ /* @__PURE__ */ jsx(Text, { as: "h1", size: 1, weight: "bold", children: error.name }),
342
+ /* @__PURE__ */ jsx(Text, { as: "p", muted: !0, size: 1, children: error.message })
343
+ ] })
344
+ ] }) }) }) }) });
505
345
  }
506
346
  const resolveUUID = Symbol();
507
- export { Iframe };
347
+ export {
348
+ Iframe
349
+ };
508
350
  //# sourceMappingURL=index.js.map