diff --git a/integrations/sandpack/.eslintrc.json b/integrations/sandpack/.eslintrc.json new file mode 100644 index 000000000..99e7792b9 --- /dev/null +++ b/integrations/sandpack/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": ["@gitbook/eslint-config/integration"] +} \ No newline at end of file diff --git a/integrations/sandpack/gitbook-manifest.yaml b/integrations/sandpack/gitbook-manifest.yaml new file mode 100644 index 000000000..55c222478 --- /dev/null +++ b/integrations/sandpack/gitbook-manifest.yaml @@ -0,0 +1,17 @@ +name: sandpack +title: Sandpack +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: sandpack + title: Sandpack + description: TODO Sandpack description +secrets: {} diff --git a/integrations/sandpack/package.json b/integrations/sandpack/package.json new file mode 100644 index 000000000..c211e8904 --- /dev/null +++ b/integrations/sandpack/package.json @@ -0,0 +1,18 @@ +{ + "name": "sandpack", + "private": true, + "scripts": { + "lint": "eslint ./**/*.ts*", + "typecheck": "tsc --noEmit", + "publish-integrations-staging": "gitbook publish ." + }, + "devDependencies": { + "@gitbook/cli": "^0.8.0", + "@gitbook/runtime": "latest" + }, + "dependencies": { + "@codesandbox/sandpack-client": "^2.6.7", + "@gitbook/api": "^0.3.0", + "static-browser-server": "^1.0.5" + } +} diff --git a/integrations/sandpack/src/index.tsx b/integrations/sandpack/src/index.tsx new file mode 100644 index 000000000..8a780fd08 --- /dev/null +++ b/integrations/sandpack/src/index.tsx @@ -0,0 +1,26 @@ +import { createComponent, createIntegration, RuntimeContext } from '@gitbook/runtime'; + +import { getPreviewUrl } from './sandpack'; + +const embedBlock = createComponent<{ url?: string }, {}, {}, RuntimeContext>({ + componentId: 'sandpack', + + async render(element, context) { + const previewUrl = await getPreviewUrl(); + + return ( + + + + ); + }, +}); + +export default createIntegration({ + components: [embedBlock], +}); diff --git a/integrations/sandpack/src/sandpack.ts b/integrations/sandpack/src/sandpack.ts new file mode 100644 index 000000000..6c9adf8eb --- /dev/null +++ b/integrations/sandpack/src/sandpack.ts @@ -0,0 +1,19 @@ +import { PreviewController } from 'static-browser-server'; + +export const getPreviewUrl = async () => { + const files = new Map([['index.html', 'Hello world!']]); + + const controller = new PreviewController({ + baseUrl: 'https://preview.sandpack-static-server.codesandbox.io', + // Function to get the file content for the server this can also be async + getFileContent: (filepath) => { + const content = files.get(filepath); + if (!content) { + throw new Error('File not found'); + } + return content; + }, + }); + + return await controller.initPreview(); +}; diff --git a/integrations/sandpack/tsconfig.json b/integrations/sandpack/tsconfig.json new file mode 100644 index 000000000..f839d1833 --- /dev/null +++ b/integrations/sandpack/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@gitbook/tsconfig/integration.json" +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 283b57e9e..34fba58bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -709,6 +709,7 @@ } }, "integrations/gitlab": { + "name": "@gitbook/integration-gitlab", "version": "0.1.0", "dependencies": { "@gitbook/runtime": "latest", @@ -751,6 +752,7 @@ } }, "integrations/heap": { + "name": "@gitbook/integration-heap", "version": "0.0.1", "dependencies": { "@gitbook/api": "*", @@ -761,6 +763,7 @@ } }, "integrations/hotjar": { + "name": "@gitbook/integration-hotjar", "version": "0.0.1", "dependencies": { "@gitbook/api": "*", @@ -952,6 +955,48 @@ "node": ">=12" } }, + "integrations/sandpack": { + "dependencies": { + "@codesandbox/sandpack-client": "^2.6.7", + "@gitbook/api": "^0.3.0", + "static-browser-server": "^1.0.5" + }, + "devDependencies": { + "@gitbook/cli": "^0.8.0", + "@gitbook/runtime": "latest" + } + }, + "integrations/sandpack/node_modules/@gitbook/runtime": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@gitbook/runtime/-/runtime-0.3.0.tgz", + "integrity": "sha512-CEXiPtvk2v8BJ//Ie5O4/oW4RhtXHiq0RRMxjDGGeGdVU0nh3foLBmGezPzLBFLT6VoYkBzQilYThJFE/EpgeQ==", + "dev": true, + "dependencies": { + "@gitbook/api": "*" + } + }, + "integrations/sandpack/node_modules/dotenv": { + "version": "16.1.4", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", + "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, + "integrations/sandpack/node_modules/static-browser-server": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/static-browser-server/-/static-browser-server-1.0.5.tgz", + "integrity": "sha512-TMRqt1O/qHVJK8lG+cu65+PzgBdloOIpA+mpox+I0fwV0uhLn7dEkYG6UG+7ytZqXZCcBSSyZxELGR2QnWuoLA==", + "dependencies": { + "@open-draft/deferred-promise": "^2.1.0", + "dotenv": "^16.0.3", + "mime-db": "^1.52.0", + "outvariant": "^1.3.0" + } + }, "integrations/segment": { "name": "@gitbook/integration-segment", "version": "1.0.0", @@ -994,6 +1039,7 @@ } }, "integrations/toucantoco": { + "name": "@gitbook/integration-toucantoco", "version": "1.0.0", "dependencies": { "@gitbook/api": "*", @@ -2815,6 +2861,50 @@ "dev": true, "license": "BSD-3-Clause" }, + "node_modules/@codesandbox/nodebox": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/@codesandbox/nodebox/-/nodebox-0.1.8.tgz", + "integrity": "sha512-2VRS6JDSk+M+pg56GA6CryyUSGPjBEe8Pnae0QL3jJF1mJZJVMDKr93gJRtBbLkfZN6LD/DwMtf+2L0bpWrjqg==", + "dependencies": { + "outvariant": "^1.4.0", + "strict-event-emitter": "^0.4.3" + } + }, + "node_modules/@codesandbox/sandpack-client": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/@codesandbox/sandpack-client/-/sandpack-client-2.6.7.tgz", + "integrity": "sha512-uihzc0EnEE+C0Nw/WzP03drj0nPeMMKWZt2HwHNjyapnku/J7CB57EuiaVu7oVhacHhnDgwPOMPdbYhQWVrRXg==", + "dependencies": { + "@codesandbox/nodebox": "0.1.8", + "buffer": "^6.0.3", + "dequal": "^2.0.2", + "outvariant": "1.4.0", + "static-browser-server": "1.0.3" + } + }, + "node_modules/@codesandbox/sandpack-client/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "dev": true, @@ -4551,6 +4641,11 @@ "node": ">= 8" } }, + "node_modules/@open-draft/deferred-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@open-draft/deferred-promise/-/deferred-promise-2.1.0.tgz", + "integrity": "sha512-Rzd5JrXZX8zErHzgcGyngh4fmEbSHqTETdGj9rXtejlqMIgXFlyKBA7Jn1Xp0Ls0M0Y22+xHcWiEzbmdWl0BOA==" + }, "node_modules/@openapi-contrib/openapi-schema-to-json-schema": { "version": "3.1.2", "license": "MIT", @@ -6177,6 +6272,14 @@ "node": ">= 0.6.0" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "engines": { + "node": ">=6" + } + }, "node_modules/detect-indent": { "version": "6.1.0", "license": "MIT", @@ -9787,6 +9890,11 @@ "version": "0.5.0", "license": "MIT" }, + "node_modules/outvariant": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.0.tgz", + "integrity": "sha512-AlWY719RF02ujitly7Kk/0QlV+pXGFDHrHf9O2OKqyqgBieaPOIeuSkL8sRK6j2WK+/ZAURq2kZsY0d8JapUiw==" + }, "node_modules/p-filter": { "version": "2.1.0", "license": "MIT", @@ -10718,6 +10826,10 @@ "version": "2.1.2", "license": "MIT" }, + "node_modules/sandpack": { + "resolved": "integrations/sandpack", + "link": true + }, "node_modules/scuid": { "version": "1.1.0", "dev": true, @@ -11165,6 +11277,28 @@ "node": "*" } }, + "node_modules/static-browser-server": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/static-browser-server/-/static-browser-server-1.0.3.tgz", + "integrity": "sha512-ZUyfgGDdFRbZGGJQ1YhiM930Yczz5VlbJObrQLlk24+qNHVQx4OlLcYswEUo3bIyNAbQUIUR9Yr5/Hqjzqb4zA==", + "dependencies": { + "@open-draft/deferred-promise": "^2.1.0", + "dotenv": "^16.0.3", + "mime-db": "^1.52.0", + "outvariant": "^1.3.0" + } + }, + "node_modules/static-browser-server/node_modules/dotenv": { + "version": "16.1.4", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", + "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, "node_modules/stdin-discarder": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.1.0.tgz", @@ -11226,6 +11360,11 @@ "node": ">=10.0.0" } }, + "node_modules/strict-event-emitter": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.4.6.tgz", + "integrity": "sha512-12KWeb+wixJohmnwNFerbyiBrAlq5qJLwIt38etRtKtmmHyDSoGlIqFE9wx+4IwG0aDjI7GV8tc8ZccjWZZtTg==" + }, "node_modules/string_decoder": { "version": "1.3.0", "license": "MIT", @@ -14168,6 +14307,38 @@ "version": "3.16.0", "dev": true }, + "@codesandbox/nodebox": { + "version": "0.1.8", + "resolved": "https://registry.npmjs.org/@codesandbox/nodebox/-/nodebox-0.1.8.tgz", + "integrity": "sha512-2VRS6JDSk+M+pg56GA6CryyUSGPjBEe8Pnae0QL3jJF1mJZJVMDKr93gJRtBbLkfZN6LD/DwMtf+2L0bpWrjqg==", + "requires": { + "outvariant": "^1.4.0", + "strict-event-emitter": "^0.4.3" + } + }, + "@codesandbox/sandpack-client": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/@codesandbox/sandpack-client/-/sandpack-client-2.6.7.tgz", + "integrity": "sha512-uihzc0EnEE+C0Nw/WzP03drj0nPeMMKWZt2HwHNjyapnku/J7CB57EuiaVu7oVhacHhnDgwPOMPdbYhQWVrRXg==", + "requires": { + "@codesandbox/nodebox": "0.1.8", + "buffer": "^6.0.3", + "dequal": "^2.0.2", + "outvariant": "1.4.0", + "static-browser-server": "1.0.3" + }, + "dependencies": { + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + } + } + }, "@cspotcode/source-map-support": { "version": "0.8.1", "dev": true, @@ -16325,6 +16496,11 @@ "fastq": "^1.6.0" } }, + "@open-draft/deferred-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@open-draft/deferred-promise/-/deferred-promise-2.1.0.tgz", + "integrity": "sha512-Rzd5JrXZX8zErHzgcGyngh4fmEbSHqTETdGj9rXtejlqMIgXFlyKBA7Jn1Xp0Ls0M0Y22+xHcWiEzbmdWl0BOA==" + }, "@openapi-contrib/openapi-schema-to-json-schema": { "version": "3.1.2", "requires": { @@ -17361,6 +17537,11 @@ "dependency-graph": { "version": "0.11.0" }, + "dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==" + }, "detect-indent": { "version": "6.1.0" }, @@ -19510,6 +19691,11 @@ "outdent": { "version": "0.5.0" }, + "outvariant": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.0.tgz", + "integrity": "sha512-AlWY719RF02ujitly7Kk/0QlV+pXGFDHrHf9O2OKqyqgBieaPOIeuSkL8sRK6j2WK+/ZAURq2kZsY0d8JapUiw==" + }, "p-filter": { "version": "2.1.0", "requires": { @@ -20060,6 +20246,43 @@ "safer-buffer": { "version": "2.1.2" }, + "sandpack": { + "version": "file:integrations/sandpack", + "requires": { + "@codesandbox/sandpack-client": "^2.6.7", + "@gitbook/api": "^0.3.0", + "@gitbook/cli": "^0.8.0", + "@gitbook/runtime": "latest", + "static-browser-server": "^1.0.5" + }, + "dependencies": { + "@gitbook/runtime": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@gitbook/runtime/-/runtime-0.3.0.tgz", + "integrity": "sha512-CEXiPtvk2v8BJ//Ie5O4/oW4RhtXHiq0RRMxjDGGeGdVU0nh3foLBmGezPzLBFLT6VoYkBzQilYThJFE/EpgeQ==", + "dev": true, + "requires": { + "@gitbook/api": "*" + } + }, + "dotenv": { + "version": "16.1.4", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", + "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==" + }, + "static-browser-server": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/static-browser-server/-/static-browser-server-1.0.5.tgz", + "integrity": "sha512-TMRqt1O/qHVJK8lG+cu65+PzgBdloOIpA+mpox+I0fwV0uhLn7dEkYG6UG+7ytZqXZCcBSSyZxELGR2QnWuoLA==", + "requires": { + "@open-draft/deferred-promise": "^2.1.0", + "dotenv": "^16.0.3", + "mime-db": "^1.52.0", + "outvariant": "^1.3.0" + } + } + } + }, "scuid": { "version": "1.1.0", "dev": true @@ -20385,6 +20608,24 @@ "version": "0.0.10", "dev": true }, + "static-browser-server": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/static-browser-server/-/static-browser-server-1.0.3.tgz", + "integrity": "sha512-ZUyfgGDdFRbZGGJQ1YhiM930Yczz5VlbJObrQLlk24+qNHVQx4OlLcYswEUo3bIyNAbQUIUR9Yr5/Hqjzqb4zA==", + "requires": { + "@open-draft/deferred-promise": "^2.1.0", + "dotenv": "^16.0.3", + "mime-db": "^1.52.0", + "outvariant": "^1.3.0" + }, + "dependencies": { + "dotenv": { + "version": "16.1.4", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.1.4.tgz", + "integrity": "sha512-m55RtE8AsPeJBpOIFKihEmqUcoVncQIwo7x9U8ZwLEZw9ZpXboz2c+rvog+jUaJvVrZ5kBOeYQBX5+8Aa/OZQw==" + } + } + }, "stdin-discarder": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.1.0.tgz", @@ -20424,6 +20665,11 @@ "version": "1.1.0", "dev": true }, + "strict-event-emitter": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.4.6.tgz", + "integrity": "sha512-12KWeb+wixJohmnwNFerbyiBrAlq5qJLwIt38etRtKtmmHyDSoGlIqFE9wx+4IwG0aDjI7GV8tc8ZccjWZZtTg==" + }, "string_decoder": { "version": "1.3.0", "requires": {