Skip to content

Stackblitz #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -36,4 +36,8 @@ yarn-error.log*
# turbo
.turbo

.env
.env

.idea

.gitbook-dev.yaml
3 changes: 3 additions & 0 deletions integrations/stackblitz/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["@gitbook/eslint-config/integration"]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions integrations/stackblitz/gitbook-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: stackblitz
title: Stackblitz
icon: ./assets/stackblitz-logo.png
organization: the-delta-integrations
visibility: private
description: ''
script: src/index.tsx
scopes:
- space:content:read
- space:content:write
- space:metadata:read
- space:metadata:write
- space:views:read
blocks:
- id: diagram
title: Stackblitz
description: TODO Stackblitz Integration Description
markdown:
codeblock: stackblitz
body: content
secrets: {}
2,194 changes: 2,194 additions & 0 deletions integrations/stackblitz/package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions integrations/stackblitz/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "stackblitz",
"private": true,
"scripts": {
"lint": "eslint ./**/*.ts*",
"typecheck": "tsc --noEmit",
"publish-integrations-staging": "gitbook publish ."
},
"devDependencies": {
"@gitbook/api": "latest",
"@gitbook/cli": "^0.8.0",
"@gitbook/runtime": "latest"
},
"dependencies": {
"@stackblitz/sdk": "^1.9.0"
}
}
76 changes: 76 additions & 0 deletions integrations/stackblitz/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { createIntegration, createComponent } from '@gitbook/runtime';

import { fetchHTML } from './stackblitz';

const defaultContent = '//TODO: Starter Javascript Project';

const diagramBlock = createComponent<
{
content?: string;
},
{
content: string;
}
>({
componentId: 'diagram',
initialState: (props) => {
return {
content: props.content || defaultContent,
};
},
async render(element, { environment }) {
await fetchHTML();
const { editable } = element.context;
const { content } = element.state;

element.setCache({
maxAge: 86400,
});

const output = (
<webframe
source={{
url: environment.integration.urls.publicEndpoint,
}}
aspectRatio={16 / 9}
data={{
content: element.dynamicState('content'),
}}
/>
);

return (
<block>
{editable ? (
<codeblock
state="content"
content={content}
syntax="stackblitz"
onContentChange={{
action: '@editor.node.updateProps',
props: {
content: element.dynamicState('content'),
},
}}
footer={[output]}
/>
) : (
output
)}
</block>
);
},
});

// Required Form Fields

// project[title] = Project title
// project[description] = Project description
// project[files][FILE_PATH] = Contents of file, specify file path as key
// project[files][ANOTHER_FILE_PATH] = Contents of file, specify file path as key
// project[dependencies] = JSON string of dependencies field from package.json
// project[template] = Can be one of: typescript, angular-cli, create-react-app, javascript

export default createIntegration({
components: [diagramBlock],
});
34 changes: 34 additions & 0 deletions integrations/stackblitz/src/stackblitz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export const fetchHTML = async () => {
const html = `<html lang='en'>
<head></head>
<body>
<form id='mainForm' method='post' action='https://stackblitz.com/run' target='_self'>
<input type='hidden' name='project[files][index.ts]' value="import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';
import 'rxjs/add/operator/scan';
var button = document.querySelector('button');
Observable.fromEvent(button, 'click')
.scan((count: number) => count + 1, 0)
.subscribe(count => console.log(\`Clicked times\`));
">
<input type='hidden' name='project[files][index.html]' value='<button>Click Me</button>
'>
<input type='hidden' name='project[description]' value='RxJS Example'>
<input type='hidden' name='project[dependencies]' value='{&quot;rxjs&quot;:&quot;5.5.6&quot;}'>
<input type='hidden' name='project[template]' value='typescript'>
<input type='hidden' name='project[settings]' value='{&quot;compile&quot;:{&quot;clearConsole&quot;:false}}'>
</form>
<script>document.getElementById("mainForm").submit();</script>
</body>
</html>`;

const response = new Response(html, {
headers: {
'Content-Type': 'text/html',
'Cache-Control': 'public, max-age=86400',
},
});

return response;
};
3 changes: 3 additions & 0 deletions integrations/stackblitz/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@gitbook/tsconfig/integration.json"
}
968 changes: 964 additions & 4 deletions package-lock.json

Large diffs are not rendered by default.