Skip to content

Commit 74f9dd7

Browse files
committed
WIP
1 parent dbca98e commit 74f9dd7

File tree

13 files changed

+237
-83
lines changed

13 files changed

+237
-83
lines changed

.config/.env/.env.development

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
STARBEAM_REGISTRY_URL=
1+
STARBEAM_REGISTRY_URL=http://localhost:4873

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"scssLint.showHighlights": true,
5353

5454
"[vue][scss]": {
55-
"editor.defaultFormatter": "Vue.volar"
55+
"editor.defaultFormatter": "esbenp.prettier-vscode"
5656
},
5757

5858
"[yaml]": {

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"@starbeam/debug": "*",
2424
"@starbeam/interfaces": "*",
2525
"@starbeam/js": "*",
26-
"@starbeam/react": "*",
2726
"@starbeam/preact": "*",
27+
"@starbeam/react": "0.8.6",
2828
"@starbeam/timeline": "*",
2929
"@starbeam/universal": "*",
3030
"@starbeam/vitepress": "workspace:1.0.0",
@@ -70,6 +70,7 @@
7070
"postcss-property-lookup": "^3.0.0",
7171
"postcss-scss": "^4.0.5",
7272
"preact": "^10.11.3",
73+
"preact-render-to-string": "^5.2.6",
7374
"prettier": "^2.7.1",
7475
"sass": "^1.56.1",
7576
"shiki": "^0.11.1",
@@ -98,7 +99,7 @@
9899
"@starbeam/timeline": "0.8.6",
99100
"@starbeam/universal": "0.8.6",
100101
"@starbeam/interfaces": "0.8.6",
101-
"@starbeam/preact": "0.8.6"
102+
"@starbeam/preact": "0.8.7"
102103
},
103104
"peerDependencyRules": {
104105
"allowedVersions": {

pnpm-lock.yaml

+24-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.vitepress/components/Demo/Demo.vue

+108-26
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
<script setup lang="ts">
2-
import { SandpackInternalOptions, SandpackProvider, SandpackSetup } from "codesandbox-sandpack-vue3";
2+
import {
3+
SandpackFiles,
4+
SandpackInternalOptions,
5+
SandpackProvider,
6+
SandpackSetup,
7+
} from "codesandbox-sandpack-vue3";
38
import { useData } from "vitepress";
49
import { computed, Ref } from "vue";
510
6-
711
import type { StarbeamFrontmatter } from "../../config/site-data.js";
812
import {
913
DemoDeps,
10-
toSandpackDeps, toSandpackFiles, type DemoFiles
14+
toSandpackDeps,
15+
toSandpackFiles,
16+
type DemoFiles,
1117
} from "./demo.js";
1218
import DemoBody from "./DemoBody.vue";
1319
1420
const { config } = defineProps<{
1521
config: {
1622
files: DemoFiles;
1723
dependencies: DemoDeps;
18-
24+
jsx?: string;
25+
main?: string;
1926
};
2027
}>();
2128
@@ -26,22 +33,89 @@ const deps = computed(() => {
2633
const versions = data.value["@starbeam:versions"];
2734
const deps = toSandpackDeps(config.dependencies) ?? {};
2835
29-
return Object.fromEntries(Object.entries(deps).map(([dep, version]) => {
30-
if (dep in versions) {
31-
return [dep, version === "package.json" ? versions[dep] : version]
32-
} else {
33-
throw Error(`Dependency ${dep} (used in ${info.page.value.relativePath}) not found in versions: ${JSON.stringify(versions)}`);
36+
return Object.fromEntries(
37+
Object.entries(deps).map(([dep, version]) => {
38+
if (dep in versions) {
39+
return [dep, version === "package.json" ? versions[dep] : version];
40+
} else {
41+
throw Error(
42+
`Dependency ${dep} (used in ${
43+
info.page.value.relativePath
44+
}) not found in versions: ${JSON.stringify(versions)}`
45+
);
46+
}
47+
})
48+
);
49+
});
50+
51+
const BABEL_JSX = config.jsx
52+
? [
53+
"transform-react-jsx",
54+
{
55+
runtime: "automatic",
56+
importSource: config.jsx,
57+
},
58+
]
59+
: ["transform-react-jsx"];
60+
61+
const TSCONFIG_JSX = config.jsx
62+
? {
63+
jsx: "preserve",
64+
jsxImportSource: config.jsx,
3465
}
35-
}));
36-
})
37-
38-
39-
const files = {
40-
...toSandpackFiles(config.files)
66+
: { jsx: "preserve" };
67+
68+
const files: SandpackFiles = {
69+
...toSandpackFiles(config.files),
70+
".babelrc": {
71+
hidden: true,
72+
code: JSON.stringify(
73+
{
74+
presets: ["env"],
75+
plugins: ["transform-runtime", BABEL_JSX],
76+
parserOpts: {
77+
plugins: ["dynamicImport"],
78+
},
79+
},
80+
null,
81+
2
82+
),
83+
},
84+
"package.json": JSON.stringify(
85+
{
86+
main: config.main ?? "/src/index.ts",
87+
type: "module",
88+
dependencies: deps.value,
89+
devDependencies: {
90+
typescript: "^4.0.0",
91+
},
92+
},
93+
null,
94+
2
95+
),
96+
"tsconfig.json": JSON.stringify(
97+
{
98+
compilerOptions: {
99+
strict: true,
100+
module: "commonjs",
101+
target: "esnext",
102+
...TSCONFIG_JSX,
103+
esModuleInterop: true,
104+
sourceMap: true,
105+
allowJs: true,
106+
lib: ["es6", "dom"],
107+
rootDir: "src",
108+
moduleResolution: "node16",
109+
},
110+
},
111+
null,
112+
2
113+
),
41114
};
42115
43116
const options: SandpackInternalOptions = {
44117
recompileMode: "delayed",
118+
// bundlerURL: "https://db2aecf9.sandpack-bundler.pages.dev",
45119
};
46120
47121
const registryURL = import.meta.env.STARBEAM_REGISTRY_URL;
@@ -50,23 +124,31 @@ const customSetup = computed((): SandpackSetup => {
50124
if (registryURL) {
51125
return {
52126
dependencies: deps.value,
53-
npmRegistries: [{
54-
enabledScopes: ["@starbeam"],
55-
registryUrl: registryURL,
56-
limitToScopes: true,
57-
}],
127+
entry: config.main ?? "/src/index.ts",
128+
npmRegistries: [
129+
{
130+
enabledScopes: ["@starbeam"],
131+
registryUrl: registryURL,
132+
limitToScopes: true,
133+
},
134+
],
58135
};
59136
} else {
60137
return {
61138
dependencies: deps.value,
62-
}
139+
};
63140
}
64-
})
141+
});
65142
</script>
66143

67144
<template>
68145
<div class="demo">
69-
<SandpackProvider :files="files" :options="options" :custom-setup="customSetup" template="vanilla-ts">
146+
<SandpackProvider
147+
:files="files"
148+
:options="options"
149+
:custom-setup="customSetup"
150+
template="vanilla-ts"
151+
>
70152
<DemoBody />
71153
</SandpackProvider>
72154
</div>
@@ -108,7 +190,7 @@ div.demo {
108190
padding: 0;
109191
border: none;
110192
111-
&+h2 {
193+
& + h2 {
112194
border-block-start: 1rem;
113195
margin-block-start: 0;
114196
}
@@ -133,14 +215,14 @@ button.toggle-button {
133215
color: var(--sp-colors-clickable);
134216
}
135217
136-
>span.count {
218+
> span.count {
137219
display: none;
138220
}
139221
140222
&:not([data-count="0"]) {
141223
padding-inline-end: 0.75rem;
142224
143-
>span.count {
225+
> span.count {
144226
display: grid;
145227
font-size: 0.75em;
146228
width: 2em;

0 commit comments

Comments
 (0)