Skip to content

Commit 91197ed

Browse files
committed
docs: add more tutorialkit store api docs
1 parent 0138820 commit 91197ed

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

docs/tutorialkit.dev/src/content/docs/reference/tutorialkit-api.mdx

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ You can access Tutorial Store by importing the `tutorialkit:store` entrypoint.
1313
import tutorialStore from "tutorialkit:store";
1414
```
1515

16+
:::note
17+
Using `tutorialkit:store` is **experimental** at the moment.
18+
This module may introduce breaking changes in patch and minor version updates. Pay extra attention when updating the versions.
19+
20+
You can help us stabilize the API by providing feedback at [Stabilizing `tutorialkit:store` API | Github Discussions](https://github.com/stackblitz/tutorialkit/discussions).
21+
Please let us know how you are using this API.
22+
:::
23+
1624
### Common types
1725

1826
- `ReadableAtom` from [`nanostores`](https://www.npmjs.com/package/nanostores)
@@ -56,7 +64,7 @@ Instances of the preview tabs.
5664
Type: `ReadableAtom<TerminalConfig>`
5765

5866
```ts
59-
import type { TerminalSchema } from '@tutorialkit/types';
67+
import type { TerminalPanelType, TerminalSchema } from '@tutorialkit/types';
6068
import type { WebContainerProcess } from '@webcontainer/api';
6169

6270
class TerminalConfig {
@@ -95,7 +103,7 @@ interface ITerminal {
95103
}
96104
```
97105

98-
Configuration and instances of the terminal
106+
Configuration and instances of the terminal.
99107

100108
#### `editorConfig`
101109

@@ -117,30 +125,67 @@ Configuration of the editor and file tree.
117125

118126
Type: `ReadableAtom<EditorDocument | undefined>`
119127

128+
```ts
129+
import type { FileDescriptor } from '@tutorialkit/types';
130+
131+
interface EditorDocument {
132+
value: string | Uint8Array;
133+
loading: boolean;
134+
filePath: string;
135+
type: FileDescriptor['type'];
136+
scroll?: ScrollPosition;
137+
}
138+
139+
interface ScrollPosition {
140+
top: number;
141+
left: number;
142+
}
143+
```
144+
120145
File that's currently open in the editor.
121146

122147
#### `bootStatus`
123148

124149
Type: `ReadableAtom<BootStatus>`
125150

151+
```ts
152+
type BootStatus = 'unknown' | 'blocked' | 'booting' | 'booted';
153+
```
154+
126155
Status of the webcontainer's booting.
127156

128157
#### `documents`
129158

130159
Type: `ReadableAtom<EditorDocuments>`
131160

161+
```ts
162+
// See type of `EditorDocument` above
163+
type EditorDocuments = Record<string, EditorDocument | undefined>
164+
```
165+
132166
Files that are available in the editor.
133167
134168
#### `files`
135169
136170
Type: `ReadableAtom<FileDescriptor[]>`
137171
172+
```ts
173+
type FileDescriptor = {
174+
path: string;
175+
type: 'file' | 'folder';
176+
}
177+
```
178+
138179
Paths of the files that are available in the lesson.
139180
140181
#### `template`
141182
142183
Type: `Files | undefined`
143184
185+
```ts
186+
type Files = Record<string, string | Uint8Array>
187+
```
188+
144189
Files of the template.
145190
146191
#### `selectedFile`
@@ -153,6 +198,37 @@ File that's currently selected in the file tree.
153198
154199
Type: `Readonly<Lesson> | undefined`
155200
201+
```ts
202+
interface Lesson<T = unknown> {
203+
id: string;
204+
order: number;
205+
data: LessonSchema;
206+
part: {
207+
id: string;
208+
title: string;
209+
};
210+
chapter: {
211+
id: string;
212+
title: string;
213+
};
214+
slug: string;
215+
filepath: string;
216+
editPageLink?: string;
217+
files: FilesRefList;
218+
solution: FilesRefList;
219+
next?: LessonLink;
220+
prev?: LessonLink;
221+
Markdown: T;
222+
}
223+
224+
interface LessonLink {
225+
href: string;
226+
title: string;
227+
}
228+
229+
type FilesRefList = [ref: string, files: string[]]
230+
```
231+
156232
Currently active lesson.
157233
158234
### Methods
@@ -161,26 +237,38 @@ Currently active lesson.
161237
162238
Type: `() => boolean`
163239
240+
Check if file tree is visible.
241+
164242
#### `hasEditor`
165243
166244
Type: `() => boolean`
167245
246+
Check if editor is visible.
247+
168248
#### `hasPreviews`
169249
170250
Type: `() => boolean`
171251
252+
Check if lesson has any previews set.
253+
172254
#### `hasTerminalPanel`
173255
174256
Type: `() => boolean`
175257
258+
Check if lesson has any terminals set.
259+
176260
#### `hasSolution`
177261
178262
Type: `() => boolean`
179263
264+
Check if lesson has solution files set.
265+
180266
#### `unblockBoot`
181267
182268
Type: `() => void`
183269
270+
Unlock webcontainer's boot process if it was in `'blocked'` state.
271+
184272
#### `reset`
185273
186274
Type: `() => void`

packages/runtime/src/store/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,14 @@ export class TutorialStore {
254254

255255
/**
256256
* Steps that the runner is or will be executing.
257+
*
258+
* @internal
257259
*/
258260
get steps() {
259261
return this._stepController.steps;
260262
}
261263

264+
/** Check if file tree is visible */
262265
hasFileTree(): boolean {
263266
if (!this._lesson) {
264267
return false;
@@ -267,6 +270,7 @@ export class TutorialStore {
267270
return this.editorConfig.get().fileTree.visible;
268271
}
269272

273+
/** Check if editor is visible */
270274
hasEditor(): boolean {
271275
if (!this._lesson) {
272276
return false;
@@ -275,6 +279,7 @@ export class TutorialStore {
275279
return this.editorConfig.get().visible;
276280
}
277281

282+
/** Check if lesson has any previews set */
278283
hasPreviews(): boolean {
279284
if (!this._lesson) {
280285
return false;
@@ -285,10 +290,12 @@ export class TutorialStore {
285290
return previews !== false;
286291
}
287292

293+
/** Check if lesson has any terminals set */
288294
hasTerminalPanel(): boolean {
289295
return this._terminalStore.hasTerminalPanel();
290296
}
291297

298+
/** Check if lesson has solution files set */
292299
hasSolution(): boolean {
293300
return !!this._lesson && Object.keys(this._lesson.solution[1]).length >= 1;
294301
}

0 commit comments

Comments
 (0)