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;
|
this._visible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showCopilotPanel() {
|
private _showCopilotInput() {
|
||||||
requestConnectedFrame(() => {
|
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) {
|
if (!this._copilotPanel) {
|
||||||
const panel = new EdgelessCopilotPanel();
|
const panel = new EdgelessCopilotPanel();
|
||||||
panel.host = this.host;
|
panel.host = this.host;
|
||||||
@@ -86,33 +109,19 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
this.renderRoot.append(panel);
|
this.renderRoot.append(panel);
|
||||||
this._copilotPanel = panel;
|
this._copilotPanel = panel;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const referenceElement = this.selectionElem;
|
private _updateCopilotPanel(referenceElement: HTMLElement) {
|
||||||
const panel = this._copilotPanel;
|
|
||||||
// @TODO: optimize
|
// @TODO: optimize
|
||||||
const viewport = this.gfx.viewport;
|
const viewport = this.gfx.viewport;
|
||||||
|
const panel = this._copilotPanel;
|
||||||
if (!referenceElement || !referenceElement.isConnected) return;
|
if (!panel) 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
autoUpdate(referenceElement, panel, () => {
|
autoUpdate(referenceElement, panel, () => {
|
||||||
computePosition(referenceElement, panel, {
|
computePosition(referenceElement, panel, {
|
||||||
placement: 'right-start',
|
placement: 'bottom-start',
|
||||||
middleware: [
|
middleware: [
|
||||||
offset({
|
offset({
|
||||||
mainAxis: 16,
|
mainAxis: 4,
|
||||||
crossAxis: 45,
|
|
||||||
}),
|
}),
|
||||||
flip({
|
flip({
|
||||||
mainAxis: true,
|
mainAxis: true,
|
||||||
@@ -148,7 +157,6 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
console.warn("Can't compute EdgelessCopilotPanel position", e);
|
console.warn("Can't compute EdgelessCopilotPanel position", e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _updateSelection(rect: DOMRect) {
|
private _updateSelection(rect: DOMRect) {
|
||||||
@@ -201,7 +209,7 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
this._visible = true;
|
this._visible = true;
|
||||||
this._updateSelection(CopilotSelectionTool.area);
|
this._updateSelection(CopilotSelectionTool.area);
|
||||||
if (shouldShowPanel) {
|
if (shouldShowPanel) {
|
||||||
this._showCopilotPanel();
|
this._showCopilotInput();
|
||||||
this._watchClickOutside();
|
this._watchClickOutside();
|
||||||
} else {
|
} else {
|
||||||
this.hideCopilotPanel();
|
this.hideCopilotPanel();
|
||||||
|
|||||||
Reference in New Issue
Block a user