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

fix: minor glitch in markdown ast preview #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/ast/javascript-ast-tree-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const JavascriptAstTreeItem: FC<JavascriptAstTreeItemProperties> = ({
}) => (
<AccordionItem
value={`${index}-${data.type}`}
className="border rounded-lg overflow-hidden"
className="border rounded-lg overflow-hidden min-w-80"
>
<AccordionTrigger className="text-sm bg-muted-foreground/5 px-4 py-3 capitalize">
{data.type}
</AccordionTrigger>
<AccordionContent className="p-4 border-t">
<AccordionContent className="p-4 overflow-x-scroll mr-2">
<div className="space-y-1">
{Object.entries(data).map(item => (
<TreeEntry key={item[0]} data={item} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/ast/json-ast-tree-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const JsonAstTreeItem: FC<JsonAstTreeItemProperties> = ({
}) => (
<AccordionItem
value={`${index}-${data.type}`}
className="border rounded-lg overflow-hidden"
className="border rounded-lg overflow-hidden min-w-80"
>
<AccordionTrigger className="text-sm bg-muted-foreground/5 px-4 py-3 capitalize">
{data.type}
</AccordionTrigger>
<AccordionContent className="p-4 border-t">
<AccordionContent className="p-4 overflow-x-scroll mr-2">
<div className="space-y-1">
{Object.entries(data).map(item => (
<TreeEntry key={item[0]} data={item} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/ast/markdown-ast-tree-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const MarkdownAstTreeItem: FC<MarkdownAstTreeItemProperties> = ({
}) => (
<AccordionItem
value={`${index}-${data.type}`}
className="border rounded-lg overflow-hidden"
className="border rounded-lg overflow-hidden min-w-80"
>
<AccordionTrigger className="text-sm bg-muted-foreground/5 px-4 py-3 capitalize">
{data.type}
</AccordionTrigger>
<AccordionContent className="p-4 border-t">
<AccordionContent className="p-4 overflow-x-scroll mr-2">
<div className="space-y-1">
{Object.entries(data).map(item => (
<TreeEntry key={item[0]} data={item} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/scope/scope-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export const ScopeItem: FC<ScopeItemProperties> = ({
return (
<AccordionItem
value={path + "." + index + "." + key}
className="border rounded-lg overflow-hidden"
className="border rounded-lg overflow-hidden min-w-80"
>
<AccordionTrigger className="text-sm bg-muted-foreground/5 px-4 py-3 capitalize">
{isArray && `${Math.max(index, 0)}.`} {key}
</AccordionTrigger>
<AccordionContent className="p-4 border-t">
<AccordionContent className="p-4 overflow-x-scroll mr-2">
<div className="space-y-1">
{properties.map((item, index) => (
<TreeEntry
Expand Down
41 changes: 25 additions & 16 deletions src/components/tree-entry.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In tightly packed areas when we have more than 3 keys we might actually want to add ellipsis to the text?

before overflow ellipsis after overflow ellipsis
Screenshot 2024-10-04 at 12 15 17 PM Screenshot 2024-10-04 at 12 14 51 PM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a minimum height and overflow scroll to avoid this issue.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { renderValue } from "@/lib/render-value";
import { ScopeItem } from "./scope/scope-item";
import { Reference, Variable, Scope } from "eslint-scope";
import type { FC, ReactNode } from "react";
import { cn } from "@/lib/utils";

type TreeEntryProperties = {
readonly data: [string, unknown];
Expand Down Expand Up @@ -91,36 +92,44 @@ export const TreeEntry: FC<TreeEntryProperties> = ({ data, path }) => {
const [key, value] = data;
const [open, setOpen] = useState(false);
const Icon = open ? MinusSquareIcon : PlusSquareIcon;

const toggleOpen = () => setOpen(!open);
const isObject = typeof value === "object" && value !== null;
const isExpandable =
isObject &&
(Array.isArray(value)
? value.length > 0
: Object.keys(value).length > 0);
const values = renderValue(value);
const renderParts = values.map((part, partIndex) => (
<span
key={partIndex}
className={cn(
"flex-none",
partIndex ? "text-muted-foreground" : "text-primary",
values.length === 1 && "flex-1",
)}
>
{part}
</span>
));

return (
<>
<div className="flex items-center gap-3">
{(typeof value === "object" &&
Object.values(value ?? {}).length) ||
(Array.isArray(value) && value.length) ? (
{isExpandable ? (
<button
onClick={toggleOpen}
aria-label="Toggle"
type="button"
className="flex-none"
>
<Icon size={16} className="text-muted-foreground" />
</button>
) : (
<div className="w-4 h-4" />
<div className="w-4 h-4"></div>
)}
{key && <span>{key}</span>}
{renderValue(value).map((part, partIndex) => (
<span
key={partIndex}
className={
partIndex ? "text-muted-foreground" : "text-primary"
}
>
{part}
</span>
))}
{key && <span className="flex-none">{key}</span>}
{renderParts}
</div>
{open ? (
<SanitizeValue
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const AccordionContent = React.forwardRef<
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down border-t"
{...props}
>
<div className={cn("pb-4 pt-0", className)}>{children}</div>
Expand Down