@univerjs/uniscript 0.2.11 → 0.2.12

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 CHANGED
@@ -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 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;
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 PLUGIN_CONFIG_KEY="uniscript.config",defaultPluginConfig={};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(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$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a;exports.ScriptEditorService=(_a=class extends core.Disposable{constructor(_configService){super();__publicField(this,"_editorInstance",null);this._configService=_configService}setEditorInstance(editor){return this._editorInstance=editor,core.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){const config=this._configService.getConfig(PLUGIN_CONFIG_KEY);window.MonacoEnvironment={getWorkerUrl:config==null?void 0:config.getWorkerUrl}}}},__name(_a,"ScriptEditorService"),_a);exports.ScriptEditorService=__decorateClass$3([__decorateParam$3(0,core.IConfigService)],exports.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 _a2;let UniscriptExecutionService=(_a2=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(_a2,"UniscriptExecutionService"),_a2);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(exports.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 _a5;const model=(_a5=monacoEditorRef.current)==null?void 0:_a5.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,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");const menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ToggleScriptPanelOperation.id]:{order:5,menuItemFactory: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"),_a3;let UniscriptController=(_a3=class extends core.Disposable{constructor(_menuManagerService,commandService,componentManager){super(),this._menuManagerService=_menuManagerService,this._menuManagerService.mergeMenu(menuSchema),this.disposeWithMe(componentManager.register(ScriptPanelComponentName,ScriptEditorPanel)),this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation))}},__name(_a3,"UniscriptController"),_a3);UniscriptController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Steady,UniscriptController),__decorateParam$1(0,ui.IMenuManagerService),__decorateParam$1(1,core.ICommandService),__decorateParam$1(2,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 _a4;exports.UniverUniscriptPlugin=(_a4=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){const injector=this._injector;[[UniscriptController],[exports.ScriptEditorService],[ScriptPanelService]].forEach(d=>injector.add(d)),this.registerExecution()}registerExecution(){this._injector.add([IUniscriptExecutionService,{useClass:UniscriptExecutionService}])}},__name(_a4,"UniverUniscriptPlugin"),__publicField(_a4,"pluginName",PLUGIN_NAME),_a4);exports.UniverUniscriptPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverUniscriptPlugin);exports.IUniscriptExecutionService=IUniscriptExecutionService;exports.ToggleScriptPanelOperation=ToggleScriptPanelOperation;
package/lib/es/index.js CHANGED
@@ -2,8 +2,8 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
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";
5
+ import { Disposable, CommandType, toDisposable, IConfigService, createIdentifier, Inject, Injector, ILogService, useDependency, LocaleService, DisposableCollection, UniverInstanceType, OnLifecycle, LifecycleStages, ICommandService, Plugin } from "@univerjs/core";
6
+ import { ISidebarService, IShortcutService, IMessageService, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ComponentManager, IMenuManagerService } from "@univerjs/ui";
7
7
  import { BehaviorSubject, distinctUntilChanged } from "rxjs";
8
8
  import require$$0, { useRef, useEffect, useCallback } from "react";
9
9
  import { Button, MessageType } from "@univerjs/design";
@@ -68,11 +68,17 @@ reactJsxRuntime_production_min.jsx = q;
68
68
  reactJsxRuntime_production_min.jsxs = q;
69
69
  jsxRuntime.exports = reactJsxRuntime_production_min;
70
70
  var jsxRuntimeExports = jsxRuntime.exports;
