mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 17:39:55 +08:00
refactor(editor): remove old specs (#11909)
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
||||
defaultImageProxyMiddleware,
|
||||
ImageProxyService,
|
||||
} from '@blocksuite/affine/blocks/image';
|
||||
import { PageEditorBlockSpecs } from '@blocksuite/affine/extensions';
|
||||
import { Container, type ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { codeBlockWrapMiddleware } from '@blocksuite/affine/shared/adapters';
|
||||
@@ -37,14 +36,15 @@ import { keyed } from 'lit/directives/keyed.js';
|
||||
import { literal } from 'lit/static-html.js';
|
||||
import React from 'react';
|
||||
|
||||
import { getViewManager } from '../../manager/migrating-view';
|
||||
import { markDownToDoc } from '../../utils';
|
||||
import type {
|
||||
AffineAIPanelState,
|
||||
AffineAIPanelWidgetConfig,
|
||||
} from '../widgets/ai-panel/type';
|
||||
|
||||
export const CustomPageEditorBlockSpecs: ExtensionType[] = [
|
||||
...PageEditorBlockSpecs,
|
||||
export const getCustomPageEditorBlockSpecs: () => ExtensionType[] = () => [
|
||||
...getViewManager().get('page'),
|
||||
{
|
||||
setup: di => {
|
||||
di.override(
|
||||
@@ -316,7 +316,8 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
|
||||
html`<div class="ai-answer-text-editor affine-page-viewport">
|
||||
${new BlockStdScope({
|
||||
store: this._doc,
|
||||
extensions: this.options.extensions ?? CustomPageEditorBlockSpecs,
|
||||
extensions:
|
||||
this.options.extensions ?? getCustomPageEditorBlockSpecs(),
|
||||
}).render()}
|
||||
</div>`
|
||||
)}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { EdgelessEditorBlockSpecs } from '@blocksuite/affine/extensions';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { ThemeProvider } from '@blocksuite/affine/shared/services';
|
||||
import { BlockStdScope, ShadowlessElement } from '@blocksuite/affine/std';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import type { ExtensionType, Store } from '@blocksuite/affine/store';
|
||||
import { css, html, nothing, type TemplateResult } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
@@ -95,7 +94,7 @@ export class EdgelessEditor extends SignalWatcher(
|
||||
accessor editor!: TemplateResult;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor specs = EdgelessEditorBlockSpecs;
|
||||
accessor specs: ExtensionType[] = [];
|
||||
|
||||
@state()
|
||||
accessor std!: BlockStdScope;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { PageEditorBlockSpecs } from '@blocksuite/affine/extensions';
|
||||
import { SignalWatcher, WithDisposable } from '@blocksuite/affine/global/lit';
|
||||
import { noop } from '@blocksuite/affine/global/utils';
|
||||
import { ThemeProvider } from '@blocksuite/affine/shared/services';
|
||||
@@ -7,7 +6,7 @@ import {
|
||||
EditorHost,
|
||||
ShadowlessElement,
|
||||
} from '@blocksuite/affine/std';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import type { ExtensionType, Store } from '@blocksuite/affine/store';
|
||||
import { css, html, nothing } from 'lit';
|
||||
import { property, state } from 'lit/decorators.js';
|
||||
import { guard } from 'lit/directives/guard.js';
|
||||
@@ -104,7 +103,7 @@ export class PageEditor extends SignalWatcher(
|
||||
accessor doc!: Store;
|
||||
|
||||
@property({ attribute: false })
|
||||
accessor specs = PageEditorBlockSpecs;
|
||||
accessor specs: ExtensionType[] = [];
|
||||
|
||||
@state()
|
||||
accessor std!: BlockStdScope;
|
||||
|
||||
@@ -51,7 +51,7 @@ import { getThemeExtension } from '../extensions/theme';
|
||||
|
||||
const optionsSchema = z.object({
|
||||
enableAI: z.boolean().optional(),
|
||||
framework: z.instanceof(FrameworkProvider),
|
||||
framework: z.instanceof(FrameworkProvider).optional(),
|
||||
});
|
||||
|
||||
class MigratingAffineViewExtension extends ViewExtensionProvider<
|
||||
@@ -173,8 +173,8 @@ const manager = new ViewExtensionManager([
|
||||
]);
|
||||
|
||||
export function getViewManager(
|
||||
framework: FrameworkProvider,
|
||||
enableAI: boolean
|
||||
framework?: FrameworkProvider,
|
||||
enableAI?: boolean
|
||||
) {
|
||||
manager.configure(MigratingAffineViewExtension, {
|
||||
framework,
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { StoreExtensions } from '@blocksuite/affine/extensions';
|
||||
import { getStoreManager } from '@affine/core/blocksuite/manager/migrating-store';
|
||||
import { type Store, Text } from '@blocksuite/affine/store';
|
||||
import { TestWorkspace } from '@blocksuite/affine/store/test';
|
||||
import { renderHook } from '@testing-library/react';
|
||||
@@ -13,7 +13,7 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { useBlockSuitePagePreview } from '../use-block-suite-page-preview';
|
||||
let docCollection: TestWorkspace;
|
||||
|
||||
const extensions = StoreExtensions;
|
||||
const extensions = getStoreManager().get('store');
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getViewManager } from '@affine/core/blocksuite/manager/migrating-view';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { PageEditorBlockSpecs } from '@blocksuite/affine/extensions';
|
||||
import { BlockStdScope } from '@blocksuite/affine/std';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
@@ -44,7 +44,7 @@ export function createBlockStdScope(doc: Store) {
|
||||
logger.debug('createBlockStdScope', doc.id);
|
||||
const std = new BlockStdScope({
|
||||
store: doc,
|
||||
extensions: PageEditorBlockSpecs,
|
||||
extensions: getViewManager().get('page'),
|
||||
});
|
||||
return std;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user