import * as React from "react"; import { CURSOR_ID, EditorActions } from "../../types"; import { EditorObjectState } from "../EditorObject/types"; import { ItemLegendProps } from "./types"; import { EditorContext } from "../../Editor"; /** * A table of contents for the web page. */ export const ItemLegend: React.FC = ({ children, content = [], title = "Your Components", }) => { const editor = React.useContext(EditorContext); const { dispatch } = editor; return (

{title}

{content .filter((itm) => itm.id !== CURSOR_ID) .map((itm, key) => { const { id, state } = itm; return (
  • { e.stopPropagation(); editor.dispatch({ type: EditorActions.CHANGE_STATE, payload: { id, state: EditorObjectState.ACTIVE }, }); }} onMouseEnter={(e) => { e.stopPropagation(); if (state !== EditorObjectState.ACTIVE) editor.dispatch({ type: EditorActions.CHANGE_STATE, payload: { id, state: EditorObjectState.HOVER }, }); }} onMouseLeave={(e) => { e.stopPropagation(); if (state !== EditorObjectState.ACTIVE) editor.dispatch({ type: EditorActions.CHANGE_STATE, payload: { id, state: EditorObjectState.NORMAL }, }); }} > {itm.type}
  • ); })}
    ); }; export default ItemLegend;