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

[BS-2570](https://linear.app/affine-design/issue/BS-2570/edgeless-text-没有被正确的作为上下文放入-app)
This commit is contained in:
donteatfriedrice
2025-02-13 09:38:12 +00:00
parent 887bbcf641
commit 40c6e42ab8
3 changed files with 39 additions and 39 deletions

View File

@@ -23,7 +23,7 @@ export const LIT_REACT_PORTAL = 'lit-react-portal';
@customElement(LIT_REACT_PORTAL) @customElement(LIT_REACT_PORTAL)
class LitReactPortal extends LitElement { class LitReactPortal extends LitElement {
portalId!: string; portalId!: string;
notify!: PortalListener; notify?: PortalListener;
static override get properties() { static override get properties() {
return { return {
@@ -34,7 +34,7 @@ class LitReactPortal extends LitElement {
override connectedCallback() { override connectedCallback() {
super.connectedCallback(); super.connectedCallback();
this.notify({ this.notify?.({
name: 'connectedCallback', name: 'connectedCallback',
target: this, target: this,
}); });
@@ -47,7 +47,7 @@ class LitReactPortal extends LitElement {
) { ) {
super.attributeChangedCallback(name, oldVal, newVal); super.attributeChangedCallback(name, oldVal, newVal);
if (name.toLowerCase() === 'portalid') { if (name.toLowerCase() === 'portalid') {
this.notify({ this.notify?.({
name: 'willUpdate', name: 'willUpdate',
target: this, target: this,
}); });
@@ -61,7 +61,7 @@ class LitReactPortal extends LitElement {
override disconnectedCallback() { override disconnectedCallback() {
super.disconnectedCallback(); super.disconnectedCallback();
this.notify({ this.notify?.({
name: 'disconnectedCallback', name: 'disconnectedCallback',
target: this, target: this,
}); });

View File

@@ -272,6 +272,7 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
const userId = (await AIProvider.userInfo)?.id; const userId = (await AIProvider.userInfo)?.id;
if (!userId) return; if (!userId) return;
try {
this._chatSessionId = await AIProvider.session?.createSession( this._chatSessionId = await AIProvider.session?.createSession(
this.doc.workspace.id, this.doc.workspace.id,
this.doc.id this.doc.id
@@ -282,6 +283,9 @@ export class ChatPanel extends WithDisposable(ShadowlessElement) {
this._chatSessionId this._chatSessionId
); );
} }
} catch (e) {
console.error('init panel error', e);
}
await this._updateHistory(); await this._updateHistory();
await this._updateChips(); await this._updateChips();
}; };

View File

@@ -50,39 +50,35 @@ export async function allToCanvas(host: EditorHost) {
export async function elementsToCanvas(host: EditorHost, elements: GfxModel[]) { export async function elementsToCanvas(host: EditorHost, elements: GfxModel[]) {
const edgelessRoot = getEdgelessRootFromEditor(host); const edgelessRoot = getEdgelessRootFromEditor(host);
const { notes, frames, shapes, images } = BlocksUtils.splitElements(elements); const { notes, frames, shapes, images, edgelessTexts, embedSyncedDocs } =
if (notes.length + frames.length + images.length + shapes.length === 0) { BlocksUtils.splitElements(elements);
const blockElements = [
...notes,
...frames,
...images,
...edgelessTexts,
...embedSyncedDocs,
];
const hasElements = blockElements.length > 0 || shapes.length > 0;
if (!hasElements) {
return; return;
} }
const canvas = await edgelessRoot.clipboardController.toCanvas(
[...notes, ...frames, ...images],
shapes
);
if (!canvas) {
return;
}
return canvas;
}
export async function frameToCanvas( try {
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( const canvas = await edgelessRoot.clipboardController.toCanvas(
[...notes, ...frames, ...images], blockElements,
shapes shapes
); );
if (!canvas) { if (!canvas) {
return; return;
} }
return canvas; return canvas;
} catch (e) {
console.error('elementsToCanvas error', e);
return;
}
} }
export async function selectedToPng(editor: EditorHost) { export async function selectedToPng(editor: EditorHost) {