sanity-plugin-iframe-pane 2.3.0 → 2.3.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/lib/index.cjs +216 -0
- package/lib/index.cjs.js +3 -0
- package/lib/index.cjs.map +1 -0
- package/lib/{src/index.d.ts → index.d.ts} +2 -1
- package/lib/index.js +214 -1
- package/lib/index.js.map +1 -1
- package/package.json +53 -37
- package/src/Iframe.tsx +4 -5
- package/lib/index.esm.js +0 -1
- package/lib/index.esm.js.map +0 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Display any URL in a View Pane, along with helpful buttons to Copy the URL or op
|
|
|
7
7
|
|
|
8
8
|
Accepts either a string or an async function to resolve a URL based on the current document.
|
|
9
9
|
|
|
10
|
-

|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
@@ -23,7 +23,7 @@ yarn add sanity-plugin-iframe-pane
|
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
26
|
-
This is designed to be used as a [Component inside of a View](https://www.sanity.io/docs/structure-builder-reference#c0c8284844b7).
|
|
26
|
+
This is designed to be used as a [Component inside of a View](https://www.sanity.io/docs/structure-builder-reference#c0c8284844b7).
|
|
27
27
|
|
|
28
28
|
The simplest way to configure views is by customizing the `defaultDocumentNode` setting in the `deskTool()` plugin.
|
|
29
29
|
|
|
@@ -45,7 +45,6 @@ export default defineConfig({
|
|
|
45
45
|
A basic example of a custom `defaultDocumentNode` function, to only show the Iframe Pane on `movie` type documents.
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
-
|
|
49
48
|
// ./src/defaultDocumentNode.ts
|
|
50
49
|
|
|
51
50
|
import {DefaultDocumentNodeResolver} from 'sanity/desk'
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var icons = require('@sanity/icons');
|
|
5
|
+
var ui = require('@sanity/ui');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var usehooksTs = require('usehooks-ts');
|
|
8
|
+
const sizes = {
|
|
9
|
+
desktop: {
|
|
10
|
+
width: "100%",
|
|
11
|
+
height: "100%",
|
|
12
|
+
maxHeight: "100%"
|
|
13
|
+
},
|
|
14
|
+
mobile: {
|
|
15
|
+
width: 414,
|
|
16
|
+
height: "100%",
|
|
17
|
+
maxHeight: 736
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const DEFAULT_SIZE = "desktop";
|
|
21
|
+
function Iframe(props) {
|
|
22
|
+
const {
|
|
23
|
+
document: sanityDocument,
|
|
24
|
+
options
|
|
25
|
+
} = props;
|
|
26
|
+
const {
|
|
27
|
+
url,
|
|
28
|
+
defaultSize = DEFAULT_SIZE,
|
|
29
|
+
reload,
|
|
30
|
+
loader,
|
|
31
|
+
attributes = {},
|
|
32
|
+
showDisplayUrl = true
|
|
33
|
+
} = options;
|
|
34
|
+
const [displayUrl, setDisplayUrl] = react.useState(url && typeof url === "string" ? url : "");
|
|
35
|
+
const [iframeSize, setIframeSize] = react.useState((sizes == null ? void 0 : sizes[defaultSize]) ? defaultSize : DEFAULT_SIZE);
|
|
36
|
+
const [loading, setLoading] = react.useState(false);
|
|
37
|
+
const input = react.useRef(null);
|
|
38
|
+
const iframe = react.useRef(null);
|
|
39
|
+
const {
|
|
40
|
+
displayed
|
|
41
|
+
} = sanityDocument;
|
|
42
|
+
const [, copy] = usehooksTs.useCopyToClipboard();
|
|
43
|
+
function handleCopy() {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!((_a = input == null ? void 0 : input.current) == null ? void 0 : _a.value)) return;
|
|
46
|
+
copy(input.current.value);
|
|
47
|
+
}
|
|
48
|
+
function handleReload() {
|
|
49
|
+
if (!(iframe == null ? void 0 : iframe.current)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
iframe.current.src = iframe.current.src;
|
|
53
|
+
setLoading(true);
|
|
54
|
+
}
|
|
55
|
+
function handleIframeLoad() {
|
|
56
|
+
setLoading(false);
|
|
57
|
+
if (attributes.onLoad && typeof attributes.onLoad === "function") {
|
|
58
|
+
attributes.onLoad();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
react.useEffect(() => {
|
|
62
|
+
if ((reload == null ? void 0 : reload.revision) || (reload == null ? void 0 : reload.revision) == 0) {
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
handleReload();
|
|
65
|
+
}, Number(reload == null ? void 0 : reload.revision));
|
|
66
|
+
}
|
|
67
|
+
}, [displayed._rev, reload == null ? void 0 : reload.revision]);
|
|
68
|
+
react.useEffect(() => {
|
|
69
|
+
const getUrl = async () => {
|
|
70
|
+
setLoading(true);
|
|
71
|
+
const resolveUrl = typeof url === "function" ? await url(displayed) : "";
|
|
72
|
+
if (resolveUrl !== displayUrl && resolveUrl && typeof resolveUrl === "string") {
|
|
73
|
+
setDisplayUrl(resolveUrl);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
if (typeof url === "function") {
|
|
77
|
+
getUrl();
|
|
78
|
+
}
|
|
79
|
+
}, [displayed._rev]);
|
|
80
|
+
if (!displayUrl || typeof displayUrl !== "string") {
|
|
81
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.ThemeProvider, {
|
|
82
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
83
|
+
padding: 5,
|
|
84
|
+
align: "center",
|
|
85
|
+
justify: "center",
|
|
86
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return /* @__PURE__ */jsxRuntime.jsxs(ui.ThemeProvider, {
|
|
91
|
+
children: [/* @__PURE__ */jsxRuntime.jsx("textarea", {
|
|
92
|
+
style: {
|
|
93
|
+
position: "absolute",
|
|
94
|
+
pointerEvents: "none",
|
|
95
|
+
opacity: 0
|
|
96
|
+
},
|
|
97
|
+
ref: input,
|
|
98
|
+
value: displayUrl,
|
|
99
|
+
readOnly: true,
|
|
100
|
+
tabIndex: -1
|
|
101
|
+
}), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
102
|
+
direction: "column",
|
|
103
|
+
style: {
|
|
104
|
+
height: "100%"
|
|
105
|
+
},
|
|
106
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
107
|
+
padding: 2,
|
|
108
|
+
borderBottom: true,
|
|
109
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
110
|
+
align: "center",
|
|
111
|
+
gap: 2,
|
|
112
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
113
|
+
align: "center",
|
|
114
|
+
gap: 1,
|
|
115
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
116
|
+
fontSize: [1],
|
|
117
|
+
padding: 2,
|
|
118
|
+
tone: "primary",
|
|
119
|
+
mode: iframeSize === "mobile" ? "default" : "ghost",
|
|
120
|
+
icon: icons.MobileDeviceIcon,
|
|
121
|
+
onClick: () => setIframeSize(iframeSize === "mobile" ? "desktop" : "mobile")
|
|
122
|
+
})
|
|
123
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
124
|
+
flex: 1,
|
|
125
|
+
children: showDisplayUrl && /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
126
|
+
size: 0,
|
|
127
|
+
textOverflow: "ellipsis",
|
|
128
|
+
children: displayUrl
|
|
129
|
+
})
|
|
130
|
+
}), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
131
|
+
align: "center",
|
|
132
|
+
gap: 1,
|
|
133
|
+
children: [(reload == null ? void 0 : reload.button) ? /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
134
|
+
fontSize: [1],
|
|
135
|
+
padding: 2,
|
|
136
|
+
icon: icons.UndoIcon,
|
|
137
|
+
title: "Reload",
|
|
138
|
+
"aria-label": "Reload",
|
|
139
|
+
onClick: () => handleReload()
|
|
140
|
+
}) : null, /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
141
|
+
fontSize: [1],
|
|
142
|
+
icon: icons.CopyIcon,
|
|
143
|
+
padding: [2],
|
|
144
|
+
title: "Copy",
|
|
145
|
+
"aria-label": "Copy",
|
|
146
|
+
onClick: () => handleCopy()
|
|
147
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
148
|
+
fontSize: [1],
|
|
149
|
+
icon: icons.LeaveIcon,
|
|
150
|
+
padding: [2],
|
|
151
|
+
text: "Open",
|
|
152
|
+
tone: "primary",
|
|
153
|
+
onClick: () => window.open(displayUrl)
|
|
154
|
+
})]
|
|
155
|
+
})]
|
|
156
|
+
})
|
|
157
|
+
}), /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
158
|
+
tone: "transparent",
|
|
159
|
+
padding: iframeSize === "mobile" ? 2 : 0,
|
|
160
|
+
style: {
|
|
161
|
+
height: "100%"
|
|
162
|
+
},
|
|
163
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
164
|
+
align: "center",
|
|
165
|
+
justify: "center",
|
|
166
|
+
style: {
|
|
167
|
+
height: "100%",
|
|
168
|
+
position: "relative"
|
|
169
|
+
},
|
|
170
|
+
children: [loader && loading && /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
171
|
+
justify: "center",
|
|
172
|
+
align: "center",
|
|
173
|
+
style: {
|
|
174
|
+
inset: "0",
|
|
175
|
+
position: "absolute"
|
|
176
|
+
},
|
|
177
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
178
|
+
style: {
|
|
179
|
+
...sizes[iframeSize],
|
|
180
|
+
backgroundColor: "rgba(0,0,0,0.2)"
|
|
181
|
+
},
|
|
182
|
+
justify: "center",
|
|
183
|
+
align: "center",
|
|
184
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
185
|
+
padding: 4,
|
|
186
|
+
radius: 2,
|
|
187
|
+
shadow: 1,
|
|
188
|
+
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
189
|
+
align: "center",
|
|
190
|
+
direction: "column",
|
|
191
|
+
gap: 3,
|
|
192
|
+
height: "fill",
|
|
193
|
+
justify: "center",
|
|
194
|
+
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {}), loader && typeof loader === "string" && /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
195
|
+
size: 1,
|
|
196
|
+
children: loader
|
|
197
|
+
})]
|
|
198
|
+
})
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
}), /* @__PURE__ */jsxRuntime.jsx("iframe", {
|
|
202
|
+
ref: iframe,
|
|
203
|
+
title: "preview",
|
|
204
|
+
style: sizes[iframeSize],
|
|
205
|
+
frameBorder: "0",
|
|
206
|
+
src: displayUrl,
|
|
207
|
+
...attributes,
|
|
208
|
+
onLoad: handleIframeLoad
|
|
209
|
+
})]
|
|
210
|
+
})
|
|
211
|
+
})]
|
|
212
|
+
})]
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
module.exports = Iframe;
|
|
216
|
+
//# sourceMappingURL=index.cjs.map
|
package/lib/index.cjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/Iframe.tsx"],"sourcesContent":["/* eslint-disable react/jsx-no-bind */\nimport {CopyIcon, LeaveIcon, MobileDeviceIcon, UndoIcon} from '@sanity/icons'\nimport {Box, Button, Card, Flex, Spinner, Text, ThemeProvider} from '@sanity/ui'\nimport React, {useEffect, useRef, useState} from 'react'\nimport {HTMLAttributeReferrerPolicy} from 'react'\nimport {SanityDocumentLike} from 'sanity'\nimport {useCopyToClipboard} from 'usehooks-ts'\n\ntype Size = 'desktop' | 'mobile'\n\ntype SizeProps = {\n // eslint-disable-next-line no-unused-vars\n [key in Size]: {\n width: string | number\n height: string | number\n maxHeight: string | number\n }\n}\n\nconst sizes: SizeProps = {\n desktop: {\n width: `100%`,\n height: `100%`,\n maxHeight: `100%`,\n },\n mobile: {\n width: 414,\n height: `100%`,\n maxHeight: 736,\n },\n}\n\nexport type IframeOptions = {\n url: string | ((document: SanityDocumentLike) => unknown)\n defaultSize?: 'desktop' | 'mobile'\n loader?: boolean | string\n showDisplayUrl?: boolean\n reload: {\n revision: boolean | number\n button: boolean\n }\n attributes?: Partial<{\n allow: string\n referrerPolicy: HTMLAttributeReferrerPolicy | undefined\n sandbox: string\n onLoad: () => void\n }>\n}\n\nexport type IframeProps = {\n document: {\n displayed: SanityDocumentLike\n }\n options: IframeOptions\n}\n\nconst DEFAULT_SIZE = `desktop`\n\nfunction Iframe(props: IframeProps) {\n const {document: sanityDocument, options} = props\n const {\n url,\n defaultSize = DEFAULT_SIZE,\n reload,\n loader,\n attributes = {},\n showDisplayUrl = true,\n } = options\n const [displayUrl, setDisplayUrl] = useState(url && typeof url === 'string' ? url : ``)\n const [iframeSize, setIframeSize] = useState(sizes?.[defaultSize] ? defaultSize : DEFAULT_SIZE)\n const [loading, setLoading] = useState(false)\n const input = useRef<HTMLTextAreaElement>(null)\n const iframe = useRef<HTMLIFrameElement>(null)\n const {displayed} = sanityDocument\n const [, copy] = useCopyToClipboard()\n\n function handleCopy() {\n if (!input?.current?.value) return\n\n copy(input.current.value)\n }\n\n function handleReload() {\n if (!iframe?.current) {\n return\n }\n\n // Funky way to reload an iframe without CORS issuies\n // eslint-disable-next-line no-self-assign\n iframe.current.src = iframe.current.src\n\n setLoading(true)\n }\n\n function handleIframeLoad() {\n setLoading(false)\n // Run onLoad from attributes\n if (attributes.onLoad && typeof attributes.onLoad === 'function') {\n attributes.onLoad()\n }\n }\n\n // Reload on new revisions\n useEffect(() => {\n if (reload?.revision || reload?.revision == 0) {\n setTimeout(() => {\n handleReload()\n }, Number(reload?.revision))\n }\n }, [displayed._rev, reload?.revision])\n\n // Set initial URL and refresh on new revisions\n useEffect(() => {\n const getUrl = async () => {\n setLoading(true)\n const resolveUrl = typeof url === 'function' ? await url(displayed) : ``\n\n // Only update state if URL has changed\n if (resolveUrl !== displayUrl && resolveUrl && typeof resolveUrl === 'string') {\n setDisplayUrl(resolveUrl)\n }\n }\n\n if (typeof url === 'function') {\n getUrl()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [displayed._rev])\n\n if (!displayUrl || typeof displayUrl !== 'string') {\n return (\n <ThemeProvider>\n <Flex padding={5} align=\"center\" justify=\"center\">\n <Spinner />\n </Flex>\n </ThemeProvider>\n )\n }\n\n return (\n <ThemeProvider>\n <textarea\n style={{position: `absolute`, pointerEvents: `none`, opacity: 0}}\n ref={input}\n value={displayUrl}\n readOnly\n tabIndex={-1}\n />\n <Flex direction=\"column\" style={{height: `100%`}}>\n <Card padding={2} borderBottom>\n <Flex align=\"center\" gap={2}>\n <Flex align=\"center\" gap={1}>\n <Button\n fontSize={[1]}\n padding={2}\n tone=\"primary\"\n mode={iframeSize === 'mobile' ? 'default' : 'ghost'}\n icon={MobileDeviceIcon}\n onClick={() => setIframeSize(iframeSize === 'mobile' ? 'desktop' : 'mobile')}\n />\n </Flex>\n <Box flex={1}>\n {showDisplayUrl && (\n <Text size={0} textOverflow=\"ellipsis\">\n {displayUrl}\n </Text>\n )}\n </Box>\n <Flex align=\"center\" gap={1}>\n {reload?.button ? (\n <Button\n fontSize={[1]}\n padding={2}\n icon={UndoIcon}\n title=\"Reload\"\n aria-label=\"Reload\"\n onClick={() => handleReload()}\n />\n ) : null}\n <Button\n fontSize={[1]}\n icon={CopyIcon}\n padding={[2]}\n title=\"Copy\"\n aria-label=\"Copy\"\n onClick={() => handleCopy()}\n />\n <Button\n fontSize={[1]}\n icon={LeaveIcon}\n padding={[2]}\n text=\"Open\"\n tone=\"primary\"\n onClick={() => window.open(displayUrl)}\n />\n </Flex>\n </Flex>\n </Card>\n <Card tone=\"transparent\" padding={iframeSize === 'mobile' ? 2 : 0} style={{height: `100%`}}>\n <Flex align=\"center\" justify=\"center\" style={{height: `100%`, position: `relative`}}>\n {loader && loading && (\n <Flex justify=\"center\" align=\"center\" style={{inset: `0`, position: `absolute`}}>\n <Flex\n style={{...sizes[iframeSize], backgroundColor: `rgba(0,0,0,0.2)`}}\n justify=\"center\"\n align=\"center\"\n >\n <Card padding={4} radius={2} shadow={1}>\n <Flex align=\"center\" direction=\"column\" gap={3} height=\"fill\" justify=\"center\">\n <Spinner />\n {loader && typeof loader === 'string' && <Text size={1}>{loader}</Text>}\n </Flex>\n </Card>\n </Flex>\n </Flex>\n )}\n <iframe\n ref={iframe}\n title=\"preview\"\n style={sizes[iframeSize]}\n frameBorder=\"0\"\n src={displayUrl}\n {...attributes}\n onLoad={handleIframeLoad}\n />\n </Flex>\n </Card>\n </Flex>\n </ThemeProvider>\n )\n}\n\nexport default Iframe\n"],"names":["sizes","desktop","width","height","maxHeight","mobile","DEFAULT_SIZE","Iframe","props","document","sanityDocument","options","url","defaultSize","reload","loader","attributes","showDisplayUrl","displayUrl","setDisplayUrl","useState","iframeSize","setIframeSize","loading","setLoading","input","useRef","iframe","displayed","copy","useCopyToClipboard","handleCopy","_a","current","value","handleReload","src","handleIframeLoad","onLoad","useEffect","revision","setTimeout","Number","_rev","getUrl","resolveUrl","jsx","ThemeProvider","children","Flex","padding","align","justify","Spinner","style","position","pointerEvents","opacity","ref","readOnly","tabIndex","jsxs","direction","Card","borderBottom","gap","Button","fontSize","tone","mode","icon","MobileDeviceIcon","onClick","Box","flex","Text","size","textOverflow","button","UndoIcon","title","CopyIcon","LeaveIcon","text","window","open","inset","backgroundColor","radius","shadow","frameBorder"],"mappings":";;;;;;;AAmBA,MAAMA,KAAmB,GAAA;EACvBC,OAAS,EAAA;IACPC,KAAO,QAAA;IACPC,MAAQ,QAAA;IACRC,SAAW;EACb,CAAA;EACAC,MAAQ,EAAA;IACNH,KAAO,EAAA,GAAA;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AAMqB,UAAU,CAAA;gBAAGkE;cAAkC,CAAA;cAChEnC,OAAQ,EAAA,QAAA;cACRD,KAAM,EAAA,QAAA;cAENH,wCAACe,OAAK,EAAA;gBAAAb,OAAA,EAAS;gBAAGsC,MAAQ,EAAA,CAAA;gBAAGC,QAAQ,CACnC;gBAAAzC,QAAA,EAAA,eAAAa,UAAA,CAAAA,IAAA,CAACZ;kBAAKE,KAAM,EAAA,QAAA;kBAASW,WAAU,QAAS;kBAAAG,GAAA,EAAK;kBAAG9D,MAAO,EAAA,MAAA;kBAAOiD,SAAQ,QACpE;kBAAAJ,QAAA,EAAA,CAAA,eAAAF,UAAA,CAAAA,GAAA,CAACO,EAAQ,CAAAA,OAAA,EAAA,EAAA,CAAA,EACRtC,MAAA,IAAU,OAAOA,MAAW,KAAA,QAAA,IAAA,8BAAa4D,EAAAA,CAAAA,IAAK,EAAA;oBAAAC,IAAA,EAAM;oBAAI5B,QAAO,EAAAjC;mBAAA,CAAA;gBAAA,CAClE;cACF,CAAA;YAAA,CAAA;WAEJ,CAAA,EAAA,eAEF+B,UAAA,CAAAA,GAAA,CAAC,QAAA,EAAA;YACCY,GAAK,EAAA/B,MAAA;YACLqD,KAAM,EAAA,SAAA;YACN1B,KAAA,EAAOtD,MAAMqB,UAAU,CAAA;YACvBqE,WAAY,EAAA,GAAA;YACZtD,GAAK,EAAAlB,UAAA;YACJ,GAAGF,UAAA;YACJsB,MAAQ,EAAAD;UAAA,CACV,CAAA;QAAA,CACF;MACF,CAAA,CAAA;KACF,CAAA;EACF,CAAA,CAAA;AAEJ;"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {HTMLAttributeReferrerPolicy} from 'react'
|
|
2
|
+
import {JSX as JSX_2} from 'react/jsx-runtime'
|
|
2
3
|
import {SanityDocumentLike} from 'sanity'
|
|
3
4
|
|
|
4
|
-
declare function Iframe(props: IframeProps):
|
|
5
|
+
declare function Iframe(props: IframeProps): JSX_2.Element
|
|
5
6
|
export default Iframe
|
|
6
7
|
|
|
7
8
|
export declare type IframeOptions = IframeOptions_2
|
package/lib/index.js
CHANGED
|
@@ -1 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { MobileDeviceIcon, UndoIcon, CopyIcon, LeaveIcon } from '@sanity/icons';
|
|
3
|
+
import { ThemeProvider, Flex, Spinner, Card, Button, Box, Text } from '@sanity/ui';
|
|
4
|
+
import { useState, useRef, useEffect } from 'react';
|
|
5
|
+
import { useCopyToClipboard } from 'usehooks-ts';
|
|
6
|
+
const sizes = {
|
|
7
|
+
desktop: {
|
|
8
|
+
width: "100%",
|
|
9
|
+
height: "100%",
|
|
10
|
+
maxHeight: "100%"
|
|
11
|
+
},
|
|
12
|
+
mobile: {
|
|
13
|
+
width: 414,
|
|
14
|
+
height: "100%",
|
|
15
|
+
maxHeight: 736
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const DEFAULT_SIZE = "desktop";
|
|
19
|
+
function Iframe(props) {
|
|
20
|
+
const {
|
|
21
|
+
document: sanityDocument,
|
|
22
|
+
options
|
|
23
|
+
} = props;
|
|
24
|
+
const {
|
|
25
|
+
url,
|
|
26
|
+
defaultSize = DEFAULT_SIZE,
|
|
27
|
+
reload,
|
|
28
|
+
loader,
|
|
29
|
+
attributes = {},
|
|
30
|
+
showDisplayUrl = true
|
|
31
|
+
} = options;
|
|
32
|
+
const [displayUrl, setDisplayUrl] = useState(url && typeof url === "string" ? url : "");
|
|
33
|
+
const [iframeSize, setIframeSize] = useState((sizes == null ? void 0 : sizes[defaultSize]) ? defaultSize : DEFAULT_SIZE);
|
|
34
|
+
const [loading, setLoading] = useState(false);
|
|
35
|
+
const input = useRef(null);
|
|
36
|
+
const iframe = useRef(null);
|
|
37
|
+
const {
|
|
38
|
+
displayed
|
|
39
|
+
} = sanityDocument;
|
|
40
|
+
const [, copy] = useCopyToClipboard();
|
|
41
|
+
function handleCopy() {
|
|
42
|
+
var _a;
|
|
43
|
+
if (!((_a = input == null ? void 0 : input.current) == null ? void 0 : _a.value)) return;
|
|
44
|
+
copy(input.current.value);
|
|
45
|
+
}
|
|
46
|
+
function handleReload() {
|
|
47
|
+
if (!(iframe == null ? void 0 : iframe.current)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
iframe.current.src = iframe.current.src;
|
|
51
|
+
setLoading(true);
|
|
52
|
+
}
|
|
53
|
+
function handleIframeLoad() {
|
|
54
|
+
setLoading(false);
|
|
55
|
+
if (attributes.onLoad && typeof attributes.onLoad === "function") {
|
|
56
|
+
attributes.onLoad();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if ((reload == null ? void 0 : reload.revision) || (reload == null ? void 0 : reload.revision) == 0) {
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
handleReload();
|
|
63
|
+
}, Number(reload == null ? void 0 : reload.revision));
|
|
64
|
+
}
|
|
65
|
+
}, [displayed._rev, reload == null ? void 0 : reload.revision]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const getUrl = async () => {
|
|
68
|
+
setLoading(true);
|
|
69
|
+
const resolveUrl = typeof url === "function" ? await url(displayed) : "";
|
|
70
|
+
if (resolveUrl !== displayUrl && resolveUrl && typeof resolveUrl === "string") {
|
|
71
|
+
setDisplayUrl(resolveUrl);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
if (typeof url === "function") {
|
|
75
|
+
getUrl();
|
|
76
|
+
}
|
|
77
|
+
}, [displayed._rev]);
|
|
78
|
+
if (!displayUrl || typeof displayUrl !== "string") {
|
|
79
|
+
return /* @__PURE__ */jsx(ThemeProvider, {
|
|
80
|
+
children: /* @__PURE__ */jsx(Flex, {
|
|
81
|
+
padding: 5,
|
|
82
|
+
align: "center",
|
|
83
|
+
justify: "center",
|
|
84
|
+
children: /* @__PURE__ */jsx(Spinner, {})
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return /* @__PURE__ */jsxs(ThemeProvider, {
|
|
89
|
+
children: [/* @__PURE__ */jsx("textarea", {
|
|
90
|
+
style: {
|
|
91
|
+
position: "absolute",
|
|
92
|
+
pointerEvents: "none",
|
|
93
|
+
opacity: 0
|
|
94
|
+
},
|
|
95
|
+
ref: input,
|
|
96
|
+
value: displayUrl,
|
|
97
|
+
readOnly: true,
|
|
98
|
+
tabIndex: -1
|
|
99
|
+
}), /* @__PURE__ */jsxs(Flex, {
|
|
100
|
+
direction: "column",
|
|
101
|
+
style: {
|
|
102
|
+
height: "100%"
|
|
103
|
+
},
|
|
104
|
+
children: [/* @__PURE__ */jsx(Card, {
|
|
105
|
+
padding: 2,
|
|
106
|
+
borderBottom: true,
|
|
107
|
+
children: /* @__PURE__ */jsxs(Flex, {
|
|
108
|
+
align: "center",
|
|
109
|
+
gap: 2,
|
|
110
|
+
children: [/* @__PURE__ */jsx(Flex, {
|
|
111
|
+
align: "center",
|
|
112
|
+
gap: 1,
|
|
113
|
+
children: /* @__PURE__ */jsx(Button, {
|
|
114
|
+
fontSize: [1],
|
|
115
|
+
padding: 2,
|
|
116
|
+
tone: "primary",
|
|
117
|
+
mode: iframeSize === "mobile" ? "default" : "ghost",
|
|
118
|
+
icon: MobileDeviceIcon,
|
|
119
|
+
onClick: () => setIframeSize(iframeSize === "mobile" ? "desktop" : "mobile")
|
|
120
|
+
})
|
|
121
|
+
}), /* @__PURE__ */jsx(Box, {
|
|
122
|
+
flex: 1,
|
|
123
|
+
children: showDisplayUrl && /* @__PURE__ */jsx(Text, {
|
|
124
|
+
size: 0,
|
|
125
|
+
textOverflow: "ellipsis",
|
|
126
|
+
children: displayUrl
|
|
127
|
+
})
|
|
128
|
+
}), /* @__PURE__ */jsxs(Flex, {
|
|
129
|
+
align: "center",
|
|
130
|
+
gap: 1,
|
|
131
|
+
children: [(reload == null ? void 0 : reload.button) ? /* @__PURE__ */jsx(Button, {
|
|
132
|
+
fontSize: [1],
|
|
133
|
+
padding: 2,
|
|
134
|
+
icon: UndoIcon,
|
|
135
|
+
title: "Reload",
|
|
136
|
+
"aria-label": "Reload",
|
|
137
|
+
onClick: () => handleReload()
|
|
138
|
+
}) : null, /* @__PURE__ */jsx(Button, {
|
|
139
|
+
fontSize: [1],
|
|
140
|
+
icon: CopyIcon,
|
|
141
|
+
padding: [2],
|
|
142
|
+
title: "Copy",
|
|
143
|
+
"aria-label": "Copy",
|
|
144
|
+
onClick: () => handleCopy()
|
|
145
|
+
}), /* @__PURE__ */jsx(Button, {
|
|
146
|
+
fontSize: [1],
|
|
147
|
+
icon: LeaveIcon,
|
|
148
|
+
padding: [2],
|
|
149
|
+
text: "Open",
|
|
150
|
+
tone: "primary",
|
|
151
|
+
onClick: () => window.open(displayUrl)
|
|
152
|
+
})]
|
|
153
|
+
})]
|
|
154
|
+
})
|
|
155
|
+
}), /* @__PURE__ */jsx(Card, {
|
|
156
|
+
tone: "transparent",
|
|
157
|
+
padding: iframeSize === "mobile" ? 2 : 0,
|
|
158
|
+
style: {
|
|
159
|
+
height: "100%"
|
|
160
|
+
},
|
|
161
|
+
children: /* @__PURE__ */jsxs(Flex, {
|
|
162
|
+
align: "center",
|
|
163
|
+
justify: "center",
|
|
164
|
+
style: {
|
|
165
|
+
height: "100%",
|
|
166
|
+
position: "relative"
|
|
167
|
+
},
|
|
168
|
+
children: [loader && loading && /* @__PURE__ */jsx(Flex, {
|
|
169
|
+
justify: "center",
|
|
170
|
+
align: "center",
|
|
171
|
+
style: {
|
|
172
|
+
inset: "0",
|
|
173
|
+
position: "absolute"
|
|
174
|
+
},
|
|
175
|
+
children: /* @__PURE__ */jsx(Flex, {
|
|
176
|
+
style: {
|
|
177
|
+
...sizes[iframeSize],
|
|
178
|
+
backgroundColor: "rgba(0,0,0,0.2)"
|
|
179
|
+
},
|
|
180
|
+
justify: "center",
|
|
181
|
+
align: "center",
|
|
182
|
+
children: /* @__PURE__ */jsx(Card, {
|
|
183
|
+
padding: 4,
|
|
184
|
+
radius: 2,
|
|
185
|
+
shadow: 1,
|
|
186
|
+
children: /* @__PURE__ */jsxs(Flex, {
|
|
187
|
+
align: "center",
|
|
188
|
+
direction: "column",
|
|
189
|
+
gap: 3,
|
|
190
|
+
height: "fill",
|
|
191
|
+
justify: "center",
|
|
192
|
+
children: [/* @__PURE__ */jsx(Spinner, {}), loader && typeof loader === "string" && /* @__PURE__ */jsx(Text, {
|
|
193
|
+
size: 1,
|
|
194
|
+
children: loader
|
|
195
|
+
})]
|
|
196
|
+
})
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
}), /* @__PURE__ */jsx("iframe", {
|
|
200
|
+
ref: iframe,
|
|
201
|
+
title: "preview",
|
|
202
|
+
style: sizes[iframeSize],
|
|
203
|
+
frameBorder: "0",
|
|
204
|
+
src: displayUrl,
|
|
205
|
+
...attributes,
|
|
206
|
+
onLoad: handleIframeLoad
|
|
207
|
+
})]
|
|
208
|
+
})
|
|
209
|
+
})]
|
|
210
|
+
})]
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
export { Iframe as default };
|
|
214
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Iframe.tsx"],"sourcesContent":["/* eslint-disable react/jsx-no-bind */\nimport {CopyIcon, LeaveIcon, MobileDeviceIcon, UndoIcon} from '@sanity/icons'\nimport {Box, Button, Card, Flex, Spinner, Text, ThemeProvider} from '@sanity/ui'\nimport React, {useEffect, useRef, useState} from 'react'\nimport {HTMLAttributeReferrerPolicy} from 'react'\nimport {SanityDocumentLike} from 'sanity'\nimport {useCopyToClipboard} from 'usehooks-ts'\n\ntype Size = 'desktop' | 'mobile'\n\ntype SizeProps = {\n // eslint-disable-next-line no-unused-vars\n [key in Size]: {\n width: string | number\n height: string | number\n maxHeight: string | number\n }\n}\n\nconst sizes: SizeProps = {\n desktop: {\n width: `100%`,\n height: `100%`,\n maxHeight: `100%`,\n },\n mobile: {\n width: 414,\n height: `100%`,\n maxHeight: 736,\n },\n}\n\nexport type IframeOptions = {\n url: string | ((document: SanityDocumentLike) => unknown)\n defaultSize?: 'desktop' | 'mobile'\n loader?: boolean | string\n showDisplayUrl?: boolean\n reload: {\n revision: boolean | number\n button: boolean\n }\n attributes?: Partial<{\n allow: string\n referrerPolicy: HTMLAttributeReferrerPolicy | undefined\n sandbox: string\n onLoad: () => void\n }>\n}\n\nexport type IframeProps = {\n document: {\n displayed: SanityDocumentLike\n }\n options: IframeOptions\n}\n\nconst DEFAULT_SIZE = `desktop`\n\nfunction Iframe(props: IframeProps) {\n const {document: sanityDocument, options} = props\n const {\n url,\n defaultSize = DEFAULT_SIZE,\n reload,\n loader,\n attributes = {},\n showDisplayUrl = true,\n } = options\n const [displayUrl, setDisplayUrl] = useState(url && typeof url === 'string' ? url : ``)\n const [iframeSize, setIframeSize] = useState(sizes?.[defaultSize] ? defaultSize : DEFAULT_SIZE)\n const [loading, setLoading] = useState(false)\n const input = useRef<HTMLTextAreaElement>(null)\n const iframe = useRef<HTMLIFrameElement>(null)\n const {displayed} = sanityDocument\n const [, copy] = useCopyToClipboard()\n\n function handleCopy() {\n if (!input?.current?.value) return\n\n copy(input.current.value)\n }\n\n function handleReload() {\n if (!iframe?.current) {\n return\n }\n\n // Funky way to reload an iframe without CORS issuies\n // eslint-disable-next-line no-self-assign\n iframe.current.src = iframe.current.src\n\n setLoading(true)\n }\n\n function handleIframeLoad() {\n setLoading(false)\n // Run onLoad from attributes\n if (attributes.onLoad && typeof attributes.onLoad === 'function') {\n attributes.onLoad()\n }\n }\n\n // Reload on new revisions\n useEffect(() => {\n if (reload?.revision || reload?.revision == 0) {\n setTimeout(() => {\n handleReload()\n }, Number(reload?.revision))\n }\n }, [displayed._rev, reload?.revision])\n\n // Set initial URL and refresh on new revisions\n useEffect(() => {\n const getUrl = async () => {\n setLoading(true)\n const resolveUrl = typeof url === 'function' ? await url(displayed) : ``\n\n // Only update state if URL has changed\n if (resolveUrl !== displayUrl && resolveUrl && typeof resolveUrl === 'string') {\n setDisplayUrl(resolveUrl)\n }\n }\n\n if (typeof url === 'function') {\n getUrl()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [displayed._rev])\n\n if (!displayUrl || typeof displayUrl !== 'string') {\n return (\n <ThemeProvider>\n <Flex padding={5} align=\"center\" justify=\"center\">\n <Spinner />\n </Flex>\n </ThemeProvider>\n )\n }\n\n return (\n <ThemeProvider>\n <textarea\n style={{position: `absolute`, pointerEvents: `none`, opacity: 0}}\n ref={input}\n value={displayUrl}\n readOnly\n tabIndex={-1}\n />\n <Flex direction=\"column\" style={{height: `100%`}}>\n <Card padding={2} borderBottom>\n <Flex align=\"center\" gap={2}>\n <Flex align=\"center\" gap={1}>\n <Button\n fontSize={[1]}\n padding={2}\n tone=\"primary\"\n mode={iframeSize === 'mobile' ? 'default' : 'ghost'}\n icon={MobileDeviceIcon}\n onClick={() => setIframeSize(iframeSize === 'mobile' ? 'desktop' : 'mobile')}\n />\n </Flex>\n <Box flex={1}>\n {showDisplayUrl && (\n <Text size={0} textOverflow=\"ellipsis\">\n {displayUrl}\n </Text>\n )}\n </Box>\n <Flex align=\"center\" gap={1}>\n {reload?.button ? (\n <Button\n fontSize={[1]}\n padding={2}\n icon={UndoIcon}\n title=\"Reload\"\n aria-label=\"Reload\"\n onClick={() => handleReload()}\n />\n ) : null}\n <Button\n fontSize={[1]}\n icon={CopyIcon}\n padding={[2]}\n title=\"Copy\"\n aria-label=\"Copy\"\n onClick={() => handleCopy()}\n />\n <Button\n fontSize={[1]}\n icon={LeaveIcon}\n padding={[2]}\n text=\"Open\"\n tone=\"primary\"\n onClick={() => window.open(displayUrl)}\n />\n </Flex>\n </Flex>\n </Card>\n <Card tone=\"transparent\" padding={iframeSize === 'mobile' ? 2 : 0} style={{height: `100%`}}>\n <Flex align=\"center\" justify=\"center\" style={{height: `100%`, position: `relative`}}>\n {loader && loading && (\n <Flex justify=\"center\" align=\"center\" style={{inset: `0`, position: `absolute`}}>\n <Flex\n style={{...sizes[iframeSize], backgroundColor: `rgba(0,0,0,0.2)`}}\n justify=\"center\"\n align=\"center\"\n >\n <Card padding={4} radius={2} shadow={1}>\n <Flex align=\"center\" direction=\"column\" gap={3} height=\"fill\" justify=\"center\">\n <Spinner />\n {loader && typeof loader === 'string' && <Text size={1}>{loader}</Text>}\n </Flex>\n </Card>\n </Flex>\n </Flex>\n )}\n <iframe\n ref={iframe}\n title=\"preview\"\n style={sizes[iframeSize]}\n frameBorder=\"0\"\n src={displayUrl}\n {...attributes}\n onLoad={handleIframeLoad}\n />\n </Flex>\n </Card>\n </Flex>\n </ThemeProvider>\n )\n}\n\nexport default Iframe\n"],"names":["sizes","desktop","width","height","maxHeight","mobile","DEFAULT_SIZE","Iframe","props","document","sanityDocument","options","url","defaultSize","reload","loader","attributes","showDisplayUrl","displayUrl","setDisplayUrl","useState","iframeSize","setIframeSize","loading","setLoading","input","useRef","iframe","displayed","copy","useCopyToClipboard","handleCopy","_a","current","value","handleReload","src","handleIframeLoad","onLoad","useEffect","revision","setTimeout","Number","_rev","getUrl","resolveUrl","jsx","ThemeProvider","children","Flex","padding","align","justify","Spinner","style","position","pointerEvents","opacity","ref","readOnly","tabIndex","jsxs","direction","Card","borderBottom","gap","Button","fontSize","tone","mode","icon","MobileDeviceIcon","onClick","Box","flex","Text","size","textOverflow","button","UndoIcon","title","CopyIcon","LeaveIcon","text","window","open","inset","backgroundColor","radius","shadow","frameBorder"],"mappings":";;;;;AAmBA,MAAMA,KAAmB,GAAA;EACvBC,OAAS,EAAA;IACPC,KAAO,QAAA;IACPC,MAAQ,QAAA;IACRC,SAAW;EACb,CAAA;EACAC,MAAQ,EAAA;IACNH,KAAO,EAAA,GAAA;IACPC,MAAQ,QAAA;IACRC,SAAW,EAAA;EACb;AACF,CAAA;AA0BA,MAAME,YAAe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eAEF+B,GAAA,CAAC,QAAA,EAAA;YACCY,GAAK,EAAA/B,MAAA;YACLqD,KAAM,EAAA,SAAA;YACN1B,KAAA,EAAOtD,MAAMqB,UAAU,CAAA;YACvBqE,WAAY,EAAA,GAAA;YACZtD,GAAK,EAAAlB,UAAA;YACJ,GAAGF,UAAA;YACJsB,MAAQ,EAAAD;UAAA,CACV,CAAA;QAAA,CACF;MACF,CAAA,CAAA;KACF,CAAA;EACF,CAAA,CAAA;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-iframe-pane",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.1-beta.1",
|
|
4
4
|
"description": "Display any URL in a View Pane, along with helpful buttons to Copy the URL or open in a new tab",
|
|
5
5
|
"homepage": "https://github.com/sanity-io/sanity-plugin-iframe-pane#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -11,69 +11,85 @@
|
|
|
11
11
|
"url": "git@github.com:sanity-io/sanity-plugin-iframe-pane.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"author": "
|
|
14
|
+
"author": "Sanity.io <hello@sanity.io>",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"type": "module",
|
|
15
17
|
"exports": {
|
|
16
18
|
".": {
|
|
17
|
-
"types": "./lib/
|
|
19
|
+
"types": "./lib/index.d.ts",
|
|
18
20
|
"source": "./src/index.ts",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
21
|
+
"require": "./lib/index.cjs",
|
|
22
|
+
"node": {
|
|
23
|
+
"import": "./lib/index.cjs.js",
|
|
24
|
+
"require": "./lib/index.cjs"
|
|
25
|
+
},
|
|
26
|
+
"import": "./lib/index.js",
|
|
27
|
+
"default": "./lib/index.js"
|
|
22
28
|
},
|
|
23
29
|
"./package.json": "./package.json"
|
|
24
30
|
},
|
|
25
|
-
"main": "./lib/index.
|
|
26
|
-
"module": "./lib/index.
|
|
31
|
+
"main": "./lib/index.cjs",
|
|
32
|
+
"module": "./lib/index.js",
|
|
27
33
|
"source": "./src/index.ts",
|
|
28
|
-
"types": "./lib/
|
|
34
|
+
"types": "./lib/index.d.ts",
|
|
29
35
|
"files": [
|
|
30
36
|
"src",
|
|
31
37
|
"lib",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
38
|
+
"sanity.json",
|
|
39
|
+
"v2-incompatible.js"
|
|
34
40
|
],
|
|
35
41
|
"scripts": {
|
|
36
|
-
"
|
|
37
|
-
"build": "pkg-utils build --strict",
|
|
42
|
+
"build": "run-s clean && plugin-kit verify-package --silent && pkg-utils build --strict && pkg-utils --strict",
|
|
38
43
|
"clean": "rimraf lib",
|
|
44
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
39
45
|
"link-watch": "plugin-kit link-watch",
|
|
40
46
|
"lint": "eslint .",
|
|
41
|
-
"prepare": "husky install",
|
|
42
|
-
"prepublishOnly": "
|
|
43
|
-
"
|
|
47
|
+
"prepare": "husky install || true",
|
|
48
|
+
"prepublishOnly": "run-s build",
|
|
49
|
+
"test": "npm run lint && npm run type-check && npm run build",
|
|
50
|
+
"type-check": "tsc --noEmit",
|
|
51
|
+
"watch": "pkg-utils watch --strict"
|
|
44
52
|
},
|
|
45
53
|
"dependencies": {
|
|
46
54
|
"@sanity/icons": "^2.2.2",
|
|
47
|
-
"@sanity/incompatible-plugin": "^1.0.
|
|
48
|
-
"@sanity/ui": "^1.
|
|
49
|
-
"usehooks-ts": "
|
|
55
|
+
"@sanity/incompatible-plugin": "^1.0.0",
|
|
56
|
+
"@sanity/ui": "^1.0.0",
|
|
57
|
+
"usehooks-ts": "2.9.1"
|
|
50
58
|
},
|
|
51
59
|
"devDependencies": {
|
|
52
|
-
"@commitlint/cli": "^17.
|
|
53
|
-
"@commitlint/config-conventional": "^17.
|
|
54
|
-
"@sanity/pkg-utils": "^
|
|
55
|
-
"@sanity/plugin-kit": "^
|
|
56
|
-
"@sanity/semantic-release-preset": "^
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
58
|
-
"@typescript-eslint/parser": "^5.
|
|
59
|
-
"eslint": "^8.
|
|
60
|
-
"eslint-config-prettier": "^8.
|
|
60
|
+
"@commitlint/cli": "^17.6.3",
|
|
61
|
+
"@commitlint/config-conventional": "^17.6.3",
|
|
62
|
+
"@sanity/pkg-utils": "^2.2.16",
|
|
63
|
+
"@sanity/plugin-kit": "^3.1.7",
|
|
64
|
+
"@sanity/semantic-release-preset": "^4.1.1",
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
66
|
+
"@typescript-eslint/parser": "^5.59.7",
|
|
67
|
+
"eslint": "^8.36.0",
|
|
68
|
+
"eslint-config-prettier": "^8.7.0",
|
|
69
|
+
"eslint-config-react-app": "^7.0.1",
|
|
61
70
|
"eslint-config-sanity": "^6.0.0",
|
|
71
|
+
"eslint-plugin-import": "^2.27.5",
|
|
62
72
|
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
-
"eslint-plugin-react": "^7.
|
|
73
|
+
"eslint-plugin-react": "^7.32.2",
|
|
64
74
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
75
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
76
|
+
"husky": "^8.0.3",
|
|
77
|
+
"lint-staged": "^13.2.2",
|
|
78
|
+
"npm-run-all": "^4.1.5",
|
|
79
|
+
"prettier": "^2.8.8",
|
|
68
80
|
"prettier-plugin-packagejson": "^2.4.3",
|
|
69
|
-
"react": "^18",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
81
|
+
"react": "^18.2.0",
|
|
82
|
+
"react-dom": "^18.2.0",
|
|
83
|
+
"react-is": "^18.2.0",
|
|
84
|
+
"rimraf": "^5.0.1",
|
|
85
|
+
"sanity": "^3.11.1",
|
|
86
|
+
"styled-components": "^5.3.6",
|
|
87
|
+
"typescript": "^5.0.4"
|
|
73
88
|
},
|
|
74
89
|
"peerDependencies": {
|
|
75
90
|
"react": "^18",
|
|
76
|
-
"sanity": "^3
|
|
91
|
+
"sanity": "^3",
|
|
92
|
+
"styled-components": "^5.2"
|
|
77
93
|
},
|
|
78
94
|
"engines": {
|
|
79
95
|
"node": ">=14"
|
package/src/Iframe.tsx
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/* eslint-disable react/jsx-no-bind */
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {UndoIcon, CopyIcon, LeaveIcon, MobileDeviceIcon} from '@sanity/icons'
|
|
2
|
+
import {CopyIcon, LeaveIcon, MobileDeviceIcon, UndoIcon} from '@sanity/icons'
|
|
3
|
+
import {Box, Button, Card, Flex, Spinner, Text, ThemeProvider} from '@sanity/ui'
|
|
4
|
+
import React, {useEffect, useRef, useState} from 'react'
|
|
6
5
|
import {HTMLAttributeReferrerPolicy} from 'react'
|
|
7
|
-
|
|
6
|
+
import {SanityDocumentLike} from 'sanity'
|
|
8
7
|
import {useCopyToClipboard} from 'usehooks-ts'
|
|
9
8
|
|
|
10
9
|
type Size = 'desktop' | 'mobile'
|
package/lib/index.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function t(t){for(var i=1;i<arguments.length;i++){var r=null!=arguments[i]?arguments[i]:{};i%2?e(Object(r),!0).forEach((function(e){n(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}import{jsx as i,jsxs as r}from"react/jsx-runtime";import{useState as o,useRef as l,useEffect as c}from"react";import{ThemeProvider as a,Flex as u,Spinner as d,Card as s,Button as p,Box as f,Text as y}from"@sanity/ui";import{MobileDeviceIcon as g,UndoIcon as h,CopyIcon as m,LeaveIcon as b}from"@sanity/icons";import{useCopyToClipboard as v}from"usehooks-ts";const O={desktop:{width:"100%",height:"100%",maxHeight:"100%"},mobile:{width:414,height:"100%",maxHeight:736}},j="desktop";function w(e){const{document:n,options:w}=e,{url:P,defaultSize:k=j,reload:S,loader:x,attributes:z={},showDisplayUrl:C=!0}=w,[D,E]=o(P&&"string"==typeof P?P:""),[L,B]=o((null==O?void 0:O[k])?k:j),[H,N]=o(!1),R=l(null),T=l(null),{displayed:_}=n,[,I]=v();function U(){(null==T?void 0:T.current)&&(T.current.src=T.current.src,N(!0))}return c((()=>{((null==S?void 0:S.revision)||0==(null==S?void 0:S.revision))&&setTimeout((()=>{U()}),Number(null==S?void 0:S.revision))}),[_._rev,null==S?void 0:S.revision]),c((()=>{"function"==typeof P&&(async()=>{N(!0);const e="function"==typeof P?await P(_):"";e!==D&&e&&"string"==typeof e&&E(e)})()}),[_._rev]),D&&"string"==typeof D?r(a,{children:[i("textarea",{style:{position:"absolute",pointerEvents:"none",opacity:0},ref:R,value:D,readOnly:!0,tabIndex:-1}),r(u,{direction:"column",style:{height:"100%"},children:[i(s,{padding:2,borderBottom:!0,children:r(u,{align:"center",gap:2,children:[i(u,{align:"center",gap:1,children:i(p,{fontSize:[1],padding:2,tone:"primary",mode:"mobile"===L?"default":"ghost",icon:g,onClick:()=>B("mobile"===L?"desktop":"mobile")})}),i(f,{flex:1,children:C&&i(y,{size:0,textOverflow:"ellipsis",children:D})}),r(u,{align:"center",gap:1,children:[(null==S?void 0:S.button)?i(p,{fontSize:[1],padding:2,icon:h,title:"Reload","aria-label":"Reload",onClick:()=>U()}):null,i(p,{fontSize:[1],icon:m,padding:[2],title:"Copy","aria-label":"Copy",onClick:()=>{var e;(null==(e=null==R?void 0:R.current)?void 0:e.value)&&I(R.current.value)}}),i(p,{fontSize:[1],icon:b,padding:[2],text:"Open",tone:"primary",onClick:()=>window.open(D)})]})]})}),i(s,{tone:"transparent",padding:"mobile"===L?2:0,style:{height:"100%"},children:r(u,{align:"center",justify:"center",style:{height:"100%",position:"relative"},children:[x&&H&&i(u,{justify:"center",align:"center",style:{inset:"0",position:"absolute"},children:i(u,{style:t(t({},O[L]),{},{backgroundColor:"rgba(0,0,0,0.2)"}),justify:"center",align:"center",children:i(s,{padding:4,radius:2,shadow:1,children:r(u,{align:"center",direction:"column",gap:3,height:"fill",justify:"center",children:[i(d,{}),x&&"string"==typeof x&&i(y,{size:1,children:x})]})})})}),i("iframe",t(t({ref:T,title:"preview",style:O[L],frameBorder:"0",src:D},z),{},{onLoad:function(){N(!1),z.onLoad&&"function"==typeof z.onLoad&&z.onLoad()}}))]})})]})]}):i(a,{children:i(u,{padding:5,align:"center",justify:"center",children:i(d,{})})})}export{w as default};//# sourceMappingURL=index.esm.js.map
|
package/lib/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|