Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(website): [playground] add copy as json and simplify ast viewer #6728

Merged
merged 26 commits into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
29bd5f3
chore(website): [playground] improve ast viewer
armano2 Mar 21, 2023
c8dce6f
Merge remote-tracking branch 'origin/v6' into chore/website-improve-a…
armano2 Mar 22, 2023
b05a7cf
fix: do not show undefined when there is no ast to display
armano2 Mar 22, 2023
fd062fb
fix: cleanup tooltip in button copy
armano2 Mar 22, 2023
4d1c21f
fix: apply some parts of code review
armano2 Mar 22, 2023
c1afcb9
fix: tsUtils
armano2 Mar 22, 2023
d2cad0b
fix: restore icon sizes after icon change
armano2 Mar 22, 2023
7b5a8f5
fix: improve logic used to select nodes
armano2 Mar 22, 2023
d89724f
fix: simplify code
armano2 Mar 22, 2023
ebc3a56
Merge branch 'v6' into chore/website-improve-ast-viewer
armano2 Mar 27, 2023
ecf53db
fix: remove some unnecessary changes
armano2 Mar 27, 2023
fe88028
fix: remove unnecessary type
armano2 Mar 28, 2023
8c99a05
fix: optimize code
armano2 Mar 28, 2023
a3c18e5
Merge remote-tracking branch 'origin/v6' into chore/website-improve-a…
armano2 Mar 28, 2023
68f715b
fix: correct hover effect
armano2 Mar 28, 2023
a295444
fix: correct open/close bracket for map and set
armano2 Mar 28, 2023
d122004
fix: small fix for accessibility
armano2 Mar 28, 2023
de3a6bc
fix: remove blinking when switching tabs
armano2 Mar 28, 2023
b1fcbea
fix: reactivity for onHoverItem
armano2 Mar 28, 2023
a995cf7
fix: move hook to hooks
armano2 Mar 28, 2023
4845069
Merge branch 'v6' into chore/website-improve-ast-viewer
armano2 Mar 29, 2023
61deef1
fix: correct tooltip wrapping
armano2 Mar 29, 2023
9e6c5d6
fix: apply code review changes and add some comments
armano2 Apr 2, 2023
884f6b4
fix: apply one more change from code review
armano2 Apr 2, 2023
eb9e205
fix: move shortValue to SimpleModel
armano2 Apr 2, 2023
c0e6213
fix: remove double `JSON.stringify`
armano2 Apr 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 0 additions & 42 deletions packages/website/src/components/ASTViewerESTree.tsx

This file was deleted.

22 changes: 0 additions & 22 deletions packages/website/src/components/ASTViewerScope.tsx

This file was deleted.

71 changes: 0 additions & 71 deletions packages/website/src/components/ASTViewerTS.tsx

This file was deleted.

85 changes: 31 additions & 54 deletions packages/website/src/components/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { useWindowSize } from '@docusaurus/theme-common';
import type { TSESTree } from '@typescript-eslint/utils';
import clsx from 'clsx';
import type * as ESQuery from 'esquery';
import type Monaco from 'monaco-editor';
import React, { useCallback, useReducer, useState } from 'react';
import React, { useCallback, useState } from 'react';
import type { SourceFile } from 'typescript';

import { useMediaQuery } from '../hooks/useMediaQuery';
import ASTViewerESTree from './ASTViewerESTree';
import ASTViewerScope from './ASTViewerScope';
import ASTViewerTS from './ASTViewerTS';
import ASTViewer from './ast/ASTViewer';
import { detailTabs } from './config';
import ConfigEslint from './config/ConfigEslint';
import ConfigTypeScript from './config/ConfigTypeScript';
Expand All @@ -20,7 +17,6 @@ import { ESQueryFilter } from './ESQueryFilter';
import useHashState from './hooks/useHashState';
import EditorTabs from './layout/EditorTabs';
import Loader from './layout/Loader';
import { shallowEqual } from './lib/shallowEqual';
import OptionsSelector from './OptionsSelector';
import styles from './Playground.module.css';
import ConditionalSplitPane from './SplitPane/ConditionalSplitPane';
Expand All @@ -32,22 +28,6 @@ import type {
TabType,
} from './types';

