mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
* feat(repl): improve repl by fmw, add solid repl * fix: fix lz-string pkg esm * feat(repl): sort files for repl generator link * feat(repl): add css file support for solid repl
35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import { getParameters } from 'codesandbox/lib/api/define.js';
|
|
|
|
export default function createAlpineREPL() {
|
|
const BASE_URL = 'https://codesandbox.io/api/v1/sandboxes/define?embed=1¶meters=';
|
|
const BASE_PREFIX = `<!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <meta http-equiv="X-UA-Compatible" content="ie=edge" />\n <title>Alpine.js Playground</title>\n <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>\n </head>\n <body>\n\n`;
|
|
const BASE_SUFFIX = `\n </body>\n</html>`;
|
|
|
|
function generateURLFromData(parameters) {
|
|
return `${BASE_URL}${parameters}`;
|
|
}
|
|
|
|
function fromContentByFilename(contentByFilename) {
|
|
const parameters = getParameters({
|
|
files: {
|
|
...contentByFilename,
|
|
'package.json': {
|
|
content: { dependencies: {} },
|
|
},
|
|
'index.html': {
|
|
content: BASE_PREFIX + (contentByFilename['index.html']?.content || '') + BASE_SUFFIX,
|
|
},
|
|
'sandbox.config.json': {
|
|
content: '{\n "template": "static"\n}',
|
|
},
|
|
},
|
|
});
|
|
|
|
return generateURLFromData(parameters);
|
|
}
|
|
|
|
return {
|
|
fromContentByFilename,
|
|
};
|
|
}
|