Skip to content

Commit

Permalink
fix(core): fix dependency cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 26, 2024
1 parent cadb921 commit 4331a55
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { ViewBody, ViewHeader } from '@affine/core/modules/workbench';
import type { AttachmentBlockModel } from '@blocksuite/affine/blocks';

import { AttachmentPreviewErrorBoundary, Error } from './error';
import { PDFViewer, type PDFViewerProps } from './pdf-viewer';
import { PDFViewer } from './pdf-viewer';
import * as styles from './styles.css';
import { Titlebar } from './titlebar';
import type { AttachmentViewerProps, PDFViewerProps } from './types';
import { buildAttachmentProps } from './utils';

export type AttachmentViewerProps = {
model: AttachmentBlockModel;
};

// In Peek view
export const AttachmentViewer = ({ model }: AttachmentViewerProps) => {
const props = buildAttachmentProps(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import {
useState,
} from 'react';

import type { PDFViewerProps } from './pdf-viewer';
import * as styles from './styles.css';
import * as embeddedStyles from './styles.embedded.css';
import type { PDFViewerProps } from './types';

function defaultMeta() {
return {
Expand All @@ -40,9 +40,7 @@ function defaultMeta() {
};
}

type PDFViewerEmbeddedInnerProps = PDFViewerProps;

export function PDFViewerEmbeddedInner({ model }: PDFViewerEmbeddedInnerProps) {
export function PDFViewerEmbeddedInner({ model }: PDFViewerProps) {
const scale = window.devicePixelRatio;
const peekView = useService(PeekViewService).peekView;
const pdfService = useService(PDFService);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { AttachmentBlockModel } from '@blocksuite/affine/blocks';

import { AttachmentPreviewErrorBoundary } from './error';
import { PDFViewerEmbeddedInner } from './pdf-viewer-embedded-inner';
import type { AttachmentViewerProps } from './types';
import { buildAttachmentProps } from './utils';

export interface PDFViewerEmbeddedProps {
model: AttachmentBlockModel;
name: string;
ext: string;
size: string;
}

export function PDFViewerEmbedded(props: PDFViewerEmbeddedProps) {
return <PDFViewerEmbeddedInner {...props} />;
}
// In Embed view
export const AttachmentEmbedPreview = ({ model }: AttachmentViewerProps) => {
return (
<AttachmentPreviewErrorBoundary key={model.id}>
<PDFViewerEmbeddedInner {...buildAttachmentProps(model)} />
</AttachmentPreviewErrorBoundary>
);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type PDF, PDFService, PDFStatus } from '@affine/core/modules/pdf';
import { LoadingSvg } from '@affine/core/modules/pdf/views';
import track from '@affine/track';
import type { AttachmentBlockModel } from '@blocksuite/affine/blocks';
import { useLiveData, useService } from '@toeverything/infra';
import { useEffect, useState } from 'react';

import { PDFViewerInner } from './pdf-viewer-inner';
import type { PDFViewerProps } from './types';

function PDFViewerStatus({ pdf, ...props }: PDFViewerProps & { pdf: PDF }) {
const state = useLiveData(pdf.state$);
Expand All @@ -23,13 +23,6 @@ function PDFViewerStatus({ pdf, ...props }: PDFViewerProps & { pdf: PDF }) {
return <PDFViewerInner {...props} pdf={pdf} state={state} />;
}

export interface PDFViewerProps {
model: AttachmentBlockModel;
name: string;
ext: string;
size: string;
}

export function PDFViewer({ model, ...props }: PDFViewerProps) {
const pdfService = useService(PDFService);
const [pdf, setPdf] = useState<PDF | null>(null);
Expand Down
12 changes: 12 additions & 0 deletions packages/frontend/core/src/components/attachment-viewer/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { AttachmentBlockModel } from '@blocksuite/affine/blocks';

export type AttachmentViewerProps = {
model: AttachmentBlockModel;
};

export type PDFViewerProps = {
model: AttachmentBlockModel;
name: string;
ext: string;
size: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import {
toReactNode,
type useConfirmModal,
} from '@affine/component';
import { AttachmentPreviewErrorBoundary } from '@affine/core/components/attachment-viewer/error';
import { PDFViewerEmbedded } from '@affine/core/components/attachment-viewer/pdf-viewer-embedded';
import { buildAttachmentProps } from '@affine/core/components/attachment-viewer/utils';
import { WorkspaceServerService } from '@affine/core/modules/cloud';
import { type DocService, DocsService } from '@affine/core/modules/doc';
import type { EditorService } from '@affine/core/modules/editor';
Expand Down Expand Up @@ -76,6 +73,7 @@ import { customElement } from 'lit/decorators.js';
import { literal } from 'lit/static-html.js';
import { pick } from 'lodash-es';

import { AttachmentEmbedPreview } from '../../../../attachment-viewer/pdf-viewer-embedded';
import { generateUrl } from '../../../../hooks/affine/use-share-url';
import { createKeyboardToolbarConfig } from './widgets/keyboard-toolbar';

Expand Down Expand Up @@ -604,7 +602,10 @@ export function patchForMobile() {
}

export function patchForAttachmentEmbedViews(
reactToLit: (element: ElementOrFactory) => TemplateResult
reactToLit: (
element: ElementOrFactory,
rerendering?: boolean
) => TemplateResult
): ExtensionType {
return {
setup: di => {
Expand All @@ -623,11 +624,7 @@ export function patchForAttachmentEmbedViews(
});
},
template: (model, _blobUrl) =>
reactToLit(
<AttachmentPreviewErrorBoundary key={model.id}>
<PDFViewerEmbedded {...buildAttachmentProps(model)} />
</AttachmentPreviewErrorBoundary>
),
reactToLit(<AttachmentEmbedPreview model={model} />, false),
}));
},
};
Expand Down

0 comments on commit 4331a55

Please sign in to comment.