From 1d070509042ad8d9decb8f08ed4e068a17ab1464 Mon Sep 17 00:00:00 2001 From: L-Sun Date: Mon, 9 Dec 2024 03:10:26 +0000 Subject: [PATCH] fix(presets): incorrectly adding page root widgets to edgeless (#8897) This PR fixed that page root widgets were added to edgeless mode incorrectly in mobile patch extension. --- .../blocks/src/_specs/preset/mobile-patch.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/packages/blocks/src/_specs/preset/mobile-patch.ts b/packages/blocks/src/_specs/preset/mobile-patch.ts index 5158faf2daf8..8ae75db16a5f 100644 --- a/packages/blocks/src/_specs/preset/mobile-patch.ts +++ b/packages/blocks/src/_specs/preset/mobile-patch.ts @@ -14,7 +14,6 @@ import { import type { CodeBlockConfig } from '../../code-block/code-block-config.js'; -import { pageRootWidgetViewMap } from '../../root-block/page/page-root-spec.js'; import { AFFINE_EMBED_CARD_TOOLBAR_WIDGET } from '../../root-block/widgets/embed-card-toolbar/embed-card-toolbar.js'; import { AFFINE_FORMAT_BAR_WIDGET } from '../../root-block/widgets/format-bar/format-bar.js'; import { AFFINE_SLASH_MENU_WIDGET } from '../../root-block/widgets/slash-menu/index.js'; @@ -55,28 +54,32 @@ export class MobileSpecsPatches extends LifeCycleWatcher { }); } - // Disable some toolbar widgets for mobile. + // Disable root level widgets for mobile. { - di.override(WidgetViewMapIdentifier('affine:page'), () => { + const rootWidgetViewMapIdentifier = + WidgetViewMapIdentifier('affine:page'); + + const prev = di.getFactory(rootWidgetViewMapIdentifier); + + di.override(rootWidgetViewMapIdentifier, provider => { const ignoreWidgets = [ AFFINE_FORMAT_BAR_WIDGET, AFFINE_EMBED_CARD_TOOLBAR_WIDGET, AFFINE_SLASH_MENU_WIDGET, ]; - type pageRootWidgetViewMapKey = keyof typeof pageRootWidgetViewMap; - return ( - Object.keys(pageRootWidgetViewMap) as pageRootWidgetViewMapKey[] - ).reduce( - (acc, key) => { - if (ignoreWidgets.includes(key)) return acc; - acc[key] = pageRootWidgetViewMap[key]; - return acc; - }, - {} as typeof pageRootWidgetViewMap - ); + const newMap = { ...prev?.(provider) }; + + ignoreWidgets.forEach(widget => { + if (widget in newMap) delete newMap[widget]; + }); + + return newMap; }); + } + // Disable block level toolbar widgets for mobile. + { di.override( WidgetViewMapIdentifier('affine:code'), (): WidgetViewMapType => ({})