Skip to content

Commit

Permalink
chore: better code
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku committed Dec 25, 2024
1 parent 37d44fb commit a800b69
Show file tree
Hide file tree
Showing 66 changed files with 212 additions and 193 deletions.
8 changes: 8 additions & 0 deletions docs/tldr/skeleton.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 44 additions & 18 deletions packages/core/src/sheets/sheet-skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ export class SheetSkeleton extends Skeleton {
protected _cellData: ObjectMatrix<Nullable<ICellData>>;
protected _imageCacheMap: ImageCacheMap;

/** Scale of Scene */
scaleX: number;
scaleY: number;
/** Viewport scrolled value */
scrollX: number;
/** Viewport scrolled value */
scrollY: number;

constructor(
readonly worksheet: Worksheet,
protected _styles: Styles,
Expand All @@ -99,7 +91,6 @@ export class SheetSkeleton extends Skeleton {

/**
* @deprecated should never expose a property that is provided by another module!
* @returns
*/
getWorksheetConfig(): IWorksheetData {
return this._worksheetData;
Expand All @@ -121,6 +112,13 @@ export class SheetSkeleton extends Skeleton {
private _columnWidthAccumulation: number[] = [];
private _marginTop: number = 0;
private _marginLeft: number = 0;
/** Scale of Scene */
protected _scaleX: number;
protected _scaleY: number;
/** Viewport scrolled value */
protected _scrollX: number;
/** Viewport scrolled value */
protected _scrollY: number;

get rowHeightAccumulation(): number[] {
return this._rowHeightAccumulation;
Expand Down Expand Up @@ -156,20 +154,36 @@ export class SheetSkeleton extends Skeleton {

setScale(value: number, valueY?: number): void {
this._updateLayout();
this.scaleX = value;
this.scaleY = valueY || value;
this._scaleX = value;
this._scaleY = valueY || value;
this._updateLayout();
}

setScroll(scrollX?: number, scrollY?: number) {
if (Tools.isDefine(scrollX)) {
this.scrollX = scrollX;
this._scrollX = scrollX;
}
if (Tools.isDefine(scrollY)) {
this.scrollY = scrollY;
this._scrollY = scrollY;
}
}

get scrollX(): number {
return this._scrollX;
}

get scrollY(): number {
return this._scrollY;
}

get scaleX(): number {
return this._scaleX;
}

get scaleY(): number {
return this._scaleY;
}

get rowHeaderWidthAndMarginLeft(): number {
return this.rowHeaderWidth + this._marginLeft;
}
Expand Down Expand Up @@ -377,8 +391,6 @@ export class SheetSkeleton extends Skeleton {
columnCount,
rowHeader,
columnHeader,
showGridlines,
gridlinesColor,
} = this._worksheetData;

const { rowTotalHeight, rowHeightAccumulation } =
Expand Down Expand Up @@ -534,8 +546,23 @@ export class SheetSkeleton extends Skeleton {
* @param column
* @returns {ISelectionCell} The cell info with merge data
*/
protected _getCellMergeInfo(row: number, column: number): ISelectionCell {
return this.worksheet.getCellInfoInMergeData(row, column);
// protected _getCellMergeInfo(row: number, column: number): ISelectionCell {
// return this.worksheet.getCellInfoInMergeData(row, column);
// }

/**
* @deprecated use getNoMergeCellWithCoordByIndex instead.
* @param rowIndex
* @param columnIndex
* @param header
* @returns
*/
getNoMergeCellPositionByIndex(
rowIndex: number,
columnIndex: number,
header: boolean = true
) {
return this.getNoMergeCellWithCoordByIndex(rowIndex, columnIndex, header);
}

/**
Expand Down Expand Up @@ -895,7 +922,6 @@ export class SheetSkeleton extends Skeleton {
* Original name: getDecomposedOffset
* @param offsetX
* @param offsetY
* @returns
*/
getOffsetRelativeToRowCol(
offsetX: number,
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/sheets/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVER
* @param worksheet
*/
setActiveSheet(worksheet: Worksheet): void {
console.log('active sheet');
this._activeSheet$.next(worksheet);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
export * from './component';
export * from './extension';
export * from './sheets';
export { RENDER_RAW_FORMULA_KEY } from './sheets/sheet-skeleton';
export { RENDER_RAW_FORMULA_KEY } from './sheets/sheet.render-skeleton';
export * from './slides';
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { Nullable } from '@univerjs/core';
import type { IViewportInfo, Vector2 } from '../../basics/vector2';
import type { UniverRenderingContext } from '../../context';
import type { ColumnHeaderLayout, IColumnsHeaderCfgParam } from './extensions/column-header-layout';
import type { SpreadsheetSkeleton } from './sheet-skeleton';
import type { SpreadsheetSkeleton } from './sheet.render-skeleton';
import { SheetColumnHeaderExtensionRegistry } from '../extension';
import { SpreadsheetHeader } from './sheet-component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { ICellWithCoord, IRange, IScale, ObjectMatrix } from '@univerjs/core';
import type { UniverRenderingContext } from '../../../context';
import type { IDrawInfo } from '../../extension';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';
import type { Spreadsheet } from '../spreadsheet';
import { Range } from '@univerjs/core';
import { fixLineWidthByScale, getColor, inViewRanges } from '../../../basics/tools';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { UniverRenderingContext } from '../../../context';

import type { IDrawInfo } from '../../extension';
import type { BorderCache, BorderCacheItem } from '../interfaces';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';
import { BorderStyleTypes, Range } from '@univerjs/core';
import { BORDER_TYPE as BORDER_LTRB, COLOR_BLACK_RGB, FIX_ONE_PIXEL_BLUR_OFFSET } from '../../../basics/const';
import { drawDiagonalLineByBorderType, drawLineByBorderType, getLineWidth, setLineType } from '../../../basics/draw';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { IScale } from '@univerjs/core';
import type { UniverRenderingContext } from '../../../context';

import type { IAColumnCfg, IAColumnCfgObj, IColumnStyleCfg } from '../interfaces';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';
import { numberToABC } from '@univerjs/core';
import { DEFAULT_FONTFACE_PLANE, FIX_ONE_PIXEL_BLUR_OFFSET, MIDDLE_CELL_POS_MAGIC_NUMBER } from '../../../basics/const';
import { getColor } from '../../../basics/tools';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { IRange, IScale } from '@univerjs/core';
import type { UniverRenderingContext } from '../../../context';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';
import { Range, sortRules } from '@univerjs/core';
import { SpreadsheetExtensionRegistry } from '../../extension';
import { SheetExtension } from './sheet-extension';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { VERTICAL_ROTATE_ANGLE } from '../../../basics/text-rotation';
import { clampRange, inViewRanges } from '../../../basics/tools';
import { SpreadsheetExtensionRegistry } from '../../extension';
import { EXPAND_SIZE_FOR_RENDER_OVERFLOW, FONT_EXTENSION_Z_INDEX } from '../constants';
import { getDocsSkeletonPageSize, type SpreadsheetSkeleton } from '../sheet-skeleton';
import { getDocsSkeletonPageSize, type SpreadsheetSkeleton } from '../sheet.render-skeleton';
import { SheetExtension } from './sheet-extension';

const UNIQUE_KEY = 'DefaultFontExtension';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import type { IRange, IScale } from '@univerjs/core';
import type { UniverRenderingContext } from '../../../context';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';
import { Range } from '@univerjs/core';
import { SpreadsheetExtensionRegistry } from '../../extension';
import { SheetExtension } from './sheet-extension';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { IScale } from '@univerjs/core';

import type { UniverRenderingContext } from '../../../context';
import type { IARowCfg, IARowCfgObj, IColumnStyleCfg, IRowStyleCfg } from '../interfaces';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';
import { DEFAULT_FONTFACE_PLANE, FIX_ONE_PIXEL_BLUR_OFFSET, MIDDLE_CELL_POS_MAGIC_NUMBER } from '../../../basics/const';
import { getColor } from '../../../basics/tools';
import { SheetRowHeaderExtensionRegistry } from '../../extension';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { IRange } from '@univerjs/core';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import type { SpreadsheetSkeleton } from '../sheet.render-skeleton';

import { Rectangle } from '@univerjs/core';
import { ComponentExtension } from '../../extension';
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/src/components/sheets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export * from './extensions';
export * from './interfaces';
export * from './row-header';
export * from './sheet-component';
export * from './sheet-skeleton';
export * from './sheet.render-skeleton';
export * from './spreadsheet';
2 changes: 1 addition & 1 deletion packages/engine-render/src/components/sheets/row-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { Nullable } from '@univerjs/core';
import type { IViewportInfo, Vector2 } from '../../basics/vector2';
import type { UniverRenderingContext } from '../../context';
import type { IRowsHeaderCfgParam, RowHeaderLayout } from './extensions/row-header-layout';
import type { SpreadsheetSkeleton } from './sheet-skeleton';
import type { SpreadsheetSkeleton } from './sheet.render-skeleton';
import { SheetRowHeaderExtensionRegistry } from '../extension';
import { SpreadsheetHeader } from './sheet-component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { IRange, Nullable } from '@univerjs/core';
import type { IViewportInfo, Vector2 } from '../../basics/vector2';
import type { UniverRenderingContext } from '../../context';
import type { SHEET_EXTENSION_TYPE } from './extensions/sheet-extension';
import type { SpreadsheetSkeleton } from './sheet-skeleton';
import type { SpreadsheetSkeleton } from './sheet.render-skeleton';
import { RENDER_CLASS_TYPE } from '../../basics/const';
import { RenderComponent } from '../component';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,8 @@ export class SpreadsheetSkeleton extends SheetSkeleton {
this._scene = scene;

this._scene.onTransformChange$.subscribeEvent((param: ITransformChangeState) => {
if (param.value.scaleX !== undefined) {
this.scaleX = param.value.scaleX;
}
if (param.value.scaleY !== undefined) {
this.scaleY = param.value.scaleY;
}
this.setScale(param.value.scaleX || 1, param.value.scaleY);
});

// const viewMain = this._scene.getViewport(SHEET_VIEWPORT_KEY.VIEW_MAIN);
// if (viewMain) {
// viewMain;
// }
}

override _updateLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { Background } from './extensions/background';
import type { Border } from './extensions/border';
import type { Font } from './extensions/font';
import type { IPaintForRefresh, IPaintForScrolling, SHEET_VIEWPORT_KEY } from './interfaces';
import type { SpreadsheetSkeleton } from './sheet-skeleton';
import type { SpreadsheetSkeleton } from './sheet.render-skeleton';
import { BooleanNumber, sortRules, Tools } from '@univerjs/core';
import { FIX_ONE_PIXEL_BLUR_OFFSET, RENDER_CLASS_TYPE } from '../../basics/const';
import { getColor } from '../../basics/tools';
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/src/components/sheets/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { CellValueType, IDocumentData, IPaddingData, IStyleBase, IStyleData, ITextRotation, ITextStyle, Nullable, TextDirection } from '@univerjs/core';
import { DEFAULT_EMPTY_DOCUMENT_VALUE, DocumentDataModel, HorizontalAlign, VerticalAlign, WrapStrategy } from '@univerjs/core';
import { convertTextRotation } from '../../basics/text-rotation';
import { DEFAULT_PADDING_DATA } from './sheet-skeleton';
import { DEFAULT_PADDING_DATA } from './sheet.render-skeleton';

export interface ICellStyle {
textRotation?: ITextRotation;
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export { DocumentViewModel } from './components/docs/view-model/document-view-mo
export { DocumentEditArea } from './components/docs/view-model/document-view-model';
export { parseDataStreamToTree } from './components/docs/view-model/document-view-model';
export { getLastColumn } from './components/docs/layout/tools';
export { DEFAULT_PADDING_DATA } from './components/sheets/sheet-skeleton';
export { DEFAULT_PADDING_DATA } from './components/sheets/sheet.render-skeleton';
export * from './context';
export * from './custom';
export * from './engine';
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { IKeyValue, Nullable } from '@univerjs/core';
import type { BaseObject } from './base-object';
import type { IDragEvent, IKeyboardEvent, IMouseEvent, IPointerEvent, IWheelEvent } from './basics/i-events';
import type { IObjectFullState, ISceneTransformState, ITransformChangeState } from './basics/interfaces';
import type { ISceneTransformState, ITransformChangeState } from './basics/interfaces';
import type { ITransformerConfig } from './basics/transformer-config';
import type { Vector2 } from './basics/vector2';
import type { Canvas } from './canvas';
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-render/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"outDir": "lib/types"
},
"references": [{ "path": "./tsconfig.node.json" }],
"include": ["src", "types", "../core/src/skeleton.ts"]
"include": ["src", "types"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
interceptorAutoHeight: () => {
const skeleton = this._renderManagerService.getRenderById(unitId)
?.with(SheetSkeletonManagerService)
.getWorksheetSkeleton(subUnitId)
.getSkeletonParam(subUnitId)
?.skeleton;
if (!skeleton) {
return undefined;
Expand All @@ -200,7 +200,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {

const info: ICellRenderContext = {
data: cell,
style: skeleton.getsStyles().getStyleByCell(cell),
style: skeleton.getStyles().getStyleByCell(cell),
primaryWithCoord: skeleton.getCellWithCoordByIndex(mergeCell?.startRow ?? row, mergeCell?.startColumn ?? col),
unitId,
subUnitId,
Expand All @@ -214,7 +214,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
interceptorAutoWidth: () => {
const skeleton = this._renderManagerService.getRenderById(unitId)
?.with(SheetSkeletonManagerService)
.getWorksheetSkeleton(subUnitId)
.getSkeletonParam(subUnitId)
?.skeleton;
if (!skeleton) {
return undefined;
Expand All @@ -223,7 +223,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {

const info: ICellRenderContext = {
data: cell,
style: skeleton.getsStyles().getStyleByCell(cell),
style: skeleton.getStyles().getStyleByCell(cell),
primaryWithCoord: skeleton.getCellWithCoordByIndex(mergeCell?.startRow ?? row, mergeCell?.startColumn ?? col),
unitId,
subUnitId,
Expand Down Expand Up @@ -335,7 +335,7 @@ export class SheetsDataValidationMobileRenderController extends RxDisposable {
interceptorAutoHeight: () => {
const skeleton = this._renderManagerService.getRenderById(unitId)
?.with(SheetSkeletonManagerService)
.getWorksheetSkeleton(subUnitId)
.getSkeletonParam(subUnitId)
?.skeleton;
if (!skeleton) {
return undefined;
Expand All @@ -344,7 +344,7 @@ export class SheetsDataValidationMobileRenderController extends RxDisposable {

const info: ICellRenderContext = {
data: cell,
style: skeleton.getsStyles().getStyleByCell(cell),
style: skeleton.getStyles().getStyleByCell(cell),
primaryWithCoord: skeleton.getCellWithCoordByIndex(mergeCell?.startRow ?? row, mergeCell?.startColumn ?? col),
unitId,
subUnitId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class SheetsDataValidationReRenderController extends Disposable implement
sheetIds.add(value.subUnitId);
});
sheetIds.forEach((sheetId) => {
this._sheetSkeletonManagerService.getWorksheetSkeleton(sheetId)?.skeleton.makeDirty(true);
this._sheetSkeletonManagerService.getSkeletonParam(sheetId)?.skeleton.makeDirty(true);
});
this._context.mainComponent?.makeForceDirty();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class SheetDrawingPrintingController extends Disposable {
return next(range);
}

const skeleton = renderer.with(SheetSkeletonManagerService).getWorksheetSkeleton(subUnitId);
const skeleton = renderer.with(SheetSkeletonManagerService).getSkeletonParam(subUnitId);
if (!skeleton) {
return next(range);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function getDrawingSizeByCell(
return false;
}
const skeletonManagerService = currentRender.with(SheetSkeletonManagerService);
const skeleton = skeletonManagerService.getWorksheetSkeleton(location.subUnitId)?.skeleton;
const skeleton = skeletonManagerService.getSkeletonParam(location.subUnitId)?.skeleton;
if (skeleton == null) {
return false;
}
Expand Down
Loading

0 comments on commit a800b69

Please sign in to comment.