-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
formula-ui.controller.ts
130 lines (116 loc) · 5.65 KB
/
formula-ui.controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
* 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:https://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 { Disposable, ICommandService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { MenuConfig } from '@univerjs/ui';
import { BuiltInUIPart, ComponentManager, IMenuService, IShortcutService, IUIPartsService } from '@univerjs/ui';
import type { Ctor } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { connectInjector } from '@wendellhu/redi/react-bindings';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { BaseFunction, IFunctionInfo, IFunctionNames } from '@univerjs/engine-formula';
import { SheetOnlyPasteFormulaCommand } from '../commands/commands/formula-clipboard.command';
import { InsertFunctionCommand } from '../commands/commands/insert-function.command';
import { SelectEditorFormulaOperation } from '../commands/operations/editor-formula.operation';
import { HelpFunctionOperation } from '../commands/operations/help-function.operation';
import { InsertFunctionOperation } from '../commands/operations/insert-function.operation';
import { MoreFunctionsOperation } from '../commands/operations/more-functions.operation';
import { ReferenceAbsoluteOperation } from '../commands/operations/reference-absolute.operation';
import { SearchFunctionOperation } from '../commands/operations/search-function.operation';
import { RenderFormulaPromptContent } from '../views/FormulaPromptContainer';
import { MORE_FUNCTIONS_COMPONENT } from '../views/more-functions/interface';
import { MoreFunctions } from '../views/more-functions/MoreFunctions';
import { OtherFormulaMarkDirty } from '../commands/mutations/formula.mutation';
import { InsertFunctionMenuItemFactory, MoreFunctionsMenuItemFactory, PasteFormulaMenuItemFactory } from './menu';
import {
ChangeRefToAbsoluteShortcut,
promptSelectionShortcutItem,
promptSelectionShortcutItemCtrl,
promptSelectionShortcutItemCtrlAndShift,
promptSelectionShortcutItemShift,
singleEditorPromptSelectionShortcutItem,
} from './shortcuts/prompt.shortcut';
import { FormulaEditorShowController } from './formula-editor-show.controller';
export interface IUniverSheetsFormulaConfig {
menu: MenuConfig;
description: IFunctionInfo[];
function: Array<[Ctor<BaseFunction>, IFunctionNames]>;
}
export const DefaultSheetFormulaConfig = {};
@OnLifecycle(LifecycleStages.Ready, FormulaUIController)
export class FormulaUIController extends Disposable {
constructor(
private readonly _config: Partial<IUniverSheetsFormulaConfig>,
@Inject(Injector) private readonly _injector: Injector,
@IMenuService private readonly _menuService: IMenuService,
@ICommandService private readonly _commandService: ICommandService,
@IShortcutService private readonly _shortcutService: IShortcutService,
@IUIPartsService private readonly _uiPartsService: IUIPartsService,
@IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
@Inject(ComponentManager) private readonly _componentManager: ComponentManager
) {
super();
this._initialize();
}
private _initialize(): void {
this._registerCommands();
this._registerMenus();
this._registerShortcuts();
this._registerComponents();
this._registerRenderModules();
}
private _registerMenus(): void {
const { menu = {} } = this._config;
[InsertFunctionMenuItemFactory, MoreFunctionsMenuItemFactory, PasteFormulaMenuItemFactory].forEach(
(factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory), menu));
}
);
}
private _registerCommands(): void {
[
InsertFunctionCommand,
SheetOnlyPasteFormulaCommand,
InsertFunctionOperation,
MoreFunctionsOperation,
SearchFunctionOperation,
HelpFunctionOperation,
SelectEditorFormulaOperation,
ReferenceAbsoluteOperation,
OtherFormulaMarkDirty,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
private _registerShortcuts(): void {
[
...promptSelectionShortcutItem(),
...promptSelectionShortcutItemShift(),
...promptSelectionShortcutItemCtrl(),
...promptSelectionShortcutItemCtrlAndShift(),
...singleEditorPromptSelectionShortcutItem(),
ChangeRefToAbsoluteShortcut,
].forEach((item) => {
this.disposeWithMe(this._shortcutService.registerShortcut(item));
});
}
private _registerComponents(): void {
this.disposeWithMe(
this._uiPartsService.registerComponent(BuiltInUIPart.CONTENT, () => connectInjector(RenderFormulaPromptContent, this._injector))
);
this._componentManager.register(MORE_FUNCTIONS_COMPONENT, MoreFunctions);
}
private _registerRenderModules(): void {
this.disposeWithMe(this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, FormulaEditorShowController));
}
}