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

This commit is contained in:
白熱
2024-09-04 11:12:19 +08:00
committed by GitHub
parent ebde3da362
commit 3cf0509308
233 changed files with 5453 additions and 1989 deletions
+1 -1
View File
@@ -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;
}, '');
+1 -3
View File
@@ -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, {
+1 -3
View File
@@ -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
+1 -3
View File
@@ -50,9 +50,7 @@ univer.registerPlugin(UniverUIPlugin, {
container: 'app',
});
univer.registerPlugin(UniverDocsPlugin, {
hasScroll: false,
});
univer.registerPlugin(UniverDocsPlugin);
univer.registerPlugin(UniverDocsUIPlugin);
univer.registerPlugin(UniverSheetsPlugin);
+1 -2
View File
@@ -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);
@@ -91,7 +91,6 @@ univer.registerPlugin(UniverSheetsConditionalFormattingUIPlugin);
// drawing
univer.registerPlugin(UniverSheetsDrawingUIPlugin);
// univer.registerPlugin(UniverDocsDrawingUIPlugin);
const mockUser = {
userID: 'Owner_qxVnhPbQ',
+1 -1
View File
@@ -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);
+1 -3
View File
@@ -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,
});
@@ -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,
},
},
};
@@ -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],
@@ -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() {
@@ -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,
},
},
};
@@ -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();
@@ -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],
@@ -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() {
@@ -107,4 +96,3 @@ function RenderOutline() {
<UniSheetBar />
);
}
@@ -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],
};
@@ -17,25 +17,24 @@
import React from 'react';
import type { SlideDataModel } from '@univerjs/core';
import { connectInjector, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType, useDependency } from '@univerjs/core';
import type { IUniverSlidesDrawingConfig } from '@univerjs/slides-ui';
import { IMAGE_MENU_ID, SHAPE_MENU_ID, SlideAddTextCommand, SlideEditorContainer, SlidesUIController } from '@univerjs/slides-ui';
import { BuiltInUIPart, ComponentManager, IMenuService, IShortcutService, IUIPartsService, useObservable } from '@univerjs/ui';
import { BuiltInUIPart, ComponentManager, IMenu2Service, IShortcutService, IUIPartsService, useObservable } from '@univerjs/ui';
import { BuiltinUniToolbarItemId, UniToolbarService, UniUIPart } from '@univerjs/uniui';
import { UniSlideSideBar } from '../views/UniSlideSideBar';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, UniSlidesUIController)
export class UniSlidesUIController extends SlidesUIController {
constructor(
_config: Partial<IUniverSlidesDrawingConfig>,
@Inject(Injector) _injector: Injector,
@IMenuService _menuService: IMenuService,
@IMenu2Service _menu2Service: IMenu2Service,
@Inject(ComponentManager) _componentManager: ComponentManager,
@IUIPartsService _uiPartsService: IUIPartsService,
@ICommandService _commandService: ICommandService,
@IShortcutService _shortcutService: IShortcutService,
@Inject(UniToolbarService) private readonly _toolbarService: UniToolbarService
) {
super(_config, _injector, _menuService, _componentManager, _uiPartsService, _commandService, _shortcutService);
super(_injector, _menu2Service, _componentManager, _uiPartsService, _commandService, _shortcutService);
this._initUniMenus();
}
@@ -48,6 +47,8 @@ export class UniSlidesUIController extends SlidesUIController {
}
private _initUniMenus(): void {
this._menu2Service.appendRootMenu(menuSchema);
([
[BuiltinUniToolbarItemId.IMAGE, IMAGE_MENU_ID],
[BuiltinUniToolbarItemId.FONT_GROUP, SHAPE_MENU_ID],
+1
View File
@@ -66,6 +66,7 @@
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*",
"@univerjs/uniui": "workspace:*",
"clsx": ">=2.0.0",
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
"react-dom": "^16.9.0 || ^17.0.0 || ^18.0.0",
@@ -0,0 +1,75 @@
/**
* 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 { FONT_GROUP_MENU_ID } from '@univerjs/uniui';
import {
FAKE_BG_COLOR_MENU_ID,
FAKE_FONT_COLOR_MENU_ID,
FAKE_FONT_FAMILY_MENU_ID,
FAKE_FONT_GROUP_MENU_ID,
FAKE_FONT_SIZE_MENU_ID,
FAKE_IMAGE_MENU_ID,
FAKE_ORDER_LIST_MENU_ID,
FAKE_TABLE_MENU_ID,
FAKE_UNORDER_LIST_MENU_ID,
FakeBackgroundColorSelectorMenuItemFactory,
FakeFontFamilySelectorMenuItemFactory,
FakeFontGroupMenuItemFactory,
FakeFontSizeSelectorMenuItemFactory,
FakeImageMenuFactory,
FakeOrderListMenuItemFactory,
FakePivotTableMenuItemFactory,
FakeTextColorSelectorMenuItemFactory,
FakeUnorderListMenuItemFactory,
FontGroupMenuItemFactory,
UNI_MENU_POSITIONS,
} from './menu';
export const menuSchema: IMenu2Item = {
[UNI_MENU_POSITIONS.TOOLBAR_MAIN]: {
[FAKE_FONT_FAMILY_MENU_ID]: {
menuItemFactory: FakeFontFamilySelectorMenuItemFactory,
},
[FAKE_FONT_SIZE_MENU_ID]: {
menuItemFactory: FakeFontSizeSelectorMenuItemFactory,
},
[FAKE_FONT_COLOR_MENU_ID]: {
menuItemFactory: FakeTextColorSelectorMenuItemFactory,
},
[FAKE_BG_COLOR_MENU_ID]: {
menuItemFactory: FakeBackgroundColorSelectorMenuItemFactory,
},
[FAKE_IMAGE_MENU_ID]: {
menuItemFactory: FakeImageMenuFactory,
},
[FAKE_UNORDER_LIST_MENU_ID]: {
menuItemFactory: FakeUnorderListMenuItemFactory,
},
[FAKE_ORDER_LIST_MENU_ID]: {
menuItemFactory: FakeOrderListMenuItemFactory,
},
[FONT_GROUP_MENU_ID]: {
menuItemFactory: FontGroupMenuItemFactory,
},
[FAKE_FONT_GROUP_MENU_ID]: {
menuItemFactory: FakeFontGroupMenuItemFactory,
},
[FAKE_TABLE_MENU_ID]: {
menuItemFactory: FakePivotTableMenuItemFactory,
},
},
};
@@ -16,11 +16,29 @@
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { DeleteSingle, DownloadSingle, LockSingle, PivotTableSingle, PrintSingle, ShareSingle, ZenSingle } from '@univerjs/icons';
import type { IMenuItemFactory, MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import type { MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenu2Service } from '@univerjs/ui';
import { DisposeUnitOperation } from '../commands/operations/uni.operation';
import { UniToolbarService } from '../services/toolbar/uni-toolbar-service';
import { DeleteMenuItemFactory, DownloadMenuItemFactory, FakeBackgroundColorSelectorMenuItemFactory, FakeFontFamilySelectorMenuItemFactory, FakeFontGroupMenuItemFactory, FakeFontSizeSelectorMenuItemFactory, FakeImageMenuFactory, FakeOrderListMenuItemFactory, FakePivotTableMenuItemFactory, FakeTextColorSelectorMenuItemFactory, FakeUnorderListMenuItemFactory, FontGroupMenuItemFactory, LockMenuItemFactory, PrintMenuItemFactory, ShareMenuItemFactory, ZenMenuItemFactory } from './menu';
// import {
// DeleteMenuItemFactory,
// DownloadMenuItemFactory,
// FakeBackgroundColorSelectorMenuItemFactory,
// FakeFontFamilySelectorMenuItemFactory,
// FakeFontGroupMenuItemFactory,
// FakeFontSizeSelectorMenuItemFactory,
// FakeImageMenuFactory,
// FakeOrderListMenuItemFactory,
// FakePivotTableMenuItemFactory,
// FakeTextColorSelectorMenuItemFactory,
// FakeUnorderListMenuItemFactory,
// FontGroupMenuItemFactory,
// LockMenuItemFactory,
// PrintMenuItemFactory,
// ShareMenuItemFactory,
// ZenMenuItemFactory,
// } from './menu';
import { menuSchema } from './menu.schema';
export interface IUniuiToolbarConfig {
menu: MenuConfig;
@@ -31,7 +49,7 @@ export const DefaultUniuiToolbarConfig = {};
@OnLifecycle(LifecycleStages.Ready, UniuiToolbarController)
export class UniuiToolbarController extends Disposable {
constructor(
@IMenuService protected readonly _menuService: IMenuService,
@IMenu2Service protected readonly _menu2Service: IMenu2Service,
@Inject(Injector) protected readonly _injector: Injector,
@Inject(ComponentManager) protected readonly _componentManager: ComponentManager,
@ICommandService protected readonly _commandService: ICommandService,
@@ -60,29 +78,31 @@ export class UniuiToolbarController extends Disposable {
}
private _initMenus(): void {
this._menu2Service.appendRootMenu(menuSchema);
// register menu factories
(
[
DownloadMenuItemFactory,
ShareMenuItemFactory,
LockMenuItemFactory,
PrintMenuItemFactory,
ZenMenuItemFactory,
DeleteMenuItemFactory,
FontGroupMenuItemFactory,
FakeFontFamilySelectorMenuItemFactory,
FakeTextColorSelectorMenuItemFactory,
FakeFontSizeSelectorMenuItemFactory,
FakeBackgroundColorSelectorMenuItemFactory,
FakeImageMenuFactory,
FakeFontGroupMenuItemFactory,
FakePivotTableMenuItemFactory,
FakeOrderListMenuItemFactory,
FakeUnorderListMenuItemFactory,
] as IMenuItemFactory[]
).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
});
// (
// [
// DownloadMenuItemFactory,
// ShareMenuItemFactory,
// LockMenuItemFactory,
// PrintMenuItemFactory,
// ZenMenuItemFactory,
// DeleteMenuItemFactory,
// FontGroupMenuItemFactory,
// FakeFontFamilySelectorMenuItemFactory,
// FakeTextColorSelectorMenuItemFactory,
// FakeFontSizeSelectorMenuItemFactory,
// FakeBackgroundColorSelectorMenuItemFactory,
// FakeImageMenuFactory,
// FakeFontGroupMenuItemFactory,
// FakePivotTableMenuItemFactory,
// FakeOrderListMenuItemFactory,
// FakeUnorderListMenuItemFactory,
// ] as IMenuItemFactory[]
// ).forEach((factory) => {
// this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
// });
}
private _initCommands(): void {
+6 -7
View File
@@ -47,6 +47,7 @@ import {
IGlobalZoneService,
ILayoutService,
ILeftSidebarService,
IMenu2Service,
IMenuService,
IMessageService,
INotificationService,
@@ -58,6 +59,7 @@ import {
IUIController,
IUIPartsService,
IZenZoneService,
Menu2Service,
MenuService,
PlatformService,
ProgressService,
@@ -89,7 +91,7 @@ export class UniverUniUIPlugin extends Plugin {
static override pluginName: string = UNIVER_UI_PLUGIN_NAME;
constructor(
private _config: Partial<IUniverUIConfig> = {},
private readonly _config: Partial<IUniverUIConfig> = {},
@Inject(Injector) protected readonly _injector: Injector,
@IContextService private readonly _contextService: IContextService
) {
@@ -114,6 +116,7 @@ export class UniverUniUIPlugin extends Plugin {
[IShortcutService, { useClass: ShortcutService }],
[IPlatformService, { useClass: PlatformService }],
[IMenuService, { useClass: MenuService }],
[IMenu2Service, { useClass: Menu2Service }],
[IContextMenuService, { useClass: ContextMenuService }],
[IClipboardInterfaceService, { useClass: BrowserClipboardService, lazy: true }],
[INotificationService, { useClass: DesktopNotificationService, lazy: true }],
@@ -134,13 +137,9 @@ export class UniverUniUIPlugin extends Plugin {
[IUIController, {
useFactory: () => this._injector.createInstance(UniverUniUIController, this._config),
}],
[SharedController, {
useFactory: () => this._injector.createInstance(SharedController, this._config),
}],
[SharedController],
[ErrorController],
[ShortcutPanelController, {
useFactory: () => this._injector.createInstance(ShortcutPanelController, this._config),
}],
[ShortcutPanelController],
[UniuiLeftSidebarController],
[UniuiToolbarController],
[UniuiFlowController],
@@ -15,7 +15,7 @@
*/
import { IUniverInstanceService, UniverInstanceType, useDependency, useObservable } from '@univerjs/core';
import { MenuPosition, ToolbarItem, useToolbarGroups } from '@univerjs/ui';
import { IMenu2Service, ToolbarItem } from '@univerjs/ui';
import type { ComponentType } from 'react';
import React from 'react';
import { useWorkbooks } from '@univerjs/sheets-ui';
@@ -24,15 +24,6 @@ import { UniToolbarService } from '../../services/toolbar/uni-toolbar-service';
import styles from './index.module.less';
import { UniFormulaBar } from './UniFormulaBar';
const MENU_POSITIONS = [
MenuPosition.TOOLBAR_START,
MenuPosition.TOOLBAR_INSERT,
MenuPosition.TOOLBAR_FORMULAS,
MenuPosition.TOOLBAR_DATA,
MenuPosition.TOOLBAR_VIEW,
UNI_MENU_POSITIONS.TOOLBAR_MAIN,
];
export interface IToolbarProps {
headerMenuComponents?: Set<ComponentType>;
}
@@ -41,35 +32,38 @@ export function UniToolbar() {
const uniToolbarService = useDependency(UniToolbarService);
const instanceService = useDependency(IUniverInstanceService);
const focusedUnit = useObservable(instanceService.focused$);
const menu2Service = useDependency(IMenu2Service);
const type = focusedUnit ? (instanceService.getUnit(focusedUnit)?.type ?? UniverInstanceType.UNIVER_UNKNOWN) : UniverInstanceType.UNIVER_UNKNOWN;
const { visibleItems } = useToolbarGroups(MENU_POSITIONS);
const menus = menu2Service.getMenuByPositionKey(UNI_MENU_POSITIONS.TOOLBAR_MAIN);
const toolbarItems = uniToolbarService.getItems();
const uniVisibleItems = toolbarItems.map((item) => {
const { impl } = item;
const typeImpl = impl.find((item) => item.type === type);
const visibleItem = visibleItems.find((item) => item.id === typeImpl?.id);
const visibleItem = menus.find((item) => item.key === typeImpl?.id)?.item;
if (visibleItem) {
return visibleItem;
}
const placeHolderImpl = impl.find((item) => item.type === UniverInstanceType.UNIVER_UNKNOWN);
const placeHolderItem = visibleItems.find((item) => item.id === placeHolderImpl?.id);
const placeHolderItem = menus.find((item) => item.key === placeHolderImpl?.id)?.item;
if (placeHolderItem) {
return placeHolderItem;
}
return null;
}).filter((item) => !!item);
}).filter((item) => {
return !!item && !item.id.startsWith('FAKE_');
});
const hasWorkbooks = useWorkbooks().length > 0;
return (
<div className={styles.uniToolbar}>
{ hasWorkbooks && <UniFormulaBar /> }
{hasWorkbooks && <UniFormulaBar />}
<div className={styles.toolbarGroup}>
{uniVisibleItems.map((subItem) => <ToolbarItem key={subItem.id} {...subItem} />)}
{uniVisibleItems.map((subItem) => subItem && <ToolbarItem key={subItem.id} {...subItem} />)}
</div>
</div>
@@ -15,6 +15,7 @@
*/
import { createIdentifier } from '../../common/di';
import { Tools } from '../../shared';
import type { Nullable } from '../../shared/types';
@@ -25,25 +26,49 @@ import type { Nullable } from '../../shared/types';
*/
export const IConfigService = createIdentifier<IConfigService>('univer.config-service');
interface IConfigOptions {
/**
* Whether the configuration is read-only.
* Not implemented yet.
* @ignore
*/
readonly?: boolean;
/**
* Whether to merge the configuration with the existing one.
* @default false
*/
merge?: boolean;
}
export interface IConfigService {
getConfig<T>(id: string, defaultValue: T): T;
getConfig<T>(id: string): Nullable<T>;
setConfig(id: string, value: unknown): void;
deleteConfig(id: string): void;
setConfig(id: string | symbol, value: unknown, options?: IConfigOptions): void;
deleteConfig(id: string): boolean;
}
export class ConfigService implements IConfigService {
private readonly _config: Map<string, any> = new Map();
private readonly _config: Map<string | symbol, any> = new Map();
getConfig<T>(id: string): Nullable<T> {
getConfig<T>(id: string | symbol): Nullable<T> {
return this._config.get(id) as T;
}
setConfig(id: string, value: unknown) {
setConfig(id: string, value: unknown, options?: IConfigOptions): void {
const { merge = false } = options || {};
const existingValue = this._config.get(id) ?? {};
if (merge) {
this._config.set(id, Tools.deepMerge(existingValue, value));
return;
}
this._config.set(id, value);
}
deleteConfig(id: string): void {
this._config.delete(id);
deleteConfig(id: string | symbol): boolean {
return this._config.delete(id);
}
}
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'data-validation.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDataValidationConfig {
}
export const defaultPluginConfig: IUniverDataValidationConfig = {};
+10 -3
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ICommandService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DataValidatorRegistryService } from './services/data-validator-registry.service';
import { DataValidationModel } from './models/data-validation-model';
@@ -22,6 +22,8 @@ import { AddDataValidationCommand, RemoveAllDataValidationCommand, RemoveDataVal
import { AddDataValidationMutation, RemoveDataValidationMutation, UpdateDataValidationMutation } from './commands/mutations/data-validation.mutation';
import { DataValidationResourceController } from './controllers/dv-resource.controller';
import { DataValidationSheetController } from './controllers/dv-sheet.controller';
import type { IUniverDataValidationConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'UNIVER_DATA_VALIDATION_PLUGIN';
@@ -30,11 +32,16 @@ export class UniverDataValidationPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: unknown,
private readonly _config: Partial<IUniverDataValidationConfig> = defaultPluginConfig,
@Inject(Injector) protected _injector: Injector,
@ICommandService private _commandService: ICommandService
@ICommandService private _commandService: ICommandService,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'debugger.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDebuggerConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverDebuggerConfig = {};
@@ -15,8 +15,7 @@
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { IMenuItemFactory, MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import { ComponentManager, IMenu2Service } from '@univerjs/ui';
import { ConfirmOperation } from '../commands/operations/confirm.operation';
import { DialogOperation } from '../commands/operations/dialog.operation';
@@ -38,46 +37,21 @@ import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';
import { ImageDemo } from '../components/Image';
import { ChangeUserCommand } from '../commands/operations/change-user.operation';
import { ShowCellContentOperation } from '../commands/operations/cell.operation';
import {
ChangeUserMenuItemFactory,
ConfirmMenuItemFactory,
CreateEmptySheetMenuItemFactory,
CreateFloatDOMMenuItemFactory,
DialogMenuItemFactory,
DisposeCurrentUnitMenuItemFactory,
DisposeUniverItemFactory,
FloatDomMenuItemFactory,
LocaleMenuItemFactory,
MessageMenuItemFactory,
NotificationMenuItemFactory,
SaveSnapshotSetEditableMenuItemFactory,
SetEditableMenuItemFactory,
ShowCellContentMenuItemFactory,
SidebarMenuItemFactory,
ThemeMenuItemFactory,
UnitMenuItemFactory,
} from './menu';
import { RecordController } from './local-save/record.controller';
import { ExportController } from './local-save/export.controller';
export interface IUniverDebuggerConfig {
menu: MenuConfig;
}
export const DefaultDebuggerConfig = {};
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, DebuggerController)
export class DebuggerController extends Disposable {
constructor(
private readonly _config: Partial<IUniverDebuggerConfig>,
@Inject(Injector) private readonly _injector: Injector,
@IMenuService private readonly _menuService: IMenuService,
@IMenu2Service private readonly _menu2Service: IMenu2Service,
@ICommandService private readonly _commandService: ICommandService,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager
) {
super();
this._initializeContextMenu();
this._initializeMenu();
this._initCustomComponents();
[
@@ -102,30 +76,8 @@ export class DebuggerController extends Disposable {
this._injector.add([RecordController]);
}
private _initializeContextMenu() {
const { menu = {} } = this._config;
([
LocaleMenuItemFactory,
ThemeMenuItemFactory,
NotificationMenuItemFactory,
MessageMenuItemFactory,
DialogMenuItemFactory,
ConfirmMenuItemFactory,
SidebarMenuItemFactory,
SetEditableMenuItemFactory,
SaveSnapshotSetEditableMenuItemFactory,
UnitMenuItemFactory,
DisposeUniverItemFactory,
DisposeCurrentUnitMenuItemFactory,
CreateEmptySheetMenuItemFactory,
FloatDomMenuItemFactory,
CreateFloatDOMMenuItemFactory,
ChangeUserMenuItemFactory,
ShowCellContentMenuItemFactory,
] as IMenuItemFactory[]).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
});
private _initializeMenu() {
this._menu2Service.mergeMenu(menuSchema);
}
private _initCustomComponents(): void {
@@ -0,0 +1,124 @@
/**
* 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, RibbonOthersGroup } from '@univerjs/ui';
import { LocaleOperation } from '../commands/operations/locale.operation';
import {
ChangeUserMenuItemFactory,
ConfirmMenuItemFactory,
CreateEmptySheetMenuItemFactory,
CreateFloatDOMMenuItemFactory,
DialogMenuItemFactory,
DisposeCurrentUnitMenuItemFactory,
DisposeUniverItemFactory,
FLOAT_DOM_ITEM_MENU_ID,
FloatDomMenuItemFactory,
LocaleMenuItemFactory,
MessageMenuItemFactory,
NotificationMenuItemFactory,
SaveSnapshotSetEditableMenuItemFactory,
SetEditableMenuItemFactory,
ShowCellContentMenuItemFactory,
SidebarMenuItemFactory,
ThemeMenuItemFactory,
UNIT_ITEM_MENU_ID,
UnitMenuItemFactory,
} from '../controllers/menu';
import { ThemeOperation } from '../commands/operations/theme.operation';
import { NotificationOperation } from '../commands/operations/notification.operation';
import { ConfirmOperation } from '../commands/operations/confirm.operation';
import { DialogOperation } from '../commands/operations/dialog.operation';
import { MessageOperation } from '../commands/operations/message.operation';
import { SaveSnapshotOptions } from '../commands/operations/save-snapshot.operations';
import { SetEditable } from '../commands/operations/set.editable.operation';
import { SidebarOperation } from '../commands/operations/sidebar.operation';
import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand } from '../commands/commands/unit.command';
import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';
import { ChangeUserCommand } from '../commands/operations/change-user.operation';
import { ShowCellContentOperation } from '../commands/operations/cell.operation';
export const menuSchema: IMenu2Item = {
[RibbonOthersGroup.OTHERS]: {
[LocaleOperation.id]: {
order: 0,
menuItemFactory: LocaleMenuItemFactory,
},
[ThemeOperation.id]: {
order: 1,
menuItemFactory: ThemeMenuItemFactory,
},
[NotificationOperation.id]: {
order: 2,
menuItemFactory: NotificationMenuItemFactory,
},
[DialogOperation.id]: {
order: 3,
menuItemFactory: DialogMenuItemFactory,
},
[ConfirmOperation.id]: {
order: 4,
menuItemFactory: ConfirmMenuItemFactory,
},
[MessageOperation.id]: {
order: 5,
menuItemFactory: MessageMenuItemFactory,
},
[SidebarOperation.id]: {
order: 6,
menuItemFactory: SidebarMenuItemFactory,
},
[SetEditable.id]: {
order: 7,
menuItemFactory: SetEditableMenuItemFactory,
},
[SaveSnapshotOptions.id]: {
order: 8,
menuItemFactory: SaveSnapshotSetEditableMenuItemFactory,
},
[UNIT_ITEM_MENU_ID]: {
order: 9,
menuItemFactory: UnitMenuItemFactory,
[DisposeUniverCommand.id]: {
order: 0,
menuItemFactory: DisposeUniverItemFactory,
},
[DisposeCurrentUnitCommand.id]: {
order: 1,
menuItemFactory: DisposeCurrentUnitMenuItemFactory,
},
[CreateEmptySheetCommand.id]: {
order: 2,
menuItemFactory: CreateEmptySheetMenuItemFactory,
},
},
[FLOAT_DOM_ITEM_MENU_ID]: {
order: 10,
menuItemFactory: FloatDomMenuItemFactory,
[CreateFloatDomCommand.id]: {
order: 0,
menuItemFactory: CreateFloatDOMMenuItemFactory,
},
[ShowCellContentOperation.id]: {
order: 1,
menuItemFactory: ShowCellContentMenuItemFactory,
},
},
[ChangeUserCommand.id]: {
order: 11,
menuItemFactory: ChangeUserMenuItemFactory,
},
},
};
+2 -2
View File
@@ -229,7 +229,7 @@ export function SaveSnapshotSetEditableMenuItemFactory(accessor: IAccessor): IMe
};
}
const UNIT_ITEM_MENU_ID = 'debugger.unit-menu-item';
export const UNIT_ITEM_MENU_ID = 'debugger.unit-menu-item';
export function UnitMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
return {
@@ -274,7 +274,7 @@ export function CreateEmptySheetMenuItemFactory(accessor: IAccessor): IMenuButto
};
}
const FLOAT_DOM_ITEM_MENU_ID = 'debugger.float-dom-menu-item';
export const FLOAT_DOM_ITEM_MENU_ID = 'debugger.float-dom-menu-item';
export function FloatDomMenuItemFactory(): IMenuSelectorItem {
return {
+14 -12
View File
@@ -14,13 +14,14 @@
* limitations under the License.
*/
import { Inject, Injector, Plugin, Tools } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import type { IUniverDebuggerConfig } from './controllers/debugger.controller';
import { DebuggerController, DefaultDebuggerConfig } from './controllers/debugger.controller';
import { DebuggerController } from './controllers/debugger.controller';
import { E2EMemoryController } from './controllers/e2e/e2e-memory.controller';
import { PerformanceMonitorController } from './controllers/performance-monitor.controller';
import type { IUniverDebuggerConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
export class UniverDebuggerPlugin extends Plugin {
static override pluginName = 'DEBUGGER_PLUGIN';
@@ -28,12 +29,18 @@ export class UniverDebuggerPlugin extends Plugin {
private _debuggerController!: DebuggerController;
constructor(
private readonly _config: Partial<IUniverDebuggerConfig> = {},
@Inject(Injector) override readonly _injector: Injector
private readonly _config: Partial<IUniverDebuggerConfig> = defaultPluginConfig,
@Inject(Injector) override readonly _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
this._config = Tools.deepMerge({}, DefaultDebuggerConfig, this._config);
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -42,12 +49,7 @@ export class UniverDebuggerPlugin extends Plugin {
[E2EMemoryController],
] as Dependency[]).forEach((d) => this._injector.add(d));
this._injector.add([
DebuggerController,
{
useFactory: () => this._injector.createInstance(DebuggerController, this._config),
},
]);
this._injector.add([DebuggerController]);
}
getDebuggerController() {
@@ -39,7 +39,7 @@ export interface ITooltipProps {
style?: React.CSSProperties;
}
type NullableTooltipRef = TooltipRef | null;
export type NullableTooltipRef = TooltipRef | null;
export const Tooltip = forwardRef<NullableTooltipRef, ITooltipProps>((props, ref) => {
const {
@@ -14,5 +14,5 @@
* limitations under the License.
*/
export { type ITooltipProps, Tooltip } from './Tooltip';
export { type ITooltipProps, type NullableTooltipRef, Tooltip } from './Tooltip';
export { resizeObserverCtor } from './hooks';
+1 -1
View File
@@ -54,7 +54,7 @@ export { type ISelectProps, Select } from './components/select';
export { type ISelectListProps, SelectList } from './components/select-list';
export { type ISegmentedProps, Segmented } from './components/segmented';
export { type ISliderProps, Slider } from './components/slider';
export { type ITooltipProps, Tooltip, resizeObserverCtor } from './components/tooltip';
export { type ITooltipProps, Tooltip, resizeObserverCtor, type NullableTooltipRef } from './components/tooltip';
export { type ITreeNodeProps, type ITreeProps, Tree, TreeSelectionMode, mergeTreeSelected, findSubTreeFromPath, findNodePathFromTree, filterLeafNode } from './components/tree';
export { Switch } from './components/switch';
export { type ILocale } from './locale/interface';
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'docs-drawing-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsDrawingUIConfig {
}
export const defaultPluginConfig: IUniverDocsDrawingUIConfig = {};
@@ -15,13 +15,12 @@
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { IMenuItemFactory } from '@univerjs/ui';
import { ComponentManager, IMenuService, IShortcutService } from '@univerjs/ui';
import { ComponentManager, IMenu2Service, IShortcutService } from '@univerjs/ui';
import { AddImageSingle } from '@univerjs/icons';
import { UploadFileMenu } from '../views/upload-component/UploadFile';
import { COMPONENT_DOC_UPLOAD_FILE_MENU } from '../views/upload-component/component-name';
import { ImageMenuFactory, ImageUploadIcon, UploadFloatImageMenuFactory } from '../views/menu/image.menu';
import { ImageUploadIcon } from '../views/menu/image.menu';
import { InsertDocImageOperation } from '../commands/operations/insert-image.operation';
import { COMPONENT_DOC_DRAWING_PANEL } from '../views/doc-image-panel/component-name';
import { DocDrawingPanel } from '../views/doc-image-panel/DocDrawingPanel';
@@ -38,13 +37,14 @@ import { GroupDocDrawingCommand } from '../commands/commands/group-doc-drawing.c
import { InsertDocDrawingCommand } from '../commands/commands/insert-doc-drawing.command';
import { IMoveInlineDrawingCommand, ITransformNonInlineDrawingCommand, UpdateDocDrawingDistanceCommand, UpdateDocDrawingWrappingStyleCommand, UpdateDocDrawingWrapTextCommand, UpdateDrawingDocTransformCommand } from '../commands/commands/update-doc-drawing.command';
import { DeleteDrawingsShortcutItem, MoveDrawingDownShortcutItem, MoveDrawingLeftShortcutItem, MoveDrawingRightShortcutItem, MoveDrawingUpShortcutItem } from './shortcuts/drawing.shortcut';
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Ready, DocDrawingUIController)
export class DocDrawingUIController extends Disposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@IMenuService private readonly _menuService: IMenuService,
@IMenu2Service private readonly _menu2Service: IMenu2Service,
@ICommandService private readonly _commandService: ICommandService,
@IShortcutService private readonly _shortcutService: IShortcutService
) {
@@ -61,15 +61,7 @@ export class DocDrawingUIController extends Disposable {
}
private _initMenus(): void {
// init menus
(
[
ImageMenuFactory,
UploadFloatImageMenuFactory,
] as IMenuItemFactory[]
).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), {}));
});
this._menu2Service.mergeMenu(menuSchema);
}
private _initCommands() {
@@ -0,0 +1,37 @@
/**
* 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 {
IMAGE_MENU_ID,
IMAGE_MENU_UPLOAD_FLOAT_ID,
ImageMenuFactory,
UploadFloatImageMenuFactory,
} from '../views/menu/image.menu';
export const menuSchema: IMenu2Item = {
[RibbonStartGroup.LAYOUT]: {
[IMAGE_MENU_ID]: {
order: 0,
menuItemFactory: ImageMenuFactory,
[IMAGE_MENU_UPLOAD_FLOAT_ID]: {
order: 0,
menuItemFactory: UploadFloatImageMenuFactory,
},
},
},
};
+10 -3
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { UniverDrawingUIPlugin } from '@univerjs/drawing-ui';
import { UniverDrawingPlugin } from '@univerjs/drawing';
@@ -27,6 +27,8 @@ import { DocDrawingTransformUpdateController } from './controllers/render-contro
import { DocDrawingAddRemoveController } from './controllers/doc-drawing-notification.controller';
import { DocDrawingTransformerController } from './controllers/doc-drawing-transformer-update.controller';
import { DocRefreshDrawingsService } from './services/doc-refresh-drawings.service';
import type { IUniverDocsDrawingUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'DOCS_DRAWING_UI_PLUGIN';
@@ -36,11 +38,16 @@ export class UniverDocsDrawingUIPlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
_config: undefined,
private readonly _config: Partial<IUniverDocsDrawingUIConfig> = defaultPluginConfig,
@Inject(Injector) protected _injector: Injector,
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -24,7 +24,7 @@ import { COMPONENT_DOC_UPLOAD_FILE_MENU } from '../upload-component/component-na
export const ImageUploadIcon = 'addition-and-subtraction-single';
export const IMAGE_MENU_ID = 'doc.menu.image';
const IMAGE_MENU_UPLOAD_FLOAT_ID = 'doc.menu.image.upload.float';
export const IMAGE_MENU_UPLOAD_FLOAT_ID = 'doc.menu.image.upload.float';
// TODO: @Jocs, remove this when cell support drawing.
const getDisableWhenSelectionInTableObservable = (accessor: IAccessor) => {
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'docs-drawing.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsDrawingConfig {
}
export const defaultPluginConfig: IUniverDocsDrawingConfig = {};
+10 -3
View File
@@ -14,20 +14,27 @@
* limitations under the License.
*/
import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DocDrawingController, DocDrawingLoadController, DOCS_DRAWING_PLUGIN } from './controllers/doc-drawing.controller';
import { DocDrawingService, IDocDrawingService } from './services/doc-drawing.service';
import type { IUniverDocsDrawingConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
export class UniverDocsDrawingPlugin extends Plugin {
static override pluginName = DOCS_DRAWING_PLUGIN;
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
_config: undefined,
@Inject(Injector) override _injector: Injector
private readonly _config: Partial<IUniverDocsDrawingConfig> = defaultPluginConfig,
@Inject(Injector) override _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'docs-hyper-link-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsHyperLinkUIConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverDocsHyperLinkUIConfig = {};
@@ -0,0 +1,37 @@
/**
* 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 { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import { ShowDocHyperLinkEditPopupOperation } from '../commands/operations/popup.operation';
import { AddHyperLinkMenuItemFactory } from './menu';
export const menuSchema: IMenu2Item = {
[RibbonStartGroup.OTHERS]: {
[ShowDocHyperLinkEditPopupOperation.id]: {
order: 0,
menuItemFactory: AddHyperLinkMenuItemFactory,
},
},
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.DATA]: {
[ShowDocHyperLinkEditPopupOperation.id]: {
order: 0,
menuItemFactory: AddHyperLinkMenuItemFactory,
},
},
},
};
@@ -16,7 +16,7 @@
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuService, IShortcutService } from '@univerjs/ui';
import { ComponentManager, IMenu2Service, IShortcutService } from '@univerjs/ui';
import { LinkSingle } from '@univerjs/icons';
import { DocHyperLinkEdit } from '../views/hyper-link-edit';
import { AddDocHyperLinkCommand } from '../commands/commands/add-link.command';
@@ -24,7 +24,8 @@ import { UpdateDocHyperLinkCommand } from '../commands/commands/update-link.comm
import { DeleteDocHyperLinkCommand } from '../commands/commands/delete-link.command';
import { ClickDocHyperLinkOperation, ShowDocHyperLinkEditPopupOperation, ToggleDocHyperLinkInfoPopupOperation } from '../commands/operations/popup.operation';
import { DocLinkPopup } from '../views/hyper-link-popup';
import { AddHyperLinkMenuItemFactory, addLinkShortcut, DOC_LINK_ICON } from './menu';
import { addLinkShortcut, DOC_LINK_ICON } from './menu';
import { menuSchema } from './menu.schema';
export interface IDocHyperLinkUIConfig {
menu: MenuConfig;
@@ -33,10 +34,9 @@ export interface IDocHyperLinkUIConfig {
@OnLifecycle(LifecycleStages.Starting, DocHyperLinkUIController)
export class DocHyperLinkUIController extends Disposable {
constructor(
protected _config: IDocHyperLinkUIConfig,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@ICommandService private readonly _commandService: ICommandService,
@IMenuService private readonly _menuService: IMenuService,
@IMenu2Service private readonly _menu2Service: IMenu2Service,
@Inject(Injector) private readonly _injector: Injector,
@IShortcutService private readonly _shortcutService: IShortcutService
) {
@@ -78,8 +78,6 @@ export class DocHyperLinkUIController extends Disposable {
}
private _initMenus() {
[AddHyperLinkMenuItemFactory].forEach((menuFactory) => {
this.disposeWithMe(this._menuService.addMenuItem(menuFactory(this._injector), {}));
});
this._menu2Service.mergeMenu(menuSchema);
}
}
+14 -9
View File
@@ -14,17 +14,18 @@
* limitations under the License.
*/
import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link';
import { DOC_HYPER_LINK_UI_PLUGIN } from './types/const';
import type { IDocHyperLinkUIConfig } from './controllers/ui.controller';
import { DocHyperLinkUIController } from './controllers/ui.controller';
import { DocHyperLinkPopupService } from './services/hyper-link-popup.service';
import { DocHyperLinkSelectionController } from './controllers/doc-hyper-link-selection.controller';
import { DocHyperLinkRenderController } from './controllers/render-controllers/render.controller';
import { DocHyperLinkEventRenderController } from './controllers/render-controllers/hyper-link-event.render-controller';
import type { IUniverDocsHyperLinkUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
@DependentOn(UniverDocsHyperLinkPlugin)
export class UniverDocsHyperLinkUIPlugin extends Plugin {
@@ -32,21 +33,25 @@ export class UniverDocsHyperLinkUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private _config: IDocHyperLinkUIConfig = { menu: {} },
private readonly _config: Partial<IUniverDocsHyperLinkUIConfig> = defaultPluginConfig,
@Inject(Injector) protected override _injector: Injector,
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
const deps: Dependency[] = [
[DocHyperLinkPopupService],
[DocHyperLinkUIController,
{
useFactory: () => this._injector.createInstance(DocHyperLinkUIController, this._config),
},
],
[DocHyperLinkUIController],
[DocHyperLinkSelectionController],
];
+4 -9
View File
@@ -20,8 +20,7 @@
"keywords": [],
"exports": {
".": "./src/index.ts",
"./*": "./src/*",
"./locale/*": "./src/locale/*.ts"
"./*": "./src/*"
},
"main": "./lib/cjs/index.js",
"module": "./lib/es/index.js",
@@ -41,8 +40,7 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
"./lib/*": "./lib/*",
"./locale/*": "./lib/locale/*.json"
"./lib/*": "./lib/*"
}
},
"directories": {
@@ -59,9 +57,7 @@
"build": "tsc && vite build"
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/docs": "workspace:*",
"rxjs": ">=7.0.0"
"@univerjs/core": "workspace:*"
},
"dependencies": {
"@univerjs/icons": "^0.1.74"
@@ -85,7 +81,6 @@
"require": "./lib/cjs/*",
"types": "./lib/types/index.d.ts"
},
"./lib/*": "./lib/*",
"./locale/*": "./lib/locale/*.json"
"./lib/*": "./lib/*"
}
}
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'docs-hyper-link.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsHyperLinkConfig {
}
export const defaultPluginConfig: IUniverDocsHyperLinkConfig = {};
+10 -3
View File
@@ -14,19 +14,26 @@
* limitations under the License.
*/
import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DOC_HYPER_LINK_PLUGIN, DocHyperLinkResourceController } from './controllers/resource.controller';
import type { IUniverDocsHyperLinkConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
export class UniverDocsHyperLinkPlugin extends Plugin {
static override pluginName = DOC_HYPER_LINK_PLUGIN;
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private _config: unknown,
@Inject(Injector) protected override _injector: Injector
private readonly _config: Partial<IUniverDocsHyperLinkConfig> = defaultPluginConfig,
@Inject(Injector) protected override _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'docs-mention-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsMentionUIConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverDocsMentionUIConfig = {};
@@ -0,0 +1,16 @@
/**
* 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.
*/
+13 -3
View File
@@ -14,23 +14,33 @@
* limitations under the License.
*/
import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DOC_MENTION_UI_PLUGIN } from './types/const/const';
import { DocMentionPopupService } from './services/doc-mention-popup.service';
import { DocMentionUIController } from './controllers/doc-mention-ui.controller';
import { DocMentionTriggerController } from './controllers/doc-mention-trigger.controller';
import { DocMentionService } from './services/doc-mention.service';
import type { IUniverDocsMentionUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
export class UniverDocsMentionUIPlugin extends Plugin {
static override pluginName = DOC_MENTION_UI_PLUGIN;
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private _config: unknown,
@Inject(Injector) protected override _injector: Injector
private readonly _config: Partial<IUniverDocsMentionUIConfig> = defaultPluginConfig,
@Inject(Injector) protected override _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'docs-mention.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsMentionConfig {
}
export const defaultPluginConfig: IUniverDocsMentionConfig = {};
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'docs-thread-comment-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsThreadCommentUIConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverDocsThreadCommentUIConfig = {};
@@ -14,27 +14,20 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import type { MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { ComponentManager, IMenu2Service } from '@univerjs/ui';
import { CommentSingle } from '@univerjs/icons';
import { AddDocCommentComment } from '../commands/commands/add-doc-comment.command';
import { DocThreadCommentPanel } from '../views/doc-thread-comment-panel';
import { ShowCommentPanelOperation, StartAddCommentOperation, ToggleCommentPanelOperation } from '../commands/operations/show-comment-panel.operation';
import { DeleteDocCommentComment } from '../commands/commands/delete-doc-comment.command';
import { AddDocCommentMenuItemFactory, ToolbarDocCommentMenuItemFactory } from './menu';
export interface IDocThreadCommentUIConfig {
menu: MenuConfig;
}
import { menuSchema } from './menu.schema';
@OnLifecycle(LifecycleStages.Rendered, DocThreadCommentUIController)
export class DocThreadCommentUIController extends Disposable {
constructor(
private _config: IDocThreadCommentUIConfig,
@ICommandService private readonly _commandService: ICommandService,
@IMenuService private readonly _menuService: IMenuService,
@Inject(Injector) private readonly _injector: Injector,
@IMenu2Service private readonly _menu2Service: IMenu2Service,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager
) {
super();
@@ -56,12 +49,7 @@ export class DocThreadCommentUIController extends Disposable {
}
private _initMenus() {
[
AddDocCommentMenuItemFactory,
ToolbarDocCommentMenuItemFactory,
].forEach((menuFactory) => {
this.disposeWithMe(this._menuService.addMenuItem(menuFactory(this._injector), this._config.menu));
});
this._menu2Service.mergeMenu(menuSchema);
}
private _initComponents() {
@@ -0,0 +1,40 @@
/**
* 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 { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import {
StartAddCommentOperation,
ToggleCommentPanelOperation,
} from '../commands/operations/show-comment-panel.operation';
import { AddDocCommentMenuItemFactory, ToolbarDocCommentMenuItemFactory } from './menu';
export const menuSchema: IMenu2Item = {
[RibbonStartGroup.OTHERS]: {
[ToggleCommentPanelOperation.id]: {
order: 1,
menuItemFactory: ToolbarDocCommentMenuItemFactory,
},
},
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.DATA]: {
[StartAddCommentOperation.id]: {
order: 1,
menuItemFactory: AddDocCommentMenuItemFactory,
},
},
},
};
+14 -10
View File
@@ -14,16 +14,17 @@
* limitations under the License.
*/
import { DependentOn, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { DependentOn, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { PLUGIN_NAME } from './common/const';
import type { IDocThreadCommentUIConfig } from './controllers/doc-thread-comment-ui.controller';
import { DocThreadCommentUIController } from './controllers/doc-thread-comment-ui.controller';
import { DocThreadCommentService } from './services/doc-thread-comment.service';
import { DocThreadCommentSelectionController } from './controllers/doc-thread-comment-selection.controller';
import { DocThreadCommentRenderController } from './controllers/render-controllers/render.controller';
import type { IUniverDocsThreadCommentUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
@DependentOn(UniverThreadCommentUIPlugin)
export class UniverDocsThreadCommentUIPlugin extends Plugin {
@@ -31,21 +32,24 @@ export class UniverDocsThreadCommentUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private _config: IDocThreadCommentUIConfig = { menu: {} },
private readonly _config: Partial<IUniverDocsThreadCommentUIConfig> = defaultPluginConfig,
@Inject(Injector) protected _injector: Injector,
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
([
[
DocThreadCommentUIController,
{
useFactory: () => this._injector.createInstance(DocThreadCommentUIController, this._config),
},
],
[DocThreadCommentUIController],
[DocThreadCommentSelectionController],
[DocThreadCommentService],
@@ -45,10 +45,3 @@ export const DefaultDocContainerConfig = {
infoBar: true,
toolbar: true,
};
export const DefaultDocUiConfig = {
layout: {
docContainerConfig: DefaultDocContainerConfig,
toolbarConfig: DefaultToolbarConfig,
},
};
@@ -14,21 +14,11 @@
* limitations under the License.
*/
import type { DependencyOverride } from '@univerjs/core';
import type { MenuConfig } from '@univerjs/ui';
export interface ILayout {
docContainerConfig?: DocContainerConfig;
toolbarConfig?: DocToolbarConfig;
}
export interface IUniverDocsUIConfig {
menu?: MenuConfig;
container?: HTMLElement | string;
layout?: ILayout;
override?: DependencyOverride;
}
export interface DocContainerConfig {
outerLeft?: boolean;
@@ -14,26 +14,23 @@
* limitations under the License.
*/
import type { LocaleType } from '@univerjs/core';
import { Inject, Injector, LocaleService, Optional, RxDisposable } from '@univerjs/core';
import { Inject, Injector, Optional, RxDisposable } from '@univerjs/core';
import { ILayoutService } from '@univerjs/ui';
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
import type { IUniverDocsUIConfig } from '../basics';
import { DocContainerUIController } from './doc-container-ui-controller';
export class AppUIController extends RxDisposable {
private _docContainerController: DocContainerUIController;
constructor(
_config: IUniverDocsUIConfig,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@Inject(Injector) private readonly _injector: Injector,
@ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager,
@Optional(ILayoutService) private readonly _layoutService?: ILayoutService
) {
super();
this._docContainerController = this._injector.createInstance(DocContainerUIController, _config);
this._docContainerController = this._injector.createInstance(DocContainerUIController);
this._registerContainer();
}
@@ -45,19 +42,4 @@ export class AppUIController extends RxDisposable {
);
}
}
/**
* Change language
* @param {string} locale new language
*
* e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
*
*/
changeLocale = (locale: string) => {
this._localeService.setLocale(locale as LocaleType);
};
getDocContainerController() {
return this._docContainerController;
}
}
@@ -0,0 +1,38 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
import type { DependencyOverride } from '@univerjs/core';
import type { ILayout } from '../basics';
import { DefaultDocContainerConfig, DefaultToolbarConfig } from '../basics';
export const PLUGIN_CONFIG_KEY = 'docs-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsUIConfig {
menu?: MenuConfig;
container?: HTMLElement | string;
layout?: ILayout;
override?: DependencyOverride;
}
export const defaultPluginConfig: IUniverDocsUIConfig = {
layout: {
docContainerConfig: DefaultDocContainerConfig,
toolbarConfig: DefaultToolbarConfig,
},
};
@@ -15,18 +15,19 @@
*/
import type { LocaleType } from '@univerjs/core';
import { Inject, Injector, LocaleService } from '@univerjs/core';
import { IConfigService, Inject, Injector, LocaleService } from '@univerjs/core';
import type { IUniverDocsUIConfig } from '../basics';
import type { DocContainer } from '../views/doc-container/DocContainer';
import type { IUniverDocsUIConfig } from './config.schema';
import { PLUGIN_CONFIG_KEY } from './config.schema';
export class DocContainerUIController {
private _docContainer?: DocContainer;
constructor(
private readonly _config: IUniverDocsUIConfig,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@Inject(Injector) private readonly _injector: Injector
@Inject(Injector) private readonly _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
// empty
}
@@ -34,7 +35,7 @@ export class DocContainerUIController {
getUIConfig() {
const config = {
injector: this._injector,
config: this._config,
config: this._configService.getConfig<IUniverDocsUIConfig>(PLUGIN_CONFIG_KEY),
changeLocale: this.changeLocale,
getComponent: this.getComponent,
};
@@ -14,9 +14,19 @@
* limitations under the License.
*/
import { connectInjector, Disposable, ICommandService, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { IMenuItemFactory } from '@univerjs/ui';
import { BuiltInUIPart, ComponentManager, ILayoutService, IMenuService, IShortcutService, IUIPartsService } from '@univerjs/ui';
import {
connectInjector,
Disposable,
ICommandService,
IConfigService,
Inject,
Injector,
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
UniverInstanceType,
} from '@univerjs/core';
import { BuiltInUIPart, ComponentManager, ILayoutService, IMenu2Service, IShortcutService, IUIPartsService } from '@univerjs/ui';
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
import { TodoList } from '@univerjs/icons';
@@ -28,7 +38,6 @@ import {
FontFamilyItem,
} from '../components/font-family';
import { FONT_SIZE_COMPONENT, FontSize } from '../components/font-size';
import type { IUniverDocsUIConfig } from '../basics';
import { CoreHeaderFooterCommand, OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
import { SidebarDocHeaderFooterPanelOperation } from '../commands/operations/doc-header-footer-panel.operation';
import { DocFooter } from '../views/doc-footer';
@@ -48,44 +57,23 @@ import {
} from '../shortcuts/toolbar.shortcut';
import { TabShortCut } from '../shortcuts/format.shortcut';
import { BULLET_LIST_TYPE_COMPONENT, BulletListTypePicker, ORDER_LIST_TYPE_COMPONENT, OrderListTypePicker } from '../components/list-type-picker';
import {
AlignCenterMenuItemFactory,
AlignJustifyMenuItemFactory,
AlignLeftMenuItemFactory,
AlignRightMenuItemFactory,
BackgroundColorSelectorMenuItemFactory,
BoldMenuItemFactory,
BulletListMenuItemFactory,
CheckListMenuItemFactory,
FontFamilySelectorMenuItemFactory,
FontSizeSelectorMenuItemFactory,
HeaderFooterMenuItemFactory,
InsertTableMenuFactory,
ItalicMenuItemFactory,
OrderListMenuItemFactory,
ResetBackgroundColorMenuItemFactory,
StrikeThroughMenuItemFactory,
SubscriptMenuItemFactory,
SuperscriptMenuItemFactory,
TableMenuFactory,
TextColorSelectorMenuItemFactory,
UnderlineMenuItemFactory,
} from './menu/menu';
import { CopyMenuFactory, CutMenuFactory, DeleteColumnsMenuItemFactory, DeleteMenuFactory, DeleteRowsMenuItemFactory, DeleteTableMenuItemFactory, InsertColumnLeftMenuItemFactory, InsertColumnRightMenuItemFactory, InsertRowAfterMenuItemFactory, InsertRowBeforeMenuItemFactory, ParagraphSettingMenuFactory, PasteMenuFactory, TableDeleteMenuItemFactory, TableInsertMenuItemFactory } from './menu/context-menu';
import { menuSchema } from './menu.schema';
import type { IUniverDocsUIConfig } from './config.schema';
import { PLUGIN_CONFIG_KEY } from './config.schema';
// FIXME: LifecycleStages.Rendered must be used, otherwise the menu cannot be added to the DOM, but the sheet ui plug-in can be added in LifecycleStages.Ready
@OnLifecycle(LifecycleStages.Rendered, DocUIController)
export class DocUIController extends Disposable {
constructor(
protected readonly _config: Partial<IUniverDocsUIConfig>,
@Inject(Injector) protected readonly _injector: Injector,
@Inject(ComponentManager) protected readonly _componentManager: ComponentManager,
@ICommandService protected readonly _commandService: ICommandService,
@ILayoutService protected readonly _layoutService: ILayoutService,
@IMenuService protected readonly _menuService: IMenuService,
@IMenu2Service protected readonly _menu2Service: IMenu2Service,
@IUIPartsService protected readonly _uiPartsService: IUIPartsService,
@IUniverInstanceService protected readonly _univerInstanceService: IUniverInstanceService,
@IShortcutService protected readonly _shortcutService: IShortcutService
@IShortcutService protected readonly _shortcutService: IShortcutService,
@IConfigService protected readonly _configService: IConfigService
) {
super();
@@ -106,65 +94,14 @@ export class DocUIController extends Disposable {
private _initUiParts() {
const workbook = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
if (this._config.layout?.docContainerConfig?.footer && !workbook) {
const config = this._configService.getConfig<IUniverDocsUIConfig>(PLUGIN_CONFIG_KEY);
if (config?.layout?.docContainerConfig?.footer && !workbook) {
this.disposeWithMe(this._uiPartsService.registerComponent(BuiltInUIPart.FOOTER, () => connectInjector(DocFooter, this._injector)));
}
}
private _initMenus(): void {
const { menu = {} } = this._config;
// init menus
(
[
BoldMenuItemFactory,
ItalicMenuItemFactory,
UnderlineMenuItemFactory,
StrikeThroughMenuItemFactory,
SubscriptMenuItemFactory,
SuperscriptMenuItemFactory,
FontSizeSelectorMenuItemFactory,
FontFamilySelectorMenuItemFactory,
TextColorSelectorMenuItemFactory,
HeaderFooterMenuItemFactory,
TableMenuFactory,
InsertTableMenuFactory,
AlignLeftMenuItemFactory,
AlignCenterMenuItemFactory,
AlignRightMenuItemFactory,
AlignJustifyMenuItemFactory,
OrderListMenuItemFactory,
BulletListMenuItemFactory,
CheckListMenuItemFactory,
ResetBackgroundColorMenuItemFactory,
BackgroundColorSelectorMenuItemFactory,
] as IMenuItemFactory[]
).forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
});
([
CopyMenuFactory,
CutMenuFactory,
PasteMenuFactory,
DeleteMenuFactory,
ParagraphSettingMenuFactory,
TableInsertMenuItemFactory,
InsertRowBeforeMenuItemFactory,
InsertRowAfterMenuItemFactory,
InsertColumnLeftMenuItemFactory,
InsertColumnRightMenuItemFactory,
TableDeleteMenuItemFactory,
DeleteRowsMenuItemFactory,
DeleteColumnsMenuItemFactory,
DeleteTableMenuItemFactory,
] as IMenuItemFactory[]).forEach((factory) => {
try {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
} catch (error) {
}
});
this._menu2Service.mergeMenu(menuSchema);
}
private _initShortCut() {
@@ -0,0 +1,245 @@
/**
* 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 { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import {
AlignCenterCommand,
AlignJustifyCommand,
AlignLeftCommand,
AlignRightCommand,
BulletListCommand,
CheckListCommand,
DeleteLeftCommand,
DocTableDeleteColumnsCommand,
DocTableDeleteRowsCommand,
DocTableDeleteTableCommand,
DocTableInsertColumnLeftCommand,
DocTableInsertColumnRightCommand,
DocTableInsertRowAboveCommand,
DocTableInsertRowBellowCommand,
OrderListCommand,
ResetInlineFormatTextBackgroundColorCommand,
SetInlineFormatBoldCommand,
SetInlineFormatFontFamilyCommand,
SetInlineFormatFontSizeCommand,
SetInlineFormatItalicCommand,
SetInlineFormatStrikethroughCommand,
SetInlineFormatSubscriptCommand,
SetInlineFormatSuperscriptCommand,
SetInlineFormatTextBackgroundColorCommand,
SetInlineFormatTextColorCommand,
SetInlineFormatUnderlineCommand,
} from '@univerjs/docs';
import { DocCreateTableOperation } from '../commands/operations/doc-create-table.operation';
import { OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../commands/commands/clipboard.command';
import { DocParagraphSettingPanelOperation } from '../commands/operations/doc-paragraph-setting-panel.operation';
import {
AlignCenterMenuItemFactory,
AlignJustifyMenuItemFactory,
AlignLeftMenuItemFactory,
AlignRightMenuItemFactory,
BackgroundColorSelectorMenuItemFactory,
BoldMenuItemFactory,
BulletListMenuItemFactory,
CheckListMenuItemFactory,
FontFamilySelectorMenuItemFactory,
FontSizeSelectorMenuItemFactory,
HeaderFooterMenuItemFactory,
InsertTableMenuFactory,
ItalicMenuItemFactory,
OrderListMenuItemFactory,
ResetBackgroundColorMenuItemFactory,
StrikeThroughMenuItemFactory,
SubscriptMenuItemFactory,
SuperscriptMenuItemFactory,
TABLE_MENU_ID,
TableMenuFactory,
TextColorSelectorMenuItemFactory,
UnderlineMenuItemFactory,
} from './menu/menu';
import {
CopyMenuFactory,
CutMenuFactory,
DeleteColumnsMenuItemFactory,
DeleteMenuFactory,
DeleteRowsMenuItemFactory,
DeleteTableMenuItemFactory,
InsertColumnLeftMenuItemFactory,
InsertColumnRightMenuItemFactory,
InsertRowAfterMenuItemFactory,
InsertRowBeforeMenuItemFactory,
ParagraphSettingMenuFactory,
PasteMenuFactory,
TABLE_DELETE_MENU_ID,
TABLE_INSERT_MENU_ID,
TableDeleteMenuItemFactory,
TableInsertMenuItemFactory,
} from './menu/context-menu';
export const menuSchema: IMenu2Item = {
[RibbonStartGroup.FORMAT]: {
[SetInlineFormatBoldCommand.id]: {
order: 0,
menuItemFactory: BoldMenuItemFactory,
},
[SetInlineFormatItalicCommand.id]: {
order: 1,
menuItemFactory: ItalicMenuItemFactory,
},
[SetInlineFormatUnderlineCommand.id]: {
order: 2,
menuItemFactory: UnderlineMenuItemFactory,
},
[SetInlineFormatStrikethroughCommand.id]: {
order: 3,
menuItemFactory: StrikeThroughMenuItemFactory,
},
[SetInlineFormatSubscriptCommand.id]: {
order: 4,
menuItemFactory: SubscriptMenuItemFactory,
},
[SetInlineFormatSuperscriptCommand.id]: {
order: 5,
menuItemFactory: SuperscriptMenuItemFactory,
},
[SetInlineFormatFontSizeCommand.id]: {
order: 6,
menuItemFactory: FontSizeSelectorMenuItemFactory,
},
[SetInlineFormatFontFamilyCommand.id]: {
order: 7,
menuItemFactory: FontFamilySelectorMenuItemFactory,
},
[SetInlineFormatTextColorCommand.id]: {
order: 8,
menuItemFactory: TextColorSelectorMenuItemFactory,
},
[SetInlineFormatTextBackgroundColorCommand.id]: {
order: 9,
menuItemFactory: BackgroundColorSelectorMenuItemFactory,
[ResetInlineFormatTextBackgroundColorCommand.id]: {
order: 0,
menuItemFactory: ResetBackgroundColorMenuItemFactory,
},
},
},
[RibbonStartGroup.LAYOUT]: {
[TABLE_MENU_ID]: {
order: 1,
menuItemFactory: TableMenuFactory,
[DocCreateTableOperation.id]: {
order: 0,
menuItemFactory: InsertTableMenuFactory,
},
},
[AlignLeftCommand.id]: {
order: 2,
menuItemFactory: AlignLeftMenuItemFactory,
},
[AlignCenterCommand.id]: {
order: 3,
menuItemFactory: AlignCenterMenuItemFactory,
},
[AlignRightCommand.id]: {
order: 4,
menuItemFactory: AlignRightMenuItemFactory,
},
[AlignJustifyCommand.id]: {
order: 5,
menuItemFactory: AlignJustifyMenuItemFactory,
},
[OrderListCommand.id]: {
order: 6,
menuItemFactory: OrderListMenuItemFactory,
},
[BulletListCommand.id]: {
order: 7,
menuItemFactory: BulletListMenuItemFactory,
},
[CheckListCommand.id]: {
order: 8,
menuItemFactory: CheckListMenuItemFactory,
},
[OpenHeaderFooterPanelCommand.id]: {
order: 9,
menuItemFactory: HeaderFooterMenuItemFactory,
},
},
[ContextMenuPosition.MAIN_AREA]: {
[ContextMenuGroup.FORMAT]: {
[DocCopyCommand.name]: {
order: 0,
menuItemFactory: CopyMenuFactory,
},
[DocCutCommand.id]: {
order: 1,
menuItemFactory: CutMenuFactory,
},
[DocPasteCommand.id]: {
order: 2,
menuItemFactory: PasteMenuFactory,
},
[DeleteLeftCommand.id]: {
order: 3,
menuItemFactory: DeleteMenuFactory,
},
},
[ContextMenuGroup.LAYOUT]: {
[DocParagraphSettingPanelOperation.id]: {
order: 0,
menuItemFactory: ParagraphSettingMenuFactory,
},
[TABLE_INSERT_MENU_ID]: {
order: 1,
menuItemFactory: TableInsertMenuItemFactory,
[DocTableInsertRowAboveCommand.id]: {
order: 1,
menuItemFactory: InsertRowBeforeMenuItemFactory,
},
[DocTableInsertRowBellowCommand.id]: {
order: 2,
menuItemFactory: InsertRowAfterMenuItemFactory,
},
[DocTableInsertColumnLeftCommand.id]: {
order: 3,
menuItemFactory: InsertColumnLeftMenuItemFactory,
},
[DocTableInsertColumnRightCommand.id]: {
order: 4,
menuItemFactory: InsertColumnRightMenuItemFactory,
},
},
[TABLE_DELETE_MENU_ID]: {
order: 2,
menuItemFactory: TableDeleteMenuItemFactory,
[DocTableDeleteRowsCommand.id]: {
order: 1,
menuItemFactory: DeleteRowsMenuItemFactory,
},
[DocTableDeleteColumnsCommand.id]: {
order: 2,
menuItemFactory: DeleteColumnsMenuItemFactory,
},
[DocTableDeleteTableCommand.id]: {
order: 3,
menuItemFactory: DeleteTableMenuItemFactory,
},
},
},
},
};
@@ -148,7 +148,7 @@ export const DeleteMenuFactory = (accessor: IAccessor): IMenuButtonItem => {
};
};
const TABLE_INSERT_MENU_ID = 'doc.menu.table-insert';
export const TABLE_INSERT_MENU_ID = 'doc.menu.table-insert';
export function TableInsertMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
return {
id: TABLE_INSERT_MENU_ID,
@@ -211,7 +211,7 @@ export function InsertColumnRightMenuItemFactory(accessor: IAccessor): IMenuButt
};
}
const TABLE_DELETE_MENU_ID = 'doc.menu.table-delete';
export const TABLE_DELETE_MENU_ID = 'doc.menu.table-delete';
export function TableDeleteMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
return {
id: TABLE_DELETE_MENU_ID,
@@ -26,7 +26,7 @@ import {
} from '@univerjs/core';
import { RichTextEditingMutation, TextSelectionManagerService } from '@univerjs/docs';
import type { Documents, IRenderContext, IRenderModule } from '@univerjs/engine-render';
import { IContextMenuService, MenuPosition } from '@univerjs/ui';
import { ContextMenuPosition, IContextMenuService } from '@univerjs/ui';
const SKIP_UNIT_IDS = [
DEFAULT_EMPTY_DOCUMENT_VALUE,
@@ -59,7 +59,7 @@ export class DocContextMenuRenderController extends Disposable implements IRende
// Content range context menu
const documentsSubscription = documentsPointerDownObserver.subscribeEvent((event) => {
if (event.button === 2) {
this._contextMenuService.triggerContextMenu(event, MenuPosition.CONTEXT_MENU);
this._contextMenuService.triggerContextMenu(event, ContextMenuPosition.MAIN_AREA);
}
});
this.disposeWithMe(documentsSubscription);
@@ -108,11 +108,12 @@ export class DocRenderController extends RxDisposable implements IRenderModule {
});
// TODO@wzhudev: this shouldn't be a config, because we may render different units at the same time.
const hasScroll = this._configService.getConfig('hasScroll') as Nullable<boolean>;
if (hasScroll !== false) {
// eslint-disable-next-line no-new
new ScrollBar(viewMain);
}
// @jikkai: hasScroll has never been set before, so I commented it out.
// const hasScroll = this._configService.getConfig('hasScroll') as Nullable<boolean>;
// if (hasScroll !== false) {
// eslint-disable-next-line no-new
new ScrollBar(viewMain);
// }
scene.addLayer(
new Layer(scene, [], DOCS_COMPONENT_MAIN_LAYER_INDEX),
+18 -11
View File
@@ -16,15 +16,15 @@
import type {
Dependency } from '@univerjs/core';
import {
ICommandService,
import { ICommandService,
IConfigService,
ILogService,
Inject,
Injector,
IUniverInstanceService,
mergeOverrideWithDependencies,
Plugin,
Tools, UniverInstanceType } from '@univerjs/core';
Plugin, UniverInstanceType } from '@univerjs/core';
import { IEditorService, IShortcutService } from '@univerjs/ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import { DocInterceptorService, DocSkeletonManagerService } from '@univerjs/docs';
@@ -39,8 +39,6 @@ import {
MoveSelectionUpShortcut,
SelectAllShortcut,
} from './shortcuts/cursor.shortcut';
import type { IUniverDocsUIConfig } from './basics';
import { DefaultDocUiConfig } from './basics';
import { DOC_UI_PLUGIN_NAME } from './basics/const/plugin-name';
import { AppUIController } from './controllers';
import { DocUIController } from './controllers/doc-ui.controller';
@@ -67,21 +65,30 @@ import { DocParagraphSettingController } from './controllers/doc-paragraph-setti
import { DocParagraphSettingPanelOperation } from './commands/operations/doc-paragraph-setting-panel.operation';
import { DocParagraphSettingCommand } from './commands/commands/doc-paragraph-setting.command';
import { DocTableController } from './controllers/doc-table.controller';
import type { IUniverDocsUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
export class UniverDocsUIPlugin extends Plugin {
static override pluginName = DOC_UI_PLUGIN_NAME;
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
private readonly _config: IUniverDocsUIConfig,
private readonly _config: Partial<IUniverDocsUIConfig> = defaultPluginConfig,
@Inject(Injector) override _injector: Injector,
@IRenderManagerService private readonly _renderManagerSrv: IRenderManagerService,
@ICommandService private _commandService: ICommandService,
@ILogService private _logService: ILogService
@ILogService private _logService: ILogService,
@IConfigService private readonly _configService: IConfigService
) {
super();
this._config = Tools.deepMerge({}, DefaultDocUiConfig, this._config);
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
this._initDependencies(_injector);
this._initializeShortcut();
this._initCommand();
@@ -127,14 +134,14 @@ export class UniverDocsUIPlugin extends Plugin {
private _initDependencies(injector: Injector) {
const dependencies: Dependency[] = [
[DocUIController, { useFactory: () => this._injector.createInstance(DocUIController, this._config) }],
[DocUIController],
[DocClipboardController],
[DocEditorBridgeController],
[DocAutoFormatController],
[DocTableController],
[DocsRenderService],
[AppUIController, { useFactory: () => this._injector.createInstance(AppUIController, this._config) }],
[AppUIController],
[IDocClipboardService, { useClass: DocClipboardService }],
[DocCanvasPopManagerService],
[DocParagraphSettingController],
+3 -1
View File
@@ -26,8 +26,10 @@ export { DocCanvasPopManagerService } from './services/doc-popup-manager.service
export { docDrawingPositionToTransform, transformToDocDrawingPosition } from './basics/transform-position';
export { DocEventManagerService } from './services/doc-event-manager.service';
export { DocUIController } from './controllers/doc-ui.controller';
// #region - all commands
export { menuSchema } from './controllers/menu.schema';
// #region - all commands
export { DocCopyCommand, DocCutCommand, DocPasteCommand } from './commands/commands/clipboard.command';
export { DocCreateTableOperation } from './commands/operations/doc-create-table.operation';
// #endregion
@@ -16,7 +16,7 @@
import React, { Component, createRef } from 'react';
import type { IUniverDocsUIConfig } from '../../basics';
import type { IUniverDocsUIConfig } from '../../controllers/config.schema';
import style from './index.module.less';
interface IBaseDocContainerProps {
@@ -43,6 +43,7 @@ export class DocContainer extends Component<IBaseDocContainerProps> {
constructor(props: IBaseDocContainerProps) {
super(props);
this.changeSkin(props.config.container as string, 'default');
}
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'docs.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDocsConfig {
}
export const defaultPluginConfig: IUniverDocsConfig = {};
+11 -6
View File
@@ -17,6 +17,7 @@
import type { Dependency, ICommand } from '@univerjs/core';
import {
ICommandService,
IConfigService,
Inject,
Injector,
Plugin,
@@ -64,10 +65,8 @@ import { CreateDocTableCommand } from './commands/commands/table/doc-table-creat
import { DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand } from './commands/commands/table/doc-table-delete.command';
import { DocTableInsertColumnCommand, DocTableInsertColumnLeftCommand, DocTableInsertColumnRightCommand, DocTableInsertRowAboveCommand, DocTableInsertRowBellowCommand, DocTableInsertRowCommand } from './commands/commands/table/doc-table-insert.command';
import { DocTableTabCommand } from './commands/commands/table/doc-table-tab.command';
export interface IUniverDocsConfig {
hasScroll?: boolean;
}
import type { IUniverDocsConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'DOCS_PLUGIN';
@@ -76,10 +75,16 @@ export class UniverDocsPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_DOC;
constructor(
_config: Partial<IUniverDocsConfig> = {},
@Inject(Injector) override _injector: Injector
private readonly _config: Partial<IUniverDocsConfig> = defaultPluginConfig,
@Inject(Injector) override _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
this._initializeDependencies(_injector);
this._initializeCommands();
+1 -1
View File
@@ -22,7 +22,7 @@ export type { IDocObjectParam } from './basics/component-tools';
export { getDocObject, neoGetDocObject, getDocObjectById } from './basics/component-tools';
export * from './basics/docs-view-key';
export { type IUniverDocsConfig, UniverDocsPlugin } from './doc-plugin';
export { UniverDocsPlugin } from './doc-plugin';
export { DocSkeletonManagerService } from './services/doc-skeleton-manager.service';
export { TextSelectionManagerService, serializeDocRange } from './services/text-selection-manager.service';
export { DocStateChangeManagerService, type IDocStateChangeParams } from './services/doc-state-change-manager.service';
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'drawing-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDrawingUIConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverDrawingUIConfig = {};
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector, LifecycleStages, LocaleService, OnLifecycle } from '@univerjs/core';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import { Disposable, ICommandService, Inject, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { ComponentManager } from '@univerjs/ui';
import { COMPONENT_IMAGE_POPUP_MENU } from '../views/image-popup-menu/component-name';
import { ImagePopupMenu } from '../views/image-popup-menu/ImagePopupMenu';
import { AutoImageCropOperation, CloseImageCropOperation, OpenImageCropOperation } from '../commands/operations/image-crop.operation';
@@ -27,11 +27,8 @@ import { SetDrawingAlignOperation } from '../commands/operations/drawing-align.o
@OnLifecycle(LifecycleStages.Rendered, DrawingUIController)
export class DrawingUIController extends Disposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager,
@IMenuService private readonly _menuService: IMenuService,
@ICommandService private readonly _commandService: ICommandService,
@Inject(LocaleService) private readonly _localeService: LocaleService
@ICommandService private readonly _commandService: ICommandService
) {
super();
@@ -44,17 +41,6 @@ export class DrawingUIController extends Disposable {
this.disposeWithMe(componentManager.register(COMPONENT_IMAGE_VIEWER, ImageViewer));
}
private _initMenus(): void {
// init menus
// (
// [
// ] as IMenuItemFactory[]
// ).forEach((factory) => {
// this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
// });
}
private _initCommands() {
[
OpenImageCropOperation,
@@ -68,6 +54,5 @@ export class DrawingUIController extends Disposable {
private _init(): void {
this._initCommands();
this._initCustomComponents();
this._initMenus();
}
}
+12 -3
View File
@@ -14,13 +14,15 @@
* limitations under the License.
*/
import { Inject, Injector, LocaleService, Plugin } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DrawingUpdateController } from './controllers/drawing-update.controller';
import { DrawingUIController } from './controllers/drawing-ui.controller';
import { ImageCropperController } from './controllers/image-cropper.controller';
import { ImageUpdateController } from './controllers/image-update.controller';
import { DrawingRenderService } from './services/drawing-render.service';
import type { IUniverDrawingUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'DRAWING_UI_PLUGIN';
@@ -28,11 +30,18 @@ export class UniverDrawingUIPlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
config: undefined,
private readonly _config: Partial<IUniverDrawingUIConfig> = defaultPluginConfig,
@Inject(Injector) protected _injector: Injector,
@Inject(LocaleService) private readonly _localeService: LocaleService
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -0,0 +1,27 @@
/**
* 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 { DependencyOverride } from '@univerjs/core';
export const PLUGIN_CONFIG_KEY = 'drawing.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverDrawingConfig {
override?: DependencyOverride;
}
export const defaultPluginConfig: IUniverDrawingConfig = {};
+11 -4
View File
@@ -14,13 +14,15 @@
* limitations under the License.
*/
import type { Dependency, DependencyOverride } from '@univerjs/core';
import { Inject, Injector, mergeOverrideWithDependencies, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { IConfigService, Inject, Injector, mergeOverrideWithDependencies, Plugin } from '@univerjs/core';
import { ImageIoService } from './services/image-io-impl.service';
import { DrawingManagerService } from './services/drawing-manager-impl.service';
import { IImageIoService } from './services/image-io.service';
import { IDrawingManagerService } from './services/drawing-manager.service';
import type { IUniverDrawingConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'DRAWING_PLUGIN';
@@ -28,10 +30,15 @@ export class UniverDrawingPlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
private _config: { override?: DependencyOverride },
@Inject(Injector) protected _injector: Injector
private readonly _config: Partial<IUniverDrawingConfig> = defaultPluginConfig,
@Inject(Injector) protected _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -0,0 +1,30 @@
/**
* 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 { Ctor } from '@univerjs/core';
import type { BaseFunction } from '../functions/base-function';
import type { IFunctionNames } from '../basics/function';
export const PLUGIN_CONFIG_KEY = 'engine-formula.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverEngineFormulaConfig {
notExecuteFormula?: boolean;
function?: Array<[Ctor<BaseFunction>, IFunctionNames]>;
}
export const defaultPluginConfig: IUniverEngineFormulaConfig = {};
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { Disposable, ICommandService, IConfigService, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { type Ctor, Optional } from '@univerjs/core';
import { DataSyncPrimaryController } from '@univerjs/rpc';
@@ -57,13 +57,15 @@ import { functionText } from '../functions/text/function-map';
import { functionUniver } from '../functions/univer/function-map';
import { functionWeb } from '../functions/web/function-map';
import { IFunctionService } from '../services/function.service';
import type { IUniverEngineFormulaConfig } from './config.schema';
import { PLUGIN_CONFIG_KEY } from './config.schema';
@OnLifecycle(LifecycleStages.Ready, FormulaController)
export class FormulaController extends Disposable {
constructor(
private _function: Array<[Ctor<BaseFunction>, IFunctionNames]> = [],
@ICommandService private readonly _commandService: ICommandService,
@IFunctionService private readonly _functionService: IFunctionService,
@IConfigService private readonly _configService: IConfigService,
@Optional(DataSyncPrimaryController) private readonly _dataSyncPrimaryController?: DataSyncPrimaryController
) {
super();
@@ -103,6 +105,8 @@ export class FormulaController extends Disposable {
}
private _registerFunctions() {
const config = this._configService.getConfig<IUniverEngineFormulaConfig>(PLUGIN_CONFIG_KEY);
const functions: BaseFunction[] = (
[
...functionArray,
@@ -123,7 +127,7 @@ export class FormulaController extends Disposable {
...functionWeb,
] as Array<[Ctor<BaseFunction>, IFunctionNames]>
)
.concat(this._function)
.concat(config?.function ?? [])
.map((registerObject) => {
const Func = registerObject[0] as Ctor<BaseFunction>;
const name = registerObject[1] as IFunctionNames;
+12 -17
View File
@@ -14,10 +14,9 @@
* limitations under the License.
*/
import { Inject, Injector, Plugin } from '@univerjs/core';
import type { Ctor, Dependency } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import type { IFunctionNames } from './basics/function';
import { CalculateController } from './controller/calculate.controller';
import { FormulaController } from './controller/formula.controller';
import { SetDefinedNameController } from './controller/set-defined-name.controller';
@@ -39,7 +38,6 @@ import { UnionNodeFactory } from './engine/ast-node/union-node';
import { ValueNodeFactory } from './engine/ast-node/value-node';
import { FormulaDependencyGenerator } from './engine/dependency/formula-dependency';
import { Interpreter } from './engine/interpreter/interpreter';
import type { BaseFunction } from './functions/base-function';
import { FormulaDataModel } from './models/formula-data.model';
import { CalculateFormulaService } from './services/calculate-formula.service';
import { FormulaCurrentConfigService, IFormulaCurrentConfigService } from './services/current-data.service';
@@ -55,22 +53,24 @@ import { ISuperTableService, SuperTableService } from './services/super-table.se
import { ActiveDirtyManagerService, IActiveDirtyManagerService } from './services/active-dirty-manager.service';
import { DependencyManagerService, IDependencyManagerService } from './services/dependency-manager.service';
import { SetDependencyController } from './controller/set-dependency.controller';
import type { IUniverEngineFormulaConfig } from './controller/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controller/config.schema';
const PLUGIN_NAME = 'base-formula-engine';
interface IUniverFormulaEngine {
notExecuteFormula?: boolean;
function?: Array<[Ctor<BaseFunction>, IFunctionNames]>;
}
export class UniverFormulaEnginePlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
private _config: IUniverFormulaEngine,
@Inject(Injector) protected override _injector: Injector
private readonly _config: Partial<IUniverEngineFormulaConfig> = defaultPluginConfig,
@Inject(Injector) protected override _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
@@ -93,12 +93,7 @@ export class UniverFormulaEnginePlugin extends Plugin {
[LexerTreeBuilder],
//Controllers
[
FormulaController,
{
useFactory: () => this._injector.createInstance(FormulaController, this._config?.function),
},
],
[FormulaController],
[SetDefinedNameController],
[SetSuperTableController],
];
@@ -21,7 +21,7 @@ import { getColor } from '../../../basics/tools';
import type { UniverRenderingContext } from '../../../context';
import { SheetRowHeaderExtensionRegistry } from '../../extension';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { IARowCfg, IARowCfgObj, IColumnStyleCfg, IRowStyleCfg } from '../interfaces.ts';
import type { IARowCfg, IARowCfgObj, IColumnStyleCfg, IRowStyleCfg } from '../interfaces';
import { SheetExtension } from './sheet-extension';
const UNIQUE_KEY = 'DefaultRowHeaderLayoutExtension';
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'engine-render.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverEngineRenderConfig {
}
export const defaultPluginConfig: IUniverEngineRenderConfig = {};
+10 -3
View File
@@ -14,10 +14,12 @@
* limitations under the License.
*/
import { createIdentifier, Inject, Injector, Plugin } from '@univerjs/core';
import { createIdentifier, IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import { Engine } from './engine';
import { IRenderManagerService, RenderManagerService } from './render-manager/render-manager.service';
import type { IUniverEngineRenderConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
/**
* The global rendering engine.
@@ -30,11 +32,16 @@ export class UniverRenderEnginePlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
_config: undefined,
@Inject(Injector) override readonly _injector: Injector
private readonly _config: Partial<IUniverEngineRenderConfig> = defaultPluginConfig,
@Inject(Injector) override readonly _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
this._injector.add([IRenderingEngine, { useFactory: () => new Engine() }]);
this._injector.add([
@@ -143,7 +143,7 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:
injector.add([
IDescriptionService,
{
useFactory: () => this._injector.createInstance(DescriptionService, undefined),
useFactory: () => this._injector.createInstance(DescriptionService),
},
]);
@@ -144,7 +144,7 @@ function registerFormulaDependencies(injector: Injector) {
injector.add([
IDescriptionService,
{
useFactory: () => injector.createInstance(DescriptionService, undefined),
useFactory: () => injector.createInstance(DescriptionService),
},
]);
@@ -139,7 +139,7 @@ export function createWorksheetTestBed(workbookData?: IWorkbookData, dependencie
injector.add([
IDescriptionService,
{
useFactory: () => this._injector.createInstance(DescriptionService, undefined),
useFactory: () => this._injector.createInstance(DescriptionService),
},
]);
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'find-replace.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverFindReplaceConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverFindReplaceConfig = {};
@@ -29,12 +29,10 @@ import {
toDisposable,
} from '@univerjs/core';
import { SearchSingle16 } from '@univerjs/icons';
import type { MenuConfig } from '@univerjs/ui';
import {
ComponentManager,
import { ComponentManager,
IDialogService,
ILayoutService,
IMenuService,
IMenu2Service,
IShortcutService,
} from '@univerjs/ui';
import { takeUntil } from 'rxjs';
@@ -55,13 +53,7 @@ import {
OpenFindDialogShortcutItem,
OpenReplaceDialogShortcutItem,
} from './find-replace.shortcut';
import { FindReplaceMenuItemFactory } from './find-replace.menu';
export interface IUniverFindReplaceConfig {
menu: MenuConfig;
}
export const DefaultFindReplaceConfig = {};
import { menuSchema } from './menu.schema';
const FIND_REPLACE_DIALOG_ID = 'DESKTOP_FIND_REPLACE_DIALOG';
@@ -72,9 +64,8 @@ const FIND_REPLACE_PANEL_TOP_PADDING = -90;
@OnLifecycle(LifecycleStages.Rendered, FindReplaceController)
export class FindReplaceController extends RxDisposable {
constructor(
private readonly _config: Partial<IUniverFindReplaceConfig>,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IMenuService private readonly _menuService: IMenuService,
@IMenu2Service private readonly _menu2Service: IMenu2Service,
@IShortcutService private readonly _shortcutService: IShortcutService,
@ICommandService private readonly _commandService: ICommandService,
@IFindReplaceService private readonly _findReplaceService: IFindReplaceService,
@@ -122,12 +113,11 @@ export class FindReplaceController extends RxDisposable {
}
private _initUI(): void {
const { menu = {} } = this._config;
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(FindReplaceMenuItemFactory), menu));
this.disposeWithMe(this._componentManager.register('FindReplaceDialog', FindReplaceDialog));
this.disposeWithMe(this._componentManager.register('SearchIcon', SearchSingle16));
this._menu2Service.mergeMenu(menuSchema);
// this controller is also responsible for toggling the FindReplaceDialog
this._findReplaceService.stateUpdates$.pipe(takeUntil(this.dispose$)).subscribe((newState) => {
if (newState.revealed === true) {
@@ -0,0 +1,29 @@
/**
* 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 { OpenFindDialogOperation } from '../commands/operations/find-replace.operation';
import { FindReplaceMenuItemFactory } from './find-replace.menu';
export const menuSchema: IMenu2Item = {
[RibbonStartGroup.OTHERS]: {
[OpenFindDialogOperation.id]: {
order: 2,
menuItemFactory: FindReplaceMenuItemFactory,
},
},
};
+10 -12
View File
@@ -14,12 +14,13 @@
* limitations under the License.
*/
import { LocaleService, Plugin, Tools } from '@univerjs/core';
import { IConfigService, Plugin } from '@univerjs/core';
import { type Dependency, Inject, Injector } from '@univerjs/core';
import type { IUniverFindReplaceConfig } from './controllers/find-replace.controller';
import { DefaultFindReplaceConfig, FindReplaceController } from './controllers/find-replace.controller';
import { FindReplaceController } from './controllers/find-replace.controller';
import { FindReplaceService, IFindReplaceService } from './services/find-replace.service';
import type { IUniverFindReplaceConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
const PLUGIN_NAME = 'FIND_REPLACE_PLUGIN';
@@ -27,23 +28,20 @@ export class UniverFindReplacePlugin extends Plugin {
static override pluginName = PLUGIN_NAME;
constructor(
private readonly _config: Partial<IUniverFindReplaceConfig> = {},
private readonly _config: Partial<IUniverFindReplaceConfig> = defaultPluginConfig,
@Inject(Injector) override readonly _injector: Injector,
@Inject(LocaleService) private readonly _localeService: LocaleService
@IConfigService private readonly _configService: IConfigService
) {
super();
this._config = Tools.deepMerge({}, DefaultFindReplaceConfig, this._config);
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
}
override onStarting(): void {
([
[
FindReplaceController,
{
useFactory: () => this._injector.createInstance(FindReplaceController, this._config),
},
],
[FindReplaceController],
[IFindReplaceService, { useClass: FindReplaceService }],
] as Dependency[]).forEach(
(d) => {
@@ -0,0 +1,34 @@
/**
* 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.
*/
export const PLUGIN_CONFIG_KEY_MAIN_THREAD = 'rpc.main-thread.config';
export const configSymbolMainThread = Symbol(PLUGIN_CONFIG_KEY_MAIN_THREAD);
export interface IUniverRPCMainThreadConfig {
workerURL?: string | URL | Worker;
}
export const defaultPluginMainThreadConfig: IUniverRPCMainThreadConfig = {};
export const PLUGIN_CONFIG_KEY_WORKER_THREAD = 'rpc.worker-thread.config';
export const configSymbolWorkerThread = Symbol(PLUGIN_CONFIG_KEY_WORKER_THREAD);
export interface IUniverRPCWorkerThreadConfig {
}
export const defaultPluginWorkerThreadConfig: IUniverRPCWorkerThreadConfig = {};
+2 -1
View File
@@ -15,7 +15,6 @@
*/
export {
type IUniverRPCMainThreadConfig,
UniverRPCMainThreadPlugin,
UniverRPCWorkerThreadPlugin,
} from './plugin';
@@ -31,3 +30,5 @@ export {
export { ChannelService, IRPCChannelService } from './services/rpc/channel.service';
export { ChannelClient, ChannelServer, type IMessageProtocol, fromModule, toModule } from './services/rpc/rpc.service';
export { IRemoteSyncService } from './services/remote-instance/remote-instance.service';
export type { IUniverRPCMainThreadConfig, IUniverRPCWorkerThreadConfig } from './controllers/config.schema';
+27 -9
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Inject, Injector, Plugin } from '@univerjs/core';
import { IConfigService, Inject, Injector, Plugin } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { DataSyncPrimaryController } from './controllers/data-sync/data-sync-primary.controller';
@@ -30,10 +30,14 @@ import {
createWebWorkerMessagePortOnMain,
createWebWorkerMessagePortOnWorker,
} from './services/rpc/implementations/web-worker-rpc.service';
export interface IUniverRPCMainThreadConfig {
workerURL: string | URL | Worker;
}
import type {
IUniverRPCMainThreadConfig,
IUniverRPCWorkerThreadConfig } from './controllers/config.schema';
import {
defaultPluginMainThreadConfig,
defaultPluginWorkerThreadConfig,
PLUGIN_CONFIG_KEY_MAIN_THREAD, PLUGIN_CONFIG_KEY_WORKER_THREAD,
} from './controllers/config.schema';
/**
* This plugin is used to register the RPC services on the main thread. It
@@ -45,10 +49,15 @@ export class UniverRPCMainThreadPlugin extends Plugin {
private _internalWorker: Worker | null = null;
constructor(
private readonly _config: IUniverRPCMainThreadConfig,
@Inject(Injector) protected readonly _injector: Injector
private readonly _config: Partial<IUniverRPCMainThreadConfig> = defaultPluginMainThreadConfig,
@Inject(Injector) protected readonly _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY_MAIN_THREAD, rest);
}
override dispose(): void {
@@ -62,6 +71,10 @@ export class UniverRPCMainThreadPlugin extends Plugin {
override onStarting(): void {
const { workerURL } = this._config;
if (!workerURL) {
throw new Error('[UniverRPCMainThreadPlugin]: The workerURL is required for the RPC main thread plugin.');
}
const worker = workerURL instanceof Worker ? workerURL : new Worker(workerURL);
this._internalWorker = workerURL instanceof Worker ? null : worker;
@@ -91,10 +104,15 @@ export class UniverRPCWorkerThreadPlugin extends Plugin {
static override pluginName = 'UNIVER_RPC_WORKER_THREAD_PLUGIN';
constructor(
private readonly _config: unknown,
@Inject(Injector) protected readonly _injector: Injector
private readonly _config: Partial<IUniverRPCWorkerThreadConfig> = defaultPluginWorkerThreadConfig,
@Inject(Injector) protected readonly _injector: Injector,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY_WORKER_THREAD, rest);
}
override onStarting(): void {
@@ -19,7 +19,7 @@ import { CommandType, ICommandService } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';
import { CFRuleType, CFSubRuleType, createDefaultRule } from '@univerjs/sheets-conditional-formatting';
import type { IColorScale, IConditionFormattingRule, IDataBar, IFormulaHighlightCell, IIconSet, IRankHighlightCell } from '@univerjs/sheets-conditional-formatting';
import { ConditionalFormattingMenuController } from '../../controllers/cf.menu.controller';
import { ConditionalFormattingPanelController } from '../../controllers/cf.panel.controller';
import type { IClearRangeCfParams } from '../commands/clear-range-cf.command';
import { ClearRangeCfCommand } from '../commands/clear-range-cf.command';
import { ClearWorksheetCfCommand } from '../commands/clear-worksheet-cf.command';
@@ -40,11 +40,12 @@ export enum CF_MENU_OPERATION {
clearRangeRules,
clearWorkSheetRules,
}
export const OpenConditionalFormattingOperator: ICommand = {
id: 'sheet.operation.open.conditional.formatting.panel',
type: CommandType.OPERATION,
handler: (accessor: IAccessor, params: IOpenConditionalFormattingOperatorParams) => {
const conditionalFormattingMenuController = accessor.get(ConditionalFormattingMenuController);
const conditionalFormattingMenuController = accessor.get(ConditionalFormattingPanelController);
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
@@ -15,66 +15,20 @@
*/
import type { IDisposable } from '@univerjs/core';
import { Disposable, Inject, Injector, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, Tools, UniverInstanceType } from '@univerjs/core';
import type { MenuConfig } from '@univerjs/ui';
import { ComponentManager, IMenuService, ISidebarService } from '@univerjs/ui';
import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
import { FactoryManageConditionalFormattingRule } from '../menu/manage-rule';
import { ConditionFormattingPanel } from '../components/panel';
import { Disposable, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { IMenu2Service } from '@univerjs/ui';
import { menuSchema } from './menu.schema';
export interface IUniverSheetsConditionalFormattingUIConfig {
menu: MenuConfig;
}
export const DefaultSheetConditionalFormattingUiConfig = {};
const CF_PANEL_KEY = 'sheet.conditional.formatting.panel';
@OnLifecycle(LifecycleStages.Ready, ConditionalFormattingMenuController)
export class ConditionalFormattingMenuController extends Disposable {
private _sidebarDisposable: IDisposable | null = null;
constructor(
private readonly _config: Partial<IUniverSheetsConditionalFormattingUIConfig>,
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(Injector) private _injector: Injector,
@Inject(ComponentManager) private _componentManager: ComponentManager,
@Inject(IMenuService) private _menuService: IMenuService,
@Inject(ISidebarService) private _sidebarService: ISidebarService,
@Inject(LocaleService) private _localeService: LocaleService
@IMenu2Service private readonly _menu2Service: IMenu2Service
) {
super();
this._initMenu();
this._initPanel();
this.disposeWithMe(
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((sheet) => {
if (!sheet) this._sidebarDisposable?.dispose();
})
);
}
openPanel(rule?: IConditionFormattingRule) {
const props = {
header: { title: this._localeService.t('sheet.cf.title') },
children: {
label: CF_PANEL_KEY,
rule,
key: Tools.generateRandomId(4),
},
onClose: () => this._sidebarDisposable = null,
};
this._sidebarDisposable = this._sidebarService.open(props);
}
private _initMenu() {
const { menu = {} } = this._config;
this._menuService.addMenuItem(FactoryManageConditionalFormattingRule(this._injector), menu);
}
private _initPanel() {
this._componentManager.register(CF_PANEL_KEY, ConditionFormattingPanel);
this._menu2Service.mergeMenu(menuSchema);
}
}
@@ -0,0 +1,63 @@
/**
* 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 { IDisposable } from '@univerjs/core';
import { Disposable, generateRandomId, Inject, Injector, IUniverInstanceService, LifecycleStages, LocaleService, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import { ComponentManager, ISidebarService } from '@univerjs/ui';
import type { IConditionFormattingRule } from '@univerjs/sheets-conditional-formatting';
import { ConditionFormattingPanel } from '../components/panel';
const CF_PANEL_KEY = 'sheet.conditional.formatting.panel';
@OnLifecycle(LifecycleStages.Ready, ConditionalFormattingPanelController)
export class ConditionalFormattingPanelController extends Disposable {
private _sidebarDisposable: IDisposable | null = null;
constructor(
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(Injector) private _injector: Injector,
@Inject(ComponentManager) private _componentManager: ComponentManager,
@Inject(ISidebarService) private _sidebarService: ISidebarService,
@Inject(LocaleService) private _localeService: LocaleService
) {
super();
this._initPanel();
this.disposeWithMe(
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).subscribe((sheet) => {
if (!sheet) this._sidebarDisposable?.dispose();
})
);
}
openPanel(rule?: IConditionFormattingRule) {
const props = {
header: { title: this._localeService.t('sheet.cf.title') },
children: {
label: CF_PANEL_KEY,
rule,
key: generateRandomId(4),
},
onClose: () => this._sidebarDisposable = null,
};
this._sidebarDisposable = this._sidebarService.open(props);
}
private _initPanel() {
this._componentManager.register(CF_PANEL_KEY, ConditionFormattingPanel);
}
}
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'sheets-conditional-formatting-ui.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverSheetsConditionalFormattingUIConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverSheetsConditionalFormattingUIConfig = {};
@@ -0,0 +1,29 @@
/**
* 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 { OpenConditionalFormattingOperator } from '../commands/operations/open-conditional-formatting-panel';
import { FactoryManageConditionalFormattingRule } from '../menu/manage-rule';
export const menuSchema: IMenu2Item = {
[RibbonStartGroup.FORMULAS_INSERT]: {
[OpenConditionalFormattingOperator.id]: {
order: 0,
menuItemFactory: FactoryManageConditionalFormattingRule,
},
},
};
@@ -27,52 +27,57 @@ import { AddConditionalRuleMutation, ConditionalFormattingRuleModel, DeleteCondi
import { getCurrentRangeDisable$ } from '@univerjs/sheets-ui';
import { CF_MENU_OPERATION, OpenConditionalFormattingOperator } from '../commands/operations/open-conditional-formatting-panel';
const commandList = [SetWorksheetActiveOperation.id, AddConditionalRuleMutation.id, SetConditionalRuleMutation.id, DeleteConditionalRuleMutation.id, MoveConditionalRuleMutation.id];
const commandList = [
SetWorksheetActiveOperation.id,
AddConditionalRuleMutation.id,
SetConditionalRuleMutation.id,
DeleteConditionalRuleMutation.id,
MoveConditionalRuleMutation.id,
];
const commonSelections = [
{
label: 'sheet.cf.ruleType.highlightCell',
value: CF_MENU_OPERATION.highlightCell,
},
{
label: 'sheet.cf.panel.rankAndAverage',
value: CF_MENU_OPERATION.rank,
},
{
label: 'sheet.cf.ruleType.formula',
value: CF_MENU_OPERATION.formula,
},
{
label: 'sheet.cf.ruleType.colorScale',
value: CF_MENU_OPERATION.colorScale,
},
{
label: 'sheet.cf.ruleType.dataBar',
value: CF_MENU_OPERATION.dataBar,
}, {
label: 'sheet.cf.ruleType.iconSet',
value: CF_MENU_OPERATION.icon,
},
{
label: 'sheet.cf.menu.manageConditionalFormatting',
value: CF_MENU_OPERATION.viewRule,
}, {
label: 'sheet.cf.menu.createConditionalFormatting',
value: CF_MENU_OPERATION.createRule,
},
{
label: 'sheet.cf.menu.clearRangeRules',
value: CF_MENU_OPERATION.clearRangeRules,
disabled: false,
},
{
label: 'sheet.cf.menu.clearWorkSheetRules',
value: CF_MENU_OPERATION.clearWorkSheetRules,
},
];
// eslint-disable-next-line max-lines-per-function
export const FactoryManageConditionalFormattingRule = (accessor: IAccessor): IMenuSelectorItem => {
const commonSelections = [
{
label: 'sheet.cf.ruleType.highlightCell',
value: CF_MENU_OPERATION.highlightCell,
},
{
label: 'sheet.cf.panel.rankAndAverage',
value: CF_MENU_OPERATION.rank,
},
{
label: 'sheet.cf.ruleType.formula',
value: CF_MENU_OPERATION.formula,
},
{
label: 'sheet.cf.ruleType.colorScale',
value: CF_MENU_OPERATION.colorScale,
},
{
label: 'sheet.cf.ruleType.dataBar',
value: CF_MENU_OPERATION.dataBar,
}, {
label: 'sheet.cf.ruleType.iconSet',
value: CF_MENU_OPERATION.icon,
},
{
label: 'sheet.cf.menu.manageConditionalFormatting',
value: CF_MENU_OPERATION.viewRule,
}, {
label: 'sheet.cf.menu.createConditionalFormatting',
value: CF_MENU_OPERATION.createRule,
},
{
label: 'sheet.cf.menu.clearRangeRules',
value: CF_MENU_OPERATION.clearRangeRules,
disabled: false,
},
{
label: 'sheet.cf.menu.clearWorkSheetRules',
value: CF_MENU_OPERATION.clearWorkSheetRules,
},
];
const selectionManagerService = accessor.get(SheetsSelectionsService);
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -14,7 +14,15 @@
* limitations under the License.
*/
import { DependentOn, ICommandService, Inject, Injector, Plugin, Tools, UniverInstanceType } from '@univerjs/core';
import {
DependentOn,
ICommandService,
IConfigService,
Inject,
Injector,
Plugin,
UniverInstanceType,
} from '@univerjs/core';
import { SHEET_CONDITIONAL_FORMATTING_PLUGIN, UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
import { AddAverageCfCommand } from './commands/commands/add-average-cf.command';
import { AddColorScaleConditionalRuleCommand } from './commands/commands/add-color-scale-cf.command';
@@ -35,11 +43,11 @@ import { AddCfCommand } from './commands/commands/add-cf.command';
import { SheetsCfRenderController } from './controllers/cf.render.controller';
import { ConditionalFormattingCopyPasteController } from './controllers/cf.copy-paste.controller';
import type { IUniverSheetsConditionalFormattingUIConfig } from './controllers/cf.menu.controller';
import { DefaultSheetConditionalFormattingUiConfig } from './controllers/cf.menu.controller';
import { ConditionalFormattingI18nController } from './controllers/cf.i18n.controller';
import { SheetsCfRefRangeController } from './controllers/cf.ref-range.controller';
import { ConditionalFormattingPermissionController } from './controllers/cf.permission.controller';
import type { IUniverSheetsConditionalFormattingUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
@DependentOn(UniverSheetsConditionalFormattingPlugin)
export class UniverSheetsConditionalFormattingMobileUIPlugin extends Plugin {
@@ -47,12 +55,19 @@ export class UniverSheetsConditionalFormattingMobileUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
private readonly _config: Partial<IUniverSheetsConditionalFormattingUIConfig> = {},
private readonly _config: Partial<IUniverSheetsConditionalFormattingUIConfig> = defaultPluginConfig,
@Inject(Injector) override readonly _injector: Injector,
@Inject(ICommandService) private _commandService: ICommandService
@Inject(ICommandService) private _commandService: ICommandService,
@IConfigService private readonly _configService: IConfigService
) {
super();
this._config = Tools.deepMerge({}, DefaultSheetConditionalFormattingUiConfig, this._config);
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
this._initCommand();
@@ -14,7 +14,15 @@
* limitations under the License.
*/
import { DependentOn, ICommandService, Inject, Injector, Plugin, Tools, UniverInstanceType } from '@univerjs/core';
import {
DependentOn,
ICommandService,
IConfigService,
Inject,
Injector,
Plugin,
UniverInstanceType,
} from '@univerjs/core';
import { SHEET_CONDITIONAL_FORMATTING_PLUGIN, UniverSheetsConditionalFormattingPlugin } from '@univerjs/sheets-conditional-formatting';
import { AddAverageCfCommand } from './commands/commands/add-average-cf.command';
import { AddColorScaleConditionalRuleCommand } from './commands/commands/add-color-scale-cf.command';
@@ -36,13 +44,15 @@ import { AddCfCommand } from './commands/commands/add-cf.command';
import { SheetsCfRenderController } from './controllers/cf.render.controller';
import { ConditionalFormattingCopyPasteController } from './controllers/cf.copy-paste.controller';
import { ConditionalFormattingAutoFillController } from './controllers/cf.auto-fill.controller';
import type { IUniverSheetsConditionalFormattingUIConfig } from './controllers/cf.menu.controller';
import { ConditionalFormattingMenuController, DefaultSheetConditionalFormattingUiConfig } from './controllers/cf.menu.controller';
import { ConditionalFormattingMenuController } from './controllers/cf.menu.controller';
import { ConditionalFormattingPanelController } from './controllers/cf.panel.controller';
import { ConditionalFormattingI18nController } from './controllers/cf.i18n.controller';
import { SheetsCfRefRangeController } from './controllers/cf.ref-range.controller';
import { ConditionalFormattingEditorController } from './controllers/cf.editor.controller';
import { ConditionalFormattingClearController } from './controllers/cf.clear.controller';
import { ConditionalFormattingPermissionController } from './controllers/cf.permission.controller';
import type { IUniverSheetsConditionalFormattingUIConfig } from './controllers/config.schema';
import { defaultPluginConfig, PLUGIN_CONFIG_KEY } from './controllers/config.schema';
@DependentOn(UniverSheetsConditionalFormattingPlugin)
export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
@@ -50,13 +60,19 @@ export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
private readonly _config: Partial<IUniverSheetsConditionalFormattingUIConfig> = {},
private readonly _config: Partial<IUniverSheetsConditionalFormattingUIConfig> = defaultPluginConfig,
@Inject(Injector) override readonly _injector: Injector,
@Inject(ICommandService) private _commandService: ICommandService
@Inject(ICommandService) private _commandService: ICommandService,
@IConfigService private readonly _configService: IConfigService
) {
super();
this._config = Tools.deepMerge({}, DefaultSheetConditionalFormattingUiConfig, this._config);
// Manage the plugin configuration.
const { menu, ...rest } = this._config;
if (menu) {
this._configService.setConfig('menu', menu, { merge: true });
}
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
this._initCommand();
@@ -65,12 +81,8 @@ export class UniverSheetsConditionalFormattingUIPlugin extends Plugin {
this._injector.add([ConditionalFormattingCopyPasteController]);
this._injector.add([ConditionalFormattingAutoFillController]);
this._injector.add([ConditionalFormattingPermissionController]);
this._injector.add([
ConditionalFormattingMenuController,
{
useFactory: () => this._injector.createInstance(ConditionalFormattingMenuController, this._config),
},
]);
this._injector.add([ConditionalFormattingPanelController]);
this._injector.add([ConditionalFormattingMenuController]);
this._injector.add([ConditionalFormattingI18nController]);
this._injector.add([ConditionalFormattingEditorController]);
this._injector.add([ConditionalFormattingClearController]);
@@ -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.
*/
export const PLUGIN_CONFIG_KEY = 'ssheets-conditional-formatting.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverSheetsConditionalFormattingConfig {
}
export const defaultPluginConfig: IUniverSheetsConditionalFormattingConfig = {};
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ICommandService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import { ICommandService, IConfigService, Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
import type { Dependency } from '@univerjs/core';
import { SHEET_CONDITIONAL_FORMATTING_PLUGIN } from './base/const';
import { ConditionalFormattingService } from './services/conditional-formatting.service';
@@ -27,17 +27,28 @@ import { SetConditionalRuleMutation } from './commands/mutations/set-conditional
import { MoveConditionalRuleMutation } from './commands/mutations/move-conditional-rule.mutation';
import { ConditionalFormattingFormulaService } from './services/conditional-formatting-formula.service';
import { ConditionalFormattingFormulaMarkDirty } from './commands/mutations/formula-mark-dirty.mutation';
import type { IUniverSheetsConditionalFormattingConfig } from './controllers/config.schema';
import {
defaultPluginConfig,
PLUGIN_CONFIG_KEY,
} from './controllers/config.schema';
export class UniverSheetsConditionalFormattingPlugin extends Plugin {
static override pluginName = SHEET_CONDITIONAL_FORMATTING_PLUGIN;
static override type = UniverInstanceType.UNIVER_SHEET;
constructor(
_config: unknown,
private readonly _config: Partial<IUniverSheetsConditionalFormattingConfig> = defaultPluginConfig,
@Inject(Injector) override readonly _injector: Injector,
@Inject(ICommandService) private _commandService: ICommandService
@Inject(ICommandService) private _commandService: ICommandService,
@IConfigService private readonly _configService: IConfigService
) {
super();
// Manage the plugin configuration.
const { ...rest } = this._config;
this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
([
[ConditionalFormattingService],
[ConditionalFormattingFormulaService],
@@ -0,0 +1,27 @@
/**
* 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 { MenuConfig } from '@univerjs/ui';
export const PLUGIN_CONFIG_KEY = 'sheets-crosshair-highlight.config';
export const configSymbol = Symbol(PLUGIN_CONFIG_KEY);
export interface IUniverSheetsCrosshairHighlightConfig {
menu?: MenuConfig;
}
export const defaultPluginConfig: IUniverSheetsCrosshairHighlightConfig = {};
@@ -14,8 +14,8 @@
* limitations under the License.
*/
import { Disposable, ICommandService, Inject, Injector } from '@univerjs/core';
import { ComponentManager, IMenuService } from '@univerjs/ui';
import { Disposable, ICommandService, Inject } from '@univerjs/core';
import { ComponentManager, IMenu2Service } from '@univerjs/ui';
import { CrossHighlightingSingle } from '@univerjs/icons';
import {
DisableCrosshairHighlightOperation,
@@ -24,13 +24,13 @@ import {
ToggleCrosshairHighlightOperation,
} from '../commands/operations/operation';
import { CrosshairOverlay } from '../views/components/CrosshairHighlight';
import { CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT, CrosshairHighlightMenuItemFactory } from './crosshair.menu';
import { CROSSHAIR_HIGHLIGHT_OVERLAY_COMPONENT } from './crosshair.menu';
import { menuSchema } from './menu.schema';
export class SheetsCrosshairHighlightController extends Disposable {
constructor(
@Inject(Injector) private readonly _injector: Injector,
@Inject(ComponentManager) private readonly _componentMgr: ComponentManager,
@IMenuService private readonly _menuService: IMenuService,
@IMenu2Service private readonly _menu2Service: IMenu2Service,
@ICommandService private readonly _cmdSrv: ICommandService
) {
super();
@@ -50,7 +50,7 @@ export class SheetsCrosshairHighlightController extends Disposable {
}
private _initMenus(): void {
this._menuService.addMenuItem(this._injector.invoke(CrosshairHighlightMenuItemFactory), {});
this._menu2Service.mergeMenu(menuSchema);
}
private _initComponents(): void {

Some files were not shown because too many files have changed in this diff Show More