Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

chore(base-sheets): init config selections

Dushusirfe745eb771e0
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.md
index 12bdf8e5e5..5126023982 100644
--- a/.github/contributing-zh.md
+++ b/.github/contributing-zh.md
@@ -24,6 +24,15 @@ pnpm 管理的多包项目,
- PR 贡献请提交到 dev 分支,提到其它分支的会被驳回
- commit 信息必须使用全英文,代码中注释和 issues 尽量使用英文,便于全球的开发者沟通交流
+## 使用
+
+### ESM
+
+#### 安装
+```shell
+npm i @univerjs/core @univerjs/base-render @univerjs/base-ui @univerjs/base-sheets @univerjs/ui-plugin-sheets
+```
+
## 基本命令
开发
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsx
index b115ec9111..b80f0c5e8d 100644
--- a/examples/univer-sheet-ts/src/main.tsx
+++ b/examples/univer-sheet-ts/src/main.tsx
@@ -58,26 +58,7 @@ const universheet = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);
univer.addUniverSheet(universheet);
// base-sheet
-universheet.installPlugin(
- new SheetPlugin({
- selections: {
- 'sheet-0001': [
- {
- selection: {
- startRow: 2,
- endRow: 2,
- startColumn: 3,
- endColumn: 3,
- },
- cell: {
- row: 2,
- column: 3,
- },
- },
- ],
- },
- })
-);
+universheet.installPlugin(new SheetPlugin());
// universheet.installPlugin(new FormulaPlugin(DEFAULT_FORMULA_DATA_DEMO));
// ui-plugin-sheets
diff --git a/packages/base-docs/src/Controller/ToolBarController.ts b/packages/base-docs/src/Controller/ToolBarController.ts
index f6646cd9e6..b43626df86 100644
--- a/packages/base-docs/src/Controller/ToolBarController.ts
+++ b/packages/base-docs/src/Controller/ToolBarController.ts
@@ -50,9 +50,9 @@ export class ToolbarController {
this._initRegisterComponent();
const config =
- this._plugin.config.layout === 'auto'
+ this._plugin.getConfig().layout === 'auto'
? Tools.deepClone(defaultLayout.toolbarConfig)
- : Tools.deepMerge(defaultLayout.toolbarConfig, (this._plugin.config.layout as ILayout).toolbarConfig);
+ : Tools.deepMerge(defaultLayout.toolbarConfig, (this._plugin.getConfig().layout as ILayout).toolbarConfig);
this._borderInfo = {
color: '#000',
diff --git a/packages/base-docs/src/DocPlugin.tsx b/packages/base-docs/src/DocPlugin.tsx
index ad11b56c7b..e2f1f14e17 100644
--- a/packages/base-docs/src/DocPlugin.tsx
+++ b/packages/base-docs/src/DocPlugin.tsx
@@ -177,7 +177,7 @@ export class DocPlugin extends Plugin<DocPluginObserve, DocContext> {
// };
}
- get config() {
+ getConfig() {
return this._config;
}
diff --git a/packages/base-sheets/src/Basics/Const/DEFAULT_SPREADSHEET_PLUGIN_DATA.ts b/packages/base-sheets/src/Basics/Const/DEFAULT_SPREADSHEET_PLUGIN_DATA.ts
index 6415da3460..60f624de2e 100644
--- a/packages/base-sheets/src/Basics/Const/DEFAULT_SPREADSHEET_PLUGIN_DATA.ts
+++ b/packages/base-sheets/src/Basics/Const/DEFAULT_SPREADSHEET_PLUGIN_DATA.ts
@@ -1,112 +1,5 @@
import { ISheetPluginConfig } from '../Interfaces/SpreadsheetConfig';
-export const DefaultSheetContainerConfig = {
- outerLeft: false,
-
- outerRight: false,
-
- header: true,
-
- footer: true,
-
- innerLeft: false,
-
- innerRight: false,
-
- frozenHeaderLT: true,
-
- frozenHeaderRT: true,
-
- frozenHeaderLM: true,
-
- frozenContent: true,
-
- infoBar: true,
-
- formulaBar: true,
-
- toolbar: true,
-
- countBar: true,
-
- sheetBar: true,
-
- contentSplit: false,
-
- rightMenu: true,
-};
-
-export const DefaultToolbarConfig = {
- undoRedo: true, // Undo redo
- paintFormat: true, // Format brush
- currencyFormat: true, // currency format
- percentageFormat: true, // Percentage format
- numberDecrease: true, // 'Decrease the number of decimal places'
- numberIncrease: true, // 'Increase the number of decimal places
- moreFormats: true, // 'More Formats'
- font: true, // 'font'
- fontSize: true, // 'Font size'
- bold: true, // 'Bold (Ctrl+B)'
- italic: true, // 'Italic (Ctrl+I)'
- strikethrough: true, // 'Strikethrough (Alt+Shift+5)'
- underline: true, // 'Underline (Alt+Shift+6)'
- textColor: true, // 'Text color'
- fillColor: true, // 'Cell color'
- border: true, // 'border'
- mergeCell: true, // 'Merge cells'
- horizontalAlignMode: true, // 'Horizontal alignment'
- verticalAlignMode: true, // 'Vertical alignment'
- textWrapMode: true, // 'Wrap mode'
- textRotateMode: true, // 'Text Rotation Mode'
-};
-
-export const DefaultRightMenuConfig = {
- hideInsertRow: false,
- hideInsertColumn: false,
- hideAddRowTop: true,
- hideAddRowBottom: true,
- hideAddColumnLeft: true,
- hideAddColumnRight: true,
- hideDeleteRow: false,
- hideDeleteColumn: false,
- hideHideRow: true,
- hideShowRow: true,
- hideRowHeight: false,
- hideHideColumn: true,
- hideShowColumn: true,
- hideColumnWidth: false,
- hideDeleteCell: false,
- hideClearContent: false,
- hideMatrix: true,
-};
-
export const DEFAULT_SPREADSHEET_PLUGIN_DATA: ISheetPluginConfig = {
- container: 'universheet',
- layout: {
- sheetContainerConfig: DefaultSheetContainerConfig,
- toolbarConfig: DefaultToolbarConfig,
- rightMenuConfig: DefaultRightMenuConfig,
- },
- selections: {
- 'sheet-01': [
- {
- selection: {
- startRow: 0,
- endRow: 0,
- startColumn: 0,
- endColumn: 0,
- },
- },
- ],
- 'sheet-02': [
- {
- selection: {
- startRow: 0,
- endRow: 0,
- startColumn: 0,
- endColumn: 0,
- },
- },
- ],
- },
+ selections: {},
};
diff --git a/packages/base-sheets/src/Basics/Interfaces/SpreadsheetConfig.ts b/packages/base-sheets/src/Basics/Interfaces/SpreadsheetConfig.ts
index b3d4963b99..404a7fe815 100644
--- a/packages/base-sheets/src/Basics/Interfaces/SpreadsheetConfig.ts
+++ b/packages/base-sheets/src/Basics/Interfaces/SpreadsheetConfig.ts
@@ -1,7 +1,5 @@
-import { ISheetPluginConfigBase } from '../../Controller';
import { ISelectionsConfig } from './SelectionConfig';
-export interface ISheetPluginConfig extends ISheetPluginConfigBase {
- container: HTMLElement | string;
+export interface ISheetPluginConfig {
selections: ISelectionsConfig;
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index b8ecefca9b..80c3db0b45 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -682,7 +682,7 @@ export class SelectionManager {
* @param selections
*/
private _initModels() {
- const selections: ISelectionsConfig = this._plugin.config.selections;
+ const selections: ISelectionsConfig = this._plugin.getConfig().selections;
Object.keys(selections).forEach((worksheetId) => {
const selectionsList = selections[worksheetId];
@@ -743,7 +743,7 @@ export class SelectionManager {
* @param selections
*/
private _initControls() {
- const selections: ISelectionsConfig = this._plugin.config.selections;
+ const selections: ISelectionsConfig = this._plugin.getConfig().selections;
Object.keys(selections).forEach((worksheetId) => {
const selectionsList = selections[worksheetId];
const currentControls: SelectionControl[] = [];
diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.ts
index c448314639..cf0cbfc797 100644
--- a/packages/base-sheets/src/SheetPlugin.ts
+++ b/packages/base-sheets/src/SheetPlugin.ts
@@ -1,11 +1,11 @@
import { Engine, RenderEngine } from '@univerjs/base-render';
-import { SheetContext, Plugin, PLUGIN_NAMES } from '@univerjs/core';
+import { SheetContext, Plugin, PLUGIN_NAMES, DEFAULT_SELECTION } from '@univerjs/core';
import { SheetPluginObserve, uninstall } from './Basics/Observer';
import { CANVAS_VIEW_KEY } from './View/Render/BaseView';
import { CanvasView } from './View/Render/CanvasView';
import { RightMenuController, InfoBarController, SheetBarControl, CellEditorController, SheetContainerController, ToolbarController, CountBarController } from './Controller';
-import { install, ISheetPluginConfig } from './Basics';
+import { DEFAULT_SPREADSHEET_PLUGIN_DATA, install, ISheetPluginConfig } from './Basics';
import { FormulaBarController } from './Controller/FormulaBarController';
import { NamedRangeActionExtensionFactory } from './Basics/Register/NamedRangeActionExtension';
@@ -40,27 +40,39 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
// private _component: BaseComponentPlugin;
- constructor(config: any) {
+ constructor(config?: Partial<ISheetPluginConfig>) {
super(PLUGIN_NAMES.SPREADSHEET);
- // this._component = component;
-
- this._config = config;
+ this._config = Object.assign(DEFAULT_SPREADSHEET_PLUGIN_DATA, config);
}
initialize(context: SheetContext): void {
this.context = context;
install(this);
+ this.initConfig();
this.initController();
this.initCanvasView();
-
this.registerExtension();
}
- get config() {
+ getConfig() {
return this._config;
}
+ initConfig() {
+ const config = this._config;
+ if (!config.selections) {
+ const worksheetId = this.getContext().getWorkBook().getActiveSheet().getSheetId();
+ config.selections = {
+ [worksheetId]: [
+ {
+ selection: DEFAULT_SELECTION,
+ },
+ ],
+ };
+ }
+ }
+
initController() {
this._sheetContainerController = new SheetContainerController(this);
this._cellEditorController = new CellEditorController(this);
diff --git a/packages/base-slides/src/Controller/ToolBarController.ts b/packages/base-slides/src/Controller/ToolBarController.ts
index c4e92d5d9d..0b9a58b1c7 100644
--- a/packages/base-slides/src/Controller/ToolBarController.ts
+++ b/packages/base-slides/src/Controller/ToolBarController.ts
@@ -50,9 +50,9 @@ export class ToolbarController {
this._initRegisterComponent();
const config =
- this._plugin.config.layout === 'auto'
+ this._plugin.getConfig().layout === 'auto'
? Tools.deepClone(defaultLayout.toolbarConfig)
- : Tools.deepMerge(defaultLayout.toolbarConfig, (this._plugin.config.layout as ILayout).toolbarConfig);
+ : Tools.deepMerge(defaultLayout.toolbarConfig, (this._plugin.getConfig().layout as ILayout).toolbarConfig);
this._borderInfo = {
color: '#000',
diff --git a/packages/base-slides/src/SlidePlugin.tsx b/packages/base-slides/src/SlidePlugin.tsx
index e5daed83c2..61c59e2d83 100644
--- a/packages/base-slides/src/SlidePlugin.tsx
+++ b/packages/base-slides/src/SlidePlugin.tsx
@@ -175,7 +175,7 @@ export class SlidePlugin extends Plugin<SlidePluginObserve, SlideContext> {
// };
}
- get config() {
+ getConfig() {
return this._config;
}