refactor(editor): remove paragraph service (#11003)

This commit is contained in:
Saul-Mirone
2025-03-19 13:38:09 +00:00
parent 9a697dc9bb
commit c1e16aeaa7
8 changed files with 67 additions and 80 deletions

View File

@@ -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,
},
}),
];

View File

@@ -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,
]);
}