Skip to content

Commit a2e0799

Browse files
committed
feat: make core react components easily accessible
1 parent 6963947 commit a2e0799

File tree

16 files changed

+45
-19
lines changed

16 files changed

+45
-19
lines changed

packages/components/react/package.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,31 @@
88
"license": "MIT",
99
"types": "./dist/index.d.ts",
1010
"exports": {
11-
".": "./dist/index.js"
11+
".": "./dist/index.js",
12+
"./core": "./dist/core.js",
13+
"./core/CodeMirrorEditor": "./dist/core/CodeMirrorEditor/index.js",
14+
"./core/FileTree": "./dist/core/FileTree.js",
15+
"./core/Terminal": "./dist/core/Terminal/index.js"
1216
},
1317
"files": [
1418
"dist"
1519
],
20+
"typesVersions": {
21+
"*": {
22+
"core": [
23+
"dist/core.d.ts"
24+
],
25+
"./core/CodeMirrorEditor": [
26+
"dist/core/CodeMirrorEditor/index.d.ts"
27+
],
28+
"./core/FileTree": [
29+
"dist/core/FileTree.d.ts"
30+
],
31+
"./core/Terminal": [
32+
"dist/core/Terminal/index.d.ts"
33+
]
34+
}
35+
},
1636
"scripts": {
1737
"build": "node ./scripts/build.js"
1838
},

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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Terminal, { type Props as TerminalProps, type TerminalRef } from './core/Terminal/index.js';
2+
3+
export * from './core/CodeMirrorEditor/index.js';
4+
export * from './core/FileTree.js';
5+
export { Terminal, type TerminalProps, type TerminalRef };

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from '@codemirror/view';
1616
import { useEffect, useRef, useState, type MutableRefObject } from 'react';
1717
import type { Theme } from '../types.js';
18-
import { debounce } from '../utils/debounce.js';
18+
import { debounce } from '../../utils/debounce.js';
1919
import { BinaryContent } from './BinaryContent.js';
2020
import { getTheme, reconfigureTheme } from './cm-theme.js';
2121
import { indentKeyBinding } from './indent.js';
@@ -46,14 +46,15 @@ export type OnChangeCallback = (update: EditorUpdate) => void;
4646
export type OnScrollCallback = (position: ScrollPosition) => void;
4747

4848
interface Props {
49+
theme: Theme;
4950
id?: unknown;
5051
doc?: EditorDocument;
5152
debounceChange?: number;
5253
debounceScroll?: number;
5354
autoFocusOnDocumentChange?: boolean;
5455
onChange?: OnChangeCallback;
5556
onScroll?: OnScrollCallback;
56-
theme: Theme;
57+
className?: string;
5758
}
5859

5960
type EditorStates = Map<string, EditorState>;
@@ -67,6 +68,7 @@ export function CodeMirrorEditor({
6768
onScroll,
6869
onChange,
6970
theme,
71+
className = '',
7072
}: Props) {
7173
const [language] = useState(new Compartment());
7274
const [readOnly] = useState(new Compartment());
@@ -176,7 +178,7 @@ export function CodeMirrorEditor({
176178
}, [doc]);
177179

178180
return (
179-
<div className="h-full relative">
181+
<div className={`relative ${className}`}>
180182
{isBinaryFile && <BinaryContent />}
181183
<div className="h-full overflow-hidden" ref={containerRef} />
182184
</div>

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

Lines changed: 1 addition & 1 deletion
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\//];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface Props {
1818
}
1919

2020
const Terminal = forwardRef<TerminalRef, Props>(
21-
({ theme, className, readonly = true, onTerminalReady, onTerminalResize }, ref) => {
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

Lines changed: 1 addition & 3 deletions
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)