fix(core): ask AI input box in the whiteboard is blocked by the menu (#11634)
Close [AI-50](https://linear.app/affine-design/issue/AI-50). 
This commit is contained in:
@@ -77,8 +77,31 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
||||
this._visible = visible;
|
||||
}
|
||||
|
||||
private _showCopilotPanel() {
|
||||
private _showCopilotInput() {
|
||||
requestConnectedFrame(() => {
|
||||
const referenceElement = this.selectionElem;
|
||||
if (!referenceElement || !referenceElement.isConnected) return;
|
||||
|
||||
// show ai input
|
||||
const rootBlockId = this.host.doc.root?.id;
|
||||
if (!rootBlockId) return;
|
||||
|
||||
const input = this.host.view.getWidget(
|
||||
AFFINE_AI_PANEL_WIDGET,
|
||||
rootBlockId
|
||||
);
|
||||
|
||||
if (input instanceof AffineAIPanelWidget) {
|
||||
input.setState('input', referenceElement);
|
||||
requestAnimationFrame(() => {
|
||||
this._createCopilotPanel();
|
||||
this._updateCopilotPanel(input);
|
||||
});
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
private _createCopilotPanel() {
|
||||
if (!this._copilotPanel) {
|
||||
const panel = new EdgelessCopilotPanel();
|
||||
panel.host = this.host;
|
||||
@@ -86,33 +109,19 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
||||
this.renderRoot.append(panel);
|
||||
this._copilotPanel = panel;
|
||||
}
|
||||
}
|
||||
|
||||
const referenceElement = this.selectionElem;
|
||||
const panel = this._copilotPanel;
|
||||
private _updateCopilotPanel(referenceElement: HTMLElement) {
|
||||
// @TODO: optimize
|
||||
const viewport = this.gfx.viewport;
|
||||
|
||||
if (!referenceElement || !referenceElement.isConnected) return;
|
||||
|
||||
// show ai input
|
||||
const rootBlockId = this.host.doc.root?.id;
|
||||
if (rootBlockId) {
|
||||
const aiPanel = this.host.view.getWidget(
|
||||
AFFINE_AI_PANEL_WIDGET,
|
||||
rootBlockId
|
||||
);
|
||||
if (aiPanel instanceof AffineAIPanelWidget && aiPanel.config) {
|
||||
aiPanel.setState('input', referenceElement);
|
||||
}
|
||||
}
|
||||
|
||||
const panel = this._copilotPanel;
|
||||
if (!panel) return;
|
||||
autoUpdate(referenceElement, panel, () => {
|
||||
computePosition(referenceElement, panel, {
|
||||
placement: 'right-start',
|
||||
placement: 'bottom-start',
|
||||
middleware: [
|
||||
offset({
|
||||
mainAxis: 16,
|
||||
crossAxis: 45,
|
||||
mainAxis: 4,
|
||||
}),
|
||||
flip({
|
||||
mainAxis: true,
|
||||
@@ -148,7 +157,6 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
||||
console.warn("Can't compute EdgelessCopilotPanel position", e);
|
||||
});
|
||||
});
|
||||
}, this);
|
||||
}
|
||||
|
||||
private _updateSelection(rect: DOMRect) {
|
||||
@@ -201,7 +209,7 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
||||
this._visible = true;
|
||||
this._updateSelection(CopilotSelectionTool.area);
|
||||
if (shouldShowPanel) {
|
||||
this._showCopilotPanel();
|
||||
this._showCopilotInput();
|
||||
this._watchClickOutside();
|
||||
} else {
|
||||
this.hideCopilotPanel();
|
||||
|
||||
Reference in New Issue
Block a user