import { ChevronRightIcon, ArrowLeftIcon, ArrowRightIcon, PencilAltIcon, CheckIcon, } from "@heroicons/react/outline"; import { ColumnViewNode } from "~/useColumnView"; import { Body } from "./Primitives/Body"; import { useJsonColumnViewAPI, useJsonColumnViewState, } from "../hooks/useJsonColumnView"; import { useHotkeys } from "react-hotkeys-hook"; import { memo, useEffect, useRef, useState } from "react"; import { useJson } from '~/hooks/useJson'; import { JSONHeroPath } from '@jsonhero/path'; export function PathBar() { const [isEditable, setIsEditable] = useState(false); const { selectedNodes, highlightedNodeId } = useJsonColumnViewState(); const { goToNodeId } = useJsonColumnViewAPI(); const [json] = useJson(); if (isEditable) { return ( { setIsEditable(false); const heroPath = new JSONHeroPath(newPath); const node = heroPath.first(json); if (node) { goToNodeId(newPath, 'pathBar'); } }} /> ); } return ( setIsEditable(true)} /> ); } export function PathBarText({ selectedNodes, onConfirm }: { selectedNodes: ColumnViewNode[], onConfirm: (newPath: string) => void; }) { const [path, setPath] = useState(''); const ref = useRef(null); useEffect(() => { setPath(selectedNodes.at(-1)?.id || ''); }, [selectedNodes]); useEffect(() => { if (ref.current) { ref.current.focus(); } }, [ref]); return (
{ onConfirm(path); e.preventDefault(); }} // onBlur={() => onConfirm(path)} className="flex overflow-x-hidden items-center bg-slate-300 dark:bg-slate-700 rounded-sm" >
); } export type PathBarLinkProps = { selectedNodes: ColumnViewNode[]; highlightedNodeId?: string; enableEdit: () => void; }; export function PathBarLink({ selectedNodes, highlightedNodeId, enableEdit, }: PathBarLinkProps) { const { goToNodeId } = useJsonColumnViewAPI(); return (
{ if (event.detail == 2) { enableEdit(); } }} > {selectedNodes.map((node, index) => { return ( goToNodeId(id, "pathBar")} isLast={index == selectedNodes.length - 1} /> ); })}
); } export function PathHistoryControls() { const { canGoBack, canGoForward } = useJsonColumnViewState(); const { goBack, goForward } = useJsonColumnViewAPI(); useHotkeys( "[", () => { goBack(); }, [goBack] ); useHotkeys( "]", () => { goForward(); }, [goForward] ); return (
); } function PathBarElement({ node, isHighlighted, onClick, isLast, }: { node: ColumnViewNode; isHighlighted: boolean; onClick?: (id: string) => void; isLast: boolean; }) { return (
onClick && onClick(node.id)} >
{node.icon && }
{node.title}
{isLast ? ( <> ) : ( )}
); } const PathBarItem = memo(PathBarElement);