@univerjs/uniscript 0.1.0-alpha.1 → 0.1.0-alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. package/LICENSE.txt +178 -0
  2. package/README.md +1 -5
  3. package/lib/cjs/index.js +9 -863
  4. package/lib/es/index.js +366 -0
  5. package/lib/index.css +1 -9
  6. package/lib/types/commands/operations/panel.operation.d.ts +15 -1
  7. package/lib/types/controllers/menu.d.ts +15 -1
  8. package/lib/types/controllers/uniscript.controller.d.ts +15 -1
  9. package/lib/types/facade/facade.d.ts +15 -1
  10. package/lib/types/facade/sheet/f-range.d.ts +15 -1
  11. package/lib/types/facade/sheet/f-selection.d.ts +15 -1
  12. package/lib/types/facade/sheet/f-workbook.d.ts +15 -1
  13. package/lib/types/facade/sheet/f-worksheet.d.ts +16 -2
  14. package/lib/types/index.d.ts +17 -2
  15. package/lib/types/locale/en-US.d.ts +15 -1
  16. package/lib/types/locale/index.d.ts +15 -1
  17. package/lib/types/locale/zh-CN.d.ts +26 -2
  18. package/lib/types/plugin.d.ts +18 -4
  19. package/lib/types/services/command/batch-command.service.d.ts +16 -1
  20. package/lib/types/services/script-editor.service.d.ts +15 -1
  21. package/lib/types/services/script-execution.service.d.ts +15 -1
  22. package/lib/types/services/script-panel.service.d.ts +15 -1
  23. package/lib/types/views/components/ScriptEditorPanel.d.ts +15 -1
  24. package/lib/umd/index.js +9 -0
  25. package/package.json +35 -28
  26. package/LICENSE +0 -21
  27. package/lib/cjs/locale/en-US.js +0 -36
  28. package/lib/cjs/locale/zh-CN.js +0 -26
  29. package/lib/esm/index.js +0 -855
  30. package/lib/esm/locale/en-US.js +0 -15
  31. package/lib/esm/locale/zh-CN.js +0 -5
  32. package/lib/types/commands/operations/panel.operation.d.ts.map +0 -1
  33. package/lib/types/controllers/menu.d.ts.map +0 -1
  34. package/lib/types/controllers/uniscript.controller.d.ts.map +0 -1
  35. package/lib/types/facade/facade.d.ts.map +0 -1
  36. package/lib/types/facade/sheet/f-range.d.ts.map +0 -1
  37. package/lib/types/facade/sheet/f-selection.d.ts.map +0 -1
  38. package/lib/types/facade/sheet/f-workbook.d.ts.map +0 -1
  39. package/lib/types/facade/sheet/f-worksheet.d.ts.map +0 -1
  40. package/lib/types/index.d.ts.map +0 -1
  41. package/lib/types/locale/en-US.d.ts.map +0 -1
  42. package/lib/types/locale/index.d.ts.map +0 -1
  43. package/lib/types/locale/zh-CN.d.ts.map +0 -1
  44. package/lib/types/models/model.d.ts +0 -1
  45. package/lib/types/models/model.d.ts.map +0 -1
  46. package/lib/types/plugin.d.ts.map +0 -1
  47. package/lib/types/services/command/batch-command.service.d.ts.map +0 -1
  48. package/lib/types/services/script-editor.service.d.ts.map +0 -1
  49. package/lib/types/services/script-execution.service.d.ts.map +0 -1
  50. package/lib/types/services/script-panel.service.d.ts.map +0 -1
  51. package/lib/types/views/components/ScriptEditorPanel.d.ts.map +0 -1
  52. package/lib/types/views/parts/render.part.d.ts +0 -1
  53. package/lib/types/views/parts/render.part.d.ts.map +0 -1
