@univerjs/action-recorder 1.0.0-alpha.2 → 1.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +175 -174
- package/lib/es/index.js +175 -175
- package/lib/index.js +175 -175
- package/lib/types/index.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +10 -10
package/lib/cjs/index.js
CHANGED
|
@@ -1,68 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
2
3
|
let _univerjs_core = require("@univerjs/core");
|
|
4
|
+
let _univerjs_design = require("@univerjs/design");
|
|
3
5
|
let _univerjs_sheets = require("@univerjs/sheets");
|
|
6
|
+
let rxjs = require("rxjs");
|
|
4
7
|
let _univerjs_sheets_filter = require("@univerjs/sheets-filter");
|
|
5
8
|
let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
|
|
6
|
-
let _univerjs_ui = require("@univerjs/ui");
|
|
7
|
-
let rxjs = require("rxjs");
|
|
8
|
-
let _univerjs_design = require("@univerjs/design");
|
|
9
9
|
let _univerjs_icons = require("@univerjs/icons");
|
|
10
10
|
let react = require("react");
|
|
11
11
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
12
|
|
|
13
|
-
//#region package.json
|
|
14
|
-
var name = "@univerjs/action-recorder";
|
|
15
|
-
var version = "1.0.0-alpha.2";
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/config/config.ts
|
|
19
|
-
const ACTION_RECORDER_PLUGIN_CONFIG_KEY = "action-recorder.config";
|
|
20
|
-
const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
|
|
21
|
-
const defaultPluginConfig = {};
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
25
|
-
function _typeof(o) {
|
|
26
|
-
"@babel/helpers - typeof";
|
|
27
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
28
|
-
return typeof o;
|
|
29
|
-
} : function(o) {
|
|
30
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
31
|
-
}, _typeof(o);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
36
|
-
function toPrimitive(t, r) {
|
|
37
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
38
|
-
var e = t[Symbol.toPrimitive];
|
|
39
|
-
if (void 0 !== e) {
|
|
40
|
-
var i = e.call(t, r || "default");
|
|
41
|
-
if ("object" != _typeof(i)) return i;
|
|
42
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
43
|
-
}
|
|
44
|
-
return ("string" === r ? String : Number)(t);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
49
|
-
function toPropertyKey(t) {
|
|
50
|
-
var i = toPrimitive(t, "string");
|
|
51
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
//#endregion
|
|
55
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
56
|
-
function _defineProperty(e, r, t) {
|
|
57
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
58
|
-
value: t,
|
|
59
|
-
enumerable: !0,
|
|
60
|
-
configurable: !0,
|
|
61
|
-
writable: !0
|
|
62
|
-
}) : e[r] = t, e;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
13
|
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
67
14
|
function __decorateParam(paramIndex, decorator) {
|
|
68
15
|
return function(target, key) {
|
|
@@ -79,124 +26,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
79
26
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
80
27
|
}
|
|
81
28
|
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/services/action-recorder.service.ts
|
|
84
|
-
let ActionRecorderService = class ActionRecorderService extends _univerjs_core.Disposable {
|
|
85
|
-
get recording() {
|
|
86
|
-
return this._recording$.getValue();
|
|
87
|
-
}
|
|
88
|
-
get _recorded() {
|
|
89
|
-
return this._recorded$.getValue();
|
|
90
|
-
}
|
|
91
|
-
get _recordedCommands() {
|
|
92
|
-
return this._recordedCommands$.getValue();
|
|
93
|
-
}
|
|
94
|
-
constructor(_commandSrv, _logService, _localFileService, _instanceService) {
|
|
95
|
-
super();
|
|
96
|
-
this._commandSrv = _commandSrv;
|
|
97
|
-
this._logService = _logService;
|
|
98
|
-
this._localFileService = _localFileService;
|
|
99
|
-
this._instanceService = _instanceService;
|
|
100
|
-
_defineProperty(this, "_shouldRecordCommands", /* @__PURE__ */ new Set());
|
|
101
|
-
_defineProperty(this, "_panelOpened$", new rxjs.BehaviorSubject(false));
|
|
102
|
-
_defineProperty(this, "panelOpened$", this._panelOpened$.asObservable());
|
|
103
|
-
_defineProperty(this, "_recorder", null);
|
|
104
|
-
_defineProperty(this, "_recording$", new rxjs.BehaviorSubject(false));
|
|
105
|
-
_defineProperty(this, "recording$", this._recording$.asObservable());
|
|
106
|
-
_defineProperty(this, "_recorded$", new rxjs.BehaviorSubject([]));
|
|
107
|
-
_defineProperty(this, "_recordedCommands$", new rxjs.BehaviorSubject([]));
|
|
108
|
-
_defineProperty(this, "recordedCommands$", this._recordedCommands$.asObservable());
|
|
109
|
-
}
|
|
110
|
-
registerRecordedCommand(command) {
|
|
111
|
-
if (command.type === _univerjs_core.CommandType.MUTATION) throw new Error("[CommandRecorderService] Cannot record mutation commands.");
|
|
112
|
-
this._shouldRecordCommands.add(command.id);
|
|
113
|
-
}
|
|
114
|
-
togglePanel(visible) {
|
|
115
|
-
this._panelOpened$.next(visible);
|
|
116
|
-
if (visible === false) this.stopRecording();
|
|
117
|
-
}
|
|
118
|
-
startRecording(replaceId = false) {
|
|
119
|
-
this._recorder = this._commandSrv.onCommandExecuted((rawCommandInfo) => {
|
|
120
|
-
if (this._shouldRecordCommands.has(rawCommandInfo.id)) {
|
|
121
|
-
var _this$_instanceServic;
|
|
122
|
-
const recorded = this._recorded;
|
|
123
|
-
const commands = this._recordedCommands;
|
|
124
|
-
let commandInfo = { ...rawCommandInfo };
|
|
125
|
-
const focusUnitId = (_this$_instanceServic = this._instanceService.getFocusedUnit()) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getUnitId();
|
|
126
|
-
const { unitId = focusUnitId, subUnitId } = commandInfo === null || commandInfo === void 0 ? void 0 : commandInfo.params;
|
|
127
|
-
if (replaceId && unitId && subUnitId) {
|
|
128
|
-
var _getSheetBySheetId;
|
|
129
|
-
const subUnitName = (_getSheetBySheetId = this._instanceService.getUnit(unitId).getSheetBySheetId(subUnitId)) === null || _getSheetBySheetId === void 0 ? void 0 : _getSheetBySheetId.getName();
|
|
130
|
-
commandInfo = {
|
|
131
|
-
...commandInfo,
|
|
132
|
-
params: {
|
|
133
|
-
...commandInfo.params,
|
|
134
|
-
subUnitId: subUnitName
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
if (commandInfo.id === _univerjs_sheets.SetSelectionsOperation.id && recorded.length > 0 && recorded[recorded.length - 1].id === _univerjs_sheets.SetSelectionsOperation.id) recorded[recorded.length - 1] = commandInfo;
|
|
139
|
-
else {
|
|
140
|
-
recorded.push(commandInfo);
|
|
141
|
-
this._recorded$.next(recorded);
|
|
142
|
-
if (commandInfo.type === _univerjs_core.CommandType.COMMAND) {
|
|
143
|
-
commands.push(commandInfo);
|
|
144
|
-
this._recordedCommands$.next(commands);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
this._recording$.next(true);
|
|
150
|
-
}
|
|
151
|
-
stopRecording() {
|
|
152
|
-
var _this$_recorder;
|
|
153
|
-
(_this$_recorder = this._recorder) === null || _this$_recorder === void 0 || _this$_recorder.dispose();
|
|
154
|
-
this._recorder = null;
|
|
155
|
-
this._recorded$.next([]);
|
|
156
|
-
this._recordedCommands$.next([]);
|
|
157
|
-
this._recording$.next(false);
|
|
158
|
-
}
|
|
159
|
-
completeRecording() {
|
|
160
|
-
const commands = this._recorded.slice();
|
|
161
|
-
this._localFileService.downloadFile(new Blob([JSON.stringify(commands, null, 2)]), "recorded-commands.json");
|
|
162
|
-
this._logService.error("Recorded commands:", commands);
|
|
163
|
-
this.stopRecording();
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
ActionRecorderService = __decorate([
|
|
167
|
-
__decorateParam(0, _univerjs_core.ICommandService),
|
|
168
|
-
__decorateParam(1, _univerjs_core.ILogService),
|
|
169
|
-
__decorateParam(2, _univerjs_ui.ILocalFileService),
|
|
170
|
-
__decorateParam(3, _univerjs_core.IUniverInstanceService)
|
|
171
|
-
], ActionRecorderService);
|
|
172
|
-
|
|
173
|
-
//#endregion
|
|
174
|
-
//#region src/commands/commands/record.command.ts
|
|
175
|
-
const StartRecordingActionCommand = {
|
|
176
|
-
id: "action-recorder.command.start-recording",
|
|
177
|
-
type: _univerjs_core.CommandType.COMMAND,
|
|
178
|
-
handler: (accessor, params) => {
|
|
179
|
-
accessor.get(ActionRecorderService).startRecording(!!(params === null || params === void 0 ? void 0 : params.replaceId));
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const CompleteRecordingActionCommand = {
|
|
184
|
-
id: "action-recorder.command.complete-recording",
|
|
185
|
-
type: _univerjs_core.CommandType.COMMAND,
|
|
186
|
-
handler: (accessor) => {
|
|
187
|
-
accessor.get(ActionRecorderService).completeRecording();
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
const StopRecordingActionCommand = {
|
|
192
|
-
id: "action-recorder.command.stop-recording",
|
|
193
|
-
type: _univerjs_core.CommandType.COMMAND,
|
|
194
|
-
handler: (accessor) => {
|
|
195
|
-
accessor.get(ActionRecorderService).completeRecording();
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
|
|
200
29
|
//#endregion
|
|
201
30
|
//#region src/services/replay.service.ts
|
|
202
31
|
let ActionReplayService = class ActionReplayService extends _univerjs_core.Disposable {
|
|
@@ -329,6 +158,139 @@ const ReplayLocalRecordOnActiveCommand = {
|
|
|
329
158
|
}
|
|
330
159
|
};
|
|
331
160
|
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
163
|
+
function _typeof(o) {
|
|
164
|
+
"@babel/helpers - typeof";
|
|
165
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
166
|
+
return typeof o;
|
|
167
|
+
} : function(o) {
|
|
168
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
169
|
+
}, _typeof(o);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
174
|
+
function toPrimitive(t, r) {
|
|
175
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
176
|
+
var e = t[Symbol.toPrimitive];
|
|
177
|
+
if (void 0 !== e) {
|
|
178
|
+
var i = e.call(t, r || "default");
|
|
179
|
+
if ("object" != _typeof(i)) return i;
|
|
180
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
181
|
+
}
|
|
182
|
+
return ("string" === r ? String : Number)(t);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
187
|
+
function toPropertyKey(t) {
|
|
188
|
+
var i = toPrimitive(t, "string");
|
|
189
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
194
|
+
function _defineProperty(e, r, t) {
|
|
195
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
196
|
+
value: t,
|
|
197
|
+
enumerable: !0,
|
|
198
|
+
configurable: !0,
|
|
199
|
+
writable: !0
|
|
200
|
+
}) : e[r] = t, e;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/services/action-recorder.service.ts
|
|
205
|
+
let ActionRecorderService = class ActionRecorderService extends _univerjs_core.Disposable {
|
|
206
|
+
get recording() {
|
|
207
|
+
return this._recording$.getValue();
|
|
208
|
+
}
|
|
209
|
+
get _recorded() {
|
|
210
|
+
return this._recorded$.getValue();
|
|
211
|
+
}
|
|
212
|
+
get _recordedCommands() {
|
|
213
|
+
return this._recordedCommands$.getValue();
|
|
214
|
+
}
|
|
215
|
+
constructor(_commandSrv, _logService, _localFileService, _instanceService) {
|
|
216
|
+
super();
|
|
217
|
+
this._commandSrv = _commandSrv;
|
|
218
|
+
this._logService = _logService;
|
|
219
|
+
this._localFileService = _localFileService;
|
|
220
|
+
this._instanceService = _instanceService;
|
|
221
|
+
_defineProperty(this, "_shouldRecordCommands", /* @__PURE__ */ new Set());
|
|
222
|
+
_defineProperty(this, "_panelOpened$", new rxjs.BehaviorSubject(false));
|
|
223
|
+
_defineProperty(this, "panelOpened$", this._panelOpened$.asObservable());
|
|
224
|
+
_defineProperty(this, "_recorder", null);
|
|
225
|
+
_defineProperty(this, "_recording$", new rxjs.BehaviorSubject(false));
|
|
226
|
+
_defineProperty(this, "recording$", this._recording$.asObservable());
|
|
227
|
+
_defineProperty(this, "_recorded$", new rxjs.BehaviorSubject([]));
|
|
228
|
+
_defineProperty(this, "_recordedCommands$", new rxjs.BehaviorSubject([]));
|
|
229
|
+
_defineProperty(this, "recordedCommands$", this._recordedCommands$.asObservable());
|
|
230
|
+
}
|
|
231
|
+
registerRecordedCommand(command) {
|
|
232
|
+
if (command.type === _univerjs_core.CommandType.MUTATION) throw new Error("[CommandRecorderService] Cannot record mutation commands.");
|
|
233
|
+
this._shouldRecordCommands.add(command.id);
|
|
234
|
+
}
|
|
235
|
+
togglePanel(visible) {
|
|
236
|
+
this._panelOpened$.next(visible);
|
|
237
|
+
if (visible === false) this.stopRecording();
|
|
238
|
+
}
|
|
239
|
+
startRecording(replaceId = false) {
|
|
240
|
+
this._recorder = this._commandSrv.onCommandExecuted((rawCommandInfo) => {
|
|
241
|
+
if (this._shouldRecordCommands.has(rawCommandInfo.id)) {
|
|
242
|
+
var _this$_instanceServic;
|
|
243
|
+
const recorded = this._recorded;
|
|
244
|
+
const commands = this._recordedCommands;
|
|
245
|
+
let commandInfo = { ...rawCommandInfo };
|
|
246
|
+
const focusUnitId = (_this$_instanceServic = this._instanceService.getFocusedUnit()) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getUnitId();
|
|
247
|
+
const { unitId = focusUnitId, subUnitId } = commandInfo === null || commandInfo === void 0 ? void 0 : commandInfo.params;
|
|
248
|
+
if (replaceId && unitId && subUnitId) {
|
|
249
|
+
var _getSheetBySheetId;
|
|
250
|
+
const subUnitName = (_getSheetBySheetId = this._instanceService.getUnit(unitId).getSheetBySheetId(subUnitId)) === null || _getSheetBySheetId === void 0 ? void 0 : _getSheetBySheetId.getName();
|
|
251
|
+
commandInfo = {
|
|
252
|
+
...commandInfo,
|
|
253
|
+
params: {
|
|
254
|
+
...commandInfo.params,
|
|
255
|
+
subUnitId: subUnitName
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
if (commandInfo.id === _univerjs_sheets.SetSelectionsOperation.id && recorded.length > 0 && recorded[recorded.length - 1].id === _univerjs_sheets.SetSelectionsOperation.id) recorded[recorded.length - 1] = commandInfo;
|
|
260
|
+
else {
|
|
261
|
+
recorded.push(commandInfo);
|
|
262
|
+
this._recorded$.next(recorded);
|
|
263
|
+
if (commandInfo.type === _univerjs_core.CommandType.COMMAND) {
|
|
264
|
+
commands.push(commandInfo);
|
|
265
|
+
this._recordedCommands$.next(commands);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
this._recording$.next(true);
|
|
271
|
+
}
|
|
272
|
+
stopRecording() {
|
|
273
|
+
var _this$_recorder;
|
|
274
|
+
(_this$_recorder = this._recorder) === null || _this$_recorder === void 0 || _this$_recorder.dispose();
|
|
275
|
+
this._recorder = null;
|
|
276
|
+
this._recorded$.next([]);
|
|
277
|
+
this._recordedCommands$.next([]);
|
|
278
|
+
this._recording$.next(false);
|
|
279
|
+
}
|
|
280
|
+
completeRecording() {
|
|
281
|
+
const commands = this._recorded.slice();
|
|
282
|
+
this._localFileService.downloadFile(new Blob([JSON.stringify(commands, null, 2)]), "recorded-commands.json");
|
|
283
|
+
this._logService.error("Recorded commands:", commands);
|
|
284
|
+
this.stopRecording();
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
ActionRecorderService = __decorate([
|
|
288
|
+
__decorateParam(0, _univerjs_core.ICommandService),
|
|
289
|
+
__decorateParam(1, _univerjs_core.ILogService),
|
|
290
|
+
__decorateParam(2, _univerjs_ui.ILocalFileService),
|
|
291
|
+
__decorateParam(3, _univerjs_core.IUniverInstanceService)
|
|
292
|
+
], ActionRecorderService);
|
|
293
|
+
|
|
332
294
|
//#endregion
|
|
333
295
|
//#region src/commands/operations/operation.ts
|
|
334
296
|
const OpenRecordPanelOperation = {
|
|
@@ -410,6 +372,44 @@ const menuSchema = { [_univerjs_ui.RibbonOthersGroup.OTHERS]: { [RECORD_MENU_ITE
|
|
|
410
372
|
}
|
|
411
373
|
} } };
|
|
412
374
|
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region package.json
|
|
377
|
+
var name = "@univerjs/action-recorder";
|
|
378
|
+
var version = "1.0.0-alpha.3";
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/config/config.ts
|
|
382
|
+
const ACTION_RECORDER_PLUGIN_CONFIG_KEY = "action-recorder.config";
|
|
383
|
+
const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
|
|
384
|
+
const defaultPluginConfig = {};
|
|
385
|
+
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region src/commands/commands/record.command.ts
|
|
388
|
+
const StartRecordingActionCommand = {
|
|
389
|
+
id: "action-recorder.command.start-recording",
|
|
390
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
391
|
+
handler: (accessor, params) => {
|
|
392
|
+
accessor.get(ActionRecorderService).startRecording(!!(params === null || params === void 0 ? void 0 : params.replaceId));
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
const CompleteRecordingActionCommand = {
|
|
397
|
+
id: "action-recorder.command.complete-recording",
|
|
398
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
399
|
+
handler: (accessor) => {
|
|
400
|
+
accessor.get(ActionRecorderService).completeRecording();
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const StopRecordingActionCommand = {
|
|
405
|
+
id: "action-recorder.command.stop-recording",
|
|
406
|
+
type: _univerjs_core.CommandType.COMMAND,
|
|
407
|
+
handler: (accessor) => {
|
|
408
|
+
accessor.get(ActionRecorderService).completeRecording();
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
413
413
|
//#endregion
|
|
414
414
|
//#region src/views/components/RecorderPanel.tsx
|
|
415
415
|
/**
|
|
@@ -660,6 +660,7 @@ _defineProperty(UniverActionRecorderPlugin, "version", version);
|
|
|
660
660
|
UniverActionRecorderPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverActionRecorderPlugin);
|
|
661
661
|
|
|
662
662
|
//#endregion
|
|
663
|
+
exports.ActionRecorderMenuSchema = menuSchema;
|
|
663
664
|
Object.defineProperty(exports, 'ActionRecorderService', {
|
|
664
665
|
enumerable: true,
|
|
665
666
|
get: function () {
|
package/lib/es/index.js
CHANGED
|
@@ -1,67 +1,14 @@
|
|
|
1
|
+
import { BuiltInUIPart, ComponentManager, ILocalFileService, IMenuManagerService, IMessageService, IUIPartsService, IconManager, MenuItemType, RibbonOthersGroup, connectInjector, useDependency, useObservable } from "@univerjs/ui";
|
|
1
2
|
import { CommandType, Disposable, ICommandService, IConfigService, ILogService, IUniverInstanceService, Inject, Injector, Plugin, awaitTime, merge } from "@univerjs/core";
|
|
3
|
+
import { Button, MessageType } from "@univerjs/design";
|
|
2
4
|
import { AddWorksheetMergeAllCommand, AddWorksheetMergeCommand, AddWorksheetMergeHorizontalCommand, AddWorksheetMergeVerticalCommand, AutoFillCommand, CancelFrozenCommand, CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, InsertColAfterCommand, InsertColBeforeCommand, InsertRowAfterCommand, InsertRowBeforeCommand, InsertSheetCommand, RefillCommand, RemoveSheetCommand, SetFrozenCommand, SetHorizontalTextAlignCommand, SetOverlineCommand, SetRangeValuesCommand, SetSelectionsOperation, SetStrikeThroughCommand, SetStyleCommand, SetTextColorCommand, SetTextRotationCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetActivateCommand, SetWorksheetActiveOperation } from "@univerjs/sheets";
|
|
5
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
6
|
import { RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from "@univerjs/sheets-filter";
|
|
4
7
|
import { SetRangeBoldCommand, SetRangeFontFamilyCommand, SetRangeFontSizeCommand, SetRangeItalicCommand, SetRangeStrickThroughCommand, SetRangeSubscriptCommand, SetRangeSuperscriptCommand, SetRangeTextColorCommand, SetRangeUnderlineCommand, SheetCopyCommand, SheetCutCommand, SheetPasteBesidesBorderCommand, SheetPasteColWidthCommand, SheetPasteCommand, SheetPasteFormatCommand, SheetPasteShortKeyCommand, SheetPasteValueCommand } from "@univerjs/sheets-ui";
|
|
5
|
-
import { BuiltInUIPart, ComponentManager, ILocalFileService, IMenuManagerService, IMessageService, IUIPartsService, IconManager, MenuItemType, RibbonOthersGroup, connectInjector, useDependency, useObservable } from "@univerjs/ui";
|
|
6
|
-
import { BehaviorSubject } from "rxjs";
|
|
7
|
-
import { Button, MessageType } from "@univerjs/design";
|
|
8
8
|
import { RecordIcon } from "@univerjs/icons";
|
|
9
9
|
import { useCallback } from "react";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
|
|
12
|
-
//#region package.json
|
|
13
|
-
var name = "@univerjs/action-recorder";
|
|
14
|
-
var version = "1.0.0-alpha.2";
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/config/config.ts
|
|
18
|
-
const ACTION_RECORDER_PLUGIN_CONFIG_KEY = "action-recorder.config";
|
|
19
|
-
const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
|
|
20
|
-
const defaultPluginConfig = {};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
24
|
-
function _typeof(o) {
|
|
25
|
-
"@babel/helpers - typeof";
|
|
26
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
27
|
-
return typeof o;
|
|
28
|
-
} : function(o) {
|
|
29
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
30
|
-
}, _typeof(o);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
35
|
-
function toPrimitive(t, r) {
|
|
36
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
37
|
-
var e = t[Symbol.toPrimitive];
|
|
38
|
-
if (void 0 !== e) {
|
|
39
|
-
var i = e.call(t, r || "default");
|
|
40
|
-
if ("object" != _typeof(i)) return i;
|
|
41
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
42
|
-
}
|
|
43
|
-
return ("string" === r ? String : Number)(t);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
48
|
-
function toPropertyKey(t) {
|
|
49
|
-
var i = toPrimitive(t, "string");
|
|
50
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
55
|
-
function _defineProperty(e, r, t) {
|
|
56
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
57
|
-
value: t,
|
|
58
|
-
enumerable: !0,
|
|
59
|
-
configurable: !0,
|
|
60
|
-
writable: !0
|
|
61
|
-
}) : e[r] = t, e;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
12
|
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
66
13
|
function __decorateParam(paramIndex, decorator) {
|
|
67
14
|
return function(target, key) {
|
|
@@ -78,124 +25,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
78
25
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
79
26
|
}
|
|
80
27
|
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/services/action-recorder.service.ts
|
|
83
|
-
let ActionRecorderService = class ActionRecorderService extends Disposable {
|
|
84
|
-
get recording() {
|
|
85
|
-
return this._recording$.getValue();
|
|
86
|
-
}
|
|
87
|
-
get _recorded() {
|
|
88
|
-
return this._recorded$.getValue();
|
|
89
|
-
}
|
|
90
|
-
get _recordedCommands() {
|
|
91
|
-
return this._recordedCommands$.getValue();
|
|
92
|
-
}
|
|
93
|
-
constructor(_commandSrv, _logService, _localFileService, _instanceService) {
|
|
94
|
-
super();
|
|
95
|
-
this._commandSrv = _commandSrv;
|
|
96
|
-
this._logService = _logService;
|
|
97
|
-
this._localFileService = _localFileService;
|
|
98
|
-
this._instanceService = _instanceService;
|
|
99
|
-
_defineProperty(this, "_shouldRecordCommands", /* @__PURE__ */ new Set());
|
|
100
|
-
_defineProperty(this, "_panelOpened$", new BehaviorSubject(false));
|
|
101
|
-
_defineProperty(this, "panelOpened$", this._panelOpened$.asObservable());
|
|
102
|
-
_defineProperty(this, "_recorder", null);
|
|
103
|
-
_defineProperty(this, "_recording$", new BehaviorSubject(false));
|
|
104
|
-
_defineProperty(this, "recording$", this._recording$.asObservable());
|
|
105
|
-
_defineProperty(this, "_recorded$", new BehaviorSubject([]));
|
|
106
|
-
_defineProperty(this, "_recordedCommands$", new BehaviorSubject([]));
|
|
107
|
-
_defineProperty(this, "recordedCommands$", this._recordedCommands$.asObservable());
|
|
108
|
-
}
|
|
109
|
-
registerRecordedCommand(command) {
|
|
110
|
-
if (command.type === CommandType.MUTATION) throw new Error("[CommandRecorderService] Cannot record mutation commands.");
|
|
111
|
-
this._shouldRecordCommands.add(command.id);
|
|
112
|
-
}
|
|
113
|
-
togglePanel(visible) {
|
|
114
|
-
this._panelOpened$.next(visible);
|
|
115
|
-
if (visible === false) this.stopRecording();
|
|
116
|
-
}
|
|
117
|
-
startRecording(replaceId = false) {
|
|
118
|
-
this._recorder = this._commandSrv.onCommandExecuted((rawCommandInfo) => {
|
|
119
|
-
if (this._shouldRecordCommands.has(rawCommandInfo.id)) {
|
|
120
|
-
var _this$_instanceServic;
|
|
121
|
-
const recorded = this._recorded;
|
|
122
|
-
const commands = this._recordedCommands;
|
|
123
|
-
let commandInfo = { ...rawCommandInfo };
|
|
124
|
-
const focusUnitId = (_this$_instanceServic = this._instanceService.getFocusedUnit()) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getUnitId();
|
|
125
|
-
const { unitId = focusUnitId, subUnitId } = commandInfo === null || commandInfo === void 0 ? void 0 : commandInfo.params;
|
|
126
|
-
if (replaceId && unitId && subUnitId) {
|
|
127
|
-
var _getSheetBySheetId;
|
|
128
|
-
const subUnitName = (_getSheetBySheetId = this._instanceService.getUnit(unitId).getSheetBySheetId(subUnitId)) === null || _getSheetBySheetId === void 0 ? void 0 : _getSheetBySheetId.getName();
|
|
129
|
-
commandInfo = {
|
|
130
|
-
...commandInfo,
|
|
131
|
-
params: {
|
|
132
|
-
...commandInfo.params,
|
|
133
|
-
subUnitId: subUnitName
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
if (commandInfo.id === SetSelectionsOperation.id && recorded.length > 0 && recorded[recorded.length - 1].id === SetSelectionsOperation.id) recorded[recorded.length - 1] = commandInfo;
|
|
138
|
-
else {
|
|
139
|
-
recorded.push(commandInfo);
|
|
140
|
-
this._recorded$.next(recorded);
|
|
141
|
-
if (commandInfo.type === CommandType.COMMAND) {
|
|
142
|
-
commands.push(commandInfo);
|
|
143
|
-
this._recordedCommands$.next(commands);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
this._recording$.next(true);
|
|
149
|
-
}
|
|
150
|
-
stopRecording() {
|
|
151
|
-
var _this$_recorder;
|
|
152
|
-
(_this$_recorder = this._recorder) === null || _this$_recorder === void 0 || _this$_recorder.dispose();
|
|
153
|
-
this._recorder = null;
|
|
154
|
-
this._recorded$.next([]);
|
|
155
|
-
this._recordedCommands$.next([]);
|
|
156
|
-
this._recording$.next(false);
|
|
157
|
-
}
|
|
158
|
-
completeRecording() {
|
|
159
|
-
const commands = this._recorded.slice();
|
|
160
|
-
this._localFileService.downloadFile(new Blob([JSON.stringify(commands, null, 2)]), "recorded-commands.json");
|
|
161
|
-
this._logService.error("Recorded commands:", commands);
|
|
162
|
-
this.stopRecording();
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
ActionRecorderService = __decorate([
|
|
166
|
-
__decorateParam(0, ICommandService),
|
|
167
|
-
__decorateParam(1, ILogService),
|
|
168
|
-
__decorateParam(2, ILocalFileService),
|
|
169
|
-
__decorateParam(3, IUniverInstanceService)
|
|
170
|
-
], ActionRecorderService);
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/commands/commands/record.command.ts
|
|
174
|
-
const StartRecordingActionCommand = {
|
|
175
|
-
id: "action-recorder.command.start-recording",
|
|
176
|
-
type: CommandType.COMMAND,
|
|
177
|
-
handler: (accessor, params) => {
|
|
178
|
-
accessor.get(ActionRecorderService).startRecording(!!(params === null || params === void 0 ? void 0 : params.replaceId));
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const CompleteRecordingActionCommand = {
|
|
183
|
-
id: "action-recorder.command.complete-recording",
|
|
184
|
-
type: CommandType.COMMAND,
|
|
185
|
-
handler: (accessor) => {
|
|
186
|
-
accessor.get(ActionRecorderService).completeRecording();
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
const StopRecordingActionCommand = {
|
|
191
|
-
id: "action-recorder.command.stop-recording",
|
|
192
|
-
type: CommandType.COMMAND,
|
|
193
|
-
handler: (accessor) => {
|
|
194
|
-
accessor.get(ActionRecorderService).completeRecording();
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
28
|
//#endregion
|
|
200
29
|
//#region src/services/replay.service.ts
|
|
201
30
|
let ActionReplayService = class ActionReplayService extends Disposable {
|
|
@@ -328,6 +157,139 @@ const ReplayLocalRecordOnActiveCommand = {
|
|
|
328
157
|
}
|
|
329
158
|
};
|
|
330
159
|
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
162
|
+
function _typeof(o) {
|
|
163
|
+
"@babel/helpers - typeof";
|
|
164
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
165
|
+
return typeof o;
|
|
166
|
+
} : function(o) {
|
|
167
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
168
|
+
}, _typeof(o);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
173
|
+
function toPrimitive(t, r) {
|
|
174
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
175
|
+
var e = t[Symbol.toPrimitive];
|
|
176
|
+
if (void 0 !== e) {
|
|
177
|
+
var i = e.call(t, r || "default");
|
|
178
|
+
if ("object" != _typeof(i)) return i;
|
|
179
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
180
|
+
}
|
|
181
|
+
return ("string" === r ? String : Number)(t);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
186
|
+
function toPropertyKey(t) {
|
|
187
|
+
var i = toPrimitive(t, "string");
|
|
188
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
193
|
+
function _defineProperty(e, r, t) {
|
|
194
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
195
|
+
value: t,
|
|
196
|
+
enumerable: !0,
|
|
197
|
+
configurable: !0,
|
|
198
|
+
writable: !0
|
|
199
|
+
}) : e[r] = t, e;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/services/action-recorder.service.ts
|
|
204
|
+
let ActionRecorderService = class ActionRecorderService extends Disposable {
|
|
205
|
+
get recording() {
|
|
206
|
+
return this._recording$.getValue();
|
|
207
|
+
}
|
|
208
|
+
get _recorded() {
|
|
209
|
+
return this._recorded$.getValue();
|
|
210
|
+
}
|
|
211
|
+
get _recordedCommands() {
|
|
212
|
+
return this._recordedCommands$.getValue();
|
|
213
|
+
}
|
|
214
|
+
constructor(_commandSrv, _logService, _localFileService, _instanceService) {
|
|
215
|
+
super();
|
|
216
|
+
this._commandSrv = _commandSrv;
|
|
217
|
+
this._logService = _logService;
|
|
218
|
+
this._localFileService = _localFileService;
|
|
219
|
+
this._instanceService = _instanceService;
|
|
220
|
+
_defineProperty(this, "_shouldRecordCommands", /* @__PURE__ */ new Set());
|
|
221
|
+
_defineProperty(this, "_panelOpened$", new BehaviorSubject(false));
|
|
222
|
+
_defineProperty(this, "panelOpened$", this._panelOpened$.asObservable());
|
|
223
|
+
_defineProperty(this, "_recorder", null);
|
|
224
|
+
_defineProperty(this, "_recording$", new BehaviorSubject(false));
|
|
225
|
+
_defineProperty(this, "recording$", this._recording$.asObservable());
|
|
226
|
+
_defineProperty(this, "_recorded$", new BehaviorSubject([]));
|
|
227
|
+
_defineProperty(this, "_recordedCommands$", new BehaviorSubject([]));
|
|
228
|
+
_defineProperty(this, "recordedCommands$", this._recordedCommands$.asObservable());
|
|
229
|
+
}
|
|
230
|
+
registerRecordedCommand(command) {
|
|
231
|
+
if (command.type === CommandType.MUTATION) throw new Error("[CommandRecorderService] Cannot record mutation commands.");
|
|
232
|
+
this._shouldRecordCommands.add(command.id);
|
|
233
|
+
}
|
|
234
|
+
togglePanel(visible) {
|
|
235
|
+
this._panelOpened$.next(visible);
|
|
236
|
+
if (visible === false) this.stopRecording();
|
|
237
|
+
}
|
|
238
|
+
startRecording(replaceId = false) {
|
|
239
|
+
this._recorder = this._commandSrv.onCommandExecuted((rawCommandInfo) => {
|
|
240
|
+
if (this._shouldRecordCommands.has(rawCommandInfo.id)) {
|
|
241
|
+
var _this$_instanceServic;
|
|
242
|
+
const recorded = this._recorded;
|
|
243
|
+
const commands = this._recordedCommands;
|
|
244
|
+
let commandInfo = { ...rawCommandInfo };
|
|
245
|
+
const focusUnitId = (_this$_instanceServic = this._instanceService.getFocusedUnit()) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getUnitId();
|
|
246
|
+
const { unitId = focusUnitId, subUnitId } = commandInfo === null || commandInfo === void 0 ? void 0 : commandInfo.params;
|
|
247
|
+
if (replaceId && unitId && subUnitId) {
|
|
248
|
+
var _getSheetBySheetId;
|
|
249
|
+
const subUnitName = (_getSheetBySheetId = this._instanceService.getUnit(unitId).getSheetBySheetId(subUnitId)) === null || _getSheetBySheetId === void 0 ? void 0 : _getSheetBySheetId.getName();
|
|
250
|
+
commandInfo = {
|
|
251
|
+
...commandInfo,
|
|
252
|
+
params: {
|
|
253
|
+
...commandInfo.params,
|
|
254
|
+
subUnitId: subUnitName
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (commandInfo.id === SetSelectionsOperation.id && recorded.length > 0 && recorded[recorded.length - 1].id === SetSelectionsOperation.id) recorded[recorded.length - 1] = commandInfo;
|
|
259
|
+
else {
|
|
260
|
+
recorded.push(commandInfo);
|
|
261
|
+
this._recorded$.next(recorded);
|
|
262
|
+
if (commandInfo.type === CommandType.COMMAND) {
|
|
263
|
+
commands.push(commandInfo);
|
|
264
|
+
this._recordedCommands$.next(commands);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
this._recording$.next(true);
|
|
270
|
+
}
|
|
271
|
+
stopRecording() {
|
|
272
|
+
var _this$_recorder;
|
|
273
|
+
(_this$_recorder = this._recorder) === null || _this$_recorder === void 0 || _this$_recorder.dispose();
|
|
274
|
+
this._recorder = null;
|
|
275
|
+
this._recorded$.next([]);
|
|
276
|
+
this._recordedCommands$.next([]);
|
|
277
|
+
this._recording$.next(false);
|
|
278
|
+
}
|
|
279
|
+
completeRecording() {
|
|
280
|
+
const commands = this._recorded.slice();
|
|
281
|
+
this._localFileService.downloadFile(new Blob([JSON.stringify(commands, null, 2)]), "recorded-commands.json");
|
|
282
|
+
this._logService.error("Recorded commands:", commands);
|
|
283
|
+
this.stopRecording();
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
ActionRecorderService = __decorate([
|
|
287
|
+
__decorateParam(0, ICommandService),
|
|
288
|
+
__decorateParam(1, ILogService),
|
|
289
|
+
__decorateParam(2, ILocalFileService),
|
|
290
|
+
__decorateParam(3, IUniverInstanceService)
|
|
291
|
+
], ActionRecorderService);
|
|
292
|
+
|
|
331
293
|
//#endregion
|
|
332
294
|
//#region src/commands/operations/operation.ts
|
|
333
295
|
const OpenRecordPanelOperation = {
|
|
@@ -409,6 +371,44 @@ const menuSchema = { [RibbonOthersGroup.OTHERS]: { [RECORD_MENU_ITEM_ID]: {
|
|
|
409
371
|
}
|
|
410
372
|
} } };
|
|
411
373
|
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region package.json
|
|
376
|
+
var name = "@univerjs/action-recorder";
|
|
377
|
+
var version = "1.0.0-alpha.3";
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/config/config.ts
|
|
381
|
+
const ACTION_RECORDER_PLUGIN_CONFIG_KEY = "action-recorder.config";
|
|
382
|
+
const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
|
|
383
|
+
const defaultPluginConfig = {};
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/commands/commands/record.command.ts
|
|
387
|
+
const StartRecordingActionCommand = {
|
|
388
|
+
id: "action-recorder.command.start-recording",
|
|
389
|
+
type: CommandType.COMMAND,
|
|
390
|
+
handler: (accessor, params) => {
|
|
391
|
+
accessor.get(ActionRecorderService).startRecording(!!(params === null || params === void 0 ? void 0 : params.replaceId));
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const CompleteRecordingActionCommand = {
|
|
396
|
+
id: "action-recorder.command.complete-recording",
|
|
397
|
+
type: CommandType.COMMAND,
|
|
398
|
+
handler: (accessor) => {
|
|
399
|
+
accessor.get(ActionRecorderService).completeRecording();
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
const StopRecordingActionCommand = {
|
|
404
|
+
id: "action-recorder.command.stop-recording",
|
|
405
|
+
type: CommandType.COMMAND,
|
|
406
|
+
handler: (accessor) => {
|
|
407
|
+
accessor.get(ActionRecorderService).completeRecording();
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/views/components/RecorderPanel.tsx
|
|
414
414
|
/**
|
|
@@ -659,4 +659,4 @@ _defineProperty(UniverActionRecorderPlugin, "version", version);
|
|
|
659
659
|
UniverActionRecorderPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverActionRecorderPlugin);
|
|
660
660
|
|
|
661
661
|
//#endregion
|
|
662
|
-
export { ActionRecorderService, ActionReplayService, UniverActionRecorderPlugin };
|
|
662
|
+
export { menuSchema as ActionRecorderMenuSchema, ActionRecorderService, ActionReplayService, UniverActionRecorderPlugin };
|
package/lib/index.js
CHANGED
|
@@ -1,67 +1,14 @@
|
|
|
1
|
+
import { BuiltInUIPart, ComponentManager, ILocalFileService, IMenuManagerService, IMessageService, IUIPartsService, IconManager, MenuItemType, RibbonOthersGroup, connectInjector, useDependency, useObservable } from "@univerjs/ui";
|
|
1
2
|
import { CommandType, Disposable, ICommandService, IConfigService, ILogService, IUniverInstanceService, Inject, Injector, Plugin, awaitTime, merge } from "@univerjs/core";
|
|
3
|
+
import { Button, MessageType } from "@univerjs/design";
|
|
2
4
|
import { AddWorksheetMergeAllCommand, AddWorksheetMergeCommand, AddWorksheetMergeHorizontalCommand, AddWorksheetMergeVerticalCommand, AutoFillCommand, CancelFrozenCommand, CopySheetCommand, DeleteRangeMoveLeftCommand, DeleteRangeMoveUpCommand, DeltaColumnWidthCommand, DeltaRowHeightCommand, InsertColAfterCommand, InsertColBeforeCommand, InsertRowAfterCommand, InsertRowBeforeCommand, InsertSheetCommand, RefillCommand, RemoveSheetCommand, SetFrozenCommand, SetHorizontalTextAlignCommand, SetOverlineCommand, SetRangeValuesCommand, SetSelectionsOperation, SetStrikeThroughCommand, SetStyleCommand, SetTextColorCommand, SetTextRotationCommand, SetTextWrapCommand, SetVerticalTextAlignCommand, SetWorksheetActivateCommand, SetWorksheetActiveOperation } from "@univerjs/sheets";
|
|
5
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
6
|
import { RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from "@univerjs/sheets-filter";
|
|
4
7
|
import { SetRangeBoldCommand, SetRangeFontFamilyCommand, SetRangeFontSizeCommand, SetRangeItalicCommand, SetRangeStrickThroughCommand, SetRangeSubscriptCommand, SetRangeSuperscriptCommand, SetRangeTextColorCommand, SetRangeUnderlineCommand, SheetCopyCommand, SheetCutCommand, SheetPasteBesidesBorderCommand, SheetPasteColWidthCommand, SheetPasteCommand, SheetPasteFormatCommand, SheetPasteShortKeyCommand, SheetPasteValueCommand } from "@univerjs/sheets-ui";
|
|
5
|
-
import { BuiltInUIPart, ComponentManager, ILocalFileService, IMenuManagerService, IMessageService, IUIPartsService, IconManager, MenuItemType, RibbonOthersGroup, connectInjector, useDependency, useObservable } from "@univerjs/ui";
|
|
6
|
-
import { BehaviorSubject } from "rxjs";
|
|
7
|
-
import { Button, MessageType } from "@univerjs/design";
|
|
8
8
|
import { RecordIcon } from "@univerjs/icons";
|
|
9
9
|
import { useCallback } from "react";
|
|
10
10
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
11
|
|
|
12
|
-
//#region package.json
|
|
13
|
-
var name = "@univerjs/action-recorder";
|
|
14
|
-
var version = "1.0.0-alpha.2";
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/config/config.ts
|
|
18
|
-
const ACTION_RECORDER_PLUGIN_CONFIG_KEY = "action-recorder.config";
|
|
19
|
-
const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
|
|
20
|
-
const defaultPluginConfig = {};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
24
|
-
function _typeof(o) {
|
|
25
|
-
"@babel/helpers - typeof";
|
|
26
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
27
|
-
return typeof o;
|
|
28
|
-
} : function(o) {
|
|
29
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
30
|
-
}, _typeof(o);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
35
|
-
function toPrimitive(t, r) {
|
|
36
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
37
|
-
var e = t[Symbol.toPrimitive];
|
|
38
|
-
if (void 0 !== e) {
|
|
39
|
-
var i = e.call(t, r || "default");
|
|
40
|
-
if ("object" != _typeof(i)) return i;
|
|
41
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
42
|
-
}
|
|
43
|
-
return ("string" === r ? String : Number)(t);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
48
|
-
function toPropertyKey(t) {
|
|
49
|
-
var i = toPrimitive(t, "string");
|
|
50
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
55
|
-
function _defineProperty(e, r, t) {
|
|
56
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
57
|
-
value: t,
|
|
58
|
-
enumerable: !0,
|
|
59
|
-
configurable: !0,
|
|
60
|
-
writable: !0
|
|
61
|
-
}) : e[r] = t, e;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
//#endregion
|
|
65
12
|
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
66
13
|
function __decorateParam(paramIndex, decorator) {
|
|
67
14
|
return function(target, key) {
|
|
@@ -78,124 +25,6 @@ function __decorate(decorators, target, key, desc) {
|
|
|
78
25
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
79
26
|
}
|
|
80
27
|
|
|
81
|
-
//#endregion
|
|
82
|
-
//#region src/services/action-recorder.service.ts
|
|
83
|
-
let ActionRecorderService = class ActionRecorderService extends Disposable {
|
|
84
|
-
get recording() {
|
|
85
|
-
return this._recording$.getValue();
|
|
86
|
-
}
|
|
87
|
-
get _recorded() {
|
|
88
|
-
return this._recorded$.getValue();
|
|
89
|
-
}
|
|
90
|
-
get _recordedCommands() {
|
|
91
|
-
return this._recordedCommands$.getValue();
|
|
92
|
-
}
|
|
93
|
-
constructor(_commandSrv, _logService, _localFileService, _instanceService) {
|
|
94
|
-
super();
|
|
95
|
-
this._commandSrv = _commandSrv;
|
|
96
|
-
this._logService = _logService;
|
|
97
|
-
this._localFileService = _localFileService;
|
|
98
|
-
this._instanceService = _instanceService;
|
|
99
|
-
_defineProperty(this, "_shouldRecordCommands", /* @__PURE__ */ new Set());
|
|
100
|
-
_defineProperty(this, "_panelOpened$", new BehaviorSubject(false));
|
|
101
|
-
_defineProperty(this, "panelOpened$", this._panelOpened$.asObservable());
|
|
102
|
-
_defineProperty(this, "_recorder", null);
|
|
103
|
-
_defineProperty(this, "_recording$", new BehaviorSubject(false));
|
|
104
|
-
_defineProperty(this, "recording$", this._recording$.asObservable());
|
|
105
|
-
_defineProperty(this, "_recorded$", new BehaviorSubject([]));
|
|
106
|
-
_defineProperty(this, "_recordedCommands$", new BehaviorSubject([]));
|
|
107
|
-
_defineProperty(this, "recordedCommands$", this._recordedCommands$.asObservable());
|
|
108
|
-
}
|
|
109
|
-
registerRecordedCommand(command) {
|
|
110
|
-
if (command.type === CommandType.MUTATION) throw new Error("[CommandRecorderService] Cannot record mutation commands.");
|
|
111
|
-
this._shouldRecordCommands.add(command.id);
|
|
112
|
-
}
|
|
113
|
-
togglePanel(visible) {
|
|
114
|
-
this._panelOpened$.next(visible);
|
|
115
|
-
if (visible === false) this.stopRecording();
|
|
116
|
-
}
|
|
117
|
-
startRecording(replaceId = false) {
|
|
118
|
-
this._recorder = this._commandSrv.onCommandExecuted((rawCommandInfo) => {
|
|
119
|
-
if (this._shouldRecordCommands.has(rawCommandInfo.id)) {
|
|
120
|
-
var _this$_instanceServic;
|
|
121
|
-
const recorded = this._recorded;
|
|
122
|
-
const commands = this._recordedCommands;
|
|
123
|
-
let commandInfo = { ...rawCommandInfo };
|
|
124
|
-
const focusUnitId = (_this$_instanceServic = this._instanceService.getFocusedUnit()) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getUnitId();
|
|
125
|
-
const { unitId = focusUnitId, subUnitId } = commandInfo === null || commandInfo === void 0 ? void 0 : commandInfo.params;
|
|
126
|
-
if (replaceId && unitId && subUnitId) {
|
|
127
|
-
var _getSheetBySheetId;
|
|
128
|
-
const subUnitName = (_getSheetBySheetId = this._instanceService.getUnit(unitId).getSheetBySheetId(subUnitId)) === null || _getSheetBySheetId === void 0 ? void 0 : _getSheetBySheetId.getName();
|
|
129
|
-
commandInfo = {
|
|
130
|
-
...commandInfo,
|
|
131
|
-
params: {
|
|
132
|
-
...commandInfo.params,
|
|
133
|
-
subUnitId: subUnitName
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
if (commandInfo.id === SetSelectionsOperation.id && recorded.length > 0 && recorded[recorded.length - 1].id === SetSelectionsOperation.id) recorded[recorded.length - 1] = commandInfo;
|
|
138
|
-
else {
|
|
139
|
-
recorded.push(commandInfo);
|
|
140
|
-
this._recorded$.next(recorded);
|
|
141
|
-
if (commandInfo.type === CommandType.COMMAND) {
|
|
142
|
-
commands.push(commandInfo);
|
|
143
|
-
this._recordedCommands$.next(commands);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
this._recording$.next(true);
|
|
149
|
-
}
|
|
150
|
-
stopRecording() {
|
|
151
|
-
var _this$_recorder;
|
|
152
|
-
(_this$_recorder = this._recorder) === null || _this$_recorder === void 0 || _this$_recorder.dispose();
|
|
153
|
-
this._recorder = null;
|
|
154
|
-
this._recorded$.next([]);
|
|
155
|
-
this._recordedCommands$.next([]);
|
|
156
|
-
this._recording$.next(false);
|
|
157
|
-
}
|
|
158
|
-
completeRecording() {
|
|
159
|
-
const commands = this._recorded.slice();
|
|
160
|
-
this._localFileService.downloadFile(new Blob([JSON.stringify(commands, null, 2)]), "recorded-commands.json");
|
|
161
|
-
this._logService.error("Recorded commands:", commands);
|
|
162
|
-
this.stopRecording();
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
ActionRecorderService = __decorate([
|
|
166
|
-
__decorateParam(0, ICommandService),
|
|
167
|
-
__decorateParam(1, ILogService),
|
|
168
|
-
__decorateParam(2, ILocalFileService),
|
|
169
|
-
__decorateParam(3, IUniverInstanceService)
|
|
170
|
-
], ActionRecorderService);
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
|
-
//#region src/commands/commands/record.command.ts
|
|
174
|
-
const StartRecordingActionCommand = {
|
|
175
|
-
id: "action-recorder.command.start-recording",
|
|
176
|
-
type: CommandType.COMMAND,
|
|
177
|
-
handler: (accessor, params) => {
|
|
178
|
-
accessor.get(ActionRecorderService).startRecording(!!(params === null || params === void 0 ? void 0 : params.replaceId));
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
const CompleteRecordingActionCommand = {
|
|
183
|
-
id: "action-recorder.command.complete-recording",
|
|
184
|
-
type: CommandType.COMMAND,
|
|
185
|
-
handler: (accessor) => {
|
|
186
|
-
accessor.get(ActionRecorderService).completeRecording();
|
|
187
|
-
return true;
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
const StopRecordingActionCommand = {
|
|
191
|
-
id: "action-recorder.command.stop-recording",
|
|
192
|
-
type: CommandType.COMMAND,
|
|
193
|
-
handler: (accessor) => {
|
|
194
|
-
accessor.get(ActionRecorderService).completeRecording();
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
28
|
//#endregion
|
|
200
29
|
//#region src/services/replay.service.ts
|
|
201
30
|
let ActionReplayService = class ActionReplayService extends Disposable {
|
|
@@ -328,6 +157,139 @@ const ReplayLocalRecordOnActiveCommand = {
|
|
|
328
157
|
}
|
|
329
158
|
};
|
|
330
159
|
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
162
|
+
function _typeof(o) {
|
|
163
|
+
"@babel/helpers - typeof";
|
|
164
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
165
|
+
return typeof o;
|
|
166
|
+
} : function(o) {
|
|
167
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
168
|
+
}, _typeof(o);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
173
|
+
function toPrimitive(t, r) {
|
|
174
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
175
|
+
var e = t[Symbol.toPrimitive];
|
|
176
|
+
if (void 0 !== e) {
|
|
177
|
+
var i = e.call(t, r || "default");
|
|
178
|
+
if ("object" != _typeof(i)) return i;
|
|
179
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
180
|
+
}
|
|
181
|
+
return ("string" === r ? String : Number)(t);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
186
|
+
function toPropertyKey(t) {
|
|
187
|
+
var i = toPrimitive(t, "string");
|
|
188
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
193
|
+
function _defineProperty(e, r, t) {
|
|
194
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
195
|
+
value: t,
|
|
196
|
+
enumerable: !0,
|
|
197
|
+
configurable: !0,
|
|
198
|
+
writable: !0
|
|
199
|
+
}) : e[r] = t, e;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
//#endregion
|
|
203
|
+
//#region src/services/action-recorder.service.ts
|
|
204
|
+
let ActionRecorderService = class ActionRecorderService extends Disposable {
|
|
205
|
+
get recording() {
|
|
206
|
+
return this._recording$.getValue();
|
|
207
|
+
}
|
|
208
|
+
get _recorded() {
|
|
209
|
+
return this._recorded$.getValue();
|
|
210
|
+
}
|
|
211
|
+
get _recordedCommands() {
|
|
212
|
+
return this._recordedCommands$.getValue();
|
|
213
|
+
}
|
|
214
|
+
constructor(_commandSrv, _logService, _localFileService, _instanceService) {
|
|
215
|
+
super();
|
|
216
|
+
this._commandSrv = _commandSrv;
|
|
217
|
+
this._logService = _logService;
|
|
218
|
+
this._localFileService = _localFileService;
|
|
219
|
+
this._instanceService = _instanceService;
|
|
220
|
+
_defineProperty(this, "_shouldRecordCommands", /* @__PURE__ */ new Set());
|
|
221
|
+
_defineProperty(this, "_panelOpened$", new BehaviorSubject(false));
|
|
222
|
+
_defineProperty(this, "panelOpened$", this._panelOpened$.asObservable());
|
|
223
|
+
_defineProperty(this, "_recorder", null);
|
|
224
|
+
_defineProperty(this, "_recording$", new BehaviorSubject(false));
|
|
225
|
+
_defineProperty(this, "recording$", this._recording$.asObservable());
|
|
226
|
+
_defineProperty(this, "_recorded$", new BehaviorSubject([]));
|
|
227
|
+
_defineProperty(this, "_recordedCommands$", new BehaviorSubject([]));
|
|
228
|
+
_defineProperty(this, "recordedCommands$", this._recordedCommands$.asObservable());
|
|
229
|
+
}
|
|
230
|
+
registerRecordedCommand(command) {
|
|
231
|
+
if (command.type === CommandType.MUTATION) throw new Error("[CommandRecorderService] Cannot record mutation commands.");
|
|
232
|
+
this._shouldRecordCommands.add(command.id);
|
|
233
|
+
}
|
|
234
|
+
togglePanel(visible) {
|
|
235
|
+
this._panelOpened$.next(visible);
|
|
236
|
+
if (visible === false) this.stopRecording();
|
|
237
|
+
}
|
|
238
|
+
startRecording(replaceId = false) {
|
|
239
|
+
this._recorder = this._commandSrv.onCommandExecuted((rawCommandInfo) => {
|
|
240
|
+
if (this._shouldRecordCommands.has(rawCommandInfo.id)) {
|
|
241
|
+
var _this$_instanceServic;
|
|
242
|
+
const recorded = this._recorded;
|
|
243
|
+
const commands = this._recordedCommands;
|
|
244
|
+
let commandInfo = { ...rawCommandInfo };
|
|
245
|
+
const focusUnitId = (_this$_instanceServic = this._instanceService.getFocusedUnit()) === null || _this$_instanceServic === void 0 ? void 0 : _this$_instanceServic.getUnitId();
|
|
246
|
+
const { unitId = focusUnitId, subUnitId } = commandInfo === null || commandInfo === void 0 ? void 0 : commandInfo.params;
|
|
247
|
+
if (replaceId && unitId && subUnitId) {
|
|
248
|
+
var _getSheetBySheetId;
|
|
249
|
+
const subUnitName = (_getSheetBySheetId = this._instanceService.getUnit(unitId).getSheetBySheetId(subUnitId)) === null || _getSheetBySheetId === void 0 ? void 0 : _getSheetBySheetId.getName();
|
|
250
|
+
commandInfo = {
|
|
251
|
+
...commandInfo,
|
|
252
|
+
params: {
|
|
253
|
+
...commandInfo.params,
|
|
254
|
+
subUnitId: subUnitName
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (commandInfo.id === SetSelectionsOperation.id && recorded.length > 0 && recorded[recorded.length - 1].id === SetSelectionsOperation.id) recorded[recorded.length - 1] = commandInfo;
|
|
259
|
+
else {
|
|
260
|
+
recorded.push(commandInfo);
|
|
261
|
+
this._recorded$.next(recorded);
|
|
262
|
+
if (commandInfo.type === CommandType.COMMAND) {
|
|
263
|
+
commands.push(commandInfo);
|
|
264
|
+
this._recordedCommands$.next(commands);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
this._recording$.next(true);
|
|
270
|
+
}
|
|
271
|
+
stopRecording() {
|
|
272
|
+
var _this$_recorder;
|
|
273
|
+
(_this$_recorder = this._recorder) === null || _this$_recorder === void 0 || _this$_recorder.dispose();
|
|
274
|
+
this._recorder = null;
|
|
275
|
+
this._recorded$.next([]);
|
|
276
|
+
this._recordedCommands$.next([]);
|
|
277
|
+
this._recording$.next(false);
|
|
278
|
+
}
|
|
279
|
+
completeRecording() {
|
|
280
|
+
const commands = this._recorded.slice();
|
|
281
|
+
this._localFileService.downloadFile(new Blob([JSON.stringify(commands, null, 2)]), "recorded-commands.json");
|
|
282
|
+
this._logService.error("Recorded commands:", commands);
|
|
283
|
+
this.stopRecording();
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
ActionRecorderService = __decorate([
|
|
287
|
+
__decorateParam(0, ICommandService),
|
|
288
|
+
__decorateParam(1, ILogService),
|
|
289
|
+
__decorateParam(2, ILocalFileService),
|
|
290
|
+
__decorateParam(3, IUniverInstanceService)
|
|
291
|
+
], ActionRecorderService);
|
|
292
|
+
|
|
331
293
|
//#endregion
|
|
332
294
|
//#region src/commands/operations/operation.ts
|
|
333
295
|
const OpenRecordPanelOperation = {
|
|
@@ -409,6 +371,44 @@ const menuSchema = { [RibbonOthersGroup.OTHERS]: { [RECORD_MENU_ITEM_ID]: {
|
|
|
409
371
|
}
|
|
410
372
|
} } };
|
|
411
373
|
|
|
374
|
+
//#endregion
|
|
375
|
+
//#region package.json
|
|
376
|
+
var name = "@univerjs/action-recorder";
|
|
377
|
+
var version = "1.0.0-alpha.3";
|
|
378
|
+
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/config/config.ts
|
|
381
|
+
const ACTION_RECORDER_PLUGIN_CONFIG_KEY = "action-recorder.config";
|
|
382
|
+
const configSymbol = Symbol(ACTION_RECORDER_PLUGIN_CONFIG_KEY);
|
|
383
|
+
const defaultPluginConfig = {};
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/commands/commands/record.command.ts
|
|
387
|
+
const StartRecordingActionCommand = {
|
|
388
|
+
id: "action-recorder.command.start-recording",
|
|
389
|
+
type: CommandType.COMMAND,
|
|
390
|
+
handler: (accessor, params) => {
|
|
391
|
+
accessor.get(ActionRecorderService).startRecording(!!(params === null || params === void 0 ? void 0 : params.replaceId));
|
|
392
|
+
return true;
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const CompleteRecordingActionCommand = {
|
|
396
|
+
id: "action-recorder.command.complete-recording",
|
|
397
|
+
type: CommandType.COMMAND,
|
|
398
|
+
handler: (accessor) => {
|
|
399
|
+
accessor.get(ActionRecorderService).completeRecording();
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
const StopRecordingActionCommand = {
|
|
404
|
+
id: "action-recorder.command.stop-recording",
|
|
405
|
+
type: CommandType.COMMAND,
|
|
406
|
+
handler: (accessor) => {
|
|
407
|
+
accessor.get(ActionRecorderService).completeRecording();
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/views/components/RecorderPanel.tsx
|
|
414
414
|
/**
|
|
@@ -659,4 +659,4 @@ _defineProperty(UniverActionRecorderPlugin, "version", version);
|
|
|
659
659
|
UniverActionRecorderPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverActionRecorderPlugin);
|
|
660
660
|
|
|
661
661
|
//#endregion
|
|
662
|
-
export { ActionRecorderService, ActionReplayService, UniverActionRecorderPlugin };
|
|
662
|
+
export { menuSchema as ActionRecorderMenuSchema, ActionRecorderService, ActionReplayService, UniverActionRecorderPlugin };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import './global.css';
|
|
17
17
|
export type { IUniverActionRecorderConfig } from './config/config';
|
|
18
|
+
export { menuSchema as ActionRecorderMenuSchema } from './menu/action-recorder.menu';
|
|
18
19
|
export { UniverActionRecorderPlugin } from './plugin';
|
|
19
20
|
export { ActionRecorderService } from './services/action-recorder.service';
|
|
20
21
|
export { ActionReplayService } from './services/replay.service';
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("@univerjs/sheets-filter"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverActionRecorder={},e.UniverCore,e.UniverSheets,e.UniverSheetsFilter,e.UniverSheetsUi,e.UniverUi,e.rxjs,e.UniverDesign,e.React,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=`1.0.0-alpha.2`;let f={};function p(e){"@babel/helpers - typeof";return p=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},p(e)}function m(e,t){if(p(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(p(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function h(e){var t=m(e,`string`);return p(t)==`symbol`?t:t+``}function g(e,t,n){return(t=h(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _(e,t){return function(n,r){t(n,r,e)}}function v(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 y=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,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())}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(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(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===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===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()}};y=v([_(0,t.ICommandService),_(1,t.ILogService),_(2,a.ILocalFileService),_(3,t.IUniverInstanceService)],y);let b={id:`action-recorder.command.start-recording`,type:t.CommandType.COMMAND,handler:(e,t)=>(e.get(y).startRecording(!!(t!=null&&t.replaceId)),!0)},x={id:`action-recorder.command.complete-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(y).completeRecording(),!0)},S={id:`action-recorder.command.stop-recording`,type:t.CommandType.COMMAND,handler:e=>(e.get(y).completeRecording(),!0)},C=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: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===`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)(w());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}};C=v([_(0,a.IMessageService),_(1,t.IUniverInstanceService),_(2,a.ILocalFileService),_(3,t.ILogService),_(4,t.ICommandService)],C);function w(){return Math.floor(Math.random()*800)+200}let T={id:`action-recorder.command.replay-local-records`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(C).replayLocalJSON();return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},E={id:`action-recorder.command.replay-local-records-name`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(C).replayLocalJSON(`name`);return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},D={id:`action-recorder.command.replay-local-records-active`,type:t.CommandType.COMMAND,handler:async e=>{let t=await e.get(C).replayLocalJSON(`active`);return t&&e.get(a.IMessageService).show({type:s.MessageType.Success,content:`Successfully replayed local records`}),t}},O={id:`action-recorder.operation.open-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(y).togglePanel(!0),!0}},k={id:`action-recorder.operation.close-panel`,type:t.CommandType.OPERATION,handler(e){return e.get(y).togglePanel(!1),!0}},A=`RECORD_MENU_ITEM`;function j(){return{id:A,type:a.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function M(e){let t=e.get(y);return{id:O.id,title:`action-recorder.menu.record`,type:a.MenuItemType.BUTTON,disabled$:t.panelOpened$}}function N(){return{id:T.id,title:`action-recorder.menu.replay-local`,type:a.MenuItemType.BUTTON}}function P(){return{id:E.id,title:`action-recorder.menu.replay-local-name`,type:a.MenuItemType.BUTTON}}function F(){return{id:D.id,title:`action-recorder.menu.replay-local-active`,type:a.MenuItemType.BUTTON}}let I={[a.RibbonOthersGroup.OTHERS]:{[A]:{order:1,menuItemFactory:j,[O.id]:{order:1,menuItemFactory:M},[T.id]:{order:2,menuItemFactory:N},[E.id]:{order:3,menuItemFactory:P},[D.id]:{order:4,menuItemFactory:F}}}};function L({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,c.useRef)(`_${V()}`);return R(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:s,...o},a)}function R(e,t,n,r,i){return(0,c.createElement)(e.tag,{key:t,...z(e,n,i),...r},(B(e,n).children||[]).map((r,a)=>R(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function z(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=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 B(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)}L.displayName=`UniverIcon`;let H={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`]},U=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(L,Object.assign({},e,{id:`record-icon`,ref:t,icon:H}))});U.displayName=`RecordIcon`;function W(){return(0,a.useObservable)((0,a.useDependency)(y).panelOpened$)?(0,l.jsx)(G,{}):null}function G(){var e;let n=(0,a.useDependency)(t.ICommandService),r=(0,a.useDependency)(y),i=(0,a.useObservable)(r.recording$),o=(0,a.useObservable)(r.recordedCommands$),u=(e=o==null?void 0:o.length)==null?0:e,d=(0,c.useCallback)(()=>{i||n.executeCommand(k.id)},[n,i]),f=(0,c.useCallback)(e=>{i||n.executeCommand(b.id,{replaceId:e})},[n,i]),p=(0,c.useCallback)(()=>{i&&n.executeCommand(x.id)},[n,i]),m=(0,c.useCallback)(()=>{i&&n.executeCommand(S.id)},[n,i]),h=i?u===0?`Recording...`:`${u}: ${o[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)(U,{})}),(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)(s.Button,{className:`univer-w-20`,onClick:i?m:d,children:i?`Cancel`:`Close`}),(0,l.jsx)(s.Button,{className:`univer-w-20`,variant:`primary`,onClick:i?p:()=>f(),children:i?`Save`:`Start`}),!i&&(0,l.jsx)(s.Button,{variant:`primary`,onClick:()=>f(!0),children:`Start(N)`})]})]})}let K=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._actionRecorderService=r,this._injector=i,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[b,S,x,O,k,T,E,D].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(a.BuiltInUIPart.GLOBAL,()=>(0,a.connectInjector)(W,this._injector)),this._menuManagerService.mergeMenu(I)}_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(){}};K=v([_(0,t.ICommandService),_(1,a.IUIPartsService),_(2,a.IMenuManagerService),_(3,(0,t.Inject)(y)),_(4,(0,t.Inject)(t.Injector))],K);let q=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerIcons()}_registerIcons(){this.disposeWithMe(this._iconManager.register({RecordIcon:U}))}};q=v([_(0,(0,t.Inject)(a.ComponentManager)),_(1,(0,t.Inject)(a.IconManager))],q);let J=class extends t.Plugin{constructor(e=f,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},f,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(`action-recorder.config`,a)}onStarting(){this._injector.add([q]),this._injector.get(q),(this._config.replayOnly?[[C]]:[[y],[C],[K]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(K)}};g(J,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),g(J,`packageName`,u),g(J,`version`,d),J=v([_(1,(0,t.Inject)(t.Injector)),_(2,t.IConfigService)],J),Object.defineProperty(e,"ActionRecorderService",{enumerable:!0,get:function(){return y}}),Object.defineProperty(e,"ActionReplayService",{enumerable:!0,get:function(){return C}}),Object.defineProperty(e,"UniverActionRecorderPlugin",{enumerable:!0,get:function(){return J}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/ui"),require("@univerjs/core"),require("@univerjs/design"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/sheets-filter"),require("@univerjs/sheets-ui"),require("react"),require("react/jsx-runtime")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/ui`,`@univerjs/core`,`@univerjs/design`,`@univerjs/sheets`,`rxjs`,`@univerjs/sheets-filter`,`@univerjs/sheets-ui`,`react`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverActionRecorder={},e.UniverUi,e.UniverCore,e.UniverDesign,e.UniverSheets,e.rxjs,e.UniverSheetsFilter,e.UniverSheetsUi,e.React,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function u(e,t){return function(n,r){t(n,r,e)}}function d(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 f=class extends n.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:r.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 t;let r=(t=this._instanceService.getFocusedUnit())==null?void 0:t.getUnitId();r||this._logService.error(`[ReplayService]`,`no focused unit to replay commands`);for(let t of e){await(0,n.awaitTime)(p());let{id:e,params:i}=t;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}};f=d([u(0,t.IMessageService),u(1,n.IUniverInstanceService),u(2,t.ILocalFileService),u(3,n.ILogService),u(4,n.ICommandService)],f);function p(){return Math.floor(Math.random()*800)+200}let m={id:`action-recorder.command.replay-local-records`,type:n.CommandType.COMMAND,handler:async e=>{let n=await e.get(f).replayLocalJSON();return n&&e.get(t.IMessageService).show({type:r.MessageType.Success,content:`Successfully replayed local records`}),n}},h={id:`action-recorder.command.replay-local-records-name`,type:n.CommandType.COMMAND,handler:async e=>{let n=await e.get(f).replayLocalJSON(`name`);return n&&e.get(t.IMessageService).show({type:r.MessageType.Success,content:`Successfully replayed local records`}),n}},g={id:`action-recorder.command.replay-local-records-active`,type:n.CommandType.COMMAND,handler:async e=>{let n=await e.get(f).replayLocalJSON(`active`);return n&&e.get(t.IMessageService).show({type:r.MessageType.Success,content:`Successfully replayed local records`}),n}};function _(e){"@babel/helpers - typeof";return _=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},_(e)}function v(e,t){if(_(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(_(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function y(e){var t=v(e,`string`);return _(t)==`symbol`?t:t+``}function b(e,t,n){return(t=y(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let x=class extends n.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,b(this,`_shouldRecordCommands`,new Set),b(this,`_panelOpened$`,new a.BehaviorSubject(!1)),b(this,`panelOpened$`,this._panelOpened$.asObservable()),b(this,`_recorder`,null),b(this,`_recording$`,new a.BehaviorSubject(!1)),b(this,`recording$`,this._recording$.asObservable()),b(this,`_recorded$`,new a.BehaviorSubject([])),b(this,`_recordedCommands$`,new a.BehaviorSubject([])),b(this,`recordedCommands$`,this._recordedCommands$.asObservable())}registerRecordedCommand(e){if(e.type===n.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(t=>{if(this._shouldRecordCommands.has(t.id)){var r;let o=this._recorded,s=this._recordedCommands,c={...t},l=(r=this._instanceService.getFocusedUnit())==null?void 0:r.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===i.SetSelectionsOperation.id&&o.length>0&&o[o.length-1].id===i.SetSelectionsOperation.id?o[o.length-1]=c:(o.push(c),this._recorded$.next(o),c.type===n.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()}};x=d([u(0,n.ICommandService),u(1,n.ILogService),u(2,t.ILocalFileService),u(3,n.IUniverInstanceService)],x);let S={id:`action-recorder.operation.open-panel`,type:n.CommandType.OPERATION,handler(e){return e.get(x).togglePanel(!0),!0}},C={id:`action-recorder.operation.close-panel`,type:n.CommandType.OPERATION,handler(e){return e.get(x).togglePanel(!1),!0}},w=`RECORD_MENU_ITEM`;function T(){return{id:w,type:t.MenuItemType.SUBITEMS,icon:`RecordIcon`,tooltip:`action-recorder.menu.title`}}function E(e){let n=e.get(x);return{id:S.id,title:`action-recorder.menu.record`,type:t.MenuItemType.BUTTON,disabled$:n.panelOpened$}}function D(){return{id:m.id,title:`action-recorder.menu.replay-local`,type:t.MenuItemType.BUTTON}}function O(){return{id:h.id,title:`action-recorder.menu.replay-local-name`,type:t.MenuItemType.BUTTON}}function k(){return{id:g.id,title:`action-recorder.menu.replay-local-active`,type:t.MenuItemType.BUTTON}}let A={[t.RibbonOthersGroup.OTHERS]:{[w]:{order:1,menuItemFactory:T,[S.id]:{order:1,menuItemFactory:E},[m.id]:{order:2,menuItemFactory:D},[h.id]:{order:3,menuItemFactory:O},[g.id]:{order:4,menuItemFactory:k}}}};var j=`@univerjs/action-recorder`,M=`1.0.0-alpha.3`;let N={},P={id:`action-recorder.command.start-recording`,type:n.CommandType.COMMAND,handler:(e,t)=>(e.get(x).startRecording(!!(t!=null&&t.replaceId)),!0)},F={id:`action-recorder.command.complete-recording`,type:n.CommandType.COMMAND,handler:e=>(e.get(x).completeRecording(),!0)},I={id:`action-recorder.command.stop-recording`,type:n.CommandType.COMMAND,handler:e=>(e.get(x).completeRecording(),!0)};function L({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,c.useRef)(`_${V()}`);return R(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:s,...o},a)}function R(e,t,n,r,i){return(0,c.createElement)(e.tag,{key:t,...z(e,n,i),...r},(B(e,n).children||[]).map((r,a)=>R(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function z(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=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 B(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)}L.displayName=`UniverIcon`;let H={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`]},U=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(L,Object.assign({},e,{id:`record-icon`,ref:t,icon:H}))});U.displayName=`RecordIcon`;function W(){return(0,t.useObservable)((0,t.useDependency)(x).panelOpened$)?(0,l.jsx)(G,{}):null}function G(){var e;let i=(0,t.useDependency)(n.ICommandService),a=(0,t.useDependency)(x),o=(0,t.useObservable)(a.recording$),s=(0,t.useObservable)(a.recordedCommands$),u=(e=s==null?void 0:s.length)==null?0:e,d=(0,c.useCallback)(()=>{o||i.executeCommand(C.id)},[i,o]),f=(0,c.useCallback)(e=>{o||i.executeCommand(P.id,{replaceId:e})},[i,o]),p=(0,c.useCallback)(()=>{o&&i.executeCommand(F.id)},[i,o]),m=(0,c.useCallback)(()=>{o&&i.executeCommand(I.id)},[i,o]),h=o?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)(U,{})}),(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)(r.Button,{className:`univer-w-20`,onClick:o?m:d,children:o?`Cancel`:`Close`}),(0,l.jsx)(r.Button,{className:`univer-w-20`,variant:`primary`,onClick:o?p:()=>f(),children:o?`Save`:`Start`}),!o&&(0,l.jsx)(r.Button,{variant:`primary`,onClick:()=>f(!0),children:`Start(N)`})]})]})}let K=class extends n.Disposable{constructor(e,t,n,r,i){super(),this._commandSrv=e,this._uiPartsSrv=t,this._menuManagerService=n,this._actionRecorderService=r,this._injector=i,this._initCommands(),this._initUI(),this._initSheetsCommands(),this._initDocsCommands()}_initCommands(){[P,I,F,S,C,m,h,g].forEach(e=>this._commandSrv.registerCommand(e))}_initUI(){this._uiPartsSrv.registerComponent(t.BuiltInUIPart.GLOBAL,()=>(0,t.connectInjector)(W,this._injector)),this._menuManagerService.mergeMenu(A)}_initSheetsCommands(){[i.CopySheetCommand,i.DeleteRangeMoveLeftCommand,i.DeleteRangeMoveUpCommand,i.DeltaColumnWidthCommand,i.DeltaRowHeightCommand,i.InsertSheetCommand,i.InsertColAfterCommand,i.InsertColBeforeCommand,i.InsertRowAfterCommand,i.InsertRowBeforeCommand,i.RemoveSheetCommand,i.SetStyleCommand,i.AddWorksheetMergeCommand,i.AddWorksheetMergeAllCommand,i.AddWorksheetMergeVerticalCommand,i.AddWorksheetMergeHorizontalCommand,i.SetFrozenCommand,i.CancelFrozenCommand,i.SetHorizontalTextAlignCommand,i.SetOverlineCommand,s.SetRangeBoldCommand,s.SetRangeFontFamilyCommand,s.SetRangeFontSizeCommand,s.SetRangeItalicCommand,s.SetRangeStrickThroughCommand,s.SetRangeSubscriptCommand,s.SetRangeSuperscriptCommand,s.SetRangeTextColorCommand,s.SetRangeUnderlineCommand,i.SetRangeValuesCommand,i.SetStrikeThroughCommand,i.SetTextColorCommand,i.SetTextRotationCommand,i.SetTextWrapCommand,i.SetVerticalTextAlignCommand,s.SheetCopyCommand,s.SheetCutCommand,s.SheetPasteBesidesBorderCommand,s.SheetPasteColWidthCommand,s.SheetPasteCommand,s.SheetPasteFormatCommand,s.SheetPasteShortKeyCommand,s.SheetPasteValueCommand,i.AutoFillCommand,i.RefillCommand,i.SetWorksheetActivateCommand,i.SetWorksheetActiveOperation,i.SetSelectionsOperation,o.SetSheetFilterRangeCommand,o.SetSheetsFilterCriteriaCommand,o.RemoveSheetFilterCommand].forEach(e=>this._actionRecorderService.registerRecordedCommand(e))}_initDocsCommands(){}};K=d([u(0,n.ICommandService),u(1,t.IUIPartsService),u(2,t.IMenuManagerService),u(3,(0,n.Inject)(x)),u(4,(0,n.Inject)(n.Injector))],K);let q=class extends n.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerIcons()}_registerIcons(){this.disposeWithMe(this._iconManager.register({RecordIcon:U}))}};q=d([u(0,(0,n.Inject)(t.ComponentManager)),u(1,(0,n.Inject)(t.IconManager))],q);let J=class extends n.Plugin{constructor(e=N,t,r){super(),this._config=e,this._injector=t,this._configService=r;let{menu:i,...a}=(0,n.merge)({},N,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(`action-recorder.config`,a)}onStarting(){this._injector.add([q]),this._injector.get(q),(this._config.replayOnly?[[f]]:[[x],[f],[K]]).forEach(e=>this._injector.add(e))}onSteady(){this._config.replayOnly||this._injector.get(K)}};b(J,`pluginName`,`UNIVER_ACTION_RECORDER_PLUGIN`),b(J,`packageName`,j),b(J,`version`,M),J=d([u(1,(0,n.Inject)(n.Injector)),u(2,n.IConfigService)],J),e.ActionRecorderMenuSchema=A,Object.defineProperty(e,"ActionRecorderService",{enumerable:!0,get:function(){return x}}),Object.defineProperty(e,"ActionReplayService",{enumerable:!0,get:function(){return f}}),Object.defineProperty(e,"UniverActionRecorderPlugin",{enumerable:!0,get:function(){return J}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/action-recorder",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Record and replay user actions in Univer.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -58,21 +58,21 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/icons": "1.
|
|
62
|
-
"@univerjs/core": "1.0.0-alpha.
|
|
63
|
-
"@univerjs/design": "1.0.0-alpha.
|
|
64
|
-
"@univerjs/sheets": "1.0.0-alpha.
|
|
65
|
-
"@univerjs/sheets-
|
|
66
|
-
"@univerjs/
|
|
67
|
-
"@univerjs/
|
|
61
|
+
"@univerjs/icons": "1.20.0",
|
|
62
|
+
"@univerjs/core": "1.0.0-alpha.3",
|
|
63
|
+
"@univerjs/design": "1.0.0-alpha.3",
|
|
64
|
+
"@univerjs/sheets-filter": "1.0.0-alpha.3",
|
|
65
|
+
"@univerjs/sheets-ui": "1.0.0-alpha.3",
|
|
66
|
+
"@univerjs/ui": "1.0.0-alpha.3",
|
|
67
|
+
"@univerjs/sheets": "1.0.0-alpha.3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"react": "18.3.1",
|
|
71
71
|
"rxjs": "^7.8.2",
|
|
72
72
|
"tailwindcss": "3.4.18",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
|
-
"vitest": "^4.1.
|
|
75
|
-
"@univerjs-infra/shared": "1.0.0-alpha.
|
|
74
|
+
"vitest": "^4.1.10",
|
|
75
|
+
"@univerjs-infra/shared": "1.0.0-alpha.3"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"test": "vitest run",
|