mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 19:02:23 +08:00
17
blocksuite/affine/blocks/paragraph/src/store.ts
Normal file
17
blocksuite/affine/blocks/paragraph/src/store.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import {
|
||||
type StoreExtensionContext,
|
||||
StoreExtensionProvider,
|
||||
} from '@blocksuite/affine-ext-loader';
|
||||
import { ParagraphBlockSchemaExtension } from '@blocksuite/affine-model';
|
||||
|
||||
import { ParagraphBlockAdapterExtensions } from './adapters/extension';
|
||||
|
||||
export class ParagraphStoreExtension extends StoreExtensionProvider {
|
||||
override name = 'affine-paragraph-block';
|
||||
|
||||
override setup(context: StoreExtensionContext) {
|
||||
super.setup(context);
|
||||
context.register(ParagraphBlockSchemaExtension);
|
||||
context.register(ParagraphBlockAdapterExtensions);
|
||||
}
|
||||
}
|
||||
67
blocksuite/affine/blocks/paragraph/src/view.ts
Normal file
67
blocksuite/affine/blocks/paragraph/src/view.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
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
|
||||
.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);
|
||||
const getPlaceholder =
|
||||
options?.getPlaceholder ?? (model => placeholders[model.props.type]);
|
||||
|
||||
context.register([
|
||||
FlavourExtension('affine:paragraph'),
|
||||
BlockViewExtension('affine:paragraph', literal`affine-paragraph`),
|
||||
ParagraphTextKeymapExtension,
|
||||
ParagraphKeymapExtension,
|
||||
ParagraphBlockConfigExtension({
|
||||
getPlaceholder,
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user