import React from "react"; import { observer } from "mobx-react"; import { sourceRootDir } from "eez-studio-shared/util"; import { DASHBOARD_PROJECT_ICON, EEZ_GUI_PROJECT_ICON, LVGL_PROJECT_ICON } from "project-editor/ui-components/icons"; import { ComponentInfo } from "../component-info"; import { ComponentInputs } from "./ComponentInputs"; import { ComponentOutputs } from "./ComponentOutputs"; import { ComponentProperties } from "./ComponentProperties"; import { BodySection } from "./BodySection"; //////////////////////////////////////////////////////////////////////////////// export const ComponentHelp = observer( class ComponentHelp extends React.Component<{ componentInfo: ComponentInfo; generateHTML: boolean; }> { divRef = React.createRef(); dispose: (() => void) | undefined; fixMarkdown() { if (this.dispose) { this.dispose(); this.dispose = undefined; } const div = this.divRef.current; if (!div) { return; } const { generateHTML } = this.props; const imageSrcPrefix = generateHTML ? "" : `file://${sourceRootDir()}/../help/en-US/components/`; $.each($(div).find(".markdown"), function () { $.each($(this).find("img"), function () { let src = $(this).attr("src"); if ( typeof src == "string" && !src.startsWith("http://") && !src.startsWith("https://") && !src.startsWith("file://") ) { if (src.startsWith("../")) { src = src.substring("../".length); } $(this).attr("src", `${imageSrcPrefix}${src}`); } }); if (!generateHTML) { this.style.visibility = "visible"; } }); if (!generateHTML) { $(div).find(".markdown a").on("click", this.onClick); this.dispose = () => { $(div).find(".markdown a").off("click", this.onClick); }; } } componentDidMount() { this.fixMarkdown(); } componentDidUpdate() { this.fixMarkdown(); } componentWillUnmount(): void { if (this.dispose) { this.dispose(); this.dispose = undefined; } } onClick = (event: JQuery.ClickEvent) => { event.preventDefault(); event.stopPropagation(); openLink(event.target.href); }; render() { const { componentInfo } = this.props; const isDashboardComponent = componentInfo.isDashboardComponent != undefined; const isEezGuiComponent = componentInfo.isEezGuiComponent != undefined; const isLVGLComponent = componentInfo.isLVGLComponent != undefined; componentInfo.readAllMarkdown(); return (
{componentInfo.icon}
{componentInfo.nameWithoutProjectType}
{isDashboardComponent && DASHBOARD_PROJECT_ICON(36)} {isEezGuiComponent && EEZ_GUI_PROJECT_ICON(36)} {isLVGLComponent && LVGL_PROJECT_ICON(36)}
{this.props.componentInfo.renderDescription( this.props.generateHTML )} {!this.props.componentInfo.isEmptyProperties() && ( )} {!this.props.componentInfo.isEmptyInputs() && ( )} {!this.props.componentInfo.isEmptyOutputs() && ( )} {!this.props.componentInfo.isEmptyExamples() && ( {this.props.componentInfo.renderExamples( this.props.generateHTML )} )}
); } } ); function openLink(url: string) { const { shell } = require("electron"); shell.openExternal(url); }