feat: bump blocksuite (#5812)

This commit is contained in:
Flrande
2024-02-08 08:18:03 +08:00
committed by GitHub
parent a84a91d896
commit 2e3ffeced9
14 changed files with 161 additions and 158 deletions

View File

@@ -111,7 +111,6 @@ const getOrCreateShellWorkspace = (workspaceId: string) => {
const blobStorage = new AffineCloudBlobStorage(workspaceId);
workspace = new Workspace({
id: workspaceId,
providerCreators: [],
blobStorages: [
() => ({
crud: blobStorage,

View File

@@ -48,7 +48,7 @@ interface BlocksuiteEditorContainerProps {
// mimic the interface of the webcomponent and expose slots & host
type BlocksuiteEditorContainerRef = Pick<
(typeof AffineEditorContainer)['prototype'],
'mode' | 'page' | 'model' | 'slots' | 'host'
'mode' | 'page' | 'slots' | 'host'
> &
HTMLDivElement;

View File

@@ -37,24 +37,14 @@ export type EditorProps = {
className?: string;
};
/**
* TODO: Defined async cache to support suspense, instead of reflect symbol to provider persistent error cache.
*/
const PAGE_LOAD_KEY = Symbol('PAGE_LOAD');
const PAGE_ROOT_KEY = Symbol('PAGE_ROOT');
function usePageRoot(page: Page) {
let load$ = Reflect.get(page, PAGE_LOAD_KEY);
if (!load$) {
load$ = page.load();
Reflect.set(page, PAGE_LOAD_KEY, load$);
if (!page.ready) {
use(page.load());
}
use(load$);
if (!page.root) {
let root$: Promise<void> | undefined = Reflect.get(page, PAGE_ROOT_KEY);
if (!root$) {
root$ = new Promise((resolve, reject) => {
use(
new Promise<void>((resolve, reject) => {
const disposable = page.slots.rootAdded.once(() => {
resolve();
});
@@ -62,10 +52,8 @@ function usePageRoot(page: Page) {
disposable.dispose();
reject(new NoPageRootError(page));
}, 20 * 1000);
});
Reflect.set(page, PAGE_ROOT_KEY, root$);
}
use(root$);
})
);
}
return page.root;

View File

@@ -1,10 +1,12 @@
import type { BlockServiceOptions, BlockSpec } from '@blocksuite/block-std';
import type { ParagraphService } from '@blocksuite/blocks';
import type { BlockSpec } from '@blocksuite/block-std';
import type { PageService, ParagraphService } from '@blocksuite/blocks';
import {
AttachmentService,
CanvasTextFonts,
DocEditorBlockSpecs,
DocPageService,
EdgelessEditorBlockSpecs,
PageService,
EdgelessPageService,
} from '@blocksuite/blocks';
import bytes from 'bytes';
import { html, unsafeStatic } from 'lit/static-html.js';
@@ -18,23 +20,28 @@ class CustomAttachmentService extends AttachmentService {
}
}
class CustomPageService extends PageService {
constructor(opt: BlockServiceOptions) {
super(opt);
const officialDomains = new Set(['affine.pro', 'affine.fail']);
const load = this.fontLoader.load.bind(this.fontLoader);
this.fontLoader.load = function (fonts) {
if (!officialDomains.has(window.location.host)) {
return load(
fonts.map(f => ({
...f,
// self-hosted fonts are served from /assets
url: '/assets' + new URL(f.url).pathname.split('/').pop(),
}))
);
}
return load(fonts);
};
function customLoadFonts(service: PageService): void {
const officialDomains = new Set(['affine.pro', 'affine.fail']);
if (!officialDomains.has(window.location.host)) {
const fonts = CanvasTextFonts.map(font => ({
...font,
// self-hosted fonts are served from /assets
url: '/assets' + new URL(font.url).pathname.split('/').pop(),
}));
service.fontLoader.load(fonts);
} else {
service.fontLoader.load(CanvasTextFonts);
}
}
class CustomDocPageService extends DocPageService {
override loadFonts(): void {
customLoadFonts(this);
}
}
class CustomEdgelessPageService extends EdgelessPageService {
override loadFonts(): void {
customLoadFonts(this);
}
}
@@ -100,7 +107,7 @@ export const docModeSpecs = DocEditorBlockSpecs.map(spec => {
if (spec.schema.model.flavour === 'affine:page') {
return {
...spec,
service: CustomPageService,
service: CustomDocPageService,
};
}
return spec;
@@ -112,5 +119,11 @@ export const edgelessModeSpecs = EdgelessEditorBlockSpecs.map(spec => {
service: CustomAttachmentService,
};
}
if (spec.schema.model.flavour === 'affine:page') {
return {
...spec,
service: CustomEdgelessPageService,
};
}
return spec;
});