formated all code inside the src folder

This commit is contained in:
anovazzi1 2023-05-10 21:18:29 -03:00
commit b1e5e4fd19
59 changed files with 2468 additions and 2331 deletions

View file

@ -198,7 +198,9 @@ export default function ParameterComponent({
save(); save();
}} }}
/> />
):(<></>)} ) : (
<></>
)}
</> </>
</div> </div>
); );

View file

@ -1,10 +1,5 @@
import { Cog6ToothIcon, TrashIcon } from "@heroicons/react/24/outline"; import { Cog6ToothIcon, TrashIcon } from "@heroicons/react/24/outline";
import { import { classNames, nodeColors, nodeIcons, toNormalCase } from "../../utils";
classNames,
nodeColors,
nodeIcons,
toNormalCase,
} from "../../utils";
import ParameterComponent from "./components/parameterComponent"; import ParameterComponent from "./components/parameterComponent";
import { typesContext } from "../../contexts/typesContext"; import { typesContext } from "../../contexts/typesContext";
import { useContext, useState, useEffect, useRef } from "react"; import { useContext, useState, useEffect, useRef } from "react";
@ -34,7 +29,6 @@ export default function GenericNode({
const { reactFlowInstance } = useContext(typesContext); const { reactFlowInstance } = useContext(typesContext);
const [params, setParams] = useState([]); const [params, setParams] = useState([]);
useEffect(() => { useEffect(() => {
if (reactFlowInstance) { if (reactFlowInstance) {
setParams(Object.values(reactFlowInstance.toObject())); setParams(Object.values(reactFlowInstance.toObject()));

View file

@ -2,12 +2,14 @@ export default function CrashErrorComponent({ error, resetErrorBoundary }) {
return ( return (
<div className="fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-800 bg-opacity-50 z-50"> <div className="fixed top-0 left-0 w-full h-full flex items-center justify-center bg-gray-800 bg-opacity-50 z-50">
<div className="bg-white max-w-4xl h-1/3 min-h-fit rounded-lg shadow-lg p-8 text-start flex flex-col justify-evenly"> <div className="bg-white max-w-4xl h-1/3 min-h-fit rounded-lg shadow-lg p-8 text-start flex flex-col justify-evenly">
<h1 className="text-red-500 text-3xl mb-4">Oops! An unknown error has occurred.</h1> <h1 className="text-red-500 text-3xl mb-4">
Oops! An unknown error has occurred.
</h1>
<p className="text-gray-700 mb-4 text-xl"> <p className="text-gray-700 mb-4 text-xl">
Please click the 'Reset Application' button Please click the 'Reset Application' button to restore the
to restore the application's state. If the error persists, please application's state. If the error persists, please create an issue on
create an issue on our GitHub page. We apologize for any inconvenience our GitHub page. We apologize for any inconvenience this may have
this may have caused. caused.
</p> </p>
<div className="flex justify-center"> <div className="flex justify-center">
<button <button

View file

@ -1,12 +1,12 @@
import { styled } from '@mui/material/styles'; import { styled } from "@mui/material/styles";
import Tooltip, { TooltipProps, tooltipClasses } from '@mui/material/Tooltip'; import Tooltip, { TooltipProps, tooltipClasses } from "@mui/material/Tooltip";
export const LightTooltip = styled(({ className, ...props }: TooltipProps) => ( export const LightTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} /> <Tooltip {...props} classes={{ popper: className }} />
))(({ theme }) => ({ ))(({ theme }) => ({
[`& .${tooltipClasses.tooltip}`]: { [`& .${tooltipClasses.tooltip}`]: {
backgroundColor: theme.palette.common.white, backgroundColor: theme.palette.common.white,
color: 'rgba(0, 0, 0, 0.87)', color: "rgba(0, 0, 0, 0.87)",
boxShadow: theme.shadows[2], boxShadow: theme.shadows[2],
fontSize: 14, fontSize: 14,
}, },

View file

@ -2,6 +2,14 @@ import { ReactElement } from "react";
import { LightTooltip } from "../LightTooltipComponent"; import { LightTooltip } from "../LightTooltipComponent";
import { TooltipComponentType } from "../../types/components"; import { TooltipComponentType } from "../../types/components";
export default function Tooltip({ children, title,placement }:TooltipComponentType) { export default function Tooltip({
return <LightTooltip placement={placement} title={title} arrow>{children}</LightTooltip>; children,
title,
placement,
}: TooltipComponentType) {
return (
<LightTooltip placement={placement} title={title} arrow>
{children}
</LightTooltip>
);
} }

View file

@ -1,8 +1,12 @@
import { ChatBubbleLeftEllipsisIcon, ChatBubbleOvalLeftEllipsisIcon, PlusSmallIcon } from "@heroicons/react/24/outline"; import {
ChatBubbleLeftEllipsisIcon,
ChatBubbleOvalLeftEllipsisIcon,
PlusSmallIcon,
} from "@heroicons/react/24/outline";
import { useState } from "react"; import { useState } from "react";
import { ChatMessageType } from "../../../types/chat"; import { ChatMessageType } from "../../../types/chat";
import { nodeColors } from "../../../utils"; import { nodeColors } from "../../../utils";
var Convert = require('ansi-to-html'); var Convert = require("ansi-to-html");
var convert = new Convert({ newline: true }); var convert = new Convert({ newline: true });
export default function ChatMessage({ chat }: { chat: ChatMessageType }) { export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
@ -29,12 +33,15 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
style={{ backgroundColor: nodeColors["thought"] }} style={{ backgroundColor: nodeColors["thought"] }}
className=" text-start inline-block w-full pb-3 pt-3 px-5 cursor-pointer" className=" text-start inline-block w-full pb-3 pt-3 px-5 cursor-pointer"
dangerouslySetInnerHTML={{ dangerouslySetInnerHTML={{
__html: convert.toHtml(chat.thought) __html: convert.toHtml(chat.thought),
}} }}
></div> ></div>
)} )}
{chat.thought && chat.thought !== "" && !hidden && <br></br>} {chat.thought && chat.thought !== "" && !hidden && <br></br>}
<div className="w-full rounded-b-md px-4 pb-3 pt-3 pr-8" style={{ backgroundColor: nodeColors["chat"] }}> <div
className="w-full rounded-b-md px-4 pb-3 pt-3 pr-8"
style={{ backgroundColor: nodeColors["chat"] }}
>
{chat.message} {chat.message}
</div> </div>
</div> </div>

View file

@ -1,13 +1,17 @@
import { Transition } from "@headlessui/react"; import { Transition } from "@headlessui/react";
import { Bars3CenterLeftIcon, ChatBubbleBottomCenterTextIcon } from "@heroicons/react/24/outline"; import {
Bars3CenterLeftIcon,
ChatBubbleBottomCenterTextIcon,
} from "@heroicons/react/24/outline";
import { nodeColors } from "../../../utils"; import { nodeColors } from "../../../utils";
import { PopUpContext } from "../../../contexts/popUpContext"; import { PopUpContext } from "../../../contexts/popUpContext";
import { useContext } from "react"; import { useContext } from "react";
import ChatModal from "../../../modals/chatModal"; import ChatModal from "../../../modals/chatModal";
export default function ChatTrigger({ open, setOpen }) { export default function ChatTrigger({ open, setOpen }) {
const {openPopUp} = useContext(PopUpContext) const { openPopUp } = useContext(PopUpContext);
return(<Transition return (
<Transition
show={!open} show={!open}
appear={true} appear={true}
enter="transition ease-out duration-300" enter="transition ease-out duration-300"
@ -18,7 +22,10 @@ export default function ChatTrigger({open, setOpen}){
leaveTo="translate-y-96" leaveTo="translate-y-96"
> >
<div className="absolute bottom-2 right-3"> <div className="absolute bottom-2 right-3">
<div style={{backgroundColor:nodeColors['chat']}} className="border flex justify-center align-center py-1 px-3 w-12 h-12 rounded-full dark:bg-gray-800 dark:border-gray-600 dark:text-white"> <div
style={{ backgroundColor: nodeColors["chat"] }}
className="border flex justify-center align-center py-1 px-3 w-12 h-12 rounded-full dark:bg-gray-800 dark:border-gray-600 dark:text-white"
>
<button <button
onClick={() => { onClick={() => {
setOpen(true); setOpen(true);
@ -33,5 +40,6 @@ export default function ChatTrigger({open, setOpen}){
</button> </button>
</div> </div>
</div> </div>
</Transition>) </Transition>
);
} }

View file

@ -1,20 +1,27 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { FloatComponentType } from "../../types/components"; import { FloatComponentType } from "../../types/components";
export default function FloatComponent({value, onChange, disabled}: FloatComponentType){ export default function FloatComponent({
value,
onChange,
disabled,
}: FloatComponentType) {
const [myValue, setMyValue] = useState(value ?? ""); const [myValue, setMyValue] = useState(value ?? "");
useEffect(() => { useEffect(() => {
if (disabled) { if (disabled) {
setMyValue(""); setMyValue("");
onChange(""); onChange("");
} }
}, [disabled, onChange]) }, [disabled, onChange]);
return ( return (
<div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}> <div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}>
<input <input
type="number" type="number"
value={myValue} value={myValue}
className={"block w-full form-input dark:bg-gray-900 arrow-hide dark:border-gray-600 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" + (disabled ? " bg-gray-200 dark:bg-gray-700" : "")} className={
"block w-full form-input dark:bg-gray-900 arrow-hide dark:border-gray-600 rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" +
(disabled ? " bg-gray-200 dark:bg-gray-700" : "")
}
placeholder="Type a number from zero to one" placeholder="Type a number from zero to one"
onChange={(e) => { onChange={(e) => {
setMyValue(e.target.value); setMyValue(e.target.value);

View file

@ -9,7 +9,7 @@ export default function InputFileComponent({
disabled, disabled,
suffixes, suffixes,
fileTypes, fileTypes,
onFileChange onFileChange,
}: FileComponentType) { }: FileComponentType) {
const [myValue, setMyValue] = useState(value); const [myValue, setMyValue] = useState(value);
const { setErrorData } = useContext(alertContext); const { setErrorData } = useContext(alertContext);
@ -17,23 +17,23 @@ export default function InputFileComponent({
if (disabled) { if (disabled) {
setMyValue(""); setMyValue("");
onChange(""); onChange("");
onFileChange("") onFileChange("");
} }
}, [disabled, onChange]); }, [disabled, onChange]);
function attachFile(fileReadEvent: ProgressEvent<FileReader>) { function attachFile(fileReadEvent: ProgressEvent<FileReader>) {
fileReadEvent.preventDefault(); fileReadEvent.preventDefault();
const file = fileReadEvent.target.result; const file = fileReadEvent.target.result;
onFileChange(file as string) onFileChange(file as string);
} }
function checkFileType(fileName: string): boolean { function checkFileType(fileName: string): boolean {
for (let index = 0; index < suffixes.length; index++) { for (let index = 0; index < suffixes.length; index++) {
if (fileName.endsWith(suffixes[index])) { if (fileName.endsWith(suffixes[index])) {
return true return true;
} }
} }
return false return false;
} }
const handleButtonClick = () => { const handleButtonClick = () => {

View file

@ -4,22 +4,34 @@ import { InputListComponentType } from "../../types/components";
var _ = require("lodash"); var _ = require("lodash");
export default function InputListComponent({ value, onChange, disabled}:InputListComponentType) { export default function InputListComponent({
value,
onChange,
disabled,
}: InputListComponentType) {
const [inputList, setInputList] = useState(value ?? [""]); const [inputList, setInputList] = useState(value ?? [""]);
useEffect(() => { useEffect(() => {
if (disabled) { if (disabled) {
setInputList([""]); setInputList([""]);
onChange([""]); onChange([""]);
} }
}, [disabled, onChange]) }, [disabled, onChange]);
return ( return (
<div className={(disabled ? "pointer-events-none cursor-not-allowed" : "") + "flex flex-col gap-3"}> <div
className={
(disabled ? "pointer-events-none cursor-not-allowed" : "") +
"flex flex-col gap-3"
}
>
{inputList.map((i, idx) => ( {inputList.map((i, idx) => (
<div key={idx} className="w-full flex gap-3"> <div key={idx} className="w-full flex gap-3">
<input <input
type="text" type="text"
value={i} value={i}
className={"block w-full form-input rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" + (disabled ? " bg-gray-200" : "")} className={
"block w-full form-input rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" +
(disabled ? " bg-gray-200" : "")
}
placeholder="Type a text" placeholder="Type a text"
onChange={(e) => { onChange={(e) => {
setInputList((old) => { setInputList((old) => {
@ -30,23 +42,33 @@ export default function InputListComponent({ value, onChange, disabled}:InputLis
onChange(inputList); onChange(inputList);
}} }}
/> />
{idx === inputList.length - 1 ? {idx === inputList.length - 1 ? (
<button onClick={() => {setInputList((old) => { <button
onClick={() => {
setInputList((old) => {
let newInputList = _.cloneDeep(old); let newInputList = _.cloneDeep(old);
newInputList.push(''); newInputList.push("");
return newInputList; return newInputList;
}); });
onChange(inputList);}}> onChange(inputList);
}}
>
<PlusIcon className="w-4 h-4 hover:text-blue-600" /> <PlusIcon className="w-4 h-4 hover:text-blue-600" />
</button> </button>
: <button onClick={() => {setInputList((old) => { ) : (
<button
onClick={() => {
setInputList((old) => {
let newInputList = _.cloneDeep(old); let newInputList = _.cloneDeep(old);
newInputList.splice(idx, 1); newInputList.splice(idx, 1);
return newInputList; return newInputList;
}); });
onChange(inputList);}}> onChange(inputList);
}}
>
<XMarkIcon className="w-4 h-4 hover:text-red-600" /> <XMarkIcon className="w-4 h-4 hover:text-red-600" />
</button>} </button>
)}
</div> </div>
))} ))}
</div> </div>

View file

@ -14,10 +14,21 @@ export default function IntComponent({
} }
}, [disabled, onChange]); }, [disabled, onChange]);
return ( return (
<div className={disabled ? "pointer-events-none cursor-not-allowed w-full" : "w-full"}> <div
className={
disabled ? "pointer-events-none cursor-not-allowed w-full" : "w-full"
}
>
<input <input
onKeyDown={(event) => { onKeyDown={(event) => {
if (event.key !== 'Backspace' && event.key !== 'Enter' && event.key !== 'Delete' && event.key !== 'ArrowLeft' && event.key !== 'ArrowRight' && !/^[-]?\d*$/.test(event.key)) { if (
event.key !== "Backspace" &&
event.key !== "Enter" &&
event.key !== "Delete" &&
event.key !== "ArrowLeft" &&
event.key !== "ArrowRight" &&
!/^[-]?\d*$/.test(event.key)
) {
event.preventDefault(); event.preventDefault();
} }
}} }}

View file

@ -1,17 +1,28 @@
type LoadingComponentProps = { type LoadingComponentProps = {
remSize:number remSize: number;
} };
export default function LoadingComponent({ remSize }: LoadingComponentProps) { export default function LoadingComponent({ remSize }: LoadingComponentProps) {
return ( return (
<div role="status" className="w-min m-auto"> <div role="status" className="w-min m-auto">
<svg aria-hidden="true" className={`w-${remSize} h-${remSize} mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600`} viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"> <svg
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/> aria-hidden="true"
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/> className={`w-${remSize} h-${remSize} mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600`}
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg> </svg>
<br></br> <br></br>
<span className="animate-pulse text-blue-600 text-lg">Loading...</span> <span className="animate-pulse text-blue-600 text-lg">Loading...</span>
</div> </div>
) );
} }

View file

@ -4,7 +4,11 @@ import { PopUpContext } from "../../contexts/popUpContext";
import TextAreaModal from "../../modals/textAreaModal"; import TextAreaModal from "../../modals/textAreaModal";
import { TextAreaComponentType } from "../../types/components"; import { TextAreaComponentType } from "../../types/components";
export default function TextAreaComponent({ value, onChange, disabled }:TextAreaComponentType) { export default function TextAreaComponent({
value,
onChange,
disabled,
}: TextAreaComponentType) {
const [myValue, setMyValue] = useState(value); const [myValue, setMyValue] = useState(value);
const { openPopUp } = useContext(PopUpContext); const { openPopUp } = useContext(PopUpContext);
useEffect(() => { useEffect(() => {
@ -16,15 +20,38 @@ export default function TextAreaComponent({ value, onChange, disabled }:TextArea
return ( return (
<div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}> <div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}>
<div className="w-full flex items-center gap-3"> <div className="w-full flex items-center gap-3">
<span onClick={()=>{openPopUp(<TextAreaModal value={myValue} setValue={(t:string) => {setMyValue(t); onChange(t);}}/>)}} <span
onClick={() => {
openPopUp(
<TextAreaModal
value={myValue}
setValue={(t: string) => {
setMyValue(t);
onChange(t);
}}
/>
);
}}
className={ className={
"truncate block w-full text-gray-500 px-3 py-2 rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" + "truncate block w-full text-gray-500 px-3 py-2 rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" +
(disabled ? " bg-gray-200" : "") (disabled ? " bg-gray-200" : "")
} }
> >
{myValue !== "" ? myValue : 'Text empty'} {myValue !== "" ? myValue : "Text empty"}
</span> </span>
<button onClick={()=>{openPopUp(<TextAreaModal value={myValue} setValue={(t:string) => {setMyValue(t); onChange(t);}}/>)}}> <button
onClick={() => {
openPopUp(
<TextAreaModal
value={myValue}
setValue={(t: string) => {
setMyValue(t);
onChange(t);
}}
/>
);
}}
>
<ArrowTopRightOnSquareIcon className="w-6 h-6 hover:text-blue-600" /> <ArrowTopRightOnSquareIcon className="w-6 h-6 hover:text-blue-600" />
</button> </button>
</div> </div>

View file

@ -3,12 +3,16 @@ import { classNames } from "../../utils";
import { useEffect } from "react"; import { useEffect } from "react";
import { ToggleComponentType } from "../../types/components"; import { ToggleComponentType } from "../../types/components";
export default function ToggleComponent({ enabled, setEnabled, disabled }:ToggleComponentType) { export default function ToggleComponent({
enabled,
setEnabled,
disabled,
}: ToggleComponentType) {
useEffect(() => { useEffect(() => {
if (disabled) { if (disabled) {
setEnabled(false); setEnabled(false);
} }
}, [disabled, setEnabled]) }, [disabled, setEnabled]);
return ( return (
<div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}> <div className={disabled ? "pointer-events-none cursor-not-allowed" : ""}>
<Switch <Switch
@ -25,7 +29,10 @@ export default function ToggleComponent({ enabled, setEnabled, disabled }:Toggle
<span <span
className={classNames( className={classNames(
enabled ? "translate-x-5" : "translate-x-0", enabled ? "translate-x-5" : "translate-x-0",
"pointer-events-none relative inline-block h-5 w-5 transform rounded-full shadow ring-0 transition duration-200 ease-in-out", disabled ? "bg-gray-200 dark:bg-gray-600" : "bg-white dark:bg-gray-800" "pointer-events-none relative inline-block h-5 w-5 transform rounded-full shadow ring-0 transition duration-200 ease-in-out",
disabled
? "bg-gray-200 dark:bg-gray-600"
: "bg-white dark:bg-gray-800"
)} )}
> >
<span <span

View file

@ -119,7 +119,8 @@ function setSuccessData(newState: { title: string }) {
// If the new state has a "title" property, add a new success notification to the list // If the new state has a "title" property, add a new success notification to the list
if (newState.title) { if (newState.title) {
setNotificationCenter(true); // show the notification center setNotificationCenter(true); // show the notification center
pushNotificationList({ // add the new notification to the list pushNotificationList({
// add the new notification to the list
type: "success", type: "success",
title: newState.title, title: newState.title,
id: _.uniqueId(), id: _.uniqueId(),

View file

@ -20,7 +20,7 @@ export function DarkProvider({ children }) {
} else { } else {
document.getElementById("body").classList.remove("dark"); document.getElementById("body").classList.remove("dark");
} }
}, [dark]) }, [dark]);
return ( return (
<darkContext.Provider <darkContext.Provider
value={{ value={{

View file

@ -15,11 +15,11 @@ const PopUpProvider = ({ children }: PopUpProviderProps) => {
const [popUpElements, setPopUpElements] = useState<JSX.Element[]>([]); const [popUpElements, setPopUpElements] = useState<JSX.Element[]>([]);
const openPopUp = (element: JSX.Element) => { const openPopUp = (element: JSX.Element) => {
setPopUpElements(prevPopUps => [element, ...prevPopUps]); setPopUpElements((prevPopUps) => [element, ...prevPopUps]);
}; };
const closePopUp = () => { const closePopUp = () => {
setPopUpElements(prevPopUps => prevPopUps.slice(1)); setPopUpElements((prevPopUps) => prevPopUps.slice(1));
}; };
return ( return (

View file

@ -15,7 +15,7 @@ const initialValue:typesContextType = {
templates: {}, templates: {},
setTemplates: () => {}, setTemplates: () => {},
data: {}, data: {},
setData:()=>{} setData: () => {},
}; };
export const typesContext = createContext<typesContextType>(initialValue); export const typesContext = createContext<typesContextType>(initialValue);
@ -36,8 +36,8 @@ export function TypesProvider({ children }:{children:ReactNode}) {
setTemplates( setTemplates(
Object.keys(result.data).reduce((acc, curr) => { Object.keys(result.data).reduce((acc, curr) => {
Object.keys(result.data[curr]).forEach((c: keyof APIKindType) => { Object.keys(result.data[curr]).forEach((c: keyof APIKindType) => {
acc[c] = result.data[curr][c] acc[c] = result.data[curr][c];
}) });
return acc; return acc;
}, {}) }, {})
); );
@ -63,7 +63,11 @@ export function TypesProvider({ children }:{children:ReactNode}) {
reactFlowInstance.setNodes( reactFlowInstance.setNodes(
reactFlowInstance.getNodes().filter((n: Node) => n.id !== idx) reactFlowInstance.getNodes().filter((n: Node) => n.id !== idx)
); );
reactFlowInstance.setEdges(reactFlowInstance.getEdges().filter((ns) => ns.source !== idx && ns.target !== idx)); reactFlowInstance.setEdges(
reactFlowInstance
.getEdges()
.filter((ns) => ns.source !== idx && ns.target !== idx)
);
} }
return ( return (
<typesContext.Provider <typesContext.Provider
@ -76,7 +80,7 @@ export function TypesProvider({ children }:{children:ReactNode}) {
setTemplates, setTemplates,
templates, templates,
data, data,
setData setData,
}} }}
> >
{children} {children}

View file

@ -1,15 +1,13 @@
body { body {
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif; sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
} }
code { code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
monospace; monospace;
} }

View file

@ -11,7 +11,6 @@ const root = ReactDOM.createRoot(
root.render( root.render(
<ContextWrapper> <ContextWrapper>
<BrowserRouter> <BrowserRouter>
<App /> <App />
</BrowserRouter> </BrowserRouter>
</ContextWrapper> </ContextWrapper>

View file

@ -87,9 +87,13 @@ export default function NodeModal({ data }: { data: NodeDataType }) {
<div className="flex h-full w-full"> <div className="flex h-full w-full">
<div className="overflow-hidden px-4 sm:p-4 w-full rounded-lg bg-white dark:bg-gray-800 shadow"> <div className="overflow-hidden px-4 sm:p-4 w-full rounded-lg bg-white dark:bg-gray-800 shadow">
<div className="flex flex-col h-full gap-5"> <div className="flex flex-col h-full gap-5">
{ {Object.keys(data.node.template)
Object.keys(data.node.template) .filter(
.filter((t) => t.charAt(0) !== "_"&& data.node.template[t].advanced && data.node.template[t].show) (t) =>
t.charAt(0) !== "_" &&
data.node.template[t].advanced &&
data.node.template[t].show
)
.map((t: string, idx) => { .map((t: string, idx) => {
return ( return (
<ModalField <ModalField
@ -99,9 +103,7 @@ export default function NodeModal({ data }: { data: NodeDataType }) {
data.node.template[t].display_name data.node.template[t].display_name
? data.node.template[t].display_name ? data.node.template[t].display_name
: data.node.template[t].name : data.node.template[t].name
? toNormalCase( ? toNormalCase(data.node.template[t].name)
data.node.template[t].name
)
: toNormalCase(t) : toNormalCase(t)
} }
required={data.node.template[t].required} required={data.node.template[t].required}
@ -116,8 +118,7 @@ export default function NodeModal({ data }: { data: NodeDataType }) {
type={data.node.template[t].type} type={data.node.template[t].type}
/> />
); );
}) })}
}
</div> </div>
</div> </div>
</div> </div>

View file

@ -1,8 +1,8 @@
import { IconCheck, IconClipboard, IconDownload } from '@tabler/icons-react'; import { IconCheck, IconClipboard, IconDownload } from "@tabler/icons-react";
import { FC, memo, useState } from 'react'; import { FC, memo, useState } from "react";
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism'; import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism";
import { programmingLanguages } from '../../../../utils'; import { programmingLanguages } from "../../../../utils";
interface Props { interface Props {
language: string; language: string;
@ -26,24 +26,21 @@ export const CodeBlock: FC<Props> = memo(({ language, value }) => {
}); });
}; };
const downloadAsFile = () => { const downloadAsFile = () => {
const fileExtension = programmingLanguages[language] || '.file'; const fileExtension = programmingLanguages[language] || ".file";
const suggestedFileName = `${"generated-code"}${fileExtension}`; const suggestedFileName = `${"generated-code"}${fileExtension}`;
const fileName = window.prompt( const fileName = window.prompt("enter file name", suggestedFileName);
"enter file name",
suggestedFileName,
);
if (!fileName) { if (!fileName) {
// user pressed cancel on prompt // user pressed cancel on prompt
return; return;
} }
const blob = new Blob([value], { type: 'text/plain' }); const blob = new Blob([value], { type: "text/plain" });
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const link = document.createElement('a'); const link = document.createElement("a");
link.download = fileName; link.download = fileName;
link.href = url; link.href = url;
link.style.display = 'none'; link.style.display = "none";
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
@ -60,7 +57,7 @@ export const CodeBlock: FC<Props> = memo(({ language, value }) => {
onClick={copyToClipboard} onClick={copyToClipboard}
> >
{isCopied ? <IconCheck size={18} /> : <IconClipboard size={18} />} {isCopied ? <IconCheck size={18} /> : <IconClipboard size={18} />}
{isCopied ? 'Copied!' : 'Copy code'} {isCopied ? "Copied!" : "Copy code"}
</button> </button>
<button <button
className="flex items-center rounded bg-none p-1 text-xs text-white" className="flex items-center rounded bg-none p-1 text-xs text-white"
@ -81,4 +78,4 @@ export const CodeBlock: FC<Props> = memo(({ language, value }) => {
</div> </div>
); );
}); });
CodeBlock.displayName = 'CodeBlock'; CodeBlock.displayName = "CodeBlock";

View file

@ -69,20 +69,27 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
components={{ components={{
code({ node, inline, className, children, ...props }) { code({ node, inline, className, children, ...props }) {
if (children.length) { if (children.length) {
if (children[0] == '▍') { if (children[0] == "▍") {
return <span className="animate-pulse cursor-default mt-1">▍</span> return (
<span className="animate-pulse cursor-default mt-1">
▍
</span>
);
} }
children[0] = (children[0] as string).replace("`▍`", "▍") children[0] = (children[0] as string).replace(
"`▍`",
"▍"
);
} }
const match = /language-(\w+)/.exec(className || ''); const match = /language-(\w+)/.exec(className || "");
return !inline ? ( return !inline ? (
<CodeBlock <CodeBlock
key={Math.random()} key={Math.random()}
language={(match && match[1]) || ''} language={(match && match[1]) || ""}
value={String(children).replace(/\n$/, '')} value={String(children).replace(/\n$/, "")}
{...props} {...props}
/> />
) : ( ) : (
@ -90,7 +97,7 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
{children} {children}
</code> </code>
); );
} },
}} }}
> >
{message} {message}

View file

@ -39,7 +39,10 @@ export default function FileCard({ fileName, content, fileType }) {
<div <div
className={`absolute top-0 right-0 bg-gray-100 text-gray-700 rounded-bl-lg px-1 text-sm font-bold`} className={`absolute top-0 right-0 bg-gray-100 text-gray-700 rounded-bl-lg px-1 text-sm font-bold`}
> >
<button className="hover:scale-125 text-blue-500 py-1 px-2" onClick={handleDownload}> <button
className="hover:scale-125 text-blue-500 py-1 px-2"
onClick={handleDownload}
>
<CloudArrowDownIcon className="w-5 h-5 text-current"></CloudArrowDownIcon> <CloudArrowDownIcon className="w-5 h-5 text-current"></CloudArrowDownIcon>
</button> </button>
</div> </div>

View file

@ -134,7 +134,7 @@ export default function CodeAreaModal({
title: "Code is ready to run", title: "Code is ready to run",
}); });
setModalOpen(false); setModalOpen(false);
setValue(code) setValue(code);
} else { } else {
if (funcErrors.length !== 0) { if (funcErrors.length !== 0) {
setErrorData({ setErrorData({

View file

@ -135,7 +135,8 @@ export default function PromptAreaModal({
return setErrorData({ return setErrorData({
title: title:
"There is something wrong with this prompt, please review it", "There is something wrong with this prompt, please review it",
list:[error.response.data.detail]}); list: [error.response.data.detail],
});
}); });
}} }}
> >

View file

@ -1,9 +1,18 @@
import { Dialog, Transition } from "@headlessui/react"; import { Dialog, Transition } from "@headlessui/react";
import { XMarkIcon, ClipboardDocumentListIcon } from "@heroicons/react/24/outline"; import {
XMarkIcon,
ClipboardDocumentListIcon,
} from "@heroicons/react/24/outline";
import { Fragment, useContext, useRef, useState } from "react"; import { Fragment, useContext, useRef, useState } from "react";
import { PopUpContext } from "../../contexts/popUpContext"; import { PopUpContext } from "../../contexts/popUpContext";
export default function TextAreaModal({value, setValue}:{setValue:(value:string)=>void,value:string|string[]}){ export default function TextAreaModal({
value,
setValue,
}: {
setValue: (value: string) => void;
value: string | string[];
}) {
const [open, setOpen] = useState(true); const [open, setOpen] = useState(true);
const [myValue, setMyValue] = useState(value); const [myValue, setMyValue] = useState(value);
const { closePopUp } = useContext(PopUpContext); const { closePopUp } = useContext(PopUpContext);
@ -11,7 +20,9 @@ export default function TextAreaModal({value, setValue}:{setValue:(value:string)
function setModalOpen(x: boolean) { function setModalOpen(x: boolean) {
setOpen(x); setOpen(x);
if (x === false) { if (x === false) {
setTimeout(() => {closePopUp()}, 300); setTimeout(() => {
closePopUp();
}, 300);
} }
} }
return ( return (
@ -78,7 +89,15 @@ export default function TextAreaModal({value, setValue}:{setValue:(value:string)
<div className="h-full w-full bg-gray-200 dark:bg-gray-900 p-4 gap-4 flex flex-row justify-center items-center"> <div className="h-full w-full bg-gray-200 dark:bg-gray-900 p-4 gap-4 flex flex-row justify-center items-center">
<div className="flex h-full w-full"> <div className="flex h-full w-full">
<div className="overflow-hidden px-4 py-5 sm:p-6 w-full rounded-lg bg-white dark:bg-gray-800 shadow"> <div className="overflow-hidden px-4 py-5 sm:p-6 w-full rounded-lg bg-white dark:bg-gray-800 shadow">
<textarea ref={ref} className="form-input h-full w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-white" value={myValue} onChange={(e) => {setMyValue(e.target.value); setValue(e.target.value)}}/> <textarea
ref={ref}
className="form-input h-full w-full rounded-lg border-gray-300 dark:border-gray-700 dark:bg-gray-900 dark:text-white"
value={myValue}
onChange={(e) => {
setMyValue(e.target.value);
setValue(e.target.value);
}}
/>
</div> </div>
</div> </div>
</div> </div>
@ -100,5 +119,5 @@ export default function TextAreaModal({value, setValue}:{setValue:(value:string)
</div> </div>
</Dialog> </Dialog>
</Transition.Root> </Transition.Root>
) );
} }

View file

@ -1,13 +1,11 @@
import { ConnectionLineComponentProps } from 'reactflow'; import { ConnectionLineComponentProps } from "reactflow";
const ConnectionLineComponent = ({ const ConnectionLineComponent = ({
fromX, fromX,
fromY, fromY,
toX, toX,
toY, toY,
connectionLineStyle = {} // provide a default value for connectionLineStyle connectionLineStyle = {}, // provide a default value for connectionLineStyle
}: ConnectionLineComponentProps) => { }: ConnectionLineComponentProps) => {
return ( return (
<g> <g>

View file

@ -1,14 +1,11 @@
import { import { ChevronRightIcon } from "@heroicons/react/24/solid";
ChevronRightIcon,
} from "@heroicons/react/24/solid";
import { Disclosure } from "@headlessui/react"; import { Disclosure } from "@headlessui/react";
import { DisclosureComponentType } from "../../../../types/components"; import { DisclosureComponentType } from "../../../../types/components";
export default function DisclosureComponent({ export default function DisclosureComponent({
button: { title, Icon, buttons = [] }, button: { title, Icon, buttons = [] },
children, children,
}: DisclosureComponentType }: DisclosureComponentType) {
) {
return ( return (
<Disclosure as="div" key={title}> <Disclosure as="div" key={title}>
{({ open }) => ( {({ open }) => (

View file

@ -3,13 +3,10 @@ import DisclosureComponent from "../DisclosureComponent";
import { nodeColors, nodeIcons, nodeNames } from "../../../../utils"; import { nodeColors, nodeIcons, nodeNames } from "../../../../utils";
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState } from "react";
import { typesContext } from "../../../../contexts/typesContext"; import { typesContext } from "../../../../contexts/typesContext";
import { import { APIClassType, APIObjectType } from "../../../../types/api";
APIClassType,
APIObjectType,
} from "../../../../types/api";
export default function ExtraSidebar() { export default function ExtraSidebar() {
const {data} = useContext(typesContext) const { data } = useContext(typesContext);
function onDragStart( function onDragStart(
event: React.DragEvent<any>, event: React.DragEvent<any>,
@ -22,7 +19,9 @@ export default function ExtraSidebar() {
return ( return (
<div className="mt-1 w-full"> <div className="mt-1 w-full">
{Object.keys(data).sort().map((d: keyof APIObjectType, i) => ( {Object.keys(data)
.sort()
.map((d: keyof APIObjectType, i) => (
<DisclosureComponent <DisclosureComponent
key={i} key={i}
button={{ button={{
@ -31,7 +30,9 @@ export default function ExtraSidebar() {
}} }}
> >
<div className="p-2 flex flex-col gap-2"> <div className="p-2 flex flex-col gap-2">
{Object.keys(data[d]).sort().map((t: string, k) => ( {Object.keys(data[d])
.sort()
.map((t: string, k) => (
<div key={k}> <div key={k}>
<div <div
draggable draggable

View file

@ -5,9 +5,16 @@ import { FlowType } from "../../../../types/flow";
var _ = require("lodash"); var _ = require("lodash");
export default function TabComponent({ selected, flow, onClick }:{flow:FlowType,selected:boolean,onClick:()=>void}) { export default function TabComponent({
const { removeFlow, updateFlow, flows } = selected,
useContext(TabsContext); flow,
onClick,
}: {
flow: FlowType;
selected: boolean;
onClick: () => void;
}) {
const { removeFlow, updateFlow, flows } = useContext(TabsContext);
const [isRename, setIsRename] = useState(false); const [isRename, setIsRename] = useState(false);
const [value, setValue] = useState(""); const [value, setValue] = useState("");
return ( return (
@ -85,4 +92,3 @@ export default function TabComponent({ selected, flow, onClick }:{flow:FlowType,
</> </>
); );
} }

View file

@ -94,9 +94,7 @@ export default function TabsManagerComponent() {
> >
<AlertDropdown /> <AlertDropdown />
</div> </div>
<div className="h-screen w-screen fixed top-0 left-0"> <div className="h-screen w-screen fixed top-0 left-0"></div>
</div>
</> </>
); );
}} }}

View file

@ -30,8 +30,7 @@ const nodeTypes = {
var _ = require("lodash"); var _ = require("lodash");
export default function FlowPage({ flow }: { flow: FlowType }) { export default function FlowPage({ flow }: { flow: FlowType }) {
let { updateFlow, incrementNodeId} = let { updateFlow, incrementNodeId } = useContext(TabsContext);
useContext(TabsContext);
const { types, reactFlowInstance, setReactFlowInstance, templates } = const { types, reactFlowInstance, setReactFlowInstance, templates } =
useContext(typesContext); useContext(typesContext);
const reactFlowWrapper = useRef(null); const reactFlowWrapper = useRef(null);
@ -211,8 +210,7 @@ export default function FlowPage({ flow }:{flow:FlowType}) {
selectNodesOnDrag={false} selectNodesOnDrag={false}
> >
<Background className="dark:bg-gray-900" /> <Background className="dark:bg-gray-900" />
<Controls className="[&>button]:text-black [&>button]:dark:bg-gray-800 hover:[&>button]:dark:bg-gray-700 [&>button]:dark:text-gray-400 [&>button]:dark:fill-gray-400 [&>button]:dark:border-gray-600"> <Controls className="[&>button]:text-black [&>button]:dark:bg-gray-800 hover:[&>button]:dark:bg-gray-700 [&>button]:dark:text-gray-400 [&>button]:dark:fill-gray-400 [&>button]:dark:border-gray-600"></Controls>
</Controls>
</ReactFlow> </ReactFlow>
<Chat flow={flow} reactFlowInstance={reactFlowInstance} /> <Chat flow={flow} reactFlowInstance={reactFlowInstance} />
</> </>

View file

@ -14,4 +14,9 @@ export type TabsContextType = {
hardReset: () => void; hardReset: () => void;
}; };
export type LangFlowState={ tabIndex:number, flows:FlowType[], id:string, nodeId:number } export type LangFlowState = {
tabIndex: number;
flows: FlowType[];
id: string;
nodeId: number;
};

View file

@ -1,5 +1,4 @@
const template: { [char: string]: string } = {};
const template:{[char: string]: string}={}
export type TemplateContextType = { export type TemplateContextType = {
templates: typeof template; templates: typeof template;

View file

@ -1,9 +1,8 @@
import { ReactFlowInstance } from "reactflow"; import { ReactFlowInstance } from "reactflow";
const types: { [char: string]: string } = {}; const types: { [char: string]: string } = {};
const template:{[char: string]: string}={} const template: { [char: string]: string } = {};
const data:{[char: string]: string}={} const data: { [char: string]: string } = {};
export type typesContextType = { export type typesContextType = {
reactFlowInstance: ReactFlowInstance | null; reactFlowInstance: ReactFlowInstance | null;

View file

@ -327,7 +327,8 @@ export function toNormalCase(str: string) {
}) })
.join(" "); .join(" ");
return result.split("-") return result
.split("-")
.map((word, index) => { .map((word, index) => {
if (index === 0) { if (index === 0) {
return word[0].toUpperCase() + word.slice(1).toLowerCase(); return word[0].toUpperCase() + word.slice(1).toLowerCase();
@ -460,29 +461,28 @@ interface languageMap {
} }
export const programmingLanguages: languageMap = { export const programmingLanguages: languageMap = {
javascript: '.js', javascript: ".js",
python: '.py', python: ".py",
java: '.java', java: ".java",
c: '.c', c: ".c",
cpp: '.cpp', cpp: ".cpp",
'c++': '.cpp', "c++": ".cpp",
'c#': '.cs', "c#": ".cs",
ruby: '.rb', ruby: ".rb",
php: '.php', php: ".php",
swift: '.swift', swift: ".swift",
'objective-c': '.m', "objective-c": ".m",
kotlin: '.kt', kotlin: ".kt",
typescript: '.ts', typescript: ".ts",
go: '.go', go: ".go",
perl: '.pl', perl: ".pl",
rust: '.rs', rust: ".rs",
scala: '.scala', scala: ".scala",
haskell: '.hs', haskell: ".hs",
lua: '.lua', lua: ".lua",
shell: '.sh', shell: ".sh",
sql: '.sql', sql: ".sql",
html: '.html', html: ".html",
css: '.css', css: ".css",
// add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component // add more file extensions here, make sure the key is same as language prop in CodeBlock.tsx component
}; };