Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
feat: Add AI command bar (#2437)
Ivan Starkov0cf35fb5bdd2
diff --git a/apps/builder/app/builder/builder.tsx b/apps/builder/app/builder/builder.tsxindex 5f71b0b0ea..3e83dd1972 100644--- a/apps/builder/app/builder/builder.tsx+++ b/apps/builder/app/builder/builder.tsx@@ -1,4 +1,4 @@-import { useCallback, useEffect } from "react";+import { useCallback, useEffect, type ReactNode } from "react";import { useStore } from "@nanostores/react";import { useUnmount } from "react-use";import { TooltipProvider } from "@radix-ui/react-tooltip";@@ -46,6 +46,8 @@ import { BlockingAlerts } from "./features/blocking-alerts";import { useSyncPageUrl } from "~/shared/pages";import { useMount } from "~/shared/hook-utils/use-mount";import { subscribeCommands } from "~/builder/shared/commands";+import { AiCommandBar } from "./features/ai/ai-command-bar";+import { isFeatureEnabled } from "@webstudio-is/feature-flags";registerContainers();@@ -108,13 +110,14 @@ const SidePanel = ({);};-const Main = ({ children }: { children: JSX.Element | Array<JSX.Element> }) => (+const Main = ({ children }: { children: ReactNode }) => (<Flexas="main"direction="column"css={{gridArea: "main",overflow: "hidden",+ position: "relative",}}>{children}@@ -318,6 +321,7 @@ export const Builder = ({}}/></Workspace>+ {isFeatureEnabled("ai") && <AiCommandBar />}</Main><SidePanel gridArea="sidebar" isPreviewMode={isPreviewMode}><SidebarLeft publish={publish} />diff --git a/apps/builder/app/builder/features/ai/ai-command-bar.tsx b/apps/builder/app/builder/features/ai/ai-command-bar.tsxnew file mode 100644index 0000000000..9ec7f9a012--- /dev/null+++ b/apps/builder/app/builder/features/ai/ai-command-bar.tsx@@ -0,0 +1,139 @@+import { useStore } from "@nanostores/react";+import {+ AutogrowTextArea,+ Box,+ Button,+ CommandBar,+ CommandBarButton,+ CommandBarContentPrompt,+ CommandBarContentSection,+ CommandBarContentSeparator,+ CommandBarTrigger,+ Flex,+ Grid,+ ScrollArea,+ Text,+ theme,+} from "@webstudio-is/design-system";+import {+ AiIcon,+ MicIcon,+ ChevronUpIcon,+ ExternalLinkIcon,+} from "@webstudio-is/icons";+import { useState } from "react";+import { $isAiCommandBarVisible } from "~/shared/nano-states";++export const AiCommandBar = () => {+ const [open, setOpen] = useState(false);+ const isAiCommandBarVisible = useStore($isAiCommandBarVisible);++ if (isAiCommandBarVisible === false) {+ return;+ }++ return (+ <Box+ css={{+ position: "absolute",+ bottom: theme.spacing[11],+ left: 0,+ right: 0,+ height: 0,+ justifyContent: "center",+ alignItems: "flex-end",+ display: "flex",+ }}+ >+ <CommandBar+ open={open}+ onOpenChange={setOpen}+ content={<CommandBarContent />}+ >+ <CommandBarTrigger>+ <CommandBarButton color="dark-ghost">+ <ChevronUpIcon />+ </CommandBarButton>+ </CommandBarTrigger>++ <Grid+ css={{+ alignSelf: "center",+ // color: theme.colors.foregroundContrastMain,+ // Set maxWidth to autogrow in width+ width: theme.spacing[31],+ }}+ >+ <ScrollArea css={{ maxHeight: theme.spacing[29] }}>+ <AutogrowTextArea autoFocus placeholder="Enter value..." />+ </ScrollArea>+ </Grid>++ <CommandBarButton color="dark-ghost">+ <MicIcon />+ </CommandBarButton>+ <CommandBarButton color="gradient">+ <AiIcon />+ </CommandBarButton>+ </CommandBar>+ </Box>+ );+};++const CommandBarContent = () => {+ return (+ <>+ <CommandBarContentSection>+ <Text variant={"labelsSentenceCase"} align={"center"}>+ Welcome to Webstudio AI alpha!+ </Text>+ <div />+ <Text variant={"labelsSentenceCase"}>+ Ask me to generate or edit sections, text, or images.+ <br /> For example you can say: ”Make a new contact section”+ </Text>+ <Flex align={"end"}>+ <Button+ color="dark"+ css={{+ width: theme.spacing[30],+ }}+ suffix={<ExternalLinkIcon />}+ >+ Learn more+ </Button>+ <Text+ variant={"labelsSentenceCase"}+ color={"subtle"}+ css={{ flex: 1 }}+ align={"center"}+ >+ shortcut ⌘⇧Q+ </Text>+ </Flex>+ </CommandBarContentSection>++ <CommandBarContentSeparator />++ <CommandBarContentSection>+ <Text variant={"labelsSentenceCase"} align={"center"}>+ Previous propmts+ </Text>+ <div />+ <CommandBarContentPrompt>+ Make a new section with a contact form+ </CommandBarContentPrompt>+ <CommandBarContentPrompt>+ Add an image of a cat smiling wearing eyeglasses+ </CommandBarContentPrompt>+ <CommandBarContentPrompt>+ Write a breakup letter for my girlfriend and make it long enough to+ break into multiple lines+ </CommandBarContentPrompt>+ <CommandBarContentPrompt>+ Make all headings bold+ </CommandBarContentPrompt>+ </CommandBarContentSection>+ </>+ );+};diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsxindex 66adc0064c..6b18764804 100644--- a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx@@ -8,15 +8,19 @@ import {Tooltip,} from "@webstudio-is/design-system";import { useSubscribe, type Publish } from "~/shared/pubsub";-import { $dragAndDropState } from "~/shared/nano-states";+import {+ $dragAndDropState,+ $isAiCommandBarVisible,+} from "~/shared/nano-states";import { panels } from "./panels";import type { TabName } from "./types";import { useClientSettings } from "~/builder/shared/client-settings";import { Flex } from "@webstudio-is/design-system";import { theme } from "@webstudio-is/design-system";-import { BugIcon, HelpIcon } from "@webstudio-is/icons";+import { AiIcon, BugIcon, HelpIcon } from "@webstudio-is/icons";import { HelpPopover } from "./help-popover";import { useStore } from "@nanostores/react";+import { isFeatureEnabled } from "@webstudio-is/feature-flags";const none = { TabContent: () => null };@@ -30,6 +34,7 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {const { TabContent } = activeTab === "none" ? none : panels[activeTab];const [clientSettings] = useClientSettings();const [helpIsOpen, setHelpIsOpen] = useState(false);+ const isAiCommandBarVisible = useStore($isAiCommandBarVisible);useSubscribe("clickCanvas", () => {setActiveTab("none");@@ -64,6 +69,17 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {{tabName === "none" ? null : panels[tabName].icon}</SidebarTabsTrigger>))}+ {isFeatureEnabled("ai") && (+ <SidebarTabsTrigger+ aria-label="ai"+ value={isAiCommandBarVisible ? activeTab : "ai"}+ onClick={() => {+ $isAiCommandBarVisible.set(!isAiCommandBarVisible);+ }}+ >+ <AiIcon />+ </SidebarTabsTrigger>+ )}</SidebarTabsList><Box css={{ borderRight: `1px solid ${theme.colors.borderMain}` }}><HelpPopover onOpenChange={setHelpIsOpen}>diff --git a/apps/builder/app/builder/shared/commands.ts b/apps/builder/app/builder/shared/commands.tsindex 5f23b326ef..41061d7140 100644--- a/apps/builder/app/builder/shared/commands.ts+++ b/apps/builder/app/builder/shared/commands.ts@@ -84,5 +84,20 @@ export const { emitCommand, subscribeCommands } = createCommandsEmitter({editingItemIdStore.set(targetInstanceId);},},++ /*+ // @todo: decide about keyboard shortcut, uncomment when ready+ {+ name: "toggleAiCommandBar",+ defaultHotkeys: ["space"],+ disableHotkeyOnContentEditable: true,+ // this disables hotkey for inputs on style panel+ // but still work for input on canvas which call event.preventDefault() in keydown handler+ disableHotkeyOnFormTags: true,+ handler: () => {+ $isAiCommandBarVisible.set($isAiCommandBarVisible.get() === false);+ },+ },+ */],});diff --git a/apps/builder/app/shared/nano-states/nano-states.ts b/apps/builder/app/shared/nano-states/nano-states.tsindex 4d8094eb0b..92d50af3fd 100644--- a/apps/builder/app/shared/nano-states/nano-states.ts+++ b/apps/builder/app/shared/nano-states/nano-states.ts@@ -327,3 +327,5 @@ export type DragAndDropState = {export const $dragAndDropState = atom<DragAndDropState>({isDragging: false,});++export const $isAiCommandBarVisible = atom<boolean>(true);