feat: single AI action button with inline prompt; replace cell source

This commit is contained in:
tao.chen
2026-07-23 12:47:47 +08:00
parent d03f0fa434
commit 85e16914b5
3 changed files with 196 additions and 97 deletions
+59
View File
@@ -0,0 +1,59 @@
/**
* Inline prompt widget attached to a cell's DOM when the AI button is clicked.
* Renders a textarea + send/cancel buttons. The owning cell is passed so
* we can resolve the cell context at submit time. submit/cancel are
* callbacks owned by OpenCodeCellActions.
*/
import { CodeCell } from '@jupyterlab/cells';
import { Widget } from '@lumino/widgets';
export interface IOpenCodeInlinePromptOptions {
onSubmit: (text: string) => void;
onCancel: () => void;
disabled: boolean;
}
export class OpenCodeInlinePrompt extends Widget {
private _textarea: HTMLTextAreaElement;
private _sendBtn: HTMLButtonElement;
private _cancelBtn: HTMLButtonElement;
constructor(
_cell: CodeCell,
options: IOpenCodeInlinePromptOptions
) {
super();
this.addClass('opencode-inline-prompt');
this._textarea = document.createElement('textarea');
this._textarea.placeholder = '向 AI 描述你想要的修改…';
this._textarea.rows = 3;
this._sendBtn = document.createElement('button');
this._sendBtn.className = 'opencode-btn-send';
this._sendBtn.textContent = '🚀 发送';
this._sendBtn.disabled = options.disabled;
this._sendBtn.addEventListener('click', () => {
const text = this._textarea.value;
if (text.trim()) {
options.onSubmit(text);
}
});
this._cancelBtn = document.createElement('button');
this._cancelBtn.className = 'opencode-btn-cancel';
this._cancelBtn.textContent = '✕ 取消';
this._cancelBtn.addEventListener('click', () => {
options.onCancel();
});
const actions = document.createElement('div');
actions.className = 'opencode-inline-actions';
actions.appendChild(this._sendBtn);
actions.appendChild(this._cancelBtn);
this.node.appendChild(this._textarea);
this.node.appendChild(actions);
}
setDisabled(disabled: boolean): void {
this._sendBtn.disabled = disabled;
}
}