Skip to content

Commit

Permalink
fix(presets): improve make it real action
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed May 8, 2024
1 parent 1ae72f2 commit d74183b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/presets/src/ai/actions/edgeless-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export function actionToHandler<T extends keyof BlockSuitePresets.AIActions>(
const elementToolbar = getElementToolbar(host);
const isEmpty = selectedElements.length === 0;
const isCreateImageAction = id === 'createImage';
const isMakeItRealAction = !isCreateImageAction && id === 'makeItReal';
let referenceElement = null;
let togglePanel = () => Promise.resolve(isEmpty);

Expand All @@ -386,8 +387,7 @@ export function actionToHandler<T extends keyof BlockSuitePresets.AIActions>(

if (!referenceElement) return;

if (isCreateImageAction) {
// @TODO(fundon): remove async
if (isCreateImageAction || isMakeItRealAction) {
togglePanel = async () => {
if (isEmpty) return true;
const {
Expand Down
26 changes: 16 additions & 10 deletions packages/presets/src/ai/entries/edgeless/actions-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
import {
actionToHandler,
explainImageShowWhen,
getContentFromSelected,
makeItRealShowWhen,
mindmapChildShowWhen,
mindmapRootShowWhen,
Expand Down Expand Up @@ -361,17 +360,23 @@ const generateGroup: AIItemGroupConfig = {
return;
}

let content = (ctx.get()['content'] as string) || '';

// get user input
if (content.length === 0) {
const aiPanel = getAIPanel(host);
content = aiPanel.inputText?.trim() || '';
}

// single note, text, shape(text) or image(caption)
if (f === 0 && n + s + i === 1) {
const content = await getContentFromSelected(host, [
...notes,
...shapes,
...images,
]);
if (n + s + i === 1) {
if (!content) return;
return {
content,
};

if (n + s === 1) {
return {
content,
};
}
}

const edgelessRoot = getEdgelessRootFromEditor(host);
Expand All @@ -391,6 +396,7 @@ const generateGroup: AIItemGroupConfig = {
height: canvas.height,
});
return {
content,
attachments: [png],
};
}),
Expand Down

0 comments on commit d74183b

Please sign in to comment.