mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-30 00:29:46 +08:00
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
type StoreExtensionContext,
|
||||
StoreExtensionProvider,
|
||||
} from '@blocksuite/affine-ext-loader';
|
||||
import { NoteBlockSchemaExtension } from '@blocksuite/affine-model';
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
DocNoteBlockAdapterExtensions,
|
||||
EdgelessNoteBlockAdapterExtensions,
|
||||
} from './adapters';
|
||||
|
||||
const optionsSchema = z.object({
|
||||
mode: z.enum(['doc', 'edgeless']).optional(),
|
||||
});
|
||||
|
||||
export class NoteStoreExtension extends StoreExtensionProvider<
|
||||
z.infer<typeof optionsSchema>
|
||||
> {
|
||||
override name = 'affine-note-block';
|
||||
|
||||
override schema = optionsSchema;
|
||||
|
||||
override setup(
|
||||
context: StoreExtensionContext,
|
||||
options?: z.infer<typeof optionsSchema>
|
||||
) {
|
||||
super.setup(context);
|
||||
context.register(NoteBlockSchemaExtension);
|
||||
if (options?.mode === 'edgeless') {
|
||||
context.register(EdgelessNoteBlockAdapterExtensions);
|
||||
} else {
|
||||
context.register(DocNoteBlockAdapterExtensions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
type ViewExtensionContext,
|
||||
ViewExtensionProvider,
|
||||
} from '@blocksuite/affine-ext-loader';
|
||||
import { NoteBlockSchema } from '@blocksuite/affine-model';
|
||||
import { BlockViewExtension, FlavourExtension } from '@blocksuite/std';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
|
||||
import { NoteSlashMenuConfigExtension } from './configs/slash-menu';
|
||||
import { createBuiltinToolbarConfigExtension } from './configs/toolbar';
|
||||
import { effects } from './effects';
|
||||
import { NoteKeymapExtension } from './note-keymap';
|
||||
|
||||
const flavour = NoteBlockSchema.model.flavour;
|
||||
|
||||
export class NoteViewExtension extends ViewExtensionProvider {
|
||||
override name = 'affine-note-block';
|
||||
|
||||
override effect() {
|
||||
super.effect();
|
||||
effects();
|
||||
}
|
||||
|
||||
override setup(context: ViewExtensionContext) {
|
||||
super.setup(context);
|
||||
context.register([
|
||||
FlavourExtension(flavour),
|
||||
NoteSlashMenuConfigExtension,
|
||||
NoteKeymapExtension,
|
||||
]);
|
||||
|
||||
const scope = context.scope;
|
||||
const isEdgeless =
|
||||
scope === 'edgeless' ||
|
||||
scope === 'preview-edgeless' ||
|
||||
scope === 'mobile-edgeless';
|
||||
|
||||
if (isEdgeless) {
|
||||
context.register(
|
||||
BlockViewExtension(flavour, literal`affine-edgeless-note`)
|
||||
);
|
||||
context.register(createBuiltinToolbarConfigExtension(flavour));
|
||||
} else {
|
||||
context.register(BlockViewExtension(flavour, literal`affine-note`));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user