mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
refactor(editor): use transformer from store when possible (#10453)
This commit is contained in:
@@ -64,7 +64,6 @@ import {
|
|||||||
BlockSnapshotSchema,
|
BlockSnapshotSchema,
|
||||||
fromJSON,
|
fromJSON,
|
||||||
type SliceSnapshot,
|
type SliceSnapshot,
|
||||||
Transformer,
|
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
@@ -373,15 +372,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
|||||||
if (mayBeSurfaceDataJson !== undefined) {
|
if (mayBeSurfaceDataJson !== undefined) {
|
||||||
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
||||||
const { snapshot, blobs } = elementsRawData;
|
const { snapshot, blobs } = elementsRawData;
|
||||||
const job = new Transformer({
|
const job = this.std.store.getTransformer();
|
||||||
schema: this.std.store.schema,
|
|
||||||
blobCRUD: this.std.workspace.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => this.std.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => this.std.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => this.std.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const map = job.assetsManager.getAssets();
|
const map = job.assetsManager.getAssets();
|
||||||
decodeClipboardBlobs(blobs, map);
|
decodeClipboardBlobs(blobs, map);
|
||||||
for (const blobId of map.keys()) {
|
for (const blobId of map.keys()) {
|
||||||
@@ -1377,15 +1368,7 @@ export async function prepareClipboardData(
|
|||||||
selectedAll: GfxModel[],
|
selectedAll: GfxModel[],
|
||||||
std: BlockStdScope
|
std: BlockStdScope
|
||||||
) {
|
) {
|
||||||
const job = new Transformer({
|
const job = std.store.getTransformer();
|
||||||
schema: std.store.schema,
|
|
||||||
blobCRUD: std.workspace.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => std.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => std.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => std.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const selected = await Promise.all(
|
const selected = await Promise.all(
|
||||||
selectedAll.map(async selected => {
|
selectedAll.map(async selected => {
|
||||||
const data = serializeElement(selected, selectedAll, job);
|
const data = serializeElement(selected, selectedAll, job);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
type DocSnapshot,
|
type DocSnapshot,
|
||||||
DocSnapshotSchema,
|
DocSnapshotSchema,
|
||||||
type SnapshotNode,
|
type SnapshotNode,
|
||||||
Transformer,
|
type Transformer,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import type * as Y from 'yjs';
|
import type * as Y from 'yjs';
|
||||||
/**
|
/**
|
||||||
@@ -90,16 +90,7 @@ export class TemplateJob {
|
|||||||
type: TemplateType;
|
type: TemplateType;
|
||||||
|
|
||||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||||
this.job = new Transformer({
|
this.job = model.doc.getTransformer();
|
||||||
schema: model.doc.schema,
|
|
||||||
blobCRUD: model.doc.workspace.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => model.doc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => model.doc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => model.doc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [],
|
|
||||||
});
|
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.type = TEMPLATE_TYPES.includes(type as TemplateType)
|
this.type = TEMPLATE_TYPES.includes(type as TemplateType)
|
||||||
? (type as TemplateType)
|
? (type as TemplateType)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
isGfxGroupCompatibleModel,
|
isGfxGroupCompatibleModel,
|
||||||
type SerializedElement,
|
type SerializedElement,
|
||||||
} from '@blocksuite/block-std/gfx';
|
} from '@blocksuite/block-std/gfx';
|
||||||
import { type BlockSnapshot, Transformer } from '@blocksuite/store';
|
import type { BlockSnapshot, Transformer } from '@blocksuite/store';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return all elements in the tree of the elements
|
* return all elements in the tree of the elements
|
||||||
@@ -40,15 +40,7 @@ export function getSortedCloneElements(elements: GfxModel[]) {
|
|||||||
|
|
||||||
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||||
elements = sortEdgelessElements(elements);
|
elements = sortEdgelessElements(elements);
|
||||||
const job = new Transformer({
|
const job = std.store.getTransformer();
|
||||||
schema: std.store.schema,
|
|
||||||
blobCRUD: std.workspace.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => std.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => std.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => std.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const res = elements.map(element => {
|
const res = elements.map(element => {
|
||||||
const data = serializeElement(element, elements, job);
|
const data = serializeElement(element, elements, job);
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -43,19 +43,10 @@ function getProvider() {
|
|||||||
*/
|
*/
|
||||||
async function exportDoc(doc: Store) {
|
async function exportDoc(doc: Store) {
|
||||||
const provider = getProvider();
|
const provider = getProvider();
|
||||||
const job = new Transformer({
|
const job = doc.getTransformer([
|
||||||
schema: doc.schema,
|
docLinkBaseURLMiddleware(doc.workspace.id),
|
||||||
blobCRUD: doc.blobSync,
|
titleMiddleware(doc.workspace.meta.docMetas),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => doc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
docLinkBaseURLMiddleware(doc.workspace.id),
|
|
||||||
titleMiddleware(doc.workspace.meta.docMetas),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const snapshot = job.docToSnapshot(doc);
|
const snapshot = job.docToSnapshot(doc);
|
||||||
const adapter = new HtmlAdapter(job, provider);
|
const adapter = new HtmlAdapter(job, provider);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
|
|||||||
@@ -49,19 +49,10 @@ type ImportMarkdownZipOptions = {
|
|||||||
*/
|
*/
|
||||||
async function exportDoc(doc: Store) {
|
async function exportDoc(doc: Store) {
|
||||||
const provider = getProvider();
|
const provider = getProvider();
|
||||||
const job = new Transformer({
|
const job = doc.getTransformer([
|
||||||
schema: doc.schema,
|
docLinkBaseURLMiddleware(doc.workspace.id),
|
||||||
blobCRUD: doc.blobSync,
|
titleMiddleware(doc.workspace.meta.docMetas),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => doc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
docLinkBaseURLMiddleware(doc.workspace.id),
|
|
||||||
titleMiddleware(doc.workspace.meta.docMetas),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const snapshot = job.docToSnapshot(doc);
|
const snapshot = job.docToSnapshot(doc);
|
||||||
|
|
||||||
const adapter = new MarkdownAdapter(job, provider);
|
const adapter = new MarkdownAdapter(job, provider);
|
||||||
@@ -109,19 +100,10 @@ async function importMarkdownToBlock({
|
|||||||
blockId,
|
blockId,
|
||||||
}: ImportMarkdownToBlockOptions) {
|
}: ImportMarkdownToBlockOptions) {
|
||||||
const provider = getProvider();
|
const provider = getProvider();
|
||||||
const job = new Transformer({
|
const job = doc.getTransformer([
|
||||||
schema: doc.schema,
|
defaultImageProxyMiddleware,
|
||||||
blobCRUD: doc.blobSync,
|
docLinkBaseURLMiddleware(doc.workspace.id),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => doc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
defaultImageProxyMiddleware,
|
|
||||||
docLinkBaseURLMiddleware(doc.workspace.id),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const adapter = new MarkdownAdapter(job, provider);
|
const adapter = new MarkdownAdapter(job, provider);
|
||||||
const snapshot = await adapter.toSliceSnapshot({
|
const snapshot = await adapter.toSliceSnapshot({
|
||||||
file: markdown,
|
file: markdown,
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export class DNDAPIExtension extends Extension {
|
|||||||
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
const { docId, flavour = 'affine:embed-linked-doc', blockId } = options;
|
||||||
|
|
||||||
const slice = Slice.fromModels(this.std.store, []);
|
const slice = Slice.fromModels(this.std.store, []);
|
||||||
const job = this.std.getTransformer();
|
const job = this.std.store.getTransformer();
|
||||||
const snapshot = job.sliceToSnapshot(slice);
|
const snapshot = job.sliceToSnapshot(slice);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
console.error('Failed to convert slice to snapshot');
|
console.error('Failed to convert slice to snapshot');
|
||||||
|
|||||||
@@ -1354,7 +1354,7 @@ export class DragEventWatcher {
|
|||||||
middlewares.push(gfxBlocksFilter(selectedIds, std));
|
middlewares.push(gfxBlocksFilter(selectedIds, std));
|
||||||
}
|
}
|
||||||
|
|
||||||
return std.getTransformer(middlewares);
|
return std.store.getTransformer(middlewares);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _isDropOnCurrentEditor(std?: BlockStdScope) {
|
private _isDropOnCurrentEditor(std?: BlockStdScope) {
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ export class Clipboard extends LifeCycleWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getJob() {
|
private _getJob() {
|
||||||
return this.std.getTransformer(this._jobMiddlewares);
|
return this.std.store.getTransformer(this._jobMiddlewares);
|
||||||
}
|
}
|
||||||
|
|
||||||
readFromClipboard(clipboardData: DataTransfer) {
|
readFromClipboard(clipboardData: DataTransfer) {
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import {
|
|||||||
type ExtensionType,
|
type ExtensionType,
|
||||||
type Store,
|
type Store,
|
||||||
StoreSelectionExtension,
|
StoreSelectionExtension,
|
||||||
Transformer,
|
|
||||||
type TransformerMiddleware,
|
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
|
|
||||||
import { Clipboard } from '../clipboard/index.js';
|
import { Clipboard } from '../clipboard/index.js';
|
||||||
@@ -140,19 +138,6 @@ export class BlockStdScope {
|
|||||||
return this.getOptional(BlockViewIdentifier(flavour));
|
return this.getOptional(BlockViewIdentifier(flavour));
|
||||||
}
|
}
|
||||||
|
|
||||||
getTransformer(middlewares: TransformerMiddleware[] = []) {
|
|
||||||
return new Transformer({
|
|
||||||
schema: this.store.schema,
|
|
||||||
blobCRUD: this.workspace.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => this.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => this.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => this.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
mount() {
|
mount() {
|
||||||
this._lifeCycleWatchers.forEach(watcher => {
|
this._lifeCycleWatchers.forEach(watcher => {
|
||||||
watcher.mounted();
|
watcher.mounted();
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import {
|
|||||||
StoreSelectionExtension,
|
StoreSelectionExtension,
|
||||||
} from '../../extension/index.js';
|
} from '../../extension/index.js';
|
||||||
import { Schema } from '../../schema/index.js';
|
import { Schema } from '../../schema/index.js';
|
||||||
|
import type { TransformerMiddleware } from '../../transformer/middleware.js';
|
||||||
|
import { Transformer } from '../../transformer/transformer.js';
|
||||||
import {
|
import {
|
||||||
Block,
|
Block,
|
||||||
type BlockModel,
|
type BlockModel,
|
||||||
@@ -715,4 +717,17 @@ export class Store {
|
|||||||
get getOptional() {
|
get getOptional() {
|
||||||
return this.provider.getOptional.bind(this.provider);
|
return this.provider.getOptional.bind(this.provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTransformer(middlewares: TransformerMiddleware[] = []) {
|
||||||
|
return new Transformer({
|
||||||
|
schema: this.schema,
|
||||||
|
blobCRUD: this.workspace.blobSync,
|
||||||
|
docCRUD: {
|
||||||
|
create: (id: string) => this.workspace.createDoc({ id }),
|
||||||
|
get: (id: string) => this.workspace.getDoc(id),
|
||||||
|
delete: (id: string) => this.workspace.removeDoc(id),
|
||||||
|
},
|
||||||
|
middlewares,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { WithDisposable } from '@blocksuite/global/utils';
|
import { WithDisposable } from '@blocksuite/global/utils';
|
||||||
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
||||||
import { type DocSnapshot, Transformer } from '@blocksuite/store';
|
import type { DocSnapshot } from '@blocksuite/store';
|
||||||
import { effect } from '@preact/signals-core';
|
import { effect } from '@preact/signals-core';
|
||||||
import type SlTabPanel from '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
import type SlTabPanel from '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
|
||||||
import { css, html, type PropertyValues } from 'lit';
|
import { css, html, type PropertyValues } from 'lit';
|
||||||
@@ -101,24 +101,15 @@ export class AdaptersPanel extends WithDisposable(ShadowlessElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createJob() {
|
private _createJob() {
|
||||||
return new Transformer({
|
return this.doc.getTransformer([
|
||||||
schema: this.doc.schema,
|
docLinkBaseURLMiddlewareBuilder(
|
||||||
blobCRUD: this.doc.blobSync,
|
'https://example.com',
|
||||||
docCRUD: {
|
this.doc.workspace.id
|
||||||
create: (id: string) => this.doc.workspace.createDoc({ id }),
|
).get(),
|
||||||
get: (id: string) => this.doc.workspace.getDoc(id),
|
titleMiddleware(this.doc.workspace.meta.docMetas),
|
||||||
delete: (id: string) => this.doc.workspace.removeDoc(id),
|
embedSyncedDocMiddleware('content'),
|
||||||
},
|
defaultImageProxyMiddleware,
|
||||||
middlewares: [
|
]);
|
||||||
docLinkBaseURLMiddlewareBuilder(
|
|
||||||
'https://example.com',
|
|
||||||
this.doc.workspace.id
|
|
||||||
).get(),
|
|
||||||
titleMiddleware(this.doc.workspace.meta.docMetas),
|
|
||||||
embedSyncedDocMiddleware('content'),
|
|
||||||
defaultImageProxyMiddleware,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getDocSnapshot() {
|
private _getDocSnapshot() {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
|||||||
import type { SerializedXYWH } from '@blocksuite/global/utils';
|
import type { SerializedXYWH } from '@blocksuite/global/utils';
|
||||||
import type { DeltaInsert } from '@blocksuite/inline/types';
|
import type { DeltaInsert } from '@blocksuite/inline/types';
|
||||||
import { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
import { TestAffineEditorContainer } from '@blocksuite/integration-test';
|
||||||
import { Text, Transformer, type Workspace } from '@blocksuite/store';
|
import { Text, type Workspace } from '@blocksuite/store';
|
||||||
import type { SlDropdown } from '@shoelace-style/shoelace';
|
import type { SlDropdown } from '@shoelace-style/shoelace';
|
||||||
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
|
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
|
||||||
import { css, html } from 'lit';
|
import { css, html } from 'lit';
|
||||||
@@ -237,19 +237,10 @@ export class StarterDebugMenu extends ShadowlessElement {
|
|||||||
|
|
||||||
private async _exportFile(config: AdapterConfig) {
|
private async _exportFile(config: AdapterConfig) {
|
||||||
const doc = this.editor.doc;
|
const doc = this.editor.doc;
|
||||||
const job = new Transformer({
|
const job = doc.getTransformer([
|
||||||
schema: doc.schema,
|
docLinkBaseURLMiddleware(this.collection.id),
|
||||||
blobCRUD: this.collection.blobSync,
|
titleMiddleware(this.collection.meta.docMetas),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => this.collection.createDoc({ id }),
|
|
||||||
get: (id: string) => this.collection.getDoc(id),
|
|
||||||
delete: (id: string) => this.collection.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
docLinkBaseURLMiddleware(this.collection.id),
|
|
||||||
titleMiddleware(this.collection.meta.docMetas),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const adapterFactory = this.editor.std.provider.get(config.identifier);
|
const adapterFactory = this.editor.std.provider.get(config.identifier);
|
||||||
const adapter = adapterFactory.get(job);
|
const adapter = adapterFactory.get(job);
|
||||||
@@ -444,16 +435,7 @@ export class StarterDebugMenu extends ShadowlessElement {
|
|||||||
});
|
});
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
const doc = this.editor.doc;
|
const doc = this.editor.doc;
|
||||||
const job = new Transformer({
|
const job = doc.getTransformer([defaultImageProxyMiddleware]);
|
||||||
schema: doc.schema,
|
|
||||||
blobCRUD: this.collection.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => this.collection.createDoc({ id }),
|
|
||||||
get: (id: string) => this.collection.getDoc(id),
|
|
||||||
delete: (id: string) => this.collection.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [defaultImageProxyMiddleware],
|
|
||||||
});
|
|
||||||
const htmlAdapter = new NotionHtmlAdapter(job, this.editor.std.provider);
|
const htmlAdapter = new NotionHtmlAdapter(job, this.editor.std.provider);
|
||||||
await htmlAdapter.toDoc({
|
await htmlAdapter.toDoc({
|
||||||
file: await file.text(),
|
file: await file.text(),
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import {
|
|||||||
titleMiddleware,
|
titleMiddleware,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { Container } from '@blocksuite/affine/global/di';
|
import { Container } from '@blocksuite/affine/global/di';
|
||||||
import { Transformer } from '@blocksuite/affine/store';
|
|
||||||
import { App as CapacitorApp } from '@capacitor/app';
|
import { App as CapacitorApp } from '@capacitor/app';
|
||||||
import { Keyboard } from '@capacitor/keyboard';
|
import { Keyboard } from '@capacitor/keyboard';
|
||||||
import { StatusBar, Style } from '@capacitor/status-bar';
|
import { StatusBar, Style } from '@capacitor/status-bar';
|
||||||
@@ -165,19 +164,10 @@ framework.impl(AIButtonProvider, {
|
|||||||
try {
|
try {
|
||||||
const blockSuiteDoc = doc.blockSuiteDoc;
|
const blockSuiteDoc = doc.blockSuiteDoc;
|
||||||
|
|
||||||
const transformer = new Transformer({
|
const transformer = blockSuiteDoc.getTransformer([
|
||||||
schema: blockSuiteDoc.schema,
|
docLinkBaseURLMiddleware(blockSuiteDoc.workspace.id),
|
||||||
blobCRUD: blockSuiteDoc.workspace.blobSync,
|
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => blockSuiteDoc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => blockSuiteDoc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => blockSuiteDoc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
docLinkBaseURLMiddleware(blockSuiteDoc.workspace.id),
|
|
||||||
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const snapshot = transformer.docToSnapshot(blockSuiteDoc);
|
const snapshot = transformer.docToSnapshot(blockSuiteDoc);
|
||||||
|
|
||||||
const container = new Container();
|
const container = new Container();
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import {
|
|||||||
titleMiddleware,
|
titleMiddleware,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { Container } from '@blocksuite/affine/global/di';
|
import { Container } from '@blocksuite/affine/global/di';
|
||||||
import { Transformer } from '@blocksuite/affine/store';
|
|
||||||
import { App as CapacitorApp } from '@capacitor/app';
|
import { App as CapacitorApp } from '@capacitor/app';
|
||||||
import { Browser } from '@capacitor/browser';
|
import { Browser } from '@capacitor/browser';
|
||||||
import { Haptics } from '@capacitor/haptics';
|
import { Haptics } from '@capacitor/haptics';
|
||||||
@@ -223,19 +222,10 @@ const frameworkProvider = framework.provider();
|
|||||||
try {
|
try {
|
||||||
const blockSuiteDoc = doc.blockSuiteDoc;
|
const blockSuiteDoc = doc.blockSuiteDoc;
|
||||||
|
|
||||||
const transformer = new Transformer({
|
const transformer = blockSuiteDoc.getTransformer([
|
||||||
schema: blockSuiteDoc.schema,
|
docLinkBaseURLMiddleware(blockSuiteDoc.workspace.id),
|
||||||
blobCRUD: blockSuiteDoc.workspace.blobSync,
|
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => blockSuiteDoc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => blockSuiteDoc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => blockSuiteDoc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
docLinkBaseURLMiddleware(blockSuiteDoc.workspace.id),
|
|
||||||
titleMiddleware(blockSuiteDoc.workspace.meta.docMetas),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const snapshot = transformer.docToSnapshot(blockSuiteDoc);
|
const snapshot = transformer.docToSnapshot(blockSuiteDoc);
|
||||||
|
|
||||||
const container = new Container();
|
const container = new Container();
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||||
import { Schema, type Store, Transformer } from '@blocksuite/affine/store';
|
import { Schema, type Store } from '@blocksuite/affine/store';
|
||||||
import { css, html, LitElement, nothing } from 'lit';
|
import { css, html, LitElement, nothing } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
@@ -235,15 +235,7 @@ export const markdownToMindmap = (
|
|||||||
provider: ServiceProvider
|
provider: ServiceProvider
|
||||||
) => {
|
) => {
|
||||||
let result: Node | null = null;
|
let result: Node | null = null;
|
||||||
const transformer = new Transformer({
|
const transformer = doc.getTransformer();
|
||||||
schema: doc.schema,
|
|
||||||
blobCRUD: doc.workspace.blobSync,
|
|
||||||
docCRUD: {
|
|
||||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => doc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const markdown = new MarkdownAdapter(transformer, provider);
|
const markdown = new MarkdownAdapter(transformer, provider);
|
||||||
const ast: Root = markdown['_markdownToAst'](answer);
|
const ast: Root = markdown['_markdownToAst'](answer);
|
||||||
const traverse = (
|
const traverse = (
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import type { BlockModel, Store } from '@blocksuite/affine/store';
|
import type { BlockModel, Store } from '@blocksuite/affine/store';
|
||||||
import { Slice, toDraftModel, Transformer } from '@blocksuite/affine/store';
|
import { Slice, toDraftModel } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
import type { ChatContextValue } from '../chat-panel/chat-context';
|
import type { ChatContextValue } from '../chat-panel/chat-context';
|
||||||
import {
|
import {
|
||||||
@@ -196,17 +196,8 @@ function getNoteBlockModels(doc: Store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getTransformer(doc: Store) {
|
async function getTransformer(doc: Store) {
|
||||||
return new Transformer({
|
return doc.getTransformer([
|
||||||
schema: doc.schema,
|
titleMiddleware(doc.workspace.meta.docMetas),
|
||||||
blobCRUD: doc.workspace.blobSync,
|
embedSyncedDocMiddleware('content'),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => doc.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
titleMiddleware(doc.workspace.meta.docMetas),
|
|
||||||
embedSyncedDocMiddleware('content'),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,19 +80,10 @@ export async function getContentFromSlice(
|
|||||||
slice: Slice,
|
slice: Slice,
|
||||||
type: 'markdown' | 'plain-text' = 'markdown'
|
type: 'markdown' | 'plain-text' = 'markdown'
|
||||||
) {
|
) {
|
||||||
const transformer = new Transformer({
|
const transformer = host.std.store.getTransformer([
|
||||||
schema: host.std.store.schema,
|
titleMiddleware(host.std.store.workspace.meta.docMetas),
|
||||||
blobCRUD: host.std.store.workspace.blobSync,
|
embedSyncedDocMiddleware('content'),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => host.std.store.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => host.std.store.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => host.std.store.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [
|
|
||||||
titleMiddleware(host.std.store.workspace.meta.docMetas),
|
|
||||||
embedSyncedDocMiddleware('content'),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const snapshot = transformer.sliceToSnapshot(slice);
|
const snapshot = transformer.sliceToSnapshot(slice);
|
||||||
if (!snapshot) {
|
if (!snapshot) {
|
||||||
return '';
|
return '';
|
||||||
@@ -113,16 +104,10 @@ export const markdownToSnapshot = async (
|
|||||||
markdown: string,
|
markdown: string,
|
||||||
host: EditorHost
|
host: EditorHost
|
||||||
) => {
|
) => {
|
||||||
const transformer = new Transformer({
|
const transformer = host.std.store.getTransformer([
|
||||||
schema: host.std.store.schema,
|
defaultImageProxyMiddleware,
|
||||||
blobCRUD: host.std.store.workspace.blobSync,
|
pasteMiddleware(host.std),
|
||||||
docCRUD: {
|
]);
|
||||||
create: (id: string) => host.std.store.workspace.createDoc({ id }),
|
|
||||||
get: (id: string) => host.std.store.workspace.getDoc(id),
|
|
||||||
delete: (id: string) => host.std.store.workspace.removeDoc(id),
|
|
||||||
},
|
|
||||||
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
|
||||||
});
|
|
||||||
const markdownAdapter = new MixTextAdapter(transformer, host.std.provider);
|
const markdownAdapter = new MixTextAdapter(transformer, host.std.provider);
|
||||||
const payload = {
|
const payload = {
|
||||||
file: markdown,
|
file: markdown,
|
||||||
|
|||||||
Reference in New Issue
Block a user