@univerjs/uniscript 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/cjs/index.js +417 -1
  2. package/lib/cjs/locale/ca-ES.js +16 -1
  3. package/lib/cjs/locale/en-US.js +31 -1
  4. package/lib/cjs/locale/es-ES.js +16 -1
  5. package/lib/cjs/locale/fa-IR.js +16 -1
  6. package/lib/cjs/locale/fr-FR.js +16 -1
  7. package/lib/cjs/locale/ja-JP.js +16 -1
  8. package/lib/cjs/locale/ko-KR.js +16 -1
  9. package/lib/cjs/locale/ru-RU.js +16 -1
  10. package/lib/cjs/locale/sk-SK.js +16 -1
  11. package/lib/cjs/locale/vi-VN.js +16 -1
  12. package/lib/cjs/locale/zh-CN.js +16 -1
  13. package/lib/cjs/locale/zh-TW.js +16 -1
  14. package/lib/es/index.js +403 -1
  15. package/lib/es/locale/ca-ES.js +15 -1
  16. package/lib/es/locale/en-US.js +30 -1
  17. package/lib/es/locale/es-ES.js +15 -1
  18. package/lib/es/locale/fa-IR.js +15 -1
  19. package/lib/es/locale/fr-FR.js +15 -1
  20. package/lib/es/locale/ja-JP.js +15 -1
  21. package/lib/es/locale/ko-KR.js +15 -1
  22. package/lib/es/locale/ru-RU.js +15 -1
  23. package/lib/es/locale/sk-SK.js +15 -1
  24. package/lib/es/locale/vi-VN.js +15 -1
  25. package/lib/es/locale/zh-CN.js +15 -1
  26. package/lib/es/locale/zh-TW.js +15 -1
  27. package/lib/index.js +403 -1
  28. package/lib/locale/ca-ES.js +15 -1
  29. package/lib/locale/en-US.js +30 -1
  30. package/lib/locale/es-ES.js +15 -1
  31. package/lib/locale/fa-IR.js +15 -1
  32. package/lib/locale/fr-FR.js +15 -1
  33. package/lib/locale/ja-JP.js +15 -1
  34. package/lib/locale/ko-KR.js +15 -1
  35. package/lib/locale/ru-RU.js +15 -1
  36. package/lib/locale/sk-SK.js +15 -1
  37. package/lib/locale/vi-VN.js +15 -1
  38. package/lib/locale/zh-CN.js +15 -1
  39. package/lib/locale/zh-TW.js +15 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +9 -9
