Skip to content

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.

fix: Add right placeholders on audio transcribing, and shift-enter for new line in AI Command Bar (#2440)

Ivan Starkov3bdc31562054
diff --git a/apps/builder/app/builder/features/ai/ai-command-bar.tsx b/apps/builder/app/builder/features/ai/ai-command-bar.tsx
index d5c12e1b93..8769ce1a43 100644
--- a/apps/builder/app/builder/features/ai/ai-command-bar.tsx
+++ b/apps/builder/app/builder/features/ai/ai-command-bar.tsx
@@ -14,6 +14,7 @@ import {
ScrollArea,
Text,
theme,
+ useDisableCanvasPointerEvents,
} from "@webstudio-is/design-system";
import {
AiIcon,
@@ -55,6 +56,8 @@ export const AiCommandBar = () => {
const isAiCommandBarVisible = useStore($isAiCommandBarVisible);
const recordButtonRef = useRef<HTMLButtonElement>(null);
const uploadIdRef = useRef(0);
+ const { enableCanvasPointerEvents, disableCanvasPointerEvents } =
+ useDisableCanvasPointerEvents();
const {
start,
@@ -70,7 +73,7 @@ export const AiCommandBar = () => {
if (uploadId !== uploadIdRef.current) {
return;
}
- setValue(text);
+ setValue((previousText) => `${previousText} ${text}`);
setIsAudioTranscribing(false);
},
onReportSoundAmplitude: (amplitude) => {
@@ -83,11 +86,17 @@ export const AiCommandBar = () => {
const longPressToggleProps = useLongPressToggle({
onStart: () => {
- setValue("");
start();
+ disableCanvasPointerEvents();
+ },
+ onEnd: () => {
+ stop();
+ enableCanvasPointerEvents();
+ },
+ onCancel: () => {
+ cancel();
+ enableCanvasPointerEvents();
},
- onEnd: stop,
- onCancel: cancel,
});
if (isAiCommandBarVisible === false) {
@@ -98,9 +107,17 @@ export const AiCommandBar = () => {
mediaRecorderState === "recording" || isAudioTranscribing;
const recordButtonDisabled = isAudioTranscribing;
+
const aiButtonDisabled =
mediaRecorderState === "recording" || isAudioTranscribing;
+ const actionPlaceholder =
+ mediaRecorderState === "recording"
+ ? "Recording voice..."
+ : isAudioTranscribing
+ ? "Transcribing voice..."
+ : undefined;
+
return (
<Box
css={{
@@ -137,9 +154,15 @@ export const AiCommandBar = () => {
<AutogrowTextArea
autoFocus
disabled={textAreaDisabled}
- placeholder="Enter value..."
- value={value}
+ placeholder={actionPlaceholder ?? "Enter value..."}
+ value={actionPlaceholder !== undefined ? "" : value}
onChange={setValue}
+ onKeyDown={(event) => {
+ if (event.key === "Enter" && event.shiftKey === false) {
+ event.preventDefault();
+ // @todo add text submit here
+ }
+ }}
/>
</ScrollArea>
</Grid>
@@ -204,7 +227,7 @@ const CommandBarContent = () => {
<CommandBarContentSection>
<Text variant={"labelsSentenceCase"} align={"center"}>
- Previous propmts
+ Previous prompts
</Text>
<div />
<CommandBarContentPrompt>
diff --git a/apps/builder/app/builder/features/ai/hooks/media-recorder.ts b/apps/builder/app/builder/features/ai/hooks/media-recorder.ts
index 01adf5bf44..690127cfe3 100644
--- a/apps/builder/app/builder/features/ai/hooks/media-recorder.ts
+++ b/apps/builder/app/builder/features/ai/hooks/media-recorder.ts
@@ -126,6 +126,7 @@ export const useMediaRecorder = (
// Cancelled, do cleanup and return
if (cancelRef.current) {
+ setState("inactive");
chunks.length = 0;
return;
}
@@ -143,6 +144,7 @@ export const useMediaRecorder = (
onReportSoundAmplitude?.(0);
}
chunks.length = 0;
+ setState("inactive");
}
};
@@ -153,7 +155,6 @@ export const useMediaRecorder = (
isActiveRef.current = false;
disposeRef.current?.();
disposeRef.current = undefined;
- setState("inactive");
});
const cancel = useEffectEvent(() => {
diff --git a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
index 6b18764804..9d3a9208e9 100644
--- a/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
+++ b/apps/builder/app/builder/features/sidebar-left/sidebar-left.tsx
@@ -72,7 +72,9 @@ export const SidebarLeft = ({ publish }: SidebarLeftProps) => {
{isFeatureEnabled("ai") && (
<SidebarTabsTrigger
aria-label="ai"
- value={isAiCommandBarVisible ? activeTab : "ai"}
+ value={
+ "anyValueNotInTabName" /* !!! This button does not have active state, use impossible tab value !!! */
+ }
onClick={() => {
$isAiCommandBarVisible.set(!isAiCommandBarVisible);
}}
diff --git a/packages/design-system/src/components/button.tsx b/packages/design-system/src/components/button.tsx
index 68ee41f1f1..76a410af32 100644
--- a/packages/design-system/src/components/button.tsx
+++ b/packages/design-system/src/components/button.tsx
@@ -65,7 +65,7 @@ const perColorStyle = (variant: ButtonColor) => ({
: backgrounds[variant],
color:
variant === "dark-ghost"
- ? theme.colors.foregroundMoreSubtle
+ ? theme.colors.foregroundSubtle
: foregrounds[variant],
"&[data-state=auto]:hover, &[data-state=hover]": {