mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-23 13:02:21 +08:00
fix(core): generate the image cannot enter text prompt (#12717)
Close [AI-167](https://linear.app/affine-design/issue/AI-167)   <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved AI panel behavior with explicit modes for input and answer generation, providing a more intuitive user experience when interacting with AI features. - **Refactor** - Streamlined AI panel toggling logic for more consistent and predictable panel states during different actions. - **Tests** - Enhanced AI image generation test to simulate user input and send actions for more accurate end-to-end validation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -208,7 +208,18 @@ export function actionToHandler<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
if (!blocks || blocks.length === 0) return;
|
if (!blocks || blocks.length === 0) return;
|
||||||
const block = blocks.at(-1);
|
const block = blocks.at(-1);
|
||||||
if (!block) return;
|
if (!block) return;
|
||||||
aiPanel.toggle(block, '');
|
if (
|
||||||
|
blocks.length === 1 &&
|
||||||
|
block.model.flavour === 'affine:image' &&
|
||||||
|
id === 'createImage'
|
||||||
|
) {
|
||||||
|
// if only one image block is selected, and the action is createImage
|
||||||
|
// toggle panel to allow user to enter text prompt
|
||||||
|
aiPanel.toggle(block, 'input');
|
||||||
|
} else {
|
||||||
|
// generate the answer
|
||||||
|
aiPanel.toggle(block, 'generate');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +243,7 @@ export function handleInlineAskAIAction(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!actionGroups) {
|
if (!actionGroups) {
|
||||||
panel.toggle(block);
|
panel.toggle(block, 'input');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,7 +263,7 @@ export function handleInlineAskAIAction(
|
|||||||
clear();
|
clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
panel.toggle(block);
|
panel.toggle(block, 'input');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
abortController = new AbortController();
|
abortController = new AbortController();
|
||||||
|
|||||||
@@ -457,7 +457,7 @@ export function actionToHandler<T extends keyof BlockSuitePresets.AIActions>(
|
|||||||
|
|
||||||
togglePanel()
|
togglePanel()
|
||||||
.then(isEmpty => {
|
.then(isEmpty => {
|
||||||
aiPanel.toggle(referenceElement, isEmpty ? undefined : '', false);
|
aiPanel.toggle(referenceElement, isEmpty ? 'input' : 'generate');
|
||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -333,20 +333,14 @@ export class AffineAIPanelWidget extends WidgetComponent {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
toggle = (
|
toggle = (reference: Element, type: 'input' | 'generate') => {
|
||||||
reference: Element,
|
if (type === 'generate') {
|
||||||
input?: string,
|
this._inputText = '';
|
||||||
shouldTriggerCallback?: boolean
|
|
||||||
) => {
|
|
||||||
if (typeof input === 'string') {
|
|
||||||
this._inputText = input;
|
|
||||||
this.generate();
|
this.generate();
|
||||||
} else {
|
} else if (type === 'input') {
|
||||||
// reset state
|
this.hide();
|
||||||
this.hide(shouldTriggerCallback);
|
|
||||||
this.state = 'input';
|
this.state = 'input';
|
||||||
}
|
}
|
||||||
|
|
||||||
this._autoUpdatePosition(reference);
|
this._autoUpdatePosition(reference);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -551,9 +551,11 @@ export class EditorUtils {
|
|||||||
explainImage: this.createAction(page, () =>
|
explainImage: this.createAction(page, () =>
|
||||||
page.getByTestId('action-explain-image').click()
|
page.getByTestId('action-explain-image').click()
|
||||||
),
|
),
|
||||||
generateImage: this.createAction(page, () =>
|
generateImage: this.createAction(page, async () => {
|
||||||
page.getByTestId('action-generate-image').click()
|
await page.getByTestId('action-generate-image').click();
|
||||||
),
|
await page.keyboard.type('generate an image');
|
||||||
|
await page.getByTestId('ai-panel-input-send').click();
|
||||||
|
}),
|
||||||
generateCaption: this.createAction(page, () =>
|
generateCaption: this.createAction(page, () =>
|
||||||
page.getByTestId('action-generate-caption').click()
|
page.getByTestId('action-generate-caption').click()
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user