@univerjs/uniscript 0.3.0 → 0.4.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +6 -6
- package/lib/locale/fa-IR.json +17 -0
- package/lib/types/locale/fa-IR.d.ts +3 -0
- package/lib/types/plugin.d.ts +2 -1
- package/lib/umd/index.js +2 -2
- package/package.json +18 -19
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,
|
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
|
+
}
|
package/lib/types/plugin.d.ts
CHANGED
@@ -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
|
+
"version": "0.4.0-alpha.0",
|
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.
|
54
|
-
"@univerjs/design": "0.
|
55
|
-
"@univerjs/facade": "0.
|
56
|
-
"@univerjs/sheets
|
57
|
-
"@univerjs/sheets": "0.
|
58
|
-
"@univerjs/ui": "0.
|
53
|
+
"@univerjs/core": "0.4.0-alpha.0",
|
54
|
+
"@univerjs/design": "0.4.0-alpha.0",
|
55
|
+
"@univerjs/facade": "0.4.0-alpha.0",
|
56
|
+
"@univerjs/sheets": "0.4.0-alpha.0",
|
57
|
+
"@univerjs/sheets-ui": "0.4.0-alpha.0",
|
58
|
+
"@univerjs/ui": "0.4.0-alpha.0"
|
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.
|
64
|
-
"@univerjs/design": "0.
|
65
|
-
"@univerjs/facade": "0.
|
66
|
-
"@univerjs/sheets": "0.
|
67
|
-
"@univerjs/
|
68
|
-
"@univerjs/ui": "0.
|
63
|
+
"@univerjs/core": "0.4.0-alpha.0",
|
64
|
+
"@univerjs/design": "0.4.0-alpha.0",
|
65
|
+
"@univerjs/facade": "0.4.0-alpha.0",
|
66
|
+
"@univerjs/sheets": "0.4.0-alpha.0",
|
67
|
+
"@univerjs/ui": "0.4.0-alpha.0",
|
68
|
+
"@univerjs/sheets-ui": "0.4.0-alpha.0"
|
69
69
|
},
|
70
70
|
"devDependencies": {
|
71
|
-
"@types/react": "^18.3.
|
71
|
+
"@types/react": "^18.3.11",
|
72
72
|
"less": "^4.2.0",
|
73
73
|
"rxjs": "^7.8.1",
|
74
|
-
"typescript": "^5.6.
|
74
|
+
"typescript": "^5.6.3",
|
75
75
|
"vite": "^5.4.8",
|
76
|
-
"vitest": "^2.1.
|
77
|
-
"@univerjs-infra/shared": "0.
|
76
|
+
"vitest": "^2.1.2",
|
77
|
+
"@univerjs-infra/shared": "0.4.0-alpha.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
|
}
|