mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
fix(editor): worker loading in webpack env (#10832)
### TL;DR Created dedicated worker entry points to avoid dynamic imports. ### What changed? - Painters are provided during worker initialization - Removed `ParagraphPaintConfigExtension` and the associated configuration system - Created dedicated worker entry points in both the integration test and frontend packages - Modified `ViewportLayoutPainter` to accept painters in its constructor - Updated the `TurboRendererConfig` interface to require a `painterWorkerEntry` function ### Why make this change? Webpack support. Extension objects in main thread are not available to be passed into workers. Dynamic painter path import is hard to support in webpack environment. With the [webpack-ignore](https://webpack.js.org/api/module-methods/#webpackignore) rule, there are still build errors in webpack.
This commit is contained in:
@@ -4,4 +4,4 @@ export * from './paragraph-block.js';
|
||||
export * from './paragraph-service.js';
|
||||
export * from './paragraph-spec.js';
|
||||
export * from './turbo/paragraph-layout-provider.js';
|
||||
export * from './turbo/paragraph-painter-config.js';
|
||||
export * from './turbo/paragraph-painter.worker.js';
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import { BlockPainterConfigIdentifier } from '@blocksuite/affine-gfx-turbo-renderer';
|
||||
import type { Container } from '@blocksuite/global/di';
|
||||
import { Extension } from '@blocksuite/store';
|
||||
|
||||
export class ParagraphPaintConfigExtension extends Extension {
|
||||
static override setup(di: Container) {
|
||||
const config = {
|
||||
type: 'affine:paragraph',
|
||||
path: new URL(
|
||||
'@blocksuite/affine-block-paragraph/turbo-painter',
|
||||
import.meta.url
|
||||
).href,
|
||||
};
|
||||
di.addImpl(BlockPainterConfigIdentifier, config);
|
||||
}
|
||||
}
|
||||
@@ -39,16 +39,23 @@ function isParagraphLayout(layout: BlockLayout): layout is ParagraphLayout {
|
||||
return layout.type === 'affine:paragraph';
|
||||
}
|
||||
|
||||
export default class ParagraphLayoutPainter implements BlockLayoutPainter {
|
||||
static readonly font = new FontFace(
|
||||
'Inter',
|
||||
`url(https://fonts.gstatic.com/s/inter/v18/UcCo3FwrK3iLTcviYwYZ8UA3.woff2)`
|
||||
);
|
||||
export class ParagraphLayoutPainter implements BlockLayoutPainter {
|
||||
private static readonly supportFontFace =
|
||||
typeof FontFace !== 'undefined' &&
|
||||
typeof self !== 'undefined' &&
|
||||
'fonts' in self;
|
||||
|
||||
static fontLoaded = false;
|
||||
static readonly font = ParagraphLayoutPainter.supportFontFace
|
||||
? new FontFace(
|
||||
'Inter',
|
||||
`url(https://fonts.gstatic.com/s/inter/v18/UcCo3FwrK3iLTcviYwYZ8UA3.woff2)`
|
||||
)
|
||||
: null;
|
||||
|
||||
static fontLoaded = !ParagraphLayoutPainter.supportFontFace;
|
||||
|
||||
static {
|
||||
if (typeof self !== 'undefined' && 'fonts' in self) {
|
||||
if (ParagraphLayoutPainter.supportFontFace && ParagraphLayoutPainter.font) {
|
||||
// @ts-expect-error worker fonts API
|
||||
self.fonts.add(ParagraphLayoutPainter.font);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user