mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
refactor: clean anti pattern editor element
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { CreateView } from '@toeverything/framework/virgo';
|
|
||||||
import {
|
import {
|
||||||
BlockPendantProvider,
|
BlockPendantProvider,
|
||||||
useOnSelect,
|
useOnSelect,
|
||||||
} from '@toeverything/components/editor-core';
|
} from '@toeverything/components/editor-core';
|
||||||
import { Upload } from '../../components/upload/upload';
|
import { CreateView } from '@toeverything/framework/virgo';
|
||||||
|
import { useState } from 'react';
|
||||||
import { SourceView } from '../../components/source-view';
|
import { SourceView } from '../../components/source-view';
|
||||||
import { LinkContainer } from '../../components/style-container';
|
import { LinkContainer } from '../../components/style-container';
|
||||||
|
import { Upload } from '../../components/upload/upload';
|
||||||
|
|
||||||
const MESSAGES = {
|
const MESSAGES = {
|
||||||
ADD_EMBED_LINK: 'Add embed link',
|
ADD_EMBED_LINK: 'Add embed link',
|
||||||
@@ -38,7 +38,6 @@ export const EmbedLinkView = (props: EmbedLinkView) => {
|
|||||||
{embedLinkUrl ? (
|
{embedLinkUrl ? (
|
||||||
<SourceView
|
<SourceView
|
||||||
block={block}
|
block={block}
|
||||||
editorElement={props.editorElement}
|
|
||||||
isSelected={isSelect}
|
isSelected={isSelect}
|
||||||
viewType="embedLink"
|
viewType="embedLink"
|
||||||
link={embedLinkUrl}
|
link={embedLinkUrl}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { memo, useEffect, useRef, useState } from 'react';
|
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
import { memo, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
import { StyledBlockPreview } from '@toeverything/components/common';
|
import { StyledBlockPreview } from '@toeverything/components/common';
|
||||||
|
import { AsyncBlock, useEditor } from '@toeverything/components/editor-core';
|
||||||
import { services } from '@toeverything/datasource/db-service';
|
import { services } from '@toeverything/datasource/db-service';
|
||||||
import { AsyncBlock } from '@toeverything/framework/virgo';
|
|
||||||
import { debounce, sleep } from '@toeverything/utils';
|
import { debounce, sleep } from '@toeverything/utils';
|
||||||
|
|
||||||
const updateTitle = async (
|
const updateTitle = async (
|
||||||
@@ -73,15 +73,15 @@ const useBlockTitle = (block: AsyncBlock, blockId: string) => {
|
|||||||
type BlockPreviewProps = {
|
type BlockPreviewProps = {
|
||||||
block: AsyncBlock;
|
block: AsyncBlock;
|
||||||
blockId: string;
|
blockId: string;
|
||||||
editorElement?: () => JSX.Element;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const InternalBlockPreview = (props: BlockPreviewProps) => {
|
const InternalBlockPreview = (props: BlockPreviewProps) => {
|
||||||
const container = useRef<HTMLDivElement>();
|
const container = useRef<HTMLDivElement>();
|
||||||
const [preview, setPreview] = useState(true);
|
const [preview, setPreview] = useState(true);
|
||||||
const title = useBlockTitle(props.block, props.blockId);
|
const title = useBlockTitle(props.block, props.blockId);
|
||||||
|
const { editorElement } = useEditor();
|
||||||
|
|
||||||
const AffineEditor = props.editorElement as any;
|
const AffineEditor = editorElement as any;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (container?.current) {
|
if (container?.current) {
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import {
|
import {
|
||||||
AsyncBlock,
|
AsyncBlock,
|
||||||
useCurrentView,
|
useCurrentView,
|
||||||
useLazyIframe,
|
|
||||||
} from '@toeverything/components/editor-core';
|
} from '@toeverything/components/editor-core';
|
||||||
import { styled } from '@toeverything/components/ui';
|
import { styled } from '@toeverything/components/ui';
|
||||||
import { ReactElement, ReactNode, useEffect, useRef, useState } from 'react';
|
import { ReactNode, useEffect, useRef, useState } from 'react';
|
||||||
import { SCENE_CONFIG } from '../../blocks/group/config';
|
import { SCENE_CONFIG } from '../../blocks/group/config';
|
||||||
import { BlockPreview } from './BlockView';
|
import { BlockPreview } from './BlockView';
|
||||||
import { formatUrl } from './format-url';
|
import { formatUrl } from './format-url';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
block: AsyncBlock;
|
block: AsyncBlock;
|
||||||
editorElement?: () => JSX.Element;
|
|
||||||
viewType?: string;
|
viewType?: string;
|
||||||
link: string;
|
link: string;
|
||||||
// onResizeEnd: (data: any) => void;
|
// onResizeEnd: (data: any) => void;
|
||||||
@@ -150,7 +148,7 @@ const LoadingContiner = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SourceView = (props: Props) => {
|
export const SourceView = (props: Props) => {
|
||||||
const { link, isSelected, block, editorElement } = props;
|
const { link, isSelected, block } = props;
|
||||||
const src = formatUrl(link);
|
const src = formatUrl(link);
|
||||||
// let iframeShow = useLazyIframe(src, 3000, iframeContainer);
|
// let iframeShow = useLazyIframe(src, 3000, iframeContainer);
|
||||||
const [currentView] = useCurrentView();
|
const [currentView] = useCurrentView();
|
||||||
@@ -161,10 +159,7 @@ export const SourceView = (props: Props) => {
|
|||||||
<SourceViewContainer isSelected={isSelected} scene={type}>
|
<SourceViewContainer isSelected={isSelected} scene={type}>
|
||||||
<MouseMaskContainer />
|
<MouseMaskContainer />
|
||||||
|
|
||||||
<LazyIframe
|
<LazyIframe src={src} fallback={LoadingContiner()} />
|
||||||
src={src}
|
|
||||||
fallback={LoadingContiner()}
|
|
||||||
></LazyIframe>
|
|
||||||
</SourceViewContainer>
|
</SourceViewContainer>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -175,11 +170,7 @@ export const SourceView = (props: Props) => {
|
|||||||
style={{ padding: '0' }}
|
style={{ padding: '0' }}
|
||||||
scene={type}
|
scene={type}
|
||||||
>
|
>
|
||||||
<BlockPreview
|
<BlockPreview block={block} blockId={src} />
|
||||||
block={block}
|
|
||||||
editorElement={editorElement}
|
|
||||||
blockId={src}
|
|
||||||
/>
|
|
||||||
</SourceViewContainer>
|
</SourceViewContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import { SelectBlock } from '../selection';
|
|||||||
export interface CreateView {
|
export interface CreateView {
|
||||||
block: AsyncBlock;
|
block: AsyncBlock;
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
editorElement: () => JSX.Element;
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use recast table instead
|
* @deprecated Use recast table instead
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function RenderBlock({
|
|||||||
blockId,
|
blockId,
|
||||||
hasContainer = true,
|
hasContainer = true,
|
||||||
}: RenderBlockProps) {
|
}: RenderBlockProps) {
|
||||||
const { editor, editorElement } = useEditor();
|
const { editor } = useEditor();
|
||||||
const { block } = useBlock(blockId);
|
const { block } = useBlock(blockId);
|
||||||
|
|
||||||
const setRef = useCallback(
|
const setRef = useCallback(
|
||||||
@@ -50,7 +50,6 @@ export function RenderBlock({
|
|||||||
block={block}
|
block={block}
|
||||||
columns={columns.columns}
|
columns={columns.columns}
|
||||||
columnsFromId={columns.fromId}
|
columnsFromId={columns.fromId}
|
||||||
editorElement={editorElement}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user