Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove sheets dependency on engine-render #2520

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/src/types/interfaces/i-row-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ export interface IRowData {
*/
hd?: BooleanNumber;
}

export interface IRowAutoHeightInfo {
row: number;
autoHeight?: number;
}

63 changes: 63 additions & 0 deletions packages/core/src/types/interfaces/i-selection-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,66 @@ export interface ITextRangeParam extends ITextRange {
segmentId?: string; //The ID of the header, footer or footnote the location is in. An empty segment ID signifies the document's body.
isActive?: boolean; // Whether the text range is active or current range.
}

/**
* Determines whether the cell(row, column) is within the range of the merged cells.
*/
export function getCellInfoInMergeData(row: number, column: number, mergeData?: IRange[]): ISelectionCell {
let isMerged = false; // The upper left cell only renders the content
let isMergedMainCell = false;
let newEndRow = row;
let newEndColumn = column;
let mergeRow = row;
let mergeColumn = column;

if (mergeData == null) {
return {
actualRow: row,
actualColumn: column,
isMergedMainCell,
isMerged,
endRow: newEndRow,
endColumn: newEndColumn,
startRow: mergeRow,
startColumn: mergeColumn,
};
}

for (let i = 0; i < mergeData.length; i++) {
const {
startRow: startRowMarge,
endRow: endRowMarge,
startColumn: startColumnMarge,
endColumn: endColumnMarge,
} = mergeData[i];
if (row === startRowMarge && column === startColumnMarge) {
newEndRow = endRowMarge;
newEndColumn = endColumnMarge;
mergeRow = startRowMarge;
mergeColumn = startColumnMarge;

isMergedMainCell = true;
break;
}
if (row >= startRowMarge && row <= endRowMarge && column >= startColumnMarge && column <= endColumnMarge) {
newEndRow = endRowMarge;
newEndColumn = endColumnMarge;
mergeRow = startRowMarge;
mergeColumn = startColumnMarge;

isMerged = true;
break;
}
}

return {
actualRow: row,
actualColumn: column,
isMergedMainCell,
isMerged,
endRow: newEndRow,
endColumn: newEndColumn,
startRow: mergeRow,
startColumn: mergeColumn,
};
}
66 changes: 1 addition & 65 deletions packages/engine-render/src/basics/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ import type {
IRange,
IRangeWithCoord,
IScale,
ISelectionCell,
ISelectionCellWithCoord,
IStyleBase,
LocaleService,
Nullable,
} from '@univerjs/core';
import { BaselineOffset, ColorKit, DEFAULT_STYLES, FontStyleType, Rectangle, Tools } from '@univerjs/core';
import { BaselineOffset, ColorKit, DEFAULT_STYLES, FontStyleType, getCellInfoInMergeData, Rectangle, Tools } from '@univerjs/core';
import * as cjk from 'cjk-regex';

import { FontCache } from '../components/docs/layout/shaping-engine/font-cache';
Expand Down Expand Up @@ -599,69 +598,6 @@ export function getCellByIndex(
};
}

/**
* Determines whether the cell(row, column) is within the range of the merged cells.
*/
export function getCellInfoInMergeData(row: number, column: number, mergeData?: IRange[]): ISelectionCell {
let isMerged = false; // The upper left cell only renders the content
let isMergedMainCell = false;
let newEndRow = row;
let newEndColumn = column;
let mergeRow = row;
let mergeColumn = column;

if (mergeData == null) {
return {
actualRow: row,
actualColumn: column,
isMergedMainCell,
isMerged,
endRow: newEndRow,
endColumn: newEndColumn,
startRow: mergeRow,
startColumn: mergeColumn,
};
}

for (let i = 0; i < mergeData.length; i++) {
const {
startRow: startRowMarge,
endRow: endRowMarge,
startColumn: startColumnMarge,
endColumn: endColumnMarge,
} = mergeData[i];
if (row === startRowMarge && column === startColumnMarge) {
newEndRow = endRowMarge;
newEndColumn = endColumnMarge;
mergeRow = startRowMarge;
mergeColumn = startColumnMarge;

isMergedMainCell = true;
break;
}
if (row >= startRowMarge && row <= endRowMarge && column >= startColumnMarge && column <= endColumnMarge) {
newEndRow = endRowMarge;
newEndColumn = endColumnMarge;
mergeRow = startRowMarge;
mergeColumn = startColumnMarge;

isMerged = true;
break;
}
}

return {
actualRow: row,
actualColumn: column,
isMergedMainCell,
isMerged,
endRow: newEndRow,
endColumn: newEndColumn,
startRow: mergeRow,
startColumn: mergeColumn,
};
}

