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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix: fix unit empty snapshot export (#7219)
wpxp123456423bb61fc1ff
diff --git a/packages/core/src/bases/base-data-model.ts b/packages/core/src/bases/base-data-model.tsindex 75e1484923..249522c184 100644--- a/packages/core/src/bases/base-data-model.ts+++ b/packages/core/src/bases/base-data-model.ts@@ -20,7 +20,7 @@ import { BehaviorSubject } from 'rxjs';import { UnitModel, UniverInstanceType } from '../common/unit';import { Tools } from '../shared/tools';import { CellValueType } from '../types/enum';-import { getEmptyBaseSnapshot } from './empty-snapshot';+import { getEmptySnapshot } from './empty-snapshot';const BASE_LIST_VALUE_SEPARATOR = ', ';const BASE_ATTACHMENT_RESOURCE_KEY_SEPARATOR = '\u001F';@@ -36,21 +36,7 @@ export class BaseDataModel extends UnitModel<IBaseSnapshot, UniverInstanceType.Uconstructor(snapshot: Partial<IBaseSnapshot> = {}) {super();- const now = Date.now();-- const defaultSnapshot = Tools.isEmptyObject(snapshot)- ? getEmptyBaseSnapshot()- : {- id: '',- name: '',- schemaVersion: 1,- tables: {},- tableOrder: [],- createdAt: now,- updatedAt: now,- rev: 1,- };-+ const defaultSnapshot = getEmptySnapshot();this._snapshot = normalizeBaseSnapshot(Tools.commonExtend(defaultSnapshot, snapshot));if (!this._snapshot.id) {diff --git a/packages/core/src/bases/empty-snapshot.ts b/packages/core/src/bases/empty-snapshot.tsindex 753a425747..854d1e7123 100644--- a/packages/core/src/bases/empty-snapshot.ts+++ b/packages/core/src/bases/empty-snapshot.ts@@ -15,6 +15,9 @@*/import type { IBaseSnapshot, IFieldSnapshot, IRecordSnapshot, ITableSnapshot, IViewSnapshot } from './typedef';+import pkg from '../../package.json';+import { generateRandomId } from '../shared';+import { LocaleType } from '../types/enum';export interface ICreateDefaultBaseTableSnapshotOptions {id: string;@@ -90,16 +93,19 @@ export function createDefaultBaseTableSnapshot(options: ICreateDefaultBaseTableS};}-export function getEmptyBaseSnapshot(- unitID = '',- name = ''+export function getEmptySnapshot(+ unitId: string = generateRandomId(),+ name: string = '',+ locale: LocaleType = LocaleType.ZH_CN): IBaseSnapshot {const now = Date.now();const tableId = 'table-1';return {- id: unitID,+ id: unitId,name,+ locale,+ appVersion: pkg.version,schemaVersion: 1,tableOrder: [tableId],tables: {@@ -112,6 +118,5 @@ export function getEmptyBaseSnapshot(},createdAt: now,updatedAt: now,- rev: 1,};}diff --git a/packages/core/src/bases/index.ts b/packages/core/src/bases/index.tsindex 6eea0fdadb..f41e3485f8 100644--- a/packages/core/src/bases/index.ts+++ b/packages/core/src/bases/index.ts@@ -15,7 +15,11 @@*/export { BaseDataModel } from './base-data-model';-export { createDefaultBaseTableSnapshot, getEmptyBaseSnapshot, type ICreateDefaultBaseTableSnapshotOptions } from './empty-snapshot';+export {+ createDefaultBaseTableSnapshot,+ getEmptySnapshot as getBasesEmptySnapshot,+ type ICreateDefaultBaseTableSnapshotOptions,+} from './empty-snapshot';export type {BaseCellData,BaseCellMatrix,diff --git a/packages/core/src/bases/typedef.ts b/packages/core/src/bases/typedef.tsindex a33b13ba52..0de8d92e82 100644--- a/packages/core/src/bases/typedef.ts+++ b/packages/core/src/bases/typedef.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { CellValueType } from '../types/enum';+import type { CellValueType, LocaleType } from '../types/enum';import type { IDocumentData } from '../types/interfaces';export type BaseId = string;@@ -96,13 +96,15 @@ export type ViewSpecificConfig =export interface IBaseSnapshot {id: BaseId;name: string;+ rev?: number;+ appVersion?: string;+ locale?: LocaleType;schemaVersion: number;tables: Record<TableId, ITableSnapshot>;tableOrder: TableId[];createdAt: number;updatedAt: number;createdBy?: string;- rev?: number;}export interface ITableSnapshot {diff --git a/packages/core/src/docs/data-model/index.ts b/packages/core/src/docs/data-model/index.tsindex 2cdf8edb27..6c5903c9f6 100644--- a/packages/core/src/docs/data-model/index.ts+++ b/packages/core/src/docs/data-model/index.ts@@ -16,6 +16,42 @@export * from './document-data-model';export { getEmptySnapshot as getDocsEmptySnapshot } from './empty-snapshot';+export { JSON1, JSONX } from './json-x/json-x';+export type { JSONXActions, JSONXPath } from './json-x/json-x';export * from './preset-list-type';+export { replaceInDocumentBody } from './replacement';+export {+ ParagraphStyleBuilder,+ ParagraphStyleValue,+ RichTextBuilder,+ RichTextValue,+ TextDecorationBuilder,+ TextStyleBuilder,+ TextStyleValue,+} from './rich-text-builder';+export { DEFAULT_DOCUMENT_SUB_COMPONENT_ID } from './subdocument';+export { ActionIterator } from './text-x/action-iterator';+export { TextXActionType } from './text-x/action-types';+export type { IDeleteAction, IInsertAction, IRetainAction, TextXAction } from './text-x/action-types';+export { normalizeTextRuns, RESTORE_INSERTED_PARAGRAPH_IDS } from './text-x/apply-utils/common';+export { updateAttributeByDelete } from './text-x/apply-utils/delete-apply';+export { updateAttributeByInsert } from './text-x/apply-utils/insert-apply';export * from './text-x/build-utils';+export { getPlainText } from './text-x/build-utils/parse';+export { TextX } from './text-x/text-x';+export type { TPriority } from './text-x/text-x';+export {+ composeBody,+ getBodySlice,+ getCustomBlockSlice,+ getCustomDecorationSlice,+ getCustomRangeSlice,+ getParagraphsSlice,+ getRichTextEditPath,+ getSectionBreakSlice,+ getTableSlice,+ getTextRunSlice,+ normalizeBody,+ SliceBodyType,+} from './text-x/utils';export * from './types';diff --git a/packages/core/src/docs/index.ts b/packages/core/src/docs/index.tsindex 03f9d93e5e..fc47b0203e 100644--- a/packages/core/src/docs/index.ts+++ b/packages/core/src/docs/index.ts@@ -15,3 +15,10 @@*/export * from './data-model';+export {+ cloneBodyWithFreshParagraphIds,+ cloneParagraphWithId,+ createParagraphId,+ PARAGRAPH_ID_PREFIX,+} from './paragraph-id';+export type { IParagraphIdScope } from './paragraph-id';diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex f1d97bafb9..5cf6f7ea67 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -59,50 +59,7 @@ export type { ISequenceExecuteResult } from './common/sequence';export { mergeSets } from './common/set';export { UnitModel, UniverInstanceType } from './common/unit';export { isSafeUrl, normalizeUrl, resolveWithBasePath } from './common/url';-export * from './docs/data-model';-export { JSON1, JSONX } from './docs/data-model/json-x/json-x';-export type { JSONXActions, JSONXPath } from './docs/data-model/json-x/json-x';-export { replaceInDocumentBody } from './docs/data-model/replacement';-export {- ParagraphStyleBuilder,- ParagraphStyleValue,- RichTextBuilder,- RichTextValue,- TextDecorationBuilder,- TextStyleBuilder,- TextStyleValue,-} from './docs/data-model/rich-text-builder';-export { DEFAULT_DOCUMENT_SUB_COMPONENT_ID } from './docs/data-model/subdocument';-export { ActionIterator } from './docs/data-model/text-x/action-iterator';-export { TextXActionType } from './docs/data-model/text-x/action-types';-export type { IDeleteAction, IInsertAction, IRetainAction, TextXAction } from './docs/data-model/text-x/action-types';-export { normalizeTextRuns, RESTORE_INSERTED_PARAGRAPH_IDS } from './docs/data-model/text-x/apply-utils/common';-export { updateAttributeByDelete } from './docs/data-model/text-x/apply-utils/delete-apply';-export { updateAttributeByInsert } from './docs/data-model/text-x/apply-utils/insert-apply';-export { getPlainText } from './docs/data-model/text-x/build-utils/parse';-export { TextX } from './docs/data-model/text-x/text-x';-export type { TPriority } from './docs/data-model/text-x/text-x';-export {- composeBody,- getBodySlice,- getCustomBlockSlice,- getCustomDecorationSlice,- getCustomRangeSlice,- getParagraphsSlice,- getRichTextEditPath,- getSectionBreakSlice,- getTableSlice,- getTextRunSlice,- normalizeBody,- SliceBodyType,-} from './docs/data-model/text-x/utils';-export {- cloneBodyWithFreshParagraphIds,- cloneParagraphWithId,- createParagraphId,- PARAGRAPH_ID_PREFIX,-} from './docs/paragraph-id';-export type { IParagraphIdScope } from './docs/paragraph-id';+export * from './docs';export { EventState, EventSubject, fromEventSubject } from './observer/observable';export type { IEventObserver } from './observer/observable';export { AuthzIoLocalService } from './services/authz-io/authz-io-local.service';@@ -202,40 +159,7 @@ export {} from './shared/rxjs';export { awaitTime, delayAnimationFrame } from './shared/timer';export { isNodeEnv } from './shared/tools';-export * from './sheets/clone';-export { Range } from './sheets/range';-export { getCellCoordByIndexSimple, getCellWithCoordByIndexCore, SheetSkeleton } from './sheets/sheet-skeleton';-export type { IGetRowColByPosOptions } from './sheets/sheet-skeleton';-export * from './sheets/sheet-skeleton';-export {- DEFAULT_WORKSHEET_COLUMN_COUNT,- DEFAULT_WORKSHEET_COLUMN_COUNT_KEY,- DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT,- DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT_KEY,- DEFAULT_WORKSHEET_COLUMN_WIDTH,- DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY,- DEFAULT_WORKSHEET_ROW_COUNT,- DEFAULT_WORKSHEET_ROW_COUNT_KEY,- DEFAULT_WORKSHEET_ROW_HEIGHT,- DEFAULT_WORKSHEET_ROW_HEIGHT_KEY,- DEFAULT_WORKSHEET_ROW_TITLE_WIDTH,- DEFAULT_WORKSHEET_ROW_TITLE_WIDTH_KEY,- mergeWorksheetSnapshotWithDefault,-} from './sheets/sheet-snapshot-utils';-export { Styles } from './sheets/styles';-export * from './sheets/typedef';-export type { IPosition } from './sheets/typedef';-export {- addLinkToDocumentModel,- getEmptyCell,- isNotNullOrUndefined,- isRangesEqual,- isUnitRangesEqual,-} from './sheets/util';-export { createDocumentModelWithStyle } from './sheets/util';-export { SheetViewModel } from './sheets/view-model';-export { getWorksheetUID, Workbook } from './sheets/workbook';-export { extractPureTextFromCell, getDisplayValueFromCell, getOriginCellValue, Worksheet } from './sheets/worksheet';+export * from './sheets';export { Skeleton } from './skeleton';export * from './types/const';export { skipParseTagNames } from './types/const/clipboard';diff --git a/packages/core/src/sheets/index.ts b/packages/core/src/sheets/index.tsnew file mode 100644index 0000000000..68e59ac133--- /dev/null+++ b/packages/core/src/sheets/index.ts@@ -0,0 +1,48 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++export * from './clone';+export { getEmptySnapshot as getSheetsEmptySnapshot } from './empty-snapshot';+export { Range } from './range';+export * from './sheet-skeleton';+export {+ DEFAULT_WORKSHEET_COLUMN_COUNT,+ DEFAULT_WORKSHEET_COLUMN_COUNT_KEY,+ DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT,+ DEFAULT_WORKSHEET_COLUMN_TITLE_HEIGHT_KEY,+ DEFAULT_WORKSHEET_COLUMN_WIDTH,+ DEFAULT_WORKSHEET_COLUMN_WIDTH_KEY,+ DEFAULT_WORKSHEET_ROW_COUNT,+ DEFAULT_WORKSHEET_ROW_COUNT_KEY,+ DEFAULT_WORKSHEET_ROW_HEIGHT,+ DEFAULT_WORKSHEET_ROW_HEIGHT_KEY,+ DEFAULT_WORKSHEET_ROW_TITLE_WIDTH,+ DEFAULT_WORKSHEET_ROW_TITLE_WIDTH_KEY,+ mergeWorksheetSnapshotWithDefault,+} from './sheet-snapshot-utils';+export { Styles } from './styles';+export * from './typedef';+export {+ addLinkToDocumentModel,+ createDocumentModelWithStyle,+ getEmptyCell,+ isNotNullOrUndefined,+ isRangesEqual,+ isUnitRangesEqual,+} from './util';+export { SheetViewModel } from './view-model';+export { getWorksheetUID, Workbook } from './workbook';+export { extractPureTextFromCell, getDisplayValueFromCell, getOriginCellValue, Worksheet } from './worksheet';