mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 12:36:24 +08:00
feat(editor): replace spec provider with extension manager (#11861)
Closes: BS-3273
This commit is contained in:
+11
-6
@@ -1,10 +1,10 @@
|
||||
import { Skeleton } from '@affine/component';
|
||||
import { getViewManager } from '@affine/core/blocksuite/manager/migrating-view';
|
||||
import type { EditorSettingSchema } from '@affine/core/modules/editor-setting';
|
||||
import { EditorSettingService } from '@affine/core/modules/editor-setting';
|
||||
import { EdgelessCRUDIdentifier } from '@blocksuite/affine/blocks/surface';
|
||||
import { Bound } from '@blocksuite/affine/global/gfx';
|
||||
import { ViewportElementExtension } from '@blocksuite/affine/shared/services';
|
||||
import { SpecProvider } from '@blocksuite/affine/shared/utils';
|
||||
import type { EditorHost } from '@blocksuite/affine/std';
|
||||
import { BlockStdScope } from '@blocksuite/affine/std';
|
||||
import {
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
import type { Block, Store } from '@blocksuite/affine/store';
|
||||
import { useFramework } from '@toeverything/infra';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||
import { map, pairwise } from 'rxjs';
|
||||
|
||||
import {
|
||||
@@ -55,6 +55,13 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
const framework = useFramework();
|
||||
const { editorSetting } = framework.get(EditorSettingService);
|
||||
|
||||
const extensions = useMemo(() => {
|
||||
const manager = getViewManager(framework, false);
|
||||
return manager
|
||||
.get('preview-edgeless')
|
||||
.concat([ViewportElementExtension('.ref-viewport')]);
|
||||
}, [framework]);
|
||||
|
||||
const updateElements = useCallback(() => {
|
||||
const editorHost = editorHostRef.current;
|
||||
const doc = docRef.current;
|
||||
@@ -76,9 +83,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
|
||||
const editorHost = new BlockStdScope({
|
||||
store: doc,
|
||||
extensions: SpecProvider._.getSpec('preview:edgeless').extend([
|
||||
ViewportElementExtension('.ref-viewport'),
|
||||
]).value,
|
||||
extensions,
|
||||
}).render();
|
||||
docRef.current = doc;
|
||||
editorHostRef.current?.remove();
|
||||
@@ -115,7 +120,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
|
||||
// append to dom node
|
||||
wrapperRef.current.append(editorHost);
|
||||
}, [docName, firstUpdate, updateElements]);
|
||||
}, [docName, extensions, firstUpdate, updateElements]);
|
||||
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
|
||||
@@ -2,12 +2,10 @@ import { ChatPanel } from '@affine/core/blocksuite/ai';
|
||||
import type { AffineEditorContainer } from '@affine/core/blocksuite/block-suite-editor';
|
||||
import { useAIChatConfig } from '@affine/core/components/hooks/affine/use-ai-chat-config';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import { ViewExtensionManagerIdentifier } from '@blocksuite/affine/ext-loader';
|
||||
import { RefNodeSlotsProvider } from '@blocksuite/affine/inlines/reference';
|
||||
import { DocModeProvider } from '@blocksuite/affine/shared/services';
|
||||
import {
|
||||
createSignalFromObservable,
|
||||
SpecProvider,
|
||||
} from '@blocksuite/affine/shared/utils';
|
||||
import { createSignalFromObservable } from '@blocksuite/affine/shared/utils';
|
||||
import { useFramework } from '@toeverything/infra';
|
||||
import { forwardRef, useEffect, useRef } from 'react';
|
||||
|
||||
@@ -69,8 +67,9 @@ export const EditorChatPanel = forwardRef(function EditorChatPanel(
|
||||
chatPanelRef.current.docDisplayConfig = docDisplayConfig;
|
||||
chatPanelRef.current.searchMenuConfig = searchMenuConfig;
|
||||
chatPanelRef.current.networkSearchConfig = networkSearchConfig;
|
||||
chatPanelRef.current.previewSpecBuilder =
|
||||
SpecProvider._.getSpec('preview:page');
|
||||
chatPanelRef.current.extensions = editor.host.std
|
||||
.get(ViewExtensionManagerIdentifier)
|
||||
.get('preview-page');
|
||||
|
||||
containerRef.current?.append(chatPanelRef.current);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user