feat(editor): improve status display in attachment embed view (#12180)

Closes: [BS-3438](https://linear.app/affine-design/issue/BS-3438/attachment-embed-view-中的-status-组件)
Closes: [BS-3447](https://linear.app/affine-design/issue/BS-3447/触发-litportal-re-render)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced a visual status indicator for embedded attachments with reload capability.
  - Added a new resource status component to display error messages and reload actions.
- **Improvements**
  - Enhanced attachment rendering flow with reactive state and unified embed handling.
  - Simplified resource state and blob URL lifecycle management.
  - Added status visibility flags for PDF and video embeds.
- **Bug Fixes**
  - Improved error handling and refresh support for embedded content including PDFs, videos, and audio.
- **Style**
  - Added styles for the attachment embed status indicator positioning.
- **Refactor**
  - Streamlined attachment and resource controller implementations for better maintainability.
- **Tests**
  - Added end-to-end test verifying PDF viewer reload and re-rendering in embed mode.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
fundon
2025-05-10 08:34:47 +00:00
parent 66500669c8
commit b3f0f38b41
11 changed files with 567 additions and 281 deletions

View File

@@ -74,7 +74,7 @@ declare global {
}
}
export type ElementOrFactory = React.ReactElement | (() => React.ReactElement);
export type ElementOrFactory = React.ReactNode | (() => React.ReactNode);
type LitPortal = {
id: string;
@@ -139,18 +139,16 @@ export const useLitPortalFactory = () => {
};
// render a react element to a lit template
export const useLitPortal = (
elementOrFactory: React.ReactElement | (() => React.ReactElement)
) => {
export const useLitPortal = (elementOrFactory: ElementOrFactory) => {
const [anchor, setAnchor] = useState<HTMLElement>();
const template = useMemo(
() =>
createLitPortalAnchor(event => {
let anchor: HTMLElement | undefined;
if (event.name !== 'disconnectedCallback') {
setAnchor(event.target as HTMLElement);
} else {
setAnchor(undefined);
anchor = event.target as HTMLElement;
}
setAnchor(anchor);
}),
[]
);