TutorialKit API
TutorialKit exposes low level APIs that authors can utilize to provide highly custom experience in their tutorials. These APIs allow authors to control internal parts of TutorialKit. See How to use TutorialKit API guide for examples.
Tutorial Store
You can access Tutorial Store by importing the tutorialkit:store
entrypoint.
Common types
ReadableAtom
fromnanostores
WebContainerProcess
from@webcontainer/api
Properties
previews
Type: ReadableAtom<PreviewInfo[]>
Instances of the preview tabs.
terminalConfig
Type: ReadableAtom<TerminalConfig>
Configuration and instances of the terminal.
editorConfig
Type: ReadableAtom<EditorConfig>
Configuration of the editor and file tree.
currentDocument
Type: ReadableAtom<EditorDocument | undefined>
File that’s currently open in the editor.
bootStatus
Type: ReadableAtom<BootStatus>
Status of the webcontainer’s booting.
documents
Type: ReadableAtom<EditorDocuments>
Files that are available in the editor.
files
Type: ReadableAtom<FileDescriptor[]>
Paths of the files that are available in the lesson.
selectedFile
Type: ReadableAtom<string | undefined>
File that’s currently selected in the file tree.
lesson
Type: Readonly<Lesson> | undefined
Currently active lesson.
Methods
hasFileTree
Type: () => boolean
Check if file tree is visible.
hasEditor
Type: () => boolean
Check if editor is visible.
hasPreviews
Type: () => boolean
Check if lesson has any previews set.
hasTerminalPanel
Type: () => boolean
Check if lesson has any terminals set.
hasSolution
Type: () => boolean
Check if lesson has solution files set.
unblockBoot
Type: () => void
Unlock webcontainer’s boot process if it was in 'blocked'
state.
reset
Type: () => void
Reset changed files back to lesson’s initial state.
solve
Type: () => void
Apply lesson solution into the lesson files.
setSelectedFile
Type: (filePath: string | undefined) => void
Set file from file tree as selected.
addFile
Type: (filePath: string) => Promise<void>
Add new file to file tree.
Throws error with message FILE_EXISTS
if file exists already on file system.
addFolder
Type: (folderPath: string) => Promise<void>
Add new file to file tree.
Throws error with message FOLDER_EXISTS
if folder exists already on file system.
updateFile
Type: (filePath: string, content: string) => void
Update contents of file.
setCurrentDocumentContent
Type: (newContent: string) => void
Update content of the active file.
setCurrentDocumentScrollPosition
Type: (position: ScrollPosition) => void
Update scroll position of the file in editor.
onTerminalResize
Type: (cols: number, rows: number) => void
Callback that should be called when terminal resizes.
onDocumentChanged
Type: (filePath: string, callback: (document: Readonly<EditorDocument>) => void) => () => void
Listen for file changes made in the editor.
takeSnapshot
Type: () => { files: Record<string, string> }
Take snapshot of the current state of the lesson.
Tutorial Core
You can access Tutorial Core by importing the tutorialkit:core
entrypoint.
The Tutorial Core provides access to webcontainer APIs. You can use it for example to read and modify files on the virtual file system.
Common Types
WebContainer
from@webcontainer/api
Properties
webcontainer
Type: Promise<WebContainer>
Promise that resolves to the webcontainer that’s running in the current lesson.