Skip to content

Commit

Permalink
fix: color of canvas element under embed dark theme whiteboard is wro…
Browse files Browse the repository at this point in the history
  • Loading branch information
akumatus committed Nov 6, 2024
1 parent 65baeb5 commit 5dc58a6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
20 changes: 9 additions & 11 deletions packages/affine/shared/src/services/theme-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@toeverything/theme';
import { unsafeCSS } from 'lit';

import { DocModeProvider, type DocModeService } from './doc-mode-service.js';
import { isInsideEdgelessEditor } from '../utils/index.js';

const TRANSPARENT = 'transparent';

Expand Down Expand Up @@ -53,28 +53,26 @@ export class ThemeService extends Extension {
}

get theme() {
return this.docMode.getEditorMode() === 'page'
? this.appTheme
: this.edgelessTheme;
return isInsideEdgelessEditor(this.std.host)
? this.edgelessTheme
: this.appTheme;
}

get theme$() {
return this.docMode.getEditorMode() === 'page' ? this.app$ : this.edgeless$;
return isInsideEdgelessEditor(this.std.host) ? this.edgeless$ : this.app$;
}

constructor(
private std: BlockStdScope,
private docMode: DocModeService
) {
constructor(private std: BlockStdScope) {
super();
const extension = this.std.getOptional(ThemeExtensionIdentifier);
this.app$ = extension?.getAppTheme?.() || getThemeObserver().theme$;
this.edgeless$ =
extension?.getEdgelessTheme?.() || getThemeObserver().theme$;
extension?.getEdgelessTheme?.(this.std.doc.id) ||
getThemeObserver().theme$;
}

static override setup(di: Container) {
di.addImpl(ThemeProvider, ThemeService, [StdIdentifier, DocModeProvider]);
di.addImpl(ThemeProvider, ThemeService, [StdIdentifier]);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/affine/shared/src/utils/dom/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export function isInsidePageEditor(host: EditorHost) {

export function isInsideEdgelessEditor(host: EditorHost) {
return Array.from(host.children).some(
v => v.tagName.toLowerCase() === 'affine-edgeless-root'
v =>
v.tagName.toLowerCase() === 'affine-edgeless-root' ||
v.tagName.toLowerCase() === 'affine-edgeless-root-preview'
);
}
13 changes: 13 additions & 0 deletions packages/affine/shared/src/utils/spec/spec-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,17 @@ export class SpecProvider {
hasSpec(id: string) {
return this.specMap.has(id);
}

omitSpec(id: string, targetSpec: ExtensionType) {
const existingSpec = this.specMap.get(id);
if (!existingSpec) {
console.error(`Spec not found for ${id}`);
return;
}

this.specMap.set(
id,
existingSpec.filter(spec => spec !== targetSpec)
);
}
}
5 changes: 4 additions & 1 deletion packages/playground/apps/default/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ParseDocUrlExtension,
RefNodeSlotsExtension,
RefNodeSlotsProvider,
SpecProvider,
} from '@blocksuite/blocks';
import { assertExists } from '@blocksuite/global/utils';
import { AffineEditorContainer } from '@blocksuite/presets';
Expand Down Expand Up @@ -63,6 +64,9 @@ export async function mountDefaultDocEditor(collection: DocCollection) {
refNodeSlotsExtension,
...specs.edgelessModeSpecs,
]);
SpecProvider.getInstance().extendSpec('edgeless:preview', [
OverrideThemeExtension(themeExtension),
]);
editor.doc = doc;
editor.mode = 'page';
editor.std
Expand Down Expand Up @@ -130,7 +134,6 @@ export async function mountDefaultDocEditor(collection: DocCollection) {
FontConfigExtension(CommunityCanvasTextFonts),
mockPeekViewExtension(attachmentViewerPanel),
];

return newSpec;
}
}
4 changes: 4 additions & 0 deletions packages/playground/apps/starter/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export async function mountDefaultDocEditor(collection: DocCollection) {
edgelessSpecs.extend([...extensions]);
editor.edgelessSpecs = edgelessSpecs.value;

SpecProvider.getInstance().extendSpec('edgeless:preview', [
OverrideThemeExtension(themeExtension),
]);

editor.mode = 'page';
editor.doc = doc;
editor.std
Expand Down

0 comments on commit 5dc58a6

Please sign in to comment.