function rangeReducer<T extends SelectedRange | null>(
prevState: T,
action: T,
): T {
if (prevState !== action) {
if (
!prevState ||
!action ||
!shallowEqual(prevState.start, action.start) ||
!shallowEqual(prevState.end, action.end)
) {
return action;
}
}
return prevState;
}
function Playground(): JSX.Element {
const [state, setState] = useHashState({
jsx: false,
Expand All @@ -65,13 +45,13 @@ function Playground(): JSX.Element {
const [ruleNames, setRuleNames] = useState<RuleDetails[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(true);
const [tsVersions, setTSVersion] = useState<readonly string[]>([]);
const [selectedRange, setSelectedRange] = useReducer(rangeReducer, null);
const [position, setPosition] = useState<Monaco.Position | null>(null);
const [selectedRange, setSelectedRange] = useState<SelectedRange>();
const [position, setPosition] = useState<number>();
const [activeTab, setTab] = useState<TabType>('code');
const [showModal, setShowModal] = useState<TabType | false>(false);
const [esQueryFilter, setEsQueryFilter] = useState<ESQuery.Selector>();
const [esQueryError, setEsQueryError] = useState<Error>();
const enableSplitPanes = useMediaQuery('(min-width: 996px)');
const windowSize = useWindowSize();

const updateModal = useCallback(
(config?: Partial<ConfigModel>) => {
Expand All @@ -92,6 +72,15 @@ function Playground(): JSX.Element {
[],
);

const astToShow =
state.showAST === 'ts'
? tsAst
: state.showAST === 'scope'
? scope
: state.showAST === 'es'
? esAst
: undefined;

return (
<div className={styles.codeContainer}>
{ruleNames.length > 0 && (
Expand All @@ -109,7 +98,7 @@ function Playground(): JSX.Element {
/>
<div className={styles.codeBlocks}>
<ConditionalSplitPane
render={enableSplitPanes}
render={windowSize !== 'mobile'}
split="vertical"
minSize="10%"
defaultSize="20rem"
Expand All @@ -126,7 +115,7 @@ function Playground(): JSX.Element {
/>
</div>
<ConditionalSplitPane
render={enableSplitPanes}
render={windowSize !== 'mobile'}
armano2 marked this conversation as resolved.
Show resolved Hide resolved
split="vertical"
minSize="10%"
defaultSize="50%"
Expand Down Expand Up @@ -157,7 +146,7 @@ function Playground(): JSX.Element {
onTsASTChange={setTsAST}
onScopeChange={setScope}
onMarkersChange={setMarkers}
decoration={selectedRange}
selectedRange={selectedRange}
onChange={setState}
onLoaded={onLoaded}
onSelect={setPosition}
Expand All @@ -178,33 +167,21 @@ function Playground(): JSX.Element {
)}
</div>

{(state.showAST === 'ts' && tsAst && (
<ASTViewerTS
value={tsAst}
position={position}
onSelectNode={setSelectedRange}
{(state.showAST === 'es' && esQueryError && (
<ErrorViewer
type="warning"
title="Invalid Selector"
value={esQueryError}
/>
)) ||
(state.showAST === 'scope' && scope && (
<ASTViewerScope
value={scope}
position={position}
onSelectNode={setSelectedRange}
/>
)) ||
(state.showAST === 'es' && esQueryError && (
<ErrorViewer
type="warning"
title="Invalid Selector"
value={esQueryError}
/>
)) ||
(state.showAST === 'es' && esAst && (
<ASTViewerESTree
value={esAst}
position={position}
filter={esQueryFilter}
onSelectNode={setSelectedRange}
(state.showAST && astToShow && (
<ASTViewer
key={String(state.showAST)}
filter={state.showAST === 'es' ? esQueryFilter : undefined}
value={astToShow}
enableScrolling={true}
cursorPosition={position}
onHoverNode={setSelectedRange}
/>
)) || <ErrorsViewer value={markers} />}
</div>
Expand Down
24 changes: 24 additions & 0 deletions packages/website/src/components/ast/ASTViewer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
line-height: 18px;
letter-spacing: 0;
font-feature-settings: 'liga' 0, 'calt' 0;
position: relative;
min-width: 100%;
}

.list * {
vertical-align: top;
}

.list,
Expand Down Expand Up @@ -47,6 +53,20 @@
color: var(--token-color-class-name);
}

.propNumber,
.propEmpty,
.propRegExp,
.propClass,
.propBoolean,
.propError,
.propString {
display: inline-block;
max-width: 600px;
word-wrap: break-word;
word-break: break-all;
white-space: pre-wrap;
}

.propName {
color: var(--token-color-property);
}
Expand All @@ -71,6 +91,10 @@
color: var(--token-color-boolean);
}

.propError {
color: var(--token-color-deleted);
}

.propString {
color: var(--token-color-string);
}
Expand Down