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

refactor(ui): refactor menu service & config service #3246

Merged
merged 1 commit into from
Sep 4, 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
2 changes: 1 addition & 1 deletion examples/scripts/generate-locales.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { Tools } from '@univerjs/core';
return ` ${dep.replace(/(@univerjs\/|\-)/g, '')}${formattedLocale}`;
}).join(',\n');

acc += `export const ${formattedLocale} = Tools.deepMerge(\n${depStatements}\n);\n`;
acc += `export const ${formattedLocale} = Tools.deepMerge(\n {},\n${depStatements}\n);\n`;
return acc;
}, '');

Expand Down
4 changes: 1 addition & 3 deletions examples/src/mobile-s/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ const univer = new Univer({
univer.registerPlugin(UniverFormulaEnginePlugin);

// core plugins
univer.registerPlugin(UniverDocsPlugin, {
hasScroll: false,
});
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverMobileUIPlugin, { container: 'app', contextMenu: true });
univer.registerPlugin(UniverRPCMainThreadPlugin, {
Expand Down
4 changes: 1 addition & 3 deletions examples/src/sheets-multi/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function factory(id: string) {
univer.registerPlugin(UniverUIPlugin, {
container: id,
});
univer.registerPlugin(UniverDocsPlugin, {
hasScroll: false,
});
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverDocsUIPlugin);

// sheets plugin
Expand Down
4 changes: 1 addition & 3 deletions examples/src/sheets-uniscript/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ univer.registerPlugin(UniverUIPlugin, {
container: 'app',
});

univer.registerPlugin(UniverDocsPlugin, {
hasScroll: false,
});
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverDocsUIPlugin);

univer.registerPlugin(UniverSheetsPlugin);
Expand Down
3 changes: 1 addition & 2 deletions examples/src/sheets/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ univer.registerPlugin(UniverRPCMainThreadPlugin, {
workerURL: './worker.js',
} as IUniverRPCMainThreadConfig);

univer.registerPlugin(UniverDocsPlugin, { hasScroll: false });
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, { container: 'app' });
univer.registerPlugin(UniverDocsUIPlugin);
Expand All @@ -91,7 +91,6 @@ univer.registerPlugin(UniverSheetsConditionalFormattingUIPlugin);

// drawing
univer.registerPlugin(UniverSheetsDrawingUIPlugin);
// univer.registerPlugin(UniverDocsDrawingUIPlugin);

const mockUser = {
userID: 'Owner_qxVnhPbQ',
Expand Down
2 changes: 1 addition & 1 deletion examples/src/slides/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const univer = new Univer({
// core plugins
univer.registerPlugin(UniverRenderEnginePlugin);
univer.registerPlugin(UniverUIPlugin, { container: 'app' });
univer.registerPlugin(UniverDocsPlugin, { hasScroll: false });
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverDocsUIPlugin);
// base-render
univer.registerPlugin(UniverFormulaEnginePlugin);
Expand Down
4 changes: 1 addition & 3 deletions examples/src/uni/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ window.univer = univer;
window.univerAPI = FUniver.newAPI(univer);

function registerBasicPlugins(univer: Univer) {
univer.registerPlugin(UniverDocsPlugin, {
hasScroll: false,
});
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverFormulaEnginePlugin, {
notExecuteFormula: true,
});
Expand Down
52 changes: 52 additions & 0 deletions packages-experimental/uni-docs-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { IMenu2Item } from '@univerjs/ui';
import { RibbonStartGroup } from '@univerjs/ui';
import { FONT_GROUP_MENU_ID, UNI_MENU_POSITIONS } from '@univerjs/uniui';
import { menuSchema as docsUIMenuSchema } from '@univerjs/docs-ui';
import {
DOC_BOLD_MUTATION_ID,
DOC_ITALIC_MUTATION_ID,
DOC_STRIKE_MUTATION_ID,
DOC_UNDERLINE_MUTATION_ID,
DocBoldMenuItemFactory,
DocItalicMenuItemFactory,
DocStrikeThroughMenuItemFactory,
DocUnderlineMenuItemFactory,
} from './menu';

export const menuSchema: IMenu2Item = {
[UNI_MENU_POSITIONS.TOOLBAR_MAIN]: (docsUIMenuSchema as any)[RibbonStartGroup.FORMAT],
[FONT_GROUP_MENU_ID]: {
[DOC_BOLD_MUTATION_ID]: {
order: 0,
menuItemFactory: DocBoldMenuItemFactory,
},
[DOC_ITALIC_MUTATION_ID]: {
order: 1,
menuItemFactory: DocItalicMenuItemFactory,
},
[DOC_UNDERLINE_MUTATION_ID]: {
order: 2,
menuItemFactory: DocUnderlineMenuItemFactory,
},
[DOC_STRIKE_MUTATION_ID]: {
order: 3,
menuItemFactory: DocStrikeThroughMenuItemFactory,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,47 @@
* limitations under the License.
*/

import { ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { IMenuItemFactory } from '@univerjs/ui';
import { ComponentManager, ILayoutService, IMenuService, IShortcutService, IUIPartsService } from '@univerjs/ui';
import { ICommandService, IConfigService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { ComponentManager, ILayoutService, IMenu2Service, IShortcutService, IUIPartsService } from '@univerjs/ui';
import { BuiltinUniToolbarItemId, generateCloneMutation, UniToolbarService } from '@univerjs/uniui';
import type { IUniverDocsUIConfig } from '@univerjs/docs-ui';
import { DocCreateTableOperation, DocUIController } from '@univerjs/docs-ui';
import { BulletListCommand, OrderListCommand, SetInlineFormatBoldCommand, SetInlineFormatFontFamilyCommand, SetInlineFormatFontSizeCommand, SetInlineFormatItalicCommand, SetInlineFormatStrikethroughCommand, SetInlineFormatTextBackgroundColorCommand, SetInlineFormatTextColorCommand, SetInlineFormatUnderlineCommand } from '@univerjs/docs';
import { IMAGE_MENU_ID as DocsImageMenuId } from '@univerjs/docs-drawing-ui';
import { DOC_BOLD_MUTATION_ID, DOC_ITALIC_MUTATION_ID, DOC_STRIKE_MUTATION_ID, DOC_TABLE_MUTATION_ID, DOC_UNDERLINE_MUTATION_ID, DocBoldMenuItemFactory, DocItalicMenuItemFactory, DocStrikeThroughMenuItemFactory, DocTableMenuFactory, DocUnderlineMenuItemFactory } from './menu';
import { DOC_BOLD_MUTATION_ID, DOC_ITALIC_MUTATION_ID, DOC_STRIKE_MUTATION_ID, DOC_TABLE_MUTATION_ID, DOC_UNDERLINE_MUTATION_ID } from './menu';
import { menuSchema } from './menu.schema';

@OnLifecycle(LifecycleStages.Ready, UniDocsUIController)
export class UniDocsUIController extends DocUIController {
constructor(
config: Partial<IUniverDocsUIConfig>,
@Inject(Injector) injector: Injector,
@Inject(ComponentManager) componentManager: ComponentManager,
@ICommandService commandService: ICommandService,
@ILayoutService layoutService: ILayoutService,
@IMenuService menuService: IMenuService,
@IMenu2Service menu2Service: IMenu2Service,
@IUIPartsService uiPartsService: IUIPartsService,
@IUniverInstanceService univerInstanceService: IUniverInstanceService,
@IShortcutService shortcutService: IShortcutService,
@IConfigService configService: IConfigService,
@Inject(UniToolbarService) private readonly _toolbarService: UniToolbarService

) {
super(
config,
injector,
componentManager,
commandService,
layoutService,
menuService,
menu2Service,
uiPartsService,
univerInstanceService,
shortcutService
shortcutService,
configService
);
this._initUniMenus();
this._initMutations();
}

private _initUniMenus(): void {
this._menu2Service.appendRootMenu(menuSchema);

([
[BuiltinUniToolbarItemId.FONT_FAMILY, SetInlineFormatFontFamilyCommand.id],
[BuiltinUniToolbarItemId.FONT_SIZE, SetInlineFormatFontSizeCommand.id],
Expand All @@ -67,18 +67,6 @@ export class UniDocsUIController extends DocUIController {
]).forEach(([id, menuId]) => {
this.disposeWithMe(this._toolbarService.implementItem(id, { id: menuId, type: UniverInstanceType.UNIVER_DOC }));
});

(
[
DocBoldMenuItemFactory,
DocItalicMenuItemFactory,
DocUnderlineMenuItemFactory,
DocStrikeThroughMenuItemFactory,
DocTableMenuFactory,
] as IMenuItemFactory[]
).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
});
}

private _initMutations() {
Expand Down
51 changes: 51 additions & 0 deletions packages-experimental/uni-sheets-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { type IMenu2Item, RibbonStartGroup } from '@univerjs/ui';
import { FONT_GROUP_MENU_ID, UNI_MENU_POSITIONS } from '@univerjs/uniui';
import { menuSchema as sheetsUIMenuSchema } from '@univerjs/sheets-ui';
import {
SHEET_BOLD_MUTATION_ID,
SHEET_ITALIC_MUTATION_ID,
SHEET_STRIKE_MUTATION_ID,
SHEET_UNDERLINE_MUTATION_ID,
SheetBoldMenuItemFactory,
SheetItalicMenuItemFactory,
SheetStrikeThroughMenuItemFactory,
SheetUnderlineMenuItemFactory,
} from './menu';

export const menuSchema: IMenu2Item = {
[UNI_MENU_POSITIONS.TOOLBAR_MAIN]: (sheetsUIMenuSchema as any)[RibbonStartGroup.FORMAT],
[FONT_GROUP_MENU_ID]: {
[SHEET_BOLD_MUTATION_ID]: {
order: 0,
menuItemFactory: SheetBoldMenuItemFactory,
},
[SHEET_ITALIC_MUTATION_ID]: {
order: 1,
menuItemFactory: SheetItalicMenuItemFactory,
},
[SHEET_UNDERLINE_MUTATION_ID]: {
order: 2,
menuItemFactory: SheetUnderlineMenuItemFactory,
},
[SHEET_STRIKE_MUTATION_ID]: {
order: 3,
menuItemFactory: SheetStrikeThroughMenuItemFactory,
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,35 @@

import type { Workbook } from '@univerjs/core';
import { connectInjector, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, useDependency } from '@univerjs/core';
import { type IUniverSheetsUIConfig, RenderSheetContent, SetRangeBoldCommand, SetRangeFontFamilyCommand, SetRangeFontSizeCommand, SetRangeItalicCommand, SetRangeStrickThroughCommand, SetRangeTextColorCommand, SetRangeUnderlineCommand, SheetUIController } from '@univerjs/sheets-ui';
import type { IMenuItemFactory } from '@univerjs/ui';
import { BuiltInUIPart, ComponentManager, ILayoutService, IMenuService, IShortcutService, IUIPartsService, useObservable } from '@univerjs/ui';
import { RenderSheetContent, SetRangeBoldCommand, SetRangeFontFamilyCommand, SetRangeFontSizeCommand, SetRangeItalicCommand, SetRangeStrickThroughCommand, SetRangeTextColorCommand, SetRangeUnderlineCommand, SheetUIController } from '@univerjs/sheets-ui';
import { BuiltInUIPart, ComponentManager, ILayoutService, IMenu2Service, IShortcutService, IUIPartsService, useObservable } from '@univerjs/ui';
import { BuiltinUniToolbarItemId, generateCloneMutation, UniToolbarService, UniUIPart } from '@univerjs/uniui';
import React from 'react';
import { SetBackgroundColorCommand } from '@univerjs/sheets';
import { IMAGE_MENU_ID as SheetsImageMenuId } from '@univerjs/sheets-drawing-ui';
import { UniSheetBar } from '../views/uni-sheet-bar/UniSheetBar';
import { SHEET_BOLD_MUTATION_ID, SHEET_ITALIC_MUTATION_ID, SHEET_STRIKE_MUTATION_ID, SHEET_UNDERLINE_MUTATION_ID, SheetBoldMenuItemFactory, SheetItalicMenuItemFactory, SheetStrikeThroughMenuItemFactory, SheetUnderlineMenuItemFactory } from './menu';
import { SHEET_BOLD_MUTATION_ID, SHEET_ITALIC_MUTATION_ID, SHEET_STRIKE_MUTATION_ID, SHEET_UNDERLINE_MUTATION_ID } from './menu';
import { menuSchema } from './menu.schema';

@OnLifecycle(LifecycleStages.Ready, SheetUIController)
export class UniSheetsUIController extends SheetUIController {
constructor(
config: Partial<IUniverSheetsUIConfig>,
@Inject(Injector) injector: Injector,
@Inject(ComponentManager) componentManager: ComponentManager,
@ILayoutService layoutService: ILayoutService,
@ICommandService commandService: ICommandService,
@IShortcutService shortcutService: IShortcutService,
@IMenuService menuService: IMenuService,
@IMenu2Service menu2Service: IMenu2Service,
@IUIPartsService uiPartsService: IUIPartsService,
@Inject(UniToolbarService) private readonly _toolbarService: UniToolbarService
) {
super(
config,
injector,
componentManager,
layoutService,
commandService,
shortcutService,
menuService,
menu2Service,
uiPartsService
);
this._initUniMenus();
Expand All @@ -63,6 +61,8 @@ export class UniSheetsUIController extends SheetUIController {
}

private _initUniMenus(): void {
this._menu2Service.appendRootMenu(menuSchema);

([
[BuiltinUniToolbarItemId.FONT_FAMILY, SetRangeFontFamilyCommand.id],
[BuiltinUniToolbarItemId.FONT_SIZE, SetRangeFontSizeCommand.id],
Expand All @@ -72,17 +72,6 @@ export class UniSheetsUIController extends SheetUIController {
]).forEach(([id, menuId]) => {
this._toolbarService.implementItem(id, { id: menuId, type: UniverInstanceType.UNIVER_SHEET });
});

(
[
SheetBoldMenuItemFactory,
SheetItalicMenuItemFactory,
SheetUnderlineMenuItemFactory,
SheetStrikeThroughMenuItemFactory,
] as IMenuItemFactory[]
).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
});
}

private _initMutations() {
Expand All @@ -107,4 +96,3 @@ function RenderOutline() {
<UniSheetBar />
);
}

24 changes: 24 additions & 0 deletions packages-experimental/uni-slides-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2023-present DreamNum Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import type { IMenu2Item } from '@univerjs/ui';
import { RibbonStartGroup } from '@univerjs/ui';
import { UNI_MENU_POSITIONS } from '@univerjs/uniui';
import { menuSchema as slidesUIMenuSchema } from '@univerjs/slides-ui';

export const menuSchema: IMenu2Item = {
[UNI_MENU_POSITIONS.TOOLBAR_MAIN]: (slidesUIMenuSchema as any)[RibbonStartGroup.FORMAT],
};
Loading
Loading