Skip to content

Commit d8a5a34

Browse files
authored
feat: make core react components easily accessible (#104)
1 parent d431d4d commit d8a5a34

File tree

16 files changed

+66
-21
lines changed

16 files changed

+66
-21
lines changed

packages/components/react/package.json

+30-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,36 @@
88
"license": "MIT",
99
"types": "./dist/index.d.ts",
1010
"exports": {
11-
".": "./dist/index.js"
11+
".": {
12+
"import": {
13+
"types": "./dist/index.d.ts",
14+
"default": "./dist/index.js"
15+
}
16+
},
17+
"./core": {
18+
"import": {
19+
"types": "./dist/core.d.ts",
20+
"default": "./dist/core.js"
21+
}
22+
},
23+
"./core/CodeMirrorEditor": {
24+
"import": {
25+
"types": "./dist/core/CodeMirrorEditor/index.d.ts",
26+
"default": "./dist/core/CodeMirrorEditor/index.js"
27+
}
28+
},
29+
"./core/FileTree": {
30+
"import": {
31+
"types": "./dist/core/FileTree.d.ts",
32+
"default": "./dist/core/FileTree.js"
33+
}
34+
},
35+
"./core/Terminal": {
36+
"import": {
37+
"types": "./dist/core/Terminal/index.d.ts",
38+
"default": "./dist/core/Terminal/index.js"
39+
}
40+
}
1241
},
1342
"files": [
1443
"dist"

packages/components/react/src/Panels/EditorPanel.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import {
55
type EditorDocument,
66
type OnChangeCallback as OnEditorChange,
77
type OnScrollCallback as OnEditorScroll,
8-
} from '../CodeMirrorEditor/index.js';
9-
import { FileTree } from '../FileTree.js';
8+
} from '../core/CodeMirrorEditor/index.js';
9+
import { FileTree } from '../core/FileTree.js';
1010
import resizePanelStyles from '../styles/resize-panel.module.css';
11-
import type { Theme } from '../types.js';
11+
import type { Theme } from '../core/types.js';
1212

1313
const DEFAULT_FILE_TREE_SIZE = 25;
1414

@@ -88,6 +88,7 @@ export function EditorPanel({
8888
<FileTab editorDocument={editorDocument} onHelpClick={onHelpClick} helpAction={helpAction} />
8989
<div className="h-full flex-1 overflow-hidden">
9090
<CodeMirrorEditor
91+
className="h-full"
9192
theme={theme}
9293
id={id}
9394
doc={editorDocument}

packages/components/react/src/Panels/TerminalPanel.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { useStore } from '@nanostores/react';
22
import type { TutorialStore } from '@tutorialkit/runtime';
33
import type { TerminalPanelType } from '@tutorialkit/types';
44
import { lazy, Suspense, useEffect, useRef, useState } from 'react';
5-
import type { TerminalRef } from '../Terminal/index.js';
5+
import type { TerminalRef } from '../core/Terminal/index.js';
66
import { classNames } from '../utils/classnames.js';
77

8-
const Terminal = lazy(() => import('../Terminal/index.js'));
8+
const Terminal = lazy(() => import('../core/Terminal/index.js'));
99

1010
interface TerminalPanelProps {
1111
theme: 'dark' | 'light';
@@ -93,7 +93,7 @@ export function TerminalPanel({ theme, tutorialStore }: TerminalPanelProps) {
9393
{terminalConfig.panels.map(({ id, type }, index) => (
9494
<Terminal
9595
key={id}
96-
className={tabIndex !== index ? 'hidden' : ''}
96+
className={tabIndex !== index ? 'hidden h-full' : 'h-full'}
9797
theme={theme}
9898
readonly={type === 'output'}
9999
ref={(ref) => (terminalRefs.current[index] = ref!)}

packages/components/react/src/Panels/WorkspacePanel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { Panel, PanelGroup, PanelResizeHandle, type ImperativePanelHandle } from
55
import type {
66
OnChangeCallback as OnEditorChange,
77
OnScrollCallback as OnEditorScroll,
8-
} from '../CodeMirrorEditor/index.js';
8+
} from '../core/CodeMirrorEditor/index.js';
99
import resizePanelStyles from '../styles/resize-panel.module.css';
10-
import type { Theme } from '../types.js';
10+
import type { Theme } from '../core/types.js';
1111
import { EditorPanel } from './EditorPanel.js';
1212
import { PreviewPanel, type ImperativePreviewHandle } from './PreviewPanel.js';
1313
import { TerminalPanel } from './TerminalPanel.js';

packages/components/react/src/core.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export {
2+
CodeMirrorEditor,
3+
type EditorDocument,
4+
type EditorUpdate,
5+
type OnChangeCallback,
6+
type OnScrollCallback,
7+
type ScrollPosition,
8+
} from './core/CodeMirrorEditor/index.js';
9+
export { FileTree } from './core/FileTree.js';
10+
export { Terminal, type TerminalRef, type TerminalProps } from './core/Terminal/index.js';

packages/components/react/src/CodeMirrorEditor/cm-theme.ts renamed to packages/components/react/src/core/CodeMirrorEditor/cm-theme.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
22
import { Compartment, type Extension } from '@codemirror/state';
33
import { EditorView } from '@codemirror/view';
4-
import '../styles/cm.css';
4+
import '../../styles/cm.css';
55
import type { Theme } from '../types.js';
66
import { vscodeDarkTheme } from './themes/vscode-dark.js';
77

packages/components/react/src/CodeMirrorEditor/index.tsx renamed to packages/components/react/src/core/CodeMirrorEditor/index.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import {
1414
scrollPastEnd,
1515
} from '@codemirror/view';
1616
import { useEffect, useRef, useState, type MutableRefObject } from 'react';
17+
import { classNames } from '../../utils/classnames.js';
18+
import { debounce } from '../../utils/debounce.js';
1719
import type { Theme } from '../types.js';
18-
import { debounce } from '../utils/debounce.js';
1920
import { BinaryContent } from './BinaryContent.js';
2021
import { getTheme, reconfigureTheme } from './cm-theme.js';
2122
import { indentKeyBinding } from './indent.js';
@@ -46,14 +47,15 @@ export type OnChangeCallback = (update: EditorUpdate) => void;
4647
export type OnScrollCallback = (position: ScrollPosition) => void;
4748

4849
interface Props {
50+
theme: Theme;
4951
id?: unknown;
5052
doc?: EditorDocument;
5153
debounceChange?: number;
5254
debounceScroll?: number;
5355
autoFocusOnDocumentChange?: boolean;
5456
onChange?: OnChangeCallback;
5557
onScroll?: OnScrollCallback;
56-
theme: Theme;
58+
className?: string;
5759
}
5860

5961
type EditorStates = Map<string, EditorState>;
@@ -67,6 +69,7 @@ export function CodeMirrorEditor({
6769
onScroll,
6870
onChange,
6971
theme,
72+
className = '',
7073
}: Props) {
7174
const [language] = useState(new Compartment());
7275
const [readOnly] = useState(new Compartment());
@@ -176,13 +179,15 @@ export function CodeMirrorEditor({
176179
}, [doc?.value, doc?.filePath, doc?.loading]);
177180

178181
return (
179-
<div className="h-full relative">
182+
<div className={classNames('relative', className)}>
180183
{isBinaryFile && <BinaryContent />}
181184
<div className="h-full overflow-hidden" ref={containerRef} />
182185
</div>
183186
);
184187
}
185188

189+
export default CodeMirrorEditor;
190+
186191
CodeMirrorEditor.displayName = 'CodeMirrorEditor';
187192

188193
function newEditorState(

packages/components/react/src/FileTree.tsx renamed to packages/components/react/src/core/FileTree.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useMemo, useState, type ReactNode } from 'react';
2-
import { classNames } from './utils/classnames.js';
2+
import { classNames } from '../utils/classnames.js';
33

44
const NODE_PADDING_LEFT = 12;
55
const DEFAULT_HIDDEN_FILES = [/\/node_modules\//];
@@ -102,6 +102,8 @@ export function FileTree({ files, onFileSelect, selectedFile, hideRoot, scope, h
102102
);
103103
}
104104

105+
export default FileTree;
106+
105107
interface FolderProps {
106108
folder: FolderNode;
107109
collapsed: boolean;

packages/components/react/src/Terminal/index.tsx renamed to packages/components/react/src/core/Terminal/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ export interface TerminalRef {
99
reloadStyles: () => void;
1010
}
1111

12-
export interface Props {
12+
export interface TerminalProps {
1313
theme: 'dark' | 'light';
1414
className?: string;
1515
readonly?: boolean;
1616
onTerminalReady?: (terminal: XTerm) => void;
1717
onTerminalResize?: (cols: number, rows: number) => void;
1818
}
1919

20-
const Terminal = forwardRef<TerminalRef, Props>(
21-
({ theme, className, readonly = true, onTerminalReady, onTerminalResize }, ref) => {
20+
export const Terminal = forwardRef<TerminalRef, TerminalProps>(
21+
({ theme, className = '', readonly = true, onTerminalReady, onTerminalResize }, ref) => {
2222
const divRef = useRef<HTMLDivElement>(null);
2323
const terminalRef = useRef<XTerm>();
2424

@@ -78,7 +78,7 @@ const Terminal = forwardRef<TerminalRef, Props>(
7878
};
7979
}, []);
8080

81-
return <div className={`h-full ${className}`} ref={divRef} />;
81+
return <div className={className} ref={divRef} />;
8282
},
8383
);
8484

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
export * from './BootScreen.js';
2-
export * from './CodeMirrorEditor/index.js';
3-
export * from './FileTree.js';
42
export * from './Nav.js';
53
export * from './Panels/EditorPanel.js';
64
export * from './Panels/PreviewPanel.js';
75
export * from './Panels/TerminalPanel.js';
86
export * from './Panels/WorkspacePanel.js';
9-
export type * from './types.js';
7+
export type * from './core/types.js';
108
export * from './utils/classnames.js';

0 commit comments

Comments
 (0)