facade.js 4.8 KB

1
  1. "use strict";var v=Object.defineProperty;var l=(o,e,t)=>e in o?v(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var a=(o,e,t)=>l(o,typeof e!="symbol"?e+"":e,t);const n=require("@univerjs/core"),i=require("@univerjs/ui");var b=Object.defineProperty,I=Object.getOwnPropertyDescriptor,g=(o,e,t,r)=>{for(var s=r>1?void 0:r?I(e,t):e,c=o.length-1,u;c>=0;c--)(u=o[c])&&(s=(r?u(e,t,s):u(s))||s);return r&&s&&b(e,t,s),s},d=(o,e)=>(t,r)=>e(t,r,o),m;let h=(m=class extends n.FBase{constructor(e,t,r,s){super();a(this,"_commandToRegister",new Map);a(this,"_buildingSchema");this._item=e,this._injector=t,this._commandService=r,this._menuManagerService=s;const c=typeof e.action=="string"?e.action:n.Tools.generateRandomId(12);c!==e.action&&this._commandToRegister.set(c,e.action),this._buildingSchema={menuItemFactory:()=>({id:e.id,type:i.MenuItemType.BUTTON,icon:e.icon,title:e.title,tooltip:e.tooltip,commandId:c})},typeof e.order<"u"&&(this._buildingSchema.order=e.order)}__getSchema(){return this._commandToRegister.forEach((e,t)=>{this._commandService.hasCommand(t)||this._commandService.registerCommand({id:t,type:n.CommandType.COMMAND,handler:e})}),{[this._item.id]:this._buildingSchema}}appendTo(e){const t=this.__getSchema();this._menuManagerService.mergeMenu({[e]:t})}},a(m,"RibbonStartGroup",i.RibbonStartGroup),a(m,"RibbonPosition",i.RibbonPosition),a(m,"MenuManagerPosition",i.MenuManagerPosition),m);h=g([d(1,n.Inject(n.Injector)),d(2,n.ICommandService),d(3,i.IMenuManagerService)],h);let S=class extends n.FBase{constructor(e,t,r){super();a(this,"_menuByGroups",[]);a(this,"_submenus",[]);a(this,"_buildingSchema");this._item=e,this._injector=t,this._menuManagerService=r,this._buildingSchema={menuItemFactory:()=>({id:e.id,type:i.MenuItemType.SUBITEMS,icon:e.icon,title:e.title,tooltip:e.tooltip})},typeof e.order<"u"&&(this._buildingSchema.order=e.order)}addSubmenu(e){return this._submenus.push(e),this}addSeparator(){return this._menuByGroups.push(this._submenus),this._submenus=[],this}appendTo(e){const t=this.__getSchema();this._menuManagerService.mergeMenu({[e]:t})}__getSchema(){const e={};return this.addSeparator(),this._menuByGroups.forEach((t,r)=>{const s={};t.forEach(c=>{Object.assign(s,c.__getSchema())}),e[`${this._item.id}-group-${r}`]=s}),{[this._item.id]:Object.assign(this._buildingSchema,e)}}};S=g([d(1,n.Inject(n.Injector)),d(2,i.IMenuManagerService)],S);var f=Object.defineProperty,C=Object.getOwnPropertyDescriptor,j=(o,e,t,r)=>{for(var s=r>1?void 0:r?C(e,t):e,c=o.length-1,u;c>=0;c--)(u=o[c])&&(s=(r?u(e,t,s):u(s))||s);return r&&s&&f(e,t,s),s},_=(o,e)=>(t,r)=>e(t,r,o);let p=class extends n.FBase{constructor(e,t){super();a(this,"_forceEscapeDisposable",null);this._injector=e,this._shortcutService=t}enableShortcut(){var e;(e=this._forceEscapeDisposable)==null||e.dispose(),this._forceEscapeDisposable=null}disableShortcut(){this._forceEscapeDisposable||(this._forceEscapeDisposable=this._shortcutService.forceEscape())}dispatchShortcutEvent(e){return this._shortcutService.dispatch(e)}};p=j([_(0,n.Inject(n.Injector)),_(1,i.IShortcutService)],p);class P extends n.FUniver{getURL(){return new URL(window.location.href)}getShortcut(){return this._injector.createInstance(p)}copy(){return this._commandService.syncExecuteCommand(i.CopyCommand.id)}paste(){return this._commandService.syncExecuteCommand(i.PasteCommand.id)}createMenu(e){return this._injector.createInstance(h,e)}createSubmenu(e){return this._injector.createInstance(S,e)}openSiderbar(e){return this._injector.get(i.ISidebarService).open(e)}openSidebar(e){return this.openSiderbar(e)}openDialog(e){const r=this._injector.get(i.IDialogService).open({...e,onClose:()=>{r.dispose()}});return r}getComponentManager(){return this._injector.get(i.ComponentManager)}showMessage(e){return this._injector.get(i.IMessageService).show(e),this}setUIVisible(e,t){return this._injector.get(i.IUIPartsService).setUIVisible(e,t),this}isUIVisible(e){return this._injector.get(i.IUIPartsService).isUIVisible(e)}registerUIPart(e,t){return this._injector.get(i.IUIPartsService).registerComponent(e,()=>n.connectInjector(t,this._injector))}registerComponent(e,t,r){const s=this._injector.get(i.ComponentManager);return this.disposeWithMe(s.register(e,t,r))}}n.FUniver.extend(P);class M extends n.FHooks{onBeforeCopy(e){return this._injector.get(n.ICommandService).beforeCommandExecuted(r=>{r.id===i.CopyCommand.id&&e()})}onCopy(e){return this._injector.get(n.ICommandService).onCommandExecuted(r=>{r.id===i.CopyCommand.id&&e()})}onBeforePaste(e){return this._injector.get(n.ICommandService).beforeCommandExecuted(r=>{r.id===i.PasteCommand.id&&e()})}onPaste(e){return this._injector.get(n.ICommandService).onCommandExecuted(r=>{(r.id===i.PasteCommand.id||r.id===i.SheetPasteShortKeyCommandName)&&e()})}}n.FHooks.extend(M);class y extends n.FEnum{get BuiltInUIPart(){return i.BuiltInUIPart}}n.FEnum.extend(y);