-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cross-origin isolation flag (#20)
- Loading branch information
1 parent
b55124d
commit 008665a
Showing
14 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
{ | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"tabWidth": 2, | ||
"endOfLine": "lf", | ||
"semi": true, | ||
"arrowParens": "always", | ||
"bracketSpacing": true, | ||
"trailingComma": "es5" | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"tabWidth": 2, | ||
"endOfLine": "lf", | ||
"semi": true, | ||
"arrowParens": "always", | ||
"bracketSpacing": true, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>StackBlitz SDK - Open and embed a StackBlitz WebContainer project</title> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<script type="module" src="./index.ts"></script> | ||
</head> | ||
<body> | ||
<header> | ||
<h1>Open and embed a StackBlitz WebContainer project</h1> | ||
<div> | ||
<label> | ||
<input type="checkbox" name="corp" /> Cross-Origin Isolation | ||
</label> | ||
</div> | ||
<nav> | ||
<button type="button" name="embed-project">Embed project</button> | ||
<button type="button" name="open-project">Open project</button> | ||
</nav> | ||
</header> | ||
<div id="embed"> | ||
<p>Embed will go here</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import sdk from '@stackblitz/sdk'; | ||
|
||
import './styles.css'; | ||
|
||
// This opens https://stackblitz.com/edit/node | ||
// in the current window with the Preview pane | ||
function openProject() { | ||
sdk.openProjectId('node', { | ||
newWindow: false, | ||
view: 'preview', | ||
}); | ||
} | ||
|
||
// This replaces the HTML element with | ||
// the id of "embed" with https://stackblitz.com/edit/node embedded in an iframe. | ||
function embedProject() { | ||
sdk.embedProjectId('embed', 'node', { | ||
openFile: 'index.ts', | ||
crossOriginIsolated: true, | ||
}); | ||
} | ||
|
||
function toggleCorp(event: Event) { | ||
const queryParams = new URLSearchParams(window.location.search); | ||
const isChecked = (event.target as any)?.checked; | ||
|
||
if (isChecked) { | ||
if (!queryParams.has('corp') || queryParams.get('corp') !== '1') { | ||
queryParams.set('corp', '1'); | ||
} | ||
} else { | ||
queryParams.delete('corp'); | ||
} | ||
|
||
window.location.search = queryParams.toString(); | ||
} | ||
|
||
function setup() { | ||
const embedButton = document.querySelector('[name=embed-project]') as HTMLButtonElement; | ||
const openButton = document.querySelector('[name=open-project]') as HTMLButtonElement; | ||
const corpCheckbox = document.querySelector('[name=corp]') as HTMLInputElement; | ||
|
||
embedButton.addEventListener('click', embedProject); | ||
openButton.addEventListener('click', openProject); | ||
corpCheckbox.addEventListener('change', toggleCorp); | ||
|
||
// mark the checkbox checked if the corp param is already set | ||
const queryParams = new URLSearchParams(window.location.search); | ||
|
||
corpCheckbox.checked = queryParams.get('corp') === '1'; | ||
} | ||
|
||
setup(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "sdk-example-open-embed-webcontainer", | ||
"description": "Demo of the StackBlitz SDK's methods for opening & embedding an existing StackBlitz WebContainer project", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@stackblitz/sdk": "^1.8.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
html { | ||
height: 100%; | ||
text-align: center; | ||
font-family: system-ui, sans-serif; | ||
color: black; | ||
background-color: white; | ||
} | ||
|
||
body { | ||
height: 100%; | ||
margin: 0; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
h1 { | ||
margin: 1rem; | ||
font-size: 1.25rem; | ||
} | ||
|
||
nav { | ||
margin: 1rem; | ||
font-size: 0.9rem; | ||
} | ||
|
||
button { | ||
margin: 0.2em; | ||
padding: 0.2em 0.5em; | ||
font-size: inherit; | ||
font-family: inherit; | ||
} | ||
|
||
#embed { | ||
display: flex; | ||
flex: 1 1 60%; | ||
flex-direction: column; | ||
justify-content: center; | ||
overflow: hidden; | ||
width: 100%; | ||
height: auto; | ||
margin: 0; | ||
border: 0; | ||
} | ||
|
||
#embed > p { | ||
width: min(300px, 100%); | ||
margin: 2rem auto; | ||
padding: 4rem 1rem; | ||
border: dashed 2px #ccc; | ||
border-radius: 0.5em; | ||
font-size: 85%; | ||
color: #777; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters