mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-13 04:42:56 +08:00
feat(mobile): get content in markdown api
This commit is contained in:
@@ -137,12 +137,9 @@ events?.applicationMenu.onNewPageAction(() => {
|
||||
.get(GlobalContextService)
|
||||
.globalContext.workspaceId.get();
|
||||
const workspacesService = frameworkProvider.get(WorkspacesService);
|
||||
const workspaceMetadata = currentWorkspaceId
|
||||
? workspacesService.list.workspace$(currentWorkspaceId).value
|
||||
const workspaceRef = currentWorkspaceId
|
||||
? workspacesService.openByWorkspaceId(currentWorkspaceId)
|
||||
: null;
|
||||
const workspaceRef =
|
||||
workspaceMetadata &&
|
||||
workspacesService.open({ metadata: workspaceMetadata });
|
||||
if (!workspaceRef) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -44,4 +44,4 @@ SPEC CHECKSUMS:
|
||||
|
||||
PODFILE CHECKSUM: 1b0d3fe81862c0e9ce712ddd0c5a0accd0097698
|
||||
|
||||
COCOAPODS: 1.16.2
|
||||
COCOAPODS: 1.15.2
|
||||
|
||||
@@ -9,7 +9,7 @@ const config: CapacitorConfig = {
|
||||
path: '.',
|
||||
},
|
||||
server: {
|
||||
// url: 'http://localhost:8080',
|
||||
url: 'http://localhost:8080',
|
||||
},
|
||||
plugins: {
|
||||
CapacitorCookies: {
|
||||
|
||||
@@ -19,13 +19,22 @@ import {
|
||||
configureBrowserWorkspaceFlavours,
|
||||
configureIndexedDBWorkspaceEngineStorageProvider,
|
||||
} from '@affine/core/modules/workspace-engine';
|
||||
import {
|
||||
docLinkBaseURLMiddleware,
|
||||
MarkdownAdapter,
|
||||
titleMiddleware,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { Job } from '@blocksuite/affine/store';
|
||||
import { App as CapacitorApp } from '@capacitor/app';
|
||||
import { Browser } from '@capacitor/browser';
|
||||
import {
|
||||
DocsService,
|
||||
Framework,
|
||||
FrameworkRoot,
|
||||
getCurrentStore,
|
||||
GlobalContextService,
|
||||
LifecycleService,
|
||||
WorkspacesService,
|
||||
} from '@toeverything/infra';
|
||||
import { Suspense } from 'react';
|
||||
import { RouterProvider } from 'react-router-dom';
|
||||
@@ -86,8 +95,55 @@ framework.impl(AIButtonProvider, {
|
||||
return Intelligents.dismissIntelligentsButton();
|
||||
},
|
||||
});
|
||||
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
(window as any).getCurrentDocContentInMarkdown = async () => {
|
||||
const globalContextService = frameworkProvider.get(GlobalContextService);
|
||||
const currentWorkspaceId =
|
||||
globalContextService.globalContext.workspaceId.get();
|
||||
const currentDocId = globalContextService.globalContext.docId.get();
|
||||
const workspacesService = frameworkProvider.get(WorkspacesService);
|
||||
const workspaceRef = currentWorkspaceId
|
||||
? workspacesService.openByWorkspaceId(currentWorkspaceId)
|
||||
: null;
|
||||
if (!workspaceRef) {
|
||||
return;
|
||||
}
|
||||
const { workspace, dispose: disposeWorkspace } = workspaceRef;
|
||||
|
||||
const docsService = workspace.scope.get(DocsService);
|
||||
const docRef = currentDocId ? docsService.open(currentDocId) : null;
|
||||
if (!docRef) {
|
||||
return;
|
||||
}
|
||||
const { doc, release: disposeDoc } = docRef;
|
||||
|
||||
try {
|
||||
const blockSuiteDoc = doc.blockSuiteDoc;
|
||||
|
||||
const job = new Job({
|
||||
collection: blockSuiteDoc.collection,
|
||||
middlewares: [docLinkBaseURLMiddleware, titleMiddleware],
|
||||
});
|
||||
const snapshot = await job.docToSnapshot(blockSuiteDoc);
|
||||
|
||||
const adapter = new MarkdownAdapter(job);
|
||||
if (!snapshot) {
|
||||
return;
|
||||
}
|
||||
|
||||
const markdownResult = await adapter.fromDocSnapshot({
|
||||
snapshot,
|
||||
assets: job.assetsManager,
|
||||
});
|
||||
return markdownResult.file;
|
||||
} finally {
|
||||
disposeDoc();
|
||||
disposeWorkspace();
|
||||
}
|
||||
};
|
||||
|
||||
// setup application lifecycle events, and emit application start event
|
||||
window.addEventListener('focus', () => {
|
||||
frameworkProvider.get(LifecycleService).applicationFocus();
|
||||
|
||||
Reference in New Issue
Block a user