mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
refactor(editor): remove paragraph service (#11003)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export * from './adapters/index.js';
|
||||
export * from './commands';
|
||||
export * from './paragraph-block.js';
|
||||
export * from './paragraph-service.js';
|
||||
export * from './paragraph-block-config.js';
|
||||
export * from './paragraph-spec.js';
|
||||
export * from './turbo/paragraph-layout-provider.js';
|
||||
export * from './turbo/paragraph-painter.worker.js';
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { ParagraphBlockModel } from '@blocksuite/affine-model';
|
||||
import { ConfigExtensionFactory } from '@blocksuite/block-std';
|
||||
|
||||
export interface ParagraphBlockConfig {
|
||||
getPlaceholder: (model: ParagraphBlockModel) => string;
|
||||
}
|
||||
|
||||
export const ParagraphBlockConfigExtension =
|
||||
ConfigExtensionFactory<ParagraphBlockConfig>('affine:paragraph');
|
||||
@@ -25,13 +25,10 @@ import { classMap } from 'lit/directives/class-map.js';
|
||||
import { styleMap } from 'lit/directives/style-map.js';
|
||||
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
|
||||
|
||||
import type { ParagraphBlockService } from './paragraph-service.js';
|
||||
import { ParagraphBlockConfigExtension } from './paragraph-block-config.js';
|
||||
import { paragraphBlockStyles } from './styles.js';
|
||||
|
||||
export class ParagraphBlockComponent extends CaptionedBlockComponent<
|
||||
ParagraphBlockModel,
|
||||
ParagraphBlockService
|
||||
> {
|
||||
export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBlockModel> {
|
||||
static override styles = paragraphBlockStyles;
|
||||
|
||||
focused$ = computed(() => {
|
||||
@@ -59,6 +56,12 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<
|
||||
return false;
|
||||
};
|
||||
|
||||
private get _placeholder() {
|
||||
return this.std
|
||||
.get(ParagraphBlockConfigExtension.identifier)
|
||||
?.getPlaceholder(this.model);
|
||||
}
|
||||
|
||||
get attributeRenderer() {
|
||||
return this.inlineManager.getRenderer();
|
||||
}
|
||||
@@ -309,7 +312,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<
|
||||
visible: this._displayPlaceholder.value,
|
||||
})}
|
||||
>
|
||||
${this.service.placeholderGenerator(this.model)}
|
||||
${this._placeholder}
|
||||
</div>
|
||||
`}
|
||||
</div>
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import {
|
||||
type ParagraphBlockModel,
|
||||
ParagraphBlockSchema,
|
||||
} from '@blocksuite/affine-model';
|
||||
import { BlockService } from '@blocksuite/block-std';
|
||||
|
||||
export class ParagraphBlockService extends BlockService {
|
||||
static override readonly flavour = ParagraphBlockSchema.model.flavour;
|
||||
|
||||
placeholderGenerator: (model: ParagraphBlockModel) => string = model => {
|
||||
if (model.props.type === 'text') {
|
||||
return "Type '/' for commands";
|
||||
}
|
||||
|
||||
const placeholders = {
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
h4: 'Heading 4',
|
||||
h5: 'Heading 5',
|
||||
h6: 'Heading 6',
|
||||
quote: '',
|
||||
};
|
||||
return placeholders[model.props.type];
|
||||
};
|
||||
}
|
||||
@@ -3,17 +3,32 @@ import type { ExtensionType } from '@blocksuite/store';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
|
||||
import { ParagraphBlockAdapterExtensions } from './adapters/extension.js';
|
||||
import { ParagraphBlockConfigExtension } from './paragraph-block-config.js';
|
||||
import {
|
||||
ParagraphKeymapExtension,
|
||||
ParagraphTextKeymapExtension,
|
||||
} from './paragraph-keymap.js';
|
||||
import { ParagraphBlockService } from './paragraph-service.js';
|
||||
|
||||
const placeholders = {
|
||||
text: "Type '/' for commands",
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
h4: 'Heading 4',
|
||||
h5: 'Heading 5',
|
||||
h6: 'Heading 6',
|
||||
quote: '',
|
||||
};
|
||||
|
||||
export const ParagraphBlockSpec: ExtensionType[] = [
|
||||
FlavourExtension('affine:paragraph'),
|
||||
ParagraphBlockService,
|
||||
BlockViewExtension('affine:paragraph', literal`affine-paragraph`),
|
||||
ParagraphTextKeymapExtension,
|
||||
ParagraphKeymapExtension,
|
||||
ParagraphBlockAdapterExtensions,
|
||||
ParagraphBlockConfigExtension({
|
||||
getPlaceholder: model => {
|
||||
return placeholders[model.props.type];
|
||||
},
|
||||
}),
|
||||
].flat();
|
||||
|
||||
@@ -32,7 +32,7 @@ export function ConfigExtensionFactory<Config extends Record<string, any>>(
|
||||
const identifier = ConfigIdentifier(flavor) as ServiceIdentifier<Config>;
|
||||
const extensionFactory = (config: Config): ExtensionType => ({
|
||||
setup: di => {
|
||||
di.addImpl(ConfigIdentifier(flavor), () => config);
|
||||
di.override(ConfigIdentifier(flavor), () => config);
|
||||
},
|
||||
});
|
||||
extensionFactory.identifier = identifier;
|
||||
|
||||
Reference in New Issue
Block a user