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