@univerjs/action-recorder 0.6.10 → 0.7.0-beta.1
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 +4 -1
- package/lib/es/index.js +222 -204
- package/lib/index.css +1 -1
- package/lib/index.js +222 -204
- package/lib/umd/index.js +4 -1
- package/package.json +11 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
"use strict";var z=Object.defineProperty;var J=(e,n,r)=>n in e?z(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r;var v=(e,n,r)=>J(e,typeof n!="symbol"?n+"":n,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),a=require("@univerjs/sheets"),x=require("@univerjs/sheets-filter"),l=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),A=require("rxjs"),C=require("@univerjs/design"),f=require("react/jsx-runtime"),p=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)},G=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},L=p.forwardRef(function(e,n){var r=e.icon,t=e.id,o=e.className,c=e.extend,i=G(e,["icon","id","className","extend"]),m="univerjs-icon univerjs-icon-".concat(t," ").concat(o||"").trim(),u=p.useRef("_".concat(Y()));return B(r,"".concat(t),{defIds:r.defIds,idSuffix:u.current},S({ref:n,className:m},i),c)});function B(e,n,r,t,o){return p.createElement(e.tag,S(S({key:n},Z(e,r,o)),t),(K(e,r).children||[]).map(function(c,i){return B(c,"".concat(n,"-").concat(e.tag,"-").concat(i),r,void 0,o)}))}function Z(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(c){var i=c[0],m=c[1];i==="mask"&&typeof m=="string"&&(t[i]=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(c){var i=c[0],m=c[1];typeof m=="string"&&(t[i]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function K(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.indexOf(o.attrs.id)>-1?S(S({},o),{attrs:S(S({},o.attrs),{id:o.attrs.id+n.idSuffix})}):o})}):e}function Y(){return Math.random().toString(36).substring(2,8)}L.displayName="UniverIcon";var Q={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-single_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-single_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"#fff",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-single_clip0_1559_19"]},U=p.forwardRef(function(e,n){return p.createElement(L,Object.assign({},e,{id:"record-single",ref:n,icon:Q}))});U.displayName="RecordSingle";var X=Object.getOwnPropertyDescriptor,ee=(e,n,r,t)=>{for(var o=t>1?void 0:t?X(n,r):n,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=i(o)||o);return o},b=(e,n)=>(r,t)=>n(r,t,e);exports.ActionRecorderService=class extends s.Disposable{constructor(r,t,o,c){super();v(this,"_shouldRecordCommands",new Set);v(this,"_panelOpened$",new A.BehaviorSubject(!1));v(this,"panelOpened$",this._panelOpened$.asObservable());v(this,"_recorder",null);v(this,"_recording$",new A.BehaviorSubject(!1));v(this,"recording$",this._recording$.asObservable());v(this,"_recorded$",new A.BehaviorSubject([]));v(this,"_recordedCommands$",new A.BehaviorSubject([]));v(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=r,this._logService=t,this._localFileService=o,this._instanceService=c}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,c;if(this._shouldRecordCommands.has(t.id)){const i=this._recorded,m=this._recordedCommands;let u={...t};const y=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId(),{unitId:h=y,subUnitId:g}=u==null?void 0:u.params;if(r&&h&&g){const P=(c=this._instanceService.getUnit(h).getSheetBySheetId(g))==null?void 0:c.getName();u={...u,params:{...u.params,subUnitId:P}}}u.id===a.SetSelectionsOperation.id&&i.length>0&&i[i.length-1].id===a.SetSelectionsOperation.id?i[i.length-1]=u:(i.push(u),this._recorded$.next(i),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=ee([b(0,s.ICommandService),b(1,s.ILogService),b(2,d.ILocalFileService),b(3,s.IUniverInstanceService)],exports.ActionRecorderService);const k={id:"action-recorder.command.start-recording",type:s.CommandType.COMMAND,handler:(e,n)=>(e.get(exports.ActionRecorderService).startRecording(!!(n!=null&&n.replaceId)),!0)},V={id:"action-recorder.command.complete-recording",type:s.CommandType.COMMAND,handler:e=>(e.get(exports.ActionRecorderService).completeRecording(),!0)},W={id:"action-recorder.command.stop-recording",type:s.CommandType.COMMAND,handler:e=>(e.get(exports.ActionRecorderService).completeRecording(),!0)};var re=Object.getOwnPropertyDescriptor,te=(e,n,r,t)=>{for(var o=t>1?void 0:t?re(n,r):n,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=i(o)||o);return o},I=(e,n)=>(r,t)=>n(r,t,e),N=(e=>(e.DEFAULT="default",e.NAME="name",e.ACTIVE="active",e))(N||{});exports.ActionReplayService=class extends s.Disposable{constructor(n,r,t,o,c){super(),this._messageService=n,this._instanceService=r,this._localFileService=t,this._logService=o,this._commandService=c}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 c,i,m;const t=(c=this._instanceService.getFocusedUnit())==null?void 0:c.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:h}=u,g=h;if(g){if(typeof g.unitId<"u"&&(g.unitId=t),o==="name"&&g.subUnitId!=="undefined"){const _=(i=this._instanceService.getFocusedUnit().getSheetBySheetName(g.subUnitId))==null?void 0:i.getSheetId();_?g.subUnitId=_:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${g.subUnitId}`)}if(o==="active"&&g.subUnitId!=="undefined"){const _=(m=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:m.getSheetId();_?g.subUnitId=_:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(y,h))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(ne());const{id:c,params:i}=o;if(i){if(typeof i.unitId<"u"&&(i.unitId=r),!await this._commandService.executeCommand(c,i))return!1}else if(!await this._commandService.executeCommand(c))return!1}return!0}};exports.ActionReplayService=te([I(0,d.IMessageService),I(1,s.IUniverInstanceService),I(2,d.ILocalFileService),I(3,s.ILogService),I(4,s.ICommandService)],exports.ActionReplayService);function ne(){return Math.floor(Math.random()*800)+200}const j={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}},w={id:"action-recorder.command.replay-local-records-name",type:s.CommandType.COMMAND,handler:async e=>{const r=await e.get(exports.ActionReplayService).replayLocalJSON(N.NAME);return r&&e.get(d.IMessageService).show({type:C.MessageType.Success,content:"Successfully replayed local records"}),r}},$={id:"action-recorder.command.replay-local-records-active",type:s.CommandType.COMMAND,handler:async e=>{const r=await e.get(exports.ActionReplayService).replayLocalJSON(N.ACTIVE);return r&&e.get(d.IMessageService).show({type:C.MessageType.Success,content:"Successfully replayed local records"}),r}},F={id:"action-recorder.operation.open-panel",type:s.CommandType.OPERATION,handler(e){return e.get(exports.ActionRecorderService).togglePanel(!0),!0}},q={id:"action-recorder.operation.close-panel",type:s.CommandType.OPERATION,handler(e){return e.get(exports.ActionRecorderService).togglePanel(!1),!0}},oe="univer-action-recorder-panel",ce="univer-action-recorder-panel-icon",ie="univer-action-recorder-panel-icon-recording",ae="univer-action-recorder-panel-title",se="univer-action-recorder-panel-actions",O={actionRecorderPanel:oe,actionRecorderPanelIcon:ce,actionRecorderPanelIconRecording:ie,actionRecorderPanelTitle:ae,actionRecorderPanelActions:se};function de(){const e=d.useDependency(exports.ActionRecorderService);return d.useObservable(e.panelOpened$)?f.jsx(le,{}):null}function le(){var h;const e=d.useDependency(s.ICommandService),n=d.useDependency(exports.ActionRecorderService),r=d.useObservable(n.recording$),t=d.useObservable(n.recordedCommands$),o=(h=t==null?void 0:t.length)!=null?h:0,c=p.useCallback(()=>{r||e.executeCommand(q.id)},[e,r]),i=p.useCallback(g=>{r||e.executeCommand(k.id,{replaceId:g})},[e,r]),m=p.useCallback(()=>{r&&e.executeCommand(V.id)},[e,r]),u=p.useCallback(()=>{r&&e.executeCommand(W.id)},[e,r]),y=r?o===0?"Recording...":`${o}: ${t[o-1].id}`:"Start Recording";return f.jsxs("div",{className:O.actionRecorderPanel,children:[f.jsx("div",{className:C.clsx(O.actionRecorderPanelIcon,r?O.actionRecorderPanelIconRecording:!1),children:f.jsx(U,{})}),f.jsx("div",{className:O.actionRecorderPanelTitle,children:y}),f.jsxs("div",{className:O.actionRecorderPanelActions,children:[f.jsx(C.Button,{onClick:r?u:c,children:r?"Cancel":"Close"}),f.jsx(C.Button,{variant:"primary",onClick:r?m:()=>i(),children:r?"Save":"Start"}),!r&&f.jsx(C.Button,{variant:"primary",onClick:()=>i(!0),children:"Start(N)"})]})]})}const H="RECORD_MENU_ITEM";function me(){return{id:H,type:d.MenuItemType.SUBITEMS,icon:"RecordSingle",tooltip:"action-recorder.menu.title"}}function ue(e){const n=e.get(exports.ActionRecorderService);return{id:F.id,title:"action-recorder.menu.record",type:d.MenuItemType.BUTTON,disabled$:n.panelOpened$}}function ge(){return{id:j.id,title:"action-recorder.menu.replay-local",type:d.MenuItemType.BUTTON}}function Se(){return{id:w.id,title:"action-recorder.menu.replay-local-name",type:d.MenuItemType.BUTTON}}function ve(){return{id:$.id,title:"action-recorder.menu.replay-local-active",type:d.MenuItemType.BUTTON}}const fe={[d.RibbonStartGroup.OTHERS]:{[H]:{order:10,menuItemFactory:me,[F.id]:{order:1,menuItemFactory:ue},[j.id]:{order:2,menuItemFactory:ge},[w.id]:{order:3,menuItemFactory:Se},[$.id]:{order:4,menuItemFactory:ve}}}};var pe=Object.getOwnPropertyDescriptor,he=(e,n,r,t)=>{for(var o=t>1?void 0:t?pe(n,r):n,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=i(o)||o);return o},R=(e,n)=>(r,t)=>n(r,t,e);let M=class extends s.Disposable{constructor(e,n,r,t,o,c){super(),this._commandSrv=e,this._uiPartsSrv=n,this._menuManagerService=r,this._componentManager=t,this._actionRecorderService=o,this._injector=c,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[k,W,V,F,q,j,w,$].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(d.BuiltInUIPart.GLOBAL,()=>d.connectInjector(de,this._injector)),this._componentManager.register("RecordSingle",U),this._menuManagerService.mergeMenu(fe)}_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(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};M=he([R(0,s.ICommandService),R(1,d.IUIPartsService),R(2,d.IMenuManagerService),R(3,s.Inject(d.ComponentManager)),R(4,s.Inject(exports.ActionRecorderService)),R(5,s.Inject(s.Injector))],M);const Ce="action-recorder.config",D={};var ye=Object.getOwnPropertyDescriptor,Re=(e,n,r,t)=>{for(var o=t>1?void 0:t?ye(n,r):n,c=e.length-1,i;c>=0;c--)(i=e[c])&&(o=i(o)||o);return o},E=(e,n)=>(r,t)=>n(r,t,e),T;exports.UniverActionRecorderPlugin=(T=class extends s.Plugin{constructor(n=D,r,t){super(),this._config=n,this._injector=r,this._configService=t;const{menu:o,...c}=s.merge({},D,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ce,c)}onStarting(){(this._config.replayOnly?[[exports.ActionReplayService]]:[[exports.ActionRecorderService],[exports.ActionReplayService],[M]]).forEach(r=>this._injector.add(r))}onSteady(){this._config.replayOnly||this._injector.get(M)}},v(T,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),T);exports.UniverActionRecorderPlugin=Re([E(1,s.Inject(s.Injector)),E(2,s.IConfigService)],exports.UniverActionRecorderPlugin);
|
|
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 S=(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 g=function(){return g=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},g.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 i=0,t=Object.getOwnPropertySymbols(e);i<t.length;i++)n.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(e,t[i])&&(r[t[i]]=e[t[i]]);return r},E=h.forwardRef(function(e,n){var r=e.icon,t=e.id,i=e.className,o=e.extend,c=J(e,["icon","id","className","extend"]),m="univerjs-icon univerjs-icon-".concat(t," ").concat(i||"").trim(),u=h.useRef("_".concat(K()));return L(r,"".concat(t),{defIds:r.defIds,idSuffix:u.current},g({ref:n,className:m},c),o)});function L(e,n,r,t,i){return h.createElement(e.tag,g(g({key:n},G(e,r,i)),t),(Z(e,r).children||[]).map(function(o,c){return L(o,"".concat(n,"-").concat(e.tag,"-").concat(c),r,void 0,i)}))}function G(e,n,r){var t=g({},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(o){var c=o[0],m=o[1];c==="mask"&&typeof m=="string"&&(t[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});var i=n.defIds;return!i||i.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(o){var c=o[0],m=o[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)?g(g({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&t&&t.indexOf(i.attrs.id)>-1?g(g({},i),{attrs:g(g({},i.attrs),{id:i.attrs.id+n.idSuffix})}):i})}):e}function K(){return Math.random().toString(36).substring(2,8)}E.displayName="UniverIcon";var Y={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-single_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-single_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"#fff",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-single_clip0_1559_19"]},T=h.forwardRef(function(e,n){return h.createElement(E,Object.assign({},e,{id:"record-single",ref:n,icon:Y}))});T.displayName="RecordSingle";var Q=Object.getOwnPropertyDescriptor,X=(e,n,r,t)=>{for(var i=t>1?void 0:t?Q(n,r):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},A=(e,n)=>(r,t)=>n(r,t,e);exports.ActionRecorderService=class extends s.Disposable{constructor(r,t,i,o){super();S(this,"_shouldRecordCommands",new Set);S(this,"_panelOpened$",new O.BehaviorSubject(!1));S(this,"panelOpened$",this._panelOpened$.asObservable());S(this,"_recorder",null);S(this,"_recording$",new O.BehaviorSubject(!1));S(this,"recording$",this._recording$.asObservable());S(this,"_recorded$",new O.BehaviorSubject([]));S(this,"_recordedCommands$",new O.BehaviorSubject([]));S(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=r,this._logService=t,this._localFileService=i,this._instanceService=o}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 i,o;if(this._shouldRecordCommands.has(t.id)){const c=this._recorded,m=this._recordedCommands;let u={...t};const y=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:p=y,subUnitId:v}=u==null?void 0:u.params;if(r&&p&&v){const x=(o=this._instanceService.getUnit(p).getSheetBySheetId(v))==null?void 0:o.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 i=t>1?void 0:t?ee(n,r):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},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,i,o){super(),this._messageService=n,this._instanceService=r,this._localFileService=t,this._logService=i,this._commandService=o}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 o,c,m;const t=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId();t||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:i}=r||{};for(const u of n){const{id:y,params:p}=u,v=p;if(v){if(typeof v.unitId<"u"&&(v.unitId=t),i==="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(i==="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 i of n){await s.awaitTime(te());const{id:o,params:c}=i;if(c){if(typeof c.unitId<"u"&&(c.unitId=r),!await this._commandService.executeCommand(o,c))return!1}else if(!await this._commandService.executeCommand(o))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(ie,{}):null}function ie(){var p;const e=d.useDependency(s.ICommandService),n=d.useDependency(exports.ActionRecorderService),r=d.useObservable(n.recording$),t=d.useObservable(n.recordedCommands$),i=(p=t==null?void 0:t.length)!=null?p:0,o=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?i===0?"Recording...":`${i}: ${t[i-1].id}`:"Start Recording";return f.jsxs("div",{className:`
|
|
2
|
+
univer-fixed univer-bottom-20 univer-left-1/2 univer-z-[1000] univer-flex univer-h-16 univer-w-[512px]
|
|
3
|
+
-univer-translate-x-1/2 univer-items-center univer-rounded-lg univer-bg-white univer-px-5 univer-shadow-lg
|
|
4
|
+
`,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-[13px]",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:o,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 oe(){return{id:q,type:d.MenuItemType.SUBITEMS,icon:"RecordSingle",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:10,menuItemFactory:oe,[$.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 i=t>1?void 0:t?me(n,r):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},_=(e,n)=>(r,t)=>n(r,t,e);let b=class extends s.Disposable{constructor(e,n,r,t,i,o){super(),this._commandSrv=e,this._uiPartsSrv=n,this._menuManagerService=r,this._componentManager=t,this._actionRecorderService=i,this._injector=o,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._componentManager.register("RecordSingle",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 ge=Object.getOwnPropertyDescriptor,Se=(e,n,r,t)=>{for(var i=t>1?void 0:t?ge(n,r):n,o=e.length-1,c;o>=0;o--)(c=e[o])&&(i=c(i)||i);return i},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:i,...o}=s.merge({},F,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(ve,o)}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)}},S(w,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),w);exports.UniverActionRecorderPlugin=Se([D(1,s.Inject(s.Injector)),D(2,s.IConfigService)],exports.UniverActionRecorderPlugin);
|