mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
fix: load snapshot files in parallel (#8145)
This commit is contained in:
@@ -27,20 +27,49 @@ export type DocName =
|
|||||||
|
|
||||||
const docMap = new Map<DocName, Promise<Doc | undefined>>();
|
const docMap = new Map<DocName, Promise<Doc | undefined>>();
|
||||||
|
|
||||||
|
async function loadNote() {
|
||||||
|
return (await import('./note.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPen() {
|
||||||
|
return (await import('./pen.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadShape() {
|
||||||
|
return (await import('./shape.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadFlow() {
|
||||||
|
return (await import('./flow.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadText() {
|
||||||
|
return (await import('./text.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadConnector() {
|
||||||
|
return (await import('./connector.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadMindmap() {
|
||||||
|
return (await import('./mindmap.json')).default;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loaders = {
|
||||||
|
note: loadNote,
|
||||||
|
pen: loadPen,
|
||||||
|
shape: loadShape,
|
||||||
|
flow: loadFlow,
|
||||||
|
text: loadText,
|
||||||
|
connector: loadConnector,
|
||||||
|
mindmap: loadMindmap,
|
||||||
|
};
|
||||||
|
|
||||||
export async function getDocByName(name: DocName) {
|
export async function getDocByName(name: DocName) {
|
||||||
const rawData: Record<DocName, any> = {
|
|
||||||
note: (await import('./note.json')).default,
|
|
||||||
pen: (await import('./pen.json')).default,
|
|
||||||
shape: (await import('./shape.json')).default,
|
|
||||||
flow: (await import('./flow.json')).default,
|
|
||||||
text: (await import('./text.json')).default,
|
|
||||||
connector: (await import('./connector.json')).default,
|
|
||||||
mindmap: (await import('./mindmap.json')).default,
|
|
||||||
};
|
|
||||||
if (docMap.get(name)) {
|
if (docMap.get(name)) {
|
||||||
return docMap.get(name);
|
return docMap.get(name);
|
||||||
}
|
}
|
||||||
const snapshot = rawData[name] as DocSnapshot;
|
const snapshot = (await loaders[name]()) as DocSnapshot;
|
||||||
const promiseDoc = initDocFromSnapshot(snapshot);
|
const promiseDoc = initDocFromSnapshot(snapshot);
|
||||||
docMap.set(name, promiseDoc);
|
docMap.set(name, promiseDoc);
|
||||||
return promiseDoc;
|
return promiseDoc;
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"type": "page",
|
"type": "page",
|
||||||
"meta": {
|
"meta": {
|
||||||
"id": "H26C3mrHAO",
|
"id": "UpLwaWKe8S9s8krsxi3A8",
|
||||||
"title": "BlockSuite Playground",
|
"title": "BlockSuite Playground",
|
||||||
"createDate": 1725457623442,
|
"createDate": 1725435317986,
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"blocks": {
|
"blocks": {
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "gMFM1yrveo",
|
"id": "mUEhyeRfVdzFKHV3w897g",
|
||||||
"flavour": "affine:page",
|
"flavour": "affine:page",
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "ICj50zYaZ-",
|
"id": "oc5oq3DFWcqVjzyevWrx6",
|
||||||
"flavour": "affine:surface",
|
"flavour": "affine:surface",
|
||||||
"version": 5,
|
"version": 5,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"textResizing": 1,
|
"textResizing": 1,
|
||||||
"xywh": "[-14.79056021743071,154.8369594850144,100.11936661988601,100.11932857954827]",
|
"xywh": "[190.275413673033,378.1994245551321,100.11936661988601,100.11932857954827]",
|
||||||
"type": "shape",
|
"type": "shape",
|
||||||
"id": "e6t9tKz8Sy"
|
"id": "e6t9tKz8Sy"
|
||||||
},
|
},
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"textResizing": 1,
|
"textResizing": 1,
|
||||||
"xywh": "[145.85713815180185,171.45701762455542,131.14345570418993,66.87921230046624]",
|
"xywh": "[717.3900484965246,378.29923435003775,100.25918467911882,99.76145851000166]",
|
||||||
"type": "shape",
|
"type": "shape",
|
||||||
"id": "F8qB_zDC5Q"
|
"id": "F8qB_zDC5Q"
|
||||||
},
|
},
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"textResizing": 1,
|
"textResizing": 1,
|
||||||
"xywh": "[337.5289256053383,154.8369594850144,105.1083470248982,101.65945505340866]",
|
"xywh": "[364.3172984791928,376.3029173497159,105.1083470248982,104.78589902189475]",
|
||||||
"type": "shape",
|
"type": "shape",
|
||||||
"id": "mPR44JBpcd"
|
"id": "mPR44JBpcd"
|
||||||
},
|
},
|
||||||
@@ -121,7 +121,7 @@
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"textResizing": 1,
|
"textResizing": 1,
|
||||||
"xywh": "[503.16560437958293,165.36299989942228,99.95316838431143,80.60737422459296]",
|
"xywh": "[543.3481636903648,382.77123494325747,99.95316838431143,93.33554571739376]",
|
||||||
"type": "shape",
|
"type": "shape",
|
||||||
"id": "cmtluc3FWR"
|
"id": "cmtluc3FWR"
|
||||||
},
|
},
|
||||||
@@ -145,7 +145,7 @@
|
|||||||
"strokeStyle": "solid",
|
"strokeStyle": "solid",
|
||||||
"strokeWidth": 2,
|
"strokeWidth": 2,
|
||||||
"textResizing": 1,
|
"textResizing": 1,
|
||||||
"xywh": "[663.6471045132407,172.22708086148566,131.14345570418993,66.87921230046624]",
|
"xywh": "[16.1402039335359,378.4574848297732,100.2126915532233,99.60320803026627]",
|
||||||
"type": "shape",
|
"type": "shape",
|
||||||
"id": "knt_TKvACR"
|
"id": "knt_TKvACR"
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "GuSXhkqpUl",
|
"id": "NSlTmqVn2NsIJCDvzIoUF",
|
||||||
"flavour": "affine:frame",
|
"flavour": "affine:frame",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -162,20 +162,13 @@
|
|||||||
"$blocksuite:internal:text$": true,
|
"$blocksuite:internal:text$": true,
|
||||||
"delta": [
|
"delta": [
|
||||||
{
|
{
|
||||||
"insert": "Frame 1"
|
"insert": "Shapes"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"background": "--affine-palette-transparent",
|
"background": "--affine-palette-transparent",
|
||||||
"xywh": "[-140.35546875000006,60.96746826171875,1079.28125,307.06640625]",
|
"xywh": "[-23.859796066464128,332.87664265400565,881.5090292421075,190.55181066780085]",
|
||||||
"index": "a0",
|
"index": "a0"
|
||||||
"childElementIds": {
|
|
||||||
"e6t9tKz8Sy": true,
|
|
||||||
"F8qB_zDC5Q": true,
|
|
||||||
"mPR44JBpcd": true,
|
|
||||||
"cmtluc3FWR": true,
|
|
||||||
"knt_TKvACR": true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"children": []
|
"children": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"type": "page",
|
"type": "page",
|
||||||
"meta": {
|
"meta": {
|
||||||
"id": "VKd9Ksg2BG",
|
"id": "NJwLoscdk4",
|
||||||
"title": "BlockSuite Playground",
|
"title": "BlockSuite Playground",
|
||||||
"createDate": 1725454903728,
|
"createDate": 1725610138401,
|
||||||
"tags": []
|
"tags": []
|
||||||
},
|
},
|
||||||
"blocks": {
|
"blocks": {
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "rhCCfuveZ8",
|
"id": "W-A_1geJy3",
|
||||||
"flavour": "affine:page",
|
"flavour": "affine:page",
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "1Gr7rOSQE0",
|
"id": "KNi1ipoyX6",
|
||||||
"flavour": "affine:surface",
|
"flavour": "affine:surface",
|
||||||
"version": 5,
|
"version": 5,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -33,25 +33,25 @@
|
|||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "wTA9OwLHan",
|
"id": "bv-d4LA-Nr",
|
||||||
"flavour": "affine:edgeless-text",
|
"flavour": "affine:edgeless-text",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"props": {
|
"props": {
|
||||||
"xywh": "[272.7708206176758,163.16667556762695,245.12498474121088,56]",
|
"xywh": "[18.221401559354234,201.98389611782602,800.6283921393511,489.15472412109375]",
|
||||||
"index": "a1",
|
"index": "a0",
|
||||||
"color": "--affine-palette-line-blue",
|
"color": "--affine-palette-line-blue",
|
||||||
"fontFamily": "blocksuite:surface:Inter",
|
"fontFamily": "blocksuite:surface:Inter",
|
||||||
"fontStyle": "normal",
|
"fontStyle": "normal",
|
||||||
"fontWeight": "400",
|
"fontWeight": "400",
|
||||||
"textAlign": "left",
|
"textAlign": "left",
|
||||||
"scale": 1,
|
"scale": 5.435052533564726,
|
||||||
"rotate": 0,
|
"rotate": 0,
|
||||||
"hasMaxWidth": true
|
"hasMaxWidth": true
|
||||||
},
|
},
|
||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "ig8oN3BQrC",
|
"id": "vkzwo90EHS",
|
||||||
"flavour": "affine:paragraph",
|
"flavour": "affine:paragraph",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -60,7 +60,25 @@
|
|||||||
"$blocksuite:internal:text$": true,
|
"$blocksuite:internal:text$": true,
|
||||||
"delta": [
|
"delta": [
|
||||||
{
|
{
|
||||||
"insert": "To shape, Not to Adapt."
|
"insert": "To Shape,"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"children": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "block",
|
||||||
|
"id": "0ugn1XiO-U",
|
||||||
|
"flavour": "affine:paragraph",
|
||||||
|
"version": 1,
|
||||||
|
"props": {
|
||||||
|
"type": "text",
|
||||||
|
"text": {
|
||||||
|
"$blocksuite:internal:text$": true,
|
||||||
|
"delta": [
|
||||||
|
{
|
||||||
|
"insert": "Not to Adopt."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -71,7 +89,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "block",
|
"type": "block",
|
||||||
"id": "d3qe5CuEDW",
|
"id": "mkbmK_R1sC",
|
||||||
"flavour": "affine:frame",
|
"flavour": "affine:frame",
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"props": {
|
"props": {
|
||||||
@@ -84,10 +102,10 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"background": "--affine-palette-transparent",
|
"background": "--affine-palette-transparent",
|
||||||
"xywh": "[207.38800048828125,138.71615600585938,328.28125,106.92578125]",
|
"xywh": "[-21.778598440645766,126.5612581783729,880.6283921393511,640]",
|
||||||
"index": "a0",
|
"index": "a1",
|
||||||
"childElementIds": {
|
"childElementIds": {
|
||||||
"wTA9OwLHan": true
|
"bv-d4LA-Nr": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"children": []
|
"children": []
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
renderEditor();
|
renderEditor();
|
||||||
|
return () => editorHostRef.current?.remove();
|
||||||
}, [renderEditor]);
|
}, [renderEditor]);
|
||||||
|
|
||||||
// observe editor settings change
|
// observe editor settings change
|
||||||
|
|||||||
Reference in New Issue
Block a user