@univerjs/action-recorder 0.10.14 → 0.11.0-nightly.202511151013

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var q=Object.defineProperty;var z=(t,r,e)=>r in t?q(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var v=(t,r,e)=>z(t,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),p=require("react"),a=require("@univerjs/sheets"),x=require("@univerjs/sheets-filter"),l=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),I=require("rxjs"),f=require("@univerjs/design"),g=require("react/jsx-runtime");function D({ref:t,...r}){const{icon:e,id:n,className:o,extend:i,...c}=r,S=`univerjs-icon univerjs-icon-${n} ${o||""}`.trim(),m=p.useRef(`_${G()}`);return E(e,`${n}`,{defIds:e.defIds,idSuffix:m.current},{ref:t,className:S,...c},i)}function E(t,r,e,n,o){return p.createElement(t.tag,{key:r,...H(t,e,o),...n},(J(t,e).children||[]).map((i,c)=>E(i,`${r}-${t.tag}-${c}`,e,void 0,o)))}function H(t,r,e){const n={...t.attrs};e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),t.tag==="mask"&&n.id&&(n.id=n.id+r.idSuffix),Object.entries(n).forEach(([i,c])=>{i==="mask"&&typeof c=="string"&&(n[i]=c.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))});const{defIds:o}=r;return!o||o.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+r.idSuffix),Object.entries(n).forEach(([i,c])=>{typeof c=="string"&&(n[i]=c.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))})),n}function J(t,r){var n;const{defIds:e}=r;return!e||e.length===0?t:t.tag==="defs"&&((n=t.children)!=null&&n.length)?{...t,children:t.children.map(o=>typeof o.attrs.id=="string"&&e&&e.includes(o.attrs.id)?{...o,attrs:{...o.attrs,id:o.attrs.id+r.idSuffix}}:o)}:t}function G(){return Math.random().toString(36).substring(2,8)}D.displayName="UniverIcon";const Z={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-icon_clip0_1559_19)"},children:[{tag:"path",attrs:{d:"M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z"}},{tag:"path",attrs:{d:"M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z",fillRule:"evenodd",clipRule:"evenodd"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"record-icon_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-icon_clip0_1559_19"]},w=p.forwardRef(function(r,e){return p.createElement(D,Object.assign({},r,{id:"record-icon",ref:e,icon:Z}))});w.displayName="RecordIcon";var K=Object.getOwnPropertyDescriptor,Y=(t,r,e,n)=>{for(var o=n>1?void 0:n?K(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},O=(t,r)=>(e,n)=>r(e,n,t);exports.ActionRecorderService=class extends s.Disposable{constructor(e,n,o,i){super();v(this,"_shouldRecordCommands",new Set);v(this,"_panelOpened$",new I.BehaviorSubject(!1));v(this,"panelOpened$",this._panelOpened$.asObservable());v(this,"_recorder",null);v(this,"_recording$",new I.BehaviorSubject(!1));v(this,"recording$",this._recording$.asObservable());v(this,"_recorded$",new I.BehaviorSubject([]));v(this,"_recordedCommands$",new I.BehaviorSubject([]));v(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=e,this._logService=n,this._localFileService=o,this._instanceService=i}get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}registerRecordedCommand(e){if(e.type===s.CommandType.MUTATION)throw new Error("[CommandRecorderService] Cannot record mutation commands.");this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{var o,i;if(this._shouldRecordCommands.has(n.id)){const c=this._recorded,S=this._recordedCommands;let m={...n};const C=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId(),{unitId:h=C,subUnitId:u}=m==null?void 0:m.params;if(e&&h&&u){const M=(i=this._instanceService.getUnit(h).getSheetBySheetId(u))==null?void 0:i.getName();m={...m,params:{...m.params,subUnitId:M}}}m.id===a.SetSelectionsOperation.id&&c.length>0&&c[c.length-1].id===a.SetSelectionsOperation.id?c[c.length-1]=m:(c.push(m),this._recorded$.next(c),m.type===s.CommandType.COMMAND&&(S.push(m),this._recordedCommands$.next(S)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){const e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),"recorded-commands.json"),this._logService.error("Recorded commands:",e),this.stopRecording()}};exports.ActionRecorderService=Y([O(0,s.ICommandService),O(1,s.ILogService),O(2,d.ILocalFileService),O(3,s.IUniverInstanceService)],exports.ActionRecorderService);const L={id:"action-recorder.command.start-recording",type:s.CommandType.COMMAND,handler:(t,r)=>(t.get(exports.ActionRecorderService).startRecording(!!(r!=null&&r.replaceId)),!0)},B={id:"action-recorder.command.complete-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)},k={id:"action-recorder.command.stop-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)};var Q=Object.getOwnPropertyDescriptor,X=(t,r,e,n)=>{for(var o=n>1?void 0:n?Q(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},R=(t,r)=>(e,n)=>r(e,n,t),T=(t=>(t.DEFAULT="default",t.NAME="name",t.ACTIVE="active",t))(T||{});exports.ActionReplayService=class extends s.Disposable{constructor(r,e,n,o,i){super(),this._messageService=r,this._instanceService=e,this._localFileService=n,this._logService=o,this._commandService=i}async replayLocalJSON(r="default"){const e=await this._localFileService.openFile({multiple:!1,accept:".json"});if(e.length!==1)return!1;const n=e[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:r})}catch{return this._messageService.show({type:f.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(r,e){var i,c,S;const n=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId();n||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:o}=e||{};for(const m of r){const{id:C,params:h}=m,u=h;if(u){if(typeof u.unitId<"u"&&(u.unitId=n),o==="name"&&u.subUnitId!=="undefined"){const _=(c=this._instanceService.getFocusedUnit().getSheetBySheetName(u.subUnitId))==null?void 0:c.getSheetId();_?u.subUnitId=_:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${u.subUnitId}`)}if(o==="active"&&u.subUnitId!=="undefined"){const _=(S=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:S.getSheetId();_?u.subUnitId=_:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(C,h))return!1}else if(!await this._commandService.executeCommand(C))return!1}return!0}async replayCommandsWithDelay(r){var n;const e=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();e||this._logService.error("[ReplayService]","no focused unit to replay commands");for(const o of r){await s.awaitTime(ee());const{id:i,params:c}=o;if(c){if(typeof c.unitId<"u"&&(c.unitId=e),!await this._commandService.executeCommand(i,c))return!1}else if(!await this._commandService.executeCommand(i))return!1}return!0}};exports.ActionReplayService=X([R(0,d.IMessageService),R(1,s.IUniverInstanceService),R(2,d.ILocalFileService),R(3,s.ILogService),R(4,s.ICommandService)],exports.ActionReplayService);function ee(){return Math.floor(Math.random()*800)+200}const U={id:"action-recorder.command.replay-local-records",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON();return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},$={id:"action-recorder.command.replay-local-records-name",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON(T.NAME);return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},N={id:"action-recorder.command.replay-local-records-active",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON(T.ACTIVE);return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},j={id:"action-recorder.operation.open-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!0),!0}},V={id:"action-recorder.operation.close-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!1),!0}};function te(){const t=d.useDependency(exports.ActionRecorderService);return d.useObservable(t.panelOpened$)?g.jsx(re,{}):null}function re(){var h;const t=d.useDependency(s.ICommandService),r=d.useDependency(exports.ActionRecorderService),e=d.useObservable(r.recording$),n=d.useObservable(r.recordedCommands$),o=(h=n==null?void 0:n.length)!=null?h:0,i=p.useCallback(()=>{e||t.executeCommand(V.id)},[t,e]),c=p.useCallback(u=>{e||t.executeCommand(L.id,{replaceId:u})},[t,e]),S=p.useCallback(()=>{e&&t.executeCommand(B.id)},[t,e]),m=p.useCallback(()=>{e&&t.executeCommand(k.id)},[t,e]),C=e?o===0?"Recording...":`${o}: ${n[o-1].id}`:"Start Recording";return g.jsxs("div",{className:"univer-fixed univer-bottom-20 univer-left-1/2 univer-z-[1000] univer-flex univer-h-16 univer-w-[512px] -univer-translate-x-1/2 univer-items-center univer-rounded-lg univer-bg-white univer-px-5 univer-shadow-lg",children:[g.jsx("div",{className:"univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl",children:g.jsx(w,{})}),g.jsx("div",{className:"univer-flex-1 univer-text-sm",children:C}),g.jsxs("div",{className:"univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between",children:[g.jsx(f.Button,{className:"univer-w-20",onClick:e?m:i,children:e?"Cancel":"Close"}),g.jsx(f.Button,{className:"univer-w-20",variant:"primary",onClick:e?S:()=>c(),children:e?"Save":"Start"}),!e&&g.jsx(f.Button,{variant:"primary",onClick:()=>c(!0),children:"Start(N)"})]})]})}const W="RECORD_MENU_ITEM";function ne(){return{id:W,type:d.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function oe(t){const r=t.get(exports.ActionRecorderService);return{id:j.id,title:"action-recorder.menu.record",type:d.MenuItemType.BUTTON,disabled$:r.panelOpened$}}function ie(){return{id:U.id,title:"action-recorder.menu.replay-local",type:d.MenuItemType.BUTTON}}function ce(){return{id:$.id,title:"action-recorder.menu.replay-local-name",type:d.MenuItemType.BUTTON}}function ae(){return{id:N.id,title:"action-recorder.menu.replay-local-active",type:d.MenuItemType.BUTTON}}const se={[d.RibbonStartGroup.OTHERS]:{[W]:{order:2,menuItemFactory:ne,[j.id]:{order:1,menuItemFactory:oe},[U.id]:{order:2,menuItemFactory:ie},[$.id]:{order:3,menuItemFactory:ce},[N.id]:{order:4,menuItemFactory:ae}}}};var de=Object.getOwnPropertyDescriptor,le=(t,r,e,n)=>{for(var o=n>1?void 0:n?de(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},y=(t,r)=>(e,n)=>r(e,n,t);let A=class extends s.Disposable{constructor(t,r,e,n,o,i){super(),this._commandSrv=t,this._uiPartsSrv=r,this._menuManagerService=e,this._componentManager=n,this._actionRecorderService=o,this._injector=i,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[L,k,B,j,V,U,$,N].forEach(t=>this._commandSrv.registerCommand(t))}_initUI(){this._uiPartsSrv.registerComponent(d.BuiltInUIPart.GLOBAL,()=>d.connectInjector(te,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",w)),this._menuManagerService.mergeMenu(se)}_initSheetsCommands(){[a.CopySheetCommand,a.DeleteRangeMoveLeftCommand,a.DeleteRangeMoveUpCommand,a.DeltaColumnWidthCommand,a.DeltaRowHeightCommand,a.InsertSheetCommand,a.InsertColAfterCommand,a.InsertColBeforeCommand,a.InsertRowAfterCommand,a.InsertRowBeforeCommand,a.RemoveSheetCommand,a.SetStyleCommand,a.AddWorksheetMergeCommand,a.AddWorksheetMergeAllCommand,a.AddWorksheetMergeVerticalCommand,a.AddWorksheetMergeHorizontalCommand,a.SetFrozenCommand,a.CancelFrozenCommand,a.SetHorizontalTextAlignCommand,a.SetOverlineCommand,l.SetRangeBoldCommand,l.SetRangeFontFamilyCommand,l.SetRangeFontSizeCommand,l.SetRangeItalicCommand,l.SetRangeStrickThroughCommand,l.SetRangeSubscriptCommand,l.SetRangeSuperscriptCommand,l.SetRangeTextColorCommand,l.SetRangeUnderlineCommand,a.SetRangeValuesCommand,a.SetStrikeThroughCommand,a.SetTextColorCommand,a.SetTextRotationCommand,a.SetTextWrapCommand,a.SetVerticalTextAlignCommand,l.SheetCopyCommand,l.SheetCutCommand,l.SheetPasteBesidesBorderCommand,l.SheetPasteColWidthCommand,l.SheetPasteCommand,l.SheetPasteFormatCommand,l.SheetPasteShortKeyCommand,l.SheetPasteValueCommand,l.AutoFillCommand,l.RefillCommand,a.SetWorksheetActivateCommand,a.SetWorksheetActiveOperation,a.SetSelectionsOperation,x.SetSheetFilterRangeCommand,x.SetSheetsFilterCriteriaCommand,x.RemoveSheetFilterCommand].forEach(t=>this._actionRecorderService.registerRecordedCommand(t))}_initDocsCommands(){}};A=le([y(0,s.ICommandService),y(1,d.IUIPartsService),y(2,d.IMenuManagerService),y(3,s.Inject(d.ComponentManager)),y(4,s.Inject(exports.ActionRecorderService)),y(5,s.Inject(s.Injector))],A);const me="action-recorder.config",P={};var ue=Object.getOwnPropertyDescriptor,Se=(t,r,e,n)=>{for(var o=n>1?void 0:n?ue(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},F=(t,r)=>(e,n)=>r(e,n,t),b;exports.UniverActionRecorderPlugin=(b=class extends s.Plugin{constructor(r=P,e,n){super(),this._config=r,this._injector=e,this._configService=n;const{menu:o,...i}=s.merge({},P,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(me,i)}onStarting(){(this._config.replayOnly?[[exports.ActionReplayService]]:[[exports.ActionRecorderService],[exports.ActionReplayService],[A]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(A)}},v(b,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),b);exports.UniverActionRecorderPlugin=Se([F(1,s.Inject(s.Injector)),F(2,s.IConfigService)],exports.UniverActionRecorderPlugin);
1
+ "use strict";var q=Object.defineProperty;var z=(t,r,e)=>r in t?q(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var v=(t,r,e)=>z(t,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),p=require("react"),a=require("@univerjs/sheets"),x=require("@univerjs/sheets-filter"),l=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),I=require("rxjs"),f=require("@univerjs/design"),h=require("react/jsx-runtime");function D({ref:t,...r}){const{icon:e,id:n,className:o,extend:i,...c}=r,S=`univerjs-icon univerjs-icon-${n} ${o||""}`.trim(),m=p.useRef(`_${G()}`);return E(e,`${n}`,{defIds:e.defIds,idSuffix:m.current},{ref:t,className:S,...c},i)}function E(t,r,e,n,o){return p.createElement(t.tag,{key:r,...H(t,e,o),...n},(J(t,e).children||[]).map((i,c)=>E(i,`${r}-${t.tag}-${c}`,e,void 0,o)))}function H(t,r,e){const n={...t.attrs};e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),t.tag==="mask"&&n.id&&(n.id=n.id+r.idSuffix),Object.entries(n).forEach(([i,c])=>{i==="mask"&&typeof c=="string"&&(n[i]=c.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))});const{defIds:o}=r;return!o||o.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+r.idSuffix),Object.entries(n).forEach(([i,c])=>{typeof c=="string"&&(n[i]=c.replace(/url\(#(.*)\)/,`url(#$1${r.idSuffix})`))})),n}function J(t,r){var n;const{defIds:e}=r;return!e||e.length===0?t:t.tag==="defs"&&((n=t.children)!=null&&n.length)?{...t,children:t.children.map(o=>typeof o.attrs.id=="string"&&e&&e.includes(o.attrs.id)?{...o,attrs:{...o.attrs,id:o.attrs.id+r.idSuffix}}:o)}:t}function G(){return Math.random().toString(36).substring(2,8)}D.displayName="UniverIcon";const Z={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-icon_clip0_1559_19)"},children:[{tag:"path",attrs:{d:"M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z"}},{tag:"path",attrs:{d:"M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z",fillRule:"evenodd",clipRule:"evenodd"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"record-icon_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-icon_clip0_1559_19"]},w=p.forwardRef(function(r,e){return p.createElement(D,Object.assign({},r,{id:"record-icon",ref:e,icon:Z}))});w.displayName="RecordIcon";var K=Object.getOwnPropertyDescriptor,Y=(t,r,e,n)=>{for(var o=n>1?void 0:n?K(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},O=(t,r)=>(e,n)=>r(e,n,t);exports.ActionRecorderService=class extends s.Disposable{constructor(e,n,o,i){super();v(this,"_shouldRecordCommands",new Set);v(this,"_panelOpened$",new I.BehaviorSubject(!1));v(this,"panelOpened$",this._panelOpened$.asObservable());v(this,"_recorder",null);v(this,"_recording$",new I.BehaviorSubject(!1));v(this,"recording$",this._recording$.asObservable());v(this,"_recorded$",new I.BehaviorSubject([]));v(this,"_recordedCommands$",new I.BehaviorSubject([]));v(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=e,this._logService=n,this._localFileService=o,this._instanceService=i}get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}registerRecordedCommand(e){if(e.type===s.CommandType.MUTATION)throw new Error("[CommandRecorderService] Cannot record mutation commands.");this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{var o,i;if(this._shouldRecordCommands.has(n.id)){const c=this._recorded,S=this._recordedCommands;let m={...n};const C=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId(),{unitId:g=C,subUnitId:u}=m==null?void 0:m.params;if(e&&g&&u){const M=(i=this._instanceService.getUnit(g).getSheetBySheetId(u))==null?void 0:i.getName();m={...m,params:{...m.params,subUnitId:M}}}m.id===a.SetSelectionsOperation.id&&c.length>0&&c[c.length-1].id===a.SetSelectionsOperation.id?c[c.length-1]=m:(c.push(m),this._recorded$.next(c),m.type===s.CommandType.COMMAND&&(S.push(m),this._recordedCommands$.next(S)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){const e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),"recorded-commands.json"),this._logService.error("Recorded commands:",e),this.stopRecording()}};exports.ActionRecorderService=Y([O(0,s.ICommandService),O(1,s.ILogService),O(2,d.ILocalFileService),O(3,s.IUniverInstanceService)],exports.ActionRecorderService);const L={id:"action-recorder.command.start-recording",type:s.CommandType.COMMAND,handler:(t,r)=>(t.get(exports.ActionRecorderService).startRecording(!!(r!=null&&r.replaceId)),!0)},B={id:"action-recorder.command.complete-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)},k={id:"action-recorder.command.stop-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)};var Q=Object.getOwnPropertyDescriptor,X=(t,r,e,n)=>{for(var o=n>1?void 0:n?Q(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},R=(t,r)=>(e,n)=>r(e,n,t),T=(t=>(t.DEFAULT="default",t.NAME="name",t.ACTIVE="active",t))(T||{});exports.ActionReplayService=class extends s.Disposable{constructor(r,e,n,o,i){super(),this._messageService=r,this._instanceService=e,this._localFileService=n,this._logService=o,this._commandService=i}async replayLocalJSON(r="default"){const e=await this._localFileService.openFile({multiple:!1,accept:".json"});if(e.length!==1)return!1;const n=e[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:r})}catch{return this._messageService.show({type:f.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(r,e){var i,c,S;const n=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId();n||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:o}=e||{};for(const m of r){const{id:C,params:g}=m,u=g;if(u){if(typeof u.unitId<"u"&&(u.unitId=n),o==="name"&&u.subUnitId!=="undefined"){const _=(c=this._instanceService.getFocusedUnit().getSheetBySheetName(u.subUnitId))==null?void 0:c.getSheetId();_?u.subUnitId=_:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${u.subUnitId}`)}if(o==="active"&&u.subUnitId!=="undefined"){const _=(S=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:S.getSheetId();_?u.subUnitId=_:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(C,g))return!1}else if(!await this._commandService.executeCommand(C))return!1}return!0}async replayCommandsWithDelay(r){var n;const e=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();e||this._logService.error("[ReplayService]","no focused unit to replay commands");for(const o of r){await s.awaitTime(ee());const{id:i,params:c}=o;if(c){if(typeof c.unitId<"u"&&(c.unitId=e),!await this._commandService.executeCommand(i,c))return!1}else if(!await this._commandService.executeCommand(i))return!1}return!0}};exports.ActionReplayService=X([R(0,d.IMessageService),R(1,s.IUniverInstanceService),R(2,d.ILocalFileService),R(3,s.ILogService),R(4,s.ICommandService)],exports.ActionReplayService);function ee(){return Math.floor(Math.random()*800)+200}const U={id:"action-recorder.command.replay-local-records",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON();return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},$={id:"action-recorder.command.replay-local-records-name",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON(T.NAME);return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},N={id:"action-recorder.command.replay-local-records-active",type:s.CommandType.COMMAND,handler:async t=>{const e=await t.get(exports.ActionReplayService).replayLocalJSON(T.ACTIVE);return e&&t.get(d.IMessageService).show({type:f.MessageType.Success,content:"Successfully replayed local records"}),e}},j={id:"action-recorder.operation.open-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!0),!0}},V={id:"action-recorder.operation.close-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!1),!0}};function te(){const t=d.useDependency(exports.ActionRecorderService);return d.useObservable(t.panelOpened$)?h.jsx(re,{}):null}function re(){var g;const t=d.useDependency(s.ICommandService),r=d.useDependency(exports.ActionRecorderService),e=d.useObservable(r.recording$),n=d.useObservable(r.recordedCommands$),o=(g=n==null?void 0:n.length)!=null?g:0,i=p.useCallback(()=>{e||t.executeCommand(V.id)},[t,e]),c=p.useCallback(u=>{e||t.executeCommand(L.id,{replaceId:u})},[t,e]),S=p.useCallback(()=>{e&&t.executeCommand(B.id)},[t,e]),m=p.useCallback(()=>{e&&t.executeCommand(k.id)},[t,e]),C=e?o===0?"Recording...":`${o}: ${n[o-1].id}`:"Start Recording";return h.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:[h.jsx("div",{className:"univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl",children:h.jsx(w,{})}),h.jsx("div",{className:"univer-flex-1 univer-text-sm",children:C}),h.jsxs("div",{className:"univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between",children:[h.jsx(f.Button,{className:"univer-w-20",onClick:e?m:i,children:e?"Cancel":"Close"}),h.jsx(f.Button,{className:"univer-w-20",variant:"primary",onClick:e?S:()=>c(),children:e?"Save":"Start"}),!e&&h.jsx(f.Button,{variant:"primary",onClick:()=>c(!0),children:"Start(N)"})]})]})}const W="RECORD_MENU_ITEM";function ne(){return{id:W,type:d.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function oe(t){const r=t.get(exports.ActionRecorderService);return{id:j.id,title:"action-recorder.menu.record",type:d.MenuItemType.BUTTON,disabled$:r.panelOpened$}}function ie(){return{id:U.id,title:"action-recorder.menu.replay-local",type:d.MenuItemType.BUTTON}}function ce(){return{id:$.id,title:"action-recorder.menu.replay-local-name",type:d.MenuItemType.BUTTON}}function ae(){return{id:N.id,title:"action-recorder.menu.replay-local-active",type:d.MenuItemType.BUTTON}}const se={[d.RibbonOthersGroup.OTHERS]:{[W]:{order:1,menuItemFactory:ne,[j.id]:{order:1,menuItemFactory:oe},[U.id]:{order:2,menuItemFactory:ie},[$.id]:{order:3,menuItemFactory:ce},[N.id]:{order:4,menuItemFactory:ae}}}};var de=Object.getOwnPropertyDescriptor,le=(t,r,e,n)=>{for(var o=n>1?void 0:n?de(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},y=(t,r)=>(e,n)=>r(e,n,t);let A=class extends s.Disposable{constructor(t,r,e,n,o,i){super(),this._commandSrv=t,this._uiPartsSrv=r,this._menuManagerService=e,this._componentManager=n,this._actionRecorderService=o,this._injector=i,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[L,k,B,j,V,U,$,N].forEach(t=>this._commandSrv.registerCommand(t))}_initUI(){this._uiPartsSrv.registerComponent(d.BuiltInUIPart.GLOBAL,()=>d.connectInjector(te,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",w)),this._menuManagerService.mergeMenu(se)}_initSheetsCommands(){[a.CopySheetCommand,a.DeleteRangeMoveLeftCommand,a.DeleteRangeMoveUpCommand,a.DeltaColumnWidthCommand,a.DeltaRowHeightCommand,a.InsertSheetCommand,a.InsertColAfterCommand,a.InsertColBeforeCommand,a.InsertRowAfterCommand,a.InsertRowBeforeCommand,a.RemoveSheetCommand,a.SetStyleCommand,a.AddWorksheetMergeCommand,a.AddWorksheetMergeAllCommand,a.AddWorksheetMergeVerticalCommand,a.AddWorksheetMergeHorizontalCommand,a.SetFrozenCommand,a.CancelFrozenCommand,a.SetHorizontalTextAlignCommand,a.SetOverlineCommand,l.SetRangeBoldCommand,l.SetRangeFontFamilyCommand,l.SetRangeFontSizeCommand,l.SetRangeItalicCommand,l.SetRangeStrickThroughCommand,l.SetRangeSubscriptCommand,l.SetRangeSuperscriptCommand,l.SetRangeTextColorCommand,l.SetRangeUnderlineCommand,a.SetRangeValuesCommand,a.SetStrikeThroughCommand,a.SetTextColorCommand,a.SetTextRotationCommand,a.SetTextWrapCommand,a.SetVerticalTextAlignCommand,l.SheetCopyCommand,l.SheetCutCommand,l.SheetPasteBesidesBorderCommand,l.SheetPasteColWidthCommand,l.SheetPasteCommand,l.SheetPasteFormatCommand,l.SheetPasteShortKeyCommand,l.SheetPasteValueCommand,l.AutoFillCommand,l.RefillCommand,a.SetWorksheetActivateCommand,a.SetWorksheetActiveOperation,a.SetSelectionsOperation,x.SetSheetFilterRangeCommand,x.SetSheetsFilterCriteriaCommand,x.RemoveSheetFilterCommand].forEach(t=>this._actionRecorderService.registerRecordedCommand(t))}_initDocsCommands(){}};A=le([y(0,s.ICommandService),y(1,d.IUIPartsService),y(2,d.IMenuManagerService),y(3,s.Inject(d.ComponentManager)),y(4,s.Inject(exports.ActionRecorderService)),y(5,s.Inject(s.Injector))],A);const me="action-recorder.config",P={};var ue=Object.getOwnPropertyDescriptor,Se=(t,r,e,n)=>{for(var o=n>1?void 0:n?ue(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},F=(t,r)=>(e,n)=>r(e,n,t),b;exports.UniverActionRecorderPlugin=(b=class extends s.Plugin{constructor(r=P,e,n){super(),this._config=r,this._injector=e,this._configService=n;const{menu:o,...i}=s.merge({},P,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(me,i)}onStarting(){(this._config.replayOnly?[[exports.ActionReplayService]]:[[exports.ActionRecorderService],[exports.ActionReplayService],[A]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(A)}},v(b,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),b);exports.UniverActionRecorderPlugin=Se([F(1,s.Inject(s.Injector)),F(2,s.IConfigService)],exports.UniverActionRecorderPlugin);
@@ -0,0 +1 @@
1
+ "use strict";const e={"action-recorder":{menu:{title:"操作記録",record:"記録を開始...","replay-local":"ローカルの記録で置き換え...","replay-local-name":"サブ単位ごとにローカルの記録で置き換え...","replay-local-active":"現在のサブ単位をローカルの記録で置き換え..."}}};module.exports=e;
package/lib/es/index.js CHANGED
@@ -6,7 +6,7 @@ import { useRef as de, createElement as Z, forwardRef as le, useCallback as y }
6
6
  import { SetSelectionsOperation as A, CopySheetCommand as me, DeleteRangeMoveLeftCommand as ue, DeleteRangeMoveUpCommand as he, DeltaColumnWidthCommand as ge, DeltaRowHeightCommand as fe, InsertSheetCommand as pe, InsertColAfterCommand as Se, InsertColBeforeCommand as ve, InsertRowAfterCommand as Ce, InsertRowBeforeCommand as _e, RemoveSheetCommand as ye, SetStyleCommand as Re, AddWorksheetMergeCommand as Ie, AddWorksheetMergeAllCommand as Oe, AddWorksheetMergeVerticalCommand as we, AddWorksheetMergeHorizontalCommand as Me, SetFrozenCommand as $e, CancelFrozenCommand as xe, SetHorizontalTextAlignCommand as Ne, SetOverlineCommand as Ue, SetRangeValuesCommand as Ae, SetStrikeThroughCommand as be, SetTextColorCommand as Fe, SetTextRotationCommand as Pe, SetTextWrapCommand as Te, SetVerticalTextAlignCommand as De, SetWorksheetActivateCommand as Ee, SetWorksheetActiveOperation as Le } from "@univerjs/sheets";
7
7
  import { SetSheetFilterRangeCommand as je, SetSheetsFilterCriteriaCommand as Be, RemoveSheetFilterCommand as ke } from "@univerjs/sheets-filter";
8
8
  import { SetRangeBoldCommand as Ve, SetRangeFontFamilyCommand as We, SetRangeFontSizeCommand as ze, SetRangeItalicCommand as He, SetRangeStrickThroughCommand as Je, SetRangeSubscriptCommand as Ge, SetRangeSuperscriptCommand as Ze, SetRangeTextColorCommand as Ke, SetRangeUnderlineCommand as Ye, SheetCopyCommand as qe, SheetCutCommand as Qe, SheetPasteBesidesBorderCommand as Xe, SheetPasteColWidthCommand as et, SheetPasteCommand as tt, SheetPasteFormatCommand as rt, SheetPasteShortKeyCommand as nt, SheetPasteValueCommand as ot, AutoFillCommand as it, RefillCommand as ct } from "@univerjs/sheets-ui";
9
- import { ILocalFileService as K, IMessageService as $, useDependency as b, useObservable as F, RibbonStartGroup as at, MenuItemType as _, IUIPartsService as st, IMenuManagerService as dt, ComponentManager as lt, BuiltInUIPart as mt, connectInjector as ut } from "@univerjs/ui";
9
+ import { ILocalFileService as K, IMessageService as $, useDependency as b, useObservable as F, RibbonOthersGroup as at, MenuItemType as _, IUIPartsService as st, IMenuManagerService as dt, ComponentManager as lt, BuiltInUIPart as mt, connectInjector as ut } from "@univerjs/ui";
10
10
  import { BehaviorSubject as R } from "rxjs";
11
11
  import { MessageType as x, Button as N } from "@univerjs/design";
12
12
  import { jsx as g, jsxs as k } from "react/jsx-runtime";
@@ -401,7 +401,7 @@ function xt() {
401
401
  const Nt = {
402
402
  [at.OTHERS]: {
403
403
  [re]: {
404
- order: 2,
404
+ order: 1,
405
405
  menuItemFactory: Ot,
406
406
  [B.id]: {
407
407
  order: 1,
@@ -0,0 +1,14 @@
1
+ const e = {
2
+ "action-recorder": {
3
+ menu: {
4
+ title: "操作記録",
5
+ record: "記録を開始...",
6
+ "replay-local": "ローカルの記録で置き換え...",
7
+ "replay-local-name": "サブ単位ごとにローカルの記録で置き換え...",
8
+ "replay-local-active": "現在のサブ単位をローカルの記録で置き換え..."
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ e as default
14
+ };
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@ import { useRef as de, createElement as Z, forwardRef as le, useCallback as y }
6
6
  import { SetSelectionsOperation as A, CopySheetCommand as me, DeleteRangeMoveLeftCommand as ue, DeleteRangeMoveUpCommand as he, DeltaColumnWidthCommand as ge, DeltaRowHeightCommand as fe, InsertSheetCommand as pe, InsertColAfterCommand as Se, InsertColBeforeCommand as ve, InsertRowAfterCommand as Ce, InsertRowBeforeCommand as _e, RemoveSheetCommand as ye, SetStyleCommand as Re, AddWorksheetMergeCommand as Ie, AddWorksheetMergeAllCommand as Oe, AddWorksheetMergeVerticalCommand as we, AddWorksheetMergeHorizontalCommand as Me, SetFrozenCommand as $e, CancelFrozenCommand as xe, SetHorizontalTextAlignCommand as Ne, SetOverlineCommand as Ue, SetRangeValuesCommand as Ae, SetStrikeThroughCommand as be, SetTextColorCommand as Fe, SetTextRotationCommand as Pe, SetTextWrapCommand as Te, SetVerticalTextAlignCommand as De, SetWorksheetActivateCommand as Ee, SetWorksheetActiveOperation as Le } from "@univerjs/sheets";
7
7
  import { SetSheetFilterRangeCommand as je, SetSheetsFilterCriteriaCommand as Be, RemoveSheetFilterCommand as ke } from "@univerjs/sheets-filter";
8
8
  import { SetRangeBoldCommand as Ve, SetRangeFontFamilyCommand as We, SetRangeFontSizeCommand as ze, SetRangeItalicCommand as He, SetRangeStrickThroughCommand as Je, SetRangeSubscriptCommand as Ge, SetRangeSuperscriptCommand as Ze, SetRangeTextColorCommand as Ke, SetRangeUnderlineCommand as Ye, SheetCopyCommand as qe, SheetCutCommand as Qe, SheetPasteBesidesBorderCommand as Xe, SheetPasteColWidthCommand as et, SheetPasteCommand as tt, SheetPasteFormatCommand as rt, SheetPasteShortKeyCommand as nt, SheetPasteValueCommand as ot, AutoFillCommand as it, RefillCommand as ct } from "@univerjs/sheets-ui";
9
- import { ILocalFileService as K, IMessageService as $, useDependency as b, useObservable as F, RibbonStartGroup as at, MenuItemType as _, IUIPartsService as st, IMenuManagerService as dt, ComponentManager as lt, BuiltInUIPart as mt, connectInjector as ut } from "@univerjs/ui";
9
+ import { ILocalFileService as K, IMessageService as $, useDependency as b, useObservable as F, RibbonOthersGroup as at, MenuItemType as _, IUIPartsService as st, IMenuManagerService as dt, ComponentManager as lt, BuiltInUIPart as mt, connectInjector as ut } from "@univerjs/ui";
10
10
  import { BehaviorSubject as R } from "rxjs";
11
11
  import { MessageType as x, Button as N } from "@univerjs/design";
12
12
  import { jsx as g, jsxs as k } from "react/jsx-runtime";
@@ -401,7 +401,7 @@ function xt() {
401
401
  const Nt = {
402
402
  [at.OTHERS]: {
403
403
  [re]: {
404
- order: 2,
404
+ order: 1,
405
405
  menuItemFactory: Ot,
406
406
  [B.id]: {
407
407
  order: 1,
@@ -0,0 +1,14 @@
1
+ const e = {
2
+ "action-recorder": {
3
+ menu: {
4
+ title: "操作記録",
5
+ record: "記録を開始...",
6
+ "replay-local": "ローカルの記録で置き換え...",
7
+ "replay-local-name": "サブ単位ごとにローカルの記録で置き換え...",
8
+ "replay-local-active": "現在のサブ単位をローカルの記録で置き換え..."
9
+ }
10
+ }
11
+ };
12
+ export {
13
+ e as default
14
+ };
@@ -0,0 +1,3 @@
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
3
+ export default locale;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(o,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.UniverActionRecorder={},o.UniverCore,o.React,o.UniverSheets,o.UniverSheetsFilter,o.UniverSheetsUi,o.UniverUi,o.rxjs,o.UniverDesign,o.React))})(this,(function(o,c,S,s,T,m,l,O,h,p){"use strict";var ve=Object.defineProperty;var Se=(o,c,S)=>c in o?ve(o,c,{enumerable:!0,configurable:!0,writable:!0,value:S}):o[c]=S;var g=(o,c,S)=>Se(o,typeof c!="symbol"?c+"":c,S);var P;function F({ref:r,...t}){const{icon:e,id:n,className:i,extend:a,...d}=t,f=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),u=S.useRef(`_${J()}`);return E(e,`${n}`,{defIds:e.defIds,idSuffix:u.current},{ref:r,className:f,...d},a)}function E(r,t,e,n,i){return S.createElement(r.tag,{key:t,...z(r,e,i),...n},(H(r,e).children||[]).map((a,d)=>E(a,`${t}-${r.tag}-${d}`,e,void 0,i)))}function z(r,t,e){const n={...r.attrs};e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(([a,d])=>{a==="mask"&&typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([a,d])=>{typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function H(r,t){var n;const{defIds:e}=t;return!e||e.length===0?r:r.tag==="defs"&&((n=r.children)!=null&&n.length)?{...r,children:r.children.map(i=>typeof i.attrs.id=="string"&&e&&e.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:r}function J(){return Math.random().toString(36).substring(2,8)}F.displayName="UniverIcon";const G={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-icon_clip0_1559_19)"},children:[{tag:"path",attrs:{d:"M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z"}},{tag:"path",attrs:{d:"M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z",fillRule:"evenodd",clipRule:"evenodd"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"record-icon_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-icon_clip0_1559_19"]},w=S.forwardRef(function(t,e){return S.createElement(F,Object.assign({},t,{id:"record-icon",ref:e,icon:G}))});w.displayName="RecordIcon";var Z=Object.getOwnPropertyDescriptor,K=(r,t,e,n)=>{for(var i=n>1?void 0:n?Z(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},A=(r,t)=>(e,n)=>t(e,n,r);o.ActionRecorderService=class extends c.Disposable{constructor(e,n,i,a){super();g(this,"_shouldRecordCommands",new Set);g(this,"_panelOpened$",new O.BehaviorSubject(!1));g(this,"panelOpened$",this._panelOpened$.asObservable());g(this,"_recorder",null);g(this,"_recording$",new O.BehaviorSubject(!1));g(this,"recording$",this._recording$.asObservable());g(this,"_recorded$",new O.BehaviorSubject([]));g(this,"_recordedCommands$",new O.BehaviorSubject([]));g(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=e,this._logService=n,this._localFileService=i,this._instanceService=a}get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}registerRecordedCommand(e){if(e.type===c.CommandType.MUTATION)throw new Error("[CommandRecorderService] Cannot record mutation commands.");this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{var i,a;if(this._shouldRecordCommands.has(n.id)){const d=this._recorded,f=this._recordedCommands;let u={...n};const _=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:C=_,subUnitId:v}=u==null?void 0:u.params;if(e&&C&&v){const D=(a=this._instanceService.getUnit(C).getSheetBySheetId(v))==null?void 0:a.getName();u={...u,params:{...u.params,subUnitId:D}}}u.id===s.SetSelectionsOperation.id&&d.length>0&&d[d.length-1].id===s.SetSelectionsOperation.id?d[d.length-1]=u:(d.push(u),this._recorded$.next(d),u.type===c.CommandType.COMMAND&&(f.push(u),this._recordedCommands$.next(f)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){const e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),"recorded-commands.json"),this._logService.error("Recorded commands:",e),this.stopRecording()}},o.ActionRecorderService=K([A(0,c.ICommandService),A(1,c.ILogService),A(2,l.ILocalFileService),A(3,c.IUniverInstanceService)],o.ActionRecorderService);const x={id:"action-recorder.command.start-recording",type:c.CommandType.COMMAND,handler:(r,t)=>(r.get(o.ActionRecorderService).startRecording(!!(t!=null&&t.replaceId)),!0)},L={id:"action-recorder.command.complete-recording",type:c.CommandType.COMMAND,handler:r=>(r.get(o.ActionRecorderService).completeRecording(),!0)},B={id:"action-recorder.command.stop-recording",type:c.CommandType.COMMAND,handler:r=>(r.get(o.ActionRecorderService).completeRecording(),!0)};var Y=Object.getOwnPropertyDescriptor,Q=(r,t,e,n)=>{for(var i=n>1?void 0:n?Y(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},R=(r,t)=>(e,n)=>t(e,n,r),$=(r=>(r.DEFAULT="default",r.NAME="name",r.ACTIVE="active",r))($||{});o.ActionReplayService=class extends c.Disposable{constructor(t,e,n,i,a){super(),this._messageService=t,this._instanceService=e,this._localFileService=n,this._logService=i,this._commandService=a}async replayLocalJSON(t="default"){const e=await this._localFileService.openFile({multiple:!1,accept:".json"});if(e.length!==1)return!1;const n=e[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:t})}catch{return this._messageService.show({type:h.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(t,e){var a,d,f;const n=(a=this._instanceService.getFocusedUnit())==null?void 0:a.getUnitId();n||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:i}=e||{};for(const u of t){const{id:_,params:C}=u,v=C;if(v){if(typeof v.unitId<"u"&&(v.unitId=n),i==="name"&&v.subUnitId!=="undefined"){const I=(d=this._instanceService.getFocusedUnit().getSheetBySheetName(v.subUnitId))==null?void 0:d.getSheetId();I?v.subUnitId=I:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${v.subUnitId}`)}if(i==="active"&&v.subUnitId!=="undefined"){const I=(f=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:f.getSheetId();I?v.subUnitId=I:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(_,C))return!1}else if(!await this._commandService.executeCommand(_))return!1}return!0}async replayCommandsWithDelay(t){var n;const e=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();e||this._logService.error("[ReplayService]","no focused unit to replay commands");for(const i of t){await c.awaitTime(X());const{id:a,params:d}=i;if(d){if(typeof d.unitId<"u"&&(d.unitId=e),!await this._commandService.executeCommand(a,d))return!1}else if(!await this._commandService.executeCommand(a))return!1}return!0}},o.ActionReplayService=Q([R(0,l.IMessageService),R(1,c.IUniverInstanceService),R(2,l.ILocalFileService),R(3,c.ILogService),R(4,c.ICommandService)],o.ActionReplayService);function X(){return Math.floor(Math.random()*800)+200}const N={id:"action-recorder.command.replay-local-records",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON();return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},b={id:"action-recorder.command.replay-local-records-name",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON($.NAME);return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},j={id:"action-recorder.command.replay-local-records-active",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON($.ACTIVE);return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},U={id:"action-recorder.operation.open-panel",type:c.CommandType.OPERATION,handler(r){return r.get(o.ActionRecorderService).togglePanel(!0),!0}},k={id:"action-recorder.operation.close-panel",type:c.CommandType.OPERATION,handler(r){return r.get(o.ActionRecorderService).togglePanel(!1),!0}};function ee(){const r=l.useDependency(o.ActionRecorderService);return l.useObservable(r.panelOpened$)?p.jsx(re,{}):null}function re(){var C;const r=l.useDependency(c.ICommandService),t=l.useDependency(o.ActionRecorderService),e=l.useObservable(t.recording$),n=l.useObservable(t.recordedCommands$),i=(C=n==null?void 0:n.length)!=null?C:0,a=S.useCallback(()=>{e||r.executeCommand(k.id)},[r,e]),d=S.useCallback(v=>{e||r.executeCommand(x.id,{replaceId:v})},[r,e]),f=S.useCallback(()=>{e&&r.executeCommand(L.id)},[r,e]),u=S.useCallback(()=>{e&&r.executeCommand(B.id)},[r,e]),_=e?i===0?"Recording...":`${i}: ${n[i-1].id}`:"Start Recording";return p.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:[p.jsx("div",{className:"univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl",children:p.jsx(w,{})}),p.jsx("div",{className:"univer-flex-1 univer-text-sm",children:_}),p.jsxs("div",{className:"univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between",children:[p.jsx(h.Button,{className:"univer-w-20",onClick:e?u:a,children:e?"Cancel":"Close"}),p.jsx(h.Button,{className:"univer-w-20",variant:"primary",onClick:e?f:()=>d(),children:e?"Save":"Start"}),!e&&p.jsx(h.Button,{variant:"primary",onClick:()=>d(!0),children:"Start(N)"})]})]})}const V="RECORD_MENU_ITEM";function ne(){return{id:V,type:l.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function te(r){const t=r.get(o.ActionRecorderService);return{id:U.id,title:"action-recorder.menu.record",type:l.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function ie(){return{id:N.id,title:"action-recorder.menu.replay-local",type:l.MenuItemType.BUTTON}}function oe(){return{id:b.id,title:"action-recorder.menu.replay-local-name",type:l.MenuItemType.BUTTON}}function ce(){return{id:j.id,title:"action-recorder.menu.replay-local-active",type:l.MenuItemType.BUTTON}}const ae={[l.RibbonStartGroup.OTHERS]:{[V]:{order:2,menuItemFactory:ne,[U.id]:{order:1,menuItemFactory:te},[N.id]:{order:2,menuItemFactory:ie},[b.id]:{order:3,menuItemFactory:oe},[j.id]:{order:4,menuItemFactory:ce}}}};var de=Object.getOwnPropertyDescriptor,se=(r,t,e,n)=>{for(var i=n>1?void 0:n?de(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},y=(r,t)=>(e,n)=>t(e,n,r);let M=class extends c.Disposable{constructor(r,t,e,n,i,a){super(),this._commandSrv=r,this._uiPartsSrv=t,this._menuManagerService=e,this._componentManager=n,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[x,B,L,U,k,N,b,j].forEach(r=>this._commandSrv.registerCommand(r))}_initUI(){this._uiPartsSrv.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(ee,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",w)),this._menuManagerService.mergeMenu(ae)}_initSheetsCommands(){[s.CopySheetCommand,s.DeleteRangeMoveLeftCommand,s.DeleteRangeMoveUpCommand,s.DeltaColumnWidthCommand,s.DeltaRowHeightCommand,s.InsertSheetCommand,s.InsertColAfterCommand,s.InsertColBeforeCommand,s.InsertRowAfterCommand,s.InsertRowBeforeCommand,s.RemoveSheetCommand,s.SetStyleCommand,s.AddWorksheetMergeCommand,s.AddWorksheetMergeAllCommand,s.AddWorksheetMergeVerticalCommand,s.AddWorksheetMergeHorizontalCommand,s.SetFrozenCommand,s.CancelFrozenCommand,s.SetHorizontalTextAlignCommand,s.SetOverlineCommand,m.SetRangeBoldCommand,m.SetRangeFontFamilyCommand,m.SetRangeFontSizeCommand,m.SetRangeItalicCommand,m.SetRangeStrickThroughCommand,m.SetRangeSubscriptCommand,m.SetRangeSuperscriptCommand,m.SetRangeTextColorCommand,m.SetRangeUnderlineCommand,s.SetRangeValuesCommand,s.SetStrikeThroughCommand,s.SetTextColorCommand,s.SetTextRotationCommand,s.SetTextWrapCommand,s.SetVerticalTextAlignCommand,m.SheetCopyCommand,m.SheetCutCommand,m.SheetPasteBesidesBorderCommand,m.SheetPasteColWidthCommand,m.SheetPasteCommand,m.SheetPasteFormatCommand,m.SheetPasteShortKeyCommand,m.SheetPasteValueCommand,m.AutoFillCommand,m.RefillCommand,s.SetWorksheetActivateCommand,s.SetWorksheetActiveOperation,s.SetSelectionsOperation,T.SetSheetFilterRangeCommand,T.SetSheetsFilterCriteriaCommand,T.RemoveSheetFilterCommand].forEach(r=>this._actionRecorderService.registerRecordedCommand(r))}_initDocsCommands(){}};M=se([y(0,c.ICommandService),y(1,l.IUIPartsService),y(2,l.IMenuManagerService),y(3,c.Inject(l.ComponentManager)),y(4,c.Inject(o.ActionRecorderService)),y(5,c.Inject(c.Injector))],M);const le="action-recorder.config",W={};var me=Object.getOwnPropertyDescriptor,ue=(r,t,e,n)=>{for(var i=n>1?void 0:n?me(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},q=(r,t)=>(e,n)=>t(e,n,r);o.UniverActionRecorderPlugin=(P=class extends c.Plugin{constructor(t=W,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{menu:i,...a}=c.merge({},W,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(le,a)}onStarting(){(this._config.replayOnly?[[o.ActionReplayService]]:[[o.ActionRecorderService],[o.ActionReplayService],[M]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(M)}},g(P,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),P),o.UniverActionRecorderPlugin=ue([q(1,c.Inject(c.Injector)),q(2,c.IConfigService)],o.UniverActionRecorderPlugin),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(o,c){typeof exports=="object"&&typeof module<"u"?c(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"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.UniverActionRecorder={},o.UniverCore,o.React,o.UniverSheets,o.UniverSheetsFilter,o.UniverSheetsUi,o.UniverUi,o.rxjs,o.UniverDesign,o.React))})(this,(function(o,c,S,s,T,m,l,O,h,p){"use strict";var ve=Object.defineProperty;var Se=(o,c,S)=>c in o?ve(o,c,{enumerable:!0,configurable:!0,writable:!0,value:S}):o[c]=S;var g=(o,c,S)=>Se(o,typeof c!="symbol"?c+"":c,S);var P;function F({ref:r,...t}){const{icon:e,id:n,className:i,extend:a,...d}=t,f=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),u=S.useRef(`_${J()}`);return E(e,`${n}`,{defIds:e.defIds,idSuffix:u.current},{ref:r,className:f,...d},a)}function E(r,t,e,n,i){return S.createElement(r.tag,{key:t,...z(r,e,i),...n},(H(r,e).children||[]).map((a,d)=>E(a,`${t}-${r.tag}-${d}`,e,void 0,i)))}function z(r,t,e){const n={...r.attrs};e!=null&&e.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=e.colorChannel1),r.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(([a,d])=>{a==="mask"&&typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(r.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([a,d])=>{typeof d=="string"&&(n[a]=d.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function H(r,t){var n;const{defIds:e}=t;return!e||e.length===0?r:r.tag==="defs"&&((n=r.children)!=null&&n.length)?{...r,children:r.children.map(i=>typeof i.attrs.id=="string"&&e&&e.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:r}function J(){return Math.random().toString(36).substring(2,8)}F.displayName="UniverIcon";const G={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#record-icon_clip0_1559_19)"},children:[{tag:"path",attrs:{d:"M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z"}},{tag:"path",attrs:{d:"M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z",fillRule:"evenodd",clipRule:"evenodd"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"record-icon_clip0_1559_19"},children:[{tag:"path",attrs:{fill:"white",d:"M0 0H16V16H0z",transform:"translate(.94)"}}]}]}],defIds:["record-icon_clip0_1559_19"]},w=S.forwardRef(function(t,e){return S.createElement(F,Object.assign({},t,{id:"record-icon",ref:e,icon:G}))});w.displayName="RecordIcon";var Z=Object.getOwnPropertyDescriptor,K=(r,t,e,n)=>{for(var i=n>1?void 0:n?Z(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},A=(r,t)=>(e,n)=>t(e,n,r);o.ActionRecorderService=class extends c.Disposable{constructor(e,n,i,a){super();g(this,"_shouldRecordCommands",new Set);g(this,"_panelOpened$",new O.BehaviorSubject(!1));g(this,"panelOpened$",this._panelOpened$.asObservable());g(this,"_recorder",null);g(this,"_recording$",new O.BehaviorSubject(!1));g(this,"recording$",this._recording$.asObservable());g(this,"_recorded$",new O.BehaviorSubject([]));g(this,"_recordedCommands$",new O.BehaviorSubject([]));g(this,"recordedCommands$",this._recordedCommands$.asObservable());this._commandSrv=e,this._logService=n,this._localFileService=i,this._instanceService=a}get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}registerRecordedCommand(e){if(e.type===c.CommandType.MUTATION)throw new Error("[CommandRecorderService] Cannot record mutation commands.");this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{var i,a;if(this._shouldRecordCommands.has(n.id)){const d=this._recorded,f=this._recordedCommands;let u={...n};const _=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:C=_,subUnitId:v}=u==null?void 0:u.params;if(e&&C&&v){const D=(a=this._instanceService.getUnit(C).getSheetBySheetId(v))==null?void 0:a.getName();u={...u,params:{...u.params,subUnitId:D}}}u.id===s.SetSelectionsOperation.id&&d.length>0&&d[d.length-1].id===s.SetSelectionsOperation.id?d[d.length-1]=u:(d.push(u),this._recorded$.next(d),u.type===c.CommandType.COMMAND&&(f.push(u),this._recordedCommands$.next(f)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){const e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),"recorded-commands.json"),this._logService.error("Recorded commands:",e),this.stopRecording()}},o.ActionRecorderService=K([A(0,c.ICommandService),A(1,c.ILogService),A(2,l.ILocalFileService),A(3,c.IUniverInstanceService)],o.ActionRecorderService);const x={id:"action-recorder.command.start-recording",type:c.CommandType.COMMAND,handler:(r,t)=>(r.get(o.ActionRecorderService).startRecording(!!(t!=null&&t.replaceId)),!0)},L={id:"action-recorder.command.complete-recording",type:c.CommandType.COMMAND,handler:r=>(r.get(o.ActionRecorderService).completeRecording(),!0)},B={id:"action-recorder.command.stop-recording",type:c.CommandType.COMMAND,handler:r=>(r.get(o.ActionRecorderService).completeRecording(),!0)};var Y=Object.getOwnPropertyDescriptor,Q=(r,t,e,n)=>{for(var i=n>1?void 0:n?Y(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},R=(r,t)=>(e,n)=>t(e,n,r),$=(r=>(r.DEFAULT="default",r.NAME="name",r.ACTIVE="active",r))($||{});o.ActionReplayService=class extends c.Disposable{constructor(t,e,n,i,a){super(),this._messageService=t,this._instanceService=e,this._localFileService=n,this._logService=i,this._commandService=a}async replayLocalJSON(t="default"){const e=await this._localFileService.openFile({multiple:!1,accept:".json"});if(e.length!==1)return!1;const n=e[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:t})}catch{return this._messageService.show({type:h.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(t,e){var a,d,f;const n=(a=this._instanceService.getFocusedUnit())==null?void 0:a.getUnitId();n||this._logService.error("[ReplayService]","no focused unit to replay commands");const{mode:i}=e||{};for(const u of t){const{id:_,params:C}=u,v=C;if(v){if(typeof v.unitId<"u"&&(v.unitId=n),i==="name"&&v.subUnitId!=="undefined"){const I=(d=this._instanceService.getFocusedUnit().getSheetBySheetName(v.subUnitId))==null?void 0:d.getSheetId();I?v.subUnitId=I:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${v.subUnitId}`)}if(i==="active"&&v.subUnitId!=="undefined"){const I=(f=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:f.getSheetId();I?v.subUnitId=I:this._logService.error("[ReplayService]","failed to find active subunit")}if(!await this._commandService.executeCommand(_,C))return!1}else if(!await this._commandService.executeCommand(_))return!1}return!0}async replayCommandsWithDelay(t){var n;const e=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();e||this._logService.error("[ReplayService]","no focused unit to replay commands");for(const i of t){await c.awaitTime(X());const{id:a,params:d}=i;if(d){if(typeof d.unitId<"u"&&(d.unitId=e),!await this._commandService.executeCommand(a,d))return!1}else if(!await this._commandService.executeCommand(a))return!1}return!0}},o.ActionReplayService=Q([R(0,l.IMessageService),R(1,c.IUniverInstanceService),R(2,l.ILocalFileService),R(3,c.ILogService),R(4,c.ICommandService)],o.ActionReplayService);function X(){return Math.floor(Math.random()*800)+200}const N={id:"action-recorder.command.replay-local-records",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON();return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},b={id:"action-recorder.command.replay-local-records-name",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON($.NAME);return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},j={id:"action-recorder.command.replay-local-records-active",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON($.ACTIVE);return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},U={id:"action-recorder.operation.open-panel",type:c.CommandType.OPERATION,handler(r){return r.get(o.ActionRecorderService).togglePanel(!0),!0}},k={id:"action-recorder.operation.close-panel",type:c.CommandType.OPERATION,handler(r){return r.get(o.ActionRecorderService).togglePanel(!1),!0}};function ee(){const r=l.useDependency(o.ActionRecorderService);return l.useObservable(r.panelOpened$)?p.jsx(re,{}):null}function re(){var C;const r=l.useDependency(c.ICommandService),t=l.useDependency(o.ActionRecorderService),e=l.useObservable(t.recording$),n=l.useObservable(t.recordedCommands$),i=(C=n==null?void 0:n.length)!=null?C:0,a=S.useCallback(()=>{e||r.executeCommand(k.id)},[r,e]),d=S.useCallback(v=>{e||r.executeCommand(x.id,{replaceId:v})},[r,e]),f=S.useCallback(()=>{e&&r.executeCommand(L.id)},[r,e]),u=S.useCallback(()=>{e&&r.executeCommand(B.id)},[r,e]),_=e?i===0?"Recording...":`${i}: ${n[i-1].id}`:"Start Recording";return p.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:[p.jsx("div",{className:"univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl",children:p.jsx(w,{})}),p.jsx("div",{className:"univer-flex-1 univer-text-sm",children:_}),p.jsxs("div",{className:"univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between",children:[p.jsx(h.Button,{className:"univer-w-20",onClick:e?u:a,children:e?"Cancel":"Close"}),p.jsx(h.Button,{className:"univer-w-20",variant:"primary",onClick:e?f:()=>d(),children:e?"Save":"Start"}),!e&&p.jsx(h.Button,{variant:"primary",onClick:()=>d(!0),children:"Start(N)"})]})]})}const V="RECORD_MENU_ITEM";function ne(){return{id:V,type:l.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function te(r){const t=r.get(o.ActionRecorderService);return{id:U.id,title:"action-recorder.menu.record",type:l.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function ie(){return{id:N.id,title:"action-recorder.menu.replay-local",type:l.MenuItemType.BUTTON}}function oe(){return{id:b.id,title:"action-recorder.menu.replay-local-name",type:l.MenuItemType.BUTTON}}function ce(){return{id:j.id,title:"action-recorder.menu.replay-local-active",type:l.MenuItemType.BUTTON}}const ae={[l.RibbonOthersGroup.OTHERS]:{[V]:{order:1,menuItemFactory:ne,[U.id]:{order:1,menuItemFactory:te},[N.id]:{order:2,menuItemFactory:ie},[b.id]:{order:3,menuItemFactory:oe},[j.id]:{order:4,menuItemFactory:ce}}}};var de=Object.getOwnPropertyDescriptor,se=(r,t,e,n)=>{for(var i=n>1?void 0:n?de(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},y=(r,t)=>(e,n)=>t(e,n,r);let M=class extends c.Disposable{constructor(r,t,e,n,i,a){super(),this._commandSrv=r,this._uiPartsSrv=t,this._menuManagerService=e,this._componentManager=n,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[x,B,L,U,k,N,b,j].forEach(r=>this._commandSrv.registerCommand(r))}_initUI(){this._uiPartsSrv.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(ee,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",w)),this._menuManagerService.mergeMenu(ae)}_initSheetsCommands(){[s.CopySheetCommand,s.DeleteRangeMoveLeftCommand,s.DeleteRangeMoveUpCommand,s.DeltaColumnWidthCommand,s.DeltaRowHeightCommand,s.InsertSheetCommand,s.InsertColAfterCommand,s.InsertColBeforeCommand,s.InsertRowAfterCommand,s.InsertRowBeforeCommand,s.RemoveSheetCommand,s.SetStyleCommand,s.AddWorksheetMergeCommand,s.AddWorksheetMergeAllCommand,s.AddWorksheetMergeVerticalCommand,s.AddWorksheetMergeHorizontalCommand,s.SetFrozenCommand,s.CancelFrozenCommand,s.SetHorizontalTextAlignCommand,s.SetOverlineCommand,m.SetRangeBoldCommand,m.SetRangeFontFamilyCommand,m.SetRangeFontSizeCommand,m.SetRangeItalicCommand,m.SetRangeStrickThroughCommand,m.SetRangeSubscriptCommand,m.SetRangeSuperscriptCommand,m.SetRangeTextColorCommand,m.SetRangeUnderlineCommand,s.SetRangeValuesCommand,s.SetStrikeThroughCommand,s.SetTextColorCommand,s.SetTextRotationCommand,s.SetTextWrapCommand,s.SetVerticalTextAlignCommand,m.SheetCopyCommand,m.SheetCutCommand,m.SheetPasteBesidesBorderCommand,m.SheetPasteColWidthCommand,m.SheetPasteCommand,m.SheetPasteFormatCommand,m.SheetPasteShortKeyCommand,m.SheetPasteValueCommand,m.AutoFillCommand,m.RefillCommand,s.SetWorksheetActivateCommand,s.SetWorksheetActiveOperation,s.SetSelectionsOperation,T.SetSheetFilterRangeCommand,T.SetSheetsFilterCriteriaCommand,T.RemoveSheetFilterCommand].forEach(r=>this._actionRecorderService.registerRecordedCommand(r))}_initDocsCommands(){}};M=se([y(0,c.ICommandService),y(1,l.IUIPartsService),y(2,l.IMenuManagerService),y(3,c.Inject(l.ComponentManager)),y(4,c.Inject(o.ActionRecorderService)),y(5,c.Inject(c.Injector))],M);const le="action-recorder.config",W={};var me=Object.getOwnPropertyDescriptor,ue=(r,t,e,n)=>{for(var i=n>1?void 0:n?me(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},q=(r,t)=>(e,n)=>t(e,n,r);o.UniverActionRecorderPlugin=(P=class extends c.Plugin{constructor(t=W,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{menu:i,...a}=c.merge({},W,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(le,a)}onStarting(){(this._config.replayOnly?[[o.ActionReplayService]]:[[o.ActionRecorderService],[o.ActionReplayService],[M]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(M)}},g(P,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),P),o.UniverActionRecorderPlugin=ue([q(1,c.Inject(c.Injector)),q(2,c.IConfigService)],o.UniverActionRecorderPlugin),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
@@ -0,0 +1 @@
1
+ (function(e,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(e=typeof globalThis<"u"?globalThis:e||self,e.UniverActionRecorderJaJP=o())})(this,(function(){"use strict";return{"action-recorder":{menu:{title:"操作記録",record:"記録を開始...","replay-local":"ローカルの記録で置き換え...","replay-local-name":"サブ単位ごとにローカルの記録で置き換え...","replay-local-active":"現在のサブ単位をローカルの記録で置き換え..."}}}}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/action-recorder",
3
- "version": "0.10.14",
3
+ "version": "0.11.0-nightly.202511151013",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,21 +53,21 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@univerjs/icons": "^1.0.2",
56
- "@univerjs/core": "0.10.14",
57
- "@univerjs/sheets": "0.10.14",
58
- "@univerjs/design": "0.10.14",
59
- "@univerjs/sheets-filter": "0.10.14",
60
- "@univerjs/sheets-ui": "0.10.14",
61
- "@univerjs/ui": "0.10.14"
56
+ "@univerjs/core": "0.11.0-nightly.202511151013",
57
+ "@univerjs/design": "0.11.0-nightly.202511151013",
58
+ "@univerjs/sheets": "0.11.0-nightly.202511151013",
59
+ "@univerjs/sheets-filter": "0.11.0-nightly.202511151013",
60
+ "@univerjs/sheets-ui": "0.11.0-nightly.202511151013",
61
+ "@univerjs/ui": "0.11.0-nightly.202511151013"
62
62
  },
63
63
  "devDependencies": {
64
64
  "react": "18.3.1",
65
65
  "rxjs": "^7.8.2",
66
66
  "tailwindcss": "3.4.18",
67
67
  "typescript": "^5.9.3",
68
- "vite": "^7.1.12",
68
+ "vite": "^7.2.2",
69
69
  "vitest": "^3.2.4",
70
- "@univerjs-infra/shared": "0.10.14"
70
+ "@univerjs-infra/shared": "0.11.0"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS