Skip to content

Commit b44848d

Browse files
committed
Cleanup components interface
1 parent f96e872 commit b44848d

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

src/App.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { useCallback, useEffect, useState } from 'react';
1+
import { FC, useCallback, useEffect, useState } from 'react';
22
import { Node } from 'typescript';
33
import './index.css';
44
import { queryCode } from './engine';
55
import QueryEditor from './QueryEditor';
66
import Code, { HighlightedInterval, HighlightedIntervals } from './Code';
77
import { isSyntaxError } from './tsquery-util';
8+
import Header from './Header';
89

910
const REG_EXPS: Record<string, RegExp> = {
1011
AllLineBreaks: /\n/g,
@@ -16,7 +17,7 @@ const REG_EXPS: Record<string, RegExp> = {
1617
OnlyWhitespace: /^\s*$/,
1718
};
1819

19-
export default function App() {
20+
const App: FC = () => {
2021
const [highlightedIntervals, setHighlightedIntervals] = useState<HighlightedIntervals>([]);
2122
const [query, setQuery] = useState<string>('');
2223
const [code, setCode] = useState<string>('');
@@ -54,20 +55,16 @@ export default function App() {
5455
// Layout
5556
return (
5657
<div className="App">
57-
<header>
58-
<h1>TSQuery Playground</h1>
59-
<aside>
60-
<a href="https://github.com/phenomnomnominal/tsquery#selectors">Reference</a>
61-
<a href="https://github.com/flycode-org/tsquery-playground">GitHub</a>
62-
</aside>
63-
</header>
58+
<Header />
6459
<h2>Query</h2>
6560
<QueryEditor onChange={handleQueryChange} />
6661
<h2>Code</h2>
6762
<Code highlighted={highlightedIntervals} onChange={handleCodeChange} />
6863
</div>
6964
);
70-
}
65+
};
66+
67+
export default App;
7168

7269
function mapNodeToHighlightInterval(node: Node): HighlightedInterval {
7370
const fullText = node.getFullText();

src/Code.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export type HighlightedInterval = {
99

1010
export type HighlightedIntervals = HighlightedInterval[];
1111

12-
const Code: FC<{
12+
export type CodeProps = {
1313
highlighted: HighlightedIntervals;
1414
onChange: OnChange;
15-
}> = ({ highlighted, onChange }) => {
15+
};
16+
17+
const Code: FC<CodeProps> = ({ highlighted, onChange }) => {
1618
const [instances, setInstances] = useState<[Monaco.editor.IStandaloneCodeEditor, typeof Monaco] | null>(null);
1719

1820
/** @todo https://microsoft.github.io/monaco-editor/api/modules/monaco.editor.html#setmodelmarkers */

src/Header.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { FC } from 'react';
2+
3+
const Header: FC = () => (
4+
<header>
5+
<h1>TSQuery Playground</h1>
6+
<aside>
7+
<a href="https://github.com/phenomnomnominal/tsquery#selectors">Reference</a>
8+
<a href="https://github.com/flycode-org/tsquery-playground">GitHub</a>
9+
</aside>
10+
</header>
11+
);
12+
13+
export default Header;

src/QueryEditor.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import { isSyntaxError } from './tsquery-util';
77

88
const MONACO_MODEL_MARKER_OWNER = 'tsquery';
99

10-
const QueryEditor: FC<Omit<EditorProps, 'defaultLanguage' | 'theme' | 'options' | 'onMount'>> = ({
11-
onChange,
12-
...rest
13-
}) => {
10+
export type QueryEditorProps = Omit<EditorProps, 'defaultLanguage' | 'theme' | 'options' | 'onMount'>;
11+
12+
const QueryEditor: FC<QueryEditorProps> = ({ onChange, ...rest }) => {
1413
const monacoRef = useRef<typeof Monaco>();
1514
const editorRef = useRef<Monaco.editor.IStandaloneCodeEditor>();
1615
const handleQueryMount = useCallback((editor: Monaco.editor.IStandaloneCodeEditor, monaco: typeof Monaco) => {

0 commit comments

Comments
 (0)