@tutorialkit-rb/astro 0.1.7 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useStore } from '@nanostores/react';
|
|
2
|
+
import { isDeferred, isActivated, activateText, activate } from '../stores/deferred-store.js';
|
|
3
|
+
|
|
4
|
+
export default function ActivateOverlay() {
|
|
5
|
+
const activated = useStore(isActivated);
|
|
6
|
+
|
|
7
|
+
if (!isDeferred || activated) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const displayText = (activateText ?? 'Start Tutorial').replace(/\b\w/g, (c) => c.toUpperCase());
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div className="fixed inset-0 z-50 flex flex-col justify-center items-center backdrop-blur-md" style={{ backgroundColor: 'rgba(255, 255, 255, 0.1)' }}>
|
|
15
|
+
<button
|
|
16
|
+
onClick={activate}
|
|
17
|
+
className="inline-flex items-center font-500 text-sm rounded-md cursor-pointer transition-all duration-150"
|
|
18
|
+
style={{
|
|
19
|
+
padding: '0.5rem 1rem',
|
|
20
|
+
backgroundColor: '#4f46e5',
|
|
21
|
+
borderColor: '#4f46e5',
|
|
22
|
+
border: '1px solid #4f46e5',
|
|
23
|
+
color: '#ffffff',
|
|
24
|
+
borderRadius: '0.375rem',
|
|
25
|
+
}}
|
|
26
|
+
onMouseEnter={(e) => {
|
|
27
|
+
e.currentTarget.style.backgroundColor = '#4338ca';
|
|
28
|
+
e.currentTarget.style.borderColor = '#4338ca';
|
|
29
|
+
}}
|
|
30
|
+
onMouseLeave={(e) => {
|
|
31
|
+
e.currentTarget.style.backgroundColor = '#4f46e5';
|
|
32
|
+
e.currentTarget.style.borderColor = '#4f46e5';
|
|
33
|
+
}}
|
|
34
|
+
>
|
|
35
|
+
{displayText}
|
|
36
|
+
</button>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -4,6 +4,7 @@ import { useAuth } from './setup.js';
|
|
|
4
4
|
import { safeBoot, TutorialStore } from '@tutorialkit-rb/runtime';
|
|
5
5
|
import { auth, WebContainer } from '@webcontainer/api';
|
|
6
6
|
import { joinPaths } from '../utils/url.js';
|
|
7
|
+
import { activationPromise } from '../stores/deferred-store.js';
|
|
7
8
|
|
|
8
9
|
interface WebContainerContext {
|
|
9
10
|
readonly useAuth: boolean;
|
|
@@ -16,7 +17,9 @@ export let webcontainer: Promise<WebContainer> = new Promise(() => {
|
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
if (!import.meta.env.SSR) {
|
|
19
|
-
webcontainer =
|
|
20
|
+
webcontainer = activationPromise
|
|
21
|
+
.then(() => (useAuth ? auth.loggedIn() : null))
|
|
22
|
+
.then(() => safeBoot({ workdirName: 'tutorial' }));
|
|
20
23
|
|
|
21
24
|
webcontainer.then(() => {
|
|
22
25
|
webcontainerContext.loaded = true;
|
|
@@ -3,6 +3,7 @@ import type { InferGetStaticPropsType } from 'astro';
|
|
|
3
3
|
import TopBarWrapper from '../components/TopBarWrapper.astro';
|
|
4
4
|
import MainContainer from '../components/MainContainer.astro';
|
|
5
5
|
import PageLoadingIndicator from '../components/PageLoadingIndicator.astro';
|
|
6
|
+
import ActivateOverlay from '../components/ActivateOverlay.tsx';
|
|
6
7
|
import Layout from '../layouts/Layout.astro';
|
|
7
8
|
import '../styles/base.css';
|
|
8
9
|
import '@tutorialkit/custom.css';
|
|
@@ -44,4 +45,6 @@ meta.description ??= 'A TutorialKit interactive lesson';
|
|
|
44
45
|
|
|
45
46
|
<MainContainer lesson={lesson} navList={navList} showNav={showNav} />
|
|
46
47
|
</main>
|
|
48
|
+
|
|
49
|
+
<ActivateOverlay client:load />
|
|
47
50
|
</Layout>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { atom } from 'nanostores';
|
|
2
|
+
|
|
3
|
+
function getActivateText(): string | null {
|
|
4
|
+
if (typeof window === 'undefined') {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const value = new URLSearchParams(window.location.search).get('activate');
|
|
9
|
+
|
|
10
|
+
if (value === null || value === '') {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const activateText = getActivateText();
|
|
18
|
+
export const isDeferred = activateText !== null;
|
|
19
|
+
export const isActivated = atom<boolean>(!isDeferred);
|
|
20
|
+
|
|
21
|
+
let _resolveActivation: (() => void) | undefined;
|
|
22
|
+
|
|
23
|
+
export const activationPromise: Promise<void> = isDeferred
|
|
24
|
+
? new Promise<void>((resolve) => {
|
|
25
|
+
_resolveActivation = resolve;
|
|
26
|
+
})
|
|
27
|
+
: Promise.resolve();
|
|
28
|
+
|
|
29
|
+
export function activate() {
|
|
30
|
+
isActivated.set(true);
|
|
31
|
+
_resolveActivation?.();
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tutorialkit-rb/astro",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"description": "TutorialKit integration for Astro (https://astro.build)",
|
|
5
5
|
"author": "StackBlitz Inc.",
|
|
6
6
|
"type": "module",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"unist-util-visit": "^5.0.0",
|
|
55
55
|
"unocss": "^0.59.4",
|
|
56
56
|
"zod": "3.23.8",
|
|
57
|
-
"@tutorialkit-rb/react": "0.1
|
|
58
|
-
"@tutorialkit-rb/runtime": "0.1
|
|
59
|
-
"@tutorialkit-rb/theme": "0.1
|
|
60
|
-
"@tutorialkit-rb/types": "0.1
|
|
57
|
+
"@tutorialkit-rb/react": "1.0.0-rc.1",
|
|
58
|
+
"@tutorialkit-rb/runtime": "1.0.0-rc.1",
|
|
59
|
+
"@tutorialkit-rb/theme": "1.0.0-rc.1",
|
|
60
|
+
"@tutorialkit-rb/types": "1.0.0-rc.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/mdast": "^4.0.4",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"typescript": "^5.4.5",
|
|
68
68
|
"vite-plugin-inspect": "0.8.4",
|
|
69
69
|
"vitest": "^3.0.5",
|
|
70
|
-
"@tutorialkit-rb/types": "0.1
|
|
70
|
+
"@tutorialkit-rb/types": "1.0.0-rc.1"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"astro": "^4.15.0"
|