@univerjs/uniscript 0.1.0-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +20 -0
  3. package/lib/cjs/index.js +863 -0
  4. package/lib/cjs/locale/en-US.js +36 -0
  5. package/lib/cjs/locale/zh-CN.js +26 -0
  6. package/lib/esm/index.js +855 -0
  7. package/lib/esm/locale/en-US.js +15 -0
  8. package/lib/esm/locale/zh-CN.js +5 -0
  9. package/lib/index.css +9 -0
  10. package/lib/types/commands/operations/panel.operation.d.ts +4 -0
  11. package/lib/types/commands/operations/panel.operation.d.ts.map +1 -0
  12. package/lib/types/controllers/menu.d.ts +3 -0
  13. package/lib/types/controllers/menu.d.ts.map +1 -0
  14. package/lib/types/controllers/uniscript.controller.d.ts +6 -0
  15. package/lib/types/controllers/uniscript.controller.d.ts.map +1 -0
  16. package/lib/types/facade/facade.d.ts +11 -0
  17. package/lib/types/facade/facade.d.ts.map +1 -0
  18. package/lib/types/facade/sheet/f-range.d.ts +18 -0
  19. package/lib/types/facade/sheet/f-range.d.ts.map +1 -0
  20. package/lib/types/facade/sheet/f-selection.d.ts +13 -0
  21. package/lib/types/facade/sheet/f-selection.d.ts.map +1 -0
  22. package/lib/types/facade/sheet/f-workbook.d.ts +10 -0
  23. package/lib/types/facade/sheet/f-workbook.d.ts.map +1 -0
  24. package/lib/types/facade/sheet/f-worksheet.d.ts +15 -0
  25. package/lib/types/facade/sheet/f-worksheet.d.ts.map +1 -0
  26. package/lib/types/index.d.ts +2 -0
  27. package/lib/types/index.d.ts.map +1 -0
  28. package/lib/types/locale/en-US.d.ts +13 -0
  29. package/lib/types/locale/en-US.d.ts.map +1 -0
  30. package/lib/types/locale/index.d.ts +3 -0
  31. package/lib/types/locale/index.d.ts.map +1 -0
  32. package/lib/types/locale/zh-CN.d.ts +3 -0
  33. package/lib/types/locale/zh-CN.d.ts.map +1 -0
  34. package/lib/types/models/model.d.ts +1 -0
  35. package/lib/types/models/model.d.ts.map +1 -0
  36. package/lib/types/plugin.d.ts +14 -0
  37. package/lib/types/plugin.d.ts.map +1 -0
  38. package/lib/types/services/command/batch-command.service.d.ts +10 -0
  39. package/lib/types/services/command/batch-command.service.d.ts.map +1 -0
  40. package/lib/types/services/script-editor.service.d.ts +13 -0
  41. package/lib/types/services/script-editor.service.d.ts.map +1 -0
  42. package/lib/types/services/script-execution.service.d.ts +12 -0
  43. package/lib/types/services/script-execution.service.d.ts.map +1 -0
  44. package/lib/types/services/script-panel.service.d.ts +10 -0
  45. package/lib/types/services/script-panel.service.d.ts.map +1 -0
  46. package/lib/types/views/components/ScriptEditorPanel.d.ts +3 -0
  47. package/lib/types/views/components/ScriptEditorPanel.d.ts.map +1 -0
  48. package/lib/types/views/parts/render.part.d.ts +1 -0
  49. package/lib/types/views/parts/render.part.d.ts.map +1 -0
  50. package/package.json +66 -0
