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,80 +77,88 @@ export class EdgelessCopilotWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
this._visible = visible;
|
this._visible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showCopilotPanel() {
|
private _showCopilotInput() {
|
||||||
requestConnectedFrame(() => {
|
requestConnectedFrame(() => {
|
||||||
if (!this._copilotPanel) {
|
|
||||||
const panel = new EdgelessCopilotPanel();
|
|
||||||
panel.host = this.host;
|
|
||||||
panel.groups = this.groups;
|
|
||||||
this.renderRoot.append(panel);
|
|
||||||
this._copilotPanel = panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
const referenceElement = this.selectionElem;
|
const referenceElement = this.selectionElem;
|
||||||
const panel = this._copilotPanel;
|
|
||||||
// @TODO: optimize
|
|
||||||
const viewport = this.gfx.viewport;
|
|
||||||
|
|
||||||
if (!referenceElement || !referenceElement.isConnected) return;
|
if (!referenceElement || !referenceElement.isConnected) return;
|
||||||
|
|
||||||
// show ai input
|
// show ai input
|
||||||
const rootBlockId = this.host.doc.root?.id;
|
const rootBlockId = this.host.doc.root?.id;
|
||||||
if (rootBlockId) {
|
if (!rootBlockId) return;
|
||||||
const aiPanel = this.host.view.getWidget(
|
|
||||||
AFFINE_AI_PANEL_WIDGET,
|
|
||||||
rootBlockId
|
|
||||||
);
|
|
||||||
if (aiPanel instanceof AffineAIPanelWidget && aiPanel.config) {
|
|
||||||
aiPanel.setState('input', referenceElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
autoUpdate(referenceElement, panel, () => {
|
const input = this.host.view.getWidget(
|
||||||
computePosition(referenceElement, panel, {
|
AFFINE_AI_PANEL_WIDGET,
|
||||||
placement: 'right-start',
|
rootBlockId
|
||||||
middleware: [
|
);
|
||||||
offset({
|
|
||||||
mainAxis: 16,
|
if (input instanceof AffineAIPanelWidget) {
|
||||||
crossAxis: 45,
|
input.setState('input', referenceElement);
|
||||||
}),
|
requestAnimationFrame(() => {
|
||||||
flip({
|
this._createCopilotPanel();
|
||||||
mainAxis: true,
|
this._updateCopilotPanel(input);
|
||||||
crossAxis: true,
|
});
|
||||||
flipAlignment: true,
|
}
|
||||||
}),
|
|
||||||
shift(() => {
|
|
||||||
const { left, top, width, height } = viewport;
|
|
||||||
return {
|
|
||||||
padding: 20,
|
|
||||||
crossAxis: true,
|
|
||||||
rootBoundary: {
|
|
||||||
x: left,
|
|
||||||
y: top,
|
|
||||||
width,
|
|
||||||
height: height - 100,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
size({
|
|
||||||
apply: ({ elements }) => {
|
|
||||||
const { height } = viewport;
|
|
||||||
elements.floating.style.maxHeight = `${height - 140}px`;
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
})
|
|
||||||
.then(({ x, y }) => {
|
|
||||||
panel.style.left = `${x}px`;
|
|
||||||
panel.style.top = `${y}px`;
|
|
||||||
})
|
|
||||||
.catch(e => {
|
|
||||||
console.warn("Can't compute EdgelessCopilotPanel position", e);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _createCopilotPanel() {
|
||||||
|
if (!this._copilotPanel) {
|
||||||
|
const panel = new EdgelessCopilotPanel();
|
||||||
|
panel.host = this.host;
|
||||||
|
panel.groups = this.groups;
|
||||||
|
this.renderRoot.append(panel);
|
||||||
|
this._copilotPanel = panel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _updateCopilotPanel(referenceElement: HTMLElement) {
|
||||||
|
// @TODO: optimize
|
||||||
|
const viewport = this.gfx.viewport;
|
||||||
|
const panel = this._copilotPanel;
|
||||||
|
if (!panel) return;
|
||||||
|
autoUpdate(referenceElement, panel, () => {
|
||||||
|
computePosition(referenceElement, panel, {
|
||||||
|
placement: 'bottom-start',
|
||||||
|
middleware: [
|
||||||
|
offset({
|
||||||
|
mainAxis: 4,
|
||||||
|
}),
|
||||||
|
flip({
|
||||||
|
mainAxis: true,
|
||||||
|
crossAxis: true,
|
||||||
|
flipAlignment: true,
|
||||||
|
}),
|
||||||
|
shift(() => {
|
||||||
|
const { left, top, width, height } = viewport;
|
||||||
|
return {
|
||||||
|
padding: 20,
|
||||||
|
crossAxis: true,
|
||||||
|
rootBoundary: {
|
||||||
|
x: left,
|
||||||
|
y: top,
|
||||||
|
width,
|
||||||
|
height: height - 100,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
size({
|
||||||
|
apply: ({ elements }) => {
|
||||||
|
const { height } = viewport;
|
||||||
|
elements.floating.style.maxHeight = `${height - 140}px`;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then(({ x, y }) => {
|
||||||
|
panel.style.left = `${x}px`;
|
||||||
|
panel.style.top = `${y}px`;
|
||||||
|
})
|
||||||
|
.catch(e => {
|
||||||
|
console.warn("Can't compute EdgelessCopilotPanel position", e);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private _updateSelection(rect: DOMRect) {
|
private _updateSelection(rect: DOMRect) {
|
||||||
this._selectionModelRect = rect;
|
this._selectionModelRect = rect;
|
||||||
|
|
||||||
@@ -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