@univerjs/uniscript 0.3.0-alpha.1 → 0.3.0-nightly.202410111606

Sign up to get free protection for your applications and to get access to all the features.
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
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={};/**
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"),PLUGIN_CONFIG_KEY="uniscript.config",defaultPluginConfig={},_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 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="UNIVER_UNISCRIPT_PLUGIN";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;
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,__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([__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="UNIVER_UNISCRIPT_PLUGIN";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()}onSteady(){this._injector.get(UniscriptController)}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,7 +2,7 @@ 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, IConfigService, createIdentifier, Inject, Injector, ILogService, useDependency, LocaleService, DisposableCollection, UniverInstanceType, OnLifecycle, LifecycleStages, ICommandService, Plugin } from "@univerjs/core";
5
+ import { Disposable, CommandType, toDisposable, IConfigService, createIdentifier, Inject, Injector, ILogService, useDependency, LocaleService, DisposableCollection, UniverInstanceType, ICommandService, Plugin } from "@univerjs/core";
6
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";
@@ -11,7 +11,7 @@ import { editor } from "monaco-editor";
11
11
  import { FUniver } from "@univerjs/facade";
12
12
  import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
13
13
  import { WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission, RangeProtectionPermissionEditPoint } from "@univerjs/sheets";
14
- const _ScriptPanelService = class _ScriptPanelService extends Disposable {
14
+ const PLUGIN_CONFIG_KEY = "uniscript.config", defaultPluginConfig = {}, _ScriptPanelService = class _ScriptPanelService extends Disposable {
15
15
  constructor() {
16
16
  super(...arguments);
17
17
  __publicField(this, "_open$", new BehaviorSubject(!1));
@@ -67,9 +67,7 @@ reactJsxRuntime_production_min.Fragment = l;
67
67
  reactJsxRuntime_production_min.jsx = q;
68
68
  reactJsxRuntime_production_min.jsxs = q;
69
69
  jsxRuntime.exports = reactJsxRuntime_production_min;
70
- var jsxRuntimeExports = jsxRuntime.exports;
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) => {
70
+ var jsxRuntimeExports = jsxRuntime.exports, __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
73
71
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
74
72
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
75
73
  return kind && result && __defProp$3(target, key, result), result;
@@ -219,7 +217,6 @@ let UniscriptController = (_a3 = class extends Disposable {
219
217
  }
220
218
  }, __name(_a3, "UniscriptController"), _a3);
221
219
  UniscriptController = __decorateClass$1([
222
- OnLifecycle(LifecycleStages.Steady, UniscriptController),
223
220
  __decorateParam$1(0, IMenuManagerService),
224
221
  __decorateParam$1(1, ICommandService),
225
222
  __decorateParam$1(2, Inject(ComponentManager))
@@ -245,6 +242,9 @@ let UniverUniscriptPlugin = (_a4 = class extends Plugin {
245
242
  [ScriptPanelService]
246
243
  ].forEach((d) => injector.add(d)), this.registerExecution();
247
244
  }
245
+ onSteady() {
246
+ this._injector.get(UniscriptController);
247
+ }
248
248
  /**
249
249
  * Allows being overridden, replacing with a new UniscriptExecutionService.
250
250
  */