@@ -0,0 +1,863 @@
1
+ "use strict";
2
+ function _assert_this_initialized(self) {
3
+ if (self === void 0) {
4
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5
+ }
6
+ return self;
7
+ }
8
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
9
+ try {
10
+ var info = gen[key](arg);
11
+ var value = info.value;
12
+ } catch (error) {
13
+ reject(error);
14
+ return;
15
+ }
16
+ if (info.done) {
17
+ resolve(value);
18
+ } else {
19
+ Promise.resolve(value).then(_next, _throw);
20
+ }
21
+ }
22
+ function _async_to_generator(fn) {
23
+ return function() {
24
+ var self = this, args = arguments;
25
+ return new Promise(function(resolve, reject) {
26
+ var gen = fn.apply(self, args);
27
+ function _next(value) {
28
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
29
+ }
30
+ function _throw(err) {
31
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
32
+ }
33
+ _next(undefined);
34
+ });
35
+ };
36
+ }
37
+ function _class_call_check(instance, Constructor) {
38
+ if (!(instance instanceof Constructor)) {
39
+ throw new TypeError("Cannot call a class as a function");
40
+ }
41
+ }
42
+ function _defineProperties(target, props) {
43
+ for(var i = 0; i < props.length; i++){
44
+ var descriptor = props[i];
45
+ descriptor.enumerable = descriptor.enumerable || false;
46
+ descriptor.configurable = true;
47
+ if ("value" in descriptor) descriptor.writable = true;
48
+ Object.defineProperty(target, descriptor.key, descriptor);
49
+ }
50
+ }
51
+ function _create_class(Constructor, protoProps, staticProps) {
52
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
53
+ if (staticProps) _defineProperties(Constructor, staticProps);
54
+ return Constructor;
55
+ }
56
+ function _define_property(obj, key, value) {
57
+ if (key in obj) {
58
+ Object.defineProperty(obj, key, {
59
+ value: value,
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true
63
+ });
64
+ } else {
65
+ obj[key] = value;
66
+ }
67
+ return obj;
68
+ }
69
+ function _get_prototype_of(o) {
70
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
71
+ return o.__proto__ || Object.getPrototypeOf(o);
72
+ };
73
+ return _get_prototype_of(o);
74
+ }
75
+ function _inherits(subClass, superClass) {
76
+ if (typeof superClass !== "function" && superClass !== null) {
77
+ throw new TypeError("Super expression must either be null or a function");
78
+ }
79
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
80
+ constructor: {
81
+ value: subClass,
82
+ writable: true,
83
+ configurable: true
84
+ }
85
+ });
86
+ if (superClass) _set_prototype_of(subClass, superClass);
87
+ }
88
+ function _possible_constructor_return(self, call) {
89
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
90
+ return call;
91
+ }
92
+ return _assert_this_initialized(self);
93
+ }
94
+ function _set_prototype_of(o, p) {
95
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
96
+ o.__proto__ = p;
97
+ return o;
98
+ };
99
+ return _set_prototype_of(o, p);
100
+ }
101
+ function _type_of(obj) {
102
+ "@swc/helpers - typeof";
103
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
104
+ }
105
+ function _is_native_reflect_construct() {
106
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
107
+ if (Reflect.construct.sham) return false;
108
+ if (typeof Proxy === "function") return true;
109
+ try {
110
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
111
+ return true;
112
+ } catch (e) {
113
+ return false;
114
+ }
115
+ }
116
+ function _create_super(Derived) {
117
+ var hasNativeReflectConstruct = _is_native_reflect_construct();
118
+ return function _createSuperInternal() {
119
+ var Super = _get_prototype_of(Derived), result;
120
+ if (hasNativeReflectConstruct) {
121
+ var NewTarget = _get_prototype_of(this).constructor;
122
+ result = Reflect.construct(Super, arguments, NewTarget);
123
+ } else {
124
+ result = Super.apply(this, arguments);
125
+ }
126
+ return _possible_constructor_return(this, result);
127
+ };
128
+ }
129
+ function _ts_generator(thisArg, body) {
130
+ var f, y, t, g, _ = {
131
+ label: 0,
132
+ sent: function() {
133
+ if (t[0] & 1) throw t[1];
134
+ return t[1];
135
+ },
136
+ trys: [],
137
+ ops: []
138
+ };
139
+ return g = {
140
+ next: verb(0),
141
+ "throw": verb(1),
142
+ "return": verb(2)
143
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
144
+ return this;
145
+ }), g;
146
+ function verb(n) {
147
+ return function(v) {
148
+ return step([
149
+ n,
150
+ v
151
+ ]);
152
+ };
153
+ }
154
+ function step(op) {
155
+ if (f) throw new TypeError("Generator is already executing.");
156
+ while(_)try {
157
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
158
+ if (y = 0, t) op = [
159
+ op[0] & 2,
160
+ t.value
161
+ ];
162
+ switch(op[0]){
163
+ case 0:
164
+ case 1:
165
+ t = op;
166
+ break;
167
+ case 4:
168
+ _.label++;
169
+ return {
170
+ value: op[1],
171
+ done: false
172
+ };
173
+ case 5:
174
+ _.label++;
175
+ y = op[1];
176
+ op = [
177
+ 0
178
+ ];
179
+ continue;
180
+ case 7:
181
+ op = _.ops.pop();
182
+ _.trys.pop();
183
+ continue;
184
+ default:
185
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
186
+ _ = 0;
187
+ continue;
188
+ }
189
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
190
+ _.label = op[1];
191
+ break;
192
+ }
193
+ if (op[0] === 6 && _.label < t[1]) {
194
+ _.label = t[1];
195
+ t = op;
196
+ break;
197
+ }
198
+ if (t && _.label < t[2]) {
199
+ _.label = t[2];
200
+ _.ops.push(op);
201
+ break;
202
+ }
203
+ if (t[2]) _.ops.pop();
204
+ _.trys.pop();
205
+ continue;
206
+ }
207
+ op = body.call(thisArg, _);
208
+ } catch (e) {
209
+ op = [
210
+ 6,
211
+ e
212
+ ];
213
+ y = 0;
214
+ } finally{
215
+ f = t = 0;
216
+ }
217
+ if (op[0] & 5) throw op[1];
218
+ return {
219
+ value: op[0] ? op[1] : void 0,
220
+ done: true
221
+ };
222
+ }
223
+ }
224
+ var _import_core9_Plugin, _class;
225
+ var __create = Object.create;
226
+ var __defProp = Object.defineProperty;
227
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
228
+ var __getOwnPropNames = Object.getOwnPropertyNames;
229
+ var __getProtoOf = Object.getPrototypeOf;
230
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
231
+ var __export = function(target, all) {
232
+ for(var name in all)__defProp(target, name, {
233
+ get: all[name],
234
+ enumerable: true
235
+ });
236
+ };
237
+ var __copyProps = function(to, from, except, desc) {
238
+ if (from && typeof from === "object" || typeof from === "function") {
239
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
240
+ try {
241
+ var _loop = function() {
242
+ var key = _step.value;
243
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
244
+ get: function() {
245
+ return from[key];
246
+ },
247
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
248
+ });
249
+ };
250
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
251
+ } catch (err) {
252
+ _didIteratorError = true;
253
+ _iteratorError = err;
254
+ } finally{
255
+ try {
256
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
257
+ _iterator.return();
258
+ }
259
+ } finally{
260
+ if (_didIteratorError) {
261
+ throw _iteratorError;
262
+ }
263
+ }
264
+ }
265
+ }
266
+ return to;
267
+ };
268
+ var __toESM = function(mod, isNodeMode, target) {
269
+ return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
270
+ // file that has been converted to a CommonJS file using a Babel-
271
+ // compatible transform (i.e. "__esModule" has not been set), then set
272
+ // "default" to the CommonJS "module.exports" for node compatibility.
273
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
274
+ value: mod,
275
+ enumerable: true
276
+ }) : target, mod);
277
+ };
278
+ var __toCommonJS = function(mod) {
279
+ return __copyProps(__defProp({}, "__esModule", {
280
+ value: true
281
+ }), mod);
282
+ };
283
+ var __decorateClass = function(decorators, target, key, kind) {
284
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
285
+ for(var i = decorators.length - 1, decorator; i >= 0; i--)if (decorator = decorators[i]) result = (kind ? decorator(target, key, result) : decorator(result)) || result;
286
+ if (kind && result) __defProp(target, key, result);
287
+ return result;
288
+ };
289
+ var __decorateParam = function(index, decorator) {
290
+ return function(target, key) {
291
+ return decorator(target, key, index);
292
+ };
293
+ };
294
+ // src/index.ts
295
+ var src_exports = {};
296
+ __export(src_exports, {
297
+ UniscriptPlugin: function() {
298
+ return UniscriptPlugin;
299
+ }
300
+ });
301
+ module.exports = __toCommonJS(src_exports);
302
+ // src/plugin.ts
303
+ var import_core9 = require("@univerjs/core");
304
+ var import_redi8 = require("@wendellhu/redi");
305
+ // src/controllers/uniscript.controller.ts
306
+ var import_core8 = require("@univerjs/core");
307
+ var import_ui4 = require("@univerjs/ui");
308
+ var import_redi7 = require("@wendellhu/redi");
309
+ // src/commands/operations/panel.operation.ts
310
+ var import_core2 = require("@univerjs/core");
311
+ var import_ui = require("@univerjs/ui");
312
+ // src/services/script-panel.service.ts
313
+ var import_core = require("@univerjs/core");
314
+ var import_rxjs = require("rxjs");
315
+ var ScriptPanelService = /*#__PURE__*/ function(_import_core_Disposable) {
316
+ _inherits(ScriptPanelService, _import_core_Disposable);
317
+ var _super = _create_super(ScriptPanelService);
318
+ function ScriptPanelService() {
319
+ _class_call_check(this, ScriptPanelService);
320
+ var _this;
321
+ _this = _super.apply(this, arguments);
322
+ _define_property(_assert_this_initialized(_this), "_open$", new import_rxjs.BehaviorSubject(false));
323
+ _define_property(_assert_this_initialized(_this), "open$", _this._open$.pipe((0, import_rxjs.distinctUntilChanged)()));
324
+ return _this;
325
+ }
326
+ _create_class(ScriptPanelService, [
327
+ {
328
+ key: "isOpen",
329
+ get: function get() {
330
+ return this._open$.getValue();
331
+ }
332
+ },
333
+ {
334
+ key: "dispose",
335
+ value: function dispose() {
336
+ this._open$.next(false);
337
+ this._open$.complete();
338
+ }
339
+ },
340
+ {
341
+ key: "open",
342
+ value: function open() {
343
+ this._open$.next(true);
344
+ }
345
+ },
346
+ {
347
+ key: "close",
348
+ value: function close() {
349
+ this._open$.next(false);
350
+ }
351
+ }
352
+ ]);
353
+ return ScriptPanelService;
354
+ }(import_core.Disposable);
355
+ // src/commands/operations/panel.operation.ts
356
+ var ScriptPanelComponentName = "ScriptPanel";
357
+ var ToggleScriptPanelOperation = {
358
+ type: import_core2.CommandType.OPERATION,
359
+ id: "univer.operation.toggle-sscript-panel",
360
+ handler: function(accessor) {
361
+ var scriptPanelService = accessor.get(ScriptPanelService);
362
+ var sidebarService = accessor.get(import_ui.ISidebarService);
363
+ var isOpen = scriptPanelService.isOpen;
364
+ if (isOpen) {
365
+ scriptPanelService.close();
366
+ sidebarService.close();
367
+ } else {
368
+ scriptPanelService.open();
369
+ sidebarService.open({
370
+ header: {
371
+ title: "script-panel.title"
372
+ },
373
+ children: {
374
+ label: ScriptPanelComponentName
375
+ },
376
+ width: 600
377
+ });
378
+ }
379
+ return true;
380
+ }
381
+ };
382
+ // src/views/components/ScriptEditorPanel.tsx
383
+ var import_core7 = require("@univerjs/core");
384
+ var import_design = require("@univerjs/design");
385
+ var import_ui2 = require("@univerjs/ui");
386
+ var import_react_bindings = require("@wendellhu/redi/react-bindings");
387
+ var import_monaco_editor = require("monaco-editor");
388
+ var import_react = __toESM(require("react"));
389
+ // src/services/script-editor.service.ts
390
+ var import_core3 = require("@univerjs/core");
391
+ var ScriptEditorService = /*#__PURE__*/ function(_import_core3_Disposable) {
392
+ _inherits(ScriptEditorService, _import_core3_Disposable);
393
+ var _super = _create_super(ScriptEditorService);
394
+ function ScriptEditorService(_config) {
395
+ _class_call_check(this, ScriptEditorService);
396
+ var _this;
397
+ _this = _super.call(this);
398
+ _this._config = _config;
399
+ return _this;
400
+ }
401
+ _create_class(ScriptEditorService, [
402
+ {
403
+ key: "requireVscodeEditor",
404
+ value: function requireVscodeEditor() {
405
+ if (!window.MonacoEnvironment) {
406
+ window.MonacoEnvironment = {
407
+ getWorkerUrl: this._config.getWorkerUrl
408
+ };
409
+ }
410
+ }
411
+ }
412
+ ]);
413
+ return ScriptEditorService;
414
+ }(import_core3.Disposable);
415
+ // src/services/script-execution.service.ts
416
+ var import_core6 = require("@univerjs/core");
417
+ var import_redi6 = require("@wendellhu/redi");
418
+ // src/facade/facade.ts
419
+ var import_core5 = require("@univerjs/core");
420
+ var import_redi5 = require("@wendellhu/redi");
421
+ // src/facade/sheet/f-workbook.ts
422
+ var import_redi4 = require("@wendellhu/redi");
423
+ // src/facade/sheet/f-worksheet.ts
424
+ var import_sheets2 = require("@univerjs/sheets");
425
+ var import_redi3 = require("@wendellhu/redi");
426
+ // src/facade/sheet/f-range.ts
427
+ var import_core4 = require("@univerjs/core");
428
+ var import_sheets = require("@univerjs/sheets");
429
+ var import_redi = require("@wendellhu/redi");
430
+ var FRange = /*#__PURE__*/ function() {
431
+ function FRange(_workbook, _worksheet, _range, _injector, _commandService) {
432
+ _class_call_check(this, FRange);
433
+ this._workbook = _workbook;
434
+ this._worksheet = _worksheet;
435
+ this._range = _range;
436
+ this._injector = _injector;
437
+ this._commandService = _commandService;
438
+ }
439
+ _create_class(FRange, [
440
+ {
441
+ key: "getRow",
442
+ value: function getRow() {
443
+ return this._range.startRow;
444
+ }
445
+ },
446
+ {
447
+ key: "getColumn",
448
+ value: function getColumn() {
449
+ return this._range.startColumn;
450
+ }
451
+ },
452
+ {
453
+ key: "getWidth",
454
+ value: function getWidth() {
455
+ return this._range.endColumn - this._range.startColumn + 1;
456
+ }
457
+ },
458
+ {
459
+ key: "getHeight",
460
+ value: function getHeight() {
461
+ return this._range.endRow - this._range.startRow + 1;
462
+ }
463
+ },
464
+ {
465
+ key: "getValue",
466
+ value: function getValue() {
467
+ var _this__worksheet_getCell;
468
+ var _this__worksheet_getCell_v;
469
+ return (_this__worksheet_getCell_v = (_this__worksheet_getCell = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) === null || _this__worksheet_getCell === void 0 ? void 0 : _this__worksheet_getCell.v) !== null && _this__worksheet_getCell_v !== void 0 ? _this__worksheet_getCell_v : null;
470
+ }
471
+ },
472
+ {
473
+ key: "setBackgroundColor",
474
+ value: function setBackgroundColor(color) {
475
+ this._commandService.executeCommand(import_sheets.SetStyleCommand.id, {
476
+ workbookId: this._workbook.getUnitId(),
477
+ worksheetId: this._worksheet.getSheetId(),
478
+ range: this._range,
479
+ style: {
480
+ type: "bg",
481
+ value: {
482
+ rgb: color
483
+ }
484
+ }
485
+ });
486
+ }
487
+ }
488
+ ]);
489
+ return FRange;
490
+ }();
491
+ FRange = __decorateClass([
492
+ __decorateParam(3, (0, import_redi.Inject)(import_redi.Injector)),
493
+ __decorateParam(4, import_core4.ICommandService)
494
+ ], FRange);
495
+ // src/facade/sheet/f-selection.ts
496
+ var import_redi2 = require("@wendellhu/redi");
497
+ var FSelection = /*#__PURE__*/ function() {
498
+ function FSelection(_workbook, _worksheet, _selections, _injector) {
499
+ _class_call_check(this, FSelection);
500
+ this._workbook = _workbook;
501
+ this._worksheet = _worksheet;
502
+ this._selections = _selections;
503
+ this._injector = _injector;
504
+ }
505
+ _create_class(FSelection, [
506
+ {
507
+ key: "getActiveRange",
508
+ value: function getActiveRange() {
509
+ var active = this._selections.find(function(selection) {
510
+ return !!selection.primary;
511
+ });
512
+ if (!active) {
513
+ return null;
514
+ }
515
+ return this._injector.createInstance(FRange, this._workbook, this._worksheet, active.range);
516
+ }
517
+ }
518
+ ]);
519
+ return FSelection;
520
+ }();
521
+ FSelection = __decorateClass([
522
+ __decorateParam(3, (0, import_redi2.Inject)(import_redi2.Injector))
523
+ ], FSelection);
524
+ // src/facade/sheet/f-worksheet.ts
525
+ var FWorksheet = /*#__PURE__*/ function() {
526
+ function FWorksheet(_workbook, _worksheet, _injector, _selectionManagerService) {
527
+ _class_call_check(this, FWorksheet);
528
+ this._workbook = _workbook;
529
+ this._worksheet = _worksheet;
530
+ this._injector = _injector;
531
+ this._selectionManagerService = _selectionManagerService;
532
+ }
533
+ _create_class(FWorksheet, [
534
+ {
535
+ key: "getSelection",
536
+ value: function getSelection() {
537
+ var selections = this._selectionManagerService.getSelections();
538
+ if (!selections) {
539
+ return null;
540
+ }
541
+ return this._injector.createInstance(FSelection, this._workbook, this._worksheet, selections);
542
+ }
543
+ },
544
+ {
545
+ key: "getRange",
546
+ value: function getRange(row, col) {
547
+ var range = {
548
+ startRow: row,
549
+ endRow: row,
550
+ startColumn: col,
551
+ endColumn: col
552
+ };
553
+ return this._injector.createInstance(FRange, this._workbook, this._worksheet, range);
554
+ }
555
+ }
556
+ ]);
557
+ return FWorksheet;
558
+ }();
559
+ FWorksheet = __decorateClass([
560
+ __decorateParam(2, (0, import_redi3.Inject)(import_redi3.Injector)),
561
+ __decorateParam(3, (0, import_redi3.Inject)(import_sheets2.SelectionManagerService))
562
+ ], FWorksheet);
563
+ // src/facade/sheet/f-workbook.ts
564
+ var FWorkbook = /*#__PURE__*/ function() {
565
+ function FWorkbook(_workbook, _injector) {
566
+ _class_call_check(this, FWorkbook);
567
+ this._workbook = _workbook;
568
+ this._injector = _injector;
569
+ }
570
+ _create_class(FWorkbook, [
571
+ {
572
+ key: "getActiveSheet",
573
+ value: function getActiveSheet() {
574
+ var activeSheet = this._workbook.getActiveSheet();
575
+ if (!activeSheet) {
576
+ return null;
577
+ }
578
+ return this._injector.createInstance(FWorksheet, this._workbook, activeSheet);
579
+ }
580
+ }
581
+ ]);
582
+ return FWorkbook;
583
+ }();
584
+ FWorkbook = __decorateClass([
585
+ __decorateParam(1, (0, import_redi4.Inject)(import_redi4.Injector))
586
+ ], FWorkbook);
587
+ // src/facade/facade.ts
588
+ var FUniver = /*#__PURE__*/ function() {
589
+ function FUniver1(_injector, _univerInstanceService) {
590
+ _class_call_check(this, FUniver1);
591
+ this._injector = _injector;
592
+ this._univerInstanceService = _univerInstanceService;
593
+ }
594
+ _create_class(FUniver1, [
595
+ {
596
+ key: "getCurrentSheet",
597
+ value: function getCurrentSheet() {
598
+ var workbook = this._univerInstanceService.getCurrentUniverSheetInstance();
599
+ if (!workbook) {
600
+ return null;
601
+ }
602
+ return this._injector.createInstance(FWorkbook, workbook);
603
+ }
604
+ }
605
+ ], [
606
+ {
607
+ key: "newInstance",
608
+ value: function newInstance(injector) {
609
+ return injector.createInstance(FUniver);
610
+ }
611
+ }
612
+ ]);
613
+ return FUniver1;
614
+ }();
615
+ FUniver = __decorateClass([
616
+ __decorateParam(0, (0, import_redi5.Inject)(import_redi5.Injector)),
617
+ __decorateParam(1, import_core5.IUniverInstanceService)
618
+ ], FUniver);
619
+ // src/services/script-execution.service.ts
620
+ var UniscriptExecutionService = /*#__PURE__*/ function(_import_core6_Disposable) {
621
+ _inherits(UniscriptExecutionService, _import_core6_Disposable);
622
+ var _super = _create_super(UniscriptExecutionService);
623
+ function UniscriptExecutionService(_logService, _injector) {
624
+ _class_call_check(this, UniscriptExecutionService);
625
+ var _this;
626
+ _this = _super.call(this);
627
+ _this._logService = _logService;
628
+ _this._injector = _injector;
629
+ return _this;
630
+ }
631
+ _create_class(UniscriptExecutionService, [
632
+ {
633
+ key: "execute",
634
+ value: function execute(code) {
635
+ var _this = this;
636
+ return _async_to_generator(function() {
637
+ var facadeInstance, scriptFunction;
638
+ return _ts_generator(this, function(_state) {
639
+ _this._logService.log("[UniscriptExecutionService]", "executing Uniscript...");
640
+ facadeInstance = FUniver.newInstance(_this._injector);
641
+ scriptFunction = new Function("Univer", "(() => {".concat(code, "})()"));
642
+ try {
643
+ scriptFunction(facadeInstance);
644
+ return [
645
+ 2,
646
+ true
647
+ ];
648
+ } catch (e) {
649
+ _this._logService.error(e);
650
+ return [
651
+ 2,
652
+ false
653
+ ];
654
+ }
655
+ return [
656
+ 2
657
+ ];
658
+ });
659
+ })();
660
+ }
661
+ }
662
+ ]);
663
+ return UniscriptExecutionService;
664
+ }(import_core6.Disposable);
665
+ UniscriptExecutionService = __decorateClass([
666
+ __decorateParam(0, import_core6.ILogService),
667
+ __decorateParam(1, (0, import_redi6.Inject)(import_redi6.Injector))
668
+ ], UniscriptExecutionService);
669
+ // stylePlugin:/Users/jikkaixiao/dev/univer/packages/uniscript/src/views/components/index.module.less
670
+ var index_module_default = {
671
+ "scriptEditorPanel": "univer-script-editor-panel",
672
+ "scriptEditorContent": "univer-script-editor-content"
673
+ };
674
+ // src/views/components/ScriptEditorPanel.tsx
675
+ function ScriptEditorPanel() {
676
+ var editorContentRef = (0, import_react.useRef)(null);
677
+ var editorContainerRef = (0, import_react.useRef)(null);
678
+ var monacoEditorRef = (0, import_react.useRef)(null);
679
+ var localeService = (0, import_react_bindings.useDependency)(import_core7.LocaleService);
680
+ var scriptService = (0, import_react_bindings.useDependency)(UniscriptExecutionService);
681
+ var shortcutService = (0, import_react_bindings.useDependency)(import_ui2.IShortcutService);
682
+ var editorService = (0, import_react_bindings.useDependency)(ScriptEditorService);
683
+ var messageService = (0, import_react_bindings.useDependency)(import_ui2.IMessageService);
684
+ (0, import_react.useEffect)(function() {
685
+ var containerElement = editorContainerRef.current;
686
+ var contentElement = editorContentRef.current;
687
+ var disposableCollection = null;
688
+ var resizeObserver = null;
689
+ if (containerElement && contentElement) {
690
+ editorService.requireVscodeEditor();
691
+ var monacoEditor = monacoEditorRef.current = import_monaco_editor.editor.create(containerElement, {
692
+ value: "",
693
+ language: "javascript"
694
+ });
695
+ resizeObserver = new ResizeObserver(function() {
696
+ var timer = requestIdleCallback(function() {
697
+ if (!timer) return;
698
+ var _contentElement_getBoundingClientRect = contentElement.getBoundingClientRect(), height = _contentElement_getBoundingClientRect.height, width = _contentElement_getBoundingClientRect.width;
699
+ monacoEditor.layout({
700
+ width: width,
701
+ height: height
702
+ });
703
+ timer = void 0;
704
+ });
705
+ });
706
+ resizeObserver.observe(contentElement);
707
+ var terminateEscaping;
708
+ disposableCollection = new import_core7.DisposableCollection();
709
+ disposableCollection.add(monacoEditor.onDidFocusEditorWidget(function() {
710
+ terminateEscaping = shortcutService.forceEscape();
711
+ }));
712
+ disposableCollection.add(monacoEditor.onDidBlurEditorWidget(function() {
713
+ terminateEscaping === null || terminateEscaping === void 0 ? void 0 : terminateEscaping.dispose();
714
+ terminateEscaping = void 0;
715
+ }));
716
+ disposableCollection.add((0, import_core7.toDisposable)(function() {
717
+ return terminateEscaping === null || terminateEscaping === void 0 ? void 0 : terminateEscaping.dispose();
718
+ }));
719
+ }
720
+ return function() {
721
+ if (resizeObserver && contentElement) {
722
+ resizeObserver.unobserve(contentElement);
723
+ }
724
+ disposableCollection === null || disposableCollection === void 0 ? void 0 : disposableCollection.dispose();
725
+ };
726
+ }, []);
727
+ var startExecution = (0, import_react.useCallback)(function() {
728
+ var _monacoEditorRef_current;
729
+ var model = (_monacoEditorRef_current = monacoEditorRef.current) === null || _monacoEditorRef_current === void 0 ? void 0 : _monacoEditorRef_current.getModel();
730
+ if (model) {
731
+ scriptService.execute(model.getValue()).then(function() {
732
+ messageService.show({
733
+ content: "Execution completed",
734
+ type: import_design.MessageType.Success
735
+ });
736
+ }).catch(function() {
737
+ messageService.show({
738
+ content: "Execution failed",
739
+ type: import_design.MessageType.Error
740
+ });
741
+ });
742
+ }
743
+ }, [
744
+ scriptService
745
+ ]);
746
+ return /* @__PURE__ */ import_react.default.createElement("div", {
747
+ className: index_module_default.scriptEditorPanel
748
+ }, /* @__PURE__ */ import_react.default.createElement("div", {
749
+ className: index_module_default.scriptEditorContent,
750
+ ref: editorContentRef
751
+ }, /* @__PURE__ */ import_react.default.createElement("div", {
752
+ className: index_module_default.scriptEditorContainer,
753
+ ref: editorContainerRef
754
+ })), /* @__PURE__ */ import_react.default.createElement("div", {
755
+ className: index_module_default.scriptEditorActions
756
+ }, /* @__PURE__ */ import_react.default.createElement(import_design.Button, {
757
+ type: "primary",
758
+ size: "small",
759
+ onClick: startExecution
760
+ }, localeService.t("script-panel.panel.execute"))));
761
+ }
762
+ // src/controllers/menu.ts
763
+ var import_ui3 = require("@univerjs/ui");
764
+ function UniscriptMenuItemFactory() {
765
+ return {
766
+ id: ToggleScriptPanelOperation.id,
767
+ title: "toggle-script-panel",
768
+ tooltip: "script-panel.tooltip.menu-button",
769
+ icon: "CodeSingle",
770
+ type: import_ui3.MenuItemType.BUTTON,
771
+ positions: [
772
+ import_ui3.MenuPosition.TOOLBAR_START
773
+ ]
774
+ };
775
+ }
776
+ // src/controllers/uniscript.controller.ts
777
+ var UniscriptController = /*#__PURE__*/ function(_import_core8_Disposable) {
778
+ _inherits(UniscriptController, _import_core8_Disposable);
779
+ var _super = _create_super(UniscriptController);
780
+ function UniscriptController(menuService, commandService, componentManager) {
781
+ _class_call_check(this, UniscriptController);
782
+ var _this;
783
+ _this = _super.call(this);
784
+ _this.disposeWithMe(menuService.addMenuItem(UniscriptMenuItemFactory()));
785
+ _this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
786
+ _this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
787
+ return _this;
788
+ }
789
+ return UniscriptController;
790
+ }(import_core8.Disposable);
791
+ UniscriptController = __decorateClass([
792
+ (0, import_core8.OnLifecycle)(import_core8.LifecycleStages.Steady, UniscriptController),
793
+ __decorateParam(0, import_ui4.IMenuService),
794
+ __decorateParam(1, import_core8.ICommandService),
795
+ __decorateParam(2, (0, import_redi7.Inject)(import_ui4.ComponentManager))
796
+ ], UniscriptController);
797
+ // src/locale/en-US.ts
798
+ var en_US_default = {
799
+ "script-panel": {
800
+ title: "Uniscript",
801
+ tooltip: {
802
+ "menu-button": "Toggle Uniscript Panel"
803
+ },
804
+ panel: {
805
+ execute: "Execute Script"
806
+ }
807
+ }
808
+ };
809
+ // src/plugin.ts
810
+ var PLUGIN_NAME = "uniscript";
811
+ var UniscriptPlugin = (_class = /*#__PURE__*/ function(_superClass) {
812
+ _inherits(_class, _superClass);
813
+ var _super = _create_super(_class);
814
+ function _class(_config, _injector, _localeService) {
815
+ _class_call_check(this, _class);
816
+ var _this;
817
+ _this = _super.call(this, PLUGIN_NAME);
818
+ _this._config = _config;
819
+ _this._injector = _injector;
820
+ _this._localeService = _localeService;
821
+ return _this;
822
+ }
823
+ _create_class(_class, [
824
+ {
825
+ key: "onStarting",
826
+ value: function onStarting(injector) {
827
+ var _this = this;
828
+ var dependencies = [
829
+ // controllers
830
+ [
831
+ UniscriptController
832
+ ],
833
+ // services
834
+ [
835
+ ScriptEditorService,
836
+ {
837
+ useFactory: function() {
838
+ return injector.createInstance(ScriptEditorService, _this._config);
839
+ }
840
+ }
841
+ ],
842
+ [
843
+ ScriptPanelService
844
+ ],
845
+ [
846
+ UniscriptExecutionService
847
+ ]
848
+ ];
849
+ dependencies.forEach(function(d) {
850
+ return injector.add(d);
851
+ });
852
+ this._localeService.load({
853
+ enUS: en_US_default
854
+ });
855
+ }
856
+ }
857
+ ]);
858
+ return _class;
859
+ }(_import_core9_Plugin = import_core9.Plugin), _define_property(_class, "type", import_core9.PluginType.Univer), _class);
860
+ UniscriptPlugin = __decorateClass([
861
+ __decorateParam(1, (0, import_redi8.Inject)(import_redi8.Injector)),
862
+ __decorateParam(2, (0, import_redi8.Inject)(import_core9.LocaleService))
863
+ ], UniscriptPlugin);