@univerjs/uniscript 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +172 -164
- package/lib/types/controllers/menu.d.ts +1 -1
- package/lib/types/controllers/uniscript.controller.d.ts +1 -2
- package/lib/types/plugin.d.ts +2 -3
- package/lib/types/services/script-editor.service.d.ts +1 -2
- package/lib/types/services/script-execution.service.d.ts +2 -3
- package/lib/umd/index.js +2 -2
- package/package.json +17 -19
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),ui=require("@univerjs/ui"),rxjs=require("rxjs"),require$$0=require("react"),design=require("@univerjs/design"),monacoEditor=require("monaco-editor"),facade=require("@univerjs/facade"),sheetsUi=require("@univerjs/sheets-ui"),sheets=require("@univerjs/sheets"),_ScriptPanelService=class _ScriptPanelService extends core.Disposable{constructor(){super(...arguments);__publicField(this,"_open$",new rxjs.BehaviorSubject(!1));__publicField(this,"open$",this._open$.pipe(rxjs.distinctUntilChanged()))}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)}};__name(_ScriptPanelService,"ScriptPanelService");let ScriptPanelService=_ScriptPanelService;const ScriptPanelComponentName="ScriptPanel",ToggleScriptPanelOperation={type:core.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:__name(accessor=>{const scriptPanelService=accessor.get(ScriptPanelService),sidebarService=accessor.get(ui.ISidebarService);return scriptPanelService.isOpen?(scriptPanelService.close(),sidebarService.close()):(scriptPanelService.open(),sidebarService.open({header:{title:"script-panel.title"},children:{label:ScriptPanelComponentName},width:600})),!0},"handler")};var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q");reactJsxRuntime_production_min.Fragment=l;reactJsxRuntime_production_min.jsx=q;reactJsxRuntime_production_min.jsxs=q;jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const _ScriptEditorService=class _ScriptEditorService extends core.Disposable{constructor(_config){super();__publicField(this,"_editorInstance",null);this._config=_config}setEditorInstance(editor){return this._editorInstance=editor,core.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}};__name(_ScriptEditorService,"ScriptEditorService");let ScriptEditorService=_ScriptEditorService;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");const IUniscriptExecutionService=core.createIdentifier("univer.uniscript.execution-service");var _a;let UniscriptExecutionService=(_a=class extends core.Disposable{constructor(_logService,_injector){super(),this._logService=_logService,this._injector=_injector}async execute(code){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const apiInstance=facade.FUniver.newAPI(this._injector),scriptFunction=new Function("univerAPI",`(() => {${code}})()`);try{return scriptFunction(apiInstance),!0}catch(e){return this._logService.error(e),!1}}},__name(_a,"UniscriptExecutionService"),_a);UniscriptExecutionService=__decorateClass$2([__decorateParam$2(0,core.ILogService),__decorateParam$2(1,core.Inject(core.Injector))],UniscriptExecutionService);const scriptEditorPanel="univer-script-editor-panel",scriptEditorContent="univer-script-editor-content",scriptEditorActions="univer-script-editor-actions",styles={scriptEditorPanel,scriptEditorContent,scriptEditorActions};function ScriptEditorPanel(){const editorContentRef=require$$0.useRef(null),editorContainerRef=require$$0.useRef(null),monacoEditorRef=require$$0.useRef(null),localeService=core.useDependency(core.LocaleService),shortcutService=core.useDependency(ui.IShortcutService),editorService=core.useDependency(ScriptEditorService);require$$0.useEffect(()=>{const containerElement=editorContainerRef.current,contentElement=editorContentRef.current;let disposableCollection=null,resizeObserver=null;if(containerElement&&contentElement){editorService.requireVscodeEditor();const monacoEditor$1=monacoEditorRef.current=monacoEditor.editor.create(containerElement,{value:"",language:"javascript"});resizeObserver=new ResizeObserver(()=>{let timer=requestIdleCallback(()=>{if(!timer)return;const{height,width}=contentElement.getBoundingClientRect();monacoEditor$1.layout({width,height}),timer=void 0})}),resizeObserver.observe(contentElement);let terminateEscaping;disposableCollection=new core.DisposableCollection,disposableCollection.add(editorService.setEditorInstance(monacoEditor$1)),disposableCollection.add(monacoEditor$1.onDidFocusEditorWidget(()=>{terminateEscaping=shortcutService.forceEscape()})),disposableCollection.add(monacoEditor$1.onDidBlurEditorWidget(()=>{terminateEscaping==null||terminateEscaping.dispose(),terminateEscaping=void 0})),disposableCollection.add(core.toDisposable(()=>terminateEscaping==null?void 0:terminateEscaping.dispose()))}return()=>{resizeObserver&&contentElement&&resizeObserver.unobserve(contentElement),disposableCollection==null||disposableCollection.dispose()}},[editorService,shortcutService]);const startExecution=useExecution(monacoEditorRef);return jsxRuntimeExports.jsxs("div",{className:styles.scriptEditorPanel,children:[jsxRuntimeExports.jsx("div",{className:styles.scriptEditorContent,ref:editorContentRef,children:jsxRuntimeExports.jsx("div",{className:styles.scriptEditorContainer,ref:editorContainerRef})}),jsxRuntimeExports.jsx("div",{className:styles.scriptEditorActions,children:jsxRuntimeExports.jsx(design.Button,{type:"primary",size:"small",onClick:startExecution,children:localeService.t("script-panel.panel.execute")})})]})}__name(ScriptEditorPanel,"ScriptEditorPanel");function useExecution(monacoEditorRef){const scriptService=core.useDependency(IUniscriptExecutionService),messageService=core.useDependency(ui.IMessageService),localeService=core.useDependency(core.LocaleService);return require$$0.useCallback(()=>{var _a4;const model=(_a4=monacoEditorRef.current)==null?void 0:_a4.getModel();model&&scriptService.execute(model.getValue()).then(()=>{messageService.show({content:localeService.t("uniscript.message.success"),type:design.MessageType.Success})}).catch(()=>{messageService.show({content:localeService.t("uniscript.message.failed"),type:design.MessageType.Error})})},[localeService,messageService,monacoEditorRef,scriptService])}__name(useExecution,"useExecution");function UniscriptMenuItemFactory(accessor){return{id:ToggleScriptPanelOperation.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission,sheets.WorksheetSetCellValuePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}}__name(UniscriptMenuItemFactory,"UniscriptMenuItemFactory");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const DefaultUniscriptConfig={};var _a2;let UniscriptController=(_a2=class extends core.Disposable{constructor(_config,_injector,_menuService,commandService,componentManager){super(),this._config=_config,this._injector=_injector,this._menuService=_menuService;const{menu={}}=this._config;this.disposeWithMe(_menuService.addMenuItem(this._injector.invoke(UniscriptMenuItemFactory),menu)),this.disposeWithMe(componentManager.register(ScriptPanelComponentName,ScriptEditorPanel)),this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation))}},__name(_a2,"UniscriptController"),_a2);UniscriptController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Steady,UniscriptController),__decorateParam$1(1,core.Inject(core.Injector)),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,core.ICommandService),__decorateParam$1(4,core.Inject(ui.ComponentManager))],UniscriptController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="uniscript";var _a3;exports.UniverUniscriptPlugin=(_a3=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultUniscriptConfig,this._config)}onStarting(){const injector=this._injector;[[UniscriptController,{useFactory:__name(()=>injector.createInstance(UniscriptController,this._config),"useFactory")}],[ScriptEditorService,{useFactory:__name(()=>injector.createInstance(ScriptEditorService,this._config),"useFactory")}],[ScriptPanelService]].forEach(d=>injector.add(d)),this.registerExecution()}registerExecution(){this._injector.add([IUniscriptExecutionService,{useClass:UniscriptExecutionService}])}},__name(_a3,"UniverUniscriptPlugin"),__publicField(_a3,"pluginName",PLUGIN_NAME),_a3);exports.UniverUniscriptPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService))],exports.UniverUniscriptPlugin);exports.IUniscriptExecutionService=IUniscriptExecutionService;exports.ScriptEditorService=ScriptEditorService;exports.ToggleScriptPanelOperation=ToggleScriptPanelOperation;
|
package/lib/es/index.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import { ISidebarService
|
|
7
|
-
import { BehaviorSubject
|
|
8
|
-
import
|
|
9
|
-
import { Button
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
class M extends S {
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { Disposable, CommandType, toDisposable, createIdentifier, Inject, Injector, ILogService, useDependency, LocaleService, DisposableCollection, UniverInstanceType, OnLifecycle, LifecycleStages, ICommandService, Plugin, Tools } from "@univerjs/core";
|
|
6
|
+
import { ISidebarService, IShortcutService, IMessageService, MenuItemType, MenuPosition, getMenuHiddenObservable, ComponentManager, IMenuService } from "@univerjs/ui";
|
|
7
|
+
import { BehaviorSubject, distinctUntilChanged } from "rxjs";
|
|
8
|
+
import require$$0, { useRef, useEffect, useCallback } from "react";
|
|
9
|
+
import { Button, MessageType } from "@univerjs/design";
|
|
10
|
+
import { editor } from "monaco-editor";
|
|
11
|
+
import { FUniver } from "@univerjs/facade";
|
|
12
|
+
import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
|
|
13
|
+
import { WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, RangeProtectionPermissionEditPoint } from "@univerjs/sheets";
|
|
14
|
+
const _ScriptPanelService = class _ScriptPanelService extends Disposable {
|
|
16
15
|
constructor() {
|
|
17
16
|
super(...arguments);
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
__publicField(this, "_open$", new BehaviorSubject(!1));
|
|
18
|
+
__publicField(this, "open$", this._open$.pipe(distinctUntilChanged()));
|
|
20
19
|
}
|
|
21
20
|
get isOpen() {
|
|
22
21
|
return this._open$.getValue();
|
|
@@ -30,20 +29,22 @@ class M extends S {
|
|
|
30
29
|
close() {
|
|
31
30
|
this._open$.next(!1);
|
|
32
31
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
};
|
|
33
|
+
__name(_ScriptPanelService, "ScriptPanelService");
|
|
34
|
+
let ScriptPanelService = _ScriptPanelService;
|
|
35
|
+
const ScriptPanelComponentName = "ScriptPanel", ToggleScriptPanelOperation = {
|
|
36
|
+
type: CommandType.OPERATION,
|
|
36
37
|
id: "univer.operation.toggle-script-panel",
|
|
37
|
-
handler: (
|
|
38
|
-
const
|
|
39
|
-
return
|
|
38
|
+
handler: /* @__PURE__ */ __name((accessor) => {
|
|
39
|
+
const scriptPanelService = accessor.get(ScriptPanelService), sidebarService = accessor.get(ISidebarService);
|
|
40
|
+
return scriptPanelService.isOpen ? (scriptPanelService.close(), sidebarService.close()) : (scriptPanelService.open(), sidebarService.open({
|
|
40
41
|
header: { title: "script-panel.title" },
|
|
41
|
-
children: { label:
|
|
42
|
+
children: { label: ScriptPanelComponentName },
|
|
42
43
|
width: 600
|
|
43
44
|
})), !0;
|
|
44
|
-
}
|
|
45
|
+
}, "handler")
|
|
45
46
|
};
|
|
46
|
-
var
|
|
47
|
+
var jsxRuntime = { exports: {} }, reactJsxRuntime_production_min = {};
|
|
47
48
|
/**
|
|
48
49
|
* @license React
|
|
49
50
|
* react-jsx-runtime.production.min.js
|
|
@@ -53,27 +54,28 @@ var W = { exports: {} }, E = {};
|
|
|
53
54
|
* This source code is licensed under the MIT license found in the
|
|
54
55
|
* LICENSE file in the root directory of this source tree.
|
|
55
56
|
*/
|
|
56
|
-
var
|
|
57
|
-
function
|
|
58
|
-
var
|
|
59
|
-
|
|
60
|
-
for (
|
|
61
|
-
if (
|
|
62
|
-
return { $$typeof:
|
|
57
|
+
var f = require$$0, k = Symbol.for("react.element"), l = Symbol.for("react.fragment"), m = Object.prototype.hasOwnProperty, n = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, p = { key: !0, ref: !0, __self: !0, __source: !0 };
|
|
58
|
+
function q(c, a, g) {
|
|
59
|
+
var b, d = {}, e = null, h = null;
|
|
60
|
+
g !== void 0 && (e = "" + g), a.key !== void 0 && (e = "" + a.key), a.ref !== void 0 && (h = a.ref);
|
|
61
|
+
for (b in a) m.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
|
|
62
|
+
if (c && c.defaultProps) for (b in a = c.defaultProps, a) d[b] === void 0 && (d[b] = a[b]);
|
|
63
|
+
return { $$typeof: k, type: c, key: e, ref: h, props: d, _owner: n.current };
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
__name(q, "q");
|
|
66
|
+
reactJsxRuntime_production_min.Fragment = l;
|
|
67
|
+
reactJsxRuntime_production_min.jsx = q;
|
|
68
|
+
reactJsxRuntime_production_min.jsxs = q;
|
|
69
|
+
jsxRuntime.exports = reactJsxRuntime_production_min;
|
|
70
|
+
var jsxRuntimeExports = jsxRuntime.exports;
|
|
71
|
+
const _ScriptEditorService = class _ScriptEditorService extends Disposable {
|
|
72
|
+
constructor(_config) {
|
|
71
73
|
super();
|
|
72
|
-
|
|
73
|
-
this._config =
|
|
74
|
+
__publicField(this, "_editorInstance", null);
|
|
75
|
+
this._config = _config;
|
|
74
76
|
}
|
|
75
|
-
setEditorInstance(
|
|
76
|
-
return this._editorInstance =
|
|
77
|
+
setEditorInstance(editor2) {
|
|
78
|
+
return this._editorInstance = editor2, toDisposable(() => this._editorInstance = null);
|
|
77
79
|
}
|
|
78
80
|
getEditorInstance() {
|
|
79
81
|
return this._editorInstance;
|
|
@@ -83,160 +85,166 @@ class x extends S {
|
|
|
83
85
|
getWorkerUrl: this._config.getWorkerUrl
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
88
|
+
};
|
|
89
|
+
__name(_ScriptEditorService, "ScriptEditorService");
|
|
90
|
+
let ScriptEditorService = _ScriptEditorService;
|
|
91
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
92
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
93
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
94
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
95
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
|
|
96
|
+
const IUniscriptExecutionService = createIdentifier("univer.uniscript.execution-service");
|
|
97
|
+
var _a;
|
|
98
|
+
let UniscriptExecutionService = (_a = class extends Disposable {
|
|
99
|
+
constructor(_logService, _injector) {
|
|
100
|
+
super(), this._logService = _logService, this._injector = _injector;
|
|
101
|
+
}
|
|
102
|
+
async execute(code) {
|
|
98
103
|
this._logService.log("[UniscriptExecutionService]", "executing Uniscript...");
|
|
99
|
-
const
|
|
104
|
+
const apiInstance = FUniver.newAPI(this._injector), scriptFunction = new Function("univerAPI", `(() => {${code}})()`);
|
|
100
105
|
try {
|
|
101
|
-
return
|
|
102
|
-
} catch (
|
|
103
|
-
return this._logService.error(
|
|
106
|
+
return scriptFunction(apiInstance), !0;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return this._logService.error(e), !1;
|
|
104
109
|
}
|
|
105
110
|
}
|
|
111
|
+
}, __name(_a, "UniscriptExecutionService"), _a);
|
|
112
|
+
UniscriptExecutionService = __decorateClass$2([
|
|
113
|
+
__decorateParam$2(0, ILogService),
|
|
114
|
+
__decorateParam$2(1, Inject(Injector))
|
|
115
|
+
], UniscriptExecutionService);
|
|
116
|
+
const scriptEditorPanel = "univer-script-editor-panel", scriptEditorContent = "univer-script-editor-content", scriptEditorActions = "univer-script-editor-actions", styles = {
|
|
117
|
+
scriptEditorPanel,
|
|
118
|
+
scriptEditorContent,
|
|
119
|
+
scriptEditorActions
|
|
106
120
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
};
|
|
116
|
-
function Me() {
|
|
117
|
-
const t = P(null), e = P(null), r = P(null), i = p(I), n = p(te), o = p(x);
|
|
118
|
-
ue(() => {
|
|
119
|
-
const C = e.current, a = t.current;
|
|
120
|
-
let c = null, _ = null;
|
|
121
|
-
if (C && a) {
|
|
122
|
-
o.requireVscodeEditor();
|
|
123
|
-
const m = r.current = fe.create(C, {
|
|
121
|
+
function ScriptEditorPanel() {
|
|
122
|
+
const editorContentRef = useRef(null), editorContainerRef = useRef(null), monacoEditorRef = useRef(null), localeService = useDependency(LocaleService), shortcutService = useDependency(IShortcutService), editorService = useDependency(ScriptEditorService);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
const containerElement = editorContainerRef.current, contentElement = editorContentRef.current;
|
|
125
|
+
let disposableCollection = null, resizeObserver = null;
|
|
126
|
+
if (containerElement && contentElement) {
|
|
127
|
+
editorService.requireVscodeEditor();
|
|
128
|
+
const monacoEditor = monacoEditorRef.current = editor.create(containerElement, {
|
|
124
129
|
value: "",
|
|
125
130
|
language: "javascript"
|
|
126
131
|
});
|
|
127
|
-
|
|
128
|
-
let
|
|
129
|
-
if (!
|
|
130
|
-
const { height
|
|
131
|
-
|
|
132
|
+
resizeObserver = new ResizeObserver(() => {
|
|
133
|
+
let timer = requestIdleCallback(() => {
|
|
134
|
+
if (!timer) return;
|
|
135
|
+
const { height, width } = contentElement.getBoundingClientRect();
|
|
136
|
+
monacoEditor.layout({ width, height }), timer = void 0;
|
|
132
137
|
});
|
|
133
|
-
}),
|
|
134
|
-
let
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
+
}), resizeObserver.observe(contentElement);
|
|
139
|
+
let terminateEscaping;
|
|
140
|
+
disposableCollection = new DisposableCollection(), disposableCollection.add(editorService.setEditorInstance(monacoEditor)), disposableCollection.add(
|
|
141
|
+
monacoEditor.onDidFocusEditorWidget(() => {
|
|
142
|
+
terminateEscaping = shortcutService.forceEscape();
|
|
138
143
|
})
|
|
139
|
-
),
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
), disposableCollection.add(
|
|
145
|
+
monacoEditor.onDidBlurEditorWidget(() => {
|
|
146
|
+
terminateEscaping == null || terminateEscaping.dispose(), terminateEscaping = void 0;
|
|
142
147
|
})
|
|
143
|
-
),
|
|
148
|
+
), disposableCollection.add(toDisposable(() => terminateEscaping == null ? void 0 : terminateEscaping.dispose()));
|
|
144
149
|
}
|
|
145
150
|
return () => {
|
|
146
|
-
|
|
151
|
+
resizeObserver && contentElement && resizeObserver.unobserve(contentElement), disposableCollection == null || disposableCollection.dispose();
|
|
147
152
|
};
|
|
148
|
-
}, [
|
|
149
|
-
const
|
|
150
|
-
return /* @__PURE__ */
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
+
}, [editorService, shortcutService]);
|
|
154
|
+
const startExecution = useExecution(monacoEditorRef);
|
|
155
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.scriptEditorPanel, children: [
|
|
156
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.scriptEditorContent, ref: editorContentRef, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.scriptEditorContainer, ref: editorContainerRef }) }),
|
|
157
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.scriptEditorActions, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "primary", size: "small", onClick: startExecution, children: localeService.t("script-panel.panel.execute") }) })
|
|
153
158
|
] });
|
|
154
159
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
__name(ScriptEditorPanel, "ScriptEditorPanel");
|
|
161
|
+
function useExecution(monacoEditorRef) {
|
|
162
|
+
const scriptService = useDependency(IUniscriptExecutionService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService);
|
|
163
|
+
return useCallback(() => {
|
|
164
|
+
var _a4;
|
|
165
|
+
const model = (_a4 = monacoEditorRef.current) == null ? void 0 : _a4.getModel();
|
|
166
|
+
model && scriptService.execute(model.getValue()).then(() => {
|
|
167
|
+
messageService.show({
|
|
168
|
+
content: localeService.t("uniscript.message.success"),
|
|
169
|
+
type: MessageType.Success
|
|
164
170
|
});
|
|
165
171
|
}).catch(() => {
|
|
166
|
-
|
|
167
|
-
content:
|
|
168
|
-
type:
|
|
172
|
+
messageService.show({
|
|
173
|
+
content: localeService.t("uniscript.message.failed"),
|
|
174
|
+
type: MessageType.Error
|
|
169
175
|
});
|
|
170
176
|
});
|
|
171
|
-
}, [
|
|
177
|
+
}, [localeService, messageService, monacoEditorRef, scriptService]);
|
|
172
178
|
}
|
|
173
|
-
|
|
179
|
+
__name(useExecution, "useExecution");
|
|
180
|
+
function UniscriptMenuItemFactory(accessor) {
|
|
174
181
|
return {
|
|
175
|
-
id:
|
|
182
|
+
id: ToggleScriptPanelOperation.id,
|
|
176
183
|
title: "toggle-script-panel",
|
|
177
184
|
tooltip: "script-panel.tooltip.menu-button",
|
|
178
185
|
icon: "CodeSingle",
|
|
179
|
-
type:
|
|
180
|
-
positions: [
|
|
186
|
+
type: MenuItemType.BUTTON,
|
|
187
|
+
positions: [MenuPosition.TOOLBAR_START],
|
|
181
188
|
// FIXME hidden$ and disabled$ are not correctly in doc
|
|
182
|
-
hidden$:
|
|
183
|
-
disabled$:
|
|
189
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
190
|
+
disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
|
|
184
191
|
};
|
|
185
192
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
193
|
+
__name(UniscriptMenuItemFactory, "UniscriptMenuItemFactory");
|
|
194
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
195
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
196
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
197
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
198
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
|
|
199
|
+
const DefaultUniscriptConfig = {};
|
|
200
|
+
var _a2;
|
|
201
|
+
let UniscriptController = (_a2 = class extends Disposable {
|
|
202
|
+
constructor(_config, _injector, _menuService, commandService, componentManager) {
|
|
203
|
+
super(), this._config = _config, this._injector = _injector, this._menuService = _menuService;
|
|
204
|
+
const { menu = {} } = this._config;
|
|
205
|
+
this.disposeWithMe(_menuService.addMenuItem(this._injector.invoke(UniscriptMenuItemFactory), menu)), this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel)), this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
|
|
206
|
+
}
|
|
207
|
+
}, __name(_a2, "UniscriptController"), _a2);
|
|
208
|
+
UniscriptController = __decorateClass$1([
|
|
209
|
+
OnLifecycle(LifecycleStages.Steady, UniscriptController),
|
|
210
|
+
__decorateParam$1(1, Inject(Injector)),
|
|
211
|
+
__decorateParam$1(2, IMenuService),
|
|
212
|
+
__decorateParam$1(3, ICommandService),
|
|
213
|
+
__decorateParam$1(4, Inject(ComponentManager))
|
|
214
|
+
], UniscriptController);
|
|
215
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
216
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
217
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
218
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
219
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
|
|
220
|
+
const PLUGIN_NAME = "uniscript";
|
|
221
|
+
var _a3;
|
|
222
|
+
let UniverUniscriptPlugin = (_a3 = class extends Plugin {
|
|
223
|
+
constructor(_config = {}, _injector, _localeService) {
|
|
224
|
+
super(), this._config = _config, this._injector = _injector, this._localeService = _localeService, this._config = Tools.deepMerge({}, DefaultUniscriptConfig, this._config);
|
|
225
|
+
}
|
|
226
|
+
onStarting() {
|
|
227
|
+
const injector = this._injector;
|
|
218
228
|
[
|
|
219
|
-
|
|
220
|
-
[
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
[M]
|
|
224
|
-
].forEach((r) => t.add(r)), this.registerExecution();
|
|
229
|
+
[UniscriptController, { useFactory: /* @__PURE__ */ __name(() => injector.createInstance(UniscriptController, this._config), "useFactory") }],
|
|
230
|
+
[ScriptEditorService, { useFactory: /* @__PURE__ */ __name(() => injector.createInstance(ScriptEditorService, this._config), "useFactory") }],
|
|
231
|
+
[ScriptPanelService]
|
|
232
|
+
].forEach((d) => injector.add(d)), this.registerExecution();
|
|
225
233
|
}
|
|
226
234
|
/**
|
|
227
235
|
* Allows being overridden, replacing with a new UniscriptExecutionService.
|
|
228
236
|
*/
|
|
229
237
|
registerExecution() {
|
|
230
|
-
this._injector.add([
|
|
238
|
+
this._injector.add([IUniscriptExecutionService, { useClass: UniscriptExecutionService }]);
|
|
231
239
|
}
|
|
232
|
-
},
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
],
|
|
240
|
+
}, __name(_a3, "UniverUniscriptPlugin"), __publicField(_a3, "pluginName", PLUGIN_NAME), _a3);
|
|
241
|
+
UniverUniscriptPlugin = __decorateClass([
|
|
242
|
+
__decorateParam(1, Inject(Injector)),
|
|
243
|
+
__decorateParam(2, Inject(LocaleService))
|
|
244
|
+
], UniverUniscriptPlugin);
|
|
237
245
|
export {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
246
|
+
IUniscriptExecutionService,
|
|
247
|
+
ScriptEditorService,
|
|
248
|
+
ToggleScriptPanelOperation,
|
|
249
|
+
UniverUniscriptPlugin
|
|
242
250
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Disposable, ICommandService } from '@univerjs/core';
|
|
1
|
+
import { Disposable, ICommandService, Injector } from '@univerjs/core';
|
|
2
2
|
import { MenuConfig, ComponentManager, IMenuService } from '@univerjs/ui';
|
|
3
|
-
import { Injector } from '@wendellhu/redi';
|
|
4
3
|
|
|
5
4
|
export interface IUniverUniscriptConfig {
|
|
6
5
|
getWorkerUrl(moduleID: string, label: string): string;
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { LocaleService, Plugin } from '@univerjs/core';
|
|
2
|
-
import { Injector } from '@wendellhu/redi';
|
|
1
|
+
import { Injector, LocaleService, Plugin } from '@univerjs/core';
|
|
3
2
|
import { IUniverUniscriptConfig } from './controllers/uniscript.controller';
|
|
4
3
|
|
|
5
4
|
export declare class UniverUniscriptPlugin extends Plugin {
|
|
@@ -8,7 +7,7 @@ export declare class UniverUniscriptPlugin extends Plugin {
|
|
|
8
7
|
private readonly _localeService;
|
|
9
8
|
static pluginName: string;
|
|
10
9
|
constructor(_config: Partial<IUniverUniscriptConfig>, _injector: Injector, _localeService: LocaleService);
|
|
11
|
-
onStarting(
|
|
10
|
+
onStarting(): void;
|
|
12
11
|
/**
|
|
13
12
|
* Allows being overridden, replacing with a new UniscriptExecutionService.
|
|
14
13
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Disposable } from '@univerjs/core';
|
|
2
|
-
import { IDisposable } from '@wendellhu/redi';
|
|
1
|
+
import { Disposable, IDisposable } from '@univerjs/core';
|
|
3
2
|
import { editor } from 'monaco-editor';
|
|
4
3
|
import { IUniverUniscriptConfig } from '../controllers/uniscript.controller';
|
|
5
4
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Disposable, ILogService } from '@univerjs/core';
|
|
2
|
-
import { Injector } from '@wendellhu/redi';
|
|
1
|
+
import { Disposable, ILogService, Injector } from '@univerjs/core';
|
|
3
2
|
|
|
4
|
-
export declare const IUniscriptExecutionService: import('@
|
|
3
|
+
export declare const IUniscriptExecutionService: import('@univerjs/core').IdentifierDecorator<IUniscriptExecutionService>;
|
|
5
4
|
export interface IUniscriptExecutionService {
|
|
6
5
|
execute(code: string): Promise<boolean>;
|
|
7
6
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("monaco-editor"),require("@univerjs/facade"),require("@univerjs/sheets-ui"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","react","@univerjs/design","monaco-editor","@univerjs/facade","@univerjs/sheets-ui","@univerjs/sheets"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverUniscript={},global.UniverCore,global.UniverUi,global.rxjs,global.React,global.UniverDesign,global.monaco,global.UniverFacade,global.UniverSheetsUi,global.UniverSheets))})(this,function(exports2,core,ui,rxjs,require$$0,design,monacoEditor,facade,sheetsUi,sheets){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c;const _ScriptPanelService=class _ScriptPanelService extends core.Disposable{constructor(){super(...arguments);__publicField(this,"_open$",new rxjs.BehaviorSubject(!1));__publicField(this,"open$",this._open$.pipe(rxjs.distinctUntilChanged()))}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)}};__name(_ScriptPanelService,"ScriptPanelService");let ScriptPanelService=_ScriptPanelService;const ScriptPanelComponentName="ScriptPanel",ToggleScriptPanelOperation={type:core.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:__name(accessor=>{const scriptPanelService=accessor.get(ScriptPanelService),sidebarService=accessor.get(ui.ISidebarService);return scriptPanelService.isOpen?(scriptPanelService.close(),sidebarService.close()):(scriptPanelService.open(),sidebarService.open({header:{title:"script-panel.title"},children:{label:ScriptPanelComponentName},width:600})),!0},"handler")};var jsxRuntime={exports:{}},reactJsxRuntime_production_min={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
9
|
+
*/var f=require$$0,k=Symbol.for("react.element"),l=Symbol.for("react.fragment"),m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function q(c,a,g){var b,d={},e=null,h=null;g!==void 0&&(e=""+g),a.key!==void 0&&(e=""+a.key),a.ref!==void 0&&(h=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)d[b]===void 0&&(d[b]=a[b]);return{$$typeof:k,type:c,key:e,ref:h,props:d,_owner:n.current}}__name(q,"q"),reactJsxRuntime_production_min.Fragment=l,reactJsxRuntime_production_min.jsx=q,reactJsxRuntime_production_min.jsxs=q,jsxRuntime.exports=reactJsxRuntime_production_min;var jsxRuntimeExports=jsxRuntime.exports;const _ScriptEditorService=class _ScriptEditorService extends core.Disposable{constructor(_config){super();__publicField(this,"_editorInstance",null);this._config=_config}setEditorInstance(editor){return this._editorInstance=editor,core.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}};__name(_ScriptEditorService,"ScriptEditorService");let ScriptEditorService=_ScriptEditorService;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");const IUniscriptExecutionService=core.createIdentifier("univer.uniscript.execution-service");let UniscriptExecutionService=(_a=class extends core.Disposable{constructor(_logService,_injector){super(),this._logService=_logService,this._injector=_injector}async execute(code){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const apiInstance=facade.FUniver.newAPI(this._injector),scriptFunction=new Function("univerAPI",`(() => {${code}})()`);try{return scriptFunction(apiInstance),!0}catch(e){return this._logService.error(e),!1}}},__name(_a,"UniscriptExecutionService"),_a);UniscriptExecutionService=__decorateClass$2([__decorateParam$2(0,core.ILogService),__decorateParam$2(1,core.Inject(core.Injector))],UniscriptExecutionService);const styles={scriptEditorPanel:"univer-script-editor-panel",scriptEditorContent:"univer-script-editor-content",scriptEditorActions:"univer-script-editor-actions"};function ScriptEditorPanel(){const editorContentRef=require$$0.useRef(null),editorContainerRef=require$$0.useRef(null),monacoEditorRef=require$$0.useRef(null),localeService=core.useDependency(core.LocaleService),shortcutService=core.useDependency(ui.IShortcutService),editorService=core.useDependency(ScriptEditorService);require$$0.useEffect(()=>{const containerElement=editorContainerRef.current,contentElement=editorContentRef.current;let disposableCollection=null,resizeObserver=null;if(containerElement&&contentElement){editorService.requireVscodeEditor();const monacoEditor$1=monacoEditorRef.current=monacoEditor.editor.create(containerElement,{value:"",language:"javascript"});resizeObserver=new ResizeObserver(()=>{let timer=requestIdleCallback(()=>{if(!timer)return;const{height,width}=contentElement.getBoundingClientRect();monacoEditor$1.layout({width,height}),timer=void 0})}),resizeObserver.observe(contentElement);let terminateEscaping;disposableCollection=new core.DisposableCollection,disposableCollection.add(editorService.setEditorInstance(monacoEditor$1)),disposableCollection.add(monacoEditor$1.onDidFocusEditorWidget(()=>{terminateEscaping=shortcutService.forceEscape()})),disposableCollection.add(monacoEditor$1.onDidBlurEditorWidget(()=>{terminateEscaping==null||terminateEscaping.dispose(),terminateEscaping=void 0})),disposableCollection.add(core.toDisposable(()=>terminateEscaping==null?void 0:terminateEscaping.dispose()))}return()=>{resizeObserver&&contentElement&&resizeObserver.unobserve(contentElement),disposableCollection==null||disposableCollection.dispose()}},[editorService,shortcutService]);const startExecution=useExecution(monacoEditorRef);return jsxRuntimeExports.jsxs("div",{className:styles.scriptEditorPanel,children:[jsxRuntimeExports.jsx("div",{className:styles.scriptEditorContent,ref:editorContentRef,children:jsxRuntimeExports.jsx("div",{className:styles.scriptEditorContainer,ref:editorContainerRef})}),jsxRuntimeExports.jsx("div",{className:styles.scriptEditorActions,children:jsxRuntimeExports.jsx(design.Button,{type:"primary",size:"small",onClick:startExecution,children:localeService.t("script-panel.panel.execute")})})]})}__name(ScriptEditorPanel,"ScriptEditorPanel");function useExecution(monacoEditorRef){const scriptService=core.useDependency(IUniscriptExecutionService),messageService=core.useDependency(ui.IMessageService),localeService=core.useDependency(core.LocaleService);return require$$0.useCallback(()=>{var _a2;const model=(_a2=monacoEditorRef.current)==null?void 0:_a2.getModel();model&&scriptService.execute(model.getValue()).then(()=>{messageService.show({content:localeService.t("uniscript.message.success"),type:design.MessageType.Success})}).catch(()=>{messageService.show({content:localeService.t("uniscript.message.failed"),type:design.MessageType.Error})})},[localeService,messageService,monacoEditorRef,scriptService])}__name(useExecution,"useExecution");function UniscriptMenuItemFactory(accessor){return{id:ToggleScriptPanelOperation.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:ui.MenuItemType.BUTTON,positions:[ui.MenuPosition.TOOLBAR_START],hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_SHEET),disabled$:sheetsUi.getCurrentRangeDisable$(accessor,{workbookTypes:[sheets.WorkbookEditablePermission],worksheetTypes:[sheets.WorksheetEditPermission,sheets.WorksheetSetCellStylePermission,sheets.WorksheetSetCellValuePermission],rangeTypes:[sheets.RangeProtectionPermissionEditPoint]})}}__name(UniscriptMenuItemFactory,"UniscriptMenuItemFactory");var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");const DefaultUniscriptConfig={};let UniscriptController=(_b=class extends core.Disposable{constructor(_config,_injector,_menuService,commandService,componentManager){super(),this._config=_config,this._injector=_injector,this._menuService=_menuService;const{menu={}}=this._config;this.disposeWithMe(_menuService.addMenuItem(this._injector.invoke(UniscriptMenuItemFactory),menu)),this.disposeWithMe(componentManager.register(ScriptPanelComponentName,ScriptEditorPanel)),this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation))}},__name(_b,"UniscriptController"),_b);UniscriptController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Steady,UniscriptController),__decorateParam$1(1,core.Inject(core.Injector)),__decorateParam$1(2,ui.IMenuService),__decorateParam$1(3,core.ICommandService),__decorateParam$1(4,core.Inject(ui.ComponentManager))],UniscriptController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");const PLUGIN_NAME="uniscript";exports2.UniverUniscriptPlugin=(_c=class extends core.Plugin{constructor(_config={},_injector,_localeService){super(),this._config=_config,this._injector=_injector,this._localeService=_localeService,this._config=core.Tools.deepMerge({},DefaultUniscriptConfig,this._config)}onStarting(){const injector=this._injector;[[UniscriptController,{useFactory:__name(()=>injector.createInstance(UniscriptController,this._config),"useFactory")}],[ScriptEditorService,{useFactory:__name(()=>injector.createInstance(ScriptEditorService,this._config),"useFactory")}],[ScriptPanelService]].forEach(d=>injector.add(d)),this.registerExecution()}registerExecution(){this._injector.add([IUniscriptExecutionService,{useClass:UniscriptExecutionService}])}},__name(_c,"UniverUniscriptPlugin"),__publicField(_c,"pluginName",PLUGIN_NAME),_c),exports2.UniverUniscriptPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.Inject(core.LocaleService))],exports2.UniverUniscriptPlugin),exports2.IUniscriptExecutionService=IUniscriptExecutionService,exports2.ScriptEditorService=ScriptEditorService,exports2.ToggleScriptPanelOperation=ToggleScriptPanelOperation,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/uniscript",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UI component library for building exceptional Univer.",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -50,36 +50,34 @@
|
|
|
50
50
|
"lib"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@wendellhu/redi": "0.16.0",
|
|
54
53
|
"monaco-editor": ">=0.44.0",
|
|
55
54
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
56
55
|
"rxjs": ">=7.0.0",
|
|
57
|
-
"@univerjs/core": "0.2.
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/facade": "0.2.
|
|
61
|
-
"@univerjs/sheets-ui": "0.2.
|
|
62
|
-
"@univerjs/ui": "0.2.
|
|
56
|
+
"@univerjs/core": "0.2.6",
|
|
57
|
+
"@univerjs/design": "0.2.6",
|
|
58
|
+
"@univerjs/sheets": "0.2.6",
|
|
59
|
+
"@univerjs/facade": "0.2.6",
|
|
60
|
+
"@univerjs/sheets-ui": "0.2.6",
|
|
61
|
+
"@univerjs/ui": "0.2.6"
|
|
63
62
|
},
|
|
64
63
|
"dependencies": {
|
|
65
64
|
"@univerjs/protocol": "0.1.38-alpha.23"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
68
67
|
"@types/react": "^18.3.3",
|
|
69
|
-
"@wendellhu/redi": "0.16.0",
|
|
70
68
|
"less": "^4.2.0",
|
|
71
69
|
"monaco-editor": "0.50.0",
|
|
72
70
|
"rxjs": "^7.8.1",
|
|
73
|
-
"typescript": "^5.5.
|
|
74
|
-
"vite": "^5.3.
|
|
75
|
-
"vitest": "^2.0.
|
|
76
|
-
"@univerjs/core": "0.2.
|
|
77
|
-
"@univerjs/
|
|
78
|
-
"@univerjs/
|
|
79
|
-
"@univerjs/
|
|
80
|
-
"@univerjs/
|
|
81
|
-
"@univerjs/ui": "0.2.
|
|
82
|
-
"@univerjs/
|
|
71
|
+
"typescript": "^5.5.4",
|
|
72
|
+
"vite": "^5.3.5",
|
|
73
|
+
"vitest": "^2.0.4",
|
|
74
|
+
"@univerjs/core": "0.2.6",
|
|
75
|
+
"@univerjs/design": "0.2.6",
|
|
76
|
+
"@univerjs/shared": "0.2.6",
|
|
77
|
+
"@univerjs/facade": "0.2.6",
|
|
78
|
+
"@univerjs/sheets": "0.2.6",
|
|
79
|
+
"@univerjs/sheets-ui": "0.2.6",
|
|
80
|
+
"@univerjs/ui": "0.2.6"
|
|
83
81
|
},
|
|
84
82
|
"univerSpace": {
|
|
85
83
|
".": {
|