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
chore(demo): default demo
Dushusir164026f9cd62
diff --git a/examples/univer-preact-ts/src/index.ts b/examples/univer-preact-ts/src/index.tsindex 87c166882f..9851a3580f 100644--- a/examples/univer-preact-ts/src/index.ts+++ b/examples/univer-preact-ts/src/index.ts@@ -1,4 +1,4 @@-import { Univer, IDocumentData, ISlideData, IWorkbookConfig, UniverDoc, UniverSheet, UniverSlide } from '@univerjs/core';+import { Univer, IDocumentData, ISlideData, IWorkbookConfig, UniverDoc, UniverSheet, UniverSlide, IUniverData } from '@univerjs/core';import { RenderEngine } from '@univerjs/base-render';import { ISheetPluginConfig, SheetPlugin } from '@univerjs/base-sheets';@@ -19,6 +19,7 @@ import { UIPlugin } from '@univerjs/base-ui';// import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';interface ISheetPropsCustom {+ univerConfig?: Partial<IUniverData>;coreConfig?: Partial<IWorkbookConfig>;baseSheetsConfig?: ISheetPluginConfig;uiSheetsConfig?: ISheetUIPluginConfig;@@ -33,7 +34,7 @@ interface ISheetPropsCustom {class UniverSheetCustom {constructor() {}init(config: ISheetPropsCustom = {}): UniverSheet {- const univer = new Univer();+ const univer = new Univer(config.univerConfig);// base-renderuniver.install(new RenderEngine());@@ -69,6 +70,7 @@ const univerSheetCustom = function (config?: ISheetPropsCustom) {};interface IDocPropsCustom {+ univerConfig?: Partial<IUniverData>;coreConfig?: Partial<IDocumentData>;baseDocsConfig?: IDocPluginConfig;uiDocsConfig?: IDocUIPluginConfig;@@ -81,7 +83,7 @@ class UniverDocCustom {constructor() {}init(config: IDocPropsCustom = {}): UniverDoc {- const univer = new Univer();+ const univer = new Univer(config.univerConfig);// base-renderuniver.install(new RenderEngine());@@ -112,6 +114,7 @@ const univerDocCustom = function (config?: IDocPropsCustom) {};interface ISlidePropsCustom {+ univerConfig?: Partial<IUniverData>;coreConfig?: Partial<ISlideData>;baseSlidesConfig?: ISlidePluginConfig;uiSlidesConfig?: ISlideUIPluginConfig;@@ -123,7 +126,7 @@ interface ISlidePropsCustom {class UniverSlideCustom {constructor() {}init(config: ISlidePropsCustom = {}): UniverSlide {- const univer = new Univer();+ const univer = new Univer(config.univerConfig);// base-renderuniver.install(new RenderEngine());diff --git a/examples/univer-preact-ts/src/main.tsx b/examples/univer-preact-ts/src/main.tsxindex 5f3f1130dc..a0421b4050 100644--- a/examples/univer-preact-ts/src/main.tsx+++ b/examples/univer-preact-ts/src/main.tsx@@ -1,4 +1,4 @@-import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DEMO, DEFAULT_WORKBOOK_DATA_DEMO3, DEFAULT_WORKBOOK_DATA_DOWN } from '@univerjs/common-plugin-data';+import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DEMO, DEFAULT_WORKBOOK_DATA_DEMO3, DEFAULT_WORKBOOK_DATA_DEMO5, DEFAULT_WORKBOOK_DATA_DEMO7, DEFAULT_WORKBOOK_DATA_DOWN } from '@univerjs/common-plugin-data';import { IWorkbookConfig, IWorksheetConfig, SheetTypes, Tools } from '@univerjs/core';import { univerSheetCustom } from '.';@@ -38,7 +38,7 @@ let columnCount = 8;if (window.innerWidth < 1366) {columnCount = 5;}-const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DEMO);+const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DEMO7);// defaultWorkbookData.id = 'workbook-01';// defaultWorkbookData.styles = null;// defaultWorkbookData.namedRanges = null;@@ -63,10 +63,8 @@ const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DEMO);--const serverURL = 'http://localhost:8080/new';+const ipAddress = '47.100.177.253:8500'const config = {"type":"sheet","template":"DEMO1"}-const wsURL = 'ws://localhost:8080/ws/'insertButton()insertUpdateButton()@@ -90,7 +88,7 @@ function insertInputBox(id) {sendMessage(message)})- const url = `${wsURL}${id}`;+ const url = `${'ws://'+ipAddress+'/ws/'}${id}`;const socket = new WebSocket(url);// 连接建立时触发的事件@@ -148,14 +146,20 @@ function insertUpdateButton() {const downUISheetsConfig = {container: 'universheet-demo',}- univerSheetCustom({+ const univerSheet = univerSheetCustom({+ univerConfig:{+ id+ },coreConfig:JSON.parse(universheetconfig),uiSheetsConfig:downUISheetsConfig,collaborationConfig:{- url: `${wsURL}${id}`+ url: `${'ws://'+ipAddress+'/ws/'}${id}`}});+ // const ids = univerSheet.getWorkBook().getContext().getUniver().getGlobalContext().getUniverId();+ // console.info('ids===',ids)+// insertInputBox(id)})@@ -179,27 +183,21 @@ function insertButton() {// 添加按钮点击事件处理程序button.addEventListener('click', function() {- newDocs(serverURL,config,(json)=>{+ newDocs('http://'+ipAddress+'/new',config,(json)=>{const id = json.id;const config = json.config;-- console.log('id==: ',id)-- let coreConfig+if(config === 'default'){- coreConfig = defaultWorkbookData- }- const universheet = univerSheetCustom({- coreConfig,- baseSheetsConfig,- uiSheetsConfig,- });+ const universheet = univerSheetCustom({+ uiSheetsConfig,+ coreConfig:defaultWorkbookData+ });- const universheetconfig = universheet.getWorkBook().getConfig()+ const universheetconfig = universheet.getWorkBook().getConfig()updateDocs(id,universheetconfig)-+ }})});@@ -254,7 +252,7 @@ function newDocs(url:string, params:object, cb?:(json:object)=>void) {};// 发送 POST 请求- xhr.open('POST', 'http://localhost:8080/open', true);+ xhr.open('POST', 'http://'+ipAddress+'/open', true);xhr.send(data);}@@ -280,7 +278,7 @@ function newDocs(url:string, params:object, cb?:(json:object)=>void) {};// 发送 POST 请求- xhr.open('POST', 'http://localhost:8080/update', true);+ xhr.open('POST', 'http://'+ipAddress+'/update', true);xhr.send(data);}diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.tsindex ab0a0300ed..03694815ad 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO.ts@@ -195,7 +195,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0010','sheet-0009','sheet-0008','sheet-0007','sheet-0006','sheet-0005','sheet-0004','sheet-0003','sheet-0002','sheet-0001'],pluginMeta: {},styles: {'1': {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO1.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO1.tsindex 90535558ac..bab18a5da1 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO1.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO1.ts@@ -10,7 +10,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO1: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0003'],pluginMeta: {},styles: {'1': {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO2.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO2.tsindex 0218a6ea5c..c07b714120 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO2.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO2.ts@@ -10,7 +10,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO2: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0002'],pluginMeta: {},styles: {'1': {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO3.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO3.tsindex 6a5b1e7894..1072cec9c2 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO3.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO3.ts@@ -136,7 +136,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO3: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0001'],pluginMeta: {},styles: {'1': {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO4.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO4.tsindex 332fd88713..512f04e386 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO4.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO4.ts@@ -68,7 +68,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO4: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0004'],pluginMeta: {},styles: {'1': {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO5.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO5.tsindex 038f317767..25210e658c 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO5.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO5.ts@@ -10,7 +10,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO5: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0005'],pluginMeta: {},styles: {idtqdi: {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO6.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO6.tsindex fdeffb0665..3b77257f43 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO6.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO6.ts@@ -10,7 +10,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO6: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0006'],pluginMeta: {},styles: {idtqdi: {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO7.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO7.tsindex c6b149bc45..713d5ffd91 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO7.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO7.ts@@ -10,7 +10,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO7: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0012','sheet-0011'],pluginMeta: {},styles:{"1": {diff --git a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO8.ts b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO8.tsindex ba359300f7..64982564a7 100644--- a/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO8.ts+++ b/packages/common-plugin-data/src/Sheets/Demo/DEFAULT_WORKBOOK_DATA_DEMO8.ts@@ -10,7 +10,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO8: IWorkbookConfig = {socketUrl: '',socketEnable: BooleanNumber.FALSE,extensions: [],- sheetOrder: [],+ sheetOrder: ['sheet-0013'],pluginMeta: {},styles:{"1": {diff --git a/packages/core/src/Basics/Context.ts b/packages/core/src/Basics/Context.tsindex 315388e210..721e3a974a 100644--- a/packages/core/src/Basics/Context.ts+++ b/packages/core/src/Basics/Context.ts@@ -1,5 +1,5 @@import { IUniverData } from '../Interfaces/IUniverData';-import { Locale } from '../Shared';+import { Locale, Tools } from '../Shared';import { ContextBase } from './ContextBase';/**@@ -8,16 +8,28 @@ import { ContextBase } from './ContextBase';export class Context extends ContextBase {protected _locale: Locale;+ private _univerId: string;+constructor(univerData: Partial<IUniverData> = {}) {super();this._locale = new Locale();this._locale.initialize();++ if (univerData.id == null || univerData.id.length === 0) {+ this._univerId = Tools.generateRandomId(10);+ } else {+ this._univerId = univerData.id;+ }}getLocale(): Locale {return this._locale;}+ getUniverId() {+ return this._univerId;+ }+protected _setObserver(): void {}}diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.tsindex 86522584d4..9b90ffb74f 100644--- a/packages/core/src/Basics/Univer.ts+++ b/packages/core/src/Basics/Univer.ts@@ -1,3 +1,4 @@+import { IUniverData } from './../Interfaces/IUniverData';import { UniverSheet } from './UniverSheet';import { UniverDoc } from './UniverDoc';import { UniverSlide } from './UniverSlide';@@ -14,12 +15,12 @@ export class Univer {private _context: Context;- constructor() {+ constructor(univerData: Partial<IUniverData> = {}) {this._univerSheets = [];this._univerDocs = [];this._univerSlides = [];- this._context = new Context();+ this._context = new Context(univerData);this._context.onUniver(this);}diff --git a/packages/core/src/Interfaces/IUniverData.ts b/packages/core/src/Interfaces/IUniverData.tsindex 23bf5d458c..781ba5b15b 100644--- a/packages/core/src/Interfaces/IUniverData.ts+++ b/packages/core/src/Interfaces/IUniverData.ts@@ -2,6 +2,7 @@ import { LocaleType } from '../Enum';export interface IUniverData {locale: LocaleType;+ id: string;}/**