"use client"; import { v4 as uuid4 } from "uuid"; import classNames from "classnames"; import { Fragment, MouseEvent, MutableRefObject, useCallback, useEffect, useRef, useState, memo } from "react"; import { useModal } from "@/ui/elements/Modal"; import { CaretIcon, CloseIcon, PlusIcon } from "@/ui/Icons"; import PopupMenu from "@/ui/elements/PopupMenu"; import { IconButton, TextArea, Modal, GhostButton, CTAButton } from "@/ui/elements"; import { GraphControlsAPI } from "@/app/(graph)/GraphControls"; import GraphVisualization, { GraphVisualizationAPI } from "@/app/(graph)/GraphVisualization"; import NotebookCellHeader from "./NotebookCellHeader"; import MarkdownPreview from "./MarkdownPreview"; import { Cell, Notebook as NotebookType } from "./types"; interface NotebookProps { notebook: NotebookType; runCell: (notebook: NotebookType, cell: Cell, cogneeInstance: string) => Promise; updateNotebook: (updatedNotebook: NotebookType) => void; } interface NotebookCellProps { cell: Cell; index: number; isOpen: boolean; isMarkdownEditMode: boolean; onToggleOpen: () => void; onToggleMarkdownEdit: () => void; onContentChange: (value: string) => void; onCellRun: (cell: Cell, cogneeInstance: string) => Promise; onCellRename: (cell: Cell) => void; onCellRemove: (cell: Cell) => void; onCellUp: (cell: Cell) => void; onCellDown: (cell: Cell) => void; onCellAdd: (afterCellIndex: number, cellType: "markdown" | "code") => void; } const NotebookCell = memo(function NotebookCell({ cell, index, isOpen, isMarkdownEditMode, onToggleOpen, onToggleMarkdownEdit, onContentChange, onCellRun, onCellRename, onCellRemove, onCellUp, onCellDown, onCellAdd, }: NotebookCellProps) { return (
{cell.type === "code" ? ( <>
{isOpen && ( <>