The Open Standard for Generative UI
demo
abhishek06a5c2f4efc3
diff --git a/frontend-sdk/packages/react-ui/cp-css.js b/frontend-sdk/packages/react-ui/cp-css.jsnew file mode 100644index 000000000..501444313--- /dev/null+++ b/frontend-sdk/packages/react-ui/cp-css.js@@ -0,0 +1,48 @@+const fs = require('fs');+const path = require('path');++// Create directories if they don't exist+function ensureDirectoryExists(dirPath) {+ if (!fs.existsSync(dirPath)) {+ fs.mkdirSync(dirPath, { recursive: true });+ }+}++// Copy CSS files from src to dist+function copyCssFiles() {+ const srcDir = path.join(__dirname, 'src', 'components');+ const distDir = path.join(__dirname, 'dist', 'styles');++ // Ensure the dist/styles directory exists+ ensureDirectoryExists(distDir);++ // Read all component directories+ const components = fs.readdirSync(srcDir);++ components.forEach(component => {+ const componentSrcPath = path.join(srcDir, component);++ // Skip if not a directory+ if (!fs.statSync(componentSrcPath).isDirectory()) {+ return;+ }++ // Look specifically for style.css+ const stylePath = path.join(componentSrcPath, 'style.css');++ if (fs.existsSync(stylePath)) {+ // Copy style.css to dist/styles/<component>.css+ const distFile = path.join(distDir, `${component}.css`);+ fs.copyFileSync(stylePath, distFile);+ console.log(`Copied ${stylePath} to ${distFile}`);+ }+ });+}++try {+ copyCssFiles();+ console.log('CSS files copied successfully!');+} catch (error) {+ console.error('Error copying CSS files:', error);+ process.exit(1);+}diff --git a/frontend-sdk/packages/react-ui/package.json b/frontend-sdk/packages/react-ui/package.jsonindex a375313f8..9731be4c0 100644--- a/frontend-sdk/packages/react-ui/package.json+++ b/frontend-sdk/packages/react-ui/package.json@@ -4,29 +4,38 @@"description": "","main": "dist/index.js","types": "dist/index.d.ts",+ "exports": {+ ".": {+ "types": "./dist/index.d.ts",+ "default": "./dist/index.js"+ },+ "./styles/*": {+ "default": "./dist/styles/*"+ }+ },"files": ["dist"],"scripts": {"test": "echo \"Error: no test specified\" && exit 1",- "build": "tsc -p .",+ "build": "tsc -p . && pnpm run copy-css","lint": "eslint src --ext .ts,.tsx","format": "prettier --write src","storybook": "storybook dev -p 6006",- "build-storybook": "storybook build"+ "build-storybook": "storybook build",+ "copy-css": "node cp-css.js"},"peerDependencies": {- "ai": "^4.0.3","react": "19.0.0-rc-66855b96-20241106","react-dom": "19.0.0-rc-66855b96-20241106","tailwind-merge": "^2.5.4","tailwindcss": "^3.0.0","tailwindcss-animate": "^1.0.7","tiny-invariant": "^1.3.3",- "zustand": "^5.0.2"+ "zustand": "^5.0.2",+ "@crayonai/react-core": "workspace:*"},"dependencies": {- "@crayonai/react-core": "workspace:*","clsx": "^2.0.0","lucide-react": "^0.469.0"},diff --git a/frontend-sdk/packages/react-ui/src/components/Fullscreen.tsx b/frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsxsimilarity index 62%rename from frontend-sdk/packages/react-ui/src/components/Fullscreen.tsxrename to frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsxindex ce2bb9141..3d2fbdcc0 100644--- a/frontend-sdk/packages/react-ui/src/components/Fullscreen.tsx+++ b/frontend-sdk/packages/react-ui/src/components/fullscreen/Fullscreen.tsx@@ -1,4 +1,6 @@import {+ Message,+ Thread,useThreadActions,useThreadListActions,useThreadListState,@@ -6,9 +8,9 @@ import {} from "@crayonai/react-core";import clsx from "clsx";import { PanelLeft, PanelRight, Plus, Search, SendHorizontal } from "lucide-react";-import { createContext, useContext, useRef, useState } from "react";-import { useComposerState } from "../hooks/useComposerState";-import { useScrollToBottom } from "../hooks/useScrollToBottom";+import { createContext, Fragment, useContext, useEffect, useRef, useState } from "react";+import { useComposerState } from "../../hooks/useComposerState";+import { useScrollToBottom } from "../../hooks/useScrollToBottom";export const Container = ({children,@@ -131,11 +133,18 @@ export const ThreadButton = ({className?: string;}) => {const { selectThread } = useThreadListActions();+ const { selectedThreadId } = useThreadListState();return (<buttononClick={() => selectThread(id)}- className={clsx("cui-fullscreen-thread-button", className)}+ className={clsx(+ "cui-fullscreen-thread-button",+ {+ "cui-fullscreen-thread-button-selected": selectedThreadId === id,+ },+ className,+ )}>{title}</button>@@ -144,19 +153,80 @@ export const ThreadButton = ({export const ThreadList = ({ className }: { className?: string }) => {const { threads } = useThreadListState();+ const { load } = useThreadListActions();+ const { searchText } = useContext(SidebarContext);++ useEffect(() => {+ load();+ }, []);++ const groupThreads = () => {+ const now = new Date();+ const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());+ const yesterday = new Date(today);+ yesterday.setDate(yesterday.getDate() - 1);+ const last7Days = new Date(today);+ last7Days.setDate(last7Days.getDate() - 7);+ const last30Days = new Date(today);+ last30Days.setDate(last30Days.getDate() - 30);+ const thisYear = new Date(today);+ thisYear.setMonth(0, 1);++ return threads.reduce(+ (groups, thread) => {+ const threadDate = new Date(thread.createdAt);++ if (threadDate >= today) {+ groups.today = [...(groups.today || []), thread];+ } else if (threadDate >= yesterday) {+ groups.yesterday = [...(groups.yesterday || []), thread];+ } else if (threadDate >= last7Days) {+ groups.last7Days = [...(groups.last7Days || []), thread];+ } else if (threadDate >= last30Days) {+ groups.last30Days = [...(groups.last30Days || []), thread];+ } else if (threadDate >= thisYear) {+ groups.thisYear = [...(groups.thisYear || []), thread];+ } else {+ groups.older = [...(groups.older || []), thread];+ }++ return groups;+ },+ {+ today: [] as Thread[],+ yesterday: [] as Thread[],+ last7Days: [] as Thread[],+ last30Days: [] as Thread[],+ thisYear: [] as Thread[],+ older: [] as Thread[],+ },+ );+ };++ const groupedThreads = groupThreads();+ const groupLabels: { [key in keyof typeof groupedThreads]: string } = {+ today: "Today",+ yesterday: "Yesterday",+ last7Days: "Previous 7 Days",+ last30Days: "Previous 30 Days",+ thisYear: "This Year",+ older: "Older",+ };return (<div className={clsx("cui-fullscreen-thread-list", className)}>- <div className="cui-fullscreen-thread-list-group ">Today</div>- <ThreadButton- className=""- key={123}- id={"thread.threadId"}- title={"thread.titleosdnfoiwnsofnwornwijrifgjowijrnig"}- />- {threads.map((thread) => (- <ThreadButton key={thread.threadId} id={thread.threadId} title={thread.title} />- ))}+ {Object.entries(groupedThreads)+ .filter(([_, groupThreads]) => groupThreads.length > 0)+ .map(([group, groupThreads]) => (+ <Fragment key={group}>+ <div className="cui-fullscreen-thread-list-group">+ {groupLabels[group as keyof typeof groupLabels]}+ </div>+ {groupThreads.map((thread) => (+ <ThreadButton key={thread.threadId} id={thread.threadId} title={thread.title} />+ ))}+ </Fragment>+ ))}</div>);};@@ -183,18 +253,18 @@ export const ScrollArea = ({};export const Messages = ({ className }: { className?: string }) => {- const thread = useThreadState();+ const { messages } = useThreadState();return (<div className={clsx("cui-fullscreen-messages", className)}>- {thread.messages.map((message) => (- <Message key={message.id} message={message} />+ {messages.map((message) => (+ <RenderMessage key={message.id} message={message} />))}</div>);};-export const Message = ({ message, className }: { message: any; className?: string }) => {+export const RenderMessage = ({ message, className }: { message: Message; className?: string }) => {return (<divclassName={clsx(@@ -205,21 +275,21 @@ export const Message = ({ message, className }: { message: any; className?: striclassName,)}>- {message.content}+ {message.message}</div>);};export const Composer = ({ className }: { className?: string }) => {const { textContent, setTextContent } = useComposerState();- const { onNew } = useThreadActions();+ const { addMessages } = useThreadActions();const handleSubmit = () => {if (!textContent.trim()) return;- onNew({+ addMessages({role: "user",- content: textContent,+ message: textContent,});setTextContent("");diff --git a/frontend-sdk/packages/react-ui/src/components/fullscreen/index.ts b/frontend-sdk/packages/react-ui/src/components/fullscreen/index.tsnew file mode 100644index 000000000..8ce9ea805--- /dev/null+++ b/frontend-sdk/packages/react-ui/src/components/fullscreen/index.ts@@ -0,0 +1 @@+export * from "./Fullscreen";diff --git a/frontend-sdk/packages/react-ui/src/components/fullscreen/style.css b/frontend-sdk/packages/react-ui/src/components/fullscreen/style.cssnew file mode 100644index 000000000..349100026--- /dev/null+++ b/frontend-sdk/packages/react-ui/src/components/fullscreen/style.css@@ -0,0 +1,226 @@+.cui-fullscreen-container {+ height: 100vh;+ width: 100vw;+ padding: 1rem;+ display: flex;+ gap: 1rem;+}++.cui-fullscreen-sidebar {+ width: 264px;+ height: 100%;+ border-width: 1px;+ border-color: rgba(0, 0, 0, 0.06);+ flex-shrink: 0;+ padding: 0.67rem;+ border-radius: 1rem;+ display: flex;+ flex-direction: column;+ gap: 0.5rem;+ background-color: rgb(255, 255, 255);+ transition: width 1s ease-in-out;+ white-space: nowrap;+ overflow: hidden;+}++.cui-fullscreen-sidebar.cui-fullscreen-sidebar-closed {+ width: 109px;+ height: min-content;+}++.cui-fullscreen-sidebar.cui-fullscreen-sidebar-closed > * {+ display: none;+}++.cui-fullscreen-sidebar.cui-fullscreen-sidebar-closed .cui-fullscreen-sidebar-header {+ display: flex;+ width: max-content;+}++.cui-fullscreen-sidebar.cui-fullscreen-sidebar-closed .cui-fullscreen-sidebar-title {+ display: none;+}++.cui-fullscreen-sidebar-header {+ display: flex;+ align-items: center;+ justify-content: space-between;+ gap: 0.5rem;+}++.cui-fullscreen-sidebar-header-title-icon {+ display: flex;+ align-items: center;+ gap: 0.5rem;+}++.cui-fullscreen-sidebar-logo {+ height: 1.5rem;+ width: 1.5rem;+ margin-right: 0.5rem;+}++.cui-fullscreen-sidebar-title {+ font-size: 1.15rem;+ font-weight: 400;+ font-style: normal;+ line-height: 1.5rem;+ color: rgb(0, 0, 0);+}++.cui-fullscreen-sidebar-header-button {+ display: flex;+ align-items: center;+ border-radius: 0.5rem;+ padding: 0.66rem;+ border: 1px solid rgba(0, 0, 0, 0.06);+}++.cui-fullscreen-search-input {+ display: flex;+ align-items: center;+ gap: 0.25rem;+ padding: 0.375rem 0.5rem;+ border-radius: 0.5rem;+ border: 1px solid rgba(0, 0, 0, 0.04);+ background-color: rgba(0, 0, 0, 0.04);+}++.cui-fullscreen-search-input-input {+ flex-grow: 1;+ outline: none;+ border: none;+ background-color: transparent;+ font-size: 0.875rem;+ font-style: normal;+ font-weight: 400;+ line-height: 1.25rem;+}++.cui-fullscreen-new-chat-button {+ width: 100%;+ padding: 0.5rem 1rem;+ border-radius: 0.66rem;+ background-color: rgb(0, 0, 0);+ display: flex;+ align-items: center;+ justify-content: left;+ gap: 0.5rem;+ color: rgb(255, 255, 255);+}++.cui-fullscreen-new-chat-button:hover {+ background-color: rgba(0, 0, 0, 0.8);+}++.cui-fullscreen-thread-button {+ width: 100%;+ padding: 8px;+ text-align: left;+ border-radius: 10px;+ text-overflow: ellipsis;+ white-space: nowrap;+ overflow: hidden;+ flex-shrink: 0;+}++.cui-fullscreen-thread-button-selected {+ background-color: rgb(243, 244, 246);+ outline: 1px solid rgba(0, 0, 0, 0.06);+}++.cui-fullscreen-thread-button-disabled {+ width: 100%;+ padding: 8px;+ text-align: left;+ border-radius: 10px;+ text-overflow: ellipsis;+ white-space: nowrap;+ overflow: hidden;+ flex-shrink: 0;+ color: rgba(0, 0, 0, 0.4);+}++.cui-fullscreen-thread-list {+ display: flex;+ flex-direction: column;+ gap: 8px;+}++.cui-fullscreen-thread-list-group {+ display: flex;+ padding-left: 6px;+ color: rgba(0, 0, 0, 0.4);+}++.cui-fullscreen-thread-container {+ flex-grow: 1;+ flex-shrink: 1;+ height: 100%;+ display: flex;+ flex-direction: column;+ max-width: 800px;+ margin: 0 auto;+}++.cui-fullscreen-scroll-area {+ flex-grow: 1;+ flex-shrink: 1;+ height: 100%;+ display: flex;+ flex-direction: column;+ overflow-y: auto;+}++.cui-fullscreen-messages {+ display: flex;+ flex-direction: column;+ gap: 1rem;+ padding: 1rem;+}++.cui-fullscreen-message {+ padding: 1rem;+ border-radius: 0.375rem;+}++.cui-fullscreen-message-user {+ background-color: rgb(219, 234, 254);+ margin-left: 2rem;+}++.cui-fullscreen-message-assistant {+ background-color: rgb(243, 244, 246);+ margin-right: 2rem;+}++.cui-fullscreen-composer {+ display: flex;+ align-items: center;+ gap: 0.67rem;+ padding: 0.67rem;+ border: 1px solid rgba(0, 0, 0, 0.06);+ border-radius: 1rem;+ overflow: hidden;+}++.cui-fullscreen-composer-input {+ flex-grow: 1;+ padding: 0;+ resize: none;+ height: 1.5em;+ outline: none;+ overflow: hidden;+ color: rgb(0, 0, 0);+}++.cui-fullscreen-composer-button {+ padding: 1rem;+ background-color: rgb(0, 0, 0);+ color: white;+ border-radius: 1rem;+ border: rgba(0, 0, 0, 0.10);+ display: flex;+ align-items: center;+ justify-content: center;+}diff --git a/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts b/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.tsindex 66e81e77c..5b936eae7 100644--- a/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts+++ b/frontend-sdk/packages/react-ui/src/hooks/useScrollToBottom.ts@@ -7,7 +7,6 @@ export const useScrollToBottom = <T extends HTMLElement | null>(ref: RefObject<T// Function to scroll to bottomconst scrollToBottom = () => {- debugger;element.scrollTop = element.scrollHeight;};diff --git a/frontend-sdk/packages/react-ui/src/index.ts b/frontend-sdk/packages/react-ui/src/index.tsindex 141b43725..422a46f86 100644--- a/frontend-sdk/packages/react-ui/src/index.ts+++ b/frontend-sdk/packages/react-ui/src/index.ts@@ -1,2 +1 @@-export * as Fullscreen from "./components/Fullscreen";-export { fullscreenTailwindPlugin } from "./plugins/fullscreen";+export * as Fullscreen from "./components/fullscreen";diff --git a/frontend-sdk/packages/react-ui/src/plugins/fullscreen.ts b/frontend-sdk/packages/react-ui/src/plugins/fullscreen.tsdeleted file mode 100644index c56d922e5..000000000--- a/frontend-sdk/packages/react-ui/src/plugins/fullscreen.ts+++ /dev/null@@ -1,202 +0,0 @@-import plugin from "tailwindcss/plugin";--export const fullscreenTailwindPlugin = plugin(function ({ addComponents }) {- addComponents({- ".cui-fullscreen-container": {- height: "100vh",- width: "100vw",- padding: "1rem",- display: "flex",- gap: "1rem",- },- ".cui-fullscreen-sidebar": {- width: "264px",- height: "100%",- borderWidth: "1px",- borderColor: "rgba(0, 0, 0, 0.06)",- flexShrink: "0",- padding: "0.67rem",- borderRadius: "1rem",- display: "flex",- flexDirection: "column",- gap: "0.5rem",- backgroundColor: "rgba(255, 255, 255, 1)",- transition: "width 1s ease-in-out",- whiteSpace: "nowrap",- overflow: "hidden",- "&.cui-fullscreen-sidebar-closed": {- width: "109px",- height: "min-content",- "& > *": {- display: "none",- },- "& .cui-fullscreen-sidebar-header": {- display: "flex",- width: "max-content",- },- "& .cui-fullscreen-sidebar-title": {- display: "none",- },- },- },- ".cui-fullscreen-sidebar-header": {- display: "flex",- alignItems: "center",- justifyContent: "space-between",- gap: "0.5rem",- },- ".cui-fullscreen-sidebar-header-title-icon": {- display: "flex",- alignItems: "center",- gap: "0.5rem",- },- ".cui-fullscreen-sidebar-logo": {- height: "1.5rem",- width: "1.5rem",- marginRight: "0.5rem",- },- ".cui-fullscreen-sidebar-title": {- fontSize: "1.15rem",- fontWeight: "400",- fontStyle: "normal",- lineHeight: "1.5rem",- color: "rgba(0, 0, 0, 1)",- },- ".cui-fullscreen-sidebar-header-button": {- display: "flex",- alignItems: "center",- borderRadius: "0.5rem",- padding: "0.66rem",- border: "1px solid rgba(0, 0, 0, 0.06)",- },- ".cui-fullscreen-search-input": {- display: "flex",- alignItems: "center",- gap: "0.25rem",- padding: "0.375rem 0.5rem",- borderRadius: "0.5rem",- border: "1px solid rgba(0, 0, 0, 0.04)",- backgroundColor: "rgba(0, 0, 0, 0.04)",- },- ".cui-fullscreen-search-input-input": {- flexGrow: "1",- outline: "none",- border: "none",- backgroundColor: "transparent",- fontSize: "0.875rem",- fontStyle: "normal",- fontWeight: "400",- lineHeight: "1.25rem",- },- ".cui-fullscreen-new-chat-button": {- width: "100%",- padding: "0.5rem 1rem",- borderRadius: "0.66rem",- backgroundColor: "rgba(0, 0, 0, 1)",- display: "flex",- alignItems: "center",- justifyContent: "left",- gap: "0.5rem",- "&:hover": {- backgroundColor: "rgba(0, 0, 0, 0.8)",- },- color: "rgba(255, 255, 255, 1)",- },- ".cui-fullscreen-thread-button": {- width: "100%",- padding: "8px",- textAlign: "left",- backgroundColor: "rgba(243, 244, 246, 1)",- borderRadius: "10px",- outline: "1px solid rgba(0, 0, 0, 0.06)",- textOverflow: "ellipsis",- whiteSpace: "nowrap",- overflow: "hidden",- flexShrink: "0",- },- ".cui-fullscreen-thread-button-disabled": {- width: "100%",- padding: "8px",- textAlign: "left",- borderRadius: "10px",- textOverflow: "ellipsis",- whiteSpace: "nowrap",- overflow: "hidden",- flexShrink: "0",- color: "rgba(0, 0, 0, 0.4)",- },- ".cui-fullscreen-thread-list": {- display: "flex",- flexDirection: "column",- gap: "8px",- },- ".cui-fullscreen-thread-list-group": {- display: "flex",- paddingLeft: "6px",- color: "rgba(0, 0, 0, 0.4)",- },- ".cui-fullscreen-thread-container": {- flexGrow: "1",- flexShrink: "1",- height: "100%",- display: "flex",- flexDirection: "column",- maxWidth: "800px",- margin: "0 auto",- },- ".cui-fullscreen-scroll-area": {- flexGrow: "1",- flexShrink: "1",- height: "100%",- display: "flex",- flexDirection: "column",- overflowY: "auto",- },- ".cui-fullscreen-messages": {- display: "flex",- flexDirection: "column",- gap: "1rem",- padding: "1rem",- },- ".cui-fullscreen-message": {- padding: "1rem",- borderRadius: "0.375rem",- },- ".cui-fullscreen-message-user": {- backgroundColor: "rgba(219, 234, 254, 1)",- marginLeft: "2rem",- },- ".cui-fullscreen-message-assistant": {- backgroundColor: "rgba(243, 244, 246, 1)",- marginRight: "2rem",- },- ".cui-fullscreen-composer": {- display: "flex",- alignItems: "center",- gap: "0.67rem",- padding: "0.67rem",- border: "1px solid rgba(0, 0, 0, 0.06)",- borderRadius: "1rem",- overflow: "hidden",- },- ".cui-fullscreen-composer-input": {- flexGrow: "1",- padding: "0",- resize: "none",- height: "1.5em",- outline: "none",- overflow: "hidden",- color: "rgba(0, 0, 0, 1)",- },- ".cui-fullscreen-composer-button": {- padding: "1rem",- backgroundColor: "rgba(0, 0, 0, 1)",- color: "white",- borderRadius: "1rem",- border: "rgba(0, 0, 0, 0.10)",- display: "flex",- alignItems: "center",- justifyContent: "center",- },- });-});