@@ -12,6 +12,8 @@ buttons in the hover state (even when tacking mouse moves!),
12
12
which is confusing.
13
13
*/
14
14
15
+ // cSpell:ignore aicell
16
+
15
17
import { Button , Space , Tooltip } from "antd" ;
16
18
import { ReactNode } from "react" ;
17
19
@@ -96,6 +98,65 @@ export function InsertCell({
96
98
classNames . push ( "cocalc-jupyter-insert-cell-below" ) ;
97
99
}
98
100
101
+ const isActiveAIGenerator = ! hide && showAICellGen === position ;
102
+
103
+ function renderControls ( ) {
104
+ return (
105
+ < div
106
+ className = "cocalc-jupyter-insert-cell-controls"
107
+ style = {
108
+ showAICellGen || alwaysShow
109
+ ? {
110
+ visibility : "visible" ,
111
+ opacity : 1 ,
112
+ }
113
+ : undefined
114
+ }
115
+ >
116
+ < Space size = "large" >
117
+ < TinyButton
118
+ type = "code"
119
+ title = "Insert code cell (click line)"
120
+ handleButtonClick = { handleButtonClick }
121
+ >
122
+ < Icon name = "code" /> Code
123
+ </ TinyButton >
124
+ < TinyButton
125
+ type = "markdown"
126
+ title = "Insert text cell (shift+click line)"
127
+ handleButtonClick = { handleButtonClick }
128
+ >
129
+ < Icon name = "pen" /> Text
130
+ </ TinyButton >
131
+ < TinyButton
132
+ type = "paste"
133
+ title = "Insert clipboard content as cell"
134
+ handleButtonClick = { handleButtonClick }
135
+ >
136
+ < Icon name = "paste" /> Paste
137
+ </ TinyButton >
138
+ { showGenerateCell && llmTools && (
139
+ < TinyButton
140
+ type = "aicell"
141
+ title = "Create code based on your description (alt+click line)"
142
+ handleButtonClick = { handleButtonClick }
143
+ >
144
+ < Space >
145
+ < AIAvatar
146
+ backgroundColor = { "transparent" }
147
+ size = { 14 }
148
+ innerStyle = { { color : "default" , top : "-2px" } }
149
+ />
150
+ Generate...
151
+ </ Space >
152
+ </ TinyButton >
153
+ ) }
154
+ </ Space >
155
+ </ div >
156
+ ) ;
157
+ }
158
+
159
+ // the AIGenerateCodeCell is only rendered if active – otherwise that dialog is rendered for each cell insertion line
99
160
return (
100
161
< div
101
162
className = { classNames . join ( " " ) }
@@ -105,66 +166,20 @@ export function InsertCell({
105
166
} }
106
167
onClick = { showAICellGen ? undefined : handleBarClick }
107
168
>
108
- < AIGenerateCodeCell
109
- setShowAICellGen = { setShowAICellGen }
110
- showAICellGen = { ! hide ? showAICellGen : null }
111
- actions = { actions }
112
- frameActions = { frameActions }
113
- id = { id }
114
- llmTools = { llmTools }
115
- >
116
- < div
117
- className = "cocalc-jupyter-insert-cell-controls"
118
- style = {
119
- showAICellGen || alwaysShow
120
- ? {
121
- visibility : "visible" ,
122
- opacity : 1 ,
123
- }
124
- : undefined
125
- }
169
+ { isActiveAIGenerator ? (
170
+ < AIGenerateCodeCell
171
+ setShowAICellGen = { setShowAICellGen }
172
+ showAICellGen = { showAICellGen }
173
+ actions = { actions }
174
+ frameActions = { frameActions }
175
+ id = { id }
176
+ llmTools = { llmTools }
126
177
>
127
- < Space size = "large" >
128
- < TinyButton
129
- type = "code"
130
- title = "Insert code cell (click line)"
131
- handleButtonClick = { handleButtonClick }
132
- >
133
- < Icon name = "code" /> Code
134
- </ TinyButton >
135
- < TinyButton
136
- type = "markdown"
137
- title = "Insert text cell (shift+click line)"
138
- handleButtonClick = { handleButtonClick }
139
- >
140
- < Icon name = "pen" /> Text
141
- </ TinyButton >
142
- < TinyButton
143
- type = "paste"
144
- title = "Insert clipboard content as cell"
145
- handleButtonClick = { handleButtonClick }
146
- >
147
- < Icon name = "paste" /> Paste
148
- </ TinyButton >
149
- { showGenerateCell && llmTools && (
150
- < TinyButton
151
- type = "aicell"
152
- title = "Create code based on your description (alt+click line)"
153
- handleButtonClick = { handleButtonClick }
154
- >
155
- < Space >
156
- < AIAvatar
157
- backgroundColor = { "transparent" }
158
- size = { 14 }
159
- innerStyle = { { color : "default" , top : "-2px" } }
160
- />
161
- Generate...
162
- </ Space >
163
- </ TinyButton >
164
- ) }
165
- </ Space >
166
- </ div >
167
- </ AIGenerateCodeCell >
178
+ { renderControls ( ) }
179
+ </ AIGenerateCodeCell >
180
+ ) : (
181
+ renderControls ( )
182
+ ) }
168
183
</ div >
169
184
) ;
170
185
}
0 commit comments