Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move image proxy middleware and adapter extensions #10345

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DatabaseBlockSchema } from '@blocksuite/affine-model';
import {
AdapterTextUtils,
BlockNotionHtmlAdapterExtension,
type BlockNotionHtmlAdapterMatcher,
HastUtils,
TextUtils,
} from '@blocksuite/affine-shared/adapters';
import { getTagColor } from '@blocksuite/data-view';
import { type BlockSnapshot, nanoid } from '@blocksuite/store';
Expand Down Expand Up @@ -219,7 +219,7 @@ export const databaseBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatche
column.type = 'rich-text';
row[column.id] = {
columnId: column.id,
value: TextUtils.createText(text),
value: AdapterTextUtils.createText(text),
};
} else {
row[column.id] = {
Expand All @@ -235,11 +235,11 @@ export const databaseBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatche
}
if (
column.type === 'rich-text' &&
!TextUtils.isText(row[column.id].value)
!AdapterTextUtils.isText(row[column.id].value)
) {
row[column.id] = {
columnId: column.id,
value: TextUtils.createText(row[column.id].value),
value: AdapterTextUtils.createText(row[column.id].value),
};
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async function renderNoteContent(
match: ids.map(id => ({ id, viewType: 'display' })),
};
const previewDoc = doc.doc.getStore({ query });
const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
const previewSpec = SpecProvider.getInstance().getSpec('preview:page');
const previewStd = new BlockStdScope({
store: previewDoc,
extensions: previewSpec.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EmbedLinkedDocBlockSchema } from '@blocksuite/affine-model';
import {
AdapterTextUtils,
BlockHtmlAdapterExtension,
type BlockHtmlAdapterMatcher,
TextUtils,
} from '@blocksuite/affine-shared/adapters';

export const embedLinkedDocBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
Expand All @@ -18,7 +18,7 @@ export const embedLinkedDocBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
return;
}
const title = configs.get('title:' + o.node.props.pageId) ?? 'untitled';
const url = TextUtils.generateDocUrl(
const url = AdapterTextUtils.generateDocUrl(
configs.get('docLinkBaseUrl') ?? '',
String(o.node.props.pageId),
o.node.props.params ?? Object.create(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EmbedLinkedDocBlockSchema } from '@blocksuite/affine-model';
import {
AdapterTextUtils,
BlockMarkdownAdapterExtension,
type BlockMarkdownAdapterMatcher,
TextUtils,
} from '@blocksuite/affine-shared/adapters';

export const embedLinkedDocBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher =
Expand All @@ -19,7 +19,7 @@ export const embedLinkedDocBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatc
return;
}
const title = configs.get('title:' + o.node.props.pageId) ?? 'untitled';
const url = TextUtils.generateDocUrl(
const url = AdapterTextUtils.generateDocUrl(
configs.get('docLinkBaseUrl') ?? '',
String(o.node.props.pageId),
o.node.props.params ?? Object.create(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EmbedLinkedDocBlockSchema } from '@blocksuite/affine-model';
import {
AdapterTextUtils,
BlockPlainTextAdapterExtension,
type BlockPlainTextAdapterMatcher,
TextUtils,
} from '@blocksuite/affine-shared/adapters';

export const embedLinkedDocBlockPlainTextAdapterMatcher: BlockPlainTextAdapterMatcher =
Expand All @@ -19,7 +19,7 @@ export const embedLinkedDocBlockPlainTextAdapterMatcher: BlockPlainTextAdapterMa
return;
}
const title = configs.get('title:' + o.node.props.pageId) ?? 'untitled';
const url = TextUtils.generateDocUrl(
const url = AdapterTextUtils.generateDocUrl(
configs.get('docLinkBaseUrl') ?? '',
String(o.node.props.pageId),
o.node.props.params ?? Object.create(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
<div class="affine-page-viewport" data-theme=${appTheme}>
${new BlockStdScope({
store: syncedDoc,
extensions: this._buildPreviewSpec('page:preview'),
extensions: this._buildPreviewSpec('preview:page'),
}).render()}
</div>
`,
Expand All @@ -81,7 +81,7 @@ export class EmbedEdgelessSyncedDocBlockComponent extends toEdgelessEmbedBlock(
<div class="affine-edgeless-viewport" data-theme=${edgelessTheme}>
${new BlockStdScope({
store: syncedDoc,
extensions: this._buildPreviewSpec('edgeless:preview'),
extensions: this._buildPreviewSpec('preview:edgeless'),
}).render()}
</div>
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
],
};

protected _buildPreviewSpec = (name: 'page:preview' | 'edgeless:preview') => {
protected _buildPreviewSpec = (name: 'preview:page' | 'preview:edgeless') => {
const nextDepth = this.depth + 1;
const previewSpecBuilder = SpecProvider.getInstance().getSpec(name);
const currentDisposables = this.disposables;
Expand Down Expand Up @@ -203,7 +203,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
<div class="affine-page-viewport" data-theme=${appTheme}>
${new BlockStdScope({
store: syncedDoc,
extensions: this._buildPreviewSpec('page:preview'),
extensions: this._buildPreviewSpec('preview:page'),
}).render()}
</div>
`,
Expand All @@ -214,7 +214,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
<div class="affine-edgeless-viewport" data-theme=${edgelessTheme}>
${new BlockStdScope({
store: syncedDoc,
extensions: this._buildPreviewSpec('edgeless:preview'),
extensions: this._buildPreviewSpec('preview:edgeless'),
}).render()}
</div>
`,
Expand Down
1 change: 1 addition & 0 deletions blocksuite/affine/block-frame/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './frame-block.js';
export * from './frame-manager.js';
export * from './frame-spec.js';
export * from './tool.js';
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { NavigatorMode } from '@blocksuite/affine-block-frame';
import { BaseTool } from '@blocksuite/block-std/gfx';

import type { NavigatorMode } from './frame-manager';

type PresentToolOption = {
mode?: NavigatorMode;
};
Expand Down
1 change: 1 addition & 0 deletions blocksuite/affine/block-image/src/adapters/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './html.js';
export * from './markdown.js';
export * from './middleware.js';
export * from './notion-html.js';
6 changes: 3 additions & 3 deletions blocksuite/affine/block-list/src/adapters/html.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ListBlockSchema } from '@blocksuite/affine-model';
import {
AdapterTextUtils,
BlockHtmlAdapterExtension,
type BlockHtmlAdapterMatcher,
HastUtils,
TextUtils,
} from '@blocksuite/affine-shared/adapters';
import type { DeltaInsert } from '@blocksuite/inline';
import { nanoid } from '@blocksuite/store';
Expand Down Expand Up @@ -124,7 +124,7 @@ export const listBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
Array.isArray(currentTNode.properties.className) &&
currentTNode.properties.className.includes('todo-list')
) ===
TextUtils.isNullish(
AdapterTextUtils.isNullish(
o.node.props.type === 'todo'
? (o.node.props.checked as boolean)
: undefined
Expand Down Expand Up @@ -177,7 +177,7 @@ export const listBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
Array.isArray(previousTNode.properties.className) &&
previousTNode.properties.className.includes('todo-list')
) ===
TextUtils.isNullish(
AdapterTextUtils.isNullish(
o.node.props.type === 'todo'
? (o.node.props.checked as boolean)
: undefined
Expand Down
10 changes: 5 additions & 5 deletions blocksuite/affine/block-list/src/adapters/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ListBlockSchema } from '@blocksuite/affine-model';
import {
AdapterTextUtils,
BlockMarkdownAdapterExtension,
type BlockMarkdownAdapterMatcher,
type MarkdownAST,
TextUtils,
} from '@blocksuite/affine-shared/adapters';
import type { DeltaInsert } from '@blocksuite/inline';
import { nanoid } from '@blocksuite/store';
Expand Down Expand Up @@ -75,8 +75,8 @@ export const listBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher = {
walkerContext.getNodeContext('affine:list:parent') === o.parent &&
currentTNode.type === 'list' &&
currentTNode.ordered === (o.node.props.type === 'numbered') &&
TextUtils.isNullish(currentTNode.children[0].checked) ===
TextUtils.isNullish(
AdapterTextUtils.isNullish(currentTNode.children[0].checked) ===
AdapterTextUtils.isNullish(
o.node.props.type === 'todo'
? (o.node.props.checked as boolean)
: undefined
Expand Down Expand Up @@ -129,8 +129,8 @@ export const listBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher = {
currentTNode.type === 'listItem' &&
previousTNode?.type === 'list' &&
previousTNode.ordered === (o.node.props.type === 'numbered') &&
TextUtils.isNullish(currentTNode.checked) ===
TextUtils.isNullish(
AdapterTextUtils.isNullish(currentTNode.checked) ===
AdapterTextUtils.isNullish(
o.node.props.type === 'todo'
? (o.node.props.checked as boolean)
: undefined
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/block-surface-ref/src/portal/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class SurfaceRefNotePortal extends WithDisposable(ShadowlessElement) {
query: this.query,
readonly: true,
});
const previewSpec = SpecProvider.getInstance().getSpec('page:preview');
const previewSpec = SpecProvider.getInstance().getSpec('preview:page');
return new BlockStdScope({
store: doc,
extensions: previewSpec.value.slice(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
private _previewDoc: Store | null = null;

private readonly _previewSpec =
SpecProvider.getInstance().getSpec('edgeless:preview');
SpecProvider.getInstance().getSpec('preview:edgeless');

private _referencedModel: GfxModel | null = null;

Expand Down
7 changes: 5 additions & 2 deletions blocksuite/affine/block-table/src/adapters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import type {
TableColumn,
TableRow,
} from '@blocksuite/affine-model';
import { HastUtils, TextUtils } from '@blocksuite/affine-shared/adapters';
import {
AdapterTextUtils,
HastUtils,
} from '@blocksuite/affine-shared/adapters';
import { generateFractionalIndexingKeyBetween } from '@blocksuite/affine-shared/utils';
import type { DeltaInsert } from '@blocksuite/inline';
import { nanoid } from '@blocksuite/store';
Expand Down Expand Up @@ -155,7 +158,7 @@ export const createTableProps = (rowTextLists: string[][]) => {
const cellId = `${row.rowId}:${column.columnId}`;
const text = rowTextLists[i]?.[j];
cells[cellId] = {
text: TextUtils.createText(text ?? ''),
text: AdapterTextUtils.createText(text ?? ''),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { InlineHtmlAST } from '@blocksuite/affine-shared/adapters';
import {
AdapterTextUtils,
InlineDeltaToHtmlAdapterExtension,
TextUtils,
} from '@blocksuite/affine-shared/adapters';
import { ThemeProvider } from '@blocksuite/affine-shared/services';

Expand Down Expand Up @@ -90,7 +90,7 @@ export const referenceDeltaToHtmlAdapterMatcher =

const { configs } = context;
const title = configs.get(`title:${reference.pageId}`);
const url = TextUtils.generateDocUrl(
const url = AdapterTextUtils.generateDocUrl(
configs.get('docLinkBaseUrl') ?? '',
String(reference.pageId),
reference.params ?? Object.create(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AdapterTextUtils,
FOOTNOTE_DEFINITION_PREFIX,
InlineDeltaToMarkdownAdapterExtension,
TextUtils,
} from '@blocksuite/affine-shared/adapters';
import type { PhrasingContent } from 'mdast';
import type RemarkMath from 'remark-math';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const referenceDeltaToMarkdownAdapterMatcher =
const { configs } = context;
const title = configs.get(`title:${reference.pageId}`);
const params = reference.params ?? {};
const url = TextUtils.generateDocUrl(
const url = AdapterTextUtils.generateDocUrl(
configs.get('docLinkBaseUrl') ?? '',
String(reference.pageId),
params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AdapterTextUtils,
InlineDeltaToPlainTextAdapterExtension,
type TextBuffer,
TextUtils,
} from '@blocksuite/affine-shared/adapters';
import type { ExtensionType } from '@blocksuite/store';

Expand All @@ -20,7 +20,7 @@ export const referenceDeltaMarkdownAdapterMatch =

const { configs } = context;
const title = configs.get(`title:${reference.pageId}`) ?? '';
const url = TextUtils.generateDocUrl(
const url = AdapterTextUtils.generateDocUrl(
configs.get('docLinkBaseUrl') ?? '',
String(reference.pageId),
reference.params ?? Object.create(null)
Expand Down
1 change: 0 additions & 1 deletion blocksuite/affine/fragment-frame-panel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './frame-panel';
export * from './tool';
13 changes: 13 additions & 0 deletions blocksuite/affine/model/src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import type { GfxModel } from '@blocksuite/block-std/gfx';

import type {
BrushElementModel,
ConnectorElementModel,
GroupElementModel,
} from '../elements';

export type EmbedCardStyle =
| 'horizontal'
| 'horizontalThin'
Expand All @@ -17,3 +25,8 @@ export type LinkPreviewData = {
image: string | null;
title: string | null;
};

export type Connectable = Exclude<
GfxModel,
ConnectorElementModel | BrushElementModel | GroupElementModel
>;
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
type InlineDeltaMatcher,
} from '../types/adapter.js';
import type { HtmlAST, InlineHtmlAST } from '../types/hast.js';
import { TextUtils } from '../utils/text.js';
import { AdapterTextUtils } from '../utils/text.js';

export type InlineDeltaToHtmlAdapterMatcher = InlineDeltaMatcher<InlineHtmlAST>;

Expand Down Expand Up @@ -119,7 +119,7 @@ export class HtmlDeltaConverter extends DeltaASTConverter<
options: DeltaASTConverterOptions = Object.create(null)
): DeltaInsert<AffineTextAttributes>[] {
return this._spreadAstToDelta(ast, options).reduce((acc, cur) => {
return TextUtils.mergeDeltas(acc, cur);
return AdapterTextUtils.mergeDeltas(acc, cur);
}, [] as DeltaInsert<AffineTextAttributes>[]);
}

Expand Down
Loading
Loading