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