mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(editor): remove paragraph service (#11003)
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import { LifeCycleWatcher } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
ParagraphBlockService,
|
||||
ParagraphBlockConfigExtension,
|
||||
ParagraphBlockSpec,
|
||||
} from '@blocksuite/affine/blocks/paragraph';
|
||||
import type { ExtensionType } from '@blocksuite/affine/store';
|
||||
|
||||
class AIParagraphBlockWatcher extends LifeCycleWatcher {
|
||||
static override key = 'ai-paragraph-block-watcher';
|
||||
|
||||
override mounted() {
|
||||
super.mounted();
|
||||
const service = this.std.get(ParagraphBlockService);
|
||||
service.placeholderGenerator = model => {
|
||||
if (model.props.type === 'text') {
|
||||
return "Type '/' for commands, 'space' for AI";
|
||||
}
|
||||
|
||||
export const AIParagraphBlockSpec: ExtensionType[] = [
|
||||
...ParagraphBlockSpec,
|
||||
ParagraphBlockConfigExtension({
|
||||
getPlaceholder: model => {
|
||||
const placeholders = {
|
||||
text: "Type '/' for commands, 'space' for AI",
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
@@ -26,11 +19,6 @@ class AIParagraphBlockWatcher extends LifeCycleWatcher {
|
||||
quote: '',
|
||||
};
|
||||
return placeholders[model.props.type];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const AIParagraphBlockSpec: ExtensionType[] = [
|
||||
...ParagraphBlockSpec,
|
||||
AIParagraphBlockWatcher,
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import type { CodeBlockConfig } from '@blocksuite/affine/blocks/code';
|
||||
import { codeToolbarWidget } from '@blocksuite/affine/blocks/code';
|
||||
import { imageToolbarWidget } from '@blocksuite/affine/blocks/image';
|
||||
import { ParagraphBlockService } from '@blocksuite/affine/blocks/paragraph';
|
||||
import { ParagraphBlockConfigExtension } from '@blocksuite/affine/blocks/paragraph';
|
||||
import { surfaceRefToolbarWidget } from '@blocksuite/affine/blocks/surface-ref';
|
||||
import type {
|
||||
Container,
|
||||
@@ -68,30 +68,24 @@ class MobileSpecsPatches extends LifeCycleWatcher {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
override mounted() {
|
||||
// remove slash placeholder for mobile: `type / ...`
|
||||
{
|
||||
const paragraphService = this.std.get(ParagraphBlockService);
|
||||
if (!paragraphService) return;
|
||||
|
||||
paragraphService.placeholderGenerator = model => {
|
||||
const placeholders = {
|
||||
text: '',
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
h4: 'Heading 4',
|
||||
h5: 'Heading 5',
|
||||
h6: 'Heading 6',
|
||||
quote: '',
|
||||
};
|
||||
return placeholders[model.props.type];
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const mobileParagraphConfig = ParagraphBlockConfigExtension({
|
||||
getPlaceholder: model => {
|
||||
const placeholders = {
|
||||
text: '',
|
||||
h1: 'Heading 1',
|
||||
h2: 'Heading 2',
|
||||
h3: 'Heading 3',
|
||||
h4: 'Heading 4',
|
||||
h5: 'Heading 5',
|
||||
h6: 'Heading 6',
|
||||
quote: '',
|
||||
};
|
||||
return placeholders[model.props.type];
|
||||
},
|
||||
});
|
||||
|
||||
function KeyboardToolbarExtension(framework: FrameworkProvider): ExtensionType {
|
||||
const affineVirtualKeyboardProvider = framework.get(VirtualKeyboardProvider);
|
||||
|
||||
@@ -171,5 +165,9 @@ export function enableMobileExtension(
|
||||
specBuilder.omit(surfaceRefToolbarWidget);
|
||||
specBuilder.omit(toolbarWidget);
|
||||
specBuilder.omit(SlashMenuExtension);
|
||||
specBuilder.extend([MobileSpecsPatches, KeyboardToolbarExtension(framework)]);
|
||||
specBuilder.extend([
|
||||
MobileSpecsPatches,
|
||||
KeyboardToolbarExtension(framework),
|
||||
mobileParagraphConfig,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user