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.

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

白熱8115c3254bd8
diff --git a/packages/core/src/docs/data-model/document-data-model.ts b/packages/core/src/docs/data-model/document-data-model.ts
index 35c54cc1e4..0b1278e108 100644
--- a/packages/core/src/docs/data-model/document-data-model.ts
+++ b/packages/core/src/docs/data-model/document-data-model.ts
@@ -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 ?? '');
diff --git a/packages/core/src/docs/data-model/empty-snapshot.ts b/packages/core/src/docs/data-model/empty-snapshot.ts
index e615516336..2e85a75299 100644
--- a/packages/core/src/docs/data-model/empty-snapshot.ts
+++ b/packages/core/src/docs/data-model/empty-snapshot.ts
@@ -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 {
diff --git a/packages/core/src/docs/data-model/text-x/build-utils/paragraph.ts b/packages/core/src/docs/data-model/text-x/build-utils/paragraph.ts
index 3ba2774efc..64d0a3f325 100644
--- a/packages/core/src/docs/data-model/text-x/build-utils/paragraph.ts
+++ b/packages/core/src/docs/data-model/text-x/build-utils/paragraph.ts
@@ -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();
diff --git a/packages/core/src/services/user-manager/const.ts b/packages/core/src/services/user-manager/const.ts
index 63650f6085..776cd83d6c 100644
--- a/packages/core/src/services/user-manager/const.ts
+++ b/packages/core/src/services/user-manager/const.ts
@@ -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;
diff --git a/packages/core/src/shared/tools.ts b/packages/core/src/shared/tools.ts
index 94e96949a2..9316e77fd6 100644
--- a/packages/core/src/shared/tools.ts
+++ b/packages/core/src/shared/tools.ts
@@ -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;
}
diff --git a/packages/core/src/sheets/styles.ts b/packages/core/src/sheets/styles.ts
index 76ad0d38ba..9a3fbd2692 100644
--- a/packages/core/src/sheets/styles.ts
+++ b/packages/core/src/sheets/styles.ts
@@ -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);
diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.ts
index 86950b7307..d4c4b8d8cb 100644
--- a/packages/core/src/sheets/workbook.ts
+++ b/packages/core/src/sheets/workbook.ts
@@ -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 };
}
diff --git a/packages/core/src/sheets/worksheet.ts b/packages/core/src/sheets/worksheet.ts
index 43d144b832..1635c47454 100644
--- a/packages/core/src/sheets/worksheet.ts
+++ b/packages/core/src/sheets/worksheet.ts
@@ -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.
diff --git a/packages/core/src/slides/slide-model.ts b/packages/core/src/slides/slide-model.ts
index 41462867f4..c8336de52c 100644
--- a/packages/core/src/slides/slide-model.ts
+++ b/packages/core/src/slides/slide-model.ts
@@ -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();
diff --git a/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts b/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts
index 6fcff98e25..6762d8897e 100644
--- a/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts
+++ b/packages/docs-drawing-ui/src/controllers/doc-drawing-transformer-update.controller.ts
@@ -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,
diff --git a/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx b/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx
index cdd96be127..58cc6e1477 100644
--- a/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx
+++ b/packages/docs-mention-ui/src/views/mention-edit-popup/index.tsx
@@ -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,
});
diff --git a/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts b/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
index 0aa2bc84e3..cb880cdf54 100644
--- a/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
+++ b/packages/docs-ui/src/commands/commands/clipboard.inner.command.ts
@@ -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;
diff --git a/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts b/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts
index 23765926ca..9d39079dfd 100644
--- a/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts
+++ b/packages/docs-ui/src/commands/commands/doc-header-footer.command.ts
@@ -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(),
diff --git a/packages/docs-ui/src/commands/commands/list.command.ts b/packages/docs-ui/src/commands/commands/list.command.ts
index a136468b3a..a8970d2675 100644
--- a/packages/docs-ui/src/commands/commands/list.command.ts
+++ b/packages/docs-ui/src/commands/commands/list.command.ts
@@ -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,
},
},
diff --git a/packages/docs-ui/src/controllers/doc-auto-format.controller.ts b/packages/docs-ui/src/controllers/doc-auto-format.controller.ts
index 16334248b9..4c461d1966 100644
--- a/packages/docs-ui/src/controllers/doc-auto-format.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-auto-format.controller.ts
@@ -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';
diff --git a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
index bb3156229b..ff52bd232f 100644
--- a/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-header-footer.controller.ts
@@ -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);
diff --git a/packages/docs-ui/src/services/clipboard/clipboard.service.ts b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
index 7565cc7998..789a3c7c0e 100644
--- a/packages/docs-ui/src/services/clipboard/clipboard.service.ts
+++ b/packages/docs-ui/src/services/clipboard/clipboard.service.ts
@@ -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;
diff --git a/packages/docs-ui/src/services/clipboard/copy-content-cache.ts b/packages/docs-ui/src/services/clipboard/copy-content-cache.ts
index c0c0d771f4..67397348a7 100644
--- a/packages/docs-ui/src/services/clipboard/copy-content-cache.ts
+++ b/packages/docs-ui/src/services/clipboard/copy-content-cache.ts
@@ -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) {
diff --git a/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts b/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts
index a35ef1fe86..0abdefda19 100644
--- a/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts
+++ b/packages/docs-ui/src/services/clipboard/html-to-udm/converter.ts
@@ -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) {
diff --git a/packages/docs-ui/src/services/selection/rect-range.ts b/packages/docs-ui/src/services/selection/rect-range.ts
index e690503632..680fce38a6 100644
--- a/packages/docs-ui/src/services/selection/rect-range.ts
+++ b/packages/docs-ui/src/services/selection/rect-range.ts
@@ -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,
diff --git a/packages/docs-ui/src/services/selection/text-range.ts b/packages/docs-ui/src/services/selection/text-range.ts
index 229d3dbe70..0c5265c5bb 100644
--- a/packages/docs-ui/src/services/selection/text-range.ts
+++ b/packages/docs-ui/src/services/selection/text-range.ts
@@ -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,
diff --git a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
index 204cbd1d4b..5e2f7d6110 100644
--- a/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
+++ b/packages/docs-ui/src/views/header-footer/panel/DocHeaderFooterOptions.tsx
@@ -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);
diff --git a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
index 01a3440cce..da8b789d50 100644
--- a/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
+++ b/packages/drawing-ui/src/views/panel/DrawingGroup.tsx
@@ -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,
diff --git a/packages/drawing/src/services/image-io-impl.service.ts b/packages/drawing/src/services/image-io-impl.service.ts
index 568d7c19ce..cb4a1eda18 100644
--- a/packages/drawing/src/services/image-io-impl.service.ts
+++ b/packages/drawing/src/services/image-io-impl.service.ts
@@ -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,
diff --git a/packages/engine-formula/src/engine/ast-node/lambda-node.ts b/packages/engine-formula/src/engine/ast-node/lambda-node.ts
index 7812fccb69..7783303bbe 100644
--- a/packages/engine-formula/src/engine/ast-node/lambda-node.ts
+++ b/packages/engine-formula/src/engine/ast-node/lambda-node.ts
@@ -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>>();
diff --git a/packages/engine-render/src/components/docs/layout/hyphenation/__tests__/hypen.spec.ts b/packages/engine-render/src/components/docs/layout/hyphenation/__tests__/hypen.spec.ts
index 984866edd6..24cb6bacc3 100644
--- a/packages/engine-render/src/components/docs/layout/hyphenation/__tests__/hypen.spec.ts
+++ b/packages/engine-render/src/components/docs/layout/hyphenation/__tests__/hypen.spec.ts
@@ -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';
diff --git a/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts b/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts
index a043ca6b0a..392257a9a2 100644
--- a/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts
+++ b/packages/sheets-conditional-formatting/src/services/conditional-formatting-formula.service.ts
@@ -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)}`;
}
/**
diff --git a/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts b/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts
index 9348fee1a9..81fc73fc3e 100644
--- a/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts
+++ b/packages/sheets-conditional-formatting/src/services/conditional-formatting.service.ts
@@ -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') {
diff --git a/packages/sheets-conditional-formatting/src/utils/create-cf-id.ts b/packages/sheets-conditional-formatting/src/utils/create-cf-id.ts
index d4314f7cd8..bfe62b399a 100644
--- a/packages/sheets-conditional-formatting/src/utils/create-cf-id.ts
+++ b/packages/sheets-conditional-formatting/src/utils/create-cf-id.ts
@@ -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)}`;
diff --git a/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx b/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx
index 5e3f58902c..9b134d3a1f 100644
--- a/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx
+++ b/packages/sheets-data-validation-ui/src/views/components/formula-input/ListFormulaInput.tsx
@@ -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),
},
]);
};
diff --git a/packages/sheets-data-validation/src/utils/create.ts b/packages/sheets-data-validation/src/utils/create.ts
index c600719d69..08a6ab103f 100644
--- a/packages/sheets-data-validation/src/utils/create.ts
+++ b/packages/sheets-data-validation/src/utils/create.ts
@@ -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,
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-copy-paste.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-copy-paste.controller.ts
index d7d012392d..fb3257a598 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-copy-paste.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-copy-paste.controller.ts
@@ -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,
};
diff --git a/packages/sheets-formula-ui/src/controllers/formula-auto-fill.controller.ts b/packages/sheets-formula-ui/src/controllers/formula-auto-fill.controller.ts
index e1a444367c..efcf1a18b7 100644
--- a/packages/sheets-formula-ui/src/controllers/formula-auto-fill.controller.ts
+++ b/packages/sheets-formula-ui/src/controllers/formula-auto-fill.controller.ts
@@ -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);
diff --git a/packages/sheets-formula-ui/src/controllers/formula-clipboard.controller.ts b/packages/sheets-formula-ui/src/controllers/formula-clipboard.controller.ts
index e03126b5ce..4ad25efe53 100644
--- a/packages/sheets-formula-ui/src/controllers/formula-clipboard.controller.ts
+++ b/packages/sheets-formula-ui/src/controllers/formula-clipboard.controller.ts
@@ -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];
diff --git a/packages/sheets-formula/src/commands/commands/insert-function.command.ts b/packages/sheets-formula/src/commands/commands/insert-function.command.ts
index a34a8f1a79..41540cb479 100644
--- a/packages/sheets-formula/src/commands/commands/insert-function.command.ts
+++ b/packages/sheets-formula/src/commands/commands/insert-function.command.ts
@@ -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,
diff --git a/packages/sheets-formula/src/services/register-other-formula.service.ts b/packages/sheets-formula/src/services/register-other-formula.service.ts
index cc187c76fc..cd5cdb9c60 100644
--- a/packages/sheets-formula/src/services/register-other-formula.service.ts
+++ b/packages/sheets-formula/src/services/register-other-formula.service.ts
@@ -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() {
diff --git a/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts
index 5256c97e22..70e4197db5 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts
@@ -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({
diff --git a/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts
index 71548623d6..cb9372d16a 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts
@@ -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,
diff --git a/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts b/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts
index e34f0501b4..edf9ea147c 100644
--- a/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts
+++ b/packages/sheets-ui/src/services/clipboard/copy-content-cache.ts
@@ -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) {
diff --git a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts
index 3720717c7f..eda3c1af66 100644
--- a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts
+++ b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts
@@ -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,
diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx
index 5edea9bd88..d0e5e6a964 100644
--- a/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx
+++ b/packages/sheets-ui/src/views/defined-name/DefinedNameContainer.tsx
@@ -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 };
diff --git a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts
index c6139f6223..5cba2f55f6 100644
--- a/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts
+++ b/packages/sheets/src/commands/commands/__tests__/set-range-values.command.spec.ts
@@ -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();
diff --git a/packages/sheets/src/commands/commands/copy-worksheet.command.ts b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
index c769c79b34..cdc81cc538 100644
--- a/packages/sheets/src/commands/commands/copy-worksheet.command.ts
+++ b/packages/sheets/src/commands/commands/copy-worksheet.command.ts
@@ -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 = {
diff --git a/packages/sheets/src/commands/commands/insert-sheet.command.ts b/packages/sheets/src/commands/commands/insert-sheet.command.ts
index 63e8a65995..e153083325 100644
--- a/packages/sheets/src/commands/commands/insert-sheet.command.ts
+++ b/packages/sheets/src/commands/commands/insert-sheet.command.ts
@@ -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')}`);
}
diff --git a/packages/sheets/src/model/range-protection-rule.model.ts b/packages/sheets/src/model/range-protection-rule.model.ts
index a656165e71..112c6e2b8b 100644
--- a/packages/sheets/src/model/range-protection-rule.model.ts
+++ b/packages/sheets/src/model/range-protection-rule.model.ts
@@ -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;
}
diff --git a/packages/slides-ui/src/commands/operations/update-element.operation.ts b/packages/slides-ui/src/commands/operations/update-element.operation.ts
index 53b1491c91..96ab56ab9d 100644
--- a/packages/slides-ui/src/commands/operations/update-element.operation.ts
+++ b/packages/slides-ui/src/commands/operations/update-element.operation.ts
@@ -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;
diff --git a/packages/ui/src/facade/f-menu-builder.ts b/packages/ui/src/facade/f-menu-builder.ts
index 3ff244cae5..17cb6164af 100644
--- a/packages/ui/src/facade/f-menu-builder.ts
+++ b/packages/ui/src/facade/f-menu-builder.ts
@@ -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);
}
diff --git a/packages/ui/src/services/popup/canvas-popup.service.ts b/packages/ui/src/services/popup/canvas-popup.service.ts
index b9779c0b7c..dac580168b 100644
--- a/packages/ui/src/services/popup/canvas-popup.service.ts
+++ b/packages/ui/src/services/popup/canvas-popup.service.ts
@@ -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) => {
diff --git a/packages/ui/src/utils/cell.ts b/packages/ui/src/utils/cell.ts
index 28cc135ca1..cb97a97fb7 100644
--- a/packages/ui/src/utils/cell.ts
+++ b/packages/ui/src/utils/cell.ts
@@ -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,