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
feat: implement rev number in snapshot (#367)
Wenzhao Hub12086eba936
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.tsindex b00cfa3149..a52fff83b1 100644--- a/packages/core/src/Basics/Univer.ts+++ b/packages/core/src/Basics/Univer.ts@@ -1,12 +1,12 @@/* eslint-disable @typescript-eslint/no-explicit-any */import { Ctor, Injector } from '@wendellhu/redi';-import { ErrorService } from '..';import { DocumentModel } from '../Docs/Domain/DocumentModel';import { Plugin, PluginCtor, PluginRegistry, PluginStore, PluginType } from '../plugin/plugin';import { CommandService, ICommandService } from '../services/command/command.service';import { ConfigService, IConfigService } from '../services/config/config.service';import { ContextService, IContextService } from '../services/context/context.service';+import { ErrorService } from '../services/error/error.service';import { IUniverInstanceService, UniverInstanceService } from '../services/instance/instance.service';import { LifecycleStages } from '../services/lifecycle/lifecycle';import { LifecycleInitializerService, LifecycleService } from '../services/lifecycle/lifecycle.service';@@ -24,6 +24,12 @@ import { UniverDoc } from './UniverDoc';import { UniverSheet } from './UniverSheet';import { UniverSlide } from './UniverSlide';+export const enum DocumentType {+ DOC = 0,+ SHEET = 1,+ SLIDE = 2,+}+/*** Univer.*/diff --git a/packages/core/src/Docs/Domain/DocumentModel.ts b/packages/core/src/Docs/Domain/DocumentModel.tsindex afaed5dc3c..6c955d74e3 100644--- a/packages/core/src/Docs/Domain/DocumentModel.ts+++ b/packages/core/src/Docs/Domain/DocumentModel.ts@@ -202,6 +202,14 @@ export class DocumentModel extends DocumentModelSimple {this._initializeRowColTree();}+ getRev(): number {+ return this.snapshot.rev ?? 0;+ }++ incrementRev(): void {+ this.snapshot.rev = this.getRev() + 1;+ }+getSettings() {return this.snapshot.settings;}diff --git a/packages/core/src/Types/Interfaces/IDocumentData.ts b/packages/core/src/Types/Interfaces/IDocumentData.tsindex 6b7f9a5a4d..c3c5fe9cbe 100644--- a/packages/core/src/Types/Interfaces/IDocumentData.ts+++ b/packages/core/src/Types/Interfaces/IDocumentData.ts@@ -9,7 +9,12 @@ import { IColorStyle, IStyleBase } from './IStyleData';* Properties of document*/export interface IDocumentData extends IReferenceSource, IExtraModelConfig {- id: string; // unit id+ /** unit ID */+ id: string;++ /** Revision of this document. Would be used in collaborated editing. Starts with zero. */+ rev?: number;+locale?: LocaleType;title?: string;body?: IDocumentBody;diff --git a/packages/core/src/Types/Interfaces/IWorkbookData.ts b/packages/core/src/Types/Interfaces/IWorkbookData.tsindex e5c63be83f..83948ac4bd 100644--- a/packages/core/src/Types/Interfaces/IWorkbookData.ts+++ b/packages/core/src/Types/Interfaces/IWorkbookData.ts@@ -10,15 +10,19 @@ import { IWorksheetConfig } from './IWorksheetData';* Properties of a workbook's configuration*/export interface IWorkbookConfig extends IExtraModelConfig {- appVersion: string;- createdTime: string;- creator: string;- extensions: [];/*** unit id*/id: string;++ /** Revision of this document. Would be used in collaborated editing. Starts with zero. */+ rev?: number;+lastModifiedBy: string;+ appVersion: string;+ createdTime: string;+ creator: string;+ extensions: [];locale: LocaleType;modifiedTime: string;name: string;diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.tsindex fa110447d6..830f039ff1 100644--- a/packages/core/src/sheets/workbook.ts+++ b/packages/core/src/sheets/workbook.ts@@ -102,6 +102,14 @@ export class Workbook extends Disposable {return this._unitId;}+ getRev(): number {+ return this._snapshot.rev ?? 0;+ }++ incrementRev(): void {+ this._snapshot.rev = this.getRev() + 1;+ }+getShouldRenderLoopImmediately() {const should = this._snapshot.shouldStartRenderingImmediately;return should !== false;