package/lib/es/index.js CHANGED
@@ -1 +1,403 @@
1
- import{CommandType as e,Disposable as t,DisposableCollection as n,ICommandService as r,IConfigService as i,ILogService as a,Inject as o,Injector as s,LocaleService as c,Plugin as l,ThemeService as u,UniverInstanceType as d,createIdentifier as f,merge as p,toDisposable as m}from"@univerjs/core";import{ComponentManager as h,IMenuManagerService as g,IMessageService as _,IShortcutService as v,ISidebarService as y,MenuItemType as b,RibbonOthersGroup as x,getMenuHiddenObservable as S,useDependency as C}from"@univerjs/ui";import{BehaviorSubject as ee,distinctUntilChanged as te}from"rxjs";import{RangeProtectionPermissionEditPoint as ne,WorkbookEditablePermission as re,WorksheetEditPermission as ie,WorksheetSetCellStylePermission as ae,WorksheetSetCellValuePermission as oe}from"@univerjs/sheets";import{getCurrentRangeDisable$ as w}from"@univerjs/sheets-ui";import{Button as T,MessageType as E}from"@univerjs/design";import{editor as D}from"monaco-editor";import{useCallback as O,useEffect as k,useRef as A}from"react";import{FUniver as j}from"@univerjs/core/facade";import{jsx as M,jsxs as N}from"react/jsx-runtime";function P(e){"@babel/helpers - typeof";return P=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},P(e)}function F(e,t){if(P(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(P(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function I(e){var t=F(e,`string`);return P(t)==`symbol`?t:t+``}function L(e,t,n){return(t=I(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var R=class extends t{constructor(...e){super(...e),L(this,`_open$`,new ee(!1)),L(this,`open$`,this._open$.pipe(te()))}get isOpen(){return this._open$.getValue()}dispose(){super.dispose(),this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}};const z=`ScriptPanel`,B={type:e.OPERATION,id:`univer.operation.toggle-script-panel`,handler:e=>{let t=e.get(R),n=e.get(y);return t.isOpen?(t.close(),n.close()):(t.open(),n.open({header:{title:`script-panel.title`},children:{label:z},width:600})),!0}};var V=`@univerjs/uniscript`,H=`0.20.1`;const U=`uniscript.config`;Symbol(U);const W={};function G(e){return{id:B.id,title:`toggle-script-panel`,tooltip:`script-panel.tooltip.menu-button`,icon:`CodeIcon`,type:b.BUTTON,hidden$:S(e,d.UNIVER_SHEET),disabled$:w(e,{workbookTypes:[re],worksheetTypes:[ie,ae,oe],rangeTypes:[ne]})}}const K={[x.OTHERS]:{[B.id]:{order:0,menuItemFactory:G}}};function q(e,t){return function(n,r){t(n,r,e)}}function J(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Y=class extends t{constructor(e){super(),this._configService=e,L(this,`_editorInstance`,null)}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(e){return this._editorInstance=e,m(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){let e=this._configService.getConfig(U);window.MonacoEnvironment={getWorkerUrl:e==null?void 0:e.getWorkerUrl}}}};Y=J([q(0,i)],Y);const X=f(`univer.uniscript.execution-service`);let Z=class extends t{constructor(e,t){super(),this._logService=e,this._injector=t}async execute(e){this._logService.log(`[UniscriptExecutionService]`,`executing Uniscript...`);let t=j.newAPI(this._injector),n=Function(`univerAPI`,`(() => {${e}})()`);try{return n(t),!0}catch(e){return this._logService.error(e),!1}}};Z=J([q(0,a),q(1,o(s))],Z);function se(){let e=A(null),t=A(null),r=A(null),i=C(c),a=C(v),o=C(Y),s=C(u);k(()=>{let i=t.current,c=e.current,l=null,u=null;if(i&&c){o.requireVscodeEditor();let e=r.current=D.create(i,{value:``,language:`javascript`,theme:s.darkMode?`vs-dark`:`vs-light`});u=new ResizeObserver(()=>{let t=requestIdleCallback(()=>{if(!t)return;let{height:n,width:r}=c.getBoundingClientRect();e.layout({width:r,height:n}),t=void 0})}),u.observe(c);let t;l=new n,l.add(o.setEditorInstance(e)),l.add(e.onDidFocusEditorWidget(()=>{t=a.forceEscape()})),l.add(e.onDidBlurEditorWidget(()=>{t==null||t.dispose(),t=void 0})),l.add(m(()=>t==null?void 0:t.dispose()))}return()=>{u&&c&&u.unobserve(c),l==null||l.dispose()}},[o,a]);let l=ce(r);return N(`div`,{className:`univer-h-full`,children:[M(`div`,{ref:e,className:`univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden`,children:M(`div`,{ref:t})}),M(`div`,{className:`univer-mt-2.5`,children:M(T,{variant:`primary`,onClick:l,children:i.t(`script-panel.panel.execute`)})})]})}function ce(e){let t=C(X),n=C(_),r=C(c);return O(()=>{var i;let a=(i=e.current)==null?void 0:i.getModel();a&&t.execute(a.getValue()).then(()=>{n.show({content:r.t(`uniscript.message.success`),type:E.Success})}).catch(()=>{n.show({content:r.t(`uniscript.message.failed`),type:E.Error})})},[r,n,e,t])}let Q=class extends t{constructor(e,t,n){super(),this._menuManagerService=e,this._menuManagerService.mergeMenu(K),this.disposeWithMe(n.register(z,se)),this.disposeWithMe(t.registerCommand(B))}};Q=J([q(0,g),q(1,r),q(2,o(h))],Q);let $=class extends l{constructor(e=W,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=p({},W,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(U,i)}onStarting(){let e=this._injector;[[Q],[Y],[R]].forEach(t=>e.add(t)),this.registerExecution()}onSteady(){this._injector.get(Q)}registerExecution(){this._injector.add([X,{useClass:Z}])}};L($,`pluginName`,`UNIVER_UNISCRIPT_PLUGIN`),L($,`packageName`,V),L($,`version`,H),$=J([q(1,o(s)),q(2,i)],$);export{X as IUniscriptExecutionService,Y as ScriptEditorService,B as ToggleScriptPanelOperation,$ as UniverUniscriptPlugin};
1
+ import { CommandType, Disposable, DisposableCollection, ICommandService, IConfigService, ILogService, Inject, Injector, LocaleService, Plugin, ThemeService, UniverInstanceType, createIdentifier, merge, toDisposable } from "@univerjs/core";
2
+ import { ComponentManager, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, MenuItemType, RibbonOthersGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
3
+ import { BehaviorSubject, distinctUntilChanged } from "rxjs";
4
+ import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
5
+ import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
6
+ import { Button, MessageType } from "@univerjs/design";
7
+ import { editor } from "monaco-editor";
8
+ import { useCallback, useEffect, useRef } from "react";
9
+ import { FUniver } from "@univerjs/core/facade";
10
+ import { jsx, jsxs } from "react/jsx-runtime";
11
+
12
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
13
+ function _typeof(o) {
14
+ "@babel/helpers - typeof";
15
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
16
+ return typeof o;
17
+ } : function(o) {
18
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
19
+ }, _typeof(o);
20
+ }
21
+
22
+ //#endregion
23
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
24
+ function toPrimitive(t, r) {
25
+ if ("object" != _typeof(t) || !t) return t;
26
+ var e = t[Symbol.toPrimitive];
27
+ if (void 0 !== e) {
28
+ var i = e.call(t, r || "default");
29
+ if ("object" != _typeof(i)) return i;
30
+ throw new TypeError("@@toPrimitive must return a primitive value.");
31
+ }
32
+ return ("string" === r ? String : Number)(t);
33
+ }
34
+
35
+ //#endregion
36
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
37
+ function toPropertyKey(t) {
38
+ var i = toPrimitive(t, "string");
39
+ return "symbol" == _typeof(i) ? i : i + "";
40
+ }
41
+
42
+ //#endregion
43
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
44
+ function _defineProperty(e, r, t) {
45
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
46
+ value: t,
47
+ enumerable: !0,
48
+ configurable: !0,
49
+ writable: !0
50
+ }) : e[r] = t, e;
51
+ }
52
+
53
+ //#endregion
54
+ //#region src/services/script-panel.service.ts
55
+ /**
56
+ * Copyright 2023-present DreamNum Co., Ltd.
57
+ *
58
+ * Licensed under the Apache License, Version 2.0 (the "License");
59
+ * you may not use this file except in compliance with the License.
60
+ * You may obtain a copy of the License at
61
+ *
62
+ * http://www.apache.org/licenses/LICENSE-2.0
63
+ *
64
+ * Unless required by applicable law or agreed to in writing, software
65
+ * distributed under the License is distributed on an "AS IS" BASIS,
66
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
67
+ * See the License for the specific language governing permissions and
68
+ * limitations under the License.
69
+ */
70
+ var ScriptPanelService = class extends Disposable {
71
+ constructor(..._args) {
72
+ super(..._args);
73
+ _defineProperty(this, "_open$", new BehaviorSubject(false));
74
+ _defineProperty(this, "open$", this._open$.pipe(distinctUntilChanged()));
75
+ }
76
+ get isOpen() {
77
+ return this._open$.getValue();
78
+ }
79
+ dispose() {
80
+ super.dispose();
81
+ this._open$.next(false);
82
+ this._open$.complete();
83
+ }
84
+ open() {
85
+ this._open$.next(true);
86
+ }
87
+ close() {
88
+ this._open$.next(false);
89
+ }
90
+ };
91
+
92
+ //#endregion
93
+ //#region src/commands/operations/panel.operation.ts
94
+ const ScriptPanelComponentName = "ScriptPanel";
95
+ const ToggleScriptPanelOperation = {
96
+ type: CommandType.OPERATION,
97
+ id: "univer.operation.toggle-script-panel",
98
+ handler: (accessor) => {
99
+ const scriptPanelService = accessor.get(ScriptPanelService);
100
+ const sidebarService = accessor.get(ISidebarService);
101
+ if (scriptPanelService.isOpen) {
102
+ scriptPanelService.close();
103
+ sidebarService.close();
104
+ } else {
105
+ scriptPanelService.open();
106
+ sidebarService.open({
107
+ header: { title: "script-panel.title" },
108
+ children: { label: ScriptPanelComponentName },
109
+ width: 600
110
+ });
111
+ }
112
+ return true;
113
+ }
114
+ };
115
+
116
+ //#endregion
117
+ //#region package.json
118
+ var name = "@univerjs/uniscript";
119
+ var version = "0.21.0";
120
+
121
+ //#endregion
122
+ //#region src/config/config.ts
123
+ const UNISCRIPT_PLUGIN_CONFIG_KEY = "uniscript.config";
124
+ const configSymbol = Symbol(UNISCRIPT_PLUGIN_CONFIG_KEY);
125
+ const defaultPluginConfig = {};
126
+
127
+ //#endregion
128
+ //#region src/menu/menu.ts
129
+ function UniscriptMenuItemFactory(accessor) {
130
+ return {
131
+ id: ToggleScriptPanelOperation.id,
132
+ title: "toggle-script-panel",
133
+ tooltip: "script-panel.tooltip.menu-button",
134
+ icon: "CodeIcon",
135
+ type: MenuItemType.BUTTON,
136
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
137
+ disabled$: getCurrentRangeDisable$(accessor, {
138
+ workbookTypes: [WorkbookEditablePermission],
139
+ worksheetTypes: [
140
+ WorksheetEditPermission,
141
+ WorksheetSetCellStylePermission,
142
+ WorksheetSetCellValuePermission
143
+ ],
144
+ rangeTypes: [RangeProtectionPermissionEditPoint]
145
+ })
146
+ };
147
+ }
148
+
149
+ //#endregion
150
+ //#region src/menu/schema.ts
151
+ const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
152
+ order: 0,
153
+ menuItemFactory: UniscriptMenuItemFactory
154
+ } } };
155
+
156
+ //#endregion
157
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
158
+ function __decorateParam(paramIndex, decorator) {
159
+ return function(target, key) {
160
+ decorator(target, key, paramIndex);
161
+ };
162
+ }
163
+
164
+ //#endregion
165
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
166
+ function __decorate(decorators, target, key, desc) {
167
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
168
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
169
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
170
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
171
+ }
172
+
173
+ //#endregion
174
+ //#region src/services/script-editor.service.ts
175
+ let ScriptEditorService = class ScriptEditorService extends Disposable {
176
+ constructor(_configService) {
177
+ super();
178
+ this._configService = _configService;
179
+ _defineProperty(this, "_editorInstance", null);
180
+ }
181
+ dispose() {
182
+ super.dispose();
183
+ if (this._editorInstance) this._editorInstance.dispose();
184
+ }
185
+ setEditorInstance(editor) {
186
+ this._editorInstance = editor;
187
+ return toDisposable(() => this._editorInstance = null);
188
+ }
189
+ getEditorInstance() {
190
+ return this._editorInstance;
191
+ }
192
+ requireVscodeEditor() {
193
+ if (!window.MonacoEnvironment) {
194
+ const config = this._configService.getConfig(UNISCRIPT_PLUGIN_CONFIG_KEY);
195
+ window.MonacoEnvironment = { getWorkerUrl: config === null || config === void 0 ? void 0 : config.getWorkerUrl };
196
+ }
197
+ }
198
+ };
199
+ ScriptEditorService = __decorate([__decorateParam(0, IConfigService)], ScriptEditorService);
200
+
201
+ //#endregion
202
+ //#region src/services/script-execution.service.ts
203
+ /**
204
+ * Copyright 2023-present DreamNum Co., Ltd.
205
+ *
206
+ * Licensed under the Apache License, Version 2.0 (the "License");
207
+ * you may not use this file except in compliance with the License.
208
+ * You may obtain a copy of the License at
209
+ *
210
+ * http://www.apache.org/licenses/LICENSE-2.0
211
+ *
212
+ * Unless required by applicable law or agreed to in writing, software
213
+ * distributed under the License is distributed on an "AS IS" BASIS,
214
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
215
+ * See the License for the specific language governing permissions and
216
+ * limitations under the License.
217
+ */
218
+ const IUniscriptExecutionService = createIdentifier("univer.uniscript.execution-service");
219
+ let UniscriptExecutionService = class UniscriptExecutionService extends Disposable {
220
+ constructor(_logService, _injector) {
221
+ super();
222
+ this._logService = _logService;
223
+ this._injector = _injector;
224
+ }
225
+ async execute(code) {
226
+ this._logService.log("[UniscriptExecutionService]", "executing Uniscript...");
227
+ const apiInstance = FUniver.newAPI(this._injector);
228
+ const scriptFunction = new Function("univerAPI", `(() => {${code}})()`);
229
+ try {
230
+ scriptFunction(apiInstance);
231
+ return true;
232
+ } catch (e) {
233
+ this._logService.error(e);
234
+ return false;
235
+ }
236
+ }
237
+ };
238
+ UniscriptExecutionService = __decorate([__decorateParam(0, ILogService), __decorateParam(1, Inject(Injector))], UniscriptExecutionService);
239
+
240
+ //#endregion
241
+ //#region src/views/components/ScriptEditorPanel.tsx
242
+ function ScriptEditorPanel() {
243
+ const editorContentRef = useRef(null);
244
+ const editorContainerRef = useRef(null);
245
+ const monacoEditorRef = useRef(null);
246
+ const localeService = useDependency(LocaleService);
247
+ const shortcutService = useDependency(IShortcutService);
248
+ const editorService = useDependency(ScriptEditorService);
249
+ const themeService = useDependency(ThemeService);
250
+ useEffect(() => {
251
+ const containerElement = editorContainerRef.current;
252
+ const contentElement = editorContentRef.current;
253
+ let disposableCollection = null;
254
+ let resizeObserver = null;
255
+ if (containerElement && contentElement) {
256
+ editorService.requireVscodeEditor();
257
+ const monacoEditor = monacoEditorRef.current = editor.create(containerElement, {
258
+ value: "",
259
+ language: "javascript",
260
+ theme: themeService.darkMode ? "vs-dark" : "vs-light"
261
+ });
262
+ resizeObserver = new ResizeObserver(() => {
263
+ let timer = requestIdleCallback(() => {
264
+ if (!timer) return;
265
+ const { height, width } = contentElement.getBoundingClientRect();
266
+ monacoEditor.layout({
267
+ width,
268
+ height
269
+ });
270
+ timer = void 0;
271
+ });
272
+ });
273
+ resizeObserver.observe(contentElement);
274
+ let terminateEscaping;
275
+ disposableCollection = new DisposableCollection();
276
+ disposableCollection.add(editorService.setEditorInstance(monacoEditor));
277
+ disposableCollection.add(monacoEditor.onDidFocusEditorWidget(() => {
278
+ terminateEscaping = shortcutService.forceEscape();
279
+ }));
280
+ disposableCollection.add(monacoEditor.onDidBlurEditorWidget(() => {
281
+ terminateEscaping === null || terminateEscaping === void 0 || terminateEscaping.dispose();
282
+ terminateEscaping = void 0;
283
+ }));
284
+ disposableCollection.add(toDisposable(() => terminateEscaping === null || terminateEscaping === void 0 ? void 0 : terminateEscaping.dispose()));
285
+ }
286
+ return () => {
287
+ if (resizeObserver && contentElement) resizeObserver.unobserve(contentElement);
288
+ disposableCollection === null || disposableCollection === void 0 || disposableCollection.dispose();
289
+ };
290
+ }, [editorService, shortcutService]);
291
+ const startExecution = useExecution(monacoEditorRef);
292
+ return /* @__PURE__ */ jsxs("div", {
293
+ className: "univer-h-full",
294
+ children: [/* @__PURE__ */ jsx("div", {
295
+ ref: editorContentRef,
296
+ className: "univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden",
297
+ children: /* @__PURE__ */ jsx("div", { ref: editorContainerRef })
298
+ }), /* @__PURE__ */ jsx("div", {
299
+ className: "univer-mt-2.5",
300
+ children: /* @__PURE__ */ jsx(Button, {
301
+ variant: "primary",
302
+ onClick: startExecution,
303
+ children: localeService.t("script-panel.panel.execute")
304
+ })
305
+ })]
306
+ });
307
+ }
308
+ function useExecution(monacoEditorRef) {
309
+ const scriptService = useDependency(IUniscriptExecutionService);
310
+ const messageService = useDependency(IMessageService);
311
+ const localeService = useDependency(LocaleService);
312
+ return useCallback(() => {
313
+ var _monacoEditorRef$curr;
314
+ const model = (_monacoEditorRef$curr = monacoEditorRef.current) === null || _monacoEditorRef$curr === void 0 ? void 0 : _monacoEditorRef$curr.getModel();
315
+ if (model) scriptService.execute(model.getValue()).then(() => {
316
+ messageService.show({
317
+ content: localeService.t("uniscript.message.success"),
318
+ type: MessageType.Success
319
+ });
320
+ }).catch(() => {
321
+ messageService.show({
322
+ content: localeService.t("uniscript.message.failed"),
323
+ type: MessageType.Error
324
+ });
325
+ });
326
+ }, [
327
+ localeService,
328
+ messageService,
329
+ monacoEditorRef,
330
+ scriptService
331
+ ]);
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/controllers/uniscript.controller.ts
336
+ /**
337
+ * Copyright 2023-present DreamNum Co., Ltd.
338
+ *
339
+ * Licensed under the Apache License, Version 2.0 (the "License");
340
+ * you may not use this file except in compliance with the License.
341
+ * You may obtain a copy of the License at
342
+ *
343
+ * http://www.apache.org/licenses/LICENSE-2.0
344
+ *
345
+ * Unless required by applicable law or agreed to in writing, software
346
+ * distributed under the License is distributed on an "AS IS" BASIS,
347
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
348
+ * See the License for the specific language governing permissions and
349
+ * limitations under the License.
350
+ */
351
+ let UniscriptController = class UniscriptController extends Disposable {
352
+ constructor(_menuManagerService, commandService, componentManager) {
353
+ super();
354
+ this._menuManagerService = _menuManagerService;
355
+ this._menuManagerService.mergeMenu(menuSchema);
356
+ this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
357
+ this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
358
+ }
359
+ };
360
+ UniscriptController = __decorate([
361
+ __decorateParam(0, IMenuManagerService),
362
+ __decorateParam(1, ICommandService),
363
+ __decorateParam(2, Inject(ComponentManager))
364
+ ], UniscriptController);
365
+
366
+ //#endregion
367
+ //#region src/plugin.ts
368
+ let UniverUniscriptPlugin = class UniverUniscriptPlugin extends Plugin {
369
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
370
+ super();
371
+ this._config = _config;
372
+ this._injector = _injector;
373
+ this._configService = _configService;
374
+ const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
375
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
376
+ this._configService.setConfig(UNISCRIPT_PLUGIN_CONFIG_KEY, rest);
377
+ }
378
+ onStarting() {
379
+ const injector = this._injector;
380
+ [
381
+ [UniscriptController],
382
+ [ScriptEditorService],
383
+ [ScriptPanelService]
384
+ ].forEach((d) => injector.add(d));
385
+ this.registerExecution();
386
+ }
387
+ onSteady() {
388
+ this._injector.get(UniscriptController);
389
+ }
390
+ /**
391
+ * Allows being overridden, replacing with a new UniscriptExecutionService.
392
+ */
393
+ registerExecution() {
394
+ this._injector.add([IUniscriptExecutionService, { useClass: UniscriptExecutionService }]);
395
+ }
396
+ };
397
+ _defineProperty(UniverUniscriptPlugin, "pluginName", "UNIVER_UNISCRIPT_PLUGIN");
398
+ _defineProperty(UniverUniscriptPlugin, "packageName", name);
399
+ _defineProperty(UniverUniscriptPlugin, "version", version);
400
+ UniverUniscriptPlugin = __decorate([__decorateParam(1, Inject(Injector)), __decorateParam(2, IConfigService)], UniverUniscriptPlugin);
401
+
402
+ //#endregion
403
+ export { IUniscriptExecutionService, ScriptEditorService, ToggleScriptPanelOperation, UniverUniscriptPlugin };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Mostra/Oculta el panell Uniscript`},panel:{execute:`Executa l'script`}},uniscript:{message:{success:`Execució correcta`,failed:`Execució fallida`}}};export{e as default};
1
+ //#region src/locale/ca-ES.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Mostra/Oculta el panell Uniscript" },
6
+ panel: { execute: "Executa l'script" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "Execució correcta",
10
+ failed: "Execució fallida"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,30 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Toggle Uniscript Panel`},panel:{execute:`Execute Script`}},uniscript:{message:{success:`Execution Success`,failed:`Execution Failed`}}};export{e as default};
1
+ //#region src/locale/en-US.ts
2
+ /**
3
+ * Copyright 2023-present DreamNum Co., Ltd.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ const locale = {
18
+ "script-panel": {
19
+ title: "Uniscript",
20
+ tooltip: { "menu-button": "Toggle Uniscript Panel" },
21
+ panel: { execute: "Execute Script" }
22
+ },
23
+ uniscript: { message: {
24
+ success: "Execution Success",
25
+ failed: "Execution Failed"
26
+ } }
27
+ };
28
+
29
+ //#endregion
30
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Mostrar/Ocultar panel de Uniscript`},panel:{execute:`Ejecutar script`}},uniscript:{message:{success:`Ejecución exitosa`,failed:`Ejecución fallida`}}};export{e as default};
1
+ //#region src/locale/es-ES.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Mostrar/Ocultar panel de Uniscript" },
6
+ panel: { execute: "Ejecutar script" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "Ejecución exitosa",
10
+ failed: "Ejecución fallida"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`نمایش/مخفی کردن پنل Uniscript`},panel:{execute:`اجرای اسکریپت`}},uniscript:{message:{success:`اجرای موفق`,failed:`اجرای ناموفق`}}};export{e as default};
1
+ //#region src/locale/fa-IR.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "نمایش/مخفی کردن پنل Uniscript" },
6
+ panel: { execute: "اجرای اسکریپت" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "اجرای موفق",
10
+ failed: "اجرای ناموفق"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Basculer le panneau Uniscript`},panel:{execute:`Exécuter le script`}},uniscript:{message:{success:`Exécution réussie`,failed:`Échec de l'exécution`}}};export{e as default};
1
+ //#region src/locale/fr-FR.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Basculer le panneau Uniscript" },
6
+ panel: { execute: "Exécuter le script" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "Exécution réussie",
10
+ failed: "Échec de l'exécution"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Uniscriptパネルを切り替え`},panel:{execute:`スクリプトを実行`}},uniscript:{message:{success:`実行に成功しました`,failed:`実行に失敗しました`}}};export{e as default};
1
+ //#region src/locale/ja-JP.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Uniscriptパネルを切り替え" },
6
+ panel: { execute: "スクリプトを実行" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "実行に成功しました",
10
+ failed: "実行に失敗しました"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Uniscript 패널 전환`},panel:{execute:`스크립트 실행`}},uniscript:{message:{success:`실행 성공`,failed:`실행 실패`}}};export{e as default};
1
+ //#region src/locale/ko-KR.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Uniscript 패널 전환" },
6
+ panel: { execute: "스크립트 실행" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "실행 성공",
10
+ failed: "실행 실패"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Юнискрипт`,tooltip:{"menu-button":`Переключить панель Юнискрипт`},panel:{execute:`Выполнить скрипт`}},uniscript:{message:{success:`Выполнение успешно`,failed:`Выполнение не удалось`}}};export{e as default};
1
+ //#region src/locale/ru-RU.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Юнискрипт",
5
+ tooltip: { "menu-button": "Переключить панель Юнискрипт" },
6
+ panel: { execute: "Выполнить скрипт" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "Выполнение успешно",
10
+ failed: "Выполнение не удалось"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Prepnúť panel Uniscript`},panel:{execute:`Spustiť skript`}},uniscript:{message:{success:`Spustenie úspešné`,failed:`Spustenie zlyhalo`}}};export{e as default};
1
+ //#region src/locale/sk-SK.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Prepnúť panel Uniscript" },
6
+ panel: { execute: "Spustiť skript" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "Spustenie úspešné",
10
+ failed: "Spustenie zlyhalo"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`Mở/Thu gọn bảng điều khiển Uniscript`},panel:{execute:`Thực thi Uniscript`}},uniscript:{message:{success:`Thực thi thành công`,failed:`Thực thi thất bại`}}};export{e as default};
1
+ //#region src/locale/vi-VN.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "Mở/Thu gọn bảng điều khiển Uniscript" },
6
+ panel: { execute: "Thực thi Uniscript" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "Thực thi thành công",
10
+ failed: "Thực thi thất bại"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`打开收起 Uniscript 面板`},panel:{execute:`执行 Uniscript`}},uniscript:{message:{success:`执行成功`,failed:`执行失败`}}};export{e as default};
1
+ //#region src/locale/zh-CN.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "打开收起 Uniscript 面板" },
6
+ panel: { execute: "执行 Uniscript" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "执行成功",
10
+ failed: "执行失败"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };
@@ -1 +1,15 @@
1
- const e={"script-panel":{title:`Uniscript`,tooltip:{"menu-button":`打開收起 Uniscript 面板`},panel:{execute:`執行 Uniscript`}},uniscript:{message:{success:`執行成功`,failed:`執行失敗`}}};export{e as default};
1
+ //#region src/locale/zh-TW.ts
2
+ const locale = {
3
+ "script-panel": {
4
+ title: "Uniscript",
5
+ tooltip: { "menu-button": "打開收起 Uniscript 面板" },
6
+ panel: { execute: "執行 Uniscript" }
7
+ },
8
+ uniscript: { message: {
9
+ success: "執行成功",
10
+ failed: "執行失敗"
11
+ } }
12
+ };
13
+
14
+ //#endregion
15
+ export { locale as default };