mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-29 08:09:52 +08:00
+4
-13
@@ -10,24 +10,15 @@ export class LitTranscriptionBlock extends BlockComponent<TranscriptionBlockMode
|
||||
css`
|
||||
transcription-block {
|
||||
outline: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
get lastCalloutBlock() {
|
||||
for (const child of this.model.children.toReversed()) {
|
||||
if (child.flavour === 'affine:callout') {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
override render() {
|
||||
return this.std.host.renderChildren(this.model, model => {
|
||||
// if model is the last transcription block, we should render it
|
||||
return model === this.lastCalloutBlock;
|
||||
});
|
||||
return this.std.host.renderChildren(this.model);
|
||||
}
|
||||
|
||||
@property({ type: String, attribute: 'data-block-id' })
|
||||
|
||||
@@ -56,7 +56,7 @@ export const PPTBuilder = (host: EditorHost) => {
|
||||
return {
|
||||
process: async (text: string) => {
|
||||
try {
|
||||
const snapshot = await markdownToSnapshot(text, host);
|
||||
const snapshot = await markdownToSnapshot(text, host.doc, host);
|
||||
|
||||
const block = snapshot.snapshot?.content[0];
|
||||
if (!block) {
|
||||
@@ -73,7 +73,7 @@ export const PPTBuilder = (host: EditorHost) => {
|
||||
return { contents, images: allImages };
|
||||
},
|
||||
done: async (text: string) => {
|
||||
const snapshot = await markdownToSnapshot(text, host);
|
||||
const snapshot = await markdownToSnapshot(text, host.doc, host);
|
||||
const block = snapshot.snapshot?.content[0];
|
||||
if (!block) {
|
||||
return;
|
||||
|
||||
@@ -110,7 +110,11 @@ export const replace = async (
|
||||
|
||||
if (textSelection) {
|
||||
host.std.command.exec(deleteTextCommand, { textSelection });
|
||||
const { snapshot, transformer } = await markdownToSnapshot(content, host);
|
||||
const { snapshot, transformer } = await markdownToSnapshot(
|
||||
content,
|
||||
host.doc,
|
||||
host
|
||||
);
|
||||
if (snapshot) {
|
||||
await transformer.snapshotToSlice(
|
||||
snapshot,
|
||||
|
||||
@@ -102,18 +102,19 @@ export async function getContentFromSlice(
|
||||
|
||||
export const markdownToSnapshot = async (
|
||||
markdown: string,
|
||||
host: EditorHost
|
||||
store: Store,
|
||||
host?: EditorHost
|
||||
) => {
|
||||
const transformer = host.std.store.getTransformer([
|
||||
defaultImageProxyMiddleware,
|
||||
pasteMiddleware(host.std),
|
||||
]);
|
||||
const markdownAdapter = new MixTextAdapter(transformer, host.std.provider);
|
||||
const middlewares = host
|
||||
? [defaultImageProxyMiddleware, pasteMiddleware(host.std)]
|
||||
: [defaultImageProxyMiddleware];
|
||||
const transformer = store.getTransformer(middlewares);
|
||||
const markdownAdapter = new MixTextAdapter(transformer, store.provider);
|
||||
const payload = {
|
||||
file: markdown,
|
||||
assets: transformer.assetsManager,
|
||||
workspaceId: host.std.store.workspace.id,
|
||||
pageId: host.std.store.id,
|
||||
workspaceId: store.workspace.id,
|
||||
pageId: store.id,
|
||||
};
|
||||
|
||||
const snapshot = await markdownAdapter.toSliceSnapshot(payload);
|
||||
@@ -125,13 +126,17 @@ export const markdownToSnapshot = async (
|
||||
};
|
||||
|
||||
export async function insertFromMarkdown(
|
||||
host: EditorHost,
|
||||
host: EditorHost | undefined,
|
||||
markdown: string,
|
||||
doc: Store,
|
||||
parent?: string,
|
||||
index?: number
|
||||
) {
|
||||
const { snapshot, transformer } = await markdownToSnapshot(markdown, host);
|
||||
const { snapshot, transformer } = await markdownToSnapshot(
|
||||
markdown,
|
||||
doc,
|
||||
host
|
||||
);
|
||||
|
||||
const snapshots = snapshot?.content.flatMap(x => x.children) ?? [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user