@univerjs/core 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/es/facade.js +141 -129
- package/lib/es/index.js +446 -446
- package/lib/facade.js +141 -129
- package/lib/index.js +446 -446
- package/lib/types/facade/f-event-registry.d.ts +0 -1
- package/lib/types/types/enum/locale-type.d.ts +2 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +4 -4
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var B=Object.defineProperty;var O=(s,t,e)=>t in s?B(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var p=(s,t,e)=>O(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),g=require("rxjs");class S extends r.Disposable{static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}}const v=Symbol("initializers"),j=Symbol("manualInit");class w extends r.Disposable{constructor(t){if(super(),this._injector=t,!!this.constructor[j])return;const i=this,o=Object.getPrototypeOf(this)[v];o&&o.forEach(function(c){c.apply(i,[t])})}_initialize(t,...e){}_runInitializers(...t){const e=Object.getPrototypeOf(this)[v];e!=null&&e.length&&e.forEach(n=>n.apply(this,t))}static _enableManualInit(){this[j]=!0}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{if(e==="_initialize"){let n=this.prototype[v];n||(n=[],this.prototype[v]=n),n.push(t.prototype._initialize)}else e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}}var I=Object.getOwnPropertyDescriptor,P=(s,t,e,n)=>{for(var i=n>1?void 0:n?I(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(i=c(i)||i);return i},U=(s,t)=>(e,n)=>t(e,n,s);exports.FBlob=class extends S{constructor(t,e){super(),this._blob=t,this._injector=e}copyBlob(){return this._injector.createInstance(exports.FBlob,this._blob)}getAs(t){const e=this.copyBlob();return e.setContentType(t),e}getDataAsString(t){return this._blob===null?Promise.resolve(""):t===void 0?this._blob.text():new Promise((e,n)=>{this._blob.arrayBuffer().then(i=>{const o=new TextDecoder(t).decode(i);e(o)}).catch(i=>{n(new Error(`Failed to read Blob as ArrayBuffer: ${i.message}`))})})}getBytes(){return this._blob?this._blob.arrayBuffer().then(t=>new Uint8Array(t)):Promise.reject(new Error("Blob is undefined or null."))}setBytes(t){return this._blob=new Blob([t.buffer]),this}setDataFromString(t,e){const n=e!=null?e:"text/plain",i=new Blob([t],{type:n});return this._blob=i,this}getContentType(){var t;return(t=this._blob)==null?void 0:t.type}setContentType(t){var e;return this._blob=(e=this._blob)==null?void 0:e.slice(0,this._blob.size,t),this}};exports.FBlob=P([U(1,r.Inject(r.Injector))],exports.FBlob);const h=class h{static get(){if(this._instance)return this._instance;const t=new h;return this._instance=t,t}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}constructor(){for(const t in h.prototype)this[t]=h.prototype[t]}get AbsoluteRefType(){return r.AbsoluteRefType}get UniverInstanceType(){return r.UniverInstanceType}get LifecycleStages(){return r.LifecycleStages}get DataValidationType(){return r.DataValidationType}get DataValidationErrorStyle(){return r.DataValidationErrorStyle}get DataValidationRenderMode(){return r.DataValidationRenderMode}get DataValidationOperator(){return r.DataValidationOperator}get DataValidationStatus(){return r.DataValidationStatus}get CommandType(){return r.CommandType}get BaselineOffset(){return r.BaselineOffset}get BooleanNumber(){return r.BooleanNumber}get HorizontalAlign(){return r.HorizontalAlign}get TextDecoration(){return r.TextDecoration}get TextDirection(){return r.TextDirection}get VerticalAlign(){return r.VerticalAlign}get WrapStrategy(){return r.WrapStrategy}get BorderType(){return r.BorderType}get BorderStyleTypes(){return r.BorderStyleTypes}get AutoFillSeries(){return r.AutoFillSeries}get ColorType(){return r.ColorType}get CommonHideTypes(){return r.CommonHideTypes}get CopyPasteType(){return r.CopyPasteType}get DeleteDirection(){return r.DeleteDirection}get DeveloperMetadataVisibility(){return r.DeveloperMetadataVisibility}get Dimension(){return r.Dimension}get Direction(){return r.Direction}get InterpolationPointType(){return r.InterpolationPointType}get LocaleType(){return r.LocaleType}get MentionType(){return r.MentionType}get ProtectionType(){return r.ProtectionType}get RelativeDate(){return r.RelativeDate}get SheetTypes(){return r.SheetTypes}get ThemeColorType(){return r.ThemeColorType}};p(h,"_instance");let m=h;const u=class u{static get(){if(this._instance)return this._instance;const t=new u;return this._instance=t,t}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}constructor(){for(const t in u.prototype)this[t]=u.prototype[t]}get DocCreated(){return"DocCreated"}get DocDisposed(){return"DocDisposed"}get LifeCycleChanged(){return"LifeCycleChanged"}get Redo(){return"Redo"}get Undo(){return"Undo"}get BeforeRedo(){return"BeforeRedo"}get BeforeUndo(){return"BeforeUndo"}get CommandExecuted(){return"CommandExecuted"}get BeforeCommandExecute(){return"BeforeCommandExecute"}};p(u,"_instance");let _=u;var H=Object.getOwnPropertyDescriptor,M=(s,t,e,n)=>{for(var i=n>1?void 0:n?H(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(i=c(i)||i);return i},T=(s,t)=>(e,n)=>t(e,n,s);exports.FHooks=class extends S{constructor(t,e){super(),this._injector=t,this._lifecycleService=e}onStarting(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Starting)).subscribe(t))}onReady(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Ready)).subscribe(t))}onRendered(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Rendered)).subscribe(t))}onSteady(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Steady)).subscribe(t))}onBeforeUndo(t){return this._injector.get(r.ICommandService).beforeCommandExecuted(n=>{if(n.id===r.UndoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopUndoElement();o&&t(o)}})}onUndo(t){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===r.UndoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopUndoElement();o&&t(o)}})}onBeforeRedo(t){return this._injector.get(r.ICommandService).beforeCommandExecuted(n=>{if(n.id===r.RedoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopRedoElement();o&&t(o)}})}onRedo(t){return this._injector.get(r.ICommandService).onCommandExecuted(n=>{if(n.id===r.RedoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopRedoElement();o&&t(o)}})}};exports.FHooks=M([T(0,r.Inject(r.Injector)),T(1,r.Inject(r.LifecycleService))],exports.FHooks);var F=Object.getOwnPropertyDescriptor,V=(s,t,e,n)=>{for(var i=n>1?void 0:n?F(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(i=c(i)||i);return i},L=(s,t)=>(e,n)=>t(e,n,s);let D=class extends w{constructor(s,t){super(t),this.doc=s}};D=V([L(1,r.Inject(r.Injector))],D);class ${constructor(){p(this,"_eventRegistry",new Map);p(this,"_eventHandlerMap",new Map);p(this,"_eventHandlerRegisted",new Map)}_ensureEventRegistry(t){return this._eventRegistry.has(t)||this._eventRegistry.set(t,new r.Registry),this._eventRegistry.get(t)}dispose(){this._eventRegistry.clear(),this._eventHandlerMap.clear(),this._eventHandlerRegisted.forEach(t=>{t.forEach(e=>e.dispose()),t.clear()}),this._eventHandlerRegisted.clear()}registerEventHandler(t,e){const n=this._eventHandlerMap.get(t);return n?n.add(e):this._eventHandlerMap.set(t,new Set([e])),this._ensureEventRegistry(t).getData().length&&this._initEventHandler(t),r.toDisposable(()=>{var i,o,c,a;(i=this._eventHandlerMap.get(t))==null||i.delete(e),(c=(o=this._eventHandlerRegisted.get(t))==null?void 0:o.get(e))==null||c.dispose(),(a=this._eventHandlerRegisted.get(t))==null||a.delete(e)})}removeEvent(t,e){const n=this._ensureEventRegistry(t);if(n.delete(e),n.getData().length===0){const i=this._eventHandlerRegisted.get(t);i==null||i.forEach(o=>o.dispose()),this._eventHandlerRegisted.delete(t)}}_initEventHandler(t){let e=this._eventHandlerRegisted.get(t);const n=this._eventHandlerMap.get(t);n&&(e||(e=new Map,this._eventHandlerRegisted.set(t,e),n==null||n.forEach(i=>{e==null||e.set(i,r.toDisposable(i()))})))}addEvent(t,e){return this._ensureEventRegistry(t).add(e),this._initEventHandler(t),r.toDisposable(()=>this.removeEvent(t,e))}fireEvent(t,e){var n;return(n=this._eventRegistry.get(t))==null||n.getData().forEach(i=>{i(e)}),e.cancel}}var z=Object.getOwnPropertyDescriptor,N=(s,t,e,n)=>{for(var i=n>1?void 0:n?z(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(i=c(i)||i);return i},x=(s,t)=>(e,n)=>t(e,n,s);let R=class extends S{constructor(s,t){super(),this._injector=s,this._userManagerService=t}getCurrentUser(){return this._userManagerService.getCurrentUser()}};R=N([x(0,r.Inject(r.Injector)),x(1,r.Inject(r.UserManagerService))],R);const b=class b{static get(){if(this._instance)return this._instance;const t=new b;return this._instance=t,t}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}get rectangle(){return r.Rectangle}get numfmt(){return r.numfmt}get tools(){return r.Tools}};p(b,"_instance");let E=b;var A=Object.getOwnPropertyDescriptor,k=(s,t,e,n)=>{for(var i=n>1?void 0:n?A(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(i=c(i)||i);return i},f=(s,t)=>(e,n)=>t(e,n,s);const C=Symbol("initializers");exports.FUniver=class extends r.Disposable{constructor(e,n,i,o){super();p(this,"_eventRegistry",new $);p(this,"registerEventHandler",(e,n)=>this._eventRegistry.registerEventHandler(e,n));this._injector=e,this._commandService=n,this._univerInstanceService=i,this._lifecycleService=o,this.registerEventHandler(this.Event.LifeCycleChanged,()=>r.toDisposable(this._lifecycleService.lifecycle$.subscribe(a=>{this.fireEvent(this.Event.LifeCycleChanged,{stage:a})}))),this._initUnitEvent(this._injector),this._initBeforeCommandEvent(this._injector),this._initCommandEvent(this._injector),this._injector.onDispose(()=>{this.dispose()});const c=Object.getPrototypeOf(this)[C];if(c){const a=this;c.forEach(function(l){l.apply(a,[e])})}}static newAPI(e){return(e instanceof r.Univer?e.__getInjector():e).createInstance(exports.FUniver)}_initialize(e){}static extend(e){Object.getOwnPropertyNames(e.prototype).forEach(n=>{if(n==="_initialize"){let i=this.prototype[C];i||(i=[],this.prototype[C]=i),i.push(e.prototype._initialize)}else n!=="constructor"&&(this.prototype[n]=e.prototype[n])}),Object.getOwnPropertyNames(e).forEach(n=>{n!=="prototype"&&n!=="name"&&n!=="length"&&(this[n]=e[n])})}_initCommandEvent(e){const n=e.get(r.ICommandService);this.registerEventHandler(this.Event.Redo,()=>n.onCommandExecuted(i=>{const{id:o,type:c,params:a}=i;if(i.id===r.RedoCommand.id){const d={id:o,type:c,params:a};this.fireEvent(this.Event.Redo,d)}})),this.registerEventHandler(this.Event.Undo,()=>n.onCommandExecuted(i=>{const{id:o,type:c,params:a}=i;if(i.id===r.UndoCommand.id){const d={id:o,type:c,params:a};this.fireEvent(this.Event.Undo,d)}})),this.registerEventHandler(this.Event.CommandExecuted,()=>n.onCommandExecuted((i,o)=>{const{id:c,type:a,params:l}=i;if(i.id!==r.RedoCommand.id&&i.id!==r.UndoCommand.id){const y={id:c,type:a,params:l,options:o};this.fireEvent(this.Event.CommandExecuted,y)}}))}_initBeforeCommandEvent(e){const n=e.get(r.ICommandService);this.registerEventHandler(this.Event.BeforeRedo,()=>n.beforeCommandExecuted(i=>{const{id:o,type:c,params:a}=i;if(i.id===r.RedoCommand.id){const d={id:o,type:c,params:a};if(this.fireEvent(this.Event.BeforeRedo,d),d.cancel)throw new r.CanceledError}})),this.registerEventHandler(this.Event.BeforeUndo,()=>n.beforeCommandExecuted(i=>{const{id:o,type:c,params:a}=i;if(i.id===r.UndoCommand.id){const d={id:o,type:c,params:a};if(this.fireEvent(this.Event.BeforeUndo,d),d.cancel)throw new r.CanceledError}})),this.registerEventHandler(this.Event.BeforeCommandExecute,()=>n.beforeCommandExecuted((i,o)=>{const{id:c,type:a,params:l}=i;if(i.id!==r.RedoCommand.id&&i.id!==r.UndoCommand.id){const y={id:c,type:a,params:l,options:o};if(this.fireEvent(this.Event.BeforeCommandExecute,y),y.cancel)throw new r.CanceledError}}))}_initUnitEvent(e){const n=e.get(r.IUniverInstanceService);this.registerEventHandler(this.Event.DocDisposed,()=>n.unitDisposed$.subscribe(i=>{i.type===r.UniverInstanceType.UNIVER_DOC&&this.fireEvent(this.Event.DocDisposed,{unitId:i.getUnitId(),unitType:i.type,snapshot:i.getSnapshot()})})),this.registerEventHandler(this.Event.DocCreated,()=>n.unitAdded$.subscribe(i=>{if(i.type===r.UniverInstanceType.UNIVER_DOC){const o=i,c=e.createInstance(D,o);this.fireEvent(this.Event.DocCreated,{unitId:i.getUnitId(),type:i.type,doc:c,unit:c})}}))}disposeUnit(e){const n=this._univerInstanceService.disposeUnit(e);return this._eventRegistry.dispose(),n}getCurrentLifecycleStage(){return this._injector.get(r.LifecycleService).stage}undo(){return this._commandService.executeCommand(r.UndoCommand.id)}redo(){return this._commandService.executeCommand(r.RedoCommand.id)}toggleDarkMode(e){this._injector.get(r.ThemeService).setDarkMode(e)}loadLocales(e,n){this._injector.get(r.LocaleService).load({[e]:n})}setLocale(e){this._injector.get(r.LocaleService).setLocale(e)}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted((n,i)=>{e(n,i)})}onCommandExecuted(e){return this._commandService.onCommandExecuted((n,i)=>{e(n,i)})}executeCommand(e,n,i){return this._commandService.executeCommand(e,n,i)}syncExecuteCommand(e,n,i){return this._commandService.syncExecuteCommand(e,n,i)}getHooks(){return this._injector.createInstance(exports.FHooks)}get Enum(){return m.get()}get Event(){return _.get()}get Util(){return E.get()}addEvent(e,n){if(!e||!n)throw new Error("Cannot add empty event");return this._eventRegistry.addEvent(e,n)}fireEvent(e,n){return this._eventRegistry.fireEvent(e,n)}getUserManager(){return this._injector.createInstance(R)}newBlob(){return this._injector.createInstance(exports.FBlob)}newColor(){return new r.ColorBuilder}newRichText(e){return r.RichTextBuilder.create(e)}newRichTextValue(e){return r.RichTextValue.create(e)}newParagraphStyle(e){return r.ParagraphStyleBuilder.create(e)}newParagraphStyleValue(e){return r.ParagraphStyleValue.create(e)}newTextStyle(e){return r.TextStyleBuilder.create(e)}newTextStyleValue(e){return r.TextStyleValue.create(e)}newTextDecoration(e){return new r.TextDecorationBuilder(e)}};exports.FUniver=k([f(0,r.Inject(r.Injector)),f(1,r.ICommandService),f(2,r.IUniverInstanceService),f(3,r.Inject(r.LifecycleService))],exports.FUniver);exports.FBase=S;exports.FBaseInitialable=w;exports.FEnum=m;exports.FEventName=_;exports.FUtil=E;
|
|
1
|
+
"use strict";var B=Object.defineProperty;var O=(s,t,e)=>t in s?B(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var p=(s,t,e)=>O(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@univerjs/core"),g=require("rxjs");class S extends r.Disposable{static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}}const v=Symbol("initializers"),T=Symbol("manualInit");class w extends r.Disposable{constructor(t){if(super(),this._injector=t,!!this.constructor[T])return;const n=this,o=Object.getPrototypeOf(this)[v];o&&o.forEach(function(c){c.apply(n,[t])})}_initialize(t,...e){}_runInitializers(...t){const e=Object.getPrototypeOf(this)[v];e!=null&&e.length&&e.forEach(i=>i.apply(this,t))}static _enableManualInit(){this[T]=!0}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{if(e==="_initialize"){let i=this.prototype[v];i||(i=[],this.prototype[v]=i),i.push(t.prototype._initialize)}else e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}}var I=Object.getOwnPropertyDescriptor,P=(s,t,e,i)=>{for(var n=i>1?void 0:i?I(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(n=c(n)||n);return n},U=(s,t)=>(e,i)=>t(e,i,s);exports.FBlob=class extends S{constructor(t,e){super(),this._blob=t,this._injector=e}copyBlob(){return this._injector.createInstance(exports.FBlob,this._blob)}getAs(t){const e=this.copyBlob();return e.setContentType(t),e}getDataAsString(t){return this._blob===null?Promise.resolve(""):t===void 0?this._blob.text():new Promise((e,i)=>{this._blob.arrayBuffer().then(n=>{const o=new TextDecoder(t).decode(n);e(o)}).catch(n=>{i(new Error(`Failed to read Blob as ArrayBuffer: ${n.message}`))})})}getBytes(){return this._blob?this._blob.arrayBuffer().then(t=>new Uint8Array(t)):Promise.reject(new Error("Blob is undefined or null."))}setBytes(t){return this._blob=new Blob([t.buffer]),this}setDataFromString(t,e){const i=e!=null?e:"text/plain",n=new Blob([t],{type:i});return this._blob=n,this}getContentType(){var t;return(t=this._blob)==null?void 0:t.type}setContentType(t){var e;return this._blob=(e=this._blob)==null?void 0:e.slice(0,this._blob.size,t),this}};exports.FBlob=P([U(1,r.Inject(r.Injector))],exports.FBlob);const h=class h{static get(){if(this._instance)return this._instance;const t=new h;return this._instance=t,t}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}constructor(){for(const t in h.prototype)this[t]=h.prototype[t]}get AbsoluteRefType(){return r.AbsoluteRefType}get UniverInstanceType(){return r.UniverInstanceType}get LifecycleStages(){return r.LifecycleStages}get DataValidationType(){return r.DataValidationType}get DataValidationErrorStyle(){return r.DataValidationErrorStyle}get DataValidationRenderMode(){return r.DataValidationRenderMode}get DataValidationOperator(){return r.DataValidationOperator}get DataValidationStatus(){return r.DataValidationStatus}get CommandType(){return r.CommandType}get BaselineOffset(){return r.BaselineOffset}get BooleanNumber(){return r.BooleanNumber}get HorizontalAlign(){return r.HorizontalAlign}get TextDecoration(){return r.TextDecoration}get TextDirection(){return r.TextDirection}get VerticalAlign(){return r.VerticalAlign}get WrapStrategy(){return r.WrapStrategy}get BorderType(){return r.BorderType}get BorderStyleTypes(){return r.BorderStyleTypes}get AutoFillSeries(){return r.AutoFillSeries}get ColorType(){return r.ColorType}get CommonHideTypes(){return r.CommonHideTypes}get CopyPasteType(){return r.CopyPasteType}get DeleteDirection(){return r.DeleteDirection}get DeveloperMetadataVisibility(){return r.DeveloperMetadataVisibility}get Dimension(){return r.Dimension}get Direction(){return r.Direction}get InterpolationPointType(){return r.InterpolationPointType}get LocaleType(){return r.LocaleType}get MentionType(){return r.MentionType}get ProtectionType(){return r.ProtectionType}get RelativeDate(){return r.RelativeDate}get SheetTypes(){return r.SheetTypes}get ThemeColorType(){return r.ThemeColorType}};p(h,"_instance");let m=h;const u=class u{static get(){if(this._instance)return this._instance;const t=new u;return this._instance=t,t}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}constructor(){for(const t in u.prototype)this[t]=u.prototype[t]}get DocCreated(){return"DocCreated"}get DocDisposed(){return"DocDisposed"}get LifeCycleChanged(){return"LifeCycleChanged"}get Redo(){return"Redo"}get Undo(){return"Undo"}get BeforeRedo(){return"BeforeRedo"}get BeforeUndo(){return"BeforeUndo"}get CommandExecuted(){return"CommandExecuted"}get BeforeCommandExecute(){return"BeforeCommandExecute"}};p(u,"_instance");let _=u;var H=Object.getOwnPropertyDescriptor,M=(s,t,e,i)=>{for(var n=i>1?void 0:i?H(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(n=c(n)||n);return n},R=(s,t)=>(e,i)=>t(e,i,s);exports.FHooks=class extends S{constructor(t,e){super(),this._injector=t,this._lifecycleService=e}onStarting(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Starting)).subscribe(t))}onReady(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Ready)).subscribe(t))}onRendered(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Rendered)).subscribe(t))}onSteady(t){return r.toDisposable(this._lifecycleService.lifecycle$.pipe(g.filter(e=>e===r.LifecycleStages.Steady)).subscribe(t))}onBeforeUndo(t){return this._injector.get(r.ICommandService).beforeCommandExecuted(i=>{if(i.id===r.UndoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopUndoElement();o&&t(o)}})}onUndo(t){return this._injector.get(r.ICommandService).onCommandExecuted(i=>{if(i.id===r.UndoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopUndoElement();o&&t(o)}})}onBeforeRedo(t){return this._injector.get(r.ICommandService).beforeCommandExecuted(i=>{if(i.id===r.RedoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopRedoElement();o&&t(o)}})}onRedo(t){return this._injector.get(r.ICommandService).onCommandExecuted(i=>{if(i.id===r.RedoCommand.id){const o=this._injector.get(r.IUndoRedoService).pitchTopRedoElement();o&&t(o)}})}};exports.FHooks=M([R(0,r.Inject(r.Injector)),R(1,r.Inject(r.LifecycleService))],exports.FHooks);var F=Object.getOwnPropertyDescriptor,V=(s,t,e,i)=>{for(var n=i>1?void 0:i?F(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(n=c(n)||n);return n},L=(s,t)=>(e,i)=>t(e,i,s);let D=class extends w{constructor(s,t){super(t),this.doc=s}};D=V([L(1,r.Inject(r.Injector))],D);class ${constructor(){p(this,"_eventRegistry",new Map);p(this,"_eventHandlerMap",new Map);p(this,"_eventHandlerRegisted",new Map)}_ensureEventRegistry(t){return this._eventRegistry.has(t)||this._eventRegistry.set(t,new r.Registry),this._eventRegistry.get(t)}registerEventHandler(t,e){const i=this._eventHandlerMap.get(t);return i?i.add(e):this._eventHandlerMap.set(t,new Set([e])),this._ensureEventRegistry(t).getData().length&&this._initEventHandler(t),r.toDisposable(()=>{var n,o,c,a;(n=this._eventHandlerMap.get(t))==null||n.delete(e),(c=(o=this._eventHandlerRegisted.get(t))==null?void 0:o.get(e))==null||c.dispose(),(a=this._eventHandlerRegisted.get(t))==null||a.delete(e)})}removeEvent(t,e){const i=this._ensureEventRegistry(t);if(i.delete(e),i.getData().length===0){const n=this._eventHandlerRegisted.get(t);n==null||n.forEach(o=>o.dispose()),this._eventHandlerRegisted.delete(t)}}_initEventHandler(t){let e=this._eventHandlerRegisted.get(t);const i=this._eventHandlerMap.get(t);i&&(!e||e.size===0)&&(e=new Map,this._eventHandlerRegisted.set(t,e),i==null||i.forEach(n=>{e==null||e.set(n,r.toDisposable(n()))}))}addEvent(t,e){return this._ensureEventRegistry(t).add(e),this._initEventHandler(t),r.toDisposable(()=>this.removeEvent(t,e))}fireEvent(t,e){var i;return(i=this._eventRegistry.get(t))==null||i.getData().forEach(n=>{n(e)}),e.cancel}}var z=Object.getOwnPropertyDescriptor,N=(s,t,e,i)=>{for(var n=i>1?void 0:i?z(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(n=c(n)||n);return n},x=(s,t)=>(e,i)=>t(e,i,s);let j=class extends S{constructor(s,t){super(),this._injector=s,this._userManagerService=t}getCurrentUser(){return this._userManagerService.getCurrentUser()}};j=N([x(0,r.Inject(r.Injector)),x(1,r.Inject(r.UserManagerService))],j);const b=class b{static get(){if(this._instance)return this._instance;const t=new b;return this._instance=t,t}static extend(t){Object.getOwnPropertyNames(t.prototype).forEach(e=>{e!=="constructor"&&(this.prototype[e]=t.prototype[e])}),Object.getOwnPropertyNames(t).forEach(e=>{e!=="prototype"&&e!=="name"&&e!=="length"&&(this[e]=t[e])})}get rectangle(){return r.Rectangle}get numfmt(){return r.numfmt}get tools(){return r.Tools}};p(b,"_instance");let E=b;var A=Object.getOwnPropertyDescriptor,W=(s,t,e,i)=>{for(var n=i>1?void 0:i?A(t,e):t,o=s.length-1,c;o>=0;o--)(c=s[o])&&(n=c(n)||n);return n},f=(s,t)=>(e,i)=>t(e,i,s);const C=Symbol("initializers");exports.FUniver=class extends r.Disposable{constructor(e,i,n,o){super();p(this,"_eventRegistry",new $);p(this,"registerEventHandler",(e,i)=>this._eventRegistry.registerEventHandler(e,i));this._injector=e,this._commandService=i,this._univerInstanceService=n,this._lifecycleService=o,this.disposeWithMe(this.registerEventHandler(this.Event.LifeCycleChanged,()=>r.toDisposable(this._lifecycleService.lifecycle$.subscribe(a=>{this.fireEvent(this.Event.LifeCycleChanged,{stage:a})})))),this._initUnitEvent(this._injector),this._initBeforeCommandEvent(this._injector),this._initCommandEvent(this._injector),this._injector.onDispose(()=>{this.dispose()});const c=Object.getPrototypeOf(this)[C];if(c){const a=this;c.forEach(function(l){l.apply(a,[e])})}}static newAPI(e){return(e instanceof r.Univer?e.__getInjector():e).createInstance(exports.FUniver)}_initialize(e){}static extend(e){Object.getOwnPropertyNames(e.prototype).forEach(i=>{if(i==="_initialize"){let n=this.prototype[C];n||(n=[],this.prototype[C]=n),n.push(e.prototype._initialize)}else i!=="constructor"&&(this.prototype[i]=e.prototype[i])}),Object.getOwnPropertyNames(e).forEach(i=>{i!=="prototype"&&i!=="name"&&i!=="length"&&(this[i]=e[i])})}_initCommandEvent(e){const i=e.get(r.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.Redo,()=>i.onCommandExecuted(n=>{const{id:o,type:c,params:a}=n;if(n.id===r.RedoCommand.id){const d={id:o,type:c,params:a};this.fireEvent(this.Event.Redo,d)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.Undo,()=>i.onCommandExecuted(n=>{const{id:o,type:c,params:a}=n;if(n.id===r.UndoCommand.id){const d={id:o,type:c,params:a};this.fireEvent(this.Event.Undo,d)}}))),this.disposeWithMe(this.registerEventHandler(this.Event.CommandExecuted,()=>i.onCommandExecuted((n,o)=>{const{id:c,type:a,params:l}=n;if(n.id!==r.RedoCommand.id&&n.id!==r.UndoCommand.id){const y={id:c,type:a,params:l,options:o};this.fireEvent(this.Event.CommandExecuted,y)}})))}_initBeforeCommandEvent(e){const i=e.get(r.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeRedo,()=>i.beforeCommandExecuted(n=>{const{id:o,type:c,params:a}=n;if(n.id===r.RedoCommand.id){const d={id:o,type:c,params:a};if(this.fireEvent(this.Event.BeforeRedo,d),d.cancel)throw new r.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeUndo,()=>i.beforeCommandExecuted(n=>{const{id:o,type:c,params:a}=n;if(n.id===r.UndoCommand.id){const d={id:o,type:c,params:a};if(this.fireEvent(this.Event.BeforeUndo,d),d.cancel)throw new r.CanceledError}}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeCommandExecute,()=>i.beforeCommandExecuted((n,o)=>{const{id:c,type:a,params:l}=n;if(n.id!==r.RedoCommand.id&&n.id!==r.UndoCommand.id){const y={id:c,type:a,params:l,options:o};if(this.fireEvent(this.Event.BeforeCommandExecute,y),y.cancel)throw new r.CanceledError}})))}_initUnitEvent(e){const i=e.get(r.IUniverInstanceService);this.disposeWithMe(this.registerEventHandler(this.Event.DocDisposed,()=>i.unitDisposed$.subscribe(n=>{n.type===r.UniverInstanceType.UNIVER_DOC&&this.fireEvent(this.Event.DocDisposed,{unitId:n.getUnitId(),unitType:n.type,snapshot:n.getSnapshot()})}))),this.disposeWithMe(this.registerEventHandler(this.Event.DocCreated,()=>i.unitAdded$.subscribe(n=>{if(n.type===r.UniverInstanceType.UNIVER_DOC){const o=n,c=e.createInstance(D,o);this.fireEvent(this.Event.DocCreated,{unitId:n.getUnitId(),type:n.type,doc:c,unit:c})}})))}disposeUnit(e){return this._univerInstanceService.disposeUnit(e)}getCurrentLifecycleStage(){return this._injector.get(r.LifecycleService).stage}undo(){return this._commandService.executeCommand(r.UndoCommand.id)}redo(){return this._commandService.executeCommand(r.RedoCommand.id)}toggleDarkMode(e){this._injector.get(r.ThemeService).setDarkMode(e)}loadLocales(e,i){this._injector.get(r.LocaleService).load({[e]:i})}setLocale(e){this._injector.get(r.LocaleService).setLocale(e)}onBeforeCommandExecute(e){return this._commandService.beforeCommandExecuted((i,n)=>{e(i,n)})}onCommandExecuted(e){return this._commandService.onCommandExecuted((i,n)=>{e(i,n)})}executeCommand(e,i,n){return this._commandService.executeCommand(e,i,n)}syncExecuteCommand(e,i,n){return this._commandService.syncExecuteCommand(e,i,n)}getHooks(){return this._injector.createInstance(exports.FHooks)}get Enum(){return m.get()}get Event(){return _.get()}get Util(){return E.get()}addEvent(e,i){if(!e||!i)throw new Error("Cannot add empty event");return this._eventRegistry.addEvent(e,i)}fireEvent(e,i){return this._eventRegistry.fireEvent(e,i)}getUserManager(){return this._injector.createInstance(j)}newBlob(){return this._injector.createInstance(exports.FBlob)}newColor(){return new r.ColorBuilder}newRichText(e){return r.RichTextBuilder.create(e)}newRichTextValue(e){return r.RichTextValue.create(e)}newParagraphStyle(e){return r.ParagraphStyleBuilder.create(e)}newParagraphStyleValue(e){return r.ParagraphStyleValue.create(e)}newTextStyle(e){return r.TextStyleBuilder.create(e)}newTextStyleValue(e){return r.TextStyleValue.create(e)}newTextDecoration(e){return new r.TextDecorationBuilder(e)}};exports.FUniver=W([f(0,r.Inject(r.Injector)),f(1,r.ICommandService),f(2,r.IUniverInstanceService),f(3,r.Inject(r.LifecycleService))],exports.FUniver);exports.FBase=S;exports.FBaseInitialable=w;exports.FEnum=m;exports.FEventName=_;exports.FUtil=E;
|