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.

flush

jerry46cf4a4d0fd0
diff --git a/packages/base-sheets/src/Basics/Observer.ts b/packages/base-sheets/src/Basics/Observer.ts
index f5644bfe76..a515952901 100644
--- a/packages/base-sheets/src/Basics/Observer.ts
+++ b/packages/base-sheets/src/Basics/Observer.ts
@@ -1,17 +1,13 @@
import { Observable, Plugin } from '@univerjs/core';
import { SelectionControl } from '../Controller/Selection/SelectionController';
-import { SheetContainer } from '../View/UI/SheetContainer';
-import { Toolbar } from '../View/UI/Toolbar/Toolbar';
-import { LineColor } from '../View/UI/Common/Line/LineColor';
-import { LineBold } from '../View/UI/Common/Line/LineBold';
-import { ModalGroup } from '../View/UI/ModalGroup/ModalGroup';
-// import { RichText } from '../View/UI/RichText/RichText';
-import { CellRangeModal } from '../View/UI/Common/CellRange/CellRangeModal';
-import { ColorSelect } from '../View/UI/Common/ColorSelect/ColorSelect';
-interface ISelectionControlFillConfig {}
+interface ISelectionControlFillConfig {
+ //TODO ...
+}
-interface ISelectionControlDragAndDropConfig {}
+interface ISelectionControlDragAndDropConfig {
+ //TODO ...
+}
export type SheetPluginObserve = {
// onAfterChangeFontFamilyObservable: Observable<string>;
@@ -39,17 +35,6 @@ export type SheetPluginObserve = {
onChangeCurrentSheetObserver: Observable<string>;
- onToolbarDidMountObservable: Observable<Toolbar>;
-
- onModalGroupDidMountObservable: Observable<ModalGroup>;
-
- onLineColorDidMountObservable: Observable<LineColor>;
- onLineBoldDidMountObservable: Observable<LineBold>;
- onColorSelectDidMountObservable: Observable<ColorSelect>;
-
- onSheetContainerDidMountObservable: Observable<SheetContainer>;
- onCellRangeModalDidMountObservable: Observable<CellRangeModal>;
-
// onSpreadsheetKeyDownObservable: Observable<IKeyboardEvent>;
// onSpreadsheetKeyUpObservable: Observable<IKeyboardEvent>;
// onSpreadsheetKeyCopyObservable: Observable<IKeyboardEvent>;
@@ -77,13 +62,7 @@ export function uninstall(plugin: Plugin) {
plugin.deleteObserve('onFillingObserver');
plugin.deleteObserve('onFillEndObserver');
plugin.deleteObserve('onChangeSelectionObserver');
-
- plugin.deleteObserve('onToolbarDidMountObservable');
- plugin.deleteObserve('onModalGroupDidMountObservable');
-
plugin.deleteObserve('onChangeCurrentSheetObserver');
- plugin.deleteObserve('onSheetContainerDidMountObservable');
- plugin.deleteObserve('onCellRangeModalDidMountObservable');
// plugin.deleteObserve('onSpreadsheetKeyDownObservable');
// plugin.deleteObserve('onSpreadsheetKeyUpObservable');
// plugin.deleteObserve('onSpreadsheetKeyCopyObservable');
@@ -114,19 +93,6 @@ export function install(plugin: Plugin) {
plugin.pushToObserve('onChangeCurrentSheetObserver');
- plugin.pushToObserve('onToolbarDidMountObservable');
- plugin.pushToObserve('onCellRangeModalDidMountObservable');
- plugin.pushToObserve('onModalGroupDidMountObservable');
-
- plugin.pushToObserve('onLineColorDidMountObservable');
- plugin.pushToObserve('onLineBoldDidMountObservable');
- plugin.pushToObserve('onColorSelectDidMountObservable');
-
- plugin.pushToObserve('onSheetBarDidMountObservable');
- plugin.pushToObserve('onCountBarDidMountObservable');
- plugin.pushToObserve('onInfoBarDidMountObservable');
- plugin.pushToObserve('onRightMenuDidMountObservable');
- plugin.pushToObserve('onSheetContainerDidMountObservable');
// plugin.pushToObserve('onSpreadsheetKeyDownObservable');
// plugin.pushToObserve('onSpreadsheetKeyUpObservable');
// plugin.pushToObserve('onSpreadsheetKeyCopyObservable');
diff --git a/packages/base-sheets/src/Basics/RegisterAction.ts b/packages/base-sheets/src/Basics/RegisterAction.ts
deleted file mode 100644
index 639cbee21a..0000000000
--- a/packages/base-sheets/src/Basics/RegisterAction.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-import { CommandManager } from '@univerjs/core';
-import { SetSelectionValueAction } from '../Model/Action/SetSelectionValueAction';
-
-CommandManager.register(SetSelectionValueAction.NAME, SetSelectionValueAction);
diff --git a/packages/base-sheets/src/Basics/SlideTabBar/Animate.ts b/packages/base-sheets/src/Basics/SlideTabBar/Animate.ts
index 3219e943df..249051a9f1 100644
--- a/packages/base-sheets/src/Basics/SlideTabBar/Animate.ts
+++ b/packages/base-sheets/src/Basics/SlideTabBar/Animate.ts
@@ -50,6 +50,31 @@ export enum AnimateStatus {
}
export class Animate {
+ protected _config: AnimateConfig;
+
+ protected _status: AnimateStatus;
+
+ protected _start: number;
+
+ protected _handle: number;
+
+ protected _delayHandle: NodeJS.Timeout;
+
+ constructor(config: Partial<AnimateConfig>) {
+ this._config = {
+ ...CONFIG,
+ ...config,
+ };
+ if (this._config.loop) {
+ this._config.complete = () => {
+ /*noop*/
+ };
+ this._config.success = () => {
+ this.request();
+ };
+ }
+ }
+
static success(...animates: Animate[]): Promise<void> {
let successNumber = 0;
return new Promise<void>((resolve) => {
@@ -74,15 +99,26 @@ export class Animate {
});
}
- protected _config: AnimateConfig;
-
- protected _status: AnimateStatus;
-
- protected _start: number;
-
- protected _handle: number;
+ request(): void {
+ if (this._config.delay === 0) {
+ this._status = AnimateStatus.Request;
+ this._start = Date.now();
+ this._fakeHandle();
+ } else {
+ this._delayHandle && clearTimeout(this._delayHandle);
+ this._delayHandle = setTimeout(() => {
+ this._status = AnimateStatus.Request;
+ this._start = Date.now();
+ this._fakeHandle();
+ }, this._config.delay);
+ }
+ }
- protected _delayHandle: NodeJS.Timeout;
+ cancel(): void {
+ this._status = AnimateStatus.Cancel;
+ this._delayHandle && clearTimeout(this._delayHandle);
+ cancelAnimationFrame(this._handle);
+ }
protected _fakeHandle(): void {
let times = Date.now() - this._start;
@@ -109,40 +145,4 @@ export class Animate {
this._fakeHandle();
});
}
-
- constructor(config: Partial<AnimateConfig>) {
- this._config = {
- ...CONFIG,
- ...config,
- };
- if (this._config.loop) {
- this._config.complete = () => {
- /*noop*/
- };
- this._config.success = () => {
- this.request();
- };
- }
- }
-
- request(): void {
- if (this._config.delay === 0) {
- this._status = AnimateStatus.Request;
- this._start = Date.now();
- this._fakeHandle();
- } else {
- this._delayHandle && clearTimeout(this._delayHandle);
- this._delayHandle = setTimeout(() => {
- this._status = AnimateStatus.Request;
- this._start = Date.now();
- this._fakeHandle();
- }, this._config.delay);
- }
- }
-
- cancel(): void {
- this._status = AnimateStatus.Cancel;
- this._delayHandle && clearTimeout(this._delayHandle);
- cancelAnimationFrame(this._handle);
- }
}
diff --git a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabBar.ts b/packages/base-sheets/src/Basics/SlideTabBar/SlideTabBar.ts
index d9de3ba106..13b039bde8 100644
--- a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabBar.ts
+++ b/packages/base-sheets/src/Basics/SlideTabBar/SlideTabBar.ts
@@ -13,224 +13,37 @@ export interface SlideTabBarConfig {
}
export class SlideTabBar {
- static checkedSkipSlide(event: MouseEvent): boolean {
- let parent: HTMLElement | null = event.target as HTMLElement;
- while (parent != null && parent !== document.body) {
- if (parent.getAttribute('data-slide-skip')) {
- return true;
- }
- parent = parent.parentElement;
- }
- return false;
- }
+ protected _activeTabItemIndex: number | null;
- static keepLastIndex(inputHtml: HTMLElement) {
- setTimeout(() => {
- const range = window.getSelection();
- if (range) {
- range.selectAllChildren(inputHtml);
- range.collapseToEnd();
- }
- });
- }
-
- _activeTabItemIndex: number | null;
-
- _slideTabBar: HTMLElement;
+ protected _slideTabBar: HTMLElement;
- _slideTabItems: SlideTabItem[];
+ protected _slideTabItems: SlideTabItem[];
- _config: SlideTabBarConfig;
+ protected _config: SlideTabBarConfig;
- _downActionX: number;
+ protected _downActionX: number;
- _moveActionX: number;
+ protected _moveActionX: number;
- _compareIndex: number | null;
+ protected _compareIndex: number | null;
- _activeTabItem: SlideTabItem | null;
+ protected _activeTabItem: SlideTabItem | null;
- _moveAction: (e: MouseEvent) => void;
+ protected _moveAction: (e: MouseEvent) => void;
- _upAction: (e: MouseEvent) => void;
+ protected _upAction: (e: MouseEvent) => void;
- _downAction: (e: MouseEvent) => void;
+ protected _downAction: (e: MouseEvent) => void;
- _wheelAction: (e: WheelEvent) => void;
+ protected _wheelAction: (e: WheelEvent) => void;
- _scrollIncremental: number;
+ protected _scrollIncremental: number;
- _compareDirection: number;
+ protected _compareDirection: number;
- _autoScrollTime: number | null;
+ protected _autoScrollTime: number | null;
- _slideScrollbar: SlideScrollbar;
-
- _hasEditItem(): boolean {
- for (let index = 0; index < this._slideTabItems.length; index++) {
- const element = this._slideTabItems[index];
- if (element.isEditMode()) {
- return true;
- }
- }
- return false;
- }
-
- _autoScrollFrame(): void {
- if (this._activeTabItem) {
- this._compareDirection = this._activeTabItem.translateX(this._moveActionX);
- switch (this._compareDirection) {
- case 1: {
- this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);
- this._compareRight();
- break;
- }
- case 0: {
- this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);
- this._compareIndex = this._activeTabItemIndex;
- break;
- }
- case -1: {
- this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);
- this._compareLeft();
- break;
- }
- }
- }
- this._autoScrollTime = requestAnimationFrame(() => {
- this._autoScrollFrame();
- });
- }
-
- _startAutoScroll(): void {
- if (this._autoScrollTime == null) {
- this._autoScrollFrame();
- }
- }
-
- _closeAutoScroll(): void {
- if (this._autoScrollTime) {
- cancelAnimationFrame(this._autoScrollTime);
- }
- this._autoScrollTime = null;
- }
-
- _scrollLeft(event: MouseEvent): void {
- const boundingRect = this.getBoundingRect();
- const boundingLine = 10;
- const x = event.pageX - boundingRect.x;
- if (x < boundingLine) {
- this._scrollIncremental = -Math.min(Math.abs(x - boundingLine) * 0.1, 50);
- }
- }
-
- _scrollRight(event: MouseEvent): void {
- const boundingRect = this.getBoundingRect();
- const boundingLine = 10;
- const x = event.pageX - boundingRect.x;
- if (x > boundingRect.width - boundingLine) {
- this._scrollIncremental = Math.min(Math.abs(x - (boundingRect.width - boundingLine)) * 0.1, 50);
- }
- }
-
- _sortedItems(): void {
- if (this._activeTabItem != null && this._activeTabItemIndex != null && this._compareIndex != null) {
- // data array list sort
- this._slideTabItems.splice(this._activeTabItemIndex, 1);
- this._slideTabItems.splice(this._compareIndex, 0, this._activeTabItem);
-
- // dom list sort
- if (this._config.slideTabBarItemAutoSort) {
- for (let i = 0; i < this._slideTabItems.length; i++) {
- let item = this._slideTabItems[i];
- let next = this._slideTabItems[i + 1];
- if (next) {
- item.after(next);
- }
- }
- }
- }
- }
-
- _compareLeft(): void {
- if (this._activeTabItem && this._activeTabItemIndex) {
- let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));
- let length = this._slideTabItems.length;
- let collect = [];
-
- // collect compare item
- for (let i = 0; i < splice; i++) {
- if (i >= splice) {
- break;
- }
- collect.push(this._slideTabItems[i]);
- }
-
- // reset right
- for (let i = splice + 1; i < length; i++) {
- this._slideTabItems[i].animate().translateX(0);
- }
-
- // diff item midline
- let notFound = true;
- for (let i = collect.length - 1; i >= 0; i--) {
- let item = collect[i];
- if (SlideTabItem.midline(this._activeTabItem) < item.getMidLine()) {
- item.animate().translateX(this._activeTabItem.getWidth());
- this._compareIndex = i;
- notFound = false;
- } else {
- item.animate().translateX(0);
- if (notFound) {
- this._compareIndex = this._activeTabItemIndex;
- }
- }
- }
- }
- }
-
- _compareRight(): void {
- if (this._activeTabItem) {
- let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));
- let length = this._slideTabItems.length;
- let collect = [];
-
- // collect compare item
- for (let i = splice + 1; i < length; i++) {
- collect.push(this._slideTabItems[i]);
- }
-
- // reset left
- for (let i = 0; i < splice; i++) {
- this._slideTabItems[i].animate().translateX(0);
- }
-
- // diff item midline
- let notFound = true;
- for (let i = 0; i < collect.length; i++) {
- let item = collect[i];
- if (SlideTabItem.midline(this._activeTabItem) > item.getMidLine()) {
- item.animate().translateX(-this._activeTabItem.getWidth());
- this._compareIndex = splice + i + 1;
- notFound = false;
- } else {
- item.animate().translateX(0);
- if (notFound) {
- this._compareIndex = this._activeTabItemIndex;
- }
- }
- }
- }
- }
-
- _initialize(): void {
- document.addEventListener('mousemove', this._moveAction);
- document.addEventListener('mouseup', this._upAction);
- this._slideTabBar.addEventListener('wheel', this._wheelAction);
- this._slideTabItems.forEach((item) => {
- item.addEventListener('mousedown', this._downAction);
- });
- }
+ protected _slideScrollbar: SlideScrollbar;
constructor(config: Partial<SlideTabBarConfig>) {
if (config.slideTabRoot == null) {
@@ -372,6 +185,27 @@ export class SlideTabBar {
this._initialize();
}
+ static checkedSkipSlide(event: MouseEvent): boolean {
+ let parent: HTMLElement | null = event.target as HTMLElement;
+ while (parent != null && parent !== document.body) {
+ if (parent.getAttribute('data-slide-skip')) {
+ return true;
+ }
+ parent = parent.parentElement;
+ }
+ return false;
+ }
+
+ static keepLastIndex(inputHtml: HTMLElement) {
+ setTimeout(() => {
+ const range = window.getSelection();
+ if (range) {
+ range.selectAllChildren(inputHtml);
+ range.collapseToEnd();
+ }
+ });
+ }
+
primeval(): HTMLElement {
return this._slideTabBar;
}
@@ -408,4 +242,170 @@ export class SlideTabBar {
item.removeEventListener('mousedown', this._downAction);
});
}
+
+ protected _hasEditItem(): boolean {
+ for (let index = 0; index < this._slideTabItems.length; index++) {
+ const element = this._slideTabItems[index];
+ if (element.isEditMode()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected _autoScrollFrame(): void {
+ if (this._activeTabItem) {
+ this._compareDirection = this._activeTabItem.translateX(this._moveActionX);
+ switch (this._compareDirection) {
+ case 1: {
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);
+ this._compareRight();
+ break;
+ }
+ case 0: {
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);
+ this._compareIndex = this._activeTabItemIndex;
+ break;
+ }
+ case -1: {
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);
+ this._compareLeft();
+ break;
+ }
+ }
+ }
+ this._autoScrollTime = requestAnimationFrame(() => {
+ this._autoScrollFrame();
+ });
+ }
+
+ protected _startAutoScroll(): void {
+ if (this._autoScrollTime == null) {
+ this._autoScrollFrame();
+ }
+ }
+
+ protected _closeAutoScroll(): void {
+ if (this._autoScrollTime) {
+ cancelAnimationFrame(this._autoScrollTime);
+ }
+ this._autoScrollTime = null;
+ }
+
+ protected _scrollLeft(event: MouseEvent): void {
+ const boundingRect = this.getBoundingRect();
+ const boundingLine = 10;
+ const x = event.pageX - boundingRect.x;
+ if (x < boundingLine) {
+ this._scrollIncremental = -Math.min(Math.abs(x - boundingLine) * 0.1, 50);
+ }
+ }
+
+ protected _scrollRight(event: MouseEvent): void {
+ const boundingRect = this.getBoundingRect();
+ const boundingLine = 10;
+ const x = event.pageX - boundingRect.x;
+ if (x > boundingRect.width - boundingLine) {
+ this._scrollIncremental = Math.min(Math.abs(x - (boundingRect.width - boundingLine)) * 0.1, 50);
+ }
+ }
+
+ protected _sortedItems(): void {
+ if (this._activeTabItem != null && this._activeTabItemIndex != null && this._compareIndex != null) {
+ // data array list sort
+ this._slideTabItems.splice(this._activeTabItemIndex, 1);
+ this._slideTabItems.splice(this._compareIndex, 0, this._activeTabItem);
+
+ // dom list sort
+ if (this._config.slideTabBarItemAutoSort) {
+ for (let i = 0; i < this._slideTabItems.length; i++) {
+ let item = this._slideTabItems[i];
+ let next = this._slideTabItems[i + 1];
+ if (next) {
+ item.after(next);
+ }
+ }
+ }
+ }
+ }
+
+ protected _compareLeft(): void {
+ if (this._activeTabItem && this._activeTabItemIndex) {
+ let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));
+ let length = this._slideTabItems.length;
+ let collect = [];
+
+ // collect compare item
+ for (let i = 0; i < splice; i++) {
+ if (i >= splice) {
+ break;
+ }
+ collect.push(this._slideTabItems[i]);
+ }
+
+ // reset right
+ for (let i = splice + 1; i < length; i++) {
+ this._slideTabItems[i].animate().translateX(0);
+ }
+
+ // diff item midline
+ let notFound = true;
+ for (let i = collect.length - 1; i >= 0; i--) {
+ let item = collect[i];
+ if (SlideTabItem.midline(this._activeTabItem) < item.getMidLine()) {
+ item.animate().translateX(this._activeTabItem.getWidth());
+ this._compareIndex = i;
+ notFound = false;
+ } else {
+ item.animate().translateX(0);
+ if (notFound) {
+ this._compareIndex = this._activeTabItemIndex;
+ }
+ }
+ }
+ }
+ }
+
+ protected _compareRight(): void {
+ if (this._activeTabItem) {
+ let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));
+ let length = this._slideTabItems.length;
+ let collect = [];
+
+ // collect compare item
+ for (let i = splice + 1; i < length; i++) {
+ collect.push(this._slideTabItems[i]);
+ }
+
+ // reset left
+ for (let i = 0; i < splice; i++) {
+ this._slideTabItems[i].animate().translateX(0);
+ }
+
+ // diff item midline
+ let notFound = true;
+ for (let i = 0; i < collect.length; i++) {
+ let item = collect[i];
+ if (SlideTabItem.midline(this._activeTabItem) > item.getMidLine()) {
+ item.animate().translateX(-this._activeTabItem.getWidth());
+ this._compareIndex = splice + i + 1;
+ notFound = false;
+ } else {
+ item.animate().translateX(0);
+ if (notFound) {
+ this._compareIndex = this._activeTabItemIndex;
+ }
+ }
+ }
+ }
+ }
+
+ protected _initialize(): void {
+ document.addEventListener('mousemove', this._moveAction);
+ document.addEventListener('mouseup', this._upAction);
+ this._slideTabBar.addEventListener('wheel', this._wheelAction);
+ this._slideTabItems.forEach((item) => {
+ item.addEventListener('mousedown', this._downAction);
+ });
+ }
}
diff --git a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.ts b/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.ts
index 2f9d708bdb..3284c38c1d 100644
--- a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.ts
+++ b/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.ts
@@ -8,31 +8,21 @@ export interface SlideTabItemAnimate {
}
export class SlideTabItem {
- static midline(item: SlideTabItem) {
- return item.getBoundingRect().x + item.getBoundingRect().width / 2;
- }
-
- static make(nodeList: NodeList, slideTabBar: SlideTabBar): SlideTabItem[] {
- let result: SlideTabItem[] = [];
- nodeList.forEach((item) => result.push(new SlideTabItem(item as HTMLElement, slideTabBar)));
- return result;
- }
-
- _slideTabItem: HTMLElement;
+ protected _slideTabItem: HTMLElement;
- _animate: Animate | null;
+ protected _animate: Animate | null;
- _midline: number;
+ protected _midline: number;
- _translateX: number;
+ protected _translateX: number;
- _scrollbar: SlideScrollbar;
+ protected _scrollbar: SlideScrollbar;
- _slideTabBar: SlideTabBar;
+ protected _slideTabBar: SlideTabBar;
- _editMode: boolean;
+ protected _editMode: boolean;
- _placeholder: HTMLElement | null;
+ protected _placeholder: HTMLElement | null;
constructor(slideTabItem: HTMLElement, slideTabBar: SlideTabBar) {
this._slideTabItem = slideTabItem;
@@ -45,6 +35,16 @@ export class SlideTabItem {
this.update();
}
+ static midline(item: SlideTabItem) {
+ return item.getBoundingRect().x + item.getBoundingRect().width / 2;
+ }
+
+ static make(nodeList: NodeList, slideTabBar: SlideTabBar): SlideTabItem[] {
+ let result: SlideTabItem[] = [];
+ nodeList.forEach((item) => result.push(new SlideTabItem(item as HTMLElement, slideTabBar)));
+ return result;
+ }
+
isEditMode(): boolean {
return this._editMode;
}
diff --git a/packages/base-sheets/src/Basics/index.ts b/packages/base-sheets/src/Basics/index.ts
index 009ee64abd..efa0fc44e8 100644
--- a/packages/base-sheets/src/Basics/index.ts
+++ b/packages/base-sheets/src/Basics/index.ts
@@ -3,7 +3,4 @@ export * from './Const/index';
export * from './Enum/index';
export * from './Interfaces/index';
export * from './Observer';
-
-/* eslint-disable import/first */
-import './RegisterAction';
// @endindex
diff --git a/packages/base-sheets/src/Controller/AntLineController.ts b/packages/base-sheets/src/Controller/AntLineController.ts
index 8149fdb292..dfca50fcb0 100644
--- a/packages/base-sheets/src/Controller/AntLineController.ts
+++ b/packages/base-sheets/src/Controller/AntLineController.ts
@@ -18,6 +18,74 @@ export class AntLineControl {
private _activeSheetId: string;
+ /**
+ * Create AntLineController
+ * @param plugin
+ */
+ constructor(plugin: SheetPlugin) {
+ this._plugin = plugin;
+ this._antLineModelList = [];
+ plugin
+ .getContext()
+ .getContextObserver('onAfterChangeActiveSheetObservable')
+ .add(() => {
+ this._activeSheetId = plugin.getWorkbook().getActiveSheet().getSheetId();
+ this._makeUpdateSceneAntLineRect();
+ });
+ plugin
+ .getContext()
+ .getContextObserver('onSheetRenderDidMountObservable')
+ .add(() => {
+ this._activeSheetId = plugin.getWorkbook().getActiveSheet().getSheetId();
+ this._makeUpdateSceneAntLineRect();
+ });
+ }
+
+ /**
+ * Remove AntLine By SheetId
+ * @param sheetId
+ */
+ removeSheetAntLine(sheetId: string = this._activeSheetId): void {
+ this._removeAntLineModelBySheetId(sheetId);
+ this._makeUpdateSceneAntLineRect();
+ }
+
+ /**
+ * Add New AntLine By SheetId
+ * @param sheetId
+ * @param range
+ */
+ addAntLineToSheet(range: IAntLineRange, sheetId: string = this._activeSheetId): void {
+ const antLineModel = this._findAntLineModelBySheetId(sheetId, new AntLineModel(sheetId));
+ antLineModel.addAntLine(new AntLine(range));
+ this._saveOrUpdateAntLineModel(antLineModel);
+ this._makeUpdateSceneAntLineRect();
+ }
+
+ /**
+ * Return SheetView
+ * @returns
+ */
+ getSheetView(): SheetView {
+ return this._plugin.getCanvasView().getSheetView();
+ }
+
+ /**
+ * Return WorkBook
+ * @returns Workbook
+ */
+ getWorkBook(): Workbook {
+ return this._plugin.getWorkbook();
+ }
+
+ /**
+ * Return SheetView Scene
+ * @returns
+ */
+ getSheetViewScene(): Scene {
+ return this._plugin.getCanvasView().getSheetView().getScene();
+ }
+
/**
* Remove AntLineModel By SheetId
* @param sheetId
@@ -140,72 +208,4 @@ export class AntLineControl {
}
}
}
-
- /**
- * Create AntLineController
- * @param plugin
- */
- constructor(plugin: SheetPlugin) {
- this._plugin = plugin;
- this._antLineModelList = [];
- plugin
- .getContext()
- .getContextObserver('onAfterChangeActiveSheetObservable')
- .add(() => {
- this._activeSheetId = plugin.getWorkbook().getActiveSheet().getSheetId();
- this._makeUpdateSceneAntLineRect();
- });
- plugin
- .getContext()
- .getContextObserver('onSheetRenderDidMountObservable')
- .add(() => {
- this._activeSheetId = plugin.getWorkbook().getActiveSheet().getSheetId();
- this._makeUpdateSceneAntLineRect();
- });
- }
-
- /**
- * Remove AntLine By SheetId
- * @param sheetId
- */
- removeSheetAntLine(sheetId: string = this._activeSheetId): void {
- this._removeAntLineModelBySheetId(sheetId);
- this._makeUpdateSceneAntLineRect();
- }
-
- /**
- * Add New AntLine By SheetId
- * @param sheetId
- * @param range
- */
- addAntLineToSheet(range: IAntLineRange, sheetId: string = this._activeSheetId): void {
- const antLineModel = this._findAntLineModelBySheetId(sheetId, new AntLineModel(sheetId));
- antLineModel.addAntLine(new AntLine(range));
- this._saveOrUpdateAntLineModel(antLineModel);
- this._makeUpdateSceneAntLineRect();
- }
-
- /**
- * Return SheetView
- * @returns
- */
- getSheetView(): SheetView {
- return this._plugin.getCanvasView().getSheetView();
- }
-
- /**
- * Return WorkBook
- * @returns Workbook
- */
- getWorkBook(): Workbook {
- return this._plugin.getWorkbook();
- }
-
- /**
- * Return SheetView Scene
- * @returns
- */
- getSheetViewScene(): Scene {
- return this._plugin.getCanvasView().getSheetView().getScene();
- }
}
diff --git a/packages/base-sheets/src/Controller/CellEditorController.ts b/packages/base-sheets/src/Controller/CellEditorController.ts
index c2adf73cc0..4784203378 100644
--- a/packages/base-sheets/src/Controller/CellEditorController.ts
+++ b/packages/base-sheets/src/Controller/CellEditorController.ts
@@ -5,11 +5,11 @@ import { SheetPlugin } from '../SheetPlugin';
* Cell Editor
*/
export class CellEditorController {
- private _plugin: SheetPlugin;
-
// current edit cell
currentEditRangeData: IRangeData;
+ private _plugin: SheetPlugin;
+
constructor(plugin: SheetPlugin) {
this._plugin = plugin;
}
@@ -84,7 +84,7 @@ export class CellEditorController {
// this._plugin.getMainComponent().makeDirty(true);
}
- handleBackSpace() {}
+ handleBackSpace() { }
handleDirection(direction: Direction) {
// todo
diff --git a/packages/base-sheets/src/Controller/CountBarController.ts b/packages/base-sheets/src/Controller/CountBarController.ts
index 494e21d92a..2e95f3c2f9 100644
--- a/packages/base-sheets/src/Controller/CountBarController.ts
+++ b/packages/base-sheets/src/Controller/CountBarController.ts
@@ -4,10 +4,6 @@ import { SheetPlugin } from '../SheetPlugin';
export class CountBarController {
private _plugin: SheetPlugin;
- protected _getCoreObserver<T>(type: string) {
- return this._plugin.getGlobalContext().getObserverManager().requiredObserver<UIObserver<T>>(type, 'core');
- }
-
constructor(plugin: SheetPlugin) {
this._plugin = plugin;
}
@@ -29,4 +25,8 @@ export class CountBarController {
}
});
}
+
+ protected _getCoreObserver<T>(type: string) {
+ return this._plugin.getGlobalContext().getObserverManager().requiredObserver<UIObserver<T>>(type, 'core');
+ }
}
diff --git a/packages/base-sheets/src/Controller/RightMenuController.ts b/packages/base-sheets/src/Controller/RightMenuController.ts
index dd4b0eafea..6dc54eb153 100644
--- a/packages/base-sheets/src/Controller/RightMenuController.ts
+++ b/packages/base-sheets/src/Controller/RightMenuController.ts
@@ -44,20 +44,6 @@ export class RightMenuController {
});
}
- private _getSelections() {
- const controls = this._plugin?.getSelectionManager().getCurrentControls();
- const selections = controls?.map((control: SelectionControl) => {
- const model: SelectionModel = control.model;
- return {
- startRow: model.startRow,
- startColumn: model.startColumn,
- endRow: model.endRow,
- endColumn: model.endColumn,
- };
- });
- return selections;
- }
-
insertRow = () => {
const selections = this._getSelections();
if (selections?.length === 1) {
@@ -137,4 +123,18 @@ export class RightMenuController {
sheet.setRowHeights(selections[0].startRow, selections[0].endRow - selections[0].startRow + 1, Number(height));
}
}
+
+ private _getSelections() {
+ const controls = this._plugin?.getSelectionManager().getCurrentControls();
+ const selections = controls?.map((control: SelectionControl) => {
+ const model: SelectionModel = control.model;
+ return {
+ startRow: model.startRow,
+ startColumn: model.startColumn,
+ endRow: model.endRow,
+ endColumn: model.endColumn,
+ };
+ });
+ return selections;
+ }
}
diff --git a/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts b/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts
index 74b094718a..91d13434b6 100644
--- a/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts
+++ b/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts
@@ -48,28 +48,6 @@ export class ColumnTitleController {
this._initialize();
}
- // 拖拽图标
- private _initialize() {
- this._highlightItem.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._highlightItem.show();
- });
- this._highlightItem.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._highlightItem.show();
- });
- this._highlightItem.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._highlightItem.hide();
- });
- this._Item.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._Item.cursor = CURSOR_TYPE.COLUMN_RESIZE;
- });
- this._Item.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._Item.resetCursor();
- });
- this._Item.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this.pointerDown(evt);
- });
- }
-
pointerDown(e: IPointerEvent | IMouseEvent) {
const main = this._manager.getMainComponent();
const { offsetX: evtOffsetX, offsetY: evtOffsetY } = e;
@@ -178,4 +156,26 @@ export class ColumnTitleController {
});
this._highlightItem.show();
}
+
+ // 拖拽图标
+ private _initialize() {
+ this._highlightItem.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.hide();
+ });
+ this._Item.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.cursor = CURSOR_TYPE.COLUMN_RESIZE;
+ });
+ this._Item.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.resetCursor();
+ });
+ this._Item.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this.pointerDown(evt);
+ });
+ }
}
diff --git a/packages/base-sheets/src/Controller/Selection/RowTitleController.ts b/packages/base-sheets/src/Controller/Selection/RowTitleController.ts
index ebcbbcd1d1..20adf80778 100644
--- a/packages/base-sheets/src/Controller/Selection/RowTitleController.ts
+++ b/packages/base-sheets/src/Controller/Selection/RowTitleController.ts
@@ -50,28 +50,6 @@ export class RowTitleController {
this._initialize();
}
- // 拖拽图标
- private _initialize() {
- this._highlightItem.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._highlightItem.show();
- });
- this._highlightItem.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._highlightItem.show();
- });
- this._highlightItem.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._highlightItem.hide();
- });
- this._Item.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._Item.cursor = CURSOR_TYPE.ROW_RESIZE;
- });
- this._Item.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._Item.resetCursor();
- });
- this._Item.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this.pointerDown(evt);
- });
- }
-
pointerDown(e: IPointerEvent | IMouseEvent) {
const main = this._manager.getMainComponent();
const { offsetX: evtOffsetX, offsetY: evtOffsetY } = e;
@@ -178,4 +156,26 @@ export class RowTitleController {
this._highlightItem.show();
}
+
+ // 拖拽图标
+ private _initialize() {
+ this._highlightItem.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.hide();
+ });
+ this._Item.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.cursor = CURSOR_TYPE.ROW_RESIZE;
+ });
+ this._Item.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.resetCursor();
+ });
+ this._Item.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this.pointerDown(evt);
+ });
+ }
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionControlDragDrop.ts b/packages/base-sheets/src/Controller/Selection/SelectionControlDragDrop.ts
index 26054da772..e325028161 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionControlDragDrop.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionControlDragDrop.ts
@@ -51,93 +51,13 @@ export class SelectionControlDragAndDrop {
this._initialize();
}
- private _initialize() {
- const plugin = this._control.getPlugin();
-
- const main = plugin.getMainComponent();
-
- const { leftControl, rightControl, topControl, bottomControl, fillControl } = this._control;
- leftControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- leftControl.cursor = CURSOR_TYPE.MOVE;
- });
-
- leftControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- leftControl.resetCursor();
- });
-
- rightControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- rightControl.cursor = CURSOR_TYPE.MOVE;
- });
-
- rightControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- rightControl.resetCursor();
- });
-
- topControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- topControl.cursor = CURSOR_TYPE.MOVE;
- });
-
- topControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- topControl.resetCursor();
- });
-
- bottomControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
- bottomControl.cursor = CURSOR_TYPE.MOVE;
- });
-
- bottomControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- bottomControl.resetCursor();
- });
-
- bottomControl.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this.dragDown(evt, Direction.BOTTOM);
- });
-
- bottomControl.onPointerUpObserver.add((evt: IPointerEvent | IMouseEvent) => {
- bottomControl.resetCursor();
- });
-
- // init drag render box
- const zIndex = this._zIndex;
- this._leftDragControl = new Rect(SELECTION_DRAG_KEY.left + zIndex, {
- top: 0,
- left: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
- width: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
- fill: DEFAULT_SELECTION_CONFIG.strokeColor,
- zIndex,
- });
- this._rightDragControl = new Rect(SELECTION_DRAG_KEY.right + zIndex, {
- width: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
- fill: DEFAULT_SELECTION_CONFIG.strokeColor,
- zIndex,
- });
- this._topDragControl = new Rect(SELECTION_DRAG_KEY.top + zIndex, {
- top: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
- left: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
- height: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
- fill: DEFAULT_SELECTION_CONFIG.strokeColor,
- zIndex,
- });
- this._bottomDragControl = new Rect(SELECTION_DRAG_KEY.bottom + zIndex, {
- height: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
- fill: DEFAULT_SELECTION_CONFIG.strokeColor,
- left: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
- zIndex,
- });
-
- this._selectionDragShape = new Group(SELECTION_DRAG_KEY.Selection + zIndex, this._leftDragControl, this._rightDragControl, this._topDragControl, this._bottomDragControl);
-
- // this._selectionDragShape.visible = false;
-
- this._selectionDragShape.evented = false;
-
- this._selectionDragShape.zIndex = zIndex;
-
- const scene = this._control.getScene();
- scene.addObject(this._selectionDragShape);
+ static create(control: SelectionControl) {
+ return new SelectionControlDragAndDrop(control);
}
- dragEventInitial() {}
+ dragEventInitial() {
+ // TODO ...
+ }
dragDown(evt: IPointerEvent | IMouseEvent, direction: Direction) {
const main = this._control.getPlugin().getMainComponent();
@@ -348,7 +268,89 @@ export class SelectionControlDragAndDrop {
bottomControl.onPointerLeaveObserver.clear();
}
- static create(control: SelectionControl) {
- return new SelectionControlDragAndDrop(control);
+ private _initialize() {
+ const plugin = this._control.getPlugin();
+
+ const main = plugin.getMainComponent();
+
+ const { leftControl, rightControl, topControl, bottomControl, fillControl } = this._control;
+ leftControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ leftControl.cursor = CURSOR_TYPE.MOVE;
+ });
+
+ leftControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ leftControl.resetCursor();
+ });
+
+ rightControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ rightControl.cursor = CURSOR_TYPE.MOVE;
+ });
+
+ rightControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ rightControl.resetCursor();
+ });
+
+ topControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ topControl.cursor = CURSOR_TYPE.MOVE;
+ });
+
+ topControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ topControl.resetCursor();
+ });
+
+ bottomControl.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ bottomControl.cursor = CURSOR_TYPE.MOVE;
+ });
+
+ bottomControl.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ bottomControl.resetCursor();
+ });
+
+ bottomControl.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this.dragDown(evt, Direction.BOTTOM);
+ });
+
+ bottomControl.onPointerUpObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ bottomControl.resetCursor();
+ });
+
+ // init drag render box
+ const zIndex = this._zIndex;
+ this._leftDragControl = new Rect(SELECTION_DRAG_KEY.left + zIndex, {
+ top: 0,
+ left: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
+ width: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
+ fill: DEFAULT_SELECTION_CONFIG.strokeColor,
+ zIndex,
+ });
+ this._rightDragControl = new Rect(SELECTION_DRAG_KEY.right + zIndex, {
+ width: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
+ fill: DEFAULT_SELECTION_CONFIG.strokeColor,
+ zIndex,
+ });
+ this._topDragControl = new Rect(SELECTION_DRAG_KEY.top + zIndex, {
+ top: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
+ left: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
+ height: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
+ fill: DEFAULT_SELECTION_CONFIG.strokeColor,
+ zIndex,
+ });
+ this._bottomDragControl = new Rect(SELECTION_DRAG_KEY.bottom + zIndex, {
+ height: DEFAULT_SELECTION_CONFIG.strokeWidth * 2,
+ fill: DEFAULT_SELECTION_CONFIG.strokeColor,
+ left: -DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
+ zIndex,
+ });
+
+ this._selectionDragShape = new Group(SELECTION_DRAG_KEY.Selection + zIndex, this._leftDragControl, this._rightDragControl, this._topDragControl, this._bottomDragControl);
+
+ // this._selectionDragShape.visible = false;
+
+ this._selectionDragShape.evented = false;
+
+ this._selectionDragShape.zIndex = zIndex;
+
+ const scene = this._control.getScene();
+ scene.addObject(this._selectionDragShape);
}
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionControlFill.ts b/packages/base-sheets/src/Controller/Selection/SelectionControlFill.ts
index 5e8aad14a7..1ca19bcd33 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionControlFill.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionControlFill.ts
@@ -6,6 +6,16 @@ export class SelectionControlFill {
this._initialize();
}
+ static create(control: SelectionControl) {
+ return new SelectionControlFill(control);
+ }
+
+ remove() {
+ const { fillControl } = this._control;
+ fillControl.onPointerEnterObserver.clear();
+ fillControl.onPointerLeaveObserver.clear();
+ }
+
private _initialize() {
const { fillControl } = this._control;
const plugin = this._control.getPlugin();
@@ -17,14 +27,4 @@ export class SelectionControlFill {
fillControl.resetCursor();
});
}
-
- remove() {
- const { fillControl } = this._control;
- fillControl.onPointerEnterObserver.clear();
- fillControl.onPointerLeaveObserver.clear();
- }
-
- static create(control: SelectionControl) {
- return new SelectionControlFill(control);
- }
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionController.ts b/packages/base-sheets/src/Controller/Selection/SelectionController.ts
index 4b9b04bf91..8e3a0e9dca 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionController.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionController.ts
@@ -80,6 +80,208 @@ export class SelectionControl {
this._initialize();
}
+ get zIndex() {
+ return this._zIndex;
+ }
+
+ get leftControl() {
+ return this._leftControl;
+ }
+
+ get rightControl() {
+ return this._rightControl;
+ }
+
+ get topControl() {
+ return this._topControl;
+ }
+
+ get bottomControl() {
+ return this._bottomControl;
+ }
+
+ get fillControl() {
+ return this._fillControl;
+ }
+
+ get backgroundControlTop() {
+ return this._backgroundControlTop;
+ }
+
+ get backgroundControlBottom() {
+ return this._backgroundControlBottom;
+ }
+
+ get backgroundControlMiddleLeft() {
+ return this._backgroundControlMiddleLeft;
+ }
+
+ get backgroundControlMiddleRight() {
+ return this._backgroundControlMiddleRight;
+ }
+
+ get selectionShape() {
+ return this._selectionShape;
+ }
+
+ get model() {
+ return this._selectionModel;
+ }
+
+ static create(manager: SelectionManager, zIndex: number) {
+ return new this(manager, zIndex);
+ }
+
+ static fromJson(manager: SelectionManager, zIndex: number, newSelectionRange: ISelection) {
+ const control = SelectionControl.create(manager, zIndex);
+ control.update(newSelectionRange);
+ return control;
+ }
+
+ /**
+ * just handle the view
+ *
+ * inner update
+ */
+ _updateControl() {
+ const { startX, startY, endX, endY } = this._selectionModel;
+
+ this.leftControl.resize(undefined, endY - startY);
+ this.rightControl.transformByState({
+ height: endY - startY,
+ left: endX - startX - DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
+ });
+ this.topControl.resize(endX - startX + DEFAULT_SELECTION_CONFIG.strokeWidth);
+ this.bottomControl.transformByState({
+ width: endX - startX + DEFAULT_SELECTION_CONFIG.strokeWidth,
+ top: endY - startY - DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
+ });
+
+ this.fillControl.translate(endX - startX - DEFAULT_SELECTION_CONFIG.fillSideLength / 2, endY - startY - DEFAULT_SELECTION_CONFIG.fillSideLength / 2);
+
+ this._updateBackgroundControl();
+ this._updateDragAndFill();
+
+ this.selectionShape.show();
+ this.selectionShape.translate(startX, startY);
+
+ this.selectionShape.makeDirty(true);
+ }
+
+ update(newSelectionRange: ISelection, highlight: Nullable<ICellInfo>) {
+ this._selectionModel.setValue(newSelectionRange, highlight);
+ this._updateControl();
+ }
+
+ // /**
+ // *When switching to the current sheet
+ // *
+ // * 1. Reinitialize the rendering component
+ // * 2. Calculate the position based on the current skeleton
+ // * 3. Update data
+ // * 4. Trigger rendering
+ // */
+ // render() {
+ // this._initialize();
+
+ // let cellInfo = null;
+ // const main = this._manager.getMainComponent();
+ // const curCellRange = this._selectionModel.currentCell;
+
+ // if (curCellRange) {
+ // cellInfo = main.getCellByIndex(curCellRange.row, curCellRange.column);
+ // }
+
+ // const { startRow: finalStartRow, startColumn: finalStartColumn, endRow: finalEndRow, endColumn: finalEndColumn } = this._selectionModel;
+ // const startCell = main.getNoMergeCellPositionByIndex(finalStartRow, finalStartColumn);
+ // const endCell = main.getNoMergeCellPositionByIndex(finalEndRow, finalEndColumn);
+
+ // this._manager.updateSelectionValue(
+ // this,
+ // {
+ // startColumn: finalStartColumn,
+ // startRow: finalStartRow,
+ // endColumn: finalEndColumn,
+ // endRow: finalEndRow,
+ // startY: startCell?.startY || 0,
+ // endY: endCell?.endY || 0,
+ // startX: startCell?.startX || 0,
+ // endX: endCell?.endX || 0,
+ // },
+ // cellInfo
+ // );
+
+ // this._updateControl();
+ // }
+
+ clearHighlight() {
+ this._selectionModel.clearCurrentCell();
+ this._updateControl();
+ }
+
+ dispose() {
+ this._leftControl?.dispose();
+ this._rightControl?.dispose();
+ this._topControl?.dispose();
+ this._bottomControl?.dispose();
+ this._backgroundControlTop?.dispose();
+ this._backgroundControlMiddleLeft?.dispose();
+ this._backgroundControlMiddleRight?.dispose();
+ this._backgroundControlBottom?.dispose();
+ this._fillControl?.dispose();
+ this._selectionShape?.dispose();
+
+ this._selectionDragAndDrop.dispose();
+ }
+
+ getScene() {
+ return this._manager.getScene();
+ }
+
+ getPlugin() {
+ return this._manager.getPlugin();
+ }
+
+ /**
+ * Get the cell information of the current selection, considering the case of merging cells
+ */
+ getCurrentCellInfo(): Nullable<ISelection> {
+ const currentCell = this.model.currentCell;
+
+ if (currentCell) {
+ let currentRangeData;
+
+ if (currentCell.isMerged) {
+ const mergeInfo = currentCell.mergeInfo;
+
+ currentRangeData = {
+ startRow: mergeInfo.startRow,
+ endRow: mergeInfo.endRow,
+ startColumn: mergeInfo.startColumn,
+ endColumn: mergeInfo.endColumn,
+ startX: mergeInfo.startX,
+ endX: mergeInfo.endX,
+ startY: mergeInfo.startY,
+ endY: mergeInfo.endY,
+ };
+ } else {
+ const { row, column, startX, endX, startY, endY } = currentCell;
+ currentRangeData = {
+ startRow: row,
+ endRow: row,
+ startColumn: column,
+ endColumn: column,
+ startX,
+ endX,
+ startY,
+ endY,
+ };
+ }
+
+ return currentRangeData;
+ }
+ }
+
private _initialize() {
this._selectionModel = new SelectionModel(SELECTION_TYPE.NORMAL, this._manager.getPlugin());
const zIndex = this._zIndex;
@@ -164,40 +366,6 @@ export class SelectionControl {
scene.addObject(this._selectionShape);
}
- get zIndex() {
- return this._zIndex;
- }
-
- /**
- * just handle the view
- *
- * inner update
- */
- _updateControl() {
- const { startX, startY, endX, endY } = this._selectionModel;
-
- this.leftControl.resize(undefined, endY - startY);
- this.rightControl.transformByState({
- height: endY - startY,
- left: endX - startX - DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
- });
- this.topControl.resize(endX - startX + DEFAULT_SELECTION_CONFIG.strokeWidth);
- this.bottomControl.transformByState({
- width: endX - startX + DEFAULT_SELECTION_CONFIG.strokeWidth,
- top: endY - startY - DEFAULT_SELECTION_CONFIG.strokeWidth / 2,
- });
-
- this.fillControl.translate(endX - startX - DEFAULT_SELECTION_CONFIG.fillSideLength / 2, endY - startY - DEFAULT_SELECTION_CONFIG.fillSideLength / 2);
-
- this._updateBackgroundControl();
- this._updateDragAndFill();
-
- this.selectionShape.show();
- this.selectionShape.translate(startX, startY);
-
- this.selectionShape.makeDirty(true);
- }
-
private _updateBackgroundControl() {
const {
startColumn,
@@ -287,172 +455,4 @@ export class SelectionControl {
this._selectionControlFill.remove();
}
}
-
- update(newSelectionRange: ISelection, highlight: Nullable<ICellInfo>) {
- this._selectionModel.setValue(newSelectionRange, highlight);
- this._updateControl();
- }
-
- // /**
- // *When switching to the current sheet
- // *
- // * 1. Reinitialize the rendering component
- // * 2. Calculate the position based on the current skeleton
- // * 3. Update data
- // * 4. Trigger rendering
- // */
- // render() {
- // this._initialize();
-
- // let cellInfo = null;
- // const main = this._manager.getMainComponent();
- // const curCellRange = this._selectionModel.currentCell;
-
- // if (curCellRange) {
- // cellInfo = main.getCellByIndex(curCellRange.row, curCellRange.column);
- // }
-
- // const { startRow: finalStartRow, startColumn: finalStartColumn, endRow: finalEndRow, endColumn: finalEndColumn } = this._selectionModel;
- // const startCell = main.getNoMergeCellPositionByIndex(finalStartRow, finalStartColumn);
- // const endCell = main.getNoMergeCellPositionByIndex(finalEndRow, finalEndColumn);
-
- // this._manager.updateSelectionValue(
- // this,
- // {
- // startColumn: finalStartColumn,
- // startRow: finalStartRow,
- // endColumn: finalEndColumn,
- // endRow: finalEndRow,
- // startY: startCell?.startY || 0,
- // endY: endCell?.endY || 0,
- // startX: startCell?.startX || 0,
- // endX: endCell?.endX || 0,
- // },
- // cellInfo
- // );
-
- // this._updateControl();
- // }
-
- clearHighlight() {
- this._selectionModel.clearCurrentCell();
- this._updateControl();
- }
-
- dispose() {
- this._leftControl?.dispose();
- this._rightControl?.dispose();
- this._topControl?.dispose();
- this._bottomControl?.dispose();
- this._backgroundControlTop?.dispose();
- this._backgroundControlMiddleLeft?.dispose();
- this._backgroundControlMiddleRight?.dispose();
- this._backgroundControlBottom?.dispose();
- this._fillControl?.dispose();
- this._selectionShape?.dispose();
-
- this._selectionDragAndDrop.dispose();
- }
-
- getScene() {
- return this._manager.getScene();
- }
-
- getPlugin() {
- return this._manager.getPlugin();
- }
-
- get leftControl() {
- return this._leftControl;
- }
-
- get rightControl() {
- return this._rightControl;
- }
-
- get topControl() {
- return this._topControl;
- }
-
- get bottomControl() {
- return this._bottomControl;
- }
-
- get fillControl() {
- return this._fillControl;
- }
-
- get backgroundControlTop() {
- return this._backgroundControlTop;
- }
-
- get backgroundControlBottom() {
- return this._backgroundControlBottom;
- }
-
- get backgroundControlMiddleLeft() {
- return this._backgroundControlMiddleLeft;
- }
-
- get backgroundControlMiddleRight() {
- return this._backgroundControlMiddleRight;
- }
-
- get selectionShape() {
- return this._selectionShape;
- }
-
- get model() {
- return this._selectionModel;
- }
-
- /**
- * Get the cell information of the current selection, considering the case of merging cells
- */
- getCurrentCellInfo(): Nullable<ISelection> {
- const currentCell = this.model.currentCell;
-
- if (currentCell) {
- let currentRangeData;
-
- if (currentCell.isMerged) {
- const mergeInfo = currentCell.mergeInfo;
-
- currentRangeData = {
- startRow: mergeInfo.startRow,
- endRow: mergeInfo.endRow,
- startColumn: mergeInfo.startColumn,
- endColumn: mergeInfo.endColumn,
- startX: mergeInfo.startX,
- endX: mergeInfo.endX,
- startY: mergeInfo.startY,
- endY: mergeInfo.endY,
- };
- } else {
- const { row, column, startX, endX, startY, endY } = currentCell;
- currentRangeData = {
- startRow: row,
- endRow: row,
- startColumn: column,
- endColumn: column,
- startX,
- endX,
- startY,
- endY,
- };
- }
-
- return currentRangeData;
- }
- }
-
- static create(manager: SelectionManager, zIndex: number) {
- return new this(manager, zIndex);
- }
-
- static fromJson(manager: SelectionManager, zIndex: number, newSelectionRange: ISelection) {
- const control = SelectionControl.create(manager, zIndex);
- control.update(newSelectionRange);
- return control;
- }
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index 80c3db0b45..4290b65744 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -30,6 +30,8 @@ import { SelectionControl, SELECTION_TYPE } from './SelectionController';
* SelectionManager 维护model数据list,action也是修改这一层数据,obs监听到数据变动后,自动刷新(control仍然可以持有数据)
*/
export class SelectionManager {
+ hasSelection: boolean = false;
+
private _mainComponent: Spreadsheet;
private _rowComponent: SpreadsheetRowTitle;
@@ -62,7 +64,11 @@ export class SelectionManager {
private _dragLineControl: DragLineController;
- hasSelection: boolean = false;
+ constructor(private _sheetView: SheetView) {
+ this._plugin = this._sheetView.getPlugin() as SheetPlugin;
+ this._initialize();
+ this._initializeObserver();
+ }
getSheetView() {
return this._sheetView;
@@ -420,10 +426,168 @@ export class SelectionManager {
this.addControlToCurrentByRangeData(rangeData, currentCellData);
}
- constructor(private _sheetView: SheetView) {
- this._plugin = this._sheetView.getPlugin() as SheetPlugin;
- this._initialize();
- this._initializeObserver();
+ /**
+ * When mousedown and mouseup need to go to the coordination and undo stack, when mousemove does not need to go to the coordination and undo stack
+ * @param moveEvt
+ * @param selectionControl
+ * @returns
+ */
+ moving(moveEvt: IPointerEvent | IMouseEvent, selectionControl: Nullable<SelectionControl>) {
+ // console.log('moving');
+ const main = this._mainComponent;
+ const { offsetX: moveOffsetX, offsetY: moveOffsetY, clientX, clientY } = moveEvt;
+ const { startRow, startColumn, endRow, endColumn } = this._startSelectionRange;
+
+ const scrollXY = main.getAncestorScrollXY(this._startOffsetX, this._startOffsetY);
+ const moveCellInfo = main.calculateCellIndexByPosition(moveOffsetX, moveOffsetY, scrollXY);
+ const moveActualSelection = makeCellToSelection(moveCellInfo);
+
+ if (!moveActualSelection) {
+ return false;
+ }
+ const { startRow: moveStartRow, startColumn: moveStartColumn, endColumn: moveEndColumn, endRow: moveEndRow } = moveActualSelection;
+
+ const newStartRow = Math.min(moveStartRow, startRow);
+ const newStartColumn = Math.min(moveStartColumn, startColumn);
+ const newEndRow = Math.max(moveEndRow, endRow);
+ const newEndColumn = Math.max(moveEndColumn, endColumn);
+ const newBounding = main.getSelectionBounding(newStartRow, newStartColumn, newEndRow, newEndColumn);
+
+ if (!newBounding) {
+ return false;
+ }
+ const { startRow: finalStartRow, startColumn: finalStartColumn, endRow: finalEndRow, endColumn: finalEndColumn } = newBounding;
+
+ const startCell = main.getNoMergeCellPositionByIndex(finalStartRow, finalStartColumn);
+ const endCell = main.getNoMergeCellPositionByIndex(finalEndRow, finalEndColumn);
+
+ const newSelectionRange: ISelection = {
+ startColumn: finalStartColumn,
+ startRow: finalStartRow,
+ endColumn: finalEndColumn,
+ endRow: finalEndRow,
+ startY: startCell?.startY || 0,
+ endY: endCell?.endY || 0,
+ startX: startCell?.startX || 0,
+ endX: endCell?.endX || 0,
+ };
+ // Only notify when the selection changes
+ const {
+ startRow: oldStartRow,
+ endRow: oldEndRow,
+ startColumn: oldStartColumn,
+ endColumn: oldEndColumn,
+ } = selectionControl?.model || { startRow: -1, endRow: -1, startColumn: -1, endColumn: -1 };
+
+ if (oldStartColumn !== finalStartColumn || oldStartRow !== finalStartRow || oldEndColumn !== finalEndColumn || oldEndRow !== finalEndRow) {
+ selectionControl && selectionControl.update(newSelectionRange);
+ // update model
+ this.setSelectionModel();
+ selectionControl && this._plugin.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
+ }
+ }
+
+ /**
+ * pointer up event
+ * @param moveEvt
+ * @param selectionControl
+ * @returns
+ */
+ up() {
+ // update model
+ this.setSelectionModel();
+ }
+
+ /**
+ * Get all range data of the current selection
+ * @returns
+ */
+ getActiveRangeListData(): Nullable<IRangeData[]> {
+ const models = this.getCurrentModels();
+ if (models && models.length > 0) {
+ const selections = models?.map((model: SelectionModel) => ({
+ startRow: model.startRow,
+ startColumn: model.startColumn,
+ endRow: model.endRow,
+ endColumn: model.endColumn,
+ }));
+
+ return selections;
+ }
+ }
+
+ /**
+ * Returns the list of active ranges in the active sheet or null if there are no active ranges.
+ * If there is a single range selected, this behaves as a getActiveRange() call.
+ *
+ * @returns
+ */
+ getActiveRangeList(): Nullable<RangeList> {
+ const rangeListData = this.getActiveRangeListData();
+ return rangeListData && this._worksheet?.getRangeList(rangeListData);
+ }
+
+ /**
+ * Get the range of the currently active cell
+ * @returns
+ */
+ getActiveRangeData(): Nullable<IRangeData> {
+ const models = this.getCurrentModels();
+ if (models && models.length > 0) {
+ for (const model of models) {
+ if (model.currentCell) {
+ return {
+ startRow: model.startRow,
+ startColumn: model.startColumn,
+ endRow: model.endRow,
+ endColumn: model.endColumn,
+ };
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the selected range in the active sheet, or null if there is no active range. If multiple ranges are selected this method returns only the last selected range.
+ * @returns
+ */
+ getActiveRange(): Nullable<Range> {
+ const rangeData = this.getActiveRangeData();
+ return rangeData && this._worksheet?.getRange(rangeData);
+ }
+
+ /**
+ * get active selection control
+ * @returns
+ */
+ getCurrentCellData(): Nullable<IRangeData> {
+ const models = this.getCurrentModels();
+ if (models && models.length > 0) {
+ for (const model of models) {
+ const currentCell = model.currentCell;
+ if (currentCell) {
+ return {
+ startRow: currentCell.row,
+ startColumn: currentCell.column,
+ endRow: currentCell.row,
+ endColumn: currentCell.column,
+ };
+ }
+ }
+ }
+ }
+
+ /**
+ * get active selection control
+ * @returns
+ */
+ getCurrentCell(): Nullable<Range> {
+ const rangeData = this.getCurrentCellData();
+ return rangeData && this._worksheet?.getRange(rangeData);
+ }
+
+ getDragLineControl() {
+ return this._dragLineControl;
}
private _initialize() {
@@ -584,78 +748,6 @@ export class SelectionManager {
});
}
- /**
- * When mousedown and mouseup need to go to the coordination and undo stack, when mousemove does not need to go to the coordination and undo stack
- * @param moveEvt
- * @param selectionControl
- * @returns
- */
- moving(moveEvt: IPointerEvent | IMouseEvent, selectionControl: Nullable<SelectionControl>) {
- // console.log('moving');
- const main = this._mainComponent;
- const { offsetX: moveOffsetX, offsetY: moveOffsetY, clientX, clientY } = moveEvt;
- const { startRow, startColumn, endRow, endColumn } = this._startSelectionRange;
-
- const scrollXY = main.getAncestorScrollXY(this._startOffsetX, this._startOffsetY);
- const moveCellInfo = main.calculateCellIndexByPosition(moveOffsetX, moveOffsetY, scrollXY);
- const moveActualSelection = makeCellToSelection(moveCellInfo);
-
- if (!moveActualSelection) {
- return false;
- }
- const { startRow: moveStartRow, startColumn: moveStartColumn, endColumn: moveEndColumn, endRow: moveEndRow } = moveActualSelection;
-
- const newStartRow = Math.min(moveStartRow, startRow);
- const newStartColumn = Math.min(moveStartColumn, startColumn);
- const newEndRow = Math.max(moveEndRow, endRow);
- const newEndColumn = Math.max(moveEndColumn, endColumn);
- const newBounding = main.getSelectionBounding(newStartRow, newStartColumn, newEndRow, newEndColumn);
-
- if (!newBounding) {
- return false;
- }
- const { startRow: finalStartRow, startColumn: finalStartColumn, endRow: finalEndRow, endColumn: finalEndColumn } = newBounding;
-
- const startCell = main.getNoMergeCellPositionByIndex(finalStartRow, finalStartColumn);
- const endCell = main.getNoMergeCellPositionByIndex(finalEndRow, finalEndColumn);
-
- const newSelectionRange: ISelection = {
- startColumn: finalStartColumn,
- startRow: finalStartRow,
- endColumn: finalEndColumn,
- endRow: finalEndRow,
- startY: startCell?.startY || 0,
- endY: endCell?.endY || 0,
- startX: startCell?.startX || 0,
- endX: endCell?.endX || 0,
- };
- // Only notify when the selection changes
- const {
- startRow: oldStartRow,
- endRow: oldEndRow,
- startColumn: oldStartColumn,
- endColumn: oldEndColumn,
- } = selectionControl?.model || { startRow: -1, endRow: -1, startColumn: -1, endColumn: -1 };
-
- if (oldStartColumn !== finalStartColumn || oldStartRow !== finalStartRow || oldEndColumn !== finalEndColumn || oldEndRow !== finalEndRow) {
- selectionControl && selectionControl.update(newSelectionRange);
- // update model
- this.setSelectionModel();
- selectionControl && this._plugin.getObserver('onChangeSelectionObserver')?.notifyObservers(selectionControl);
- }
- }
-
- /**
- * pointer up event
- * @param moveEvt
- * @param selectionControl
- * @returns
- */
- up() {
- // update model
- this.setSelectionModel();
- }
-
private _rowEventInitial() {
const row = this._rowComponent;
row.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
@@ -801,96 +893,4 @@ export class SelectionManager {
this.renderCurrentControls();
});
}
-
- /**
- * Get all range data of the current selection
- * @returns
- */
- getActiveRangeListData(): Nullable<IRangeData[]> {
- const models = this.getCurrentModels();
- if (models && models.length > 0) {
- const selections = models?.map((model: SelectionModel) => ({
- startRow: model.startRow,
- startColumn: model.startColumn,
- endRow: model.endRow,
- endColumn: model.endColumn,
- }));
-
- return selections;
- }
- }
-
- /**
- * Returns the list of active ranges in the active sheet or null if there are no active ranges.
- * If there is a single range selected, this behaves as a getActiveRange() call.
- *
- * @returns
- */
- getActiveRangeList(): Nullable<RangeList> {
- const rangeListData = this.getActiveRangeListData();
- return rangeListData && this._worksheet?.getRangeList(rangeListData);
- }
-
- /**
- * Get the range of the currently active cell
- * @returns
- */
- getActiveRangeData(): Nullable<IRangeData> {
- const models = this.getCurrentModels();
- if (models && models.length > 0) {
- for (const model of models) {
- if (model.currentCell) {
- return {
- startRow: model.startRow,
- startColumn: model.startColumn,
- endRow: model.endRow,
- endColumn: model.endColumn,
- };
- }
- }
- }
- }
-
- /**
- * Returns the selected range in the active sheet, or null if there is no active range. If multiple ranges are selected this method returns only the last selected range.
- * @returns
- */
- getActiveRange(): Nullable<Range> {
- const rangeData = this.getActiveRangeData();
- return rangeData && this._worksheet?.getRange(rangeData);
- }
-
- /**
- * get active selection control
- * @returns
- */
- getCurrentCellData(): Nullable<IRangeData> {
- const models = this.getCurrentModels();
- if (models && models.length > 0) {
- for (const model of models) {
- const currentCell = model.currentCell;
- if (currentCell) {
- return {
- startRow: currentCell.row,
- startColumn: currentCell.column,
- endRow: currentCell.row,
- endColumn: currentCell.column,
- };
- }
- }
- }
- }
-
- /**
- * get active selection control
- * @returns
- */
- getCurrentCell(): Nullable<Range> {
- const rangeData = this.getCurrentCellData();
- return rangeData && this._worksheet?.getRange(rangeData);
- }
-
- getDragLineControl() {
- return this._dragLineControl;
- }
}
diff --git a/packages/base-sheets/src/Controller/SheetBarController.ts b/packages/base-sheets/src/Controller/SheetBarController.ts
index ef4ad84586..3d69f4cb0d 100644
--- a/packages/base-sheets/src/Controller/SheetBarController.ts
+++ b/packages/base-sheets/src/Controller/SheetBarController.ts
@@ -4,10 +4,6 @@ import { SheetPlugin } from '../SheetPlugin';
export class SheetBarControl {
protected _plugin: SheetPlugin;
- protected _getCoreObserver<T>(type: string) {
- return this._plugin.getGlobalContext().getObserverManager().requiredObserver<UIObserver<T>>(type, 'core');
- }
-
constructor(plugin: SheetPlugin) {
this._plugin = plugin;
}
@@ -80,4 +76,8 @@ export class SheetBarControl {
}
});
}
+
+ protected _getCoreObserver<T>(type: string) {
+ return this._plugin.getGlobalContext().getObserverManager().requiredObserver<UIObserver<T>>(type, 'core');
+ }
}
diff --git a/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts b/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts
index 99342ed9ae..6e0ba52cdb 100644
--- a/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts
+++ b/packages/base-sheets/src/Model/Action/SetSelectionValueAction.ts
@@ -1,4 +1,4 @@
-import { SheetActionBase, ActionObservers, ActionType, ISheetActionData, ICellInfo, ISelection, Nullable, CommandUnit } from '@univerjs/core';
+import { SheetActionBase, ActionObservers, ActionType, ISheetActionData, ICellInfo, ISelection, Nullable, CommandUnit, CommandManager } from '@univerjs/core';
import { ACTION_NAMES } from '../../Basics';
import { SetSelectionValue } from '../Apply/SetSelectionValue';
@@ -79,3 +79,5 @@ export class SetSelectionValueAction extends SheetActionBase<ISetSelectionValueA
return false;
}
}
+
+CommandManager.register(SetSelectionValueAction.NAME, SetSelectionValueAction);
diff --git a/packages/base-sheets/src/Model/Action/SpreadsheetAction.ts b/packages/base-sheets/src/Model/Action/SpreadsheetAction.ts
index 0073379726..3a0df63bcd 100644
--- a/packages/base-sheets/src/Model/Action/SpreadsheetAction.ts
+++ b/packages/base-sheets/src/Model/Action/SpreadsheetAction.ts
@@ -1 +1,4 @@
-export class SpreadsheetAction {}
+export class SpreadsheetAction {
+ // TODO ...
+ static NAME = 'SpreadsheetAction';
+}
diff --git a/packages/base-sheets/src/View/Render/BaseView.ts b/packages/base-sheets/src/View/Render/BaseView.ts
index 72a1175b13..75024bbf55 100644
--- a/packages/base-sheets/src/View/Render/BaseView.ts
+++ b/packages/base-sheets/src/View/Render/BaseView.ts
@@ -25,9 +25,7 @@ export class BaseView {
return this._plugin.getContext();
}
- updateToSheet(worksheet: Worksheet) {}
-
- protected _initialize() {}
+ updateToSheet(worksheet: Worksheet) { }
initialize(scene: Scene, plugin: SheetPlugin) {
this._scene = scene;
@@ -35,6 +33,10 @@ export class BaseView {
this._initialize();
return this;
}
+
+ protected _initialize() {
+ // TODO
+ }
}
export enum CANVAS_VIEW_KEY {
diff --git a/packages/base-sheets/src/View/Render/CanvasView.ts b/packages/base-sheets/src/View/Render/CanvasView.ts
index 7e42ba89dd..4225a1084e 100644
--- a/packages/base-sheets/src/View/Render/CanvasView.ts
+++ b/packages/base-sheets/src/View/Render/CanvasView.ts
@@ -15,6 +15,24 @@ export class CanvasView {
this._initialize();
}
+ getView(key: string) {
+ for (let view of this._views) {
+ if (view.viewKey === key) {
+ return view;
+ }
+ }
+ }
+
+ getSheetView(): SheetView {
+ return this.getView(CANVAS_VIEW_KEY.SHEET_VIEW) as SheetView;
+ }
+
+ updateToSheet(worksheet: Worksheet) {
+ for (let view of this._views) {
+ view.updateToSheet(worksheet);
+ }
+ }
+
private _initialize() {
const engine = this._engine;
const context = this._plugin.getContext();
@@ -132,24 +150,6 @@ export class CanvasView {
});
}
- getView(key: string) {
- for (let view of this._views) {
- if (view.viewKey === key) {
- return view;
- }
- }
- }
-
- getSheetView(): SheetView {
- return this.getView(CANVAS_VIEW_KEY.SHEET_VIEW) as SheetView;
- }
-
- updateToSheet(worksheet: Worksheet) {
- for (let view of this._views) {
- view.updateToSheet(worksheet);
- }
- }
-
private _viewLoader(scene: Scene, plugin: SheetPlugin) {
CanvasViewRegistry.getData().forEach((viewFactory) => {
this._views.push(viewFactory.create(scene, plugin));
diff --git a/packages/base-sheets/src/View/Render/Views/SheetView.ts b/packages/base-sheets/src/View/Render/Views/SheetView.ts
index 0ab97a03b7..b3e5ee0240 100644
--- a/packages/base-sheets/src/View/Render/Views/SheetView.ts
+++ b/packages/base-sheets/src/View/Render/Views/SheetView.ts
@@ -26,53 +26,6 @@ export class SheetView extends BaseView {
private _spreadsheetLeftTopPlaceholder: Rect;
- protected _initialize() {
- const scene = this.getScene();
- const context = this.getContext();
- const workbook = context.getWorkBook();
- let worksheet = workbook.getActiveSheet();
- if (!worksheet) {
- worksheet = workbook.getSheets()[0];
- }
- const spreadsheetSkeleton = this._buildSkeleton(worksheet);
-
- const { rowTotalHeight, columnTotalWidth, rowTitleWidth, columnTitleHeight } = spreadsheetSkeleton;
- // const rowTitleWidth = rowTitle.hidden !== true ? rowTitle.width : 0;
- // const columnTitleHeight = columnTitle.hidden !== true ? columnTitle.height : 0;
- const spreadsheet = new Spreadsheet(SHEET_VIEW_KEY.MAIN, spreadsheetSkeleton);
- const spreadsheetRowTitle = new SpreadsheetRowTitle(SHEET_VIEW_KEY.ROW, spreadsheetSkeleton);
- const spreadsheetColumnTitle = new SpreadsheetColumnTitle(SHEET_VIEW_KEY.COLUMN, spreadsheetSkeleton);
- const SpreadsheetLeftTopPlaceholder = new Rect(SHEET_VIEW_KEY.LEFT_TOP, {
- zIndex: 2,
- left: -1,
- top: -1,
- width: rowTitleWidth,
- height: columnTitleHeight,
- fill: getColor([248, 249, 250]),
- stroke: getColor([217, 217, 217]),
- strokeWidth: 1,
- });
-
- this._spreadsheetSkeleton = spreadsheetSkeleton;
- this._spreadsheet = spreadsheet;
- this._spreadsheetRowTitle = spreadsheetRowTitle;
- this._spreadsheetColumnTitle = spreadsheetColumnTitle;
- this._spreadsheetLeftTopPlaceholder = SpreadsheetLeftTopPlaceholder;
-
- scene.addObjects([spreadsheet], 0);
- scene.addObjects([spreadsheetRowTitle, spreadsheetColumnTitle, SpreadsheetLeftTopPlaceholder], 2);
- scene.transformByState({
- width: this._columnWidthByTitle(worksheet),
- height: this._rowHeightByTitle(worksheet) + rowTotalHeight,
- // width: this._columnWidthByTitle(worksheet) + columnTotalWidth + 100,
- // height: this._rowHeightByTitle(worksheet) + rowTotalHeight + 200,
- });
-
- this._updateViewport(rowTitleWidth, columnTitleHeight);
-
- this._selectionManager = new SelectionManager(this);
- }
-
getSelectionManager() {
return this._selectionManager;
}
@@ -125,6 +78,53 @@ export class SheetView extends BaseView {
this._selectionManager.updateToSheet(worksheet);
}
+ protected _initialize() {
+ const scene = this.getScene();
+ const context = this.getContext();
+ const workbook = context.getWorkBook();
+ let worksheet = workbook.getActiveSheet();
+ if (!worksheet) {
+ worksheet = workbook.getSheets()[0];
+ }
+ const spreadsheetSkeleton = this._buildSkeleton(worksheet);
+
+ const { rowTotalHeight, columnTotalWidth, rowTitleWidth, columnTitleHeight } = spreadsheetSkeleton;
+ // const rowTitleWidth = rowTitle.hidden !== true ? rowTitle.width : 0;
+ // const columnTitleHeight = columnTitle.hidden !== true ? columnTitle.height : 0;
+ const spreadsheet = new Spreadsheet(SHEET_VIEW_KEY.MAIN, spreadsheetSkeleton);
+ const spreadsheetRowTitle = new SpreadsheetRowTitle(SHEET_VIEW_KEY.ROW, spreadsheetSkeleton);
+ const spreadsheetColumnTitle = new SpreadsheetColumnTitle(SHEET_VIEW_KEY.COLUMN, spreadsheetSkeleton);
+ const SpreadsheetLeftTopPlaceholder = new Rect(SHEET_VIEW_KEY.LEFT_TOP, {
+ zIndex: 2,
+ left: -1,
+ top: -1,
+ width: rowTitleWidth,
+ height: columnTitleHeight,
+ fill: getColor([248, 249, 250]),
+ stroke: getColor([217, 217, 217]),
+ strokeWidth: 1,
+ });
+
+ this._spreadsheetSkeleton = spreadsheetSkeleton;
+ this._spreadsheet = spreadsheet;
+ this._spreadsheetRowTitle = spreadsheetRowTitle;
+ this._spreadsheetColumnTitle = spreadsheetColumnTitle;
+ this._spreadsheetLeftTopPlaceholder = SpreadsheetLeftTopPlaceholder;
+
+ scene.addObjects([spreadsheet], 0);
+ scene.addObjects([spreadsheetRowTitle, spreadsheetColumnTitle, SpreadsheetLeftTopPlaceholder], 2);
+ scene.transformByState({
+ width: this._columnWidthByTitle(worksheet),
+ height: this._rowHeightByTitle(worksheet) + rowTotalHeight,
+ // width: this._columnWidthByTitle(worksheet) + columnTotalWidth + 100,
+ // height: this._rowHeightByTitle(worksheet) + rowTotalHeight + 200,
+ });
+
+ this._updateViewport(rowTitleWidth, columnTitleHeight);
+
+ this._selectionManager = new SelectionManager(this);
+ }
+
private _updateViewport(rowTitleWidth: number, columnTitleHeight: number) {
const scene = this.getScene();
const rowTitleWidthScale = rowTitleWidth * scene.scaleX;
diff --git a/packages/base-sheets/src/View/Render/Views/TestView.ts b/packages/base-sheets/src/View/Render/Views/TestView.ts
index 8c3a5ba6b0..af33f205cc 100644
--- a/packages/base-sheets/src/View/Render/Views/TestView.ts
+++ b/packages/base-sheets/src/View/Render/Views/TestView.ts
@@ -1,6 +1,6 @@
import { EVENT_TYPE, getColor, Rect, Scene } from '@univerjs/base-render';
import { SheetPlugin } from '../../../SheetPlugin';
-import { BaseView, CanvasViewRegistry } from '../BaseView';
+import { BaseView } from '../BaseView';
export class TestView extends BaseView {
protected _initialize() {