mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-14 16:46:22 +08:00
refactor: setup files (#8201)
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
import '@affine/env/constant';
|
||||
import '../types/types.d.ts';
|
||||
|
||||
export { setupGlobal as setupEnvironment } from '@affine/env/global';
|
||||
+8
-6
@@ -3,9 +3,11 @@ import { builtInTemplates as builtInStickersTemplates } from '@affine/templates/
|
||||
import type { TemplateManager } from '@blocksuite/blocks';
|
||||
import { EdgelessTemplatePanel } from '@blocksuite/blocks';
|
||||
|
||||
EdgelessTemplatePanel.templates.extend(
|
||||
builtInStickersTemplates as TemplateManager
|
||||
);
|
||||
EdgelessTemplatePanel.templates.extend(
|
||||
builtInEdgelessTemplates as TemplateManager
|
||||
);
|
||||
export function setupBlocksuite() {
|
||||
EdgelessTemplatePanel.templates.extend(
|
||||
builtInStickersTemplates as TemplateManager
|
||||
);
|
||||
EdgelessTemplatePanel.templates.extend(
|
||||
builtInEdgelessTemplates as TemplateManager
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import '../types/types.d.ts';
|
||||
|
||||
import { setupEnvironment } from './app';
|
||||
import { polyfillBrowser, polyfillElectron } from './polyfill';
|
||||
|
||||
export function setupElectron() {
|
||||
polyfillElectron();
|
||||
setupEnvironment();
|
||||
}
|
||||
|
||||
export async function setupBrowser() {
|
||||
await polyfillBrowser();
|
||||
setupEnvironment();
|
||||
}
|
||||
|
||||
export { setupBlocksuite } from './blocksuite';
|
||||
@@ -0,0 +1,8 @@
|
||||
export async function polyfillDispose() {
|
||||
if (typeof Symbol.dispose !== 'symbol') {
|
||||
// @ts-expect-error ignore
|
||||
await import('core-js/modules/esnext.symbol.async-dispose');
|
||||
// @ts-expect-error ignore
|
||||
await import('core-js/modules/esnext.symbol.dispose');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { polyfillDispose } from './dispose';
|
||||
import { polyfillI18n } from './intl-segmenter';
|
||||
import { polyfillPromise } from './promise-with-resolvers';
|
||||
import { polyfillEventLoop } from './request-idle-callback';
|
||||
import { polyfillResizeObserver } from './resize-observer';
|
||||
|
||||
export function polyfillElectron() {
|
||||
polyfillResizeObserver();
|
||||
}
|
||||
|
||||
export async function polyfillBrowser() {
|
||||
polyfillResizeObserver();
|
||||
polyfillEventLoop();
|
||||
await polyfillI18n();
|
||||
await polyfillPromise();
|
||||
await polyfillDispose();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
export async function polyfillI18n() {
|
||||
if (Intl.Segmenter === undefined) {
|
||||
await import('intl-segmenter-polyfill-rs').then(({ Segmenter }) => {
|
||||
Object.defineProperty(Intl, 'Segmenter', {
|
||||
value: Segmenter,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export async function polyfillPromise() {
|
||||
if (typeof Promise.withResolvers !== 'function') {
|
||||
// @ts-expect-error ignore
|
||||
await import('core-js/features/promise/with-resolvers');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
export function polyfillEventLoop() {
|
||||
window.requestIdleCallback =
|
||||
window.requestIdleCallback ||
|
||||
function (cb) {
|
||||
const start = Date.now();
|
||||
return setTimeout(function () {
|
||||
cb({
|
||||
didTimeout: false,
|
||||
timeRemaining: function () {
|
||||
return Math.max(0, 50 - (Date.now() - start));
|
||||
},
|
||||
});
|
||||
}, 1);
|
||||
};
|
||||
|
||||
window.cancelIdleCallback =
|
||||
window.cancelIdleCallback ||
|
||||
function (id) {
|
||||
clearTimeout(id);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ResizeObserver } from '@juggle/resize-observer';
|
||||
|
||||
export function polyfillResizeObserver() {
|
||||
window.ResizeObserver = ResizeObserver;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
import { ResizeObserver } from '@juggle/resize-observer';
|
||||
window.ResizeObserver = ResizeObserver;
|
||||
|
||||
import '@affine/env/constant';
|
||||
import './edgeless-template';
|
||||
|
||||
import { setupGlobal } from '@affine/env/global';
|
||||
|
||||
setupGlobal();
|
||||
|
||||
import '../types/types.d.ts';
|
||||
Reference in New Issue
Block a user