Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix(core): edgeless text ai action should generate image correctly (#10158)

donteatfriedrice40c6e42ab80b
diff --git a/packages/frontend/component/src/lit-react/lit-portal/lit-portal.tsx b/packages/frontend/component/src/lit-react/lit-portal/lit-portal.tsx
index 6282361320..21b161ecaf 100644
--- a/packages/frontend/component/src/lit-react/lit-portal/lit-portal.tsx
+++ b/packages/frontend/component/src/lit-react/lit-portal/lit-portal.tsx
@@ -23,7 +23,7 @@ export const LIT_REACT_PORTAL = 'lit-react-portal';
@customElement(LIT_REACT_PORTAL)
class LitReactPortal extends LitElement {
portalId!: string;
- notify!: PortalListener;
+ notify?: PortalListener;
static override get properties() {
return {
@@ -34,7 +34,7 @@ class LitReactPortal extends LitElement {
override connectedCallback() {
super.connectedCallback();
- this.notify({
+ this.notify?.({
name: 'connectedCallback',
target: this,
});
@@ -47,7 +47,7 @@ class LitReactPortal extends LitElement {
) {
super.attributeChangedCallback(name, oldVal, newVal);
if (name.toLowerCase() === 'portalid') {
- this.notify({
+ this.notify?.({
name: 'willUpdate',
target: this,
});
@@ -61,7 +61,7 @@ class LitReactPortal extends LitElement {
override disconnectedCallback() {
super.disconnectedCallback();
- this.notify({
+ this.notify?.({
name: 'disconnectedCallback',
target: this,
});
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts
index 9c448e73b3..1bc7e02f7a 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/chat-panel/index.ts
@@ -272,15 +272,19 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
const userId = (await AIProvider.userInfo)?.id;
if (!userId) return;
- this._chatSessionId = await AIProvider.session?.createSession(
- this.doc.workspace.id,
- this.doc.id
- );
- if (this._chatSessionId) {
- this._chatContextId = await AIProvider.context?.createContext(
+ try {
+ this._chatSessionId = await AIProvider.session?.createSession(
this.doc.workspace.id,
- this._chatSessionId
+ this.doc.id
);
+ if (this._chatSessionId) {
+ this._chatContextId = await AIProvider.context?.createContext(
+ this.doc.workspace.id,
+ this._chatSessionId
+ );
+ }
+ } catch (e) {
+ console.error('init panel error', e);
}
await this._updateHistory();
await this._updateChips();
diff --git a/packages/frontend/core/src/blocksuite/presets/ai/utils/selection-utils.ts b/packages/frontend/core/src/blocksuite/presets/ai/utils/selection-utils.ts
index ce6ee1ac40..3615e58498 100644
--- a/packages/frontend/core/src/blocksuite/presets/ai/utils/selection-utils.ts
+++ b/packages/frontend/core/src/blocksuite/presets/ai/utils/selection-utils.ts
@@ -50,39 +50,35 @@ export async function allToCanvas(host: EditorHost) {
export async function elementsToCanvas(host: EditorHost, elements: GfxModel[]) {
const edgelessRoot = getEdgelessRootFromEditor(host);
- const { notes, frames, shapes, images } = BlocksUtils.splitElements(elements);
- if (notes.length + frames.length + images.length + shapes.length === 0) {
+ const { notes, frames, shapes, images, edgelessTexts, embedSyncedDocs } =
+ BlocksUtils.splitElements(elements);
+
+ const blockElements = [
+ ...notes,
+ ...frames,
+ ...images,
+ ...edgelessTexts,
+ ...embedSyncedDocs,
+ ];
+
+ const hasElements = blockElements.length > 0 || shapes.length > 0;
+ if (!hasElements) {
return;
}
- const canvas = await edgelessRoot.clipboardController.toCanvas(
- [...notes, ...frames, ...images],
- shapes
- );
- if (!canvas) {
- return;
- }
- return canvas;
-}
-export async function frameToCanvas(
- frame: FrameBlockModel,
- editor: EditorHost
-) {
- const edgelessRoot = getEdgelessRootFromEditor(editor);
- const { notes, frames, shapes, images } = BlocksUtils.splitElements(
- edgelessRoot.service.frame.getElementsInFrameBound(frame, true)
- );
- if (notes.length + frames.length + images.length + shapes.length === 0) {
- return;
- }
- const canvas = await edgelessRoot.clipboardController.toCanvas(
- [...notes, ...frames, ...images],
- shapes
- );
- if (!canvas) {
+ try {
+ const canvas = await edgelessRoot.clipboardController.toCanvas(
+ blockElements,
+ shapes
+ );
+ if (!canvas) {
+ return;
+ }
+ return canvas;
+ } catch (e) {
+ console.error('elementsToCanvas error', e);
return;
}
- return canvas;
}
export async function selectedToPng(editor: EditorHost) {