@univerjs/action-recorder 0.10.12 → 0.10.13

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/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var z=Object.defineProperty;var H=(e,n,r)=>n in e?z(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var g=(e,n,r)=>H(e,typeof n!="symbol"?n+"":n,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),a=require("@univerjs/sheets"),M=require("@univerjs/sheets-filter"),l=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),O=require("rxjs"),C=require("@univerjs/design"),f=require("react/jsx-runtime"),h=require("react");var S=function(){return S=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++){n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},S.apply(this,arguments)},J=function(e,n){var r={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(r[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,t=Object.getOwnPropertySymbols(e);o<t.length;o++)n.indexOf(t[o])<0&&Object.prototype.propertyIsEnumerable.call(e,t[o])&&(r[t[o]]=e[t[o]]);return r},E=h.forwardRef(function(e,n){var r=e.icon,t=e.id,o=e.className,i=e.extend,c=J(e,["icon","id","className","extend"]),m="univerjs-icon univerjs-icon-".concat(t," ").concat(o||"").trim(),u=h.useRef("_".concat(K()));return L(r,"".concat(t),{defIds:r.defIds,idSuffix:u.current},S({ref:n,className:m},c),i)});function L(e,n,r,t,o){return h.createElement(e.tag,S(S({key:n},G(e,r,o)),t),(Z(e,r).children||[]).map(function(i,c){return L(i,"".concat(n,"-").concat(e.tag,"-").concat(c),r,void 0,o)}))}function G(e,n,r){var t=S({},e.attrs);r!=null&&r.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=r.colorChannel1),e.tag==="mask"&&t.id&&(t.id=t.id+n.idSuffix),Object.entries(t).forEach(function(i){var c=i[0],m=i[1];c==="mask"&&typeof m=="string"&&(t[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});var o=n.defIds;return!o||o.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(i){var c=i[0],m=i[1];typeof m=="string"&&(t[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function Z(e,n){var r,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?S(S({},e),{children:e.children.map(function(o){return typeof o.attrs.id=="string"&&t&&t.includes(o.attrs.id)?S(S({},o),{attrs:S(S({},o.attrs),{id:o.attrs.id+n.idSuffix})}):o})}):e}function K(){return Math.random().toString(36).substring(2,8)}E.displayName="UniverIcon";var Y={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-icon_clip0_1559_19)"},children:[{tag:"path",attrs:{d:"M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z"}},{tag:"path",attrs:{d:"M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z",fillRule:"evenodd",clipRule:"evenodd"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"record-icon_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-icon_clip0_1559_19"]},T=h.forwardRef(function(e,n){return h.createElement(E,Object.assign({},e,{id:"record-icon",ref:n,icon:Y}))});T.displayName="RecordIcon";var Q=Object.getOwnPropertyDescriptor,X=(e,n,r,t)=>{for(var o=t>1?void 0:t?Q(n,r):n,i=e.length-1,c;i>=0;i--)(c=e[i])&&(o=c(o)||o);return o},A=(e,n)=>(r,t)=>n(r,t,e);exports.ActionRecorderService=class extends s.Disposable{constructor(r,t,o,i){super();g(this,"_shouldRecordCommands",new Set);g(this,"_panelOpened$",new O.BehaviorSubject(!1));g(this,"panelOpened$",this._panelOpened$.asObservable());g(this,"_recorder",null);g(this,"_recording$",new O.BehaviorSubject(!1));g(this,"recording$",this._recording$.asObservable());g(this,"_recorded$",new O.BehaviorSubject([]));g(this,"_recordedCommands$",new O.BehaviorSubject([]));g(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=r,this._logService=t,this._localFileService=o,this._instanceService=i}get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}registerRecordedCommand(r){if(r.type===s.CommandType.MUTATION)throw new Error("[CommandRecorderService] Cannot record mutation commands.");this._shouldRecordCommands.add(r.id)}togglePanel(r){this._panelOpened$.next(r),r===!1&&this.stopRecording()}startRecording(r=!1){this._recorder=this._commandSrv.onCommandExecuted(t=>{var o,i;if(this._shouldRecordCommands.has(t.id)){const c=this._recorded,m=this._recordedCommands;let u={...t};const y=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId(),{unitId:p=y,subUnitId:v}=u==null?void 0:u.params;if(r&&p&&v){const x=(i=this._instanceService.getUnit(p).getSheetBySheetId(v))==null?void 0:i.getName();u={...u,params:{...u.params,subUnitId:x}}}u.id===a.SetSelectionsOperation.id&&c.length>0&&c[c.length-1].id===a.SetSelectionsOperation.id?c[c.length-1]=u:(c.push(u),this._recorded$.next(c),u.type===s.CommandType.COMMAND&&(m.push(u),this._recordedCommands$.next(m)))}}),this._recording$.next(!0)}stopRecording(){var r;(r=this._recorder)==null||r.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){const r=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(r,null,2)]),"recorded-commands.json"),this._logService.error("Recorded commands:",r),this.stopRecording()}};exports.ActionRecorderService=X([A(0,s.ICommandService),A(1,s.ILogService),A(2,d.ILocalFileService),A(3,s.IUniverInstanceService)],exports.ActionRecorderService);const B={id:"action-recorder.command.start-recording",type:s.CommandType.COMMAND,handler:(e,n)=>(e.get(exports.ActionRecorderService).startRecording(!!(n!=null&&n.replaceId)),!0)},k={id:"action-recorder.command.complete-recording",type:s.CommandType.COMMAND,handler:e=>(e.get(exports.ActionRecorderService).completeRecording(),!0)},V={id:"action-recorder.command.stop-recording",type:s.CommandType.COMMAND,handler:e=>(e.get(exports.ActionRecorderService).completeRecording(),!0)};var ee=Object.getOwnPropertyDescriptor,re=(e,n,r,t)=>{for(var o=t>1?void 0:t?ee(n,r):n,i=e.length-1,c;i>=0;i--)(c=e[i])&&(o=c(o)||o);return o},I=(e,n)=>(r,t)=>n(r,t,e),U=(e=>(e.DEFAULT="default",e.NAME="name",e.ACTIVE="active",e))(U||{});exports.ActionReplayService=class extends s.Disposable{constructor(n,r,t,o,i){super(),this._messageService=n,this._instanceService=r,this._localFileService=t,this._logService=o,this._commandService=i}async replayLocalJSON(n="default"){const r=await this._localFileService.openFile({multiple:!1,accept:".json"});if(r.length!==1)return!1;const t=r[0];try{return this.replayCommands(JSON.parse(await t.text()),{mode:n})}catch{return this._messageService.show({type:C.MessageType.Error,content:`Failed to replay commands from local file ${t.name}.`}),!1}}async replayCommands(n,r){var i,c,m;const t=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId();t||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:o}=r||{};for(const u of n){const{id:y,params:p}=u,v=p;if(v){if(typeof v.unitId<"u"&&(v.unitId=t),o==="name"&&v.subUnitId!=="undefined"){const R=(c=this._instanceService.getFocusedUnit().getSheetBySheetName(v.subUnitId))==null?void 0:c.getSheetId();R?v.subUnitId=R:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${v.subUnitId}`)}if(o==="active"&&v.subUnitId!=="undefined"){const R=(m=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:m.getSheetId();R?v.subUnitId=R:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(y,p))return!1}else if(!await this._commandService.executeCommand(y))return!1}return!0}async replayCommandsWithDelay(n){var t;const r=(t=this._instanceService.getFocusedUnit())==null?void 0:t.getUnitId();r||this._logService.error("[ReplayService]","no focused unit to replay commands");for(const o of n){await s.awaitTime(te());const{id:i,params:c}=o;if(c){if(typeof c.unitId<"u"&&(c.unitId=r),!await this._commandService.executeCommand(i,c))return!1}else if(!await this._commandService.executeCommand(i))return!1}return!0}};exports.ActionReplayService=re([I(0,d.IMessageService),I(1,s.IUniverInstanceService),I(2,d.ILocalFileService),I(3,s.ILogService),I(4,s.ICommandService)],exports.ActionReplayService);function te(){return Math.floor(Math.random()*800)+200}const N={id:"action-recorder.command.replay-local-records",type:s.CommandType.COMMAND,handler:async e=>{const r=await e.get(exports.ActionReplayService).replayLocalJSON();return r&&e.get(d.IMessageService).show({type:C.MessageType.Success,content:"Successfully replayed local records"}),r}},j={id:"action-recorder.command.replay-local-records-name",type:s.CommandType.COMMAND,handler:async e=>{const r=await e.get(exports.ActionReplayService).replayLocalJSON(U.NAME);return r&&e.get(d.IMessageService).show({type:C.MessageType.Success,content:"Successfully replayed local records"}),r}},P={id:"action-recorder.command.replay-local-records-active",type:s.CommandType.COMMAND,handler:async e=>{const r=await e.get(exports.ActionReplayService).replayLocalJSON(U.ACTIVE);return r&&e.get(d.IMessageService).show({type:C.MessageType.Success,content:"Successfully replayed local records"}),r}},$={id:"action-recorder.operation.open-panel",type:s.CommandType.OPERATION,handler(e){return e.get(exports.ActionRecorderService).togglePanel(!0),!0}},W={id:"action-recorder.operation.close-panel",type:s.CommandType.OPERATION,handler(e){return e.get(exports.ActionRecorderService).togglePanel(!1),!0}};function ne(){const e=d.useDependency(exports.ActionRecorderService);return d.useObservable(e.panelOpened$)?f.jsx(oe,{}):null}function oe(){var p;const e=d.useDependency(s.ICommandService),n=d.useDependency(exports.ActionRecorderService),r=d.useObservable(n.recording$),t=d.useObservable(n.recordedCommands$),o=(p=t==null?void 0:t.length)!=null?p:0,i=h.useCallback(()=>{r||e.executeCommand(W.id)},[e,r]),c=h.useCallback(v=>{r||e.executeCommand(B.id,{replaceId:v})},[e,r]),m=h.useCallback(()=>{r&&e.executeCommand(k.id)},[e,r]),u=h.useCallback(()=>{r&&e.executeCommand(V.id)},[e,r]),y=r?o===0?"Recording...":`${o}: ${t[o-1].id}`:"Start Recording";return f.jsxs("div",{className:"univer-fixed univer-bottom-20 univer-left-1/2 univer-z-[1000] univer-flex univer-h-16 univer-w-[512px] -univer-translate-x-1/2 univer-items-center univer-rounded-lg univer-bg-white univer-px-5 univer-shadow-lg",children:[f.jsx("div",{className:"univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl",children:f.jsx(T,{})}),f.jsx("div",{className:"univer-flex-1 univer-text-sm",children:y}),f.jsxs("div",{className:"univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between",children:[f.jsx(C.Button,{className:"univer-w-20",onClick:r?u:i,children:r?"Cancel":"Close"}),f.jsx(C.Button,{className:"univer-w-20",variant:"primary",onClick:r?m:()=>c(),children:r?"Save":"Start"}),!r&&f.jsx(C.Button,{variant:"primary",onClick:()=>c(!0),children:"Start(N)"})]})]})}const q="RECORD_MENU_ITEM";function ie(){return{id:q,type:d.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function ce(e){const n=e.get(exports.ActionRecorderService);return{id:$.id,title:"action-recorder.menu.record",type:d.MenuItemType.BUTTON,disabled$:n.panelOpened$}}function ae(){return{id:N.id,title:"action-recorder.menu.replay-local",type:d.MenuItemType.BUTTON}}function se(){return{id:j.id,title:"action-recorder.menu.replay-local-name",type:d.MenuItemType.BUTTON}}function de(){return{id:P.id,title:"action-recorder.menu.replay-local-active",type:d.MenuItemType.BUTTON}}const le={[d.RibbonStartGroup.OTHERS]:{[q]:{order:2,menuItemFactory:ie,[$.id]:{order:1,menuItemFactory:ce},[N.id]:{order:2,menuItemFactory:ae},[j.id]:{order:3,menuItemFactory:se},[P.id]:{order:4,menuItemFactory:de}}}};var me=Object.getOwnPropertyDescriptor,ue=(e,n,r,t)=>{for(var o=t>1?void 0:t?me(n,r):n,i=e.length-1,c;i>=0;i--)(c=e[i])&&(o=c(o)||o);return o},_=(e,n)=>(r,t)=>n(r,t,e);let b=class extends s.Disposable{constructor(e,n,r,t,o,i){super(),this._commandSrv=e,this._uiPartsSrv=n,this._menuManagerService=r,this._componentManager=t,this._actionRecorderService=o,this._injector=i,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[B,V,k,$,W,N,j,P].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(d.BuiltInUIPart.GLOBAL,()=>d.connectInjector(ne,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",T)),this._menuManagerService.mergeMenu(le)}_initSheetsCommands(){[a.CopySheetCommand,a.DeleteRangeMoveLeftCommand,a.DeleteRangeMoveUpCommand,a.DeltaColumnWidthCommand,a.DeltaRowHeightCommand,a.InsertSheetCommand,a.InsertColAfterCommand,a.InsertColBeforeCommand,a.InsertRowAfterCommand,a.InsertRowBeforeCommand,a.RemoveSheetCommand,a.SetStyleCommand,a.AddWorksheetMergeCommand,a.AddWorksheetMergeAllCommand,a.AddWorksheetMergeVerticalCommand,a.AddWorksheetMergeHorizontalCommand,a.SetFrozenCommand,a.CancelFrozenCommand,a.SetHorizontalTextAlignCommand,a.SetOverlineCommand,l.SetRangeBoldCommand,l.SetRangeFontFamilyCommand,l.SetRangeFontSizeCommand,l.SetRangeItalicCommand,l.SetRangeStrickThroughCommand,l.SetRangeSubscriptCommand,l.SetRangeSuperscriptCommand,l.SetRangeTextColorCommand,l.SetRangeUnderlineCommand,a.SetRangeValuesCommand,a.SetStrikeThroughCommand,a.SetTextColorCommand,a.SetTextRotationCommand,a.SetTextWrapCommand,a.SetVerticalTextAlignCommand,l.SheetCopyCommand,l.SheetCutCommand,l.SheetPasteBesidesBorderCommand,l.SheetPasteColWidthCommand,l.SheetPasteCommand,l.SheetPasteFormatCommand,l.SheetPasteShortKeyCommand,l.SheetPasteValueCommand,l.AutoFillCommand,l.RefillCommand,a.SetWorksheetActivateCommand,a.SetWorksheetActiveOperation,a.SetSelectionsOperation,M.SetSheetFilterRangeCommand,M.SetSheetsFilterCriteriaCommand,M.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};b=ue([_(0,s.ICommandService),_(1,d.IUIPartsService),_(2,d.IMenuManagerService),_(3,s.Inject(d.ComponentManager)),_(4,s.Inject(exports.ActionRecorderService)),_(5,s.Inject(s.Injector))],b);const ve="action-recorder.config",F={};var Se=Object.getOwnPropertyDescriptor,ge=(e,n,r,t)=>{for(var o=t>1?void 0:t?Se(n,r):n,i=e.length-1,c;i>=0;i--)(c=e[i])&&(o=c(o)||o);return o},D=(e,n)=>(r,t)=>n(r,t,e),w;exports.UniverActionRecorderPlugin=(w=class extends s.Plugin{constructor(n=F,r,t){super(),this._config=n,this._injector=r,this._configService=t;const{menu:o,...i}=s.merge({},F,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(ve,i)}onStarting(){(this._config.replayOnly?[[exports.ActionReplayService]]:[[exports.ActionRecorderService],[exports.ActionReplayService],[b]]).forEach(r=>this._injector.add(r))}onSteady(){this._config.replayOnly||this._injector.get(b)}},g(w,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),w);exports.UniverActionRecorderPlugin=ge([D(1,s.Inject(s.Injector)),D(2,s.IConfigService)],exports.UniverActionRecorderPlugin);
1
+ "use strict";var q=Object.defineProperty;var z=(t,r,e)=>r in t?q(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var v=(t,r,e)=>z(t,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),p=require("react"),a=require("@univerjs/sheets"),x=require("@univerjs/sheets-filter"),l=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),I=require("rxjs"),f=require("@univerjs/design"),g=require("react/jsx-runtime");function D({ref:t,...r}){const{icon:e,id:n,className:o,extend:i,...c}=r,S=`univerjs-icon univerjs-icon-${n} ${o||""}`.trim(),m=p.useRef(`_${G()}`);return E(e,`${n}`,{defIds:e.defIds,idSuffix:m.current},{ref:t,className:S,...c},i)}function E(t,r,e,n,o){return p.createElement(t.tag,{key:r,...H(t,e,o),...n},(J(t,e).children||[]).map((i,c)=>E(i,`${r}-${t.tag}-${c}`,e,void 0,o)))}function H(t,r,e){const n={...t.attrs};e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),t.tag==="mask"&&n.id&&(n.id=n.id+r.idSuffix),Object.entries(n).forEach(([i,c])=>{i==="mask"&&typeof c=="string"&&(n[i]=c.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))});const{defIds:o}=r;return!o||o.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+r.idSuffix),Object.entries(n).forEach(([i,c])=>{typeof c=="string"&&(n[i]=c.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))})),n}function J(t,r){var n;const{defIds:e}=r;return!e||e.length===0?t:t.tag==="defs"&&((n=t.children)!=null&&n.length)?{...t,children:t.children.map(o=>typeof o.attrs.id=="string"&&e&&e.includes(o.attrs.id)?{...o,attrs:{...o.attrs,id:o.attrs.id+r.idSuffix}}:o)}:t}function G(){return Math.random().toString(36).substring(2,8)}D.displayName="UniverIcon";const Z={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-icon_clip0_1559_19)"},children:[{tag:"path",attrs:{d:"M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z"}},{tag:"path",attrs:{d:"M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z",fillRule:"evenodd",clipRule:"evenodd"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"record-icon_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-icon_clip0_1559_19"]},w=p.forwardRef(function(r,e){return p.createElement(D,Object.assign({},r,{id:"record-icon",ref:e,icon:Z}))});w.displayName="RecordIcon";var K=Object.getOwnPropertyDescriptor,Y=(t,r,e,n)=>{for(var o=n>1?void 0:n?K(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},O=(t,r)=>(e,n)=>r(e,n,t);exports.ActionRecorderService=class extends s.Disposable{constructor(e,n,o,i){super();v(this,"_shouldRecordCommands",new Set);v(this,"_panelOpened$",new I.BehaviorSubject(!1));v(this,"panelOpened$",this._panelOpened$.asObservable());v(this,"_recorder",null);v(this,"_recording$",new I.BehaviorSubject(!1));v(this,"recording$",this._recording$.asObservable());v(this,"_recorded$",new I.BehaviorSubject([]));v(this,"_recordedCommands$",new I.BehaviorSubject([]));v(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=e,this._logService=n,this._localFileService=o,this._instanceService=i}get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}registerRecordedCommand(e){if(e.type===s.CommandType.MUTATION)throw new Error("[CommandRecorderService] Cannot record mutation commands.");this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{var o,i;if(this._shouldRecordCommands.has(n.id)){const c=this._recorded,S=this._recordedCommands;let m={...n};const C=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId(),{unitId:h=C,subUnitId:u}=m==null?void 0:m.params;if(e&&h&&u){const M=(i=this._instanceService.getUnit(h).getSheetBySheetId(u))==null?void 0:i.getName();m={...m,params:{...m.params,subUnitId:M}}}m.id===a.SetSelectionsOperation.id&&c.length>0&&c[c.length-1].id===a.SetSelectionsOperation.id?c[c.length-1]=m:(c.push(m),this._recorded$.next(c),m.type===s.CommandType.COMMAND&&(S.push(m),this._recordedCommands$.next(S)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){const e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),"recorded-commands.json"),this._logService.error("Recorded commands:",e),this.stopRecording()}};exports.ActionRecorderService=Y([O(0,s.ICommandService),O(1,s.ILogService),O(2,d.ILocalFileService),O(3,s.IUniverInstanceService)],exports.ActionRecorderService);const L={id:"action-recorder.command.start-recording",type:s.CommandType.COMMAND,handler:(t,r)=>(t.get(exports.ActionRecorderService).startRecording(!!(r!=null&&r.replaceId)),!0)},B={id:"action-recorder.command.complete-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)},k={id:"action-recorder.command.stop-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)};var Q=Object.getOwnPropertyDescriptor,X=(t,r,e,n)=>{for(var o=n>1?void 0:n?Q(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},R=(t,r)=>(e,n)=>r(e,n,t),T=(t=>(t.DEFAULT="default",t.NAME="name",t.ACTIVE="active",t))(T||{});exports.ActionReplayService=class extends s.Disposable{constructor(r,e,n,o,i){super(),this._messageService=r,this._instanceService=e,this._localFileService=n,this._logService=o,this._commandService=i}async replayLocalJSON(r="default"){const e=await this._localFileService.openFile({multiple:!1,accept:".json"});if(e.length!==1)return!1;const n=e[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:r})}catch{return this._messageService.show({type:f.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(r,e){var i,c,S;const n=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId();n||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:o}=e||{};for(const m of r){const{id:C,params:h}=m,u=h;if(u){if(typeof u.unitId<"u"&&(u.unitId=n),o==="name"&&u.subUnitId!=="undefined"){const _=(c=this._instanceService.getFocusedUnit().getSheetBySheetName(u.subUnitId))==null?void 0:c.getSheetId();_?u.subUnitId=_:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${u.subUnitId}`)}if(o==="active"&&u.subUnitId!=="undefined"){const _=(S=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:S.getSheetId();_?u.subUnitId=_:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(C,h))return!1}else if(!await this._commandService.executeCommand(C))return!1}return!0}async replayCommandsWithDelay(r){var n;const e=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();e||this._logService.error("[ReplayService]","no focused unit to replay commands");for(const o of r){await s.awaitTime(ee());const{id:i,params:c}=o;if(c){if(typeof c.unitId<"u"&&(c.unitId=e),!await this._commandService.executeCommand(i,c))return!1}else if(!await this._commandService.executeCommand(i))return!1}return!0}};exports.ActionReplayService=X([R(0,d.IMessageService),R(1,s.IUniverInstanceService),R(2,d.ILocalFileService),R(3,s.ILogService),R(4,s.ICommandService)],exports.ActionReplayService);function ee(){return Math.floor(Math.random()*800)+200}const U={id:"action-recorder.command.replay-local-records",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON();return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},$={id:"action-recorder.command.replay-local-records-name",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON(T.NAME);return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},N={id:"action-recorder.command.replay-local-records-active",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON(T.ACTIVE);return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},j={id:"action-recorder.operation.open-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!0),!0}},V={id:"action-recorder.operation.close-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!1),!0}};function te(){const t=d.useDependency(exports.ActionRecorderService);return d.useObservable(t.panelOpened$)?g.jsx(re,{}):null}function re(){var h;const t=d.useDependency(s.ICommandService),r=d.useDependency(exports.ActionRecorderService),e=d.useObservable(r.recording$),n=d.useObservable(r.recordedCommands$),o=(h=n==null?void 0:n.length)!=null?h:0,i=p.useCallback(()=>{e||t.executeCommand(V.id)},[t,e]),c=p.useCallback(u=>{e||t.executeCommand(L.id,{replaceId:u})},[t,e]),S=p.useCallback(()=>{e&&t.executeCommand(B.id)},[t,e]),m=p.useCallback(()=>{e&&t.executeCommand(k.id)},[t,e]),C=e?o===0?"Recording...":`${o}: ${n[o-1].id}`:"Start Recording";return g.jsxs("div",{className:"univer-fixed univer-bottom-20 univer-left-1/2 univer-z-[1000] univer-flex univer-h-16 univer-w-[512px] -univer-translate-x-1/2 univer-items-center univer-rounded-lg univer-bg-white univer-px-5 univer-shadow-lg",children:[g.jsx("div",{className:"univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl",children:g.jsx(w,{})}),g.jsx("div",{className:"univer-flex-1 univer-text-sm",children:C}),g.jsxs("div",{className:"univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between",children:[g.jsx(f.Button,{className:"univer-w-20",onClick:e?m:i,children:e?"Cancel":"Close"}),g.jsx(f.Button,{className:"univer-w-20",variant:"primary",onClick:e?S:()=>c(),children:e?"Save":"Start"}),!e&&g.jsx(f.Button,{variant:"primary",onClick:()=>c(!0),children:"Start(N)"})]})]})}const W="RECORD_MENU_ITEM";function ne(){return{id:W,type:d.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function oe(t){const r=t.get(exports.ActionRecorderService);return{id:j.id,title:"action-recorder.menu.record",type:d.MenuItemType.BUTTON,disabled$:r.panelOpened$}}function ie(){return{id:U.id,title:"action-recorder.menu.replay-local",type:d.MenuItemType.BUTTON}}function ce(){return{id:$.id,title:"action-recorder.menu.replay-local-name",type:d.MenuItemType.BUTTON}}function ae(){return{id:N.id,title:"action-recorder.menu.replay-local-active",type:d.MenuItemType.BUTTON}}const se={[d.RibbonStartGroup.OTHERS]:{[W]:{order:2,menuItemFactory:ne,[j.id]:{order:1,menuItemFactory:oe},[U.id]:{order:2,menuItemFactory:ie},[$.id]:{order:3,menuItemFactory:ce},[N.id]:{order:4,menuItemFactory:ae}}}};var de=Object.getOwnPropertyDescriptor,le=(t,r,e,n)=>{for(var o=n>1?void 0:n?de(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},y=(t,r)=>(e,n)=>r(e,n,t);let A=class extends s.Disposable{constructor(t,r,e,n,o,i){super(),this._commandSrv=t,this._uiPartsSrv=r,this._menuManagerService=e,this._componentManager=n,this._actionRecorderService=o,this._injector=i,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[L,k,B,j,V,U,$,N].forEach(t=>this._commandSrv.registerCommand(t))}_initUI(){this._uiPartsSrv.registerComponent(d.BuiltInUIPart.GLOBAL,()=>d.connectInjector(te,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",w)),this._menuManagerService.mergeMenu(se)}_initSheetsCommands(){[a.CopySheetCommand,a.DeleteRangeMoveLeftCommand,a.DeleteRangeMoveUpCommand,a.DeltaColumnWidthCommand,a.DeltaRowHeightCommand,a.InsertSheetCommand,a.InsertColAfterCommand,a.InsertColBeforeCommand,a.InsertRowAfterCommand,a.InsertRowBeforeCommand,a.RemoveSheetCommand,a.SetStyleCommand,a.AddWorksheetMergeCommand,a.AddWorksheetMergeAllCommand,a.AddWorksheetMergeVerticalCommand,a.AddWorksheetMergeHorizontalCommand,a.SetFrozenCommand,a.CancelFrozenCommand,a.SetHorizontalTextAlignCommand,a.SetOverlineCommand,l.SetRangeBoldCommand,l.SetRangeFontFamilyCommand,l.SetRangeFontSizeCommand,l.SetRangeItalicCommand,l.SetRangeStrickThroughCommand,l.SetRangeSubscriptCommand,l.SetRangeSuperscriptCommand,l.SetRangeTextColorCommand,l.SetRangeUnderlineCommand,a.SetRangeValuesCommand,a.SetStrikeThroughCommand,a.SetTextColorCommand,a.SetTextRotationCommand,a.SetTextWrapCommand,a.SetVerticalTextAlignCommand,l.SheetCopyCommand,l.SheetCutCommand,l.SheetPasteBesidesBorderCommand,l.SheetPasteColWidthCommand,l.SheetPasteCommand,l.SheetPasteFormatCommand,l.SheetPasteShortKeyCommand,l.SheetPasteValueCommand,l.AutoFillCommand,l.RefillCommand,a.SetWorksheetActivateCommand,a.SetWorksheetActiveOperation,a.SetSelectionsOperation,x.SetSheetFilterRangeCommand,x.SetSheetsFilterCriteriaCommand,x.RemoveSheetFilterCommand].forEach(t=>this._actionRecorderService.registerRecordedCommand(t))}_initDocsCommands(){}};A=le([y(0,s.ICommandService),y(1,d.IUIPartsService),y(2,d.IMenuManagerService),y(3,s.Inject(d.ComponentManager)),y(4,s.Inject(exports.ActionRecorderService)),y(5,s.Inject(s.Injector))],A);const me="action-recorder.config",P={};var ue=Object.getOwnPropertyDescriptor,Se=(t,r,e,n)=>{for(var o=n>1?void 0:n?ue(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},F=(t,r)=>(e,n)=>r(e,n,t),b;exports.UniverActionRecorderPlugin=(b=class extends s.Plugin{constructor(r=P,e,n){super(),this._config=r,this._injector=e,this._configService=n;const{menu:o,...i}=s.merge({},P,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(me,i)}onStarting(){(this._config.replayOnly?[[exports.ActionReplayService]]:[[exports.ActionRecorderService],[exports.ActionReplayService],[A]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(A)}},v(b,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),b);exports.UniverActionRecorderPlugin=Se([F(1,s.Inject(s.Injector)),F(2,s.IConfigService)],exports.UniverActionRecorderPlugin);