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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
flush
jerry617e7b1b564b
diff --git a/packages/base-sheets/src/Controller/SheetBarController1.ts b/packages/base-sheets/src/Controller/SheetBarController1.tsindex 3807138e09..605a6b11a9 100644--- a/packages/base-sheets/src/Controller/SheetBarController1.ts+++ b/packages/base-sheets/src/Controller/SheetBarController1.ts@@ -1,4 +1,4 @@-import { Plugin, UIObserver } from '@univerjs/core';+import { NameGen, Plugin, UIObserver } from '@univerjs/core';export class SheetBarControl {protected _plugin: Plugin;@@ -12,55 +12,72 @@ export class SheetBarControl {}listenEventManager(): void {- this._getCoreObserver<string>('onDeleteSheet').add(({ name, value }) => {- const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();- if (workbook) {- workbook.removeSheetBySheetId(value!);- }- });- this._getCoreObserver('onAddSheet').add(() => {- const context = this._plugin.getContext();- const workbook = context.getUniver().getCurrentUniverSheetInstance().getWorkBook();- workbook.insertSheet();+ this._getCoreObserver('onUIChangeObservable').add(({ name, value }) => {+ switch (name) {+ case 'deleteSheet': {+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ if (workbook) {+ workbook.removeSheetBySheetId(value as string);+ }+ break;+ }+ case 'copySheet': {+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const activeSheet = workbook.getActiveSheet();+ const copySheet = activeSheet.copy(NameGen.getSheetName());+ if (workbook) {+ workbook.insertSheet(workbook.getActiveSheetIndex() + 1, copySheet.getConfig());+ }+ break;+ }+ case 'renameSheet': {+ const { sheetId, sheetName } = value as { sheetId: string; sheetName: string };+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const worksheet = workbook.getSheetBySheetId(sheetId);+ if (worksheet && sheetName !== worksheet.getName()) {+ worksheet.setName(sheetName);+ }+ break;+ }+ case 'addSheet': {+ const context = this._plugin.getContext();+ const workbook = context.getUniver().getCurrentUniverSheetInstance().getWorkBook();+ workbook.insertSheet();- const size = workbook.getSheetSize();- const sheets = workbook.getSheets();- const lastSheet = sheets[size - 1];- if (lastSheet) {- lastSheet.activate();- }- });- this._getCoreObserver('onToLeftSheet').add(() => {- //TDOO ..- });- this._getCoreObserver('onToRightSheet').add(() => {- //TDOO ..- });- this._getCoreObserver<string>('onHideSheet').add(({ value }) => {- const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();- const worksheet = workbook.getSheetBySheetId(value!);- if (worksheet) {- worksheet.hideSheet();+ const size = workbook.getSheetSize();+ const sheets = workbook.getSheets();+ const lastSheet = sheets[size - 1];+ if (lastSheet) {+ lastSheet.activate();+ }+ break;+ }+ case 'unHideSheet': {+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const worksheet = workbook.getSheetBySheetId(value as string);+ if (worksheet) {+ worksheet.showSheet();+ }+ break;+ }+ case 'hideSheet': {+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const worksheet = workbook.getSheetBySheetId(value as string);+ if (worksheet) {+ worksheet.hideSheet();+ }+ break;+ }+ case 'changeSheetColor': {+ const { color, sheetId } = value as { color: string; sheetId: string };+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const worksheet = workbook.getSheetBySheetId(sheetId);+ if (worksheet) {+ worksheet.setTabColor(color);+ }+ break;+ }}});- this._getCoreObserver<string>('onUnHideSheet').add(({ value }) => {- const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();- const worksheet = workbook.getSheetBySheetId(value!);- if (worksheet) {- worksheet.showSheet();- }- });- this._getCoreObserver('onCopySheet').add(() => {- //TDOO ..- });- this._getCoreObserver<string>('onRemoveSheet').add(({ value }) => {- const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();- if (workbook) {- workbook.removeSheetBySheetId(value!);- }- });- this._getCoreObserver('onSheetColor').add(() => {- //TDOO ..- });}}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.tsindex 14b2d3f759..63dbddae07 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts@@ -23,15 +23,15 @@ interface SheetUlProps extends BaseUlProps {export class SheetBarUIController {protected _sheetBar: SheetBar;- protected _sheetList: SheetUlProps[];+ protected _plugin: Plugin;protected _sheetUl: SheetUl[];- protected _sheetIndex: number;+ protected _dataId: string;- protected _plugin: Plugin;+ protected _sheetIndex: number;- protected _dataId: string;+ protected _sheetList: SheetUlProps[];protected _menuList: SheetUlProps[];@@ -40,9 +40,6 @@ export class SheetBarUIController {sheetList: this._sheetList,sheetUl: this._sheetUl,menuList: this._menuList,- addSheet: () => {- // this._barControl.addSheet();- },selectSheet: (event: Event, data: { item: SheetUlProps }) => {this._dataId = data.item.sheetId;const sheet = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(this._dataId);@@ -55,8 +52,8 @@ export class SheetBarUIController {this._dataId = target.dataset.id as string;//this._barControl.contextMenu(e);},- changeSheetName: (e: Event) => {- //this._barControl.changeSheetName(e);+ changeSheetName: (event: Event) => {+},dragEnd: (elements: HTMLDivElement[]) => {//this._barControl.dragEnd(elements);@@ -114,19 +111,19 @@ export class SheetBarUIController {{locale: 'sheetConfig.delete',onClick: () => {- that.setUIObserve('onDeleteSheet', { name: 'deleteSheet', value: this._dataId });+ that.setUIObserve('onUIChangeObservable', { name: 'deleteSheet', value: this._dataId });},},{locale: 'sheetConfig.copy',onClick: () => {- that.setUIObserve('onCopySheet', { name: 'copySheet' });+ that.setUIObserve('onUIChangeObservable', { name: 'copySheet' });},},{locale: 'sheetConfig.rename',onClick: () => {- that.setUIObserve('onRemoveSheet', { name: 'removeSheet' });+ this._sheetBar.reNameSheet(this._dataId);},},{@@ -139,7 +136,7 @@ export class SheetBarUIController {name: this._plugin.getPluginName() + ColorPicker.name,props: {onClick: (color: string) => {- that.setUIObserve('onSheetColor', { name: 'sheetColor', value: color });+ that.setUIObserve('onUIChangeObservable', { name: 'changeSheetColor', value: color });},lang: {collapseLocale: 'colorPicker.collapse',@@ -157,29 +154,16 @@ export class SheetBarUIController {{locale: 'sheetConfig.hide',onClick: () => {- that.setUIObserve('onHideSheet', { name: 'hideSheet', value: this._dataId });+ that.setUIObserve('onUIChangeObservable', { name: 'hideSheet', value: this._dataId });},},{locale: 'sheetConfig.unhide',onClick: () => {- that.setUIObserve('onUnHideSheet', { name: 'hideSheet', value: this._dataId });-+ that.setUIObserve('onUIChangeObservable', { name: 'unHideSheet', value: this._dataId });},border: true,- },- {- locale: 'sheetConfig.moveLeft',- onClick: () => {- that.setUIObserve('onToLeftSheet', { name: 'toLeftSheet' });- },- },- {- locale: 'sheetConfig.moveRight',- onClick: () => {- that.setUIObserve('onToRightSheet', { name: 'toRightSheet' });- },- },+ }];CommandManager.getActionObservers().add((event) => {const action = event.action as SheetActionBase<any>;@@ -304,8 +288,8 @@ export class SheetBarUIController {}- addSheet(position?: string, config?: SheetUlProps): void {- this.setUIObserve('onAddSheet', {+ addSheet = (position?: string, config?: SheetUlProps): void => {+ this.setUIObserve('onUIChangeObservable', {name: 'addSheet',value: {position,@@ -314,10 +298,6 @@ export class SheetBarUIController {});}- reNameSheet() {- this._sheetBar.reNameSheet(this._dataId);- }-hideSheet() {}@@ -330,8 +310,13 @@ export class SheetBarUIController {}- changeSheetName(e: Event) {-+ changeSheetName = (event: Event) => {+ this.setUIObserve('onUIChangeObservable', {+ name: 'renameSheet', value: {+ sheetId: this._dataId,+ sheetName: (event.target as HTMLElement).innerText+ }+ });}contextMenu(e: MouseEvent) {@@ -339,16 +324,19 @@ export class SheetBarUIController {}dragEnd(element: HTMLDivElement[]) {+ debuggerlet list: SheetUlProps[] = [];+ let sheetId = this._dataId;Array.from(element).forEach((node: any) => {const item = this._sheetList.find((ele) => ele.sheetId === node.dataset.id);if (item) {list.push(item);}});- this._sheetList = list;- this._sheetBar.setValue({- sheetList: list,+ list.forEach((ele, index) => {+ if (ele.sheetId === sheetId) {+ this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().setSheetOrder(ele.sheetId, index);+ }});}}\ No newline at end of filediff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.tsindex acdbe2e033..bac6b70837 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts@@ -137,6 +137,7 @@ export class SheetContainerUIController {getComponent: this._sheetBarController.getComponent,addSheet: this._sheetBarController.addSheet,selectSheet: this._sheetBarController.selectSheet,+ dragEnd: this._sheetBarController.dragEnd,changeSheetName: this._sheetBarController.changeSheetName,},slot: {diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsxindex a8f6e21524..4fe940a2b1 100644--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx@@ -9,12 +9,12 @@ import { AppUIController } from './Controller/AppUIController';export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {private _appUIController: AppUIController;- private _componentManager: ComponentManager;-private _registerManager: RegisterManager;private _config: ISheetUIPluginConfig;+ private _componentManager: ComponentManager;+constructor(config?: ISheetUIPluginConfig) {super(SHEET_UI_PLUGIN_NAME);this._config = Tools.deepMerge({}, DefaultSheetUiConfig, config);