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