fix: plugin infra (#3398)

This commit is contained in:
Alex Yang
2023-07-26 22:36:29 -07:00
committed by GitHub
parent 1e72d3c270
commit 780fffb88f
28 changed files with 93 additions and 52 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { currentPageIdAtom } from '@toeverything/plugin-infra/atom';
import { atom } from 'jotai/vanilla';
import { pageSettingFamily } from './index';
+1 -1
View File
@@ -17,7 +17,7 @@ import {
} from '@affine/workspace/migration';
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
import { assertExists } from '@blocksuite/global/utils';
import { rootStore } from '@toeverything/plugin-infra/manager';
import { rootStore } from '@toeverything/plugin-infra/atom';
import { WorkspaceAdapters } from '../adapters/workspace';
+20 -19
View File
@@ -6,18 +6,18 @@ import * as BlockSuiteBlocksStd from '@blocksuite/blocks/std';
import { DisposableGroup } from '@blocksuite/global/utils';
import * as BlockSuiteGlobalUtils from '@blocksuite/global/utils';
import * as Icons from '@blocksuite/icons';
import type {
CallbackMap,
PluginContext,
} from '@toeverything/plugin-infra/entry';
import * as Manager from '@toeverything/plugin-infra/manager';
import * as Manager from '@toeverything/plugin-infra/atom';
import {
editorItemsAtom,
headerItemsAtom,
registeredPluginAtom,
rootStore,
windowItemsAtom,
} from '@toeverything/plugin-infra/manager';
} from '@toeverything/plugin-infra/atom';
import type {
CallbackMap,
PluginContext,
} from '@toeverything/plugin-infra/entry';
import * as Jotai from 'jotai';
import { Provider } from 'jotai/react';
import * as JotaiUtils from 'jotai/utils';
@@ -96,6 +96,8 @@ const createGlobalThis = () => {
document,
navigator,
userAgent: navigator.userAgent,
// todo: permission control
fetch: globalThis.fetch,
// fixme: use our own db api
indexedDB: globalThis.indexedDB,
@@ -135,20 +137,19 @@ await Promise.all(
return fetch(entryURL).then(async res => {
if (assets.length > 0) {
await Promise.all(
assets.map(asset => {
assets.map(async asset => {
if (asset.endsWith('.css')) {
return fetch(new URL(asset, baseURL)).then(res => {
if (res.ok) {
// todo: how to put css file into sandbox?
return res.text().then(text => {
const style = document.createElement('style');
style.setAttribute('plugin-id', plugin);
style.textContent = text;
document.head.appendChild(style);
});
}
return null;
});
const res = await fetch(new URL(asset, baseURL));
if (res.ok) {
// todo: how to put css file into sandbox?
return res.text().then(text => {
const style = document.createElement('style');
style.setAttribute('plugin-id', plugin);
style.textContent = text;
document.head.appendChild(style);
});
}
return null;
} else {
return Promise.resolve();
}
@@ -9,7 +9,7 @@ import {
currentPageIdAtom,
currentWorkspaceIdAtom,
rootStore,
} from '@toeverything/plugin-infra/manager';
} from '@toeverything/plugin-infra/atom';
import { useAtomValue } from 'jotai/react';
import { Provider } from 'jotai/react';
import type { ErrorInfo, ReactElement, ReactNode } from 'react';
@@ -3,7 +3,7 @@ import {
SettingWrapper,
} from '@affine/component/setting-components';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { registeredPluginAtom } from '@toeverything/plugin-infra/manager';
import { registeredPluginAtom } from '@toeverything/plugin-infra/atom';
import { useAtomValue } from 'jotai';
export const Plugins = () => {
@@ -14,7 +14,7 @@ import {
useBlockSuitePageMeta,
usePageMetaHelper,
} from '@toeverything/hooks/use-block-suite-page-meta';
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { currentPageIdAtom } from '@toeverything/plugin-infra/atom';
import { useAtom, useAtomValue } from 'jotai';
import { useState } from 'react';
import { useParams } from 'react-router-dom';
@@ -3,7 +3,7 @@ import { WorkspaceSubPath } from '@affine/env/workspace';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { assertExists } from '@blocksuite/global/utils';
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { currentPageIdAtom } from '@toeverything/plugin-infra/atom';
import { useAtomValue } from 'jotai';
import { useCallback, useState } from 'react';
@@ -7,7 +7,7 @@ import { SidebarSwitch } from '@affine/component/app-sidebar/sidebar-header';
import { isDesktop } from '@affine/env/constant';
import { CloseIcon, MinusIcon, RoundedRectangleIcon } from '@blocksuite/icons';
import type { Page } from '@blocksuite/store';
import { headerItemsAtom } from '@toeverything/plugin-infra/manager';
import { headerItemsAtom } from '@toeverything/plugin-infra/atom';
import { useAtomValue } from 'jotai';
import type { FC, HTMLAttributes, PropsWithChildren, ReactNode } from 'react';
import {
@@ -7,13 +7,13 @@ import { assertExists } from '@blocksuite/global/utils';
import type { Page, Workspace } from '@blocksuite/store';
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
import { useBlockSuiteWorkspacePage } from '@toeverything/hooks/use-block-suite-workspace-page';
import type { CallbackMap } from '@toeverything/plugin-infra/entry';
import {
contentLayoutAtom,
editorItemsAtom,
rootStore,
windowItemsAtom,
} from '@toeverything/plugin-infra/manager';
} from '@toeverything/plugin-infra/atom';
import type { CallbackMap } from '@toeverything/plugin-infra/entry';
import type { LayoutNode } from '@toeverything/plugin-infra/type';
import clsx from 'clsx';
import { useAtomValue, useSetAtom } from 'jotai';
@@ -2,7 +2,7 @@ import { assertExists } from '@blocksuite/global/utils';
import {
currentPageIdAtom,
currentWorkspaceIdAtom,
} from '@toeverything/plugin-infra/manager';
} from '@toeverything/plugin-infra/atom';
import { useAtom, useSetAtom } from 'jotai';
import { useCallback, useEffect } from 'react';
@@ -1,6 +1,6 @@
import type { WorkspaceRegistry } from '@affine/env/workspace';
import type { WorkspaceFlavour } from '@affine/env/workspace';
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { currentPageIdAtom } from '@toeverything/plugin-infra/atom';
import { useSetAtom } from 'jotai';
import { useCallback } from 'react';
+1 -1
View File
@@ -28,7 +28,7 @@ import {
useSensors,
} from '@dnd-kit/core';
import { usePassiveWorkspaceEffect } from '@toeverything/plugin-infra/__internal__/react';
import { currentWorkspaceIdAtom } from '@toeverything/plugin-infra/manager';
import { currentWorkspaceIdAtom } from '@toeverything/plugin-infra/atom';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import type { FC, PropsWithChildren, ReactElement } from 'react';
import { lazy, Suspense, useCallback, useMemo } from 'react';
+1 -1
View File
@@ -1,7 +1,7 @@
import { DebugLogger } from '@affine/debug';
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
import { getWorkspace } from '@toeverything/plugin-infra/__internal__/workspace';
import { rootStore } from '@toeverything/plugin-infra/manager';
import { rootStore } from '@toeverything/plugin-infra/atom';
import { lazy } from 'react';
import type { LoaderFunction } from 'react-router-dom';
import { redirect } from 'react-router-dom';
+1 -4
View File
@@ -3,10 +3,7 @@ import { DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX } from '@affine/env/constant';
import { WorkspaceSubPath } from '@affine/env/workspace';
import { assertExists } from '@blocksuite/global/utils';
import { getActiveBlockSuiteWorkspaceAtom } from '@toeverything/plugin-infra/__internal__/workspace';
import {
currentPageIdAtom,
rootStore,
} from '@toeverything/plugin-infra/manager';
import { currentPageIdAtom, rootStore } from '@toeverything/plugin-infra/atom';
import { useAtom } from 'jotai/react';
import { useCallback, useEffect } from 'react';
import type { LoaderFunction } from 'react-router-dom';
@@ -7,10 +7,7 @@ import { WorkspaceSubPath } from '@affine/env/workspace';
import type { EditorContainer } from '@blocksuite/editor';
import { assertExists } from '@blocksuite/global/utils';
import type { Page } from '@blocksuite/store';
import {
currentPageIdAtom,
rootStore,
} from '@toeverything/plugin-infra/manager';
import { currentPageIdAtom, rootStore } from '@toeverything/plugin-infra/atom';
import { useAtomValue } from 'jotai';
import { useAtom } from 'jotai/react';
import { type ReactElement, useCallback, useEffect } from 'react';
+1 -1
View File
@@ -2,7 +2,7 @@ import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
import {
currentWorkspaceIdAtom,
rootStore,
} from '@toeverything/plugin-infra/manager';
} from '@toeverything/plugin-infra/atom';
import type { ReactElement } from 'react';
import { type LoaderFunction, Outlet, redirect } from 'react-router-dom';
+1 -1
View File
@@ -5,7 +5,7 @@ import { arrayMove } from '@dnd-kit/sortable';
import {
currentPageIdAtom,
currentWorkspaceIdAtom,
} from '@toeverything/plugin-infra/manager';
} from '@toeverything/plugin-infra/atom';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import type { FC, ReactElement } from 'react';
import { lazy, Suspense, useCallback, useTransition } from 'react';