Files
AFFiNE-Mirror/blocksuite/affine/blocks/paragraph/src/view.ts
Saul-Mirone 4ebeb530e0 refactor(editor): config the extension provider directly (#12252)
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **New Features**
	- Added new export paths to improve module accessibility for foundation store and view components.
	- Introduced new extension points for telemetry, font configuration, link preview cache, and peek view services in the view extension foundation.

- **Improvements**
	- Enhanced flexibility by allowing optional configuration of placeholders in paragraph view extensions.
	- Switched to runtime schema validation for font configuration, increasing reliability.
	- Streamlined service registration for peek view providers.

- **Refactor**
	- Centralized and simplified extension management by removing redundant extension files and consolidating setup logic.
	- Updated internal integration of telemetry, font, and peek view services for improved maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-13 11:09:21 +00:00

67 lines
1.6 KiB
TypeScript

import {
type ViewExtensionContext,
ViewExtensionProvider,
} from '@blocksuite/affine-ext-loader';
import { BlockViewExtension, FlavourExtension } from '@blocksuite/std';
import { literal } from 'lit/static-html.js';
import { ParagraphBlockConfigExtension } from './paragraph-block-config.js';
import {
ParagraphKeymapExtension,
ParagraphTextKeymapExtension,
} from './paragraph-keymap.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: '',
};
import { ParagraphBlockModel } from '@blocksuite/affine-model';
import { z } from 'zod';
import { effects } from './effects';
const optionsSchema = z.object({
getPlaceholder: z.optional(
z.function().args(z.instanceof(ParagraphBlockModel)).returns(z.string())
),
});
export class ParagraphViewExtension extends ViewExtensionProvider<
z.infer<typeof optionsSchema>
> {
override name = 'affine-paragraph-block';
override schema = optionsSchema;
override effect(): void {
super.effect();
effects();
}
override setup(
context: ViewExtensionContext,
options?: z.infer<typeof optionsSchema>
) {
super.setup(context, options);
const getPlaceholder =
options?.getPlaceholder ?? (model => placeholders[model.props.type]);
context.register([
FlavourExtension('affine:paragraph'),
BlockViewExtension('affine:paragraph', literal`affine-paragraph`),
ParagraphTextKeymapExtension,
ParagraphKeymapExtension,
ParagraphBlockConfigExtension({
getPlaceholder,
}),
]);
}
}