@@ -0,0 +1,17 @@
1
+ {
2
+ "script-panel": {
3
+ "title": "Uniscript",
4
+ "tooltip": {
5
+ "menu-button": "نمایش/مخفی کردن پنل Uniscript"
6
+ },
7
+ "panel": {
8
+ "execute": "اجرای اسکریپت"
9
+ }
10
+ },
11
+ "uniscript": {
12
+ "message": {
13
+ "success": "اجرای موفق",
14
+ "failed": "اجرای ناموفق"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ import { default as zhCN } from './zh-CN';
2
+ declare const locale: typeof zhCN;
3
+ export default locale;
@@ -1,5 +1,5 @@
1
- import { IConfigService, Injector, Plugin } from '@univerjs/core';
2
1
  import { IUniverUniscriptConfig } from './controllers/config.schema';
2
+ import { IConfigService, Injector, Plugin } from '@univerjs/core';
3
3
  export declare class UniverUniscriptPlugin extends Plugin {
4
4
  private readonly _config;
5
5
  protected _injector: Injector;
@@ -7,6 +7,7 @@ export declare class UniverUniscriptPlugin extends Plugin {
7
7
  static pluginName: string;
8
8
  constructor(_config: Partial<IUniverUniscriptConfig> | undefined, _injector: Injector, _configService: IConfigService);
9
9
  onStarting(): void;
10
+ onSteady(): void;
10
11
  /**
11
12
  * Allows being overridden, replacing with a new UniscriptExecutionService.
12
13
  */
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,_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={};/**
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 PLUGIN_CONFIG_KEY="uniscript.config",defaultPluginConfig={},_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 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="UNIVER_UNISCRIPT_PLUGIN";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"})});
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,__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([__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="UNIVER_UNISCRIPT_PLUGIN";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()}onSteady(){this._injector.get(UniscriptController)}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.3.0-alpha.1",
3
+ "version": "0.3.0-nightly.202410111606",
4
4
  "private": false,
5
5
  "description": "UI component library for building exceptional Univer.",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -50,31 +50,31 @@
50
50
  "monaco-editor": ">=0.44.0",
51
51
  "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
52
52
  "rxjs": ">=7.0.0",
53
- "@univerjs/core": "0.3.0-alpha.1",
54
- "@univerjs/design": "0.3.0-alpha.1",
55
- "@univerjs/sheets": "0.3.0-alpha.1",
56
- "@univerjs/facade": "0.3.0-alpha.1",
57
- "@univerjs/sheets-ui": "0.3.0-alpha.1",
58
- "@univerjs/ui": "0.3.0-alpha.1"
53
+ "@univerjs/design": "0.3.0-nightly.202410111606",
54
+ "@univerjs/sheets": "0.3.0-nightly.202410111606",
55
+ "@univerjs/core": "0.3.0-nightly.202410111606",
56
+ "@univerjs/facade": "0.3.0-nightly.202410111606",
57
+ "@univerjs/sheets-ui": "0.3.0-nightly.202410111606",
58
+ "@univerjs/ui": "0.3.0-nightly.202410111606"
59
59
  },
60
60
  "dependencies": {
61
61
  "@univerjs/protocol": "0.1.39-alpha.15",
62
62
  "monaco-editor": "0.52.0",
63
- "@univerjs/core": "0.3.0-alpha.1",
64
- "@univerjs/facade": "0.3.0-alpha.1",
65
- "@univerjs/sheets": "0.3.0-alpha.1",
66
- "@univerjs/design": "0.3.0-alpha.1",
67
- "@univerjs/sheets-ui": "0.3.0-alpha.1",
68
- "@univerjs/ui": "0.3.0-alpha.1"
63
+ "@univerjs/core": "0.3.0-nightly.202410111606",
64
+ "@univerjs/design": "0.3.0-nightly.202410111606",
65
+ "@univerjs/facade": "0.3.0-nightly.202410111606",
66
+ "@univerjs/sheets": "0.3.0-nightly.202410111606",
67
+ "@univerjs/ui": "0.3.0-nightly.202410111606",
68
+ "@univerjs/sheets-ui": "0.3.0-nightly.202410111606"
69
69
  },
70
70
  "devDependencies": {
71
- "@types/react": "^18.3.9",
71
+ "@types/react": "^18.3.11",
72
72
  "less": "^4.2.0",
73
73
  "rxjs": "^7.8.1",
74
- "typescript": "^5.6.2",
74
+ "typescript": "^5.6.3",
75
75
  "vite": "^5.4.8",
76
- "vitest": "^2.1.1",
77
- "@univerjs-infra/shared": "0.3.0-alpha.1"
76
+ "vitest": "^2.1.2",
77
+ "@univerjs-infra/shared": "0.3.0"
78
78
  },
79
79
  "univerSpace": {
80
80
  ".": {
@@ -95,7 +95,6 @@
95
95
  "test:watch": "vitest",
96
96
  "coverage": "vitest run --coverage",
97
97
  "lint:types": "tsc --noEmit",
98
- "build": "tsc && vite build",
99
- "sync:cnpm": "cnpm sync"
98
+ "build": "tsc && vite build"
100
99
  }
101
100
  }
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS