refactor(*): replace Tools.generateRandomId with generateRandomId (#5540)

This commit is contained in:
白熱
2025-07-16 16:18:52 +08:00
committed by GitHub
parent ddea707791
commit 8115c3254b
49 changed files with 196 additions and 139 deletions
@@ -20,8 +20,7 @@ import type { IPaddingData } from '../../types/interfaces/i-style-data';
import type { JSONXActions } from './json-x/json-x';
import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../../common/unit';
import { Tools } from '../../shared/tools';
import { generateRandomId, Tools } from '../../shared/tools';
import { getEmptySnapshot } from './empty-snapshot';
import { JSONX } from './json-x/json-x';
import { PRESET_LIST_TYPE } from './preset-list-type';
@@ -246,7 +245,7 @@ export class DocumentDataModel extends DocumentDataModelSimple {
const UNIT_ID_LENGTH = 6;
this._unitId = this.snapshot.id ?? Tools.generateRandomId(UNIT_ID_LENGTH);
this._unitId = this.snapshot.id ?? generateRandomId(UNIT_ID_LENGTH);
this._initializeHeaderFooterModel();
this._name$.next(this.snapshot.title ?? '');
@@ -15,13 +15,13 @@
*/
import type { IDocumentData } from '../../types/interfaces';
import { Tools } from '../../shared/tools';
import { generateRandomId } from '../../shared/tools';
import { BooleanNumber } from '../../types/enum';
import { LocaleType } from '../../types/enum/locale-type';
import { DocumentFlavor } from '../../types/interfaces';
export function getEmptySnapshot(
unitID = Tools.generateRandomId(6),
unitID = generateRandomId(6),
locale = LocaleType.EN_US,
title = ''
): IDocumentData {
@@ -18,7 +18,7 @@ import type { ITextRange } from '../../../../sheets/typedef';
import type { ICustomTable, IParagraph, IParagraphStyle, ITextStyle } from '../../../../types/interfaces';
import type { DocumentDataModel } from '../../document-data-model';
import { MemoryCursor } from '../../../../common/memory-cursor';
import { Tools, UpdateDocsAttributeType } from '../../../../shared';
import { generateRandomId, UpdateDocsAttributeType } from '../../../../shared';
import { PRESET_LIST_TYPE, PresetListType } from '../../preset-list-type';
import { TextXActionType } from '../action-types';
import { TextX } from '../text-x';
@@ -39,7 +39,7 @@ export const switchParagraphBullet = (params: ISwitchParagraphBulletParams) => {
const ID_LENGTH = 6;
let listId = Tools.generateRandomId(ID_LENGTH);
let listId = generateRandomId(ID_LENGTH);
if (currentParagraphs.length === 1) {
const curIndex = paragraphs.indexOf(currentParagraphs[0]);
@@ -184,7 +184,7 @@ export const setParagraphBullet = (params: ISetParagraphBulletParams) => {
}
const ID_LENGTH = 6;
const listId = Tools.generateRandomId(ID_LENGTH);
const listId = generateRandomId(ID_LENGTH);
const memoryCursor = new MemoryCursor();
@@ -16,8 +16,7 @@
import type { IUser } from '@univerjs/protocol';
import { UnitRole } from '@univerjs/protocol';
import { Tools } from '../../shared/tools';
import { generateRandomId } from '../../shared/tools';
const nameMap = {
[UnitRole.Editor]: 'Editor',
@@ -36,7 +35,7 @@ export const createDefaultUser = (type?: UnitRole) => {
} as IUser;
}
const user = {
userID: `${nameMap[type]}_${Tools.generateRandomId(8)}`,
userID: `${nameMap[type]}_${generateRandomId(8)}`,
name: nameMap[type],
avatar: '',
} as IUser;
-9
View File
@@ -237,15 +237,6 @@ export class Tools {
return 'Unknown browser';
}
/**
* Use this method without `Tools`.
*
* @deprecated
*/
static generateRandomId(n: number = 21, alphabet?: string): string {
return generateRandomId(n, alphabet);
}
static getClassName(instance: object): string {
return instance.constructor.name;
}
+2 -2
View File
@@ -17,7 +17,7 @@
import type { IKeyType, Nullable } from '../shared';
import type { IStyleData } from '../types/interfaces';
import type { ICellDataForSheetInterceptor } from './typedef';
import { LRUMap, Tools } from '../shared';
import { generateRandomId, LRUMap, Tools } from '../shared';
/**
* Styles in a workbook, cells locate styles based on style IDs
@@ -68,7 +68,7 @@ export class Styles {
}
add(data: IStyleData, styleObject: string): string {
const id = Tools.generateRandomId(6);
const id = generateRandomId(6);
this._styles[id] = data;
// update cache
this._cacheMap.set(styleObject, id);
+3 -4
View File
@@ -16,12 +16,11 @@
import type { Observable } from 'rxjs';
import type { Nullable } from '../shared';
import type { CustomData, IRangeType, IWorkbookData, IWorksheetData } from './typedef';
import { BehaviorSubject, Subject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../common/unit';
import { ILogService } from '../services/log/log.service';
import { Tools } from '../shared';
import { generateRandomId, Tools } from '../shared';
import { BooleanNumber } from '../types/enum';
import { getEmptySnapshot } from './empty-snapshot';
import { Styles } from './styles';
@@ -96,7 +95,7 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVER
const { styles } = this._snapshot;
if (this._snapshot.id == null || this._snapshot.id.length === 0) {
this._snapshot.id = Tools.generateRandomId(6);
this._snapshot.id = generateRandomId(6);
}
this._unitId = this._snapshot.id;
@@ -399,7 +398,7 @@ export class Workbook extends UnitModel<IWorkbookData, UniverInstanceType.UNIVER
// If there's no sheets in the snapshot, we should create one.
if (Tools.isEmptyObject(sheets)) {
const firstSheetId = Tools.generateRandomId();
const firstSheetId = generateRandomId();
sheets[firstSheetId] = { id: firstSheetId };
}
+2 -1
View File
@@ -25,6 +25,7 @@ import { BuildTextUtils, DocumentDataModel } from '../docs';
import { convertTextRotation, getFontStyleString } from '../docs/data-model/utils';
import { composeStyles, ObjectMatrix, toDisposable, Tools } from '../shared';
import { createRowColIter } from '../shared/row-col-iter';
import { generateRandomId } from '../shared/tools';
import { DEFAULT_STYLES } from '../types/const';
import { CellValueType } from '../types/enum';
import { ColumnManager } from './column-manager';
@@ -98,7 +99,7 @@ export class Worksheet {
this._snapshot = mergeWorksheetSnapshotWithDefault(snapshot);
const { columnData, rowData, cellData } = this._snapshot;
this._sheetId = this._snapshot.id ?? Tools.generateRandomId(6);
this._sheetId = this._snapshot.id ?? generateRandomId(6);
this._cellData = new ObjectMatrix<Nullable<ICellData>>(cellData as IObjectMatrixPrimitiveType<Nullable<ICellData>>);
// This view model will immediately injected with hooks from SheetViewModel service as Worksheet is constructed.
+2 -2
View File
@@ -19,7 +19,7 @@ import type { Nullable } from '../shared';
import type { ISlideData, ISlidePage } from '../types/interfaces';
import { BehaviorSubject } from 'rxjs';
import { UnitModel, UniverInstanceType } from '../common/unit';
import { generateRandomId, Tools } from '../shared';
import { generateRandomId } from '../shared';
import { DEFAULT_SLIDE } from '../types/const';
import { PageType } from '../types/interfaces';
@@ -54,7 +54,7 @@ export class SlideDataModel extends UnitModel<ISlideData, UniverInstanceType.UNI
super();
this._snapshot = { ...DEFAULT_SLIDE, ...snapshot };
this._unitId = this._snapshot.id ?? Tools.generateRandomId(6);
this._unitId = this._snapshot.id ?? generateRandomId(6);
this._name$ = new BehaviorSubject(this._snapshot.title);
this.name$ = this._name$.asObservable();
@@ -21,6 +21,7 @@ import {
BooleanNumber,
COLORS,
Disposable,
generateRandomId,
ICommandService,
IUniverInstanceService,
ObjectRelativeFromH,
@@ -863,7 +864,7 @@ export class DocDrawingTransformerController extends Disposable {
const ID_LENGTH = 6;
const anchor = new Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + Tools.generateRandomId(ID_LENGTH), {
const anchor = new Rect(INLINE_DRAWING_ANCHOR_KEY_PREFIX + generateRandomId(ID_LENGTH), {
left,
top,
height,
@@ -15,7 +15,7 @@
*/
import type { DocumentDataModel, ITypeMentionList } from '@univerjs/core';
import { ICommandService, IMentionIOService, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';
import { generateRandomId, ICommandService, IMentionIOService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { IEditorService } from '@univerjs/docs-ui';
import { useDependency, useObservable } from '@univerjs/ui';
@@ -65,10 +65,10 @@ export const MentionEditPopup = () => {
mentions={mentions}
onSelect={async (mention) => {
await commandService.executeCommand(AddDocMentionCommand.id, {
unitId: univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)!.getUnitId(),
unitId: univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)!.getUnitId(),
mention: {
...mention,
id: Tools.generateRandomId(),
id: generateRandomId(),
},
startIndex: editPopup.anchor,
});
@@ -30,6 +30,7 @@ import type { DocumentViewModel, IRectRangeWithStyle, ITextRangeWithStyle } from
import {
BuildTextUtils,
CommandType,
generateRandomId,
ICommandService,
IUniverInstanceService,
JSONX,
@@ -155,7 +156,7 @@ export const InnerPasteCommand: ICommand<IInnerPasteCommandParams> = {
if (hasTable) {
for (const t of cloneBody.tables!) {
const { tableId: oldTableId } = t;
const tableId = Tools.generateRandomId(6);
const tableId = generateRandomId(6);
t.tableId = tableId;
@@ -174,7 +175,7 @@ export const InnerPasteCommand: ICommand<IInnerPasteCommandParams> = {
for (const block of cloneBody.customBlocks!) {
const { blockId } = block;
const drawingId = Tools.generateRandomId(6);
const drawingId = generateRandomId(6);
block.blockId = drawingId;
@@ -17,7 +17,7 @@
import type { DocumentDataModel, ICommand, IDocumentBody, IMutationInfo, JSONXActions } from '@univerjs/core';
import type { IRichTextEditingMutationParams } from '@univerjs/docs';
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
import { BooleanNumber, CommandType, ICommandService, IUniverInstanceService, JSONX, Tools } from '@univerjs/core';
import { BooleanNumber, CommandType, generateRandomId, ICommandService, IUniverInstanceService, JSONX } from '@univerjs/core';
import { DocSelectionManagerService, DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
import { findFirstCursorOffset } from '../../basics/selection';
@@ -57,7 +57,7 @@ function getEmptyHeaderFooterBody(): IDocumentBody {
function createHeaderFooterAction(segmentId: string, createType: HeaderFooterType, documentStyle: IHeaderFooterProps, actions: JSONXActions) {
const jsonX = JSONX.getInstance();
const ID_LEN = 6;
const firstSegmentId = segmentId ?? Tools.generateRandomId(ID_LEN);
const firstSegmentId = segmentId ?? generateRandomId(ID_LEN);
const isHeader = createType === HeaderFooterType.DEFAULT_HEADER || createType === HeaderFooterType.FIRST_PAGE_HEADER || createType === HeaderFooterType.EVEN_PAGE_HEADER;
const insertAction = jsonX.insertOp([isHeader ? 'headers' : 'footers', firstSegmentId], {
[isHeader ? 'headerId' : 'footerId']: firstSegmentId,
@@ -67,7 +67,7 @@ function createHeaderFooterAction(segmentId: string, createType: HeaderFooterTyp
actions!.push(insertAction!);
// Also need to create an empty footer if you create a header, and vice versa. They are always created in pairs.
const secondSegmentId = Tools.generateRandomId(ID_LEN);
const secondSegmentId = generateRandomId(ID_LEN);
const insertPairAction = jsonX.insertOp([isHeader ? 'footers' : 'headers', secondSegmentId], {
[isHeader ? 'footerId' : 'headerId']: secondSegmentId,
body: getEmptyHeaderFooterBody(),
@@ -20,6 +20,7 @@ import type { ITextRangeWithStyle } from '@univerjs/engine-render';
import {
BuildTextUtils,
CommandType,
generateRandomId,
ICommandService,
IUniverInstanceService,
JSONX,
@@ -29,7 +30,6 @@ import {
sortRulesFactory,
TextX,
TextXActionType,
Tools,
UniverInstanceType,
} from '@univerjs/core';
import { DocSelectionManagerService, RichTextEditingMutation } from '@univerjs/docs';
@@ -398,7 +398,7 @@ export const QuickListCommand: ICommand<IQuickListCommandParams> = {
const bulletParagraphTextStyle = paragraphProperties.textStyle;
const ID_LENGTH = 6;
let listId = Tools.generateRandomId(ID_LENGTH);
let listId = generateRandomId(ID_LENGTH);
const paragraphs = docDataModel.getBody()?.paragraphs ?? [];
const curIndex = paragraphs.findIndex((i) => i.startIndex === paragraph.startIndex);
@@ -508,7 +508,7 @@ function insertList(accessor: IAccessor, listType: PresetListType) {
},
bullet: {
listType,
listId: paragraph.bullet?.listType === listType ? paragraph.bullet.listId : Tools.generateRandomId(6),
listId: paragraph.bullet?.listType === listType ? paragraph.bullet.listId : generateRandomId(6),
nestingLevel: paragraph.bullet?.listType === listType ? paragraph.bullet.nestingLevel : 0,
},
},
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Nullable } from 'vitest';
import type { Nullable } from '@univerjs/core';
import type { ITabCommandParams } from '../commands/commands/auto-format.command';
import { Disposable, Inject, QuickListTypeMap } from '@univerjs/core';
import { DocSkeletonManagerService } from '@univerjs/docs';
@@ -14,11 +14,20 @@
* limitations under the License.
*/
import type { DocumentDataModel, ICommandInfo } from '@univerjs/core';
import type { DocumentDataModel, ICommandInfo, Nullable } from '@univerjs/core';
import type { Documents, DocumentViewModel, IMouseEvent, IPageRenderConfig, IPathProps, IPointerEvent, IRenderContext, IRenderModule, RenderComponentType } from '@univerjs/engine-render';
import type { Nullable } from 'vitest';
import { BooleanNumber, Disposable, DocumentFlavor, ICommandService, Inject, IUniverInstanceService, LocaleService, toDisposable, Tools, UniverInstanceType } from '@univerjs/core';
import {
BooleanNumber,
Disposable,
DocumentFlavor,
generateRandomId,
ICommandService,
Inject,
IUniverInstanceService,
LocaleService,
toDisposable,
UniverInstanceType,
} from '@univerjs/core';
import { DocSkeletonManagerService, RichTextEditingMutation } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService, PageLayoutType, Path, Rect, Vector2 } from '@univerjs/engine-render';
import { ComponentManager } from '@univerjs/ui';
@@ -256,7 +265,7 @@ export class DocHeaderFooterController extends Disposable implements IRenderModu
} else {
if (createType != null) {
const SEGMENT_ID_LEN = 6;
const segmentId = Tools.generateRandomId(SEGMENT_ID_LEN);
const segmentId = generateRandomId(SEGMENT_ID_LEN);
this._docSelectionRenderService.setSegment(segmentId);
this._docSelectionRenderService.setSegmentPage(pageNumber);
@@ -17,8 +17,29 @@
import type { IDisposable, IDocumentBody, IDocumentData } from '@univerjs/core';
import type { IDocImage } from '@univerjs/docs-drawing';
import type { IRectRangeWithStyle, ITextRangeWithStyle } from '@univerjs/engine-render';
import { BuildTextUtils, createIdentifier, DataStreamTreeTokenType, Disposable, DOC_RANGE_TYPE, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DrawingTypeEnum, generateRandomId, getBodySlice, ICommandService, ILogService, Inject, IUniverInstanceService, normalizeBody, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, SliceBodyType, toDisposable, Tools, UniverInstanceType } from '@univerjs/core';
import {
BuildTextUtils,
createIdentifier,
DataStreamTreeTokenType,
Disposable,
DOC_RANGE_TYPE,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
DrawingTypeEnum,
generateRandomId,
getBodySlice,
ICommandService,
ILogService,
Inject,
IUniverInstanceService,
normalizeBody,
ObjectRelativeFromH,
ObjectRelativeFromV,
PositionedObjectLayoutType,
SliceBodyType,
toDisposable,
Tools,
UniverInstanceType,
} from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { ImageSourceType } from '@univerjs/drawing';
import {
@@ -336,7 +357,7 @@ export class DocClipboardService extends Disposable implements IDocClipboardServ
const drawing = doc.drawings?.[blockId];
if (drawing) {
const id = Tools.generateRandomId(6);
const id = generateRandomId(6);
block.blockId = id;
@@ -15,13 +15,13 @@
*/
import type { IDocumentData } from '@univerjs/core';
import { LRUMap, Tools } from '@univerjs/core';
import { generateRandomId, LRUMap } from '@univerjs/core';
const COPY_CONTENT_CACHE_LIMIT = 10;
const ID_LENGTH = 6;
export function genId() {
return Tools.generateRandomId(ID_LENGTH);
return generateRandomId(ID_LENGTH);
}
export function extractId(html: string) {
@@ -16,8 +16,17 @@
import type { IDocumentBody, IDocumentData, ITable, ITextStyle, Nullable } from '@univerjs/core';
import type { IAfterProcessRule, IPastePlugin, IStyleRule } from './paste-plugins/type';
import { CustomRangeType, DataStreamTreeTokenType, DrawingTypeEnum, generateRandomId, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, skipParseTagNames, Tools } from '@univerjs/core';
import {
CustomRangeType,
DataStreamTreeTokenType,
DrawingTypeEnum,
generateRandomId,
ObjectRelativeFromH,
ObjectRelativeFromV,
PositionedObjectLayoutType,
skipParseTagNames,
Tools,
} from '@univerjs/core';
import { ImageSourceType } from '@univerjs/drawing';
import { genTableSource, getEmptyTableCell, getEmptyTableRow, getTableColumn } from '../../../commands/commands/table/table';
import { extractNodeStyle } from './parse-node-style';
@@ -138,8 +147,8 @@ export class HtmlToUDMService {
const height = Number(element.dataset.height || 100);
const docTransformWidth = Number(element.dataset.docTransformWidth || width);
const docTransformHeight = Number(element.dataset.docTransformHeight || height);
// 外部会进行替换.
const id = Tools.generateRandomId(6);
const id = generateRandomId(6);
doc.body?.customBlocks?.push({ startIndex: body.dataStream.length, blockId: id });
body.dataStream += '\b';
if (!doc.drawings) {
@@ -17,7 +17,7 @@
import type { Nullable } from '@univerjs/core';
import type { Documents, DocumentSkeleton, INodePosition, IPoint, ITextSelectionStyle, Scene } from '@univerjs/engine-render';
import type { IDocRange } from './range-interface';
import { COLORS, DOC_RANGE_TYPE, RANGE_DIRECTION, Rectangle, Tools } from '@univerjs/core';
import { COLORS, DOC_RANGE_TYPE, generateRandomId, RANGE_DIRECTION, Rectangle } from '@univerjs/core';
import { getColor, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, RegularPolygon } from '@univerjs/engine-render';
import { compareNodePositionInTable, NodePositionConvertToRectRange } from './convert-rect-range';
import { TEXT_RANGE_LAYER_INDEX } from './text-range';
@@ -256,7 +256,7 @@ export class RectRange implements IDocRange {
}
const OPACITY = 0.3;
const polygon = new RegularPolygon(RECT_RANGE_KEY_PREFIX + Tools.generateRandomId(ID_LENGTH), {
const polygon = new RegularPolygon(RECT_RANGE_KEY_PREFIX + generateRandomId(ID_LENGTH), {
pointsGroup,
fill: this.style?.fill || getColor(COLORS.black, OPACITY),
left,
@@ -17,7 +17,7 @@
import type { ITextRange, Nullable } from '@univerjs/core';
import type { Documents, DocumentSkeleton, IDocumentSkeletonGlyph, INodePosition, IPoint, ISuccinctDocRangeParam, ITextSelectionStyle, Scene } from '@univerjs/engine-render';
import type { IDocRange } from './range-interface';
import { BooleanNumber, COLORS, DOC_RANGE_TYPE, generateRandomId, RANGE_DIRECTION, Tools } from '@univerjs/core';
import { BooleanNumber, COLORS, DOC_RANGE_TYPE, generateRandomId, RANGE_DIRECTION } from '@univerjs/core';
import { getColor, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, Rect, RegularPolygon } from '@univerjs/engine-render';
import {
compareNodePosition,
@@ -422,7 +422,7 @@ export class TextRange implements IDocRange {
}
const OPACITY = 0.3;
const polygon = new RegularPolygon(TEXT_RANGE_KEY_PREFIX + Tools.generateRandomId(ID_LENGTH), {
const polygon = new RegularPolygon(TEXT_RANGE_KEY_PREFIX + generateRandomId(ID_LENGTH), {
pointsGroup,
fill: this.style?.fill || getColor(COLORS.black, OPACITY),
left,
@@ -16,7 +16,7 @@
import type { IDocumentStyle } from '@univerjs/core';
import type { IHeaderFooterProps } from '../../../commands/commands/doc-header-footer.command';
import { BooleanNumber, ICommandService, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
import { BooleanNumber, generateRandomId, ICommandService, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { Button, Checkbox, InputNumber } from '@univerjs/design';
import { DocSkeletonManagerService } from '@univerjs/docs';
import { DocumentEditArea, IRenderManagerService } from '@univerjs/engine-render';
@@ -26,7 +26,16 @@ import { CloseHeaderFooterCommand, CoreHeaderFooterCommandId } from '../../../co
import { DocSelectionRenderService } from '../../../services/selection/doc-selection-render.service';
function getSegmentId(documentStyle: IDocumentStyle, editArea: DocumentEditArea, pageIndex: number): string {
const { useFirstPageHeaderFooter, evenAndOddHeaders, defaultHeaderId, defaultFooterId, firstPageHeaderId, firstPageFooterId, evenPageHeaderId, evenPageFooterId } = documentStyle;
const {
useFirstPageHeaderFooter,
evenAndOddHeaders,
defaultHeaderId,
defaultFooterId,
firstPageHeaderId,
firstPageFooterId,
evenPageHeaderId,
evenPageFooterId,
} = documentStyle;
if (editArea === DocumentEditArea.HEADER) {
if (useFirstPageHeaderFooter === BooleanNumber.TRUE) {
@@ -115,7 +124,7 @@ export const DocHeaderFooterOptions = (props: IDocHeaderFooterOptionsProps) => {
if (needCreateHeaderFooter) {
const SEGMENT_ID_LEN = 6;
const segmentId = Tools.generateRandomId(SEGMENT_ID_LEN);
const segmentId = generateRandomId(SEGMENT_ID_LEN);
// Set segment id first, then exec command.
if (needChangeSegmentId) {
docSelectionRenderService.setSegment(segmentId);
@@ -16,7 +16,7 @@
import type { IDrawingParam } from '@univerjs/core';
import type { IDrawingGroupUpdateParam } from '@univerjs/drawing';
import { DrawingTypeEnum, LocaleService, Tools } from '@univerjs/core';
import { DrawingTypeEnum, generateRandomId, LocaleService } from '@univerjs/core';
import { Button, clsx } from '@univerjs/design';
import { IDrawingManagerService } from '@univerjs/drawing';
import { getGroupState, IRenderManagerService, transformObjectOutOfGroup } from '@univerjs/engine-render';
@@ -45,7 +45,7 @@ export const DrawingGroup = (props: IDrawingGroupProps) => {
const onGroupBtnClick = () => {
const focusDrawings = drawingManagerService.getFocusDrawings();
const { unitId, subUnitId } = focusDrawings[0];
const groupId = Tools.generateRandomId(10);
const groupId = generateRandomId(10);
const groupTransform = getGroupState(0, 0, focusDrawings.map((o) => o.transform || {}));
const groupParam = {
unitId,
@@ -17,7 +17,7 @@
import type { Nullable } from '@univerjs/core';
import type { Observable } from 'rxjs';
import type { IImageIoService, IImageIoServiceParam } from './image-io.service';
import { Tools } from '@univerjs/core';
import { generateRandomId } from '@univerjs/core';
import { Subject } from 'rxjs';
import { DRAWING_IMAGE_ALLOW_IMAGE_LIST, DRAWING_IMAGE_ALLOW_SIZE } from '../basics/config';
import { ImageSourceType, ImageUploadStatusType } from './image-io.service';
@@ -77,7 +77,7 @@ export class ImageIoService implements IImageIoService {
return;
}
const imageId = Tools.generateRandomId(6);
const imageId = generateRandomId(6);
resolve({
imageId,
imageSourceType: ImageSourceType.BASE64,
@@ -16,8 +16,7 @@
import type { Nullable } from '@univerjs/core';
import type { LambdaPrivacyVarType } from './base-ast-node';
import { Inject, Tools } from '@univerjs/core';
import { generateRandomId, Inject } from '@univerjs/core';
import { ErrorType } from '../../basics/error-type';
import {
DEFAULT_TOKEN_LAMBDA_FUNCTION_NAME,
@@ -120,7 +119,7 @@ export class LambdaNodeFactory extends BaseAstNodeFactory {
}
// const lambdaId = nanoid(8);
const lambdaId = Tools.generateRandomId(8);
const lambdaId = generateRandomId(8);
// const lambdaRuntime = parserDataLoader.getLambdaRuntime();
const currentLambdaPrivacyVar = new Map<string, Nullable<BaseAstNode>>();
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import type { Nullable } from 'vitest';
import type { Nullable } from '@univerjs/core';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { Hyphen } from '../hyphen';
import { Lang } from '../lang';
@@ -18,8 +18,7 @@ import type { ICellData, IRange, Nullable } from '@univerjs/core';
import type { IRemoveOtherFormulaMutationParams, ISetFormulaCalculationResultMutation, ISetOtherFormulaMutationParams } from '@univerjs/engine-formula';
import type { IConditionalFormattingFormulaMarkDirtyParams } from '../commands/mutations/formula-mark-dirty.mutation';
import type { IConditionalFormattingRuleConfig } from '../models/type';
import { BooleanNumber, CellValueType, Disposable, ICommandService, Inject, ObjectMatrix, RefAlias, Tools } from '@univerjs/core';
import { BooleanNumber, CellValueType, Disposable, generateRandomId, ICommandService, Inject, ObjectMatrix, RefAlias } from '@univerjs/core';
import {
IActiveDirtyManagerService,
RemoveOtherFormulaMutation,
@@ -284,7 +283,7 @@ export class ConditionalFormattingFormulaService extends Disposable {
* The external environment is not aware of`formulaId`;it communicates internally with the formula engine.
*/
private _createFormulaId(unitId: string, subUnitId: string) {
return `sheet.cf_${unitId}_${subUnitId}_${Tools.generateRandomId(8)}`;
return `sheet.cf_${unitId}_${subUnitId}_${generateRandomId(8)}`;
}
/**
@@ -15,12 +15,33 @@
*/
import type { IMutationInfo, IRange, Workbook } from '@univerjs/core';
import type { IInsertColMutationParams, IMoveColumnsMutationParams, IMoveRangeMutationParams, IMoveRowsMutationParams, IRemoveRowsMutationParams, IRemoveSheetCommandParams, IReorderRangeMutationParams, ISetRangeValuesMutationParams } from '@univerjs/sheets';
import type {
IInsertColMutationParams,
IMoveColumnsMutationParams,
IMoveRangeMutationParams,
IMoveRowsMutationParams,
IRemoveRowsMutationParams,
IRemoveSheetCommandParams,
IReorderRangeMutationParams,
ISetRangeValuesMutationParams,
} from '@univerjs/sheets';
import type { IDeleteConditionalRuleMutationParams } from '../commands/mutations/delete-conditional-rule.mutation';
import type { IConditionFormattingRule, IHighlightCell, IRuleModelJson } from '../models/type';
import type { IDataBarCellData, IDataBarRenderParams, IIconSetCellData, IIconSetRenderParams } from '../render/type';
import { Disposable, ICommandService, Inject, Injector, IResourceManagerService, IUniverInstanceService, ObjectMatrix, Rectangle, Tools, UniverInstanceType } from '@univerjs/core';
import { InsertColMutation, InsertRowMutation, MoveColsMutation, MoveRangeMutation, MoveRowsMutation, RemoveColMutation, RemoveRowMutation, RemoveSheetCommand, ReorderRangeMutation, SetRangeValuesMutation, SheetInterceptorService } from '@univerjs/sheets';
import { Disposable, ICommandService, Inject, Injector, IResourceManagerService, IUniverInstanceService, merge, ObjectMatrix, Rectangle, UniverInstanceType } from '@univerjs/core';
import {
InsertColMutation,
InsertRowMutation,
MoveColsMutation,
MoveRangeMutation,
MoveRowsMutation,
RemoveColMutation,
RemoveRowMutation,
RemoveSheetCommand,
ReorderRangeMutation,
SetRangeValuesMutation,
SheetInterceptorService,
} from '@univerjs/sheets';
import { CFRuleType, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '../base/const';
import { DeleteConditionalRuleMutation, DeleteConditionalRuleMutationUndoFactory } from '../commands/mutations/delete-conditional-rule.mutation';
import { ConditionalFormattingRuleModel } from '../models/conditional-formatting-rule-model';
@@ -61,7 +82,7 @@ export class ConditionalFormattingService extends Disposable {
const ruleCacheItem = cellCfs.find((cache) => cache.cfId === rule.cfId);
if (type === CFRuleType.highlightCell) {
ruleCacheItem!.result && Tools.deepMerge(pre, { style: ruleCacheItem!.result });
ruleCacheItem!.result && merge(pre, { style: ruleCacheItem!.result });
} else if (type === CFRuleType.colorScale) {
const ruleCache = ruleCacheItem?.result;
if (ruleCache && typeof ruleCache === 'string') {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Tools } from '@univerjs/core';
import { generateRandomId } from '@univerjs/core';
// Given that unit and sunUnit will change in the case of replica creation, the ID will not be spelled in here
export const createCfId = () => `${Tools.generateRandomId(8)}`;
export const createCfId = () => `${generateRandomId(8)}`;
@@ -17,7 +17,7 @@
import type { IFormulaInputProps } from '@univerjs/data-validation';
import type { ListValidator } from '@univerjs/sheets-data-validation';
import type { IFormulaEditorRef } from '@univerjs/sheets-formula-ui';
import { DataValidationType, isFormulaString, LocaleService, Tools } from '@univerjs/core';
import { DataValidationType, generateRandomId, isFormulaString, LocaleService } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
import { borderClassName, clsx, DraggableList, Dropdown, FormLayout, Input, Radio, RadioGroup } from '@univerjs/design';
import { DeleteIcon, IncreaseIcon, MoreDownIcon, SequenceIcon } from '@univerjs/icons';
@@ -210,7 +210,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {
label,
color: strColors[i] || DROP_DOWN_DEFAULT_COLOR,
isRef: false,
id: Tools.generateRandomId(4),
id: generateRandomId(4),
}));
});
@@ -261,7 +261,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {
label: '',
color: DROP_DOWN_DEFAULT_COLOR,
isRef: false,
id: Tools.generateRandomId(4),
id: generateRandomId(4),
},
]);
};
@@ -15,13 +15,13 @@
*/
import type { IAccessor } from '@univerjs/core';
import { DataValidationOperator, DataValidationType, Tools } from '@univerjs/core';
import { DataValidationOperator, DataValidationType, generateRandomId } from '@univerjs/core';
import { SheetsSelectionsService } from '@univerjs/sheets';
export function createDefaultNewRule(accessor: IAccessor) {
const selectionManagerService = accessor.get(SheetsSelectionsService);
const currentRanges = selectionManagerService.getCurrentSelections().map((s) => s.range);
const uid = Tools.generateRandomId(6);
const uid = generateRandomId(6);
const rule = {
uid,
type: DataValidationType.DECIMAL,
@@ -19,12 +19,19 @@ import type { IDrawingJsonUndo1 } from '@univerjs/drawing';
import type { ISheetDrawing, ISheetImage } from '@univerjs/sheets-drawing';
import type { IDiscreteRange, IPasteHookValueType, ISheetDiscreteRangeLocation } from '@univerjs/sheets-ui';
import type { IDeleteDrawingCommandParams } from '../commands/commands/interfaces';
import { Disposable, DrawingTypeEnum, ICommandService, Tools } from '@univerjs/core';
import { Disposable, DrawingTypeEnum, generateRandomId, ICommandService } from '@univerjs/core';
import { IDrawingManagerService, ImageSourceType } from '@univerjs/drawing';
import { IRenderManagerService } from '@univerjs/engine-render';
import { DrawingApplyType, SetDrawingApplyMutation, SheetDrawingAnchorType } from '@univerjs/sheets-drawing';
import { COPY_TYPE, discreteRangeToRange, ISheetClipboardService, ISheetSelectionRenderService, PREDEFINED_HOOK_NAME, SheetSkeletonManagerService, virtualizeDiscreteRanges } from '@univerjs/sheets-ui';
import {
COPY_TYPE,
discreteRangeToRange,
ISheetClipboardService,
ISheetSelectionRenderService,
PREDEFINED_HOOK_NAME,
SheetSkeletonManagerService,
virtualizeDiscreteRanges,
} from '@univerjs/sheets-ui';
import { IClipboardInterfaceService } from '@univerjs/ui';
import { transformToDrawingPosition } from '../basics/transform-position';
import { InsertFloatImageCommand } from '../commands/commands/insert-image.command';
@@ -333,7 +340,7 @@ export class SheetsDrawingCopyPasteController extends Disposable {
...drawing,
unitId,
subUnitId,
drawingId: isCut ? drawing.drawingId : Tools.generateRandomId(),
drawingId: isCut ? drawing.drawingId : generateRandomId(),
transform: transformContext.transform,
sheetTransform: transformContext.sheetTransform,
};
@@ -19,6 +19,7 @@ import type { AutoFillService, IAutoFillLocation, IAutoFillRule, ICopyDataInType
import {
Direction,
Disposable,
generateRandomId,
Inject,
isFormulaId,
isFormulaString,
@@ -95,7 +96,7 @@ export class FormulaAutoFillController extends Disposable {
let formulaId = formulaIdMap.get(dataIndex);
if (!formulaId) {
formulaId = Tools.generateRandomId(6);
formulaId = generateRandomId(6);
formulaIdMap.set(dataIndex, formulaId);
const { offsetX, offsetY } = directionToOffset(step, len, direction, location, sourceIndex);
@@ -20,13 +20,13 @@ import type { ICellDataWithSpanInfo, ICopyPastePayload, IDiscreteRange, IPasteHo
import {
DEFAULT_EMPTY_DOCUMENT_VALUE,
Disposable,
generateRandomId,
Inject,
Injector,
isFormulaId,
isFormulaString,
IUniverInstanceService,
ObjectMatrix,
Tools,
UniverInstanceType,
} from '@univerjs/core';
import { FormulaDataModel, LexerTreeBuilder } from '@univerjs/engine-formula';
@@ -353,7 +353,7 @@ function getSpecialPasteFormulaValueMatrix(
let formulaId = formulaIdMap.get(index);
if (!formulaId) {
formulaId = Tools.generateRandomId(6);
formulaId = generateRandomId(6);
formulaIdMap.set(index, formulaId);
const offsetX = range.cols[col] - pasteFrom.range.cols[col % pasteFrom.range.cols.length];
@@ -487,7 +487,7 @@ function getDefaultPasteValueMatrix(
let formulaId = formulaIdMap.get(index);
if (!formulaId) {
formulaId = Tools.generateRandomId(6);
formulaId = generateRandomId(6);
formulaIdMap.set(index, formulaId);
const offsetX = range.cols[col] - pasteFrom.range.cols[col % pasteFrom.range.cols.length];
@@ -16,7 +16,7 @@
import type { IAccessor, ICellData, ICommand, IRange } from '@univerjs/core';
import type { ISetRangeValuesCommandParams } from '@univerjs/sheets';
import { CommandType, ICommandService, ObjectMatrix, Tools } from '@univerjs/core';
import { CommandType, generateRandomId, ICommandService, ObjectMatrix } from '@univerjs/core';
import { SetRangeValuesCommand } from '@univerjs/sheets';
export interface IInsertFunction {
@@ -56,7 +56,7 @@ export const InsertFunctionCommand: ICommand = {
list.forEach((item) => {
const { range, primary, formula } = item;
const { row, column } = primary;
const formulaId = Tools.generateRandomId(6);
const formulaId = generateRandomId(6);
cellMatrix.setValue(row, column, {
f: formula,
si: formulaId,
@@ -18,7 +18,7 @@ import type { IRange, Nullable } from '@univerjs/core';
import type { IRemoveOtherFormulaMutationParams, ISetFormulaCalculationResultMutation, ISetOtherFormulaMutationParams } from '@univerjs/engine-formula';
import type { IOtherFormulaMarkDirtyParams } from '../commands/mutations/formula.mutation';
import type { IOtherFormulaResult } from './formula-common';
import { Disposable, ICommandService, Inject, LifecycleService, ObjectMatrix, Tools } from '@univerjs/core';
import { Disposable, generateRandomId, ICommandService, Inject, LifecycleService, ObjectMatrix } from '@univerjs/core';
import { IActiveDirtyManagerService, RemoveOtherFormulaMutation, SetFormulaCalculationResultMutation, SetOtherFormulaMutation } from '@univerjs/engine-formula';
import { BehaviorSubject, bufferWhen, filter, Subject } from 'rxjs';
import { OtherFormulaMarkDirty } from '../commands/mutations/formula.mutation';
@@ -73,7 +73,7 @@ export class RegisterOtherFormulaService extends Disposable {
}
private _createFormulaId(unitId: string, subUnitId: string) {
return `formula.${unitId}_${subUnitId}_${Tools.generateRandomId(8)}`;
return `formula.${unitId}_${subUnitId}_${generateRandomId(8)}`;
}
private _initFormulaRegister() {
@@ -16,7 +16,7 @@
import type { IMutationInfo } from '@univerjs/core';
import type { IAutoFillLocation, ISheetAutoFillHook } from '@univerjs/sheets-ui';
import { Disposable, Inject, Range, Rectangle, Tools } from '@univerjs/core';
import { Disposable, generateRandomId, Inject, Range, Rectangle } from '@univerjs/core';
import { AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation } from '@univerjs/sheets-hyper-link';
import { APPLY_TYPE, getAutoFillRepeatRange, IAutoFillService, virtualizeDiscreteRanges } from '@univerjs/sheets-ui';
import { SHEET_HYPER_LINK_UI_PLUGIN } from '../types/const';
@@ -87,7 +87,7 @@ export class SheetsHyperLinkAutoFillController extends Disposable {
targetRange
);
const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn);
const id = Tools.generateRandomId();
const id = generateRandomId();
const currentLink = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, targetRow, targetCol);
if (currentLink) {
redos.push({
@@ -16,7 +16,7 @@
import type { IMutationInfo, IRange, Nullable } from '@univerjs/core';
import type { IDiscreteRange, IPasteHookValueType, ISheetDiscreteRangeLocation } from '@univerjs/sheets-ui';
import { Disposable, Inject, Injector, ObjectMatrix, Range, Rectangle, Tools } from '@univerjs/core';
import { Disposable, generateRandomId, Inject, Injector, ObjectMatrix, Range, Rectangle } from '@univerjs/core';
import { rangeToDiscreteRange } from '@univerjs/sheets';
import { AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation } from '@univerjs/sheets-hyper-link';
import { COPY_TYPE, getRepeatRange, ISheetClipboardService, PREDEFINED_HOOK_NAME, virtualizeDiscreteRanges } from '@univerjs/sheets-ui';
@@ -187,7 +187,7 @@ export class SheetsHyperLinkCopyPasteController extends Disposable {
const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
const currentLink = this._hyperLinkModel.getHyperLinkByLocation(copyInfo.unitId, copyInfo.subUnitId, startRow, startColumn);
const id = Tools.generateRandomId();
const id = generateRandomId();
if (currentLink) {
redos.push({
id: RemoveHyperLinkMutation.id,
@@ -18,7 +18,7 @@ import type { Nullable, ObjectMatrix } from '@univerjs/core';
import type { IDiscreteRange } from '../../controllers/utils/range-tools';
import type { COPY_TYPE, ICellDataWithSpanInfo } from './type';
import { LRUMap, Tools } from '@univerjs/core';
import { generateRandomId, LRUMap } from '@univerjs/core';
const COPY_CONTENT_CACHE_LIMIT = 10;
const ID_LENGTH = 6;
@@ -32,7 +32,7 @@ export interface ICopyContentCacheData {
}
export function genId() {
return Tools.generateRandomId(ID_LENGTH);
return generateRandomId(ID_LENGTH);
}
export function extractId(html: string) {
@@ -17,7 +17,7 @@
import type { Workbook } from '@univerjs/core';
import type { RenderUnit } from '@univerjs/engine-render';
import type { ISelectionWithStyle } from '@univerjs/sheets';
import { createIdentifier, Disposable, Inject, IUniverInstanceService, ThemeService, Tools, UniverInstanceType } from '@univerjs/core';
import { createIdentifier, Disposable, generateRandomId, Inject, IUniverInstanceService, ThemeService, UniverInstanceType } from '@univerjs/core';
import { IRenderManagerService } from '@univerjs/engine-render';
import { SELECTION_SHAPE_DEPTH } from '../selection/const';
@@ -66,7 +66,7 @@ export class MarkSelectionService extends Disposable implements IMarkSelectionSe
const workbook = this._currentService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const subUnitId = workbook.getActiveSheet()?.getSheetId();
if (!subUnitId) return null;
const id = Tools.generateRandomId();
const id = generateRandomId();
const markSelectionInfo: IMarkSelectionInfo = {
selection,
@@ -86,7 +86,7 @@ export class MarkSelectionService extends Disposable implements IMarkSelectionSe
const workbook = this._currentService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const subUnitId = workbook.getActiveSheet()?.getSheetId();
if (!subUnitId) return null;
const id = Tools.generateRandomId();
const id = generateRandomId();
this._shapeMap.set(id, {
selection,
subUnitId,
@@ -15,9 +15,8 @@
*/
import type { Nullable, Workbook } from '@univerjs/core';
import type { IDefinedNamesServiceParam, ISetDefinedNameMutationParam } from '@univerjs/engine-formula';
import { ICommandService, IUniverInstanceService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
import { generateRandomId, ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';
import { Button, clsx, Confirm, scrollbarClassName, Tooltip } from '@univerjs/design';
import { IDefinedNamesService, serializeRangeWithSheet } from '@univerjs/engine-formula';
import { DeleteIcon, IncreaseIcon, PenIcon } from '@univerjs/icons';
@@ -36,7 +35,7 @@ import { DefinedNameInput } from './DefinedNameInput';
export const DefinedNameContainer = () => {
const commandService = useDependency(ICommandService);
const univerInstanceService = useDependency(IUniverInstanceService);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const workbook = univerInstanceService.getCurrentUnitOfType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
const localeService = useDependency(LocaleService);
const definedNamesService = useDependency(IDefinedNamesService);
const selectionManagerService = useDependency(SheetsSelectionsService);
@@ -75,7 +74,7 @@ export const DefinedNameContainer = () => {
let id = param.id;
if (id == null || id.length === 0) {
id = Tools.generateRandomId(10);
id = generateRandomId(10);
commandService.executeCommand(InsertDefinedNameCommand.id, { id, unitId, name, formulaOrRefString, comment, localSheetId, hidden });
} else {
const newDefinedName: ISetDefinedNameMutationParam = { id, unitId, name, formulaOrRefString, comment, localSheetId, hidden };
@@ -23,6 +23,7 @@ import {
ICommandService,
IUniverInstanceService,
LocaleType,
merge,
RANGE_TYPE,
RedoCommand,
Tools,
@@ -710,7 +711,7 @@ describe('Test set range values commands', () => {
return paramsStyleData;
}
const allStyle = Tools.deepMerge({}, getParamsStyleBase(), getParamsStyleData());
const allStyle = merge({}, getParamsStyleBase(), getParamsStyleData());
expect(
await commandService.executeCommand(SetRangeValuesCommand.id, getParamsStyleData())
).toBeTruthy();
@@ -15,13 +15,10 @@
*/
import type { IAccessor, ICommand, IMutationInfo, Workbook } from '@univerjs/core';
import type {
IInsertSheetMutationParams,
IRemoveSheetMutationParams,
} from '../../basics/interfaces/mutation-interface';
import type { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../../basics/interfaces/mutation-interface';
import {
CommandType,
generateRandomId,
ICommandService,
IUndoRedoService,
IUniverInstanceService,
@@ -57,7 +54,7 @@ export const CopySheetCommand: ICommand = {
const { workbook, worksheet, unitId, subUnitId } = target;
const config = Tools.deepClone(worksheet.getConfig());
config.name = getCopyUniqueSheetName(workbook, localeService, config.name);
config.id = Tools.generateRandomId();
config.id = generateRandomId();
const sheetIndex = workbook.getSheetIndex(worksheet);
const insertSheetMutationParams: IInsertSheetMutationParams = {
@@ -15,20 +15,16 @@
*/
import type { IAccessor, ICommand, IWorksheetData } from '@univerjs/core';
import type { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../../basics/interfaces/mutation-interface';
import {
CommandType,
generateRandomId,
ICommandService,
IUndoRedoService,
IUniverInstanceService,
LocaleService,
mergeWorksheetSnapshotWithDefault,
Tools,
} from '@univerjs/core';
import type {
IInsertSheetMutationParams,
IRemoveSheetMutationParams,
} from '../../basics/interfaces/mutation-interface';
import { InsertSheetMutation, InsertSheetUndoMutationFactory } from '../mutations/insert-sheet.mutation';
import { RemoveSheetMutation } from '../mutations/remove-sheet.mutation';
import { getSheetCommandTargetWorkbook } from './utils/target-util';
@@ -62,10 +58,10 @@ export const InsertSheetCommand: ICommand = {
if (params) {
index = params.index ?? index;
sheetConfig.id = sheetId || Tools.generateRandomId();
sheetConfig.id = sheetId || generateRandomId();
sheetConfig.name = sheet?.name || workbook.generateNewSheetName(`${localeService.t('sheets.tabs.sheet')}`);
} else {
sheetConfig.id = Tools.generateRandomId();
sheetConfig.id = generateRandomId();
sheetConfig.name = workbook.generateNewSheetName(`${localeService.t('sheets.tabs.sheet')}`);
}
@@ -16,8 +16,7 @@
import type { IDisposable, IRange } from '@univerjs/core';
import type { UnitObject } from '@univerjs/protocol';
import { Tools } from '@univerjs/core';
import { generateRandomId } from '@univerjs/core';
import { BehaviorSubject, Subject } from 'rxjs';
export enum ViewStateEnum {
@@ -175,10 +174,10 @@ export class RangeProtectionRuleModel implements IDisposable {
}
createRuleId(unitId: string, subUnitId: string) {
let id = Tools.generateRandomId(4);
let id = generateRandomId(4);
const ruleMap = this._ensureRuleMap(unitId, subUnitId);
while (ruleMap.has(id)) {
id = Tools.generateRandomId(4);
id = generateRandomId(4);
}
return id;
}
@@ -15,7 +15,7 @@
*/
import type { ICommand, SlideDataModel } from '@univerjs/core';
import { CommandType, IUniverInstanceService, Tools } from '@univerjs/core';
import { CommandType, IUniverInstanceService, merge } from '@univerjs/core';
export interface IUpdateElementOperationParams {
unitId: string;
@@ -36,7 +36,7 @@ export const UpdateSlideElementOperation: ICommand<IUpdateElementOperationParams
if (!slideData) return false;
const activePage = slideData.getActivePage()!;
activePage.pageElements[oKey] = Tools.deepMerge(activePage.pageElements[oKey], props);
activePage.pageElements[oKey] = merge(activePage.pageElements[oKey], props);
slideData.updatePage(activePage.id, activePage);
return true;
+2 -2
View File
@@ -16,7 +16,7 @@
import type { IAccessor } from '@univerjs/core';
import type { IMenuButtonItem, IMenuItem, MenuSchemaType } from '@univerjs/ui';
import { CommandType, ICommandService, Inject, Injector, Tools } from '@univerjs/core';
import { CommandType, generateRandomId, ICommandService, Inject, Injector } from '@univerjs/core';
import { FBase } from '@univerjs/core/facade';
import { IMenuManagerService, MenuItemType, MenuManagerPosition, RibbonPosition, RibbonStartGroup } from '@univerjs/ui';
@@ -168,7 +168,7 @@ export class FMenu extends FMenuBase {
) {
super();
const commandId = typeof _item.action === 'string' ? _item.action : Tools.generateRandomId(12);
const commandId = typeof _item.action === 'string' ? _item.action : generateRandomId(12);
if (commandId !== _item.action) {
this._commandToRegister.set(commandId, _item.action as unknown as () => void);
}
@@ -18,7 +18,7 @@ import type { Nullable } from '@univerjs/core';
import type { IBoundRectNoAngle } from '@univerjs/engine-render';
import type { Observable } from 'rxjs';
import type { IRectPopupProps } from '../../views/components/popup/RectPopup';
import { createIdentifier, Disposable, Tools } from '@univerjs/core';
import { createIdentifier, Disposable, generateRandomId } from '@univerjs/core';
import { BehaviorSubject } from 'rxjs';
export interface IPopup<T = Record<string, unknown>> extends Omit<IRectPopupProps, 'children' | 'hidden' | 'excludeRects' | 'anchorRect$'> {
@@ -82,7 +82,7 @@ export class CanvasPopupService extends Disposable implements ICanvasPopupServic
}
addPopup(item: IPopup): string {
const id = Tools.generateRandomId();
const id = generateRandomId();
this._popupMap.set(id, {
...item,
onActiveChange: (active: boolean) => {
+3 -4
View File
@@ -24,7 +24,7 @@ import type {
ITextDecoration,
ITextRun,
} from '@univerjs/core';
import { BaselineOffset, BorderStyleTypes, ColorKit, getBorderStyleType, Tools } from '@univerjs/core';
import { BaselineOffset, BorderStyleTypes, ColorKit, generateRandomId, getBorderStyleType, Tools } from '@univerjs/core';
import { ptToPx } from '@univerjs/engine-render';
import { textTrim } from './util';
@@ -83,7 +83,7 @@ export function handleDomToJson($dom: HTMLElement): IDocumentData | string {
const length = item.length;
ed += length;
st = ed - length;
const sId = Tools.generateRandomId(6);
const sId = generateRandomId(6);
textRuns.push({
sId,
@@ -121,9 +121,8 @@ export function handleDomToJson($dom: HTMLElement): IDocumentData | string {
});
}
const blockId = Tools.generateRandomId(6);
const p: IDocumentData = {
id: Tools.generateRandomId(6),
id: generateRandomId(6),
body: {
dataStream,
textRuns,