71
- const _ScriptEditorService = class _ScriptEditorService extends Disposable {
72
- constructor(_config) {
71
+ const PLUGIN_CONFIG_KEY = "uniscript.config", defaultPluginConfig = {};
72
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
73
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
74
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
75
+ return kind && result && __defProp$3(target, key, result), result;
76
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a;
77
+ let ScriptEditorService = (_a = class extends Disposable {
78
+ constructor(_configService) {
73
79
  super();
74
80
  __publicField(this, "_editorInstance", null);
75
- this._config = _config;
81
+ this._configService = _configService;
76
82
  }
77
83
  setEditorInstance(editor2) {
78
84
  return this._editorInstance = editor2, toDisposable(() => this._editorInstance = null);
@@ -81,21 +87,25 @@ const _ScriptEditorService = class _ScriptEditorService extends Disposable {
81
87
  return this._editorInstance;
82
88
  }
83
89
  requireVscodeEditor() {
84
- window.MonacoEnvironment || (window.MonacoEnvironment = {
85
- getWorkerUrl: this._config.getWorkerUrl
86
- });
90
+ if (!window.MonacoEnvironment) {
91
+ const config = this._configService.getConfig(PLUGIN_CONFIG_KEY);
92
+ window.MonacoEnvironment = {
93
+ getWorkerUrl: config == null ? void 0 : config.getWorkerUrl
94
+ };
95
+ }
87
96
  }
88
- };
89
- __name(_ScriptEditorService, "ScriptEditorService");
90
- let ScriptEditorService = _ScriptEditorService;
97
+ }, __name(_a, "ScriptEditorService"), _a);
98
+ ScriptEditorService = __decorateClass$3([
99
+ __decorateParam$3(0, IConfigService)
100
+ ], ScriptEditorService);
91
101
  var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
92
102
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
93
103
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
94
104
  return kind && result && __defProp$2(target, key, result), result;
95
105
  }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2");
96
106
  const IUniscriptExecutionService = createIdentifier("univer.uniscript.execution-service");
97
- var _a;
98
- let UniscriptExecutionService = (_a = class extends Disposable {
107
+ var _a2;
108
+ let UniscriptExecutionService = (_a2 = class extends Disposable {
99
109
  constructor(_logService, _injector) {
100
110
  super(), this._logService = _logService, this._injector = _injector;
101
111
  }
@@ -108,7 +118,7 @@ let UniscriptExecutionService = (_a = class extends Disposable {
108
118
  return this._logService.error(e), !1;
109
119
  }
110
120
  }
111
- }, __name(_a, "UniscriptExecutionService"), _a);
121
+ }, __name(_a2, "UniscriptExecutionService"), _a2);
112
122
  UniscriptExecutionService = __decorateClass$2([
113
123
  __decorateParam$2(0, ILogService),
114
124
  __decorateParam$2(1, Inject(Injector))
@@ -161,8 +171,8 @@ __name(ScriptEditorPanel, "ScriptEditorPanel");
161
171
  function useExecution(monacoEditorRef) {
162
172
  const scriptService = useDependency(IUniscriptExecutionService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService);
163
173
  return useCallback(() => {
164
- var _a4;
165
- const model = (_a4 = monacoEditorRef.current) == null ? void 0 : _a4.getModel();
174
+ var _a5;
175
+ const model = (_a5 = monacoEditorRef.current) == null ? void 0 : _a5.getModel();
166
176
  model && scriptService.execute(model.getValue()).then(() => {
167
177
  messageService.show({
168
178
  content: localeService.t("uniscript.message.success"),
@@ -184,33 +194,35 @@ function UniscriptMenuItemFactory(accessor) {
184
194
  tooltip: "script-panel.tooltip.menu-button",
185
195
  icon: "CodeSingle",
186
196
  type: MenuItemType.BUTTON,
187
- positions: [MenuPosition.TOOLBAR_START],
188
197
  // FIXME hidden$ and disabled$ are not correctly in doc
189
198
  hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
190
199
  disabled$: getCurrentRangeDisable$(accessor, { workbookTypes: [WorkbookEditablePermission], worksheetTypes: [WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission], rangeTypes: [RangeProtectionPermissionEditPoint] })
191
200
  };
192
201
  }
193
202
  __name(UniscriptMenuItemFactory, "UniscriptMenuItemFactory");
203
+ const menuSchema = {
204
+ [RibbonStartGroup.OTHERS]: {
205
+ [ToggleScriptPanelOperation.id]: {
206
+ order: 5,
207
+ menuItemFactory: UniscriptMenuItemFactory
208
+ }
209
+ }
210
+ };
194
211
  var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
195
212
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
196
213
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
197
214
  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));
215
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a3;
216
+ let UniscriptController = (_a3 = class extends Disposable {
217
+ constructor(_menuManagerService, commandService, componentManager) {
218
+ super(), this._menuManagerService = _menuManagerService, this._menuManagerService.mergeMenu(menuSchema), this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel)), this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
206
219
  }
207
- }, __name(_a2, "UniscriptController"), _a2);
220
+ }, __name(_a3, "UniscriptController"), _a3);
208
221
  UniscriptController = __decorateClass$1([
209
222
  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))
223
+ __decorateParam$1(0, IMenuManagerService),
224
+ __decorateParam$1(1, ICommandService),
225
+ __decorateParam$1(2, Inject(ComponentManager))
214
226
  ], UniscriptController);
215
227
  var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
216
228
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
@@ -218,16 +230,18 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
218
230
  return kind && result && __defProp2(target, key, result), result;
219
231
  }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
220
232
  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);
