From 339bfdae0f0430c8bc072b294c6b596ab4057956 Mon Sep 17 00:00:00 2001 From: L-Sun Date: Mon, 7 Jul 2025 19:17:57 +0800 Subject: [PATCH] fix(editor): centerize iframe modal in mobile (#13073) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Close [BS-3160](https://linear.app/affine-design/issue/BS-3160/新的-embed-输入的-sheet-没有弹起来) #### PR Dependency Tree * **PR #13073** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) ## Summary by CodeRabbit * **Bug Fixes** * Improved popup positioning and responsiveness when using virtual keyboards, ensuring popups remain visible and correctly placed above the keyboard. * Standardized how popups and overlays are created and referenced throughout the app, reducing inconsistencies and potential display issues. * Enhanced stability of date picker, AI panels, and slash menu popovers by refining how their elements are managed and updated. --- .../embed-iframe-block/embed-iframe-block.ts | 43 ++++++++++++++++--- .../affine/blocks/latex/src/latex-block.ts | 2 +- .../affine/components/src/hover/controller.ts | 2 +- .../affine/components/src/portal/helper.ts | 4 +- .../property-presets/date/cell-renderer.ts | 4 +- .../latex/src/latex-node/latex-node.ts | 2 +- .../slash-menu/src/slash-menu-popover.ts | 2 +- .../src/blocksuite/ai/actions/doc-handler.ts | 2 +- .../ai/components/ask-ai-toolbar.ts | 2 +- 9 files changed, 46 insertions(+), 17 deletions(-) diff --git a/blocksuite/affine/blocks/embed/src/embed-iframe-block/embed-iframe-block.ts b/blocksuite/affine/blocks/embed/src/embed-iframe-block/embed-iframe-block.ts index c63d7123d5..326e5f811d 100644 --- a/blocksuite/affine/blocks/embed/src/embed-iframe-block/embed-iframe-block.ts +++ b/blocksuite/affine/blocks/embed/src/embed-iframe-block/embed-iframe-block.ts @@ -11,6 +11,7 @@ import { type IframeOptions, LinkPreviewServiceIdentifier, NotificationProvider, + VirtualKeyboardProvider, } from '@blocksuite/affine-shared/services'; import { matchModels } from '@blocksuite/affine-shared/utils'; import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions'; @@ -213,9 +214,33 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent ({ + mainAxis: + -rects.floating.height - + (window.innerHeight - + rects.floating.height - + keyboard.height$.value) / + 2, + })), + ], + autoUpdate: { animationFrame: true }, + } + : { + referenceElement: this._blockContainer, + placement: 'bottom' as const, + middleware: [flip(), offset(LINK_CREATE_POPUP_OFFSET), shift()], + autoUpdate: { animationFrame: true }, + }; + this._linkInputAbortController = new AbortController(); - createLitPortal({ + const { update } = createLitPortal({ template: html``, container: document.body, - computePosition: { - referenceElement: this._blockContainer, - placement: 'bottom', - middleware: [flip(), offset(LINK_CREATE_POPUP_OFFSET), shift()], - autoUpdate: { animationFrame: true }, - }, + computePosition, abortController: this._linkInputAbortController, closeOnClickAway: true, }); + + if (keyboard) { + this._linkInputAbortController.signal.addEventListener( + 'abort', + keyboard.height$.subscribe(() => { + update(); + }) + ); + } }; /** diff --git a/blocksuite/affine/blocks/latex/src/latex-block.ts b/blocksuite/affine/blocks/latex/src/latex-block.ts index a5a1275870..88d4f33965 100644 --- a/blocksuite/affine/blocks/latex/src/latex-block.ts +++ b/blocksuite/affine/blocks/latex/src/latex-block.ts @@ -116,7 +116,7 @@ export class LatexBlockComponent extends CaptionedBlockComponent {} }; } const visibility = portalRoot.style.visibility; @@ -221,5 +221,5 @@ export function createLitPortal({ }); } - return portalRoot; + return { portal: portalRoot, update }; } diff --git a/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts b/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts index 79d3493305..11c170e267 100644 --- a/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts +++ b/blocksuite/affine/data-view/src/property-presets/date/cell-renderer.ts @@ -78,7 +78,7 @@ export class DateCell extends BaseCellRenderer { }, }); } else { - const root = createLitPortal({ + const { portal } = createLitPortal({ abortController, closeOnClickAway: true, computePosition: { @@ -107,7 +107,7 @@ export class DateCell extends BaseCellRenderer { // for now the slide-layout-modal's z-index is `1001` // the z-index of popover should be higher than it // root.style.zIndex = 'var(--affine-z-index-popover)'; - root.style.zIndex = '1002'; + portal.style.zIndex = '1002'; } }; diff --git a/blocksuite/affine/inlines/latex/src/latex-node/latex-node.ts b/blocksuite/affine/inlines/latex/src/latex-node/latex-node.ts index 5ddcd8833f..ad419c5138 100644 --- a/blocksuite/affine/inlines/latex/src/latex-node/latex-node.ts +++ b/blocksuite/affine/inlines/latex/src/latex-node/latex-node.ts @@ -190,7 +190,7 @@ export class AffineLatexNode extends SignalWatcher( blockComponent.selection.setGroup('note', []); - const portal = createLitPortal({ + const { portal } = createLitPortal({ template: html`