@univerjs/action-recorder 0.16.1 → 0.17.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.
@@ -14,7 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
  import './global.css';
17
- export type { IUniverActionRecorderConfig } from './controllers/config.schema';
17
+ export type { IUniverActionRecorderConfig } from './config/config';
18
18
  export { UniverActionRecorderPlugin } from './plugin';
19
19
  export { ActionRecorderService } from './services/action-recorder.service';
20
20
  export { ActionReplayService } from './services/replay.service';
@@ -1,4 +1,4 @@
1
- import { IUniverActionRecorderConfig } from './controllers/config.schema';
1
+ import { IUniverActionRecorderConfig } from './config/config';
2
2
  import { IConfigService, Injector, Plugin } from '@univerjs/core';
3
3
  /**
4
4
  * This plugin provides a recorder for user's interactions with Univer,
@@ -9,6 +9,8 @@ export declare class UniverActionRecorderPlugin extends Plugin {
9
9
  protected readonly _injector: Injector;
10
10
  private readonly _configService;
11
11
  static pluginName: string;
12
+ static packageName: string;
13
+ static version: string;
12
14
  constructor(_config: Partial<IUniverActionRecorderConfig> | undefined, _injector: Injector, _configService: IConfigService);
13
15
  onStarting(): void;
14
16
  onSteady(): void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
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.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,s.AutoFillCommand,s.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,w,m,l,A,h,p){"use strict";var Se=Object.defineProperty;var ge=(o,c,S)=>c in o?Se(o,c,{enumerable:!0,configurable:!0,writable:!0,value:S}):o[c]=S;var g=(o,c,S)=>ge(o,typeof c!="symbol"?c+"":c,S);var I;const F={name:"@univerjs/action-recorder",version:"0.17.0"},H="action-recorder.config",E={};function x({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(`_${Z()}`);return L(e,`${n}`,{defIds:e.defIds,idSuffix:u.current},{ref:r,className:f,...d},a)}function L(r,t,e,n,i){return S.createElement(r.tag,{key:t,...J(r,e,i),...n},(G(r,e).children||[]).map((a,d)=>L(a,`${t}-${r.tag}-${d}`,e,void 0,i)))}function J(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 G(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 Z(){return Math.random().toString(36).substring(2,8)}x.displayName="UniverIcon";const K={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"]},$=S.forwardRef(function(t,e){return S.createElement(x,Object.assign({},t,{id:"record-icon",ref:e,icon:K}))});$.displayName="RecordIcon";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},M=(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 A.BehaviorSubject(!1));g(this,"panelOpened$",this._panelOpened$.asObservable());g(this,"_recorder",null);g(this,"_recording$",new A.BehaviorSubject(!1));g(this,"recording$",this._recording$.asObservable());g(this,"_recorded$",new A.BehaviorSubject([]));g(this,"_recordedCommands$",new A.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=Q([M(0,c.ICommandService),M(1,c.ILogService),M(2,l.ILocalFileService),M(3,c.IUniverInstanceService)],o.ActionRecorderService);const B={id:"action-recorder.command.start-recording",type:c.CommandType.COMMAND,handler:(r,t)=>(r.get(o.ActionRecorderService).startRecording(!!(t!=null&&t.replaceId)),!0)},k={id:"action-recorder.command.complete-recording",type:c.CommandType.COMMAND,handler:r=>(r.get(o.ActionRecorderService).completeRecording(),!0)},V={id:"action-recorder.command.stop-recording",type:c.CommandType.COMMAND,handler:r=>(r.get(o.ActionRecorderService).completeRecording(),!0)};var X=Object.getOwnPropertyDescriptor,ee=(r,t,e,n)=>{for(var i=n>1?void 0:n?X(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),N=(r=>(r.DEFAULT="default",r.NAME="name",r.ACTIVE="active",r))(N||{});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 O=(d=this._instanceService.getFocusedUnit().getSheetBySheetName(v.subUnitId))==null?void 0:d.getSheetId();O?v.subUnitId=O:this._logService.error("[ReplayService]",`failed to find subunit by subUnitName = ${v.subUnitId}`)}if(i==="active"&&v.subUnitId!=="undefined"){const O=(f=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:f.getSheetId();O?v.subUnitId=O: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(re());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=ee([R(0,l.IMessageService),R(1,c.IUniverInstanceService),R(2,l.ILocalFileService),R(3,c.ILogService),R(4,c.ICommandService)],o.ActionReplayService);function re(){return Math.floor(Math.random()*800)+200}const b={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}},j={id:"action-recorder.command.replay-local-records-name",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON(N.NAME);return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},U={id:"action-recorder.command.replay-local-records-active",type:c.CommandType.COMMAND,handler:async r=>{const e=await r.get(o.ActionReplayService).replayLocalJSON(N.ACTIVE);return e&&r.get(l.IMessageService).show({type:h.MessageType.Success,content:"Successfully replayed local records"}),e}},P={id:"action-recorder.operation.open-panel",type:c.CommandType.OPERATION,handler(r){return r.get(o.ActionRecorderService).togglePanel(!0),!0}},W={id:"action-recorder.operation.close-panel",type:c.CommandType.OPERATION,handler(r){return r.get(o.ActionRecorderService).togglePanel(!1),!0}},q="RECORD_MENU_ITEM";function ne(){return{id:q,type:l.MenuItemType.SUBITEMS,icon:"RecordIcon",tooltip:"action-recorder.menu.title"}}function te(r){const t=r.get(o.ActionRecorderService);return{id:P.id,title:"action-recorder.menu.record",type:l.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function ie(){return{id:b.id,title:"action-recorder.menu.replay-local",type:l.MenuItemType.BUTTON}}function oe(){return{id:j.id,title:"action-recorder.menu.replay-local-name",type:l.MenuItemType.BUTTON}}function ce(){return{id:U.id,title:"action-recorder.menu.replay-local-active",type:l.MenuItemType.BUTTON}}const ae={[l.RibbonOthersGroup.OTHERS]:{[q]:{order:1,menuItemFactory:ne,[P.id]:{order:1,menuItemFactory:te},[b.id]:{order:2,menuItemFactory:ie},[j.id]:{order:3,menuItemFactory:oe},[U.id]:{order:4,menuItemFactory:ce}}}};function de(){const r=l.useDependency(o.ActionRecorderService);return l.useObservable(r.panelOpened$)?p.jsx(se,{}):null}function se(){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(W.id)},[r,e]),d=S.useCallback(v=>{e||r.executeCommand(B.id,{replaceId:v})},[r,e]),f=S.useCallback(()=>{e&&r.executeCommand(k.id)},[r,e]),u=S.useCallback(()=>{e&&r.executeCommand(V.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($,{})}),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)"})]})]})}var le=Object.getOwnPropertyDescriptor,me=(r,t,e,n)=>{for(var i=n>1?void 0:n?le(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 T=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(){[B,V,k,P,W,b,j,U].forEach(r=>this._commandSrv.registerCommand(r))}_initUI(){this._uiPartsSrv.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(de,this._injector)),this.disposeWithMe(this._componentManager.register("RecordIcon",$)),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,s.AutoFillCommand,s.RefillCommand,s.SetWorksheetActivateCommand,s.SetWorksheetActiveOperation,s.SetSelectionsOperation,w.SetSheetFilterRangeCommand,w.SetSheetsFilterCriteriaCommand,w.RemoveSheetFilterCommand].forEach(r=>this._actionRecorderService.registerRecordedCommand(r))}_initDocsCommands(){}};T=me([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))],T);var ue=Object.getOwnPropertyDescriptor,ve=(r,t,e,n)=>{for(var i=n>1?void 0:n?ue(t,e):t,a=r.length-1,d;a>=0;a--)(d=r[a])&&(i=d(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);o.UniverActionRecorderPlugin=(I=class extends c.Plugin{constructor(t=E,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{menu:i,...a}=c.merge({},E,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(H,a)}onStarting(){(this._config.replayOnly?[[o.ActionReplayService]]:[[o.ActionRecorderService],[o.ActionReplayService],[T]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(T)}},g(I,"pluginName","UNIVER_ACTION_RECORDER_PLUGIN"),g(I,"packageName",F.name),g(I,"version",F.version),I),o.UniverActionRecorderPlugin=ve([z(1,c.Inject(c.Injector)),z(2,c.IConfigService)],o.UniverActionRecorderPlugin),Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/action-recorder",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,12 +53,12 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@univerjs/icons": "^1.1.1",
56
- "@univerjs/core": "0.16.1",
57
- "@univerjs/design": "0.16.1",
58
- "@univerjs/sheets-ui": "0.16.1",
59
- "@univerjs/sheets-filter": "0.16.1",
60
- "@univerjs/ui": "0.16.1",
61
- "@univerjs/sheets": "0.16.1"
56
+ "@univerjs/core": "0.17.0",
57
+ "@univerjs/design": "0.17.0",
58
+ "@univerjs/sheets": "0.17.0",
59
+ "@univerjs/sheets-filter": "0.17.0",
60
+ "@univerjs/sheets-ui": "0.17.0",
61
+ "@univerjs/ui": "0.17.0"
62
62
  },
63
63
  "devDependencies": {
64
64
  "react": "18.3.1",
@@ -67,7 +67,7 @@
67
67
  "typescript": "^5.9.3",
68
68
  "vite": "^7.3.1",
69
69
  "vitest": "^4.0.18",
70
- "@univerjs-infra/shared": "0.16.1"
70
+ "@univerjs-infra/shared": "0.17.0"
71
71
  },
72
72
  "scripts": {
73
73
  "test": "vitest run",