mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
refactor: setup files (#8201)
This commit is contained in:
@@ -51,7 +51,6 @@
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@vitejs/plugin-react-swc": "^3.6.0",
|
||||
"builder-util-runtime": "^9.2.5-alpha.2",
|
||||
"core-js": "^3.36.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"electron": "^32.0.0",
|
||||
"electron-log": "^5.1.2",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import './polyfill/dispose';
|
||||
import '@affine/core/bootstrap/preload';
|
||||
import './setup';
|
||||
import './global.css';
|
||||
|
||||
import { appConfigProxy } from '@affine/core/hooks/use-app-config-storage';
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
import 'core-js/modules/esnext.symbol.async-dispose';
|
||||
import 'core-js/modules/esnext.symbol.dispose';
|
||||
4
packages/frontend/apps/electron/renderer/setup.ts
Normal file
4
packages/frontend/apps/electron/renderer/setup.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { setupBlocksuite, setupElectron } from '@affine/core/bootstrap';
|
||||
|
||||
setupElectron();
|
||||
setupBlocksuite();
|
||||
@@ -1,7 +1,7 @@
|
||||
import '@affine/component/theme/global.css';
|
||||
import '@affine/component/theme/theme.css';
|
||||
import '@affine/core/bootstrap/preload';
|
||||
import '../global.css';
|
||||
import './setup';
|
||||
|
||||
import { ThemeProvider } from '@affine/component/theme-provider';
|
||||
import { configureAppTabsHeaderModule } from '@affine/core/modules/app-tabs-header';
|
||||
|
||||
3
packages/frontend/apps/electron/renderer/shell/setup.ts
Normal file
3
packages/frontend/apps/electron/renderer/shell/setup.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { setupElectron } from '@affine/core/bootstrap';
|
||||
|
||||
setupElectron();
|
||||
@@ -21,9 +21,7 @@
|
||||
"@sentry/react": "^8.0.0",
|
||||
"@toeverything/theme": "^1.0.9",
|
||||
"clsx": "^2.1.1",
|
||||
"core-js": "^3.36.1",
|
||||
"figma-squircle": "^1.0.0",
|
||||
"intl-segmenter-polyfill-rs": "^0.1.7",
|
||||
"jotai": "^2.9.3",
|
||||
"jotai-effect": "^1.0.2",
|
||||
"jotai-scope": "^0.7.2",
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import './polyfill/dispose';
|
||||
import './polyfill/intl-segmenter';
|
||||
import './polyfill/promise-with-resolvers';
|
||||
import './polyfill/request-idle-callback';
|
||||
import '@affine/core/bootstrap/preload';
|
||||
import './setup';
|
||||
|
||||
import { performanceLogger } from '@affine/core/shared';
|
||||
import {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
import 'core-js/modules/esnext.symbol.async-dispose';
|
||||
import 'core-js/modules/esnext.symbol.dispose';
|
||||
@@ -1,11 +0,0 @@
|
||||
if (Intl.Segmenter === undefined) {
|
||||
await import('intl-segmenter-polyfill-rs').then(({ Segmenter }) => {
|
||||
Object.defineProperty(Intl, 'Segmenter', {
|
||||
value: Segmenter,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -1 +0,0 @@
|
||||
import 'core-js/features/promise/with-resolvers';
|
||||
@@ -1,19 +0,0 @@
|
||||
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);
|
||||
};
|
||||
4
packages/frontend/apps/mobile/src/setup.ts
Normal file
4
packages/frontend/apps/mobile/src/setup.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { setupBlocksuite, setupBrowser } from '@affine/core/bootstrap';
|
||||
|
||||
await setupBrowser();
|
||||
setupBlocksuite();
|
||||
@@ -17,8 +17,6 @@
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@emotion/react": "^11.11.4",
|
||||
"@sentry/react": "^8.0.0",
|
||||
"core-js": "^3.36.1",
|
||||
"intl-segmenter-polyfill-rs": "^0.1.7",
|
||||
"jotai": "^2.8.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import './polyfill/dispose';
|
||||
import './polyfill/intl-segmenter';
|
||||
import './polyfill/promise-with-resolvers';
|
||||
import './polyfill/request-idle-callback';
|
||||
import '@affine/core/bootstrap/preload';
|
||||
import './setup';
|
||||
|
||||
import { performanceLogger } from '@affine/core/shared';
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
import 'core-js/modules/esnext.symbol.async-dispose';
|
||||
import 'core-js/modules/esnext.symbol.dispose';
|
||||
@@ -1,11 +0,0 @@
|
||||
if (Intl.Segmenter === undefined) {
|
||||
await import('intl-segmenter-polyfill-rs').then(({ Segmenter }) => {
|
||||
Object.defineProperty(Intl, 'Segmenter', {
|
||||
value: Segmenter,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -1 +0,0 @@
|
||||
import 'core-js/features/promise/with-resolvers';
|
||||
@@ -1,19 +0,0 @@
|
||||
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);
|
||||
};
|
||||
4
packages/frontend/apps/web/src/setup.ts
Normal file
4
packages/frontend/apps/web/src/setup.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { setupBlocksuite, setupBrowser } from '@affine/core/bootstrap';
|
||||
|
||||
await setupBrowser();
|
||||
setupBlocksuite();
|
||||
@@ -4,7 +4,8 @@
|
||||
"private": true,
|
||||
"version": "0.16.0",
|
||||
"exports": {
|
||||
"./*": "./src/*"
|
||||
"./*": "./src/*",
|
||||
"./bootstrap": "./src/bootstrap/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@affine-test/fixtures": "workspace:*",
|
||||
@@ -52,6 +53,7 @@
|
||||
"bytes": "^3.1.2",
|
||||
"clsx": "^2.1.0",
|
||||
"cmdk": "^1.0.0",
|
||||
"core-js": "^3.36.1",
|
||||
"css-spring": "^4.1.0",
|
||||
"dayjs": "^1.11.10",
|
||||
"file-type": "^19.1.0",
|
||||
@@ -65,6 +67,7 @@
|
||||
"idb": "^8.0.0",
|
||||
"idb-keyval": "^6.2.1",
|
||||
"image-blob-reduce": "^4.1.0",
|
||||
"intl-segmenter-polyfill-rs": "^0.1.7",
|
||||
"is-svg": "^5.0.0",
|
||||
"jotai": "^2.8.0",
|
||||
"jotai-devtools": "^0.10.0",
|
||||
|
||||
4
packages/frontend/core/src/bootstrap/app.ts
Normal file
4
packages/frontend/core/src/bootstrap/app.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import '@affine/env/constant';
|
||||
import '../types/types.d.ts';
|
||||
|
||||
export { setupGlobal as setupEnvironment } from '@affine/env/global';
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
16
packages/frontend/core/src/bootstrap/index.ts
Normal file
16
packages/frontend/core/src/bootstrap/index.ts
Normal file
@@ -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';
|
||||
8
packages/frontend/core/src/bootstrap/polyfill/dispose.ts
Normal file
8
packages/frontend/core/src/bootstrap/polyfill/dispose.ts
Normal file
@@ -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');
|
||||
}
|
||||
}
|
||||
17
packages/frontend/core/src/bootstrap/polyfill/index.ts
Normal file
17
packages/frontend/core/src/bootstrap/polyfill/index.ts
Normal file
@@ -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';
|
||||
@@ -6,7 +6,7 @@ import { listHistoryQuery, recoverDocMutation } from '@affine/graphql';
|
||||
import { i18nTime } from '@affine/i18n';
|
||||
import { assertEquals } from '@blocksuite/global/utils';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import { globalBlockSuiteSchema } from '@toeverything/infra';
|
||||
import { getAFFiNEWorkspaceSchema } from '@toeverything/infra';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import useSWRImmutable from 'swr/immutable';
|
||||
import {
|
||||
@@ -108,7 +108,7 @@ const getOrCreateShellWorkspace = (workspaceId: string) => {
|
||||
blobSources: {
|
||||
main: blobStorage,
|
||||
},
|
||||
schema: globalBlockSuiteSchema,
|
||||
schema: getAFFiNEWorkspaceSchema(),
|
||||
});
|
||||
docCollectionMap.set(workspaceId, docCollection);
|
||||
docCollection.doc.emit('sync', [true, docCollection.doc]);
|
||||
|
||||
@@ -4,8 +4,7 @@ import {
|
||||
useJournalInfoHelper,
|
||||
useJournalRouteHelper,
|
||||
} from '@affine/core/hooks/use-journal';
|
||||
import type { DocCollection } from '@affine/core/shared';
|
||||
import type { Doc } from '@blocksuite/store';
|
||||
import type { Doc, DocCollection } from '@blocksuite/store';
|
||||
import dayjs from 'dayjs';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Button } from '@affine/component';
|
||||
import { useJournalRouteHelper } from '@affine/core/hooks/use-journal';
|
||||
import type { DocCollection } from '@affine/core/shared';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export interface JournalTodayButtonProps {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { toast } from '@affine/component';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import type { DocMode } from '@blocksuite/blocks';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { DocsService, useServices } from '@toeverything/infra';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import type { DocCollection } from '../../../shared';
|
||||
|
||||
export const usePageHelper = (docCollection: DocCollection) => {
|
||||
const { docsService, workbenchService } = useServices({
|
||||
DocsService,
|
||||
|
||||
@@ -2,8 +2,8 @@ import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks';
|
||||
import { track } from '@affine/core/mixpanel';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { ImportIcon } from '@blocksuite/icons/rc';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
|
||||
import type { DocCollection } from '../../shared';
|
||||
import { MenuItem } from '../app-sidebar';
|
||||
import { usePageHelper } from '../blocksuite/block-suite-page-list/utils';
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
useJournalRouteHelper,
|
||||
} from '@affine/core/hooks/use-journal';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import type { DocCollection } from '@affine/core/shared';
|
||||
import { isNewTabTrigger } from '@affine/core/utils';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { TodayIcon, TomorrowIcon, YesterdayIcon } from '@blocksuite/icons/rc';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
import { type MouseEvent } from 'react';
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import type { DocCollection } from '../../shared';
|
||||
|
||||
export function useReferenceLinkHelper(docCollection: DocCollection) {
|
||||
const addReferenceLink = useCallback(
|
||||
(pageId: string, referenceId: string) => {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { i18nTime } from '@affine/i18n';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import { DocsService, initEmptyPage, useService } from '@toeverything/infra';
|
||||
import dayjs from 'dayjs';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
import { track } from '../mixpanel';
|
||||
import { WorkbenchService } from '../modules/workbench';
|
||||
import type { DocCollection } from '../shared';
|
||||
import { useCurrentWorkspacePropertiesAdapter } from './use-affine-adapter';
|
||||
import { useDocCollectionHelper } from './use-block-suite-workspace-helper';
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
type WorkspaceMetadata,
|
||||
type WorkspaceProfileInfo,
|
||||
} from '@toeverything/infra';
|
||||
import { effect, globalBlockSuiteSchema, Service } from '@toeverything/infra';
|
||||
import { effect, getAFFiNEWorkspaceSchema, Service } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { EMPTY, map, mergeMap } from 'rxjs';
|
||||
@@ -96,7 +96,7 @@ export class CloudWorkspaceFlavourProviderService
|
||||
const docCollection = new DocCollection({
|
||||
id: workspaceId,
|
||||
idGenerator: () => nanoid(),
|
||||
schema: globalBlockSuiteSchema,
|
||||
schema: getAFFiNEWorkspaceSchema(),
|
||||
blobSources: {
|
||||
main: blobStorage,
|
||||
},
|
||||
@@ -216,7 +216,7 @@ export class CloudWorkspaceFlavourProviderService
|
||||
|
||||
const bs = new DocCollection({
|
||||
id,
|
||||
schema: globalBlockSuiteSchema,
|
||||
schema: getAFFiNEWorkspaceSchema(),
|
||||
});
|
||||
|
||||
if (localData) applyUpdate(bs.doc, localData);
|
||||
|
||||
@@ -9,7 +9,11 @@ import type {
|
||||
WorkspaceMetadata,
|
||||
WorkspaceProfileInfo,
|
||||
} from '@toeverything/infra';
|
||||
import { globalBlockSuiteSchema, LiveData, Service } from '@toeverything/infra';
|
||||
import {
|
||||
getAFFiNEWorkspaceSchema,
|
||||
LiveData,
|
||||
Service,
|
||||
} from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -70,7 +74,7 @@ export class LocalWorkspaceFlavourProvider
|
||||
const docCollection = new DocCollection({
|
||||
id: id,
|
||||
idGenerator: () => nanoid(),
|
||||
schema: globalBlockSuiteSchema,
|
||||
schema: getAFFiNEWorkspaceSchema(),
|
||||
blobSources: { main: blobStorage },
|
||||
});
|
||||
|
||||
@@ -143,7 +147,7 @@ export class LocalWorkspaceFlavourProvider
|
||||
|
||||
const bs = new DocCollection({
|
||||
id,
|
||||
schema: globalBlockSuiteSchema,
|
||||
schema: getAFFiNEWorkspaceSchema(),
|
||||
});
|
||||
|
||||
if (localData) applyUpdate(bs.doc, localData);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
|
||||
export { DocCollection };
|
||||
|
||||
export enum WorkspaceSubPath {
|
||||
ALL = 'all',
|
||||
|
||||
Reference in New Issue
Block a user