Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(mobile): disable some toolbar widgets for mobile #8742

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading