@univerjs/action-recorder 0.18.0 → 0.19.0

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,4 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/icons`),n=require(`@univerjs/sheets`),r=require(`@univerjs/sheets-filter`),i=require(`@univerjs/sheets-ui`),a=require(`@univerjs/ui`),o=require(`rxjs`),s=require(`@univerjs/design`),c=require(`react`),l=require(`react/jsx-runtime`);var u=`@univerjs/action-recorder`,d=`0.18.0`;const f=`action-recorder.config`;Symbol(f);const p={};function m(e){"@babel/helpers - typeof";return m=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},m(e)}function h(e,t){if(m(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(m(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function g(e){var t=h(e,`string`);return m(t)==`symbol`?t:t+``}function _(e,t,n){return(t=g(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=class extends e.Disposable{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,_(this,`_shouldRecordCommands`,new Set),_(this,`_panelOpened$`,new o.BehaviorSubject(!1)),_(this,`panelOpened$`,this._panelOpened$.asObservable()),_(this,`_recorder`,null),_(this,`_recording$`,new o.BehaviorSubject(!1)),_(this,`recording$`,this._recording$.asObservable()),_(this,`_recorded$`,new o.BehaviorSubject([])),_(this,`_recordedCommands$`,new o.BehaviorSubject([])),_(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(t){if(t.type===e.CommandType.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(t.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(t=!1){this._recorder=this._commandSrv.onCommandExecuted(r=>{if(this._shouldRecordCommands.has(r.id)){var i;let o=this._recorded,s=this._recordedCommands,c={...r},l=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:u=l,subUnitId:d}=c==null?void 0:c.params;if(t&&u&&d){var a;let e=(a=this._instanceService.getUnit(u).getSheetBySheetId(d))==null?void 0:a.getName();c={...c,params:{...c.params,subUnitId:e}}}c.id===n.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===n.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===e.CommandType.COMMAND&&(s.push(c),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(){let 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()}};b=y([v(0,e.ICommandService),v(1,e.ILogService),v(2,a.ILocalFileService),v(3,e.IUniverInstanceService)],b);const x={id:`action-recorder.command.start-recording`,type:e.CommandType.COMMAND,handler:(e,t)=>(e.get(b).startRecording(!!(t!=null&&t.replaceId)),!0)},S={id:`action-recorder.command.complete-recording`,type:e.CommandType.COMMAND,handler:e=>(e.get(b).completeRecording(),!0)},C={id:`action-recorder.command.stop-recording`,type:e.CommandType.COMMAND,handler:e=>(e.get(b).completeRecording(),!0)};let w=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),T=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=w.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:s.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===w.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===w.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let n of t){await(0,e.awaitTime)(E());let{id:t,params:i}=n;if(i){if(i.unitId!==void 0&&(i.unitId=r),!await this._commandService.executeCommand(t,i))return!1}else if(!await this._commandService.executeCommand(t))return!1}return!0}};T=y([v(0,a.IMessageService),v(1,e.IUniverInstanceService),v(2,a.ILocalFileService),v(3,e.ILogService),v(4,e.ICommandService)],T);function E(){return Math.floor(Math.random()*800)+200}const D={id:`action-recorder.command.replay-local-records`,type:e.CommandType.COMMAND,handler:async e=>{let t=await e.get(T).replayLocalJSON();return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},O={id:`action-recorder.command.replay-local-records-name`,type:e.CommandType.COMMAND,handler:async e=>{let t=await e.get(T).replayLocalJSON(w.NAME);return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},k={id:`action-recorder.command.replay-local-records-active`,type:e.CommandType.COMMAND,handler:async e=>{let t=await e.get(T).replayLocalJSON(w.ACTIVE);return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},A={id:`action-recorder.operation.open-panel`,type:e.CommandType.OPERATION,handler(e){return e.get(b).togglePanel(!0),!0}},j={id:`action-recorder.operation.close-panel`,type:e.CommandType.OPERATION,handler(e){return e.get(b).togglePanel(!1),!0}},M=`RECORD_MENU_ITEM`;function N(){return{id:M,type:a.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function P(e){let t=e.get(b);return{id:A.id,title:`action-recorder.menu.record`,type:a.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function F(){return{id:D.id,title:`action-recorder.menu.replay-local`,type:a.MenuItemType.BUTTON}}function I(){return{id:O.id,title:`action-recorder.menu.replay-local-name`,type:a.MenuItemType.BUTTON}}function L(){return{id:k.id,title:`action-recorder.menu.replay-local-active`,type:a.MenuItemType.BUTTON}}const R={[a.RibbonOthersGroup.OTHERS]:{[M]:{order:1,menuItemFactory:N,[A.id]:{order:1,menuItemFactory:P},[D.id]:{order:2,menuItemFactory:F},[O.id]:{order:3,menuItemFactory:I},[k.id]:{order:4,menuItemFactory:L}}}};function z(){return(0,a.useObservable)((0,a.useDependency)(b).panelOpened$)?(0,l.jsx)(B,{}):null}function B(){var n;let r=(0,a.useDependency)(e.ICommandService),i=(0,a.useDependency)(b),o=(0,a.useObservable)(i.recording$),u=(0,a.useObservable)(i.recordedCommands$),d=(n=u==null?void 0:u.length)==null?0:n,f=(0,c.useCallback)(()=>{o||r.executeCommand(j.id)},[r,o]),p=(0,c.useCallback)(e=>{o||r.executeCommand(x.id,{replaceId:e})},[r,o]),m=(0,c.useCallback)(()=>{o&&r.executeCommand(S.id)},[r,o]),h=(0,c.useCallback)(()=>{o&&r.executeCommand(C.id)},[r,o]),g=o?d===0?`Recording...`:`${d}: ${u[d-1].id}`:`Start Recording`;return(0,l.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:[(0,l.jsx)(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:(0,l.jsx)(t.RecordIcon,{})}),(0,l.jsx)(`div`,{className:`univer-flex-1 univer-text-sm`,children:g}),(0,l.jsxs)(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[(0,l.jsx)(s.Button,{className:`univer-w-20`,onClick:o?h:f,children:o?`Cancel`:`Close`}),(0,l.jsx)(s.Button,{className:`univer-w-20`,variant:`primary`,onClick:o?m:()=>p(),children:o?`Save`:`Start`}),!o&&(0,l.jsx)(s.Button,{variant:`primary`,onClick:()=>p(!0),children:`Start(N)`})]})]})}let V=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[x,C,S,A,j,D,O,k].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(a.BuiltInUIPart.GLOBAL,()=>(0,a.connectInjector)(z,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,t.RecordIcon)),this._menuManagerService.mergeMenu(R)}_initSheetsCommands(){[n.CopySheetCommand,n.DeleteRangeMoveLeftCommand,n.DeleteRangeMoveUpCommand,n.DeltaColumnWidthCommand,n.DeltaRowHeightCommand,n.InsertSheetCommand,n.InsertColAfterCommand,n.InsertColBeforeCommand,n.InsertRowAfterCommand,n.InsertRowBeforeCommand,n.RemoveSheetCommand,n.SetStyleCommand,n.AddWorksheetMergeCommand,n.AddWorksheetMergeAllCommand,n.AddWorksheetMergeVerticalCommand,n.AddWorksheetMergeHorizontalCommand,n.SetFrozenCommand,n.CancelFrozenCommand,n.SetHorizontalTextAlignCommand,n.SetOverlineCommand,i.SetRangeBoldCommand,i.SetRangeFontFamilyCommand,i.SetRangeFontSizeCommand,i.SetRangeItalicCommand,i.SetRangeStrickThroughCommand,i.SetRangeSubscriptCommand,i.SetRangeSuperscriptCommand,i.SetRangeTextColorCommand,i.SetRangeUnderlineCommand,n.SetRangeValuesCommand,n.SetStrikeThroughCommand,n.SetTextColorCommand,n.SetTextRotationCommand,n.SetTextWrapCommand,n.SetVerticalTextAlignCommand,i.SheetCopyCommand,i.SheetCutCommand,i.SheetPasteBesidesBorderCommand,i.SheetPasteColWidthCommand,i.SheetPasteCommand,i.SheetPasteFormatCommand,i.SheetPasteShortKeyCommand,i.SheetPasteValueCommand,n.AutoFillCommand,n.RefillCommand,n.SetWorksheetActivateCommand,n.SetWorksheetActiveOperation,n.SetSelectionsOperation,r.SetSheetFilterRangeCommand,r.SetSheetsFilterCriteriaCommand,r.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};V=y([v(0,e.ICommandService),v(1,a.IUIPartsService),v(2,a.IMenuManagerService),v(3,(0,e.Inject)(a.ComponentManager)),v(4,(0,e.Inject)(b)),v(5,(0,e.Inject)(e.Injector))],V);let H=class extends e.Plugin{constructor(t=p,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},p,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(f,a)}onStarting(){(this._config.replayOnly?[[T]]:[[b],[T],[V]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(V)}};_(H,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),_(H,`packageName`,u),_(H,`version`,d),H=y([v(1,(0,e.Inject)(e.Injector)),v(2,e.IConfigService)],H),Object.defineProperty(exports,`ActionRecorderService`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`ActionReplayService`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`UniverActionRecorderPlugin`,{enumerable:!0,get:function(){return H}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/icons`),n=require(`@univerjs/sheets`),r=require(`@univerjs/sheets-filter`),i=require(`@univerjs/sheets-ui`),a=require(`@univerjs/ui`),o=require(`rxjs`),s=require(`@univerjs/design`),c=require(`react`),l=require(`react/jsx-runtime`);var u=`@univerjs/action-recorder`,d=`0.19.0`;const f=`action-recorder.config`;Symbol(f);const p={};function m(e){"@babel/helpers - typeof";return m=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},m(e)}function h(e,t){if(m(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(m(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function g(e){var t=h(e,`string`);return m(t)==`symbol`?t:t+``}function _(e,t,n){return(t=g(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function v(e,t){return function(n,r){t(n,r,e)}}function y(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let b=class extends e.Disposable{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,_(this,`_shouldRecordCommands`,new Set),_(this,`_panelOpened$`,new o.BehaviorSubject(!1)),_(this,`panelOpened$`,this._panelOpened$.asObservable()),_(this,`_recorder`,null),_(this,`_recording$`,new o.BehaviorSubject(!1)),_(this,`recording$`,this._recording$.asObservable()),_(this,`_recorded$`,new o.BehaviorSubject([])),_(this,`_recordedCommands$`,new o.BehaviorSubject([])),_(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(t){if(t.type===e.CommandType.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(t.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(t=!1){this._recorder=this._commandSrv.onCommandExecuted(r=>{if(this._shouldRecordCommands.has(r.id)){var i;let o=this._recorded,s=this._recordedCommands,c={...r},l=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:u=l,subUnitId:d}=c==null?void 0:c.params;if(t&&u&&d){var a;let e=(a=this._instanceService.getUnit(u).getSheetBySheetId(d))==null?void 0:a.getName();c={...c,params:{...c.params,subUnitId:e}}}c.id===n.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===n.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===e.CommandType.COMMAND&&(s.push(c),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(){let 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()}};b=y([v(0,e.ICommandService),v(1,e.ILogService),v(2,a.ILocalFileService),v(3,e.IUniverInstanceService)],b);const x={id:`action-recorder.command.start-recording`,type:e.CommandType.COMMAND,handler:(e,t)=>(e.get(b).startRecording(!!(t!=null&&t.replaceId)),!0)},S={id:`action-recorder.command.complete-recording`,type:e.CommandType.COMMAND,handler:e=>(e.get(b).completeRecording(),!0)},C={id:`action-recorder.command.stop-recording`,type:e.CommandType.COMMAND,handler:e=>(e.get(b).completeRecording(),!0)};let w=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),T=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=w.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:s.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===w.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===w.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let n of t){await(0,e.awaitTime)(E());let{id:t,params:i}=n;if(i){if(i.unitId!==void 0&&(i.unitId=r),!await this._commandService.executeCommand(t,i))return!1}else if(!await this._commandService.executeCommand(t))return!1}return!0}};T=y([v(0,a.IMessageService),v(1,e.IUniverInstanceService),v(2,a.ILocalFileService),v(3,e.ILogService),v(4,e.ICommandService)],T);function E(){return Math.floor(Math.random()*800)+200}const D={id:`action-recorder.command.replay-local-records`,type:e.CommandType.COMMAND,handler:async e=>{let t=await e.get(T).replayLocalJSON();return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},O={id:`action-recorder.command.replay-local-records-name`,type:e.CommandType.COMMAND,handler:async e=>{let t=await e.get(T).replayLocalJSON(w.NAME);return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},k={id:`action-recorder.command.replay-local-records-active`,type:e.CommandType.COMMAND,handler:async e=>{let t=await e.get(T).replayLocalJSON(w.ACTIVE);return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},A={id:`action-recorder.operation.open-panel`,type:e.CommandType.OPERATION,handler(e){return e.get(b).togglePanel(!0),!0}},j={id:`action-recorder.operation.close-panel`,type:e.CommandType.OPERATION,handler(e){return e.get(b).togglePanel(!1),!0}},M=`RECORD_MENU_ITEM`;function N(){return{id:M,type:a.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function P(e){let t=e.get(b);return{id:A.id,title:`action-recorder.menu.record`,type:a.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function F(){return{id:D.id,title:`action-recorder.menu.replay-local`,type:a.MenuItemType.BUTTON}}function I(){return{id:O.id,title:`action-recorder.menu.replay-local-name`,type:a.MenuItemType.BUTTON}}function L(){return{id:k.id,title:`action-recorder.menu.replay-local-active`,type:a.MenuItemType.BUTTON}}const R={[a.RibbonOthersGroup.OTHERS]:{[M]:{order:1,menuItemFactory:N,[A.id]:{order:1,menuItemFactory:P},[D.id]:{order:2,menuItemFactory:F},[O.id]:{order:3,menuItemFactory:I},[k.id]:{order:4,menuItemFactory:L}}}};function z(){return(0,a.useObservable)((0,a.useDependency)(b).panelOpened$)?(0,l.jsx)(B,{}):null}function B(){var n;let r=(0,a.useDependency)(e.ICommandService),i=(0,a.useDependency)(b),o=(0,a.useObservable)(i.recording$),u=(0,a.useObservable)(i.recordedCommands$),d=(n=u==null?void 0:u.length)==null?0:n,f=(0,c.useCallback)(()=>{o||r.executeCommand(j.id)},[r,o]),p=(0,c.useCallback)(e=>{o||r.executeCommand(x.id,{replaceId:e})},[r,o]),m=(0,c.useCallback)(()=>{o&&r.executeCommand(S.id)},[r,o]),h=(0,c.useCallback)(()=>{o&&r.executeCommand(C.id)},[r,o]),g=o?d===0?`Recording...`:`${d}: ${u[d-1].id}`:`Start Recording`;return(0,l.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:[(0,l.jsx)(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:(0,l.jsx)(t.RecordIcon,{})}),(0,l.jsx)(`div`,{className:`univer-flex-1 univer-text-sm`,children:g}),(0,l.jsxs)(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[(0,l.jsx)(s.Button,{className:`univer-w-20`,onClick:o?h:f,children:o?`Cancel`:`Close`}),(0,l.jsx)(s.Button,{className:`univer-w-20`,variant:`primary`,onClick:o?m:()=>p(),children:o?`Save`:`Start`}),!o&&(0,l.jsx)(s.Button,{variant:`primary`,onClick:()=>p(!0),children:`Start(N)`})]})]})}let V=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[x,C,S,A,j,D,O,k].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(a.BuiltInUIPart.GLOBAL,()=>(0,a.connectInjector)(z,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,t.RecordIcon)),this._menuManagerService.mergeMenu(R)}_initSheetsCommands(){[n.CopySheetCommand,n.DeleteRangeMoveLeftCommand,n.DeleteRangeMoveUpCommand,n.DeltaColumnWidthCommand,n.DeltaRowHeightCommand,n.InsertSheetCommand,n.InsertColAfterCommand,n.InsertColBeforeCommand,n.InsertRowAfterCommand,n.InsertRowBeforeCommand,n.RemoveSheetCommand,n.SetStyleCommand,n.AddWorksheetMergeCommand,n.AddWorksheetMergeAllCommand,n.AddWorksheetMergeVerticalCommand,n.AddWorksheetMergeHorizontalCommand,n.SetFrozenCommand,n.CancelFrozenCommand,n.SetHorizontalTextAlignCommand,n.SetOverlineCommand,i.SetRangeBoldCommand,i.SetRangeFontFamilyCommand,i.SetRangeFontSizeCommand,i.SetRangeItalicCommand,i.SetRangeStrickThroughCommand,i.SetRangeSubscriptCommand,i.SetRangeSuperscriptCommand,i.SetRangeTextColorCommand,i.SetRangeUnderlineCommand,n.SetRangeValuesCommand,n.SetStrikeThroughCommand,n.SetTextColorCommand,n.SetTextRotationCommand,n.SetTextWrapCommand,n.SetVerticalTextAlignCommand,i.SheetCopyCommand,i.SheetCutCommand,i.SheetPasteBesidesBorderCommand,i.SheetPasteColWidthCommand,i.SheetPasteCommand,i.SheetPasteFormatCommand,i.SheetPasteShortKeyCommand,i.SheetPasteValueCommand,n.AutoFillCommand,n.RefillCommand,n.SetWorksheetActivateCommand,n.SetWorksheetActiveOperation,n.SetSelectionsOperation,r.SetSheetFilterRangeCommand,r.SetSheetsFilterCriteriaCommand,r.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};V=y([v(0,e.ICommandService),v(1,a.IUIPartsService),v(2,a.IMenuManagerService),v(3,(0,e.Inject)(a.ComponentManager)),v(4,(0,e.Inject)(b)),v(5,(0,e.Inject)(e.Injector))],V);let H=class extends e.Plugin{constructor(t=p,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},p,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(f,a)}onStarting(){(this._config.replayOnly?[[T]]:[[b],[T],[V]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(V)}};_(H,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),_(H,`packageName`,u),_(H,`version`,d),H=y([v(1,(0,e.Inject)(e.Injector)),v(2,e.IConfigService)],H),Object.defineProperty(exports,`ActionRecorderService`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`ActionReplayService`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`UniverActionRecorderPlugin`,{enumerable:!0,get:function(){return H}});
package/lib/es/index.js CHANGED
@@ -1,4 +1 @@
1
- import{CommandType as e,Disposable as t,ICommandService as n,IConfigService as r,ILogService as i,IUniverInstanceService as a,Inject as o,Injector as s,Plugin as c,awaitTime as l,merge as u}from"@univerjs/core";import{RecordIcon as d}from"@univerjs/icons";import{AddWorksheetMergeAllCommand as f,AddWorksheetMergeCommand as ee,AddWorksheetMergeHorizontalCommand as te,AddWorksheetMergeVerticalCommand as ne,AutoFillCommand as re,CancelFrozenCommand as p,CopySheetCommand as ie,DeleteRangeMoveLeftCommand as ae,DeleteRangeMoveUpCommand as oe,DeltaColumnWidthCommand as se,DeltaRowHeightCommand as ce,InsertColAfterCommand as le,InsertColBeforeCommand as ue,InsertRowAfterCommand as de,InsertRowBeforeCommand as fe,InsertSheetCommand as pe,RefillCommand as me,RemoveSheetCommand as he,SetFrozenCommand as ge,SetHorizontalTextAlignCommand as _e,SetOverlineCommand as ve,SetRangeValuesCommand as ye,SetSelectionsOperation as m,SetStrikeThroughCommand as be,SetStyleCommand as xe,SetTextColorCommand as Se,SetTextRotationCommand as Ce,SetTextWrapCommand as we,SetVerticalTextAlignCommand as Te,SetWorksheetActivateCommand as Ee,SetWorksheetActiveOperation as De}from"@univerjs/sheets";import{RemoveSheetFilterCommand as Oe,SetSheetFilterRangeCommand as ke,SetSheetsFilterCriteriaCommand as Ae}from"@univerjs/sheets-filter";import{SetRangeBoldCommand as je,SetRangeFontFamilyCommand as h,SetRangeFontSizeCommand as g,SetRangeItalicCommand as _,SetRangeStrickThroughCommand as v,SetRangeSubscriptCommand as y,SetRangeSuperscriptCommand as b,SetRangeTextColorCommand as x,SetRangeUnderlineCommand as S,SheetCopyCommand as Me,SheetCutCommand as Ne,SheetPasteBesidesBorderCommand as Pe,SheetPasteColWidthCommand as Fe,SheetPasteCommand as Ie,SheetPasteFormatCommand as Le,SheetPasteShortKeyCommand as Re,SheetPasteValueCommand as ze}from"@univerjs/sheets-ui";import{BuiltInUIPart as Be,ComponentManager as Ve,ILocalFileService as C,IMenuManagerService as He,IMessageService as w,IUIPartsService as Ue,MenuItemType as T,RibbonOthersGroup as We,connectInjector as Ge,useDependency as E,useObservable as D}from"@univerjs/ui";import{BehaviorSubject as O}from"rxjs";import{Button as k,MessageType as A}from"@univerjs/design";import{useCallback as j}from"react";import{jsx as M,jsxs as N}from"react/jsx-runtime";var Ke=`@univerjs/action-recorder`,qe=`0.18.0`;const P=`action-recorder.config`;Symbol(P);const F={};function I(e){"@babel/helpers - typeof";return I=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},I(e)}function Je(e,t){if(I(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(I(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ye(e){var t=Je(e,`string`);return I(t)==`symbol`?t:t+``}function L(e,t,n){return(t=Ye(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,L(this,`_shouldRecordCommands`,new Set),L(this,`_panelOpened$`,new O(!1)),L(this,`panelOpened$`,this._panelOpened$.asObservable()),L(this,`_recorder`,null),L(this,`_recording$`,new O(!1)),L(this,`recording$`,this._recording$.asObservable()),L(this,`_recorded$`,new O([])),L(this,`_recordedCommands$`,new O([])),L(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(t){if(t.type===e.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(t.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(t=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{if(this._shouldRecordCommands.has(n.id)){var r;let a=this._recorded,o=this._recordedCommands,s={...n},c=(r=this._instanceService.getFocusedUnit())==null?void 0:r.getUnitId(),{unitId:l=c,subUnitId:u}=s==null?void 0:s.params;if(t&&l&&u){var i;let e=(i=this._instanceService.getUnit(l).getSheetBySheetId(u))==null?void 0:i.getName();s={...s,params:{...s.params,subUnitId:e}}}s.id===m.id&&a.length>0&&a[a.length-1].id===m.id?a[a.length-1]=s:(a.push(s),this._recorded$.next(a),s.type===e.COMMAND&&(o.push(s),this._recordedCommands$.next(o)))}}),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(){let 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()}};B=z([R(0,n),R(1,i),R(2,C),R(3,a)],B);const V={id:`action-recorder.command.start-recording`,type:e.COMMAND,handler:(e,t)=>(e.get(B).startRecording(!!(t!=null&&t.replaceId)),!0)},H={id:`action-recorder.command.complete-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)},U={id:`action-recorder.command.stop-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)};let W=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),G=class extends t{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=W.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:A.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===W.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===W.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var t;let n=(t=this._instanceService.getFocusedUnit())==null?void 0:t.getUnitId();n||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let t of e){await l(Xe());let{id:e,params:r}=t;if(r){if(r.unitId!==void 0&&(r.unitId=n),!await this._commandService.executeCommand(e,r))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};G=z([R(0,w),R(1,a),R(2,C),R(3,i),R(4,n)],G);function Xe(){return Math.floor(Math.random()*800)+200}const K={id:`action-recorder.command.replay-local-records`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON();return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},q={id:`action-recorder.command.replay-local-records-name`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.NAME);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},J={id:`action-recorder.command.replay-local-records-active`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.ACTIVE);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},Y={id:`action-recorder.operation.open-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!0),!0}},X={id:`action-recorder.operation.close-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!1),!0}},Z=`RECORD_MENU_ITEM`;function Ze(){return{id:Z,type:T.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function Qe(e){let t=e.get(B);return{id:Y.id,title:`action-recorder.menu.record`,type:T.BUTTON,disabled$:t.panelOpened$}}function $e(){return{id:K.id,title:`action-recorder.menu.replay-local`,type:T.BUTTON}}function et(){return{id:q.id,title:`action-recorder.menu.replay-local-name`,type:T.BUTTON}}function tt(){return{id:J.id,title:`action-recorder.menu.replay-local-active`,type:T.BUTTON}}const nt={[We.OTHERS]:{[Z]:{order:1,menuItemFactory:Ze,[Y.id]:{order:1,menuItemFactory:Qe},[K.id]:{order:2,menuItemFactory:$e},[q.id]:{order:3,menuItemFactory:et},[J.id]:{order:4,menuItemFactory:tt}}}};function rt(){return D(E(B).panelOpened$)?M(it,{}):null}function it(){var e;let t=E(n),r=E(B),i=D(r.recording$),a=D(r.recordedCommands$),o=(e=a==null?void 0:a.length)==null?0:e,s=j(()=>{i||t.executeCommand(X.id)},[t,i]),c=j(e=>{i||t.executeCommand(V.id,{replaceId:e})},[t,i]),l=j(()=>{i&&t.executeCommand(H.id)},[t,i]),u=j(()=>{i&&t.executeCommand(U.id)},[t,i]),f=i?o===0?`Recording...`:`${o}: ${a[o-1].id}`:`Start Recording`;return N(`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:[M(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:M(d,{})}),M(`div`,{className:`univer-flex-1 univer-text-sm`,children:f}),N(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[M(k,{className:`univer-w-20`,onClick:i?u:s,children:i?`Cancel`:`Close`}),M(k,{className:`univer-w-20`,variant:`primary`,onClick:i?l:()=>c(),children:i?`Save`:`Start`}),!i&&M(k,{variant:`primary`,onClick:()=>c(!0),children:`Start(N)`})]})]})}let Q=class extends t{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[V,U,H,Y,X,K,q,J].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(Be.GLOBAL,()=>Ge(rt,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,d)),this._menuManagerService.mergeMenu(nt)}_initSheetsCommands(){[ie,ae,oe,se,ce,pe,le,ue,de,fe,he,xe,ee,f,ne,te,ge,p,_e,ve,je,h,g,_,v,y,b,x,S,ye,be,Se,Ce,we,Te,Me,Ne,Pe,Fe,Ie,Le,Re,ze,re,me,Ee,De,m,ke,Ae,Oe].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};Q=z([R(0,n),R(1,Ue),R(2,He),R(3,o(Ve)),R(4,o(B)),R(5,o(s))],Q);let $=class extends c{constructor(e=F,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=u({},F,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(P,i)}onStarting(){(this._config.replayOnly?[[G]]:[[B],[G],[Q]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(Q)}};L($,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),L($,`packageName`,Ke),L($,`version`,qe),$=z([R(1,o(s)),R(2,r)],$);export{B as ActionRecorderService,G as ActionReplayService,$ as UniverActionRecorderPlugin};
1
+ import{CommandType as e,Disposable as t,ICommandService as n,IConfigService as r,ILogService as i,IUniverInstanceService as a,Inject as o,Injector as s,Plugin as c,awaitTime as l,merge as u}from"@univerjs/core";import{RecordIcon as d}from"@univerjs/icons";import{AddWorksheetMergeAllCommand as f,AddWorksheetMergeCommand as ee,AddWorksheetMergeHorizontalCommand as te,AddWorksheetMergeVerticalCommand as ne,AutoFillCommand as re,CancelFrozenCommand as p,CopySheetCommand as ie,DeleteRangeMoveLeftCommand as ae,DeleteRangeMoveUpCommand as oe,DeltaColumnWidthCommand as se,DeltaRowHeightCommand as ce,InsertColAfterCommand as le,InsertColBeforeCommand as ue,InsertRowAfterCommand as de,InsertRowBeforeCommand as fe,InsertSheetCommand as pe,RefillCommand as me,RemoveSheetCommand as he,SetFrozenCommand as ge,SetHorizontalTextAlignCommand as _e,SetOverlineCommand as ve,SetRangeValuesCommand as ye,SetSelectionsOperation as m,SetStrikeThroughCommand as be,SetStyleCommand as xe,SetTextColorCommand as Se,SetTextRotationCommand as Ce,SetTextWrapCommand as we,SetVerticalTextAlignCommand as Te,SetWorksheetActivateCommand as Ee,SetWorksheetActiveOperation as De}from"@univerjs/sheets";import{RemoveSheetFilterCommand as Oe,SetSheetFilterRangeCommand as ke,SetSheetsFilterCriteriaCommand as Ae}from"@univerjs/sheets-filter";import{SetRangeBoldCommand as je,SetRangeFontFamilyCommand as h,SetRangeFontSizeCommand as g,SetRangeItalicCommand as _,SetRangeStrickThroughCommand as v,SetRangeSubscriptCommand as y,SetRangeSuperscriptCommand as b,SetRangeTextColorCommand as x,SetRangeUnderlineCommand as S,SheetCopyCommand as Me,SheetCutCommand as Ne,SheetPasteBesidesBorderCommand as Pe,SheetPasteColWidthCommand as Fe,SheetPasteCommand as Ie,SheetPasteFormatCommand as Le,SheetPasteShortKeyCommand as Re,SheetPasteValueCommand as ze}from"@univerjs/sheets-ui";import{BuiltInUIPart as Be,ComponentManager as Ve,ILocalFileService as C,IMenuManagerService as He,IMessageService as w,IUIPartsService as Ue,MenuItemType as T,RibbonOthersGroup as We,connectInjector as Ge,useDependency as E,useObservable as D}from"@univerjs/ui";import{BehaviorSubject as O}from"rxjs";import{Button as k,MessageType as A}from"@univerjs/design";import{useCallback as j}from"react";import{jsx as M,jsxs as N}from"react/jsx-runtime";var Ke=`@univerjs/action-recorder`,qe=`0.19.0`;const P=`action-recorder.config`;Symbol(P);const F={};function I(e){"@babel/helpers - typeof";return I=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},I(e)}function Je(e,t){if(I(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(I(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ye(e){var t=Je(e,`string`);return I(t)==`symbol`?t:t+``}function L(e,t,n){return(t=Ye(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,L(this,`_shouldRecordCommands`,new Set),L(this,`_panelOpened$`,new O(!1)),L(this,`panelOpened$`,this._panelOpened$.asObservable()),L(this,`_recorder`,null),L(this,`_recording$`,new O(!1)),L(this,`recording$`,this._recording$.asObservable()),L(this,`_recorded$`,new O([])),L(this,`_recordedCommands$`,new O([])),L(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(t){if(t.type===e.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(t.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(t=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{if(this._shouldRecordCommands.has(n.id)){var r;let a=this._recorded,o=this._recordedCommands,s={...n},c=(r=this._instanceService.getFocusedUnit())==null?void 0:r.getUnitId(),{unitId:l=c,subUnitId:u}=s==null?void 0:s.params;if(t&&l&&u){var i;let e=(i=this._instanceService.getUnit(l).getSheetBySheetId(u))==null?void 0:i.getName();s={...s,params:{...s.params,subUnitId:e}}}s.id===m.id&&a.length>0&&a[a.length-1].id===m.id?a[a.length-1]=s:(a.push(s),this._recorded$.next(a),s.type===e.COMMAND&&(o.push(s),this._recordedCommands$.next(o)))}}),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(){let 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()}};B=z([R(0,n),R(1,i),R(2,C),R(3,a)],B);const V={id:`action-recorder.command.start-recording`,type:e.COMMAND,handler:(e,t)=>(e.get(B).startRecording(!!(t!=null&&t.replaceId)),!0)},H={id:`action-recorder.command.complete-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)},U={id:`action-recorder.command.stop-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)};let W=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),G=class extends t{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=W.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:A.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===W.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===W.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var t;let n=(t=this._instanceService.getFocusedUnit())==null?void 0:t.getUnitId();n||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let t of e){await l(Xe());let{id:e,params:r}=t;if(r){if(r.unitId!==void 0&&(r.unitId=n),!await this._commandService.executeCommand(e,r))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};G=z([R(0,w),R(1,a),R(2,C),R(3,i),R(4,n)],G);function Xe(){return Math.floor(Math.random()*800)+200}const K={id:`action-recorder.command.replay-local-records`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON();return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},q={id:`action-recorder.command.replay-local-records-name`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.NAME);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},J={id:`action-recorder.command.replay-local-records-active`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.ACTIVE);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},Y={id:`action-recorder.operation.open-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!0),!0}},X={id:`action-recorder.operation.close-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!1),!0}},Z=`RECORD_MENU_ITEM`;function Ze(){return{id:Z,type:T.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function Qe(e){let t=e.get(B);return{id:Y.id,title:`action-recorder.menu.record`,type:T.BUTTON,disabled$:t.panelOpened$}}function $e(){return{id:K.id,title:`action-recorder.menu.replay-local`,type:T.BUTTON}}function et(){return{id:q.id,title:`action-recorder.menu.replay-local-name`,type:T.BUTTON}}function tt(){return{id:J.id,title:`action-recorder.menu.replay-local-active`,type:T.BUTTON}}const nt={[We.OTHERS]:{[Z]:{order:1,menuItemFactory:Ze,[Y.id]:{order:1,menuItemFactory:Qe},[K.id]:{order:2,menuItemFactory:$e},[q.id]:{order:3,menuItemFactory:et},[J.id]:{order:4,menuItemFactory:tt}}}};function rt(){return D(E(B).panelOpened$)?M(it,{}):null}function it(){var e;let t=E(n),r=E(B),i=D(r.recording$),a=D(r.recordedCommands$),o=(e=a==null?void 0:a.length)==null?0:e,s=j(()=>{i||t.executeCommand(X.id)},[t,i]),c=j(e=>{i||t.executeCommand(V.id,{replaceId:e})},[t,i]),l=j(()=>{i&&t.executeCommand(H.id)},[t,i]),u=j(()=>{i&&t.executeCommand(U.id)},[t,i]),f=i?o===0?`Recording...`:`${o}: ${a[o-1].id}`:`Start Recording`;return N(`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:[M(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:M(d,{})}),M(`div`,{className:`univer-flex-1 univer-text-sm`,children:f}),N(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[M(k,{className:`univer-w-20`,onClick:i?u:s,children:i?`Cancel`:`Close`}),M(k,{className:`univer-w-20`,variant:`primary`,onClick:i?l:()=>c(),children:i?`Save`:`Start`}),!i&&M(k,{variant:`primary`,onClick:()=>c(!0),children:`Start(N)`})]})]})}let Q=class extends t{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[V,U,H,Y,X,K,q,J].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(Be.GLOBAL,()=>Ge(rt,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,d)),this._menuManagerService.mergeMenu(nt)}_initSheetsCommands(){[ie,ae,oe,se,ce,pe,le,ue,de,fe,he,xe,ee,f,ne,te,ge,p,_e,ve,je,h,g,_,v,y,b,x,S,ye,be,Se,Ce,we,Te,Me,Ne,Pe,Fe,Ie,Le,Re,ze,re,me,Ee,De,m,ke,Ae,Oe].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};Q=z([R(0,n),R(1,Ue),R(2,He),R(3,o(Ve)),R(4,o(B)),R(5,o(s))],Q);let $=class extends c{constructor(e=F,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=u({},F,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(P,i)}onStarting(){(this._config.replayOnly?[[G]]:[[B],[G],[Q]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(Q)}};L($,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),L($,`packageName`,Ke),L($,`version`,qe),$=z([R(1,o(s)),R(2,r)],$);export{B as ActionRecorderService,G as ActionReplayService,$ as UniverActionRecorderPlugin};
package/lib/index.js CHANGED
@@ -1,4 +1 @@
1
- import{CommandType as e,Disposable as t,ICommandService as n,IConfigService as r,ILogService as i,IUniverInstanceService as a,Inject as o,Injector as s,Plugin as c,awaitTime as l,merge as u}from"@univerjs/core";import{RecordIcon as d}from"@univerjs/icons";import{AddWorksheetMergeAllCommand as f,AddWorksheetMergeCommand as ee,AddWorksheetMergeHorizontalCommand as te,AddWorksheetMergeVerticalCommand as ne,AutoFillCommand as re,CancelFrozenCommand as p,CopySheetCommand as ie,DeleteRangeMoveLeftCommand as ae,DeleteRangeMoveUpCommand as oe,DeltaColumnWidthCommand as se,DeltaRowHeightCommand as ce,InsertColAfterCommand as le,InsertColBeforeCommand as ue,InsertRowAfterCommand as de,InsertRowBeforeCommand as fe,InsertSheetCommand as pe,RefillCommand as me,RemoveSheetCommand as he,SetFrozenCommand as ge,SetHorizontalTextAlignCommand as _e,SetOverlineCommand as ve,SetRangeValuesCommand as ye,SetSelectionsOperation as m,SetStrikeThroughCommand as be,SetStyleCommand as xe,SetTextColorCommand as Se,SetTextRotationCommand as Ce,SetTextWrapCommand as we,SetVerticalTextAlignCommand as Te,SetWorksheetActivateCommand as Ee,SetWorksheetActiveOperation as De}from"@univerjs/sheets";import{RemoveSheetFilterCommand as Oe,SetSheetFilterRangeCommand as ke,SetSheetsFilterCriteriaCommand as Ae}from"@univerjs/sheets-filter";import{SetRangeBoldCommand as je,SetRangeFontFamilyCommand as h,SetRangeFontSizeCommand as g,SetRangeItalicCommand as _,SetRangeStrickThroughCommand as v,SetRangeSubscriptCommand as y,SetRangeSuperscriptCommand as b,SetRangeTextColorCommand as x,SetRangeUnderlineCommand as S,SheetCopyCommand as Me,SheetCutCommand as Ne,SheetPasteBesidesBorderCommand as Pe,SheetPasteColWidthCommand as Fe,SheetPasteCommand as Ie,SheetPasteFormatCommand as Le,SheetPasteShortKeyCommand as Re,SheetPasteValueCommand as ze}from"@univerjs/sheets-ui";import{BuiltInUIPart as Be,ComponentManager as Ve,ILocalFileService as C,IMenuManagerService as He,IMessageService as w,IUIPartsService as Ue,MenuItemType as T,RibbonOthersGroup as We,connectInjector as Ge,useDependency as E,useObservable as D}from"@univerjs/ui";import{BehaviorSubject as O}from"rxjs";import{Button as k,MessageType as A}from"@univerjs/design";import{useCallback as j}from"react";import{jsx as M,jsxs as N}from"react/jsx-runtime";var Ke=`@univerjs/action-recorder`,qe=`0.18.0`;const P=`action-recorder.config`;Symbol(P);const F={};function I(e){"@babel/helpers - typeof";return I=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},I(e)}function Je(e,t){if(I(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(I(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ye(e){var t=Je(e,`string`);return I(t)==`symbol`?t:t+``}function L(e,t,n){return(t=Ye(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,L(this,`_shouldRecordCommands`,new Set),L(this,`_panelOpened$`,new O(!1)),L(this,`panelOpened$`,this._panelOpened$.asObservable()),L(this,`_recorder`,null),L(this,`_recording$`,new O(!1)),L(this,`recording$`,this._recording$.asObservable()),L(this,`_recorded$`,new O([])),L(this,`_recordedCommands$`,new O([])),L(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(t){if(t.type===e.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(t.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(t=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{if(this._shouldRecordCommands.has(n.id)){var r;let a=this._recorded,o=this._recordedCommands,s={...n},c=(r=this._instanceService.getFocusedUnit())==null?void 0:r.getUnitId(),{unitId:l=c,subUnitId:u}=s==null?void 0:s.params;if(t&&l&&u){var i;let e=(i=this._instanceService.getUnit(l).getSheetBySheetId(u))==null?void 0:i.getName();s={...s,params:{...s.params,subUnitId:e}}}s.id===m.id&&a.length>0&&a[a.length-1].id===m.id?a[a.length-1]=s:(a.push(s),this._recorded$.next(a),s.type===e.COMMAND&&(o.push(s),this._recordedCommands$.next(o)))}}),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(){let 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()}};B=z([R(0,n),R(1,i),R(2,C),R(3,a)],B);const V={id:`action-recorder.command.start-recording`,type:e.COMMAND,handler:(e,t)=>(e.get(B).startRecording(!!(t!=null&&t.replaceId)),!0)},H={id:`action-recorder.command.complete-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)},U={id:`action-recorder.command.stop-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)};let W=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),G=class extends t{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=W.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:A.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===W.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===W.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var t;let n=(t=this._instanceService.getFocusedUnit())==null?void 0:t.getUnitId();n||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let t of e){await l(Xe());let{id:e,params:r}=t;if(r){if(r.unitId!==void 0&&(r.unitId=n),!await this._commandService.executeCommand(e,r))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};G=z([R(0,w),R(1,a),R(2,C),R(3,i),R(4,n)],G);function Xe(){return Math.floor(Math.random()*800)+200}const K={id:`action-recorder.command.replay-local-records`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON();return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},q={id:`action-recorder.command.replay-local-records-name`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.NAME);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},J={id:`action-recorder.command.replay-local-records-active`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.ACTIVE);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},Y={id:`action-recorder.operation.open-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!0),!0}},X={id:`action-recorder.operation.close-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!1),!0}},Z=`RECORD_MENU_ITEM`;function Ze(){return{id:Z,type:T.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function Qe(e){let t=e.get(B);return{id:Y.id,title:`action-recorder.menu.record`,type:T.BUTTON,disabled$:t.panelOpened$}}function $e(){return{id:K.id,title:`action-recorder.menu.replay-local`,type:T.BUTTON}}function et(){return{id:q.id,title:`action-recorder.menu.replay-local-name`,type:T.BUTTON}}function tt(){return{id:J.id,title:`action-recorder.menu.replay-local-active`,type:T.BUTTON}}const nt={[We.OTHERS]:{[Z]:{order:1,menuItemFactory:Ze,[Y.id]:{order:1,menuItemFactory:Qe},[K.id]:{order:2,menuItemFactory:$e},[q.id]:{order:3,menuItemFactory:et},[J.id]:{order:4,menuItemFactory:tt}}}};function rt(){return D(E(B).panelOpened$)?M(it,{}):null}function it(){var e;let t=E(n),r=E(B),i=D(r.recording$),a=D(r.recordedCommands$),o=(e=a==null?void 0:a.length)==null?0:e,s=j(()=>{i||t.executeCommand(X.id)},[t,i]),c=j(e=>{i||t.executeCommand(V.id,{replaceId:e})},[t,i]),l=j(()=>{i&&t.executeCommand(H.id)},[t,i]),u=j(()=>{i&&t.executeCommand(U.id)},[t,i]),f=i?o===0?`Recording...`:`${o}: ${a[o-1].id}`:`Start Recording`;return N(`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:[M(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:M(d,{})}),M(`div`,{className:`univer-flex-1 univer-text-sm`,children:f}),N(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[M(k,{className:`univer-w-20`,onClick:i?u:s,children:i?`Cancel`:`Close`}),M(k,{className:`univer-w-20`,variant:`primary`,onClick:i?l:()=>c(),children:i?`Save`:`Start`}),!i&&M(k,{variant:`primary`,onClick:()=>c(!0),children:`Start(N)`})]})]})}let Q=class extends t{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[V,U,H,Y,X,K,q,J].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(Be.GLOBAL,()=>Ge(rt,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,d)),this._menuManagerService.mergeMenu(nt)}_initSheetsCommands(){[ie,ae,oe,se,ce,pe,le,ue,de,fe,he,xe,ee,f,ne,te,ge,p,_e,ve,je,h,g,_,v,y,b,x,S,ye,be,Se,Ce,we,Te,Me,Ne,Pe,Fe,Ie,Le,Re,ze,re,me,Ee,De,m,ke,Ae,Oe].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};Q=z([R(0,n),R(1,Ue),R(2,He),R(3,o(Ve)),R(4,o(B)),R(5,o(s))],Q);let $=class extends c{constructor(e=F,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=u({},F,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(P,i)}onStarting(){(this._config.replayOnly?[[G]]:[[B],[G],[Q]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(Q)}};L($,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),L($,`packageName`,Ke),L($,`version`,qe),$=z([R(1,o(s)),R(2,r)],$);export{B as ActionRecorderService,G as ActionReplayService,$ as UniverActionRecorderPlugin};
1
+ import{CommandType as e,Disposable as t,ICommandService as n,IConfigService as r,ILogService as i,IUniverInstanceService as a,Inject as o,Injector as s,Plugin as c,awaitTime as l,merge as u}from"@univerjs/core";import{RecordIcon as d}from"@univerjs/icons";import{AddWorksheetMergeAllCommand as f,AddWorksheetMergeCommand as ee,AddWorksheetMergeHorizontalCommand as te,AddWorksheetMergeVerticalCommand as ne,AutoFillCommand as re,CancelFrozenCommand as p,CopySheetCommand as ie,DeleteRangeMoveLeftCommand as ae,DeleteRangeMoveUpCommand as oe,DeltaColumnWidthCommand as se,DeltaRowHeightCommand as ce,InsertColAfterCommand as le,InsertColBeforeCommand as ue,InsertRowAfterCommand as de,InsertRowBeforeCommand as fe,InsertSheetCommand as pe,RefillCommand as me,RemoveSheetCommand as he,SetFrozenCommand as ge,SetHorizontalTextAlignCommand as _e,SetOverlineCommand as ve,SetRangeValuesCommand as ye,SetSelectionsOperation as m,SetStrikeThroughCommand as be,SetStyleCommand as xe,SetTextColorCommand as Se,SetTextRotationCommand as Ce,SetTextWrapCommand as we,SetVerticalTextAlignCommand as Te,SetWorksheetActivateCommand as Ee,SetWorksheetActiveOperation as De}from"@univerjs/sheets";import{RemoveSheetFilterCommand as Oe,SetSheetFilterRangeCommand as ke,SetSheetsFilterCriteriaCommand as Ae}from"@univerjs/sheets-filter";import{SetRangeBoldCommand as je,SetRangeFontFamilyCommand as h,SetRangeFontSizeCommand as g,SetRangeItalicCommand as _,SetRangeStrickThroughCommand as v,SetRangeSubscriptCommand as y,SetRangeSuperscriptCommand as b,SetRangeTextColorCommand as x,SetRangeUnderlineCommand as S,SheetCopyCommand as Me,SheetCutCommand as Ne,SheetPasteBesidesBorderCommand as Pe,SheetPasteColWidthCommand as Fe,SheetPasteCommand as Ie,SheetPasteFormatCommand as Le,SheetPasteShortKeyCommand as Re,SheetPasteValueCommand as ze}from"@univerjs/sheets-ui";import{BuiltInUIPart as Be,ComponentManager as Ve,ILocalFileService as C,IMenuManagerService as He,IMessageService as w,IUIPartsService as Ue,MenuItemType as T,RibbonOthersGroup as We,connectInjector as Ge,useDependency as E,useObservable as D}from"@univerjs/ui";import{BehaviorSubject as O}from"rxjs";import{Button as k,MessageType as A}from"@univerjs/design";import{useCallback as j}from"react";import{jsx as M,jsxs as N}from"react/jsx-runtime";var Ke=`@univerjs/action-recorder`,qe=`0.19.0`;const P=`action-recorder.config`;Symbol(P);const F={};function I(e){"@babel/helpers - typeof";return I=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},I(e)}function Je(e,t){if(I(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(I(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ye(e){var t=Je(e,`string`);return I(t)==`symbol`?t:t+``}function L(e,t,n){return(t=Ye(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e,t){return function(n,r){t(n,r,e)}}function z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let B=class extends t{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,L(this,`_shouldRecordCommands`,new Set),L(this,`_panelOpened$`,new O(!1)),L(this,`panelOpened$`,this._panelOpened$.asObservable()),L(this,`_recorder`,null),L(this,`_recording$`,new O(!1)),L(this,`recording$`,this._recording$.asObservable()),L(this,`_recorded$`,new O([])),L(this,`_recordedCommands$`,new O([])),L(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(t){if(t.type===e.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(t.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(t=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{if(this._shouldRecordCommands.has(n.id)){var r;let a=this._recorded,o=this._recordedCommands,s={...n},c=(r=this._instanceService.getFocusedUnit())==null?void 0:r.getUnitId(),{unitId:l=c,subUnitId:u}=s==null?void 0:s.params;if(t&&l&&u){var i;let e=(i=this._instanceService.getUnit(l).getSheetBySheetId(u))==null?void 0:i.getName();s={...s,params:{...s.params,subUnitId:e}}}s.id===m.id&&a.length>0&&a[a.length-1].id===m.id?a[a.length-1]=s:(a.push(s),this._recorded$.next(a),s.type===e.COMMAND&&(o.push(s),this._recordedCommands$.next(o)))}}),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(){let 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()}};B=z([R(0,n),R(1,i),R(2,C),R(3,a)],B);const V={id:`action-recorder.command.start-recording`,type:e.COMMAND,handler:(e,t)=>(e.get(B).startRecording(!!(t!=null&&t.replaceId)),!0)},H={id:`action-recorder.command.complete-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)},U={id:`action-recorder.command.stop-recording`,type:e.COMMAND,handler:e=>(e.get(B).completeRecording(),!0)};let W=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),G=class extends t{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=W.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:A.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===W.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===W.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var t;let n=(t=this._instanceService.getFocusedUnit())==null?void 0:t.getUnitId();n||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let t of e){await l(Xe());let{id:e,params:r}=t;if(r){if(r.unitId!==void 0&&(r.unitId=n),!await this._commandService.executeCommand(e,r))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};G=z([R(0,w),R(1,a),R(2,C),R(3,i),R(4,n)],G);function Xe(){return Math.floor(Math.random()*800)+200}const K={id:`action-recorder.command.replay-local-records`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON();return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},q={id:`action-recorder.command.replay-local-records-name`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.NAME);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},J={id:`action-recorder.command.replay-local-records-active`,type:e.COMMAND,handler:async e=>{let t=await e.get(G).replayLocalJSON(W.ACTIVE);return t&&e.get(w).show({type:A.Success,content:`Successfully replayed local records`}),t}},Y={id:`action-recorder.operation.open-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!0),!0}},X={id:`action-recorder.operation.close-panel`,type:e.OPERATION,handler(e){return e.get(B).togglePanel(!1),!0}},Z=`RECORD_MENU_ITEM`;function Ze(){return{id:Z,type:T.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function Qe(e){let t=e.get(B);return{id:Y.id,title:`action-recorder.menu.record`,type:T.BUTTON,disabled$:t.panelOpened$}}function $e(){return{id:K.id,title:`action-recorder.menu.replay-local`,type:T.BUTTON}}function et(){return{id:q.id,title:`action-recorder.menu.replay-local-name`,type:T.BUTTON}}function tt(){return{id:J.id,title:`action-recorder.menu.replay-local-active`,type:T.BUTTON}}const nt={[We.OTHERS]:{[Z]:{order:1,menuItemFactory:Ze,[Y.id]:{order:1,menuItemFactory:Qe},[K.id]:{order:2,menuItemFactory:$e},[q.id]:{order:3,menuItemFactory:et},[J.id]:{order:4,menuItemFactory:tt}}}};function rt(){return D(E(B).panelOpened$)?M(it,{}):null}function it(){var e;let t=E(n),r=E(B),i=D(r.recording$),a=D(r.recordedCommands$),o=(e=a==null?void 0:a.length)==null?0:e,s=j(()=>{i||t.executeCommand(X.id)},[t,i]),c=j(e=>{i||t.executeCommand(V.id,{replaceId:e})},[t,i]),l=j(()=>{i&&t.executeCommand(H.id)},[t,i]),u=j(()=>{i&&t.executeCommand(U.id)},[t,i]),f=i?o===0?`Recording...`:`${o}: ${a[o-1].id}`:`Start Recording`;return N(`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:[M(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:M(d,{})}),M(`div`,{className:`univer-flex-1 univer-text-sm`,children:f}),N(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[M(k,{className:`univer-w-20`,onClick:i?u:s,children:i?`Cancel`:`Close`}),M(k,{className:`univer-w-20`,variant:`primary`,onClick:i?l:()=>c(),children:i?`Save`:`Start`}),!i&&M(k,{variant:`primary`,onClick:()=>c(!0),children:`Start(N)`})]})]})}let Q=class extends t{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[V,U,H,Y,X,K,q,J].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(Be.GLOBAL,()=>Ge(rt,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,d)),this._menuManagerService.mergeMenu(nt)}_initSheetsCommands(){[ie,ae,oe,se,ce,pe,le,ue,de,fe,he,xe,ee,f,ne,te,ge,p,_e,ve,je,h,g,_,v,y,b,x,S,ye,be,Se,Ce,we,Te,Me,Ne,Pe,Fe,Ie,Le,Re,ze,re,me,Ee,De,m,ke,Ae,Oe].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};Q=z([R(0,n),R(1,Ue),R(2,He),R(3,o(Ve)),R(4,o(B)),R(5,o(s))],Q);let $=class extends c{constructor(e=F,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=u({},F,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(P,i)}onStarting(){(this._config.replayOnly?[[G]]:[[B],[G],[Q]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(Q)}};L($,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),L($,`packageName`,Ke),L($,`version`,qe),$=z([R(1,o(s)),R(2,r)],$);export{B as ActionRecorderService,G as ActionReplayService,$ as UniverActionRecorderPlugin};
package/lib/umd/index.js CHANGED
@@ -1,4 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`react`),require(`@univerjs/sheets`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets-ui`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`react`,`@univerjs/sheets`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverActionRecorder={},e.UniverCore,e.React,e.UniverSheets,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.rxjs,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=`@univerjs/action-recorder`,d=`0.18.0`;let f=`action-recorder.config`;Symbol(f);let p={};function m({ref:e,...t}){let{icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=(0,n.useRef)(`_${v()}`);return h(r,`${i}`,{defIds:r.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function h(e,t,r,i,a){return(0,n.createElement)(e.tag,{key:t,...g(e,r,a),...i},(_(e,r).children||[]).map((n,i)=>h(n,`${t}-${e.tag}-${i}`,r,void 0,a)))}function g(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function _(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function v(){return Math.random().toString(36).substring(2,8)}m.displayName=`UniverIcon`;let 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`]},b=(0,n.forwardRef)(function(e,t){return(0,n.createElement)(m,Object.assign({},e,{id:`record-icon`,ref:t,icon:y}))});b.displayName=`RecordIcon`;function x(e){"@babel/helpers - typeof";return x=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},x(e)}function S(e,t){if(x(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(x(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function C(e){var t=S(e,`string`);return x(t)==`symbol`?t:t+``}function w(e,t,n){return(t=C(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function T(e,t){return function(n,r){t(n,r,e)}}function E(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let D=class extends t.Disposable{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,w(this,`_shouldRecordCommands`,new Set),w(this,`_panelOpened$`,new s.BehaviorSubject(!1)),w(this,`panelOpened$`,this._panelOpened$.asObservable()),w(this,`_recorder`,null),w(this,`_recording$`,new s.BehaviorSubject(!1)),w(this,`recording$`,this._recording$.asObservable()),w(this,`_recorded$`,new s.BehaviorSubject([])),w(this,`_recordedCommands$`,new s.BehaviorSubject([])),w(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(e){if(e.type===t.CommandType.MUTATION)throw 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=>{if(this._shouldRecordCommands.has(n.id)){var i;let o=this._recorded,s=this._recordedCommands,c={...n},l=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:u=l,subUnitId:d}=c==null?void 0:c.params;if(e&&u&&d){var a;let e=(a=this._instanceService.getUnit(u).getSheetBySheetId(d))==null?void 0:a.getName();c={...c,params:{...c.params,subUnitId:e}}}c.id===r.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===r.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===t.CommandType.COMMAND&&(s.push(c),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(){let 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()}};D=E([T(0,t.ICommandService),T(1,t.ILogService),T(2,o.ILocalFileService),T(3,t.IUniverInstanceService)],D);let O={id:`action-recorder.command.start-recording`,type:t.CommandType.COMMAND,handler:(e,t)=>(e.get(D).startRecording(!!(t!=null&&t.replaceId)),!0)},k={id:`action-recorder.command.complete-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},A={id:`action-recorder.command.stop-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},j=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),M=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=j.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:c.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===j.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===j.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let n of e){await(0,t.awaitTime)(N());let{id:e,params:i}=n;if(i){if(i.unitId!==void 0&&(i.unitId=r),!await this._commandService.executeCommand(e,i))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};M=E([T(0,o.IMessageService),T(1,t.IUniverInstanceService),T(2,o.ILocalFileService),T(3,t.ILogService),T(4,t.ICommandService)],M);function N(){return Math.floor(Math.random()*800)+200}let P={id:`action-recorder.command.replay-local-records`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON();return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},F={id:`action-recorder.command.replay-local-records-name`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON(j.NAME);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},I={id:`action-recorder.command.replay-local-records-active`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON(j.ACTIVE);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},L={id:`action-recorder.operation.open-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!0),!0}},R={id:`action-recorder.operation.close-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!1),!0}},z=`RECORD_MENU_ITEM`;function B(){return{id:z,type:o.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function V(e){let t=e.get(D);return{id:L.id,title:`action-recorder.menu.record`,type:o.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function H(){return{id:P.id,title:`action-recorder.menu.replay-local`,type:o.MenuItemType.BUTTON}}function U(){return{id:F.id,title:`action-recorder.menu.replay-local-name`,type:o.MenuItemType.BUTTON}}function W(){return{id:I.id,title:`action-recorder.menu.replay-local-active`,type:o.MenuItemType.BUTTON}}let G={[o.RibbonOthersGroup.OTHERS]:{[z]:{order:1,menuItemFactory:B,[L.id]:{order:1,menuItemFactory:V},[P.id]:{order:2,menuItemFactory:H},[F.id]:{order:3,menuItemFactory:U},[I.id]:{order:4,menuItemFactory:W}}}};function K(){return(0,o.useObservable)((0,o.useDependency)(D).panelOpened$)?(0,l.jsx)(q,{}):null}function q(){var e;let r=(0,o.useDependency)(t.ICommandService),i=(0,o.useDependency)(D),a=(0,o.useObservable)(i.recording$),s=(0,o.useObservable)(i.recordedCommands$),u=(e=s==null?void 0:s.length)==null?0:e,d=(0,n.useCallback)(()=>{a||r.executeCommand(R.id)},[r,a]),f=(0,n.useCallback)(e=>{a||r.executeCommand(O.id,{replaceId:e})},[r,a]),p=(0,n.useCallback)(()=>{a&&r.executeCommand(k.id)},[r,a]),m=(0,n.useCallback)(()=>{a&&r.executeCommand(A.id)},[r,a]),h=a?u===0?`Recording...`:`${u}: ${s[u-1].id}`:`Start Recording`;return(0,l.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:[(0,l.jsx)(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:(0,l.jsx)(b,{})}),(0,l.jsx)(`div`,{className:`univer-flex-1 univer-text-sm`,children:h}),(0,l.jsxs)(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[(0,l.jsx)(c.Button,{className:`univer-w-20`,onClick:a?m:d,children:a?`Cancel`:`Close`}),(0,l.jsx)(c.Button,{className:`univer-w-20`,variant:`primary`,onClick:a?p:()=>f(),children:a?`Save`:`Start`}),!a&&(0,l.jsx)(c.Button,{variant:`primary`,onClick:()=>f(!0),children:`Start(N)`})]})]})}let J=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[O,A,k,L,R,P,F,I].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(o.BuiltInUIPart.GLOBAL,()=>(0,o.connectInjector)(K,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,b)),this._menuManagerService.mergeMenu(G)}_initSheetsCommands(){[r.CopySheetCommand,r.DeleteRangeMoveLeftCommand,r.DeleteRangeMoveUpCommand,r.DeltaColumnWidthCommand,r.DeltaRowHeightCommand,r.InsertSheetCommand,r.InsertColAfterCommand,r.InsertColBeforeCommand,r.InsertRowAfterCommand,r.InsertRowBeforeCommand,r.RemoveSheetCommand,r.SetStyleCommand,r.AddWorksheetMergeCommand,r.AddWorksheetMergeAllCommand,r.AddWorksheetMergeVerticalCommand,r.AddWorksheetMergeHorizontalCommand,r.SetFrozenCommand,r.CancelFrozenCommand,r.SetHorizontalTextAlignCommand,r.SetOverlineCommand,a.SetRangeBoldCommand,a.SetRangeFontFamilyCommand,a.SetRangeFontSizeCommand,a.SetRangeItalicCommand,a.SetRangeStrickThroughCommand,a.SetRangeSubscriptCommand,a.SetRangeSuperscriptCommand,a.SetRangeTextColorCommand,a.SetRangeUnderlineCommand,r.SetRangeValuesCommand,r.SetStrikeThroughCommand,r.SetTextColorCommand,r.SetTextRotationCommand,r.SetTextWrapCommand,r.SetVerticalTextAlignCommand,a.SheetCopyCommand,a.SheetCutCommand,a.SheetPasteBesidesBorderCommand,a.SheetPasteColWidthCommand,a.SheetPasteCommand,a.SheetPasteFormatCommand,a.SheetPasteShortKeyCommand,a.SheetPasteValueCommand,r.AutoFillCommand,r.RefillCommand,r.SetWorksheetActivateCommand,r.SetWorksheetActiveOperation,r.SetSelectionsOperation,i.SetSheetFilterRangeCommand,i.SetSheetsFilterCriteriaCommand,i.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};J=E([T(0,t.ICommandService),T(1,o.IUIPartsService),T(2,o.IMenuManagerService),T(3,(0,t.Inject)(o.ComponentManager)),T(4,(0,t.Inject)(D)),T(5,(0,t.Inject)(t.Injector))],J);let Y=class extends t.Plugin{constructor(e=p,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},p,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(f,a)}onStarting(){(this._config.replayOnly?[[M]]:[[D],[M],[J]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(J)}};w(Y,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),w(Y,`packageName`,u),w(Y,`version`,d),Y=E([T(1,(0,t.Inject)(t.Injector)),T(2,t.IConfigService)],Y),Object.defineProperty(e,`ActionRecorderService`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(e,`ActionReplayService`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,`UniverActionRecorderPlugin`,{enumerable:!0,get:function(){return Y}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`react`),require(`@univerjs/sheets`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets-ui`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`react`,`@univerjs/sheets`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverActionRecorder={},e.UniverCore,e.React,e.UniverSheets,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.rxjs,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=`@univerjs/action-recorder`,d=`0.19.0`;let f=`action-recorder.config`;Symbol(f);let p={};function m({ref:e,...t}){let{icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=(0,n.useRef)(`_${v()}`);return h(r,`${i}`,{defIds:r.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function h(e,t,r,i,a){return(0,n.createElement)(e.tag,{key:t,...g(e,r,a),...i},(_(e,r).children||[]).map((n,i)=>h(n,`${t}-${e.tag}-${i}`,r,void 0,a)))}function g(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function _(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function v(){return Math.random().toString(36).substring(2,8)}m.displayName=`UniverIcon`;let 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`]},b=(0,n.forwardRef)(function(e,t){return(0,n.createElement)(m,Object.assign({},e,{id:`record-icon`,ref:t,icon:y}))});b.displayName=`RecordIcon`;function x(e){"@babel/helpers - typeof";return x=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},x(e)}function S(e,t){if(x(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(x(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function C(e){var t=S(e,`string`);return x(t)==`symbol`?t:t+``}function w(e,t,n){return(t=C(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function T(e,t){return function(n,r){t(n,r,e)}}function E(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let D=class extends t.Disposable{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,w(this,`_shouldRecordCommands`,new Set),w(this,`_panelOpened$`,new s.BehaviorSubject(!1)),w(this,`panelOpened$`,this._panelOpened$.asObservable()),w(this,`_recorder`,null),w(this,`_recording$`,new s.BehaviorSubject(!1)),w(this,`recording$`,this._recording$.asObservable()),w(this,`_recorded$`,new s.BehaviorSubject([])),w(this,`_recordedCommands$`,new s.BehaviorSubject([])),w(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(e){if(e.type===t.CommandType.MUTATION)throw 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=>{if(this._shouldRecordCommands.has(n.id)){var i;let o=this._recorded,s=this._recordedCommands,c={...n},l=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:u=l,subUnitId:d}=c==null?void 0:c.params;if(e&&u&&d){var a;let e=(a=this._instanceService.getUnit(u).getSheetBySheetId(d))==null?void 0:a.getName();c={...c,params:{...c.params,subUnitId:e}}}c.id===r.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===r.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===t.CommandType.COMMAND&&(s.push(c),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(){let 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()}};D=E([T(0,t.ICommandService),T(1,t.ILogService),T(2,o.ILocalFileService),T(3,t.IUniverInstanceService)],D);let O={id:`action-recorder.command.start-recording`,type:t.CommandType.COMMAND,handler:(e,t)=>(e.get(D).startRecording(!!(t!=null&&t.replaceId)),!0)},k={id:`action-recorder.command.complete-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},A={id:`action-recorder.command.stop-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},j=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),M=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=j.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:c.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===j.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===j.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let n of e){await(0,t.awaitTime)(N());let{id:e,params:i}=n;if(i){if(i.unitId!==void 0&&(i.unitId=r),!await this._commandService.executeCommand(e,i))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};M=E([T(0,o.IMessageService),T(1,t.IUniverInstanceService),T(2,o.ILocalFileService),T(3,t.ILogService),T(4,t.ICommandService)],M);function N(){return Math.floor(Math.random()*800)+200}let P={id:`action-recorder.command.replay-local-records`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON();return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},F={id:`action-recorder.command.replay-local-records-name`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON(j.NAME);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},I={id:`action-recorder.command.replay-local-records-active`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON(j.ACTIVE);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},L={id:`action-recorder.operation.open-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!0),!0}},R={id:`action-recorder.operation.close-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!1),!0}},z=`RECORD_MENU_ITEM`;function B(){return{id:z,type:o.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function V(e){let t=e.get(D);return{id:L.id,title:`action-recorder.menu.record`,type:o.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function H(){return{id:P.id,title:`action-recorder.menu.replay-local`,type:o.MenuItemType.BUTTON}}function U(){return{id:F.id,title:`action-recorder.menu.replay-local-name`,type:o.MenuItemType.BUTTON}}function W(){return{id:I.id,title:`action-recorder.menu.replay-local-active`,type:o.MenuItemType.BUTTON}}let G={[o.RibbonOthersGroup.OTHERS]:{[z]:{order:1,menuItemFactory:B,[L.id]:{order:1,menuItemFactory:V},[P.id]:{order:2,menuItemFactory:H},[F.id]:{order:3,menuItemFactory:U},[I.id]:{order:4,menuItemFactory:W}}}};function K(){return(0,o.useObservable)((0,o.useDependency)(D).panelOpened$)?(0,l.jsx)(q,{}):null}function q(){var e;let r=(0,o.useDependency)(t.ICommandService),i=(0,o.useDependency)(D),a=(0,o.useObservable)(i.recording$),s=(0,o.useObservable)(i.recordedCommands$),u=(e=s==null?void 0:s.length)==null?0:e,d=(0,n.useCallback)(()=>{a||r.executeCommand(R.id)},[r,a]),f=(0,n.useCallback)(e=>{a||r.executeCommand(O.id,{replaceId:e})},[r,a]),p=(0,n.useCallback)(()=>{a&&r.executeCommand(k.id)},[r,a]),m=(0,n.useCallback)(()=>{a&&r.executeCommand(A.id)},[r,a]),h=a?u===0?`Recording...`:`${u}: ${s[u-1].id}`:`Start Recording`;return(0,l.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:[(0,l.jsx)(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:(0,l.jsx)(b,{})}),(0,l.jsx)(`div`,{className:`univer-flex-1 univer-text-sm`,children:h}),(0,l.jsxs)(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[(0,l.jsx)(c.Button,{className:`univer-w-20`,onClick:a?m:d,children:a?`Cancel`:`Close`}),(0,l.jsx)(c.Button,{className:`univer-w-20`,variant:`primary`,onClick:a?p:()=>f(),children:a?`Save`:`Start`}),!a&&(0,l.jsx)(c.Button,{variant:`primary`,onClick:()=>f(!0),children:`Start(N)`})]})]})}let J=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[O,A,k,L,R,P,F,I].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(o.BuiltInUIPart.GLOBAL,()=>(0,o.connectInjector)(K,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,b)),this._menuManagerService.mergeMenu(G)}_initSheetsCommands(){[r.CopySheetCommand,r.DeleteRangeMoveLeftCommand,r.DeleteRangeMoveUpCommand,r.DeltaColumnWidthCommand,r.DeltaRowHeightCommand,r.InsertSheetCommand,r.InsertColAfterCommand,r.InsertColBeforeCommand,r.InsertRowAfterCommand,r.InsertRowBeforeCommand,r.RemoveSheetCommand,r.SetStyleCommand,r.AddWorksheetMergeCommand,r.AddWorksheetMergeAllCommand,r.AddWorksheetMergeVerticalCommand,r.AddWorksheetMergeHorizontalCommand,r.SetFrozenCommand,r.CancelFrozenCommand,r.SetHorizontalTextAlignCommand,r.SetOverlineCommand,a.SetRangeBoldCommand,a.SetRangeFontFamilyCommand,a.SetRangeFontSizeCommand,a.SetRangeItalicCommand,a.SetRangeStrickThroughCommand,a.SetRangeSubscriptCommand,a.SetRangeSuperscriptCommand,a.SetRangeTextColorCommand,a.SetRangeUnderlineCommand,r.SetRangeValuesCommand,r.SetStrikeThroughCommand,r.SetTextColorCommand,r.SetTextRotationCommand,r.SetTextWrapCommand,r.SetVerticalTextAlignCommand,a.SheetCopyCommand,a.SheetCutCommand,a.SheetPasteBesidesBorderCommand,a.SheetPasteColWidthCommand,a.SheetPasteCommand,a.SheetPasteFormatCommand,a.SheetPasteShortKeyCommand,a.SheetPasteValueCommand,r.AutoFillCommand,r.RefillCommand,r.SetWorksheetActivateCommand,r.SetWorksheetActiveOperation,r.SetSelectionsOperation,i.SetSheetFilterRangeCommand,i.SetSheetsFilterCriteriaCommand,i.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};J=E([T(0,t.ICommandService),T(1,o.IUIPartsService),T(2,o.IMenuManagerService),T(3,(0,t.Inject)(o.ComponentManager)),T(4,(0,t.Inject)(D)),T(5,(0,t.Inject)(t.Injector))],J);let Y=class extends t.Plugin{constructor(e=p,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},p,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(f,a)}onStarting(){(this._config.replayOnly?[[M]]:[[D],[M],[J]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(J)}};w(Y,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),w(Y,`packageName`,u),w(Y,`version`,d),Y=E([T(1,(0,t.Inject)(t.Injector)),T(2,t.IConfigService)],Y),Object.defineProperty(e,`ActionRecorderService`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(e,`ActionReplayService`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,`UniverActionRecorderPlugin`,{enumerable:!0,get:function(){return Y}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/action-recorder",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,20 +53,20 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@univerjs/icons": "^1.1.1",
56
- "@univerjs/core": "0.18.0",
57
- "@univerjs/design": "0.18.0",
58
- "@univerjs/sheets": "0.18.0",
59
- "@univerjs/sheets-filter": "0.18.0",
60
- "@univerjs/sheets-ui": "0.18.0",
61
- "@univerjs/ui": "0.18.0"
56
+ "@univerjs/core": "0.19.0",
57
+ "@univerjs/design": "0.19.0",
58
+ "@univerjs/sheets-filter": "0.19.0",
59
+ "@univerjs/sheets": "0.19.0",
60
+ "@univerjs/sheets-ui": "0.19.0",
61
+ "@univerjs/ui": "0.19.0"
62
62
  },
63
63
  "devDependencies": {
64
64
  "react": "18.3.1",
65
65
  "rxjs": "^7.8.2",
66
66
  "tailwindcss": "3.4.18",
67
- "typescript": "^5.9.3",
68
- "vitest": "^4.1.0",
69
- "@univerjs-infra/shared": "0.18.0"
67
+ "typescript": "^6.0.2",
68
+ "vitest": "^4.1.1",
69
+ "@univerjs-infra/shared": "0.19.0"
70
70
  },
71
71
  "scripts": {
72
72
  "test": "vitest run",