/**
* Determine whether there are any cells in a row that are not in the merged cells, mainly used for the calculation of auto height
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DEFAULT_STYLES,
DocumentDataModel,
extractPureTextFromCell,
getCellInfoInMergeData,
getColorStyle,
HorizontalAlign,
IContextService,
Expand All @@ -46,6 +47,7 @@ import type {
IObjectArrayPrimitiveType,
IPaddingData,
IRange,
IRowAutoHeightInfo,
IRowData,
ISelectionCellWithCoord,
IStyleBase,
Expand All @@ -67,7 +69,6 @@ import type { IDocumentSkeletonColumn } from '../../basics/i-document-skeleton-c
import {
degToRad,
getCellByIndex,
getCellInfoInMergeData,
getCellPositionByIndex,
getFontStyleString,
hasUnMergedCellInRow,
Expand Down Expand Up @@ -137,11 +138,6 @@ export function getDocsSkeletonPageSize(documentSkeleton: DocumentSkeleton, angl
};
}

export interface IRowAutoHeightInfo {
row: number;
autoHeight?: number;
}

interface ICellOtherConfig {
/**
* textRotation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
FOCUSING_EDITOR_INPUT_FORMULA,
getCellInfoInMergeData,
ICommandService,
IContextService,
isFormulaString,
Expand Down Expand Up @@ -65,7 +66,6 @@ import {
} from '@univerjs/engine-formula';
import {
DeviceInputEventType,
getCellInfoInMergeData,
IRenderManagerService,
ITextSelectionRenderManager,
} from '@univerjs/engine-render';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
Direction,
Disposable,
DisposableCollection,
getCellInfoInMergeData,
ICommandService,
IUniverInstanceService,
LifecycleStages,
Expand All @@ -29,7 +30,7 @@ import {
Tools,
UniverInstanceType,
} from '@univerjs/core';
import { DeviceInputEventType, getCellInfoInMergeData } from '@univerjs/engine-render';
import { DeviceInputEventType } from '@univerjs/engine-render';
import type {
IAddWorksheetMergeMutationParams,
IRemoveSheetMutationParams,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import type { ICellData, IMutationInfo, IObjectMatrixPrimitiveType, IRange, IStyleData, Workbook } from '@univerjs/core';
import {
Disposable,
getCellInfoInMergeData,
ICommandService,
isICellData,
IUniverInstanceService,
Expand All @@ -31,7 +32,6 @@ import {
import { Inject, Injector } from '@wendellhu/redi';
import type { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { AddMergeUndoMutationFactory, AddWorksheetMergeMutation, getAddMergeMutationRangeByType, RemoveMergeUndoMutationFactory, RemoveWorksheetMergeMutation, SelectionManagerService, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService } from '@univerjs/sheets';
import { getCellInfoInMergeData } from '@univerjs/engine-render';
import {
ApplyFormatPainterCommand,
SetOnceFormatPainterCommand,
Expand Down
2 changes: 0 additions & 2 deletions packages/sheets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"peerDependencies": {
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/rpc": "workspace:*",
"@wendellhu/redi": "0.15.4",
"rxjs": ">=7.0.0"
Expand All @@ -75,7 +74,6 @@
"@univerjs/core": "workspace:*",
"@univerjs/engine-formula": "workspace:*",
"@univerjs/engine-numfmt": "workspace:*",
"@univerjs/engine-render": "workspace:*",
"@univerjs/rpc": "workspace:*",
"@univerjs/shared": "workspace:*",
"@wendellhu/redi": "0.15.4",
Expand Down
3 changes: 1 addition & 2 deletions packages/sheets/src/basics/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import type {
Nullable,
ThemeService,
} from '@univerjs/core';
import { ColorKit, makeCellRangeToRangeData } from '@univerjs/core';
import { getCellInfoInMergeData } from '@univerjs/engine-render';
import { ColorKit, getCellInfoInMergeData, makeCellRangeToRangeData } from '@univerjs/core';

export const SELECTION_CONTROL_BORDER_BUFFER_WIDTH = 1.5; // The draggable range of the selection is too thin, making it easy for users to miss. Therefore, a buffer gap is provided to make it easier for users to select.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
* limitations under the License.
*/

import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, Nullable, Workbook } from '@univerjs/core';
import type { BooleanNumber, IMutation, IObjectArrayPrimitiveType, IRange, IRowAutoHeightInfo, Nullable, Workbook } from '@univerjs/core';
import { CommandType, IUniverInstanceService } from '@univerjs/core';
import type { IRowAutoHeightInfo } from '@univerjs/engine-render';
import type { IAccessor } from '@wendellhu/redi';

const MAXIMUM_ROW_HEIGHT = 2000;
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading