mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 16:15:22 +00:00
Allow to copy in embed (#4251)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@gitbook/embed": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Allow copying in embed
|
||||||
@@ -44,6 +44,16 @@ export function createGitBookFrame(iframe: HTMLIFrameElement): GitBookFrameClien
|
|||||||
if (!iframe.contentWindow) {
|
if (!iframe.contentWindow) {
|
||||||
throw new Error('Iframe must have a content window');
|
throw new Error('Iframe must have a content window');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const allowTokens = iframe.allow
|
||||||
|
.split(';')
|
||||||
|
.map((token) => token.trim())
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
if (!allowTokens.includes('clipboard-write')) {
|
||||||
|
iframe.allow = [...allowTokens, 'clipboard-write'].join('; ');
|
||||||
|
}
|
||||||
|
|
||||||
const channel = createChannel(iframe.contentWindow);
|
const channel = createChannel(iframe.contentWindow);
|
||||||
|
|
||||||
channel.receive((message: FrameToParentMessage) => {
|
channel.receive((message: FrameToParentMessage) => {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ export function GitBookFrame(props: GitBookFrameProps) {
|
|||||||
src={frameURL}
|
src={frameURL}
|
||||||
width="100%"
|
width="100%"
|
||||||
height="100%"
|
height="100%"
|
||||||
|
allow="clipboard-write"
|
||||||
className={className}
|
className={className}
|
||||||
style={colorScheme ? { colorScheme } : undefined}
|
style={colorScheme ? { colorScheme } : undefined}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ function getIframe() {
|
|||||||
widgetIframe?.remove();
|
widgetIframe?.remove();
|
||||||
widgetIframe = document.createElement('iframe');
|
widgetIframe = document.createElement('iframe');
|
||||||
widgetIframe.id = 'gitbook-widget-iframe';
|
widgetIframe.id = 'gitbook-widget-iframe';
|
||||||
|
widgetIframe.allow = 'clipboard-write';
|
||||||
if (frameOptions?.colorScheme) {
|
if (frameOptions?.colorScheme) {
|
||||||
widgetIframe.style.colorScheme = frameOptions.colorScheme;
|
widgetIframe.style.colorScheme = frameOptions.colorScheme;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user