package/lib/cjs/index.js CHANGED
@@ -1,863 +1,9 @@
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);
1
+ "use strict";var Q=Object.defineProperty;var X=(t,e,n)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var S=(t,e,n)=>(X(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),a=require("@wendellhu/redi"),_=require("@univerjs/ui"),T=require("rxjs"),v=require("react"),C=require("@univerjs/design"),d=require("@wendellhu/redi/react-bindings"),Z=require("monaco-editor"),L=require("@univerjs/sheets"),ee={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}}},B={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}}};class z extends c.Disposable{constructor(){super(...arguments);S(this,"_open$",new T.BehaviorSubject(!1));S(this,"open$",this._open$.pipe(T.distinctUntilChanged()))}get isOpen(){return this._open$.getValue()}dispose(){this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}}const V="ScriptPanel",k={type:c.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get(z),n=t.get(_.ISidebarService);return e.isOpen?(e.close(),n.close()):(e.open(),n.open({header:{title:"script-panel.title"},children:{label:V},width:600})),!0}};var G={exports:{}},O={};/**
2
+ * @license React
3
+ * react-jsx-runtime.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */var te=v,re=Symbol.for("react.element"),ne=Symbol.for("react.fragment"),se=Object.prototype.hasOwnProperty,ie=te.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,oe={key:!0,ref:!0,__self:!0,__source:!0};function H(t,e,n){var r,s={},i=null,o=null;n!==void 0&&(i=""+n),e.key!==void 0&&(i=""+e.key),e.ref!==void 0&&(o=e.ref);for(r in e)se.call(e,r)&&!oe.hasOwnProperty(r)&&(s[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)s[r]===void 0&&(s[r]=e[r]);return{$$typeof:re,type:t,key:i,ref:o,props:s,_owner:ie.current}}O.Fragment=ne;O.jsx=H;O.jsxs=H;G.exports=O;var f=G.exports;class E extends c.Disposable{constructor(e){super(),this._config=e}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var ce=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,le=(t,e,n,r)=>{for(var s=r>1?void 0:r?ae(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&ce(e,n,s),s},q=(t,e)=>(n,r)=>e(n,r,t);let j=class{constructor(t,e,n,r,s){this._workbook=t,this._worksheet=e,this._range=n,this._injector=r,this._commandService=s}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}getValue(){var t;return((t=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:t.v)??null}setBackgroundColor(t){this._commandService.executeCommand(L.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:t}}})}};j=le([q(3,a.Inject(a.Injector)),q(4,c.ICommandService)],j);var ue=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,_e=(t,e,n,r)=>{for(var s=r>1?void 0:r?pe(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&ue(e,n,s),s},ve=(t,e)=>(n,r)=>e(n,r,t);let x=class{constructor(t,e,n,r){this._workbook=t,this._worksheet=e,this._selections=n,this._injector=r}getActiveRange(){const t=this._selections.find(e=>!!e.primary);return t?this._injector.createInstance(j,this._workbook,this._worksheet,t.range):null}};x=_e([ve(3,a.Inject(a.Injector))],x);var he=Object.defineProperty,de=Object.getOwnPropertyDescriptor,fe=(t,e,n,r)=>{for(var s=r>1?void 0:r?de(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&he(e,n,s),s},N=(t,e)=>(n,r)=>e(n,r,t);let U=class{constructor(t,e,n,r){this._workbook=t,this._worksheet=e,this._injector=n,this._selectionManagerService=r}getSelection(){const t=this._selectionManagerService.getSelections();return t?this._injector.createInstance(x,this._workbook,this._worksheet,t):null}getRange(t,e,n,r){const s={startRow:t,endRow:t+(n??1)-1,startColumn:e,endColumn:e+(r??1)-1};return this._injector.createInstance(j,this._workbook,this._worksheet,s)}};U=fe([N(2,a.Inject(a.Injector)),N(3,a.Inject(L.SelectionManagerService))],U);var ge=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,me=(t,e,n,r)=>{for(var s=r>1?void 0:r?Se(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&ge(e,n,s),s},Pe=(t,e)=>(n,r)=>e(n,r,t);let D=class{constructor(t,e){this._workbook=t,this._injector=e}getActiveSheet(){const t=this._workbook.getActiveSheet();return t?this._injector.createInstance(U,this._workbook,t):null}};D=me([Pe(1,a.Inject(a.Injector))],D);var je=Object.defineProperty,we=Object.getOwnPropertyDescriptor,be=(t,e,n,r)=>{for(var s=r>1?void 0:r?we(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&je(e,n,s),s},F=(t,e)=>(n,r)=>e(n,r,t);let w=class{constructor(t,e){this._injector=t,this._univerInstanceService=e}static newInstance(t){return t.createInstance(w)}getCurrentSheet(){const t=this._univerInstanceService.getCurrentUniverSheetInstance();return t?this._injector.createInstance(D,t):null}};w=be([F(0,a.Inject(a.Injector)),F(1,c.IUniverInstanceService)],w);var Oe=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Ce=(t,e,n,r)=>{for(var s=r>1?void 0:r?Ie(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&Oe(e,n,s),s},A=(t,e)=>(n,r)=>e(n,r,t);let b=class extends c.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=w.newInstance(this._injector),n=new Function("Univer",`(() => {${t}})()`);try{return n(e),!0}catch(r){return this._logService.error(r),!1}}};b=Ce([A(0,c.ILogService),A(1,a.Inject(a.Injector))],b);const ye="univer-script-editor-panel",$e="univer-script-editor-content",Ee="univer-script-editor-actions",m={scriptEditorPanel:ye,scriptEditorContent:$e,scriptEditorActions:Ee};function xe(){const t=v.useRef(null),e=v.useRef(null),n=v.useRef(null),r=d.useDependency(c.LocaleService),s=d.useDependency(b),i=d.useDependency(_.IShortcutService),o=d.useDependency(E),R=d.useDependency(_.IMessageService);v.useEffect(()=>{const h=e.current,l=t.current;let p=null,g=null;if(h&&l){o.requireVscodeEditor();const I=n.current=Z.editor.create(h,{value:"",language:"javascript"});g=new ResizeObserver(()=>{let M=requestIdleCallback(()=>{if(!M)return;const{height:Y,width:K}=l.getBoundingClientRect();I.layout({width:K,height:Y}),M=void 0})}),g.observe(l);let u;p=new c.DisposableCollection,p.add(I.onDidFocusEditorWidget(()=>{u=i.forceEscape()})),p.add(I.onDidBlurEditorWidget(()=>{u==null||u.dispose(),u=void 0})),p.add(c.toDisposable(()=>u==null?void 0:u.dispose()))}return()=>{g&&l&&g.unobserve(l),p==null||p.dispose()}},[]);const J=v.useCallback(()=>{var l;const h=(l=n.current)==null?void 0:l.getModel();h&&s.execute(h.getValue()).then(()=>{R.show({content:"Execution completed",type:C.MessageType.Success})}).catch(()=>{R.show({content:"Execution failed",type:C.MessageType.Error})})},[s]);return f.jsxs("div",{className:m.scriptEditorPanel,children:[f.jsx("div",{className:m.scriptEditorContent,ref:t,children:f.jsx("div",{className:m.scriptEditorContainer,ref:e})}),f.jsx("div",{className:m.scriptEditorActions,children:f.jsx(C.Button,{type:"primary",size:"small",onClick:J,children:r.t("script-panel.panel.execute")})})]})}function Ue(){return{id:k.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:_.MenuItemType.BUTTON,positions:[_.MenuPosition.TOOLBAR_START]}}var De=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Me=(t,e,n,r)=>{for(var s=r>1?void 0:r?Re(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&De(e,n,s),s},y=(t,e)=>(n,r)=>e(n,r,t);let P=class extends c.Disposable{constructor(t,e,n){super(),this.disposeWithMe(t.addMenuItem(Ue())),this.disposeWithMe(n.register(V,xe)),this.disposeWithMe(e.registerCommand(k))}};P=Me([c.OnLifecycle(c.LifecycleStages.Steady,P),y(0,_.IMenuService),y(1,c.ICommandService),y(2,a.Inject(_.ComponentManager))],P);var Te=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Ne=(t,e,n,r)=>{for(var s=r>1?void 0:r?qe(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&Te(e,n,s),s},W=(t,e)=>(n,r)=>e(n,r,t);const Fe="uniscript";var $;exports.UniverUniscriptPlugin=($=class extends c.Plugin{constructor(e,n,r){super(Fe),this._config=e,this._injector=n,this._localeService=r}onStarting(e){[[P],[E,{useFactory:()=>e.createInstance(E,this._config)}],[z],[b]].forEach(r=>e.add(r)),this._localeService.load({zhCN:B})}},S($,"type",c.PluginType.Univer),$);exports.UniverUniscriptPlugin=Ne([W(1,a.Inject(a.Injector)),W(2,a.Inject(c.LocaleService))],exports.UniverUniscriptPlugin);exports.enUS=ee;exports.zhCN=B;