PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Agent / Chat.jsx

Chat.jsx in Extendify 3.0.4, at src/Agent/Chat.jsx

94 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { DOMHighlighter } from '@agent/components/DOMHighlighter';
2 import { DragResizeLayout } from '@agent/components/layouts/DragResizeLayout';
3 import { MobileLayout } from '@agent/components/layouts/MobileLayout';
4 import { useGlobalStore } from '@agent/state/global';
5 import { useWorkflowStore } from '@agent/state/workflows';
6 import { useEffect } from '@wordpress/element';
7 import { SidebarLayout } from './components/layouts/SidebarLayout';
8
9 export const Chat = ({ busy, children }) => {
10 const { setIsMobile, isMobile, mode } = useGlobalStore();
11 const { domToolEnabled, block, setBlock, setDomToolEnabled } =
12 useWorkflowStore();
13
14 useEffect(() => {
15 if (!isMobile || !block) return;
16 // Remove the block if we switch to mobile
17 setBlock(null);
18 }, [isMobile, setIsMobile, block, setBlock]);
19
20 useEffect(() => {
21 let timeout;
22 const onResize = () => {
23 clearTimeout(timeout);
24 timeout = window.setTimeout(() => {
25 setIsMobile(window.innerWidth < 783);
26 }, 10);
27 };
28 window.addEventListener('resize', onResize);
29 return () => {
30 clearTimeout(timeout);
31 window.removeEventListener('resize', onResize);
32 };
33 }, [setIsMobile]);
34
35 useEffect(() => {
36 // Exit select mode when Escape is pressed
37 const onKeyDown = (e) => {
38 if (e.key !== 'Escape' || !domToolEnabled) return;
39
40 // Cancel the workflow
41 window.dispatchEvent(new CustomEvent('extendify-agent:cancel-workflow'));
42
43 // If a block is selected, clear it
44 if (block) return setBlock(null);
45
46 // If no block is selected, exit select mode
47 setDomToolEnabled(false);
48 };
49 window.addEventListener('keydown', onKeyDown);
50 return () => {
51 window.removeEventListener('keydown', onKeyDown);
52 };
53 }, [domToolEnabled, block, setBlock, setDomToolEnabled]);
54
55 if (isMobile) {
56 return (
57 <MobileLayout>
58 <div
59 id="extendify-agent-chat"
60 className="flex min-h-0 flex-1 grow flex-col font-sans"
61 >
62 {children}
63 </div>
64 </MobileLayout>
65 );
66 }
67
68 if (mode === 'docked-left') {
69 return (
70 <SidebarLayout>
71 <div
72 id="extendify-agent-chat"
73 className="flex min-h-0 flex-1 grow flex-col font-sans"
74 >
75 {children}
76 </div>
77 {domToolEnabled && <DOMHighlighter busy={busy} />}
78 </SidebarLayout>
79 );
80 }
81
82 return (
83 <DragResizeLayout>
84 <div
85 id="extendify-agent-chat"
86 className="flex min-h-0 flex-1 grow flex-col font-sans"
87 >
88 {children}
89 </div>
90 {domToolEnabled && <DOMHighlighter busy={busy} />}
91 </DragResizeLayout>
92 );
93 };
94