refactor(editor): remove code block service (#11010)

This commit is contained in:
Saul-Mirone
2025-03-19 13:38:10 +00:00
parent 1c6a876e6a
commit ee65d66d67
5 changed files with 55 additions and 53 deletions
@@ -26,18 +26,15 @@ import { computed, effect, type Signal, signal } from '@preact/signals-core';
import { html, nothing, type TemplateResult } from 'lit';
import { query } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import type { ThemedToken } from 'shiki';
import { bundledLanguagesInfo, type ThemedToken } from 'shiki';
import { CodeClipboardController } from './clipboard/index.js';
import { CodeBlockConfigExtension } from './code-block-config.js';
import { CodeBlockInlineManagerExtension } from './code-block-inline.js';
import type { CodeBlockService } from './code-block-service.js';
import { CodeBlockHighlighter } from './code-block-service.js';
import { codeBlockStyles } from './styles.js';
export class CodeBlockComponent extends CaptionedBlockComponent<
CodeBlockModel,
CodeBlockService
> {
export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel> {
static override styles = codeBlockStyles;
private _inlineRangeProvider: InlineRangeProvider | null = null;
@@ -52,7 +49,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
return 'Plain Text';
}
const matchedInfo = this.service.langs.find(info => info.id === lang);
const matchedInfo = this.langs.find(info => info.id === lang);
return matchedInfo ? matchedInfo.name : 'Plain Text';
});
@@ -75,6 +72,17 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
return this.doc.readonly;
}
get langs() {
return (
this.std.getOptional(CodeBlockConfigExtension.identifier)?.langs ??
bundledLanguagesInfo
);
}
get highlighter() {
return this.std.get(CodeBlockHighlighter);
}
override get topContenteditableElement() {
if (this.std.get(DocModeProvider).getEditorMode() === 'edgeless') {
return this.closest<BlockComponent>(NOTE_SELECTOR);
@@ -89,7 +97,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
return;
}
const matchedInfo = this.service.langs.find(
const matchedInfo = this.langs.find(
info =>
info.id === modelLang ||
info.name === modelLang ||
@@ -101,8 +109,8 @@ export class CodeBlockComponent extends CaptionedBlockComponent<
const langImport = matchedInfo.import;
const lang = matchedInfo.id;
const highlighter = this.service.highlighter$.value;
const theme = this.service.themeKey;
const highlighter = this.highlighter.highlighter$.value;
const theme = this.highlighter.themeKey;
if (!theme || !highlighter) {
this.highlightTokens$.value = [];
return;