Skip to content

Commit

Permalink
chore(mobile): disable some toolbar widgets for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Sun committed Nov 8, 2024
1 parent 559fc7c commit b0906c9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
patchDocModeService,
patchEdgelessClipboard,
patchEmbedLinkedDocBlockConfig,
patchForMobile,
patchForSharedPage,
patchNotificationService,
patchParseDocUrlExtension,
Expand Down Expand Up @@ -150,6 +151,9 @@ const usePatchSpecs = (shared: boolean, mode: DocMode) => {
if (shared) {
patched = patched.concat(patchForSharedPage());
}
if (BUILD_CONFIG.isMobileEdition) {
patched = patched.concat(patchForMobile());
}
patched = patched.concat(
patchDocModeService(docService, docsService, editorService)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { combineLatest, map } from 'rxjs';

import { getFontConfigExtension } from '../font-extension';
import { createDatabaseOptionsConfig } from './database-block';
import { createKeyboardToolbarConfig } from './widgets/keyboard-toolbar';
import { createLinkedWidgetConfig } from './widgets/linked';
import { createToolbarMoreMenuConfig } from './widgets/toolbar';

Expand Down Expand Up @@ -150,7 +149,6 @@ function getEditorConfigExtension(
linkedWidget: createLinkedWidgetConfig(framework),
toolbarMoreMenu: createToolbarMoreMenuConfig(framework),
databaseOptions: createDatabaseOptionsConfig(framework),
keyboardToolbar: createKeyboardToolbarConfig(),
} satisfies RootBlockConfig),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import { track } from '@affine/track';
import {
type BlockService,
BlockViewIdentifier,
ConfigIdentifier,
type ExtensionType,
type WidgetComponent,
WidgetViewMapIdentifier,
type WidgetViewMapType,
} from '@blocksuite/affine/block-std';
import { BlockServiceWatcher } from '@blocksuite/affine/block-std';
import type {
Expand All @@ -37,15 +40,19 @@ import type {
PeekOptions,
PeekViewService as BSPeekViewService,
QuickSearchResult,
RootBlockConfig,
RootService,
} from '@blocksuite/affine/blocks';
import {
AFFINE_EMBED_CARD_TOOLBAR_WIDGET,
AFFINE_FORMAT_BAR_WIDGET,
AffineSlashMenuWidget,
DocModeExtension,
EdgelessRootBlockComponent,
EmbedLinkedDocBlockComponent,
EmbedLinkedDocBlockConfigExtension,
NotificationExtension,
pageRootWidgetViewMap,
ParseDocUrlExtension,
PeekViewExtension,
QuickSearchExtension,
Expand All @@ -65,6 +72,8 @@ import { customElement } from 'lit/decorators.js';
import { literal } from 'lit/static-html.js';
import { pick } from 'lodash-es';

import { createKeyboardToolbarConfig } from './widgets/keyboard-toolbar';

export type ReferenceReactRenderer = (
reference: AffineReference
) => React.ReactElement;
Expand Down Expand Up @@ -541,3 +550,60 @@ export function patchForSharedPage() {
};
return extension;
}

export function patchForMobile() {
const extension: ExtensionType = {
setup: di => {
// page configs
{
const pageConfigIdentifier = ConfigIdentifier('affine:page');
const prev = di.getFactory(ConfigIdentifier);

di.override(pageConfigIdentifier, provider => {
return {
...prev?.(provider),
keyboardToolbar: createKeyboardToolbarConfig(),
} satisfies RootBlockConfig;
});
}

// Disable some toolbar widgets for mobile.
{
di.override(WidgetViewMapIdentifier('affine:page'), () => {
const ignoreWidgets = [
AFFINE_FORMAT_BAR_WIDGET,
AFFINE_EMBED_CARD_TOOLBAR_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
);
});

di.override(
WidgetViewMapIdentifier('affine:code'),
(): WidgetViewMapType => ({})
);

di.override(
WidgetViewMapIdentifier('affine:image'),
(): WidgetViewMapType => ({})
);

di.override(
WidgetViewMapIdentifier('affine:surface-ref'),
(): WidgetViewMapType => ({})
);
}
},
};
return extension;
}

0 comments on commit b0906c9

Please sign in to comment.