@univerjs/action-recorder 0.21.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,16 +1,42 @@
1
1
  # @univerjs/action-recorder
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@univerjs/action-recorder)](https://npmjs.org/packages/@univerjs/action-recorder)
4
- [![license](https://img.shields.io/npm/l/@univerjs/action-recorder)](https://img.shields.io/npm/l/@univerjs/action-recorder)
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/action-recorder?style=flat-square)](https://npmjs.com/package/@univerjs/action-recorder)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/action-recorder?style=flat-square)](https://npmjs.com/package/@univerjs/action-recorder)
5
+ [![downloads](https://img.shields.io/npm/dm/@univerjs/action-recorder?style=flat-square)](https://npmjs.com/package/@univerjs/action-recorder)
5
6
 
6
- ## Introduction
7
+ `@univerjs/action-recorder` records user actions in Univer and can replay them for debugging, demos, or automated workflow reproduction.
7
8
 
8
- This plugin is used to record user actions and it can also replay them.
9
+ ## Package Overview
10
+
11
+ | Package | UMD global | CSS | Locales | Facade entry |
12
+ | --- | --- | :---: | :---: | :---: |
13
+ | `@univerjs/action-recorder` | `UniverActionRecorder` | Yes | Yes | No |
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ pnpm add @univerjs/action-recorder
19
+ # or
20
+ npm install @univerjs/action-recorder
21
+ ```
22
+
23
+ Keep all `@univerjs/*` packages on the same version.
9
24
 
10
25
  ## Usage
11
26
 
12
- ### Installation
27
+ ```ts
28
+ import '@univerjs/action-recorder/lib/index.css';
29
+ import EnUS from '@univerjs/action-recorder/locale/en-US';
30
+ import { UniverActionRecorderPlugin } from '@univerjs/action-recorder';
13
31
 
14
- ```shell
15
- npm i @univerjs/action-recorder
32
+ univer.registerPlugin(UniverActionRecorderPlugin);
33
+
34
+ // Merge EnUS into your Univer locale map when this package contributes UI text.
16
35
  ```
36
+
37
+ ## Resources
38
+
39
+ - [Documentation](https://docs.univer.ai)
40
+ - [NPM package](https://npmjs.com/package/@univerjs/action-recorder)
41
+ - [GitHub repository](https://github.com/dream-num/univer)
42
+
package/lib/cjs/index.js CHANGED
@@ -12,7 +12,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
12
12
 
13
13
  //#region package.json
14
14
  var name = "@univerjs/action-recorder";
15
- var version = "0.21.1";
15
+ var version = "0.22.0";
16
16
 
17
17
  //#endregion
18
18
  //#region src/config/config.ts
@@ -21,7 +21,7 @@ const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
21
21
  const defaultPluginConfig = {};
22
22
 
23
23
  //#endregion
24
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
24
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
25
25
  function _typeof(o) {
26
26
  "@babel/helpers - typeof";
27
27
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -32,7 +32,7 @@ function _typeof(o) {
32
32
  }
33
33
 
34
34
  //#endregion
35
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
35
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
36
36
  function toPrimitive(t, r) {
37
37
  if ("object" != _typeof(t) || !t) return t;
38
38
  var e = t[Symbol.toPrimitive];
@@ -45,14 +45,14 @@ function toPrimitive(t, r) {
45
45
  }
46
46
 
47
47
  //#endregion
48
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
48
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
49
49
  function toPropertyKey(t) {
50
50
  var i = toPrimitive(t, "string");
51
51
  return "symbol" == _typeof(i) ? i : i + "";
52
52
  }
53
53
 
54
54
  //#endregion
55
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
55
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
56
56
  function _defineProperty(e, r, t) {
57
57
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
58
58
  value: t,
@@ -63,7 +63,7 @@ function _defineProperty(e, r, t) {
63
63
  }
64
64
 
65
65
  //#endregion
66
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
66
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
67
67
  function __decorateParam(paramIndex, decorator) {
68
68
  return function(target, key) {
69
69
  decorator(target, key, paramIndex);
@@ -71,7 +71,7 @@ function __decorateParam(paramIndex, decorator) {
71
71
  }
72
72
 
73
73
  //#endregion
74
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
74
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
75
75
  function __decorate(decorators, target, key, desc) {
76
76
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
77
77
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -199,12 +199,6 @@ const StopRecordingActionCommand = {
199
199
 
200
200
  //#endregion
201
201
  //#region src/services/replay.service.ts
202
- let ReplayMode = /* @__PURE__ */ function(ReplayMode) {
203
- ReplayMode["DEFAULT"] = "default";
204
- ReplayMode["NAME"] = "name";
205
- ReplayMode["ACTIVE"] = "active";
206
- return ReplayMode;
207
- }({});
208
202
  let ActionReplayService = class ActionReplayService extends _univerjs_core.Disposable {
209
203
  constructor(_messageService, _instanceService, _localFileService, _logService, _commandService) {
210
204
  super();
@@ -217,7 +211,7 @@ let ActionReplayService = class ActionReplayService extends _univerjs_core.Dispo
217
211
  /**
218
212
  * Read a local file and try to replay commands in this JSON.
219
213
  */
220
- async replayLocalJSON(mode = ReplayMode.DEFAULT) {
214
+ async replayLocalJSON(mode = "default") {
221
215
  const files = await this._localFileService.openFile({
222
216
  multiple: false,
223
217
  accept: ".json"
@@ -249,13 +243,13 @@ let ActionReplayService = class ActionReplayService extends _univerjs_core.Dispo
249
243
  const commandParams = params;
250
244
  if (commandParams) {
251
245
  if (typeof commandParams.unitId !== "undefined") commandParams.unitId = focusedUnitId;
252
- if (mode === ReplayMode.NAME && commandParams.subUnitId !== "undefined") {
246
+ if (mode === "name" && commandParams.subUnitId !== "undefined") {
253
247
  var _getSheetBySheetName;
254
248
  const realSubUnitId = (_getSheetBySheetName = this._instanceService.getFocusedUnit().getSheetBySheetName(commandParams.subUnitId)) === null || _getSheetBySheetName === void 0 ? void 0 : _getSheetBySheetName.getSheetId();
255
249
  if (realSubUnitId) commandParams.subUnitId = realSubUnitId;
256
250
  else this._logService.error("[ReplayService]", `failed to find subunit by subUnitName = ${commandParams.subUnitId}`);
257
251
  }
258
- if (mode === ReplayMode.ACTIVE && commandParams.subUnitId !== "undefined") {
252
+ if (mode === "active" && commandParams.subUnitId !== "undefined") {
259
253
  var _getActiveSheet;
260
254
  const realSubUnitId = (_getActiveSheet = this._instanceService.getFocusedUnit().getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId();
261
255
  if (realSubUnitId) commandParams.subUnitId = realSubUnitId;
@@ -314,7 +308,7 @@ const ReplayLocalRecordOnNamesakeCommand = {
314
308
  id: "action-recorder.command.replay-local-records-name",
315
309
  type: _univerjs_core.CommandType.COMMAND,
316
310
  handler: async (accessor) => {
317
- const result = await accessor.get(ActionReplayService).replayLocalJSON(ReplayMode.NAME);
311
+ const result = await accessor.get(ActionReplayService).replayLocalJSON("name");
318
312
  if (result) accessor.get(_univerjs_ui.IMessageService).show({
319
313
  type: _univerjs_design.MessageType.Success,
320
314
  content: "Successfully replayed local records"
@@ -326,7 +320,7 @@ const ReplayLocalRecordOnActiveCommand = {
326
320
  id: "action-recorder.command.replay-local-records-active",
327
321
  type: _univerjs_core.CommandType.COMMAND,
328
322
  handler: async (accessor) => {
329
- const result = await accessor.get(ActionReplayService).replayLocalJSON(ReplayMode.ACTIVE);
323
+ const result = await accessor.get(ActionReplayService).replayLocalJSON("active");
330
324
  if (result) accessor.get(_univerjs_ui.IMessageService).show({
331
325
  type: _univerjs_design.MessageType.Success,
332
326
  content: "Successfully replayed local records"
package/lib/es/index.js CHANGED
@@ -11,7 +11,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
11
11
 
12
12
  //#region package.json
13
13
  var name = "@univerjs/action-recorder";
14
- var version = "0.21.1";
14
+ var version = "0.22.0";
15
15
 
16
16
  //#endregion
17
17
  //#region src/config/config.ts
@@ -20,7 +20,7 @@ const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
20
20
  const defaultPluginConfig = {};
21
21
 
22
22
  //#endregion
23
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
23
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
24
24
  function _typeof(o) {
25
25
  "@babel/helpers - typeof";
26
26
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -31,7 +31,7 @@ function _typeof(o) {
31
31
  }
32
32
 
33
33
  //#endregion
34
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
34
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
35
35
  function toPrimitive(t, r) {
36
36
  if ("object" != _typeof(t) || !t) return t;
37
37
  var e = t[Symbol.toPrimitive];
@@ -44,14 +44,14 @@ function toPrimitive(t, r) {
44
44
  }
45
45
 
46
46
  //#endregion
47
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
47
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
48
48
  function toPropertyKey(t) {
49
49
  var i = toPrimitive(t, "string");
50
50
  return "symbol" == _typeof(i) ? i : i + "";
51
51
  }
52
52
 
53
53
  //#endregion
54
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
54
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
55
55
  function _defineProperty(e, r, t) {
56
56
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
57
57
  value: t,
@@ -62,7 +62,7 @@ function _defineProperty(e, r, t) {
62
62
  }
63
63
 
64
64
  //#endregion
65
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
65
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
66
66
  function __decorateParam(paramIndex, decorator) {
67
67
  return function(target, key) {
68
68
  decorator(target, key, paramIndex);
@@ -70,7 +70,7 @@ function __decorateParam(paramIndex, decorator) {
70
70
  }
71
71
 
72
72
  //#endregion
73
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
73
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
74
74
  function __decorate(decorators, target, key, desc) {
75
75
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
76
76
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -198,12 +198,6 @@ const StopRecordingActionCommand = {
198
198
 
199
199
  //#endregion
200
200
  //#region src/services/replay.service.ts
201
- let ReplayMode = /* @__PURE__ */ function(ReplayMode) {
202
- ReplayMode["DEFAULT"] = "default";
203
- ReplayMode["NAME"] = "name";
204
- ReplayMode["ACTIVE"] = "active";
205
- return ReplayMode;
206
- }({});
207
201
  let ActionReplayService = class ActionReplayService extends Disposable {
208
202
  constructor(_messageService, _instanceService, _localFileService, _logService, _commandService) {
209
203
  super();
@@ -216,7 +210,7 @@ let ActionReplayService = class ActionReplayService extends Disposable {
216
210
  /**
217
211
  * Read a local file and try to replay commands in this JSON.
218
212
  */
219
- async replayLocalJSON(mode = ReplayMode.DEFAULT) {
213
+ async replayLocalJSON(mode = "default") {
220
214
  const files = await this._localFileService.openFile({
221
215
  multiple: false,
222
216
  accept: ".json"
@@ -248,13 +242,13 @@ let ActionReplayService = class ActionReplayService extends Disposable {
248
242
  const commandParams = params;
249
243
  if (commandParams) {
250
244
  if (typeof commandParams.unitId !== "undefined") commandParams.unitId = focusedUnitId;
251
- if (mode === ReplayMode.NAME && commandParams.subUnitId !== "undefined") {
245
+ if (mode === "name" && commandParams.subUnitId !== "undefined") {
252
246
  var _getSheetBySheetName;
253
247
  const realSubUnitId = (_getSheetBySheetName = this._instanceService.getFocusedUnit().getSheetBySheetName(commandParams.subUnitId)) === null || _getSheetBySheetName === void 0 ? void 0 : _getSheetBySheetName.getSheetId();
254
248
  if (realSubUnitId) commandParams.subUnitId = realSubUnitId;
255
249
  else this._logService.error("[ReplayService]", `failed to find subunit by subUnitName = ${commandParams.subUnitId}`);
256
250
  }
257
- if (mode === ReplayMode.ACTIVE && commandParams.subUnitId !== "undefined") {
251
+ if (mode === "active" && commandParams.subUnitId !== "undefined") {
258
252
  var _getActiveSheet;
259
253
  const realSubUnitId = (_getActiveSheet = this._instanceService.getFocusedUnit().getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId();
260
254
  if (realSubUnitId) commandParams.subUnitId = realSubUnitId;
@@ -313,7 +307,7 @@ const ReplayLocalRecordOnNamesakeCommand = {
313
307
  id: "action-recorder.command.replay-local-records-name",
314
308
  type: CommandType.COMMAND,
315
309
  handler: async (accessor) => {
316
- const result = await accessor.get(ActionReplayService).replayLocalJSON(ReplayMode.NAME);
310
+ const result = await accessor.get(ActionReplayService).replayLocalJSON("name");
317
311
  if (result) accessor.get(IMessageService).show({
318
312
  type: MessageType.Success,
319
313
  content: "Successfully replayed local records"
@@ -325,7 +319,7 @@ const ReplayLocalRecordOnActiveCommand = {
325
319
  id: "action-recorder.command.replay-local-records-active",
326
320
  type: CommandType.COMMAND,
327
321
  handler: async (accessor) => {
328
- const result = await accessor.get(ActionReplayService).replayLocalJSON(ReplayMode.ACTIVE);
322
+ const result = await accessor.get(ActionReplayService).replayLocalJSON("active");
329
323
  if (result) accessor.get(IMessageService).show({
330
324
  type: MessageType.Success,
331
325
  content: "Successfully replayed local records"
package/lib/index.js CHANGED
@@ -11,7 +11,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
11
11
 
12
12
  //#region package.json
13
13
  var name = "@univerjs/action-recorder";
14
- var version = "0.21.1";
14
+ var version = "0.22.0";
15
15
 
16
16
  //#endregion
17
17
  //#region src/config/config.ts
@@ -20,7 +20,7 @@ const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
20
20
  const defaultPluginConfig = {};
21
21
 
22
22
  //#endregion
23
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
23
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
24
24
  function _typeof(o) {
25
25
  "@babel/helpers - typeof";
26
26
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -31,7 +31,7 @@ function _typeof(o) {
31
31
  }
32
32
 
33
33
  //#endregion
34
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
34
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
35
35
  function toPrimitive(t, r) {
36
36
  if ("object" != _typeof(t) || !t) return t;
37
37
  var e = t[Symbol.toPrimitive];
@@ -44,14 +44,14 @@ function toPrimitive(t, r) {
44
44
  }
45
45
 
46
46
  //#endregion
47
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
47
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
48
48
  function toPropertyKey(t) {
49
49
  var i = toPrimitive(t, "string");
50
50
  return "symbol" == _typeof(i) ? i : i + "";
51
51
  }
52
52
 
53
53
  //#endregion
54
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
54
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
55
55
  function _defineProperty(e, r, t) {
56
56
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
57
57
  value: t,
@@ -62,7 +62,7 @@ function _defineProperty(e, r, t) {
62
62
  }
63
63
 
64
64
  //#endregion
65
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
65
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
66
66
  function __decorateParam(paramIndex, decorator) {
67
67
  return function(target, key) {
68
68
  decorator(target, key, paramIndex);
@@ -70,7 +70,7 @@ function __decorateParam(paramIndex, decorator) {
70
70
  }
71
71
 
72
72
  //#endregion
73
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
73
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
74
74
  function __decorate(decorators, target, key, desc) {
75
75
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
76
76
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -198,12 +198,6 @@ const StopRecordingActionCommand = {
198
198
 
199
199
  //#endregion
200
200
  //#region src/services/replay.service.ts
201
- let ReplayMode = /* @__PURE__ */ function(ReplayMode) {
202
- ReplayMode["DEFAULT"] = "default";
203
- ReplayMode["NAME"] = "name";
204
- ReplayMode["ACTIVE"] = "active";
205
- return ReplayMode;
206
- }({});
207
201
  let ActionReplayService = class ActionReplayService extends Disposable {
208
202
  constructor(_messageService, _instanceService, _localFileService, _logService, _commandService) {
209
203
  super();
@@ -216,7 +210,7 @@ let ActionReplayService = class ActionReplayService extends Disposable {
216
210
  /**
217
211
  * Read a local file and try to replay commands in this JSON.
218
212
  */
219
- async replayLocalJSON(mode = ReplayMode.DEFAULT) {
213
+ async replayLocalJSON(mode = "default") {
220
214
  const files = await this._localFileService.openFile({
221
215
  multiple: false,
222
216
  accept: ".json"
@@ -248,13 +242,13 @@ let ActionReplayService = class ActionReplayService extends Disposable {
248
242
  const commandParams = params;
249
243
  if (commandParams) {
250
244
  if (typeof commandParams.unitId !== "undefined") commandParams.unitId = focusedUnitId;
251
- if (mode === ReplayMode.NAME && commandParams.subUnitId !== "undefined") {
245
+ if (mode === "name" && commandParams.subUnitId !== "undefined") {
252
246
  var _getSheetBySheetName;
253
247
  const realSubUnitId = (_getSheetBySheetName = this._instanceService.getFocusedUnit().getSheetBySheetName(commandParams.subUnitId)) === null || _getSheetBySheetName === void 0 ? void 0 : _getSheetBySheetName.getSheetId();
254
248
  if (realSubUnitId) commandParams.subUnitId = realSubUnitId;
255
249
  else this._logService.error("[ReplayService]", `failed to find subunit by subUnitName = ${commandParams.subUnitId}`);
256
250
  }
257
- if (mode === ReplayMode.ACTIVE && commandParams.subUnitId !== "undefined") {
251
+ if (mode === "active" && commandParams.subUnitId !== "undefined") {
258
252
  var _getActiveSheet;
259
253
  const realSubUnitId = (_getActiveSheet = this._instanceService.getFocusedUnit().getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId();
260
254
  if (realSubUnitId) commandParams.subUnitId = realSubUnitId;
@@ -313,7 +307,7 @@ const ReplayLocalRecordOnNamesakeCommand = {
313
307
  id: "action-recorder.command.replay-local-records-name",
314
308
  type: CommandType.COMMAND,
315
309
  handler: async (accessor) => {
316
- const result = await accessor.get(ActionReplayService).replayLocalJSON(ReplayMode.NAME);
310
+ const result = await accessor.get(ActionReplayService).replayLocalJSON("name");
317
311
  if (result) accessor.get(IMessageService).show({
318
312
  type: MessageType.Success,
319
313
  content: "Successfully replayed local records"
@@ -325,7 +319,7 @@ const ReplayLocalRecordOnActiveCommand = {
325
319
  id: "action-recorder.command.replay-local-records-active",
326
320
  type: CommandType.COMMAND,
327
321
  handler: async (accessor) => {
328
- const result = await accessor.get(ActionReplayService).replayLocalJSON(ReplayMode.ACTIVE);
322
+ const result = await accessor.get(ActionReplayService).replayLocalJSON("active");
329
323
  if (result) accessor.get(IMessageService).show({
330
324
  type: MessageType.Success,
331
325
  content: "Successfully replayed local records"
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`react`),require(`@univerjs/sheets`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets-ui`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`react`,`@univerjs/sheets`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverActionRecorder={},e.UniverCore,e.React,e.UniverSheets,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.rxjs,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=`@univerjs/action-recorder`,d=`0.21.1`;let f=`action-recorder.config`;Symbol(f);let p={};function m({ref:e,...t}){let{icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=(0,n.useRef)(`_${v()}`);return h(r,`${i}`,{defIds:r.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function h(e,t,r,i,a){return(0,n.createElement)(e.tag,{key:t,...g(e,r,a),...i},(_(e,r).children||[]).map((n,i)=>h(n,`${t}-${e.tag}-${i}`,r,void 0,a)))}function g(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function _(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function v(){return Math.random().toString(36).substring(2,8)}m.displayName=`UniverIcon`;let y={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{fill:`currentColor`,clipPath:`url(#record-icon_clip0_1559_19)`},children:[{tag:`path`,attrs:{d:`M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z`}},{tag:`path`,attrs:{d:`M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},{tag:`defs`,attrs:{},children:[{tag:`clipPath`,attrs:{id:`record-icon_clip0_1559_19`},children:[{tag:`path`,attrs:{fill:`white`,d:`M0 0H16V16H0z`,transform:`translate(.94)`}}]}]}],defIds:[`record-icon_clip0_1559_19`]},b=(0,n.forwardRef)(function(e,t){return(0,n.createElement)(m,Object.assign({},e,{id:`record-icon`,ref:t,icon:y}))});b.displayName=`RecordIcon`;function x(e){"@babel/helpers - typeof";return x=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},x(e)}function S(e,t){if(x(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(x(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function C(e){var t=S(e,`string`);return x(t)==`symbol`?t:t+``}function w(e,t,n){return(t=C(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function T(e,t){return function(n,r){t(n,r,e)}}function E(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let D=class extends t.Disposable{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,w(this,`_shouldRecordCommands`,new Set),w(this,`_panelOpened$`,new s.BehaviorSubject(!1)),w(this,`panelOpened$`,this._panelOpened$.asObservable()),w(this,`_recorder`,null),w(this,`_recording$`,new s.BehaviorSubject(!1)),w(this,`recording$`,this._recording$.asObservable()),w(this,`_recorded$`,new s.BehaviorSubject([])),w(this,`_recordedCommands$`,new s.BehaviorSubject([])),w(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(e){if(e.type===t.CommandType.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{if(this._shouldRecordCommands.has(n.id)){var i;let o=this._recorded,s=this._recordedCommands,c={...n},l=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:u=l,subUnitId:d}=c==null?void 0:c.params;if(e&&u&&d){var a;let e=(a=this._instanceService.getUnit(u).getSheetBySheetId(d))==null?void 0:a.getName();c={...c,params:{...c.params,subUnitId:e}}}c.id===r.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===r.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===t.CommandType.COMMAND&&(s.push(c),this._recordedCommands$.next(s)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){let e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),`recorded-commands.json`),this._logService.error(`Recorded commands:`,e),this.stopRecording()}};D=E([T(0,t.ICommandService),T(1,t.ILogService),T(2,o.ILocalFileService),T(3,t.IUniverInstanceService)],D);let O={id:`action-recorder.command.start-recording`,type:t.CommandType.COMMAND,handler:(e,t)=>(e.get(D).startRecording(!!(t!=null&&t.replaceId)),!0)},k={id:`action-recorder.command.complete-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},A={id:`action-recorder.command.stop-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},j=function(e){return e.DEFAULT=`default`,e.NAME=`name`,e.ACTIVE=`active`,e}({}),M=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=j.DEFAULT){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:c.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===j.NAME&&s.subUnitId!==`undefined`){var a;let e=(a=this._instanceService.getFocusedUnit().getSheetBySheetName(s.subUnitId))==null?void 0:a.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find subunit by subUnitName = ${s.subUnitId}`)}if(i===j.ACTIVE&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let n of e){await(0,t.awaitTime)(N());let{id:e,params:i}=n;if(i){if(i.unitId!==void 0&&(i.unitId=r),!await this._commandService.executeCommand(e,i))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};M=E([T(0,o.IMessageService),T(1,t.IUniverInstanceService),T(2,o.ILocalFileService),T(3,t.ILogService),T(4,t.ICommandService)],M);function N(){return Math.floor(Math.random()*800)+200}let P={id:`action-recorder.command.replay-local-records`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON();return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},F={id:`action-recorder.command.replay-local-records-name`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON(j.NAME);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},I={id:`action-recorder.command.replay-local-records-active`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(M).replayLocalJSON(j.ACTIVE);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},L={id:`action-recorder.operation.open-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!0),!0}},R={id:`action-recorder.operation.close-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!1),!0}},z=`RECORD_MENU_ITEM`;function B(){return{id:z,type:o.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function V(e){let t=e.get(D);return{id:L.id,title:`action-recorder.menu.record`,type:o.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function H(){return{id:P.id,title:`action-recorder.menu.replay-local`,type:o.MenuItemType.BUTTON}}function U(){return{id:F.id,title:`action-recorder.menu.replay-local-name`,type:o.MenuItemType.BUTTON}}function W(){return{id:I.id,title:`action-recorder.menu.replay-local-active`,type:o.MenuItemType.BUTTON}}let G={[o.RibbonOthersGroup.OTHERS]:{[z]:{order:1,menuItemFactory:B,[L.id]:{order:1,menuItemFactory:V},[P.id]:{order:2,menuItemFactory:H},[F.id]:{order:3,menuItemFactory:U},[I.id]:{order:4,menuItemFactory:W}}}};function K(){return(0,o.useObservable)((0,o.useDependency)(D).panelOpened$)?(0,l.jsx)(q,{}):null}function q(){var e;let r=(0,o.useDependency)(t.ICommandService),i=(0,o.useDependency)(D),a=(0,o.useObservable)(i.recording$),s=(0,o.useObservable)(i.recordedCommands$),u=(e=s==null?void 0:s.length)==null?0:e,d=(0,n.useCallback)(()=>{a||r.executeCommand(R.id)},[r,a]),f=(0,n.useCallback)(e=>{a||r.executeCommand(O.id,{replaceId:e})},[r,a]),p=(0,n.useCallback)(()=>{a&&r.executeCommand(k.id)},[r,a]),m=(0,n.useCallback)(()=>{a&&r.executeCommand(A.id)},[r,a]),h=a?u===0?`Recording...`:`${u}: ${s[u-1].id}`:`Start Recording`;return(0,l.jsxs)(`div`,{className:`univer-fixed univer-bottom-20 univer-left-1/2 univer-z-[1000] univer-flex univer-h-16 univer-w-[512px] -univer-translate-x-1/2 univer-items-center univer-rounded-lg univer-bg-white univer-px-5 univer-shadow-lg`,children:[(0,l.jsx)(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:(0,l.jsx)(b,{})}),(0,l.jsx)(`div`,{className:`univer-flex-1 univer-text-sm`,children:h}),(0,l.jsxs)(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[(0,l.jsx)(c.Button,{className:`univer-w-20`,onClick:a?m:d,children:a?`Cancel`:`Close`}),(0,l.jsx)(c.Button,{className:`univer-w-20`,variant:`primary`,onClick:a?p:()=>f(),children:a?`Save`:`Start`}),!a&&(0,l.jsx)(c.Button,{variant:`primary`,onClick:()=>f(!0),children:`Start(N)`})]})]})}let J=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[O,A,k,L,R,P,F,I].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(o.BuiltInUIPart.GLOBAL,()=>(0,o.connectInjector)(K,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,b)),this._menuManagerService.mergeMenu(G)}_initSheetsCommands(){[r.CopySheetCommand,r.DeleteRangeMoveLeftCommand,r.DeleteRangeMoveUpCommand,r.DeltaColumnWidthCommand,r.DeltaRowHeightCommand,r.InsertSheetCommand,r.InsertColAfterCommand,r.InsertColBeforeCommand,r.InsertRowAfterCommand,r.InsertRowBeforeCommand,r.RemoveSheetCommand,r.SetStyleCommand,r.AddWorksheetMergeCommand,r.AddWorksheetMergeAllCommand,r.AddWorksheetMergeVerticalCommand,r.AddWorksheetMergeHorizontalCommand,r.SetFrozenCommand,r.CancelFrozenCommand,r.SetHorizontalTextAlignCommand,r.SetOverlineCommand,a.SetRangeBoldCommand,a.SetRangeFontFamilyCommand,a.SetRangeFontSizeCommand,a.SetRangeItalicCommand,a.SetRangeStrickThroughCommand,a.SetRangeSubscriptCommand,a.SetRangeSuperscriptCommand,a.SetRangeTextColorCommand,a.SetRangeUnderlineCommand,r.SetRangeValuesCommand,r.SetStrikeThroughCommand,r.SetTextColorCommand,r.SetTextRotationCommand,r.SetTextWrapCommand,r.SetVerticalTextAlignCommand,a.SheetCopyCommand,a.SheetCutCommand,a.SheetPasteBesidesBorderCommand,a.SheetPasteColWidthCommand,a.SheetPasteCommand,a.SheetPasteFormatCommand,a.SheetPasteShortKeyCommand,a.SheetPasteValueCommand,r.AutoFillCommand,r.RefillCommand,r.SetWorksheetActivateCommand,r.SetWorksheetActiveOperation,r.SetSelectionsOperation,i.SetSheetFilterRangeCommand,i.SetSheetsFilterCriteriaCommand,i.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};J=E([T(0,t.ICommandService),T(1,o.IUIPartsService),T(2,o.IMenuManagerService),T(3,(0,t.Inject)(o.ComponentManager)),T(4,(0,t.Inject)(D)),T(5,(0,t.Inject)(t.Injector))],J);let Y=class extends t.Plugin{constructor(e=p,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},p,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(f,a)}onStarting(){(this._config.replayOnly?[[M]]:[[D],[M],[J]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(J)}};w(Y,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),w(Y,`packageName`,u),w(Y,`version`,d),Y=E([T(1,(0,t.Inject)(t.Injector)),T(2,t.IConfigService)],Y),Object.defineProperty(e,`ActionRecorderService`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(e,`ActionReplayService`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(e,`UniverActionRecorderPlugin`,{enumerable:!0,get:function(){return Y}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`react`),require(`@univerjs/sheets`),require(`@univerjs/sheets-filter`),require(`@univerjs/sheets-ui`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`react`,`@univerjs/sheets`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverActionRecorder={},e.UniverCore,e.React,e.UniverSheets,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.rxjs,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var u=`@univerjs/action-recorder`,d=`0.22.0`;let f=`action-recorder.config`;Symbol(f);let p={};function m({ref:e,...t}){let{icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),l=(0,n.useRef)(`_${v()}`);return h(r,`${i}`,{defIds:r.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function h(e,t,r,i,a){return(0,n.createElement)(e.tag,{key:t,...g(e,r,a),...i},(_(e,r).children||[]).map((n,i)=>h(n,`${t}-${e.tag}-${i}`,r,void 0,a)))}function g(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function _(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function v(){return Math.random().toString(36).substring(2,8)}m.displayName=`UniverIcon`;let y={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`g`,attrs:{fill:`currentColor`,clipPath:`url(#record-icon_clip0_1559_19)`},children:[{tag:`path`,attrs:{d:`M7.60303 10C8.7076 10 9.60303 9.10457 9.60303 8C9.60303 6.89543 8.7076 6 7.60303 6C6.49846 6 5.60303 6.89543 5.60303 8C5.60303 9.10457 6.49846 10 7.60303 10Z`}},{tag:`path`,attrs:{d:`M1.66943 5.29023C1.66941 3.85426 2.83349 2.69017 4.26946 2.69019L10.9362 2.69026C12.3192 2.69028 13.45 3.77008 13.5315 5.13259L14.5692 4.55638C15.3024 4.14929 16.2032 4.67947 16.2032 5.51809V10.4819C16.2032 11.3205 15.3024 11.8507 14.5692 11.4436L13.5315 10.8674C13.45 12.2299 12.3192 13.3097 10.9362 13.3097H4.26953C2.83361 13.3097 1.66956 12.1457 1.66953 10.7098L1.66943 5.29023ZM13.5362 9.49743L15.0032 10.312V5.68799L13.5362 6.50254V9.49743ZM4.26945 3.89019C3.49623 3.89018 2.86942 4.517 2.86943 5.29021L2.86953 10.7098C2.86955 11.483 3.49634 12.1097 4.26953 12.1097H10.9362C11.7094 12.1097 12.3362 11.4829 12.3362 10.7097V5.29026C12.3362 4.51707 11.7094 3.89027 10.9362 3.89026L4.26945 3.89019Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},{tag:`defs`,attrs:{},children:[{tag:`clipPath`,attrs:{id:`record-icon_clip0_1559_19`},children:[{tag:`path`,attrs:{fill:`white`,d:`M0 0H16V16H0z`,transform:`translate(.94)`}}]}]}],defIds:[`record-icon_clip0_1559_19`]},b=(0,n.forwardRef)(function(e,t){return(0,n.createElement)(m,Object.assign({},e,{id:`record-icon`,ref:t,icon:y}))});b.displayName=`RecordIcon`;function x(e){"@babel/helpers - typeof";return x=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},x(e)}function S(e,t){if(x(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(x(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function C(e){var t=S(e,`string`);return x(t)==`symbol`?t:t+``}function w(e,t,n){return(t=C(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function T(e,t){return function(n,r){t(n,r,e)}}function E(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let D=class extends t.Disposable{get recording(){return this._recording$.getValue()}get _recorded(){return this._recorded$.getValue()}get _recordedCommands(){return this._recordedCommands$.getValue()}constructor(e,t,n,r){super(),this._commandSrv=e,this._logService=t,this._localFileService=n,this._instanceService=r,w(this,`_shouldRecordCommands`,new Set),w(this,`_panelOpened$`,new s.BehaviorSubject(!1)),w(this,`panelOpened$`,this._panelOpened$.asObservable()),w(this,`_recorder`,null),w(this,`_recording$`,new s.BehaviorSubject(!1)),w(this,`recording$`,this._recording$.asObservable()),w(this,`_recorded$`,new s.BehaviorSubject([])),w(this,`_recordedCommands$`,new s.BehaviorSubject([])),w(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(e){if(e.type===t.CommandType.MUTATION)throw Error(`[CommandRecorderService] Cannot record mutation commands.`);this._shouldRecordCommands.add(e.id)}togglePanel(e){this._panelOpened$.next(e),e===!1&&this.stopRecording()}startRecording(e=!1){this._recorder=this._commandSrv.onCommandExecuted(n=>{if(this._shouldRecordCommands.has(n.id)){var i;let o=this._recorded,s=this._recordedCommands,c={...n},l=(i=this._instanceService.getFocusedUnit())==null?void 0:i.getUnitId(),{unitId:u=l,subUnitId:d}=c==null?void 0:c.params;if(e&&u&&d){var a;let e=(a=this._instanceService.getUnit(u).getSheetBySheetId(d))==null?void 0:a.getName();c={...c,params:{...c.params,subUnitId:e}}}c.id===r.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===r.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===t.CommandType.COMMAND&&(s.push(c),this._recordedCommands$.next(s)))}}),this._recording$.next(!0)}stopRecording(){var e;(e=this._recorder)==null||e.dispose(),this._recorder=null,this._recorded$.next([]),this._recordedCommands$.next([]),this._recording$.next(!1)}completeRecording(){let e=this._recorded.slice();this._localFileService.downloadFile(new Blob([JSON.stringify(e,null,2)]),`recorded-commands.json`),this._logService.error(`Recorded commands:`,e),this.stopRecording()}};D=E([T(0,t.ICommandService),T(1,t.ILogService),T(2,o.ILocalFileService),T(3,t.IUniverInstanceService)],D);let O={id:`action-recorder.command.start-recording`,type:t.CommandType.COMMAND,handler:(e,t)=>(e.get(D).startRecording(!!(t!=null&&t.replaceId)),!0)},k={id:`action-recorder.command.complete-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},A={id:`action-recorder.command.stop-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(D).completeRecording(),!0)},j=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._messageService=e,this._instanceService=t,this._localFileService=n,this._logService=r,this._commandService=i}async replayLocalJSON(e=`default`){let t=await this._localFileService.openFile({multiple:!1,accept:`.json`});if(t.length!==1)return!1;let n=t[0];try{return this.replayCommands(JSON.parse(await n.text()),{mode:e})}catch{return this._messageService.show({type:c.MessageType.Error,content:`Failed to replay commands from local file ${n.name}.`}),!1}}async replayCommands(e,t){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);let{mode:i}=t||{};for(let t of e){let{id:e,params:n}=t,s=n;if(s){if(s.unitId!==void 0&&(s.unitId=r),i===`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===`active`&&s.subUnitId!==`undefined`){var o;let e=(o=this._instanceService.getFocusedUnit().getActiveSheet())==null?void 0:o.getSheetId();e?s.subUnitId=e:this._logService.error(`[ReplayService]`,`failed to find active subunit`)}if(!await this._commandService.executeCommand(e,n))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}async replayCommandsWithDelay(e){var n;let r=(n=this._instanceService.getFocusedUnit())==null?void 0:n.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let n of e){await(0,t.awaitTime)(M());let{id:e,params:i}=n;if(i){if(i.unitId!==void 0&&(i.unitId=r),!await this._commandService.executeCommand(e,i))return!1}else if(!await this._commandService.executeCommand(e))return!1}return!0}};j=E([T(0,o.IMessageService),T(1,t.IUniverInstanceService),T(2,o.ILocalFileService),T(3,t.ILogService),T(4,t.ICommandService)],j);function M(){return Math.floor(Math.random()*800)+200}let N={id:`action-recorder.command.replay-local-records`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(j).replayLocalJSON();return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},P={id:`action-recorder.command.replay-local-records-name`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(j).replayLocalJSON(`name`);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},F={id:`action-recorder.command.replay-local-records-active`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(j).replayLocalJSON(`active`);return t&&e.get(o.IMessageService).show({type:c.MessageType.Success,content:`Successfully replayed local records`}),t}},I={id:`action-recorder.operation.open-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!0),!0}},L={id:`action-recorder.operation.close-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(D).togglePanel(!1),!0}},R=`RECORD_MENU_ITEM`;function z(){return{id:R,type:o.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function B(e){let t=e.get(D);return{id:I.id,title:`action-recorder.menu.record`,type:o.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function V(){return{id:N.id,title:`action-recorder.menu.replay-local`,type:o.MenuItemType.BUTTON}}function H(){return{id:P.id,title:`action-recorder.menu.replay-local-name`,type:o.MenuItemType.BUTTON}}function U(){return{id:F.id,title:`action-recorder.menu.replay-local-active`,type:o.MenuItemType.BUTTON}}let W={[o.RibbonOthersGroup.OTHERS]:{[R]:{order:1,menuItemFactory:z,[I.id]:{order:1,menuItemFactory:B},[N.id]:{order:2,menuItemFactory:V},[P.id]:{order:3,menuItemFactory:H},[F.id]:{order:4,menuItemFactory:U}}}};function G(){return(0,o.useObservable)((0,o.useDependency)(D).panelOpened$)?(0,l.jsx)(K,{}):null}function K(){var e;let r=(0,o.useDependency)(t.ICommandService),i=(0,o.useDependency)(D),a=(0,o.useObservable)(i.recording$),s=(0,o.useObservable)(i.recordedCommands$),u=(e=s==null?void 0:s.length)==null?0:e,d=(0,n.useCallback)(()=>{a||r.executeCommand(L.id)},[r,a]),f=(0,n.useCallback)(e=>{a||r.executeCommand(O.id,{replaceId:e})},[r,a]),p=(0,n.useCallback)(()=>{a&&r.executeCommand(k.id)},[r,a]),m=(0,n.useCallback)(()=>{a&&r.executeCommand(A.id)},[r,a]),h=a?u===0?`Recording...`:`${u}: ${s[u-1].id}`:`Start Recording`;return(0,l.jsxs)(`div`,{className:`univer-fixed univer-bottom-20 univer-left-1/2 univer-z-[1000] univer-flex univer-h-16 univer-w-[512px] -univer-translate-x-1/2 univer-items-center univer-rounded-lg univer-bg-white univer-px-5 univer-shadow-lg`,children:[(0,l.jsx)(`div`,{className:`univer-mr-2 univer-size-5 univer-shrink-0 univer-grow-0 univer-text-xl`,children:(0,l.jsx)(b,{})}),(0,l.jsx)(`div`,{className:`univer-flex-1 univer-text-sm`,children:h}),(0,l.jsxs)(`div`,{className:`univer-flex univer-w-64 univer-shrink-0 univer-grow-0 univer-justify-between`,children:[(0,l.jsx)(c.Button,{className:`univer-w-20`,onClick:a?m:d,children:a?`Cancel`:`Close`}),(0,l.jsx)(c.Button,{className:`univer-w-20`,variant:`primary`,onClick:a?p:()=>f(),children:a?`Save`:`Start`}),!a&&(0,l.jsx)(c.Button,{variant:`primary`,onClick:()=>f(!0),children:`Start(N)`})]})]})}let q=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._componentManager=r,this._actionRecorderService=i,this._injector=a,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[O,A,k,I,L,N,P,F].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(o.BuiltInUIPart.GLOBAL,()=>(0,o.connectInjector)(G,this._injector)),this.disposeWithMe(this._componentManager.register(`RecordIcon`,b)),this._menuManagerService.mergeMenu(W)}_initSheetsCommands(){[r.CopySheetCommand,r.DeleteRangeMoveLeftCommand,r.DeleteRangeMoveUpCommand,r.DeltaColumnWidthCommand,r.DeltaRowHeightCommand,r.InsertSheetCommand,r.InsertColAfterCommand,r.InsertColBeforeCommand,r.InsertRowAfterCommand,r.InsertRowBeforeCommand,r.RemoveSheetCommand,r.SetStyleCommand,r.AddWorksheetMergeCommand,r.AddWorksheetMergeAllCommand,r.AddWorksheetMergeVerticalCommand,r.AddWorksheetMergeHorizontalCommand,r.SetFrozenCommand,r.CancelFrozenCommand,r.SetHorizontalTextAlignCommand,r.SetOverlineCommand,a.SetRangeBoldCommand,a.SetRangeFontFamilyCommand,a.SetRangeFontSizeCommand,a.SetRangeItalicCommand,a.SetRangeStrickThroughCommand,a.SetRangeSubscriptCommand,a.SetRangeSuperscriptCommand,a.SetRangeTextColorCommand,a.SetRangeUnderlineCommand,r.SetRangeValuesCommand,r.SetStrikeThroughCommand,r.SetTextColorCommand,r.SetTextRotationCommand,r.SetTextWrapCommand,r.SetVerticalTextAlignCommand,a.SheetCopyCommand,a.SheetCutCommand,a.SheetPasteBesidesBorderCommand,a.SheetPasteColWidthCommand,a.SheetPasteCommand,a.SheetPasteFormatCommand,a.SheetPasteShortKeyCommand,a.SheetPasteValueCommand,r.AutoFillCommand,r.RefillCommand,r.SetWorksheetActivateCommand,r.SetWorksheetActiveOperation,r.SetSelectionsOperation,i.SetSheetFilterRangeCommand,i.SetSheetsFilterCriteriaCommand,i.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};q=E([T(0,t.ICommandService),T(1,o.IUIPartsService),T(2,o.IMenuManagerService),T(3,(0,t.Inject)(o.ComponentManager)),T(4,(0,t.Inject)(D)),T(5,(0,t.Inject)(t.Injector))],q);let J=class extends t.Plugin{constructor(e=p,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},p,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(f,a)}onStarting(){(this._config.replayOnly?[[j]]:[[D],[j],[q]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(q)}};w(J,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),w(J,`packageName`,u),w(J,`version`,d),J=E([T(1,(0,t.Inject)(t.Injector)),T(2,t.IConfigService)],J),Object.defineProperty(e,`ActionRecorderService`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(e,`ActionReplayService`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(e,`UniverActionRecorderPlugin`,{enumerable:!0,get:function(){return J}})});
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@univerjs/action-recorder",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
- "description": "",
6
- "author": "DreamNum <developer@univer.ai>",
5
+ "description": "Record and replay user actions in Univer.",
6
+ "author": "DreamNum Co., Ltd. <developer@univer.ai>",
7
7
  "license": "Apache-2.0",
8
8
  "funding": {
9
9
  "type": "opencollective",
@@ -17,7 +17,13 @@
17
17
  "bugs": {
18
18
  "url": "https://github.com/dream-num/univer/issues"
19
19
  },
20
- "keywords": [],
20
+ "keywords": [
21
+ "univer",
22
+ "action-recorder",
23
+ "replay",
24
+ "automation",
25
+ "plugin"
26
+ ],
21
27
  "exports": {
22
28
  ".": {
23
29
  "import": "./lib/es/index.js",
@@ -53,20 +59,20 @@
53
59
  },
54
60
  "dependencies": {
55
61
  "@univerjs/icons": "^1.1.1",
56
- "@univerjs/core": "0.21.1",
57
- "@univerjs/design": "0.21.1",
58
- "@univerjs/sheets": "0.21.1",
59
- "@univerjs/sheets-ui": "0.21.1",
60
- "@univerjs/ui": "0.21.1",
61
- "@univerjs/sheets-filter": "0.21.1"
62
+ "@univerjs/core": "0.22.0",
63
+ "@univerjs/sheets-filter": "0.22.0",
64
+ "@univerjs/sheets": "0.22.0",
65
+ "@univerjs/sheets-ui": "0.22.0",
66
+ "@univerjs/ui": "0.22.0",
67
+ "@univerjs/design": "0.22.0"
62
68
  },
63
69
  "devDependencies": {
64
70
  "react": "18.3.1",
65
71
  "rxjs": "^7.8.2",
66
72
  "tailwindcss": "3.4.18",
67
- "typescript": "^6.0.2",
68
- "vitest": "^4.1.4",
69
- "@univerjs-infra/shared": "0.21.1"
73
+ "typescript": "^6.0.3",
74
+ "vitest": "^4.1.5",
75
+ "@univerjs-infra/shared": "0.22.0"
70
76
  },
71
77
  "scripts": {
72
78
  "test": "vitest run",