mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
feat(editor): support text highlight html adapter (#9632)
[BS-2061](https://linear.app/affine-design/issue/BS-2061/html-adapter-支持-text-highlight-样式)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
createIdentifier,
|
||||
type ServiceIdentifier,
|
||||
type ServiceProvider,
|
||||
} from '@blocksuite/global/di';
|
||||
import type { DeltaInsert } from '@blocksuite/inline';
|
||||
import type { ExtensionType } from '@blocksuite/store';
|
||||
@@ -62,7 +63,8 @@ export class HtmlDeltaConverter extends DeltaASTConverter<
|
||||
constructor(
|
||||
readonly configs: Map<string, string>,
|
||||
readonly inlineDeltaMatchers: InlineDeltaToHtmlAdapterMatcher[],
|
||||
readonly htmlASTToDeltaMatchers: HtmlASTToDeltaMatcher[]
|
||||
readonly htmlASTToDeltaMatchers: HtmlASTToDeltaMatcher[],
|
||||
readonly provider: ServiceProvider
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -84,7 +86,7 @@ export class HtmlDeltaConverter extends DeltaASTConverter<
|
||||
};
|
||||
for (const matcher of this.inlineDeltaMatchers) {
|
||||
if (matcher.match(delta)) {
|
||||
hast = matcher.toAST(delta, context);
|
||||
hast = matcher.toAST(delta, context, this.provider);
|
||||
context.current = hast;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
|
||||
configs: this.configs,
|
||||
job: this.job,
|
||||
deltaConverter: this.deltaConverter,
|
||||
provider: this.provider,
|
||||
textBuffer: { content: '' },
|
||||
assets,
|
||||
updateAssetIds: (assetsId: string) => {
|
||||
@@ -155,6 +156,7 @@ export class HtmlAdapter extends BaseAdapter<Html> {
|
||||
configs: this.configs,
|
||||
job: this.job,
|
||||
deltaConverter: this.deltaConverter,
|
||||
provider: this.provider,
|
||||
textBuffer: { content: '' },
|
||||
assets,
|
||||
};
|
||||
@@ -172,7 +174,10 @@ export class HtmlAdapter extends BaseAdapter<Html> {
|
||||
|
||||
readonly blockMatchers: BlockHtmlAdapterMatcher[];
|
||||
|
||||
constructor(job: Transformer, provider: ServiceProvider) {
|
||||
constructor(
|
||||
job: Transformer,
|
||||
readonly provider: ServiceProvider
|
||||
) {
|
||||
super(job);
|
||||
const blockMatchers = Array.from(
|
||||
provider.getAll(BlockHtmlAdapterMatcherIdentifier).values()
|
||||
@@ -187,7 +192,8 @@ export class HtmlAdapter extends BaseAdapter<Html> {
|
||||
this.deltaConverter = new HtmlDeltaConverter(
|
||||
job.adapterConfigs,
|
||||
inlineDeltaToHtmlAdapterMatchers,
|
||||
htmlInlineToDeltaMatchers
|
||||
htmlInlineToDeltaMatchers,
|
||||
provider
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,8 @@ export type InlineDeltaMatcher<TNode extends object = never> = {
|
||||
context: {
|
||||
configs: Map<string, string>;
|
||||
current: TNode;
|
||||
}
|
||||
},
|
||||
provider?: ServiceProvider
|
||||
) => TNode;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { ReferenceParams } from '@blocksuite/affine-model';
|
||||
import { isEqual } from '@blocksuite/global/utils';
|
||||
import type { DeltaInsert } from '@blocksuite/inline';
|
||||
|
||||
@@ -74,10 +75,22 @@ function toURLSearchParams(
|
||||
);
|
||||
}
|
||||
|
||||
function generateDocUrl(
|
||||
docBaseUrl: string,
|
||||
pageId: string,
|
||||
params: ReferenceParams
|
||||
) {
|
||||
const search = toURLSearchParams(params);
|
||||
const query = search?.size ? `?${search.toString()}` : '';
|
||||
const url = docBaseUrl ? `${docBaseUrl}/${pageId}${query}` : '';
|
||||
return url;
|
||||
}
|
||||
|
||||
export const TextUtils = {
|
||||
mergeDeltas,
|
||||
isNullish,
|
||||
createText,
|
||||
isText,
|
||||
toURLSearchParams,
|
||||
generateDocUrl,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user