@univerjs/action-recorder 0.17.0 → 0.18.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.
Files changed (78) hide show
  1. package/lib/cjs/index.js +4 -1
  2. package/lib/cjs/locale/ca-ES.js +1 -1
  3. package/lib/cjs/locale/en-US.js +1 -1
  4. package/lib/cjs/locale/es-ES.js +1 -1
  5. package/lib/cjs/locale/fa-IR.js +1 -1
  6. package/lib/cjs/locale/fr-FR.js +1 -1
  7. package/lib/cjs/locale/ja-JP.js +1 -1
  8. package/lib/cjs/locale/ko-KR.js +1 -1
  9. package/lib/cjs/locale/ru-RU.js +1 -1
  10. package/lib/cjs/locale/sk-SK.js +1 -1
  11. package/lib/cjs/locale/vi-VN.js +1 -1
  12. package/lib/cjs/locale/zh-CN.js +1 -1
  13. package/lib/cjs/locale/zh-TW.js +1 -1
  14. package/lib/es/index.js +4 -572
  15. package/lib/es/locale/ca-ES.js +1 -14
  16. package/lib/es/locale/en-US.js +1 -14
  17. package/lib/es/locale/es-ES.js +1 -14
  18. package/lib/es/locale/fa-IR.js +1 -14
  19. package/lib/es/locale/fr-FR.js +1 -14
  20. package/lib/es/locale/ja-JP.js +1 -14
  21. package/lib/es/locale/ko-KR.js +1 -14
  22. package/lib/es/locale/ru-RU.js +1 -14
  23. package/lib/es/locale/sk-SK.js +1 -14
  24. package/lib/es/locale/vi-VN.js +1 -14
  25. package/lib/es/locale/zh-CN.js +1 -14
  26. package/lib/es/locale/zh-TW.js +1 -14
  27. package/lib/index.css +100 -1
  28. package/lib/index.js +4 -572
  29. package/lib/locale/ca-ES.js +1 -14
  30. package/lib/locale/en-US.js +1 -14
  31. package/lib/locale/es-ES.js +1 -14
  32. package/lib/locale/fa-IR.js +1 -14
  33. package/lib/locale/fr-FR.js +1 -14
  34. package/lib/locale/ja-JP.js +1 -14
  35. package/lib/locale/ko-KR.js +1 -14
  36. package/lib/locale/ru-RU.js +1 -14
  37. package/lib/locale/sk-SK.js +1 -14
  38. package/lib/locale/vi-VN.js +1 -14
  39. package/lib/locale/zh-CN.js +1 -14
  40. package/lib/locale/zh-TW.js +1 -14
  41. package/lib/types/commands/commands/record.command.d.ts +16 -1
  42. package/lib/types/commands/commands/replay.command.d.ts +16 -1
  43. package/lib/types/commands/operations/operation.d.ts +16 -1
  44. package/lib/types/config/config.d.ts +16 -1
  45. package/lib/types/controllers/action-recorder.controller.d.ts +15 -0
  46. package/lib/types/locale/ca-ES.d.ts +16 -1
  47. package/lib/types/locale/es-ES.d.ts +16 -1
  48. package/lib/types/locale/fa-IR.d.ts +16 -1
  49. package/lib/types/locale/fr-FR.d.ts +16 -1
  50. package/lib/types/locale/ja-JP.d.ts +16 -1
  51. package/lib/types/locale/ko-KR.d.ts +16 -1
  52. package/lib/types/locale/ru-RU.d.ts +16 -1
  53. package/lib/types/locale/sk-SK.d.ts +16 -1
  54. package/lib/types/locale/vi-VN.d.ts +16 -1
  55. package/lib/types/locale/zh-CN.d.ts +16 -1
  56. package/lib/types/locale/zh-TW.d.ts +16 -1
  57. package/lib/types/menu/action-recorder.menu.d.ts +17 -2
  58. package/lib/types/plugin.d.ts +16 -1
  59. package/lib/types/services/action-recorder.service.d.ts +20 -4
  60. package/lib/types/services/replay.service.d.ts +17 -1
  61. package/lib/umd/index.js +4 -1
  62. package/lib/umd/locale/ca-ES.js +1 -1
  63. package/lib/umd/locale/en-US.js +1 -1
  64. package/lib/umd/locale/es-ES.js +1 -1
  65. package/lib/umd/locale/fa-IR.js +1 -1
  66. package/lib/umd/locale/fr-FR.js +1 -1
  67. package/lib/umd/locale/ja-JP.js +1 -1
  68. package/lib/umd/locale/ko-KR.js +1 -1
  69. package/lib/umd/locale/ru-RU.js +1 -1
  70. package/lib/umd/locale/sk-SK.js +1 -1
  71. package/lib/umd/locale/vi-VN.js +1 -1
  72. package/lib/umd/locale/zh-CN.js +1 -1
  73. package/lib/umd/locale/zh-TW.js +1 -1
  74. package/package.json +12 -11
  75. package/lib/types/commands/commands/commands.spec.d.ts +0 -16
  76. package/lib/types/commands/operations/operation.spec.d.ts +0 -16
  77. package/lib/types/services/action-recorder.service.spec.d.ts +0 -16
  78. package/lib/types/services/replay.service.spec.d.ts +0 -16
package/lib/cjs/index.js CHANGED
@@ -1 +1,4 @@
1
- "use strict";var z=Object.defineProperty;var H=(t,r,e)=>r in t?z(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e;var v=(t,r,e)=>H(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"),b=require("@univerjs/sheets-filter"),m=require("@univerjs/sheets-ui"),d=require("@univerjs/ui"),O=require("rxjs"),f=require("@univerjs/design"),g=require("react/jsx-runtime"),J="@univerjs/action-recorder",G="0.17.0",P={name:J,version:G},Z="action-recorder.config",F={};function E({ref:t,...r}){const{icon:e,id:n,className:o,extend:i,...c}=r,S=`univerjs-icon univerjs-icon-${n} ${o||""}`.trim(),l=p.useRef(`_${Q()}`);return L(e,`${n}`,{defIds:e.defIds,idSuffix:l.current},{ref:t,className:S,...c},i)}function L(t,r,e,n,o){return p.createElement(t.tag,{key:r,...K(t,e,o),...n},(Y(t,e).children||[]).map((i,c)=>L(i,`${r}-${t.tag}-${c}`,e,void 0,o)))}function K(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 Y(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 Q(){return Math.random().toString(36).substring(2,8)}E.displayName="UniverIcon";const X={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(E,Object.assign({},r,{id:"record-icon",ref:e,icon:X}))});w.displayName="RecordIcon";var ee=Object.getOwnPropertyDescriptor,te=(t,r,e,n)=>{for(var o=n>1?void 0:n?ee(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},A=(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 O.BehaviorSubject(!1));v(this,"panelOpened$",this._panelOpened$.asObservable());v(this,"_recorder",null);v(this,"_recording$",new O.BehaviorSubject(!1));v(this,"recording$",this._recording$.asObservable());v(this,"_recorded$",new O.BehaviorSubject([]));v(this,"_recordedCommands$",new O.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 l={...n};const C=(o=this._instanceService.getFocusedUnit())==null?void 0:o.getUnitId(),{unitId:h=C,subUnitId:u}=l==null?void 0:l.params;if(e&&h&&u){const x=(i=this._instanceService.getUnit(h).getSheetBySheetId(u))==null?void 0:i.getName();l={...l,params:{...l.params,subUnitId:x}}}l.id===a.SetSelectionsOperation.id&&c.length>0&&c[c.length-1].id===a.SetSelectionsOperation.id?c[c.length-1]=l:(c.push(l),this._recorded$.next(c),l.type===s.CommandType.COMMAND&&(S.push(l),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=te([A(0,s.ICommandService),A(1,s.ILogService),A(2,d.ILocalFileService),A(3,s.IUniverInstanceService)],exports.ActionRecorderService);const B={id:"action-recorder.command.start-recording",type:s.CommandType.COMMAND,handler:(t,r)=>(t.get(exports.ActionRecorderService).startRecording(!!(r!=null&&r.replaceId)),!0)},k={id:"action-recorder.command.complete-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)},V={id:"action-recorder.command.stop-recording",type:s.CommandType.COMMAND,handler:t=>(t.get(exports.ActionRecorderService).completeRecording(),!0)};var re=Object.getOwnPropertyDescriptor,ne=(t,r,e,n)=>{for(var o=n>1?void 0:n?re(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 l of r){const{id:C,params:h}=l,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(oe());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=ne([R(0,d.IMessageService),R(1,s.IUniverInstanceService),R(2,d.ILocalFileService),R(3,s.ILogService),R(4,s.ICommandService)],exports.ActionReplayService);function oe(){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}},W={id:"action-recorder.operation.close-panel",type:s.CommandType.OPERATION,handler(t){return t.get(exports.ActionRecorderService).togglePanel(!1),!0}},q="RECORD_MENU_ITEM";function ie(){return{id:q,type:d.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function ce(t){const r=t.get(exports.ActionRecorderService);return{id:j.id,title:"action-recorder.menu.record",type:d.MenuItemType.BUTTON,disabled$:r.panelOpened$}}function ae(){return{id:U.id,title:"action-recorder.menu.replay-local",type:d.MenuItemType.BUTTON}}function se(){return{id:$.id,title:"action-recorder.menu.replay-local-name",type:d.MenuItemType.BUTTON}}function de(){return{id:N.id,title:"action-recorder.menu.replay-local-active",type:d.MenuItemType.BUTTON}}const le={[d.RibbonOthersGroup.OTHERS]:{[q]:{order:1,menuItemFactory:ie,[j.id]:{order:1,menuItemFactory:ce},[U.id]:{order:2,menuItemFactory:ae},[$.id]:{order:3,menuItemFactory:se},[N.id]:{order:4,menuItemFactory:de}}}};function me(){const t=d.useDependency(exports.ActionRecorderService);return d.useObservable(t.panelOpened$)?g.jsx(ue,{}):null}function ue(){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(W.id)},[t,e]),c=p.useCallback(u=>{e||t.executeCommand(B.id,{replaceId:u})},[t,e]),S=p.useCallback(()=>{e&&t.executeCommand(k.id)},[t,e]),l=p.useCallback(()=>{e&&t.executeCommand(V.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?l: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)"})]})]})}var ve=Object.getOwnPropertyDescriptor,Se=(t,r,e,n)=>{for(var o=n>1?void 0:n?ve(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 M=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(){[B,V,k,j,W,U,$,N].forEach(t=>this._commandSrv.registerCommand(t))}_initUI(){this._uiPartsSrv.registerComponent(d.BuiltInUIPart.GLOBAL,()=>d.connectInjector(me,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",w)),this._menuManagerService.mergeMenu(le)}_initSheetsCommands(){[a.CopySheetCommand,a.DeleteRangeMoveLeftCommand,a.DeleteRangeMoveUpCommand,a.DeltaColumnWidthCommand,a.DeltaRowHeightCommand,a.InsertSheetCommand,a.InsertColAfterCommand,a.InsertColBeforeCommand,a.InsertRowAfterCommand,a.InsertRowBeforeCommand,a.RemoveSheetCommand,a.SetStyleCommand,a.AddWorksheetMergeCommand,a.AddWorksheetMergeAllCommand,a.AddWorksheetMergeVerticalCommand,a.AddWorksheetMergeHorizontalCommand,a.SetFrozenCommand,a.CancelFrozenCommand,a.SetHorizontalTextAlignCommand,a.SetOverlineCommand,m.SetRangeBoldCommand,m.SetRangeFontFamilyCommand,m.SetRangeFontSizeCommand,m.SetRangeItalicCommand,m.SetRangeStrickThroughCommand,m.SetRangeSubscriptCommand,m.SetRangeSuperscriptCommand,m.SetRangeTextColorCommand,m.SetRangeUnderlineCommand,a.SetRangeValuesCommand,a.SetStrikeThroughCommand,a.SetTextColorCommand,a.SetTextRotationCommand,a.SetTextWrapCommand,a.SetVerticalTextAlignCommand,m.SheetCopyCommand,m.SheetCutCommand,m.SheetPasteBesidesBorderCommand,m.SheetPasteColWidthCommand,m.SheetPasteCommand,m.SheetPasteFormatCommand,m.SheetPasteShortKeyCommand,m.SheetPasteValueCommand,a.AutoFillCommand,a.RefillCommand,a.SetWorksheetActivateCommand,a.SetWorksheetActiveOperation,a.SetSelectionsOperation,b.SetSheetFilterRangeCommand,b.SetSheetsFilterCriteriaCommand,b.RemoveSheetFilterCommand].forEach(t=>this._actionRecorderService.registerRecordedCommand(t))}_initDocsCommands(){}};M=Se([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))],M);var ge=Object.getOwnPropertyDescriptor,he=(t,r,e,n)=>{for(var o=n>1?void 0:n?ge(r,e):r,i=t.length-1,c;i>=0;i--)(c=t[i])&&(o=c(o)||o);return o},D=(t,r)=>(e,n)=>r(e,n,t),I;exports.UniverActionRecorderPlugin=(I=class extends s.Plugin{constructor(r=F,e,n){super(),this._config=r,this._injector=e,this._configService=n;const{menu:o,...i}=s.merge({},F,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Z,i)}onStarting(){(this._config.replayOnly?[[exports.ActionReplayService]]:[[exports.ActionRecorderService],[exports.ActionReplayService],[M]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(M)}},v(I,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),v(I,"packageName",P.name),v(I,"version",P.version),I);exports.UniverActionRecorderPlugin=he([D(1,s.Inject(s.Injector)),D(2,s.IConfigService)],exports.UniverActionRecorderPlugin);
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 +1 @@
1
- "use strict";const a={"action-recorder":{menu:{title:"Grava accions",record:"Grava accions...","replay-local":"Reemplaça gravació local...","replay-local-name":"Reemplaça gravació local per subunitat...","replay-local-active":"Reemplaça gravació local per subunitat actual..."}}};module.exports=a;
1
+ const e={"action-recorder":{menu:{title:`Grava accions`,record:`Grava accions...`,"replay-local":`Reemplaça gravació local...`,"replay-local-name":`Reemplaça gravació local per subunitat...`,"replay-local-active":`Reemplaça gravació local per subunitat actual...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"Record Actions",record:"Record Actions...","replay-local":"Replace Local Record...","replay-local-name":"Replace Local Record by Subunit...","replay-local-active":"Replace Local Record by Current Subunit..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`Record Actions`,record:`Record Actions...`,"replay-local":`Replace Local Record...`,"replay-local-name":`Replace Local Record by Subunit...`,"replay-local-active":`Replace Local Record by Current Subunit...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const a={"action-recorder":{menu:{title:"Grabar acciones",record:"Grabar acciones...","replay-local":"Reemplazar grabación local...","replay-local-name":"Reemplazar grabación local por subunidad...","replay-local-active":"Reemplazar grabación local por subunidad actual..."}}};module.exports=a;
1
+ const e={"action-recorder":{menu:{title:`Grabar acciones`,record:`Grabar acciones...`,"replay-local":`Reemplazar grabación local...`,"replay-local-name":`Reemplazar grabación local por subunidad...`,"replay-local-active":`Reemplazar grabación local por subunidad actual...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"ثبت اقدامات",record:"ثبت اقدامات...","replay-local":"بازپخش محلی ثبت...","replay-local-name":"بازپخش محلی ثبت بر اساس نام زیر واحد...","replay-local-active":"بازپخش محلی ثبت بر اساس زیر واحد فعلی..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`ثبت اقدامات`,record:`ثبت اقدامات...`,"replay-local":`بازپخش محلی ثبت...`,"replay-local-name":`بازپخش محلی ثبت بر اساس نام زیر واحد...`,"replay-local-active":`بازپخش محلی ثبت بر اساس زیر واحد فعلی...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"Enregistrer les actions",record:"Enregistrer les actions...","replay-local":"Lecture de l'enregistrement local...","replay-local-name":"Remplacer l'enregistrement local par le sous-unité...","replay-local-active":"Remplacer l'enregistrement local par le sous-unité actuel..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`Enregistrer les actions`,record:`Enregistrer les actions...`,"replay-local":`Lecture de l'enregistrement local...`,"replay-local-name":`Remplacer l'enregistrement local par le sous-unité...`,"replay-local-active":`Remplacer l'enregistrement local par le sous-unité actuel...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"操作記録",record:"記録を開始...","replay-local":"ローカルの記録で置き換え...","replay-local-name":"サブ単位ごとにローカルの記録で置き換え...","replay-local-active":"現在のサブ単位をローカルの記録で置き換え..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`操作記録`,record:`記録を開始...`,"replay-local":`ローカルの記録で置き換え...`,"replay-local-name":`サブ単位ごとにローカルの記録で置き換え...`,"replay-local-active":`現在のサブ単位をローカルの記録で置き換え...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"동작 기록",record:"동작 기록 시작...","replay-local":"로컬 기록 대체...","replay-local-name":"하위 단위로 로컬 기록 대체...","replay-local-active":"현재 하위 단위로 로컬 기록 대체..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`동작 기록`,record:`동작 기록 시작...`,"replay-local":`로컬 기록 대체...`,"replay-local-name":`하위 단위로 로컬 기록 대체...`,"replay-local-active":`현재 하위 단위로 로컬 기록 대체...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"Record Actions",record:"Record Actions...","replay-local":"Replace Local Record...","replay-local-name":"Replace Local Record by Subunit...","replay-local-active":"Replace Local Record by Current Subunit..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`Record Actions`,record:`Record Actions...`,"replay-local":`Replace Local Record...`,"replay-local-name":`Replace Local Record by Subunit...`,"replay-local-active":`Replace Local Record by Current Subunit...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const a={"action-recorder":{menu:{title:"Zaznamenať akcie",record:"Zaznamenať akcie...","replay-local":"Nahradiť miestny záznam...","replay-local-name":"Nahradiť miestny záznam podľa podjednotky...","replay-local-active":"Nahradiť miestny záznam podľa aktuálnej podjednotky..."}}};module.exports=a;
1
+ const e={"action-recorder":{menu:{title:`Zaznamenať akcie`,record:`Zaznamenať akcie...`,"replay-local":`Nahradiť miestny záznam...`,"replay-local-name":`Nahradiť miestny záznam podľa podjednotky...`,"replay-local-active":`Nahradiť miestny záznam podľa aktuálnej podjednotky...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"Record Actions",record:"Record Actions...","replay-local":"Replace Local Record...","replay-local-name":"Replace Local Record by Subunit...","replay-local-active":"Replace Local Record by Current Subunit..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`Record Actions`,record:`Record Actions...`,"replay-local":`Replace Local Record...`,"replay-local-name":`Replace Local Record by Subunit...`,"replay-local-active":`Replace Local Record by Current Subunit...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"操作录制",record:"录制操作...","replay-local":"回放本地录制...","replay-local-name":"根据子表名回放本地录制...","replay-local-active":"根据当前子表回放本地录制..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`操作录制`,record:`录制操作...`,"replay-local":`回放本地录制...`,"replay-local-name":`根据子表名回放本地录制...`,"replay-local-active":`根据当前子表回放本地录制...`}}};module.exports=e;
@@ -1 +1 @@
1
- "use strict";const e={"action-recorder":{menu:{title:"操作錄製",record:"錄製操作...","replay-local":"回放本地錄製...","replay-local-name":"根據子表名回放本地錄製...","replay-local-active":"根據當前子表回放本地錄製..."}}};module.exports=e;
1
+ const e={"action-recorder":{menu:{title:`操作錄製`,record:`錄製操作...`,"replay-local":`回放本地錄製...`,"replay-local-name":`根據子表名回放本地錄製...`,"replay-local-active":`根據當前子表回放本地錄製...`}}};module.exports=e;