233
+ var _a4;
234
+ let UniverUniscriptPlugin = (_a4 = class extends Plugin {
235
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
236
+ super(), this._config = _config, this._injector = _injector, this._configService = _configService;
237
+ const { menu, ...rest } = this._config;
238
+ menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
225
239
  }
226
240
  onStarting() {
227
241
  const injector = this._injector;
228
242
  [
229
- [UniscriptController, { useFactory: /* @__PURE__ */ __name(() => injector.createInstance(UniscriptController, this._config), "useFactory") }],
230
- [ScriptEditorService, { useFactory: /* @__PURE__ */ __name(() => injector.createInstance(ScriptEditorService, this._config), "useFactory") }],
243
+ [UniscriptController],
244
+ [ScriptEditorService],
231
245
  [ScriptPanelService]
232
246
  ].forEach((d) => injector.add(d)), this.registerExecution();
233
247
  }
@@ -237,10 +251,10 @@ let UniverUniscriptPlugin = (_a3 = class extends Plugin {
237
251
  registerExecution() {
238
252
  this._injector.add([IUniscriptExecutionService, { useClass: UniscriptExecutionService }]);
239
253
  }
240
- }, __name(_a3, "UniverUniscriptPlugin"), __publicField(_a3, "pluginName", PLUGIN_NAME), _a3);
254
+ }, __name(_a4, "UniverUniscriptPlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
241
255
  UniverUniscriptPlugin = __decorateClass([
242
256
  __decorateParam(1, Inject(Injector)),
243
- __decorateParam(2, Inject(LocaleService))
257
+ __decorateParam(2, IConfigService)
244
258
  ], UniverUniscriptPlugin);
245
259
  export {
246
260
  IUniscriptExecutionService,
@@ -0,0 +1,8 @@
1
+ import { MenuConfig } from '@univerjs/ui';
2
+ export declare const PLUGIN_CONFIG_KEY = "uniscript.config";
3
+ export declare const configSymbol: unique symbol;
4
+ export interface IUniverUniscriptConfig {
5
+ menu?: MenuConfig;
6
+ getWorkerUrl?: (moduleID: string, label: string) => string;
7
+ }
8
+ export declare const defaultPluginConfig: IUniverUniscriptConfig;
@@ -0,0 +1,2 @@
1
+ import { MenuSchemaType } from '@univerjs/ui';
2
+ export declare const menuSchema: MenuSchemaType;
@@ -1,13 +1,6 @@
1
- import { Disposable, ICommandService, Injector } from '@univerjs/core';
2
- import { MenuConfig, ComponentManager, IMenuService } from '@univerjs/ui';
3
- export interface IUniverUniscriptConfig {
4
- getWorkerUrl(moduleID: string, label: string): string;
5
- menu: MenuConfig;
6
- }
7
- export declare const DefaultUniscriptConfig: {};
1
+ import { Disposable, ICommandService } from '@univerjs/core';
2
+ import { ComponentManager, IMenuManagerService } from '@univerjs/ui';
8
3
  export declare class UniscriptController extends Disposable {
9
- private readonly _config;
10
- private readonly _injector;
11
- private readonly _menuService;
12
- constructor(_config: Partial<IUniverUniscriptConfig>, _injector: Injector, _menuService: IMenuService, commandService: ICommandService, componentManager: ComponentManager);
4
+ private readonly _menuManagerService;
5
+ constructor(_menuManagerService: IMenuManagerService, commandService: ICommandService, componentManager: ComponentManager);
13
6
  }
@@ -1,11 +1,11 @@
1
- import { Injector, LocaleService, Plugin } from '@univerjs/core';
2
- import { IUniverUniscriptConfig } from './controllers/uniscript.controller';
1
+ import { IConfigService, Injector, Plugin } from '@univerjs/core';
2
+ import { IUniverUniscriptConfig } from './controllers/config.schema';
3
3
  export declare class UniverUniscriptPlugin extends Plugin {
4
4
  private readonly _config;
5
5
  protected _injector: Injector;
6
- private readonly _localeService;
6
+ private readonly _configService;
7
7
  static pluginName: string;
8
- constructor(_config: Partial<IUniverUniscriptConfig>, _injector: Injector, _localeService: LocaleService);
8
+ constructor(_config: Partial<IUniverUniscriptConfig>, _injector: Injector, _configService: IConfigService);
9
9
  onStarting(): void;
10
10
  /**
11
11
  * Allows being overridden, replacing with a new UniscriptExecutionService.
@@ -1,14 +1,13 @@
1
- import { Disposable, IDisposable } from '@univerjs/core';
1
+ import { Disposable, IConfigService, IDisposable } from '@univerjs/core';
2
2
  import { editor } from 'monaco-editor';
3
- import { IUniverUniscriptConfig } from '../controllers/uniscript.controller';
4
3
  /**
5
4
  * This service is for loading monaco editor and its resources. It also holds the
6
5
  * monaco editor instance so user can interact with the editor programmatically.
7
6
  */
8
7
  export declare class ScriptEditorService extends Disposable {
9
- private readonly _config;
8
+ private readonly _configService;
10
9
  private _editorInstance;
11
- constructor(_config: Partial<IUniverUniscriptConfig>);
10
+ constructor(_configService: IConfigService);
12
11
  setEditorInstance(editor: editor.IStandaloneCodeEditor): IDisposable;
13
12
  getEditorInstance(): editor.IStandaloneCodeEditor | null;
14
13
  requireVscodeEditor(): void;
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
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={};/**
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,_d;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 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"})});
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 PLUGIN_CONFIG_KEY="uniscript.config",defaultPluginConfig={};var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(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$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");exports2.ScriptEditorService=(_a=class extends core.Disposable{constructor(_configService){super();__publicField(this,"_editorInstance",null);this._configService=_configService}setEditorInstance(editor){return this._editorInstance=editor,core.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){const config=this._configService.getConfig(PLUGIN_CONFIG_KEY);window.MonacoEnvironment={getWorkerUrl:config==null?void 0:config.getWorkerUrl}}}},__name(_a,"ScriptEditorService"),_a),exports2.ScriptEditorService=__decorateClass$3([__decorateParam$3(0,core.IConfigService)],exports2.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=(_b=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(_b,"UniscriptExecutionService"),_b);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(exports2.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,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");const menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ToggleScriptPanelOperation.id]:{order:5,menuItemFactory: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");let UniscriptController=(_c=class extends core.Disposable{constructor(_menuManagerService,commandService,componentManager){super(),this._menuManagerService=_menuManagerService,this._menuManagerService.mergeMenu(menuSchema),this.disposeWithMe(componentManager.register(ScriptPanelComponentName,ScriptEditorPanel)),this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation))}},__name(_c,"UniscriptController"),_c);UniscriptController=__decorateClass$1([core.OnLifecycle(core.LifecycleStages.Steady,UniscriptController),__decorateParam$1(0,ui.IMenuManagerService),__decorateParam$1(1,core.ICommandService),__decorateParam$1(2,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=(_d=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){const injector=this._injector;[[UniscriptController],[exports2.ScriptEditorService],[ScriptPanelService]].forEach(d=>injector.add(d)),this.registerExecution()}registerExecution(){this._injector.add([IUniscriptExecutionService,{useClass:UniscriptExecutionService}])}},__name(_d,"UniverUniscriptPlugin"),__publicField(_d,"pluginName",PLUGIN_NAME),_d),exports2.UniverUniscriptPlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverUniscriptPlugin),exports2.IUniscriptExecutionService=IUniscriptExecutionService,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.11",
3
+ "version": "0.2.12",
4
4
  "private": false,
5
5
  "description": "UI component library for building exceptional Univer.",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,31 +53,31 @@
53
53
  "monaco-editor": ">=0.44.0",
54
54
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
55
55
  "rxjs": ">=7.0.0",
56
- "@univerjs/core": "0.2.11",
57
- "@univerjs/design": "0.2.11",
58
- "@univerjs/sheets": "0.2.11",
59
- "@univerjs/facade": "0.2.11",
60
- "@univerjs/sheets-ui": "0.2.11",
61
- "@univerjs/ui": "0.2.11"
56
+ "@univerjs/core": "0.2.12",
57
+ "@univerjs/facade": "0.2.12",
58
+ "@univerjs/sheets-ui": "0.2.12",
59
+ "@univerjs/ui": "0.2.12",
60
+ "@univerjs/sheets": "0.2.12",
61
+ "@univerjs/design": "0.2.12"
62
62
  },
63
63
  "dependencies": {
64
64
  "@univerjs/protocol": "0.1.39-alpha.15"
65
65
  },
66
66
  "devDependencies": {
67
- "@types/react": "^18.3.4",
67
+ "@types/react": "^18.3.5",
68
68
  "less": "^4.2.0",
69
69
  "monaco-editor": "0.51.0",
70
70
  "rxjs": "^7.8.1",
71
71
  "typescript": "^5.5.4",
72
72
  "vite": "^5.4.2",
73
73
  "vitest": "^2.0.5",
74
- "@univerjs/core": "0.2.11",
75
- "@univerjs/design": "0.2.11",
76
- "@univerjs/facade": "0.2.11",
77
- "@univerjs/shared": "0.2.11",
78
- "@univerjs/sheets": "0.2.11",
79
- "@univerjs/sheets-ui": "0.2.11",
80
- "@univerjs/ui": "0.2.11"
74
+ "@univerjs/core": "0.2.12",
75
+ "@univerjs/design": "0.2.12",
76
+ "@univerjs/facade": "0.2.12",
77
+ "@univerjs/sheets": "0.2.12",
78
+ "@univerjs/shared": "0.2.12",
79
+ "@univerjs/sheets-ui": "0.2.12",
80
+ "@univerjs/ui": "0.2.12"
81
81
  },
82
82
  "univerSpace": {
83
83
  ".": {