@univerjs/uniscript 0.7.0 → 0.8.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var N=Object.defineProperty;var q=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var d=(t,e,r)=>q(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),c=require("@univerjs/ui"),U=require("rxjs"),v=require("react/jsx-runtime"),E=require("@univerjs/design"),W=require("monaco-editor"),h=require("react"),k=require("@univerjs/core/facade"),F=require("@univerjs/sheets-ui"),g=require("@univerjs/sheets"),D="uniscript.config",O={};class $ extends o.Disposable{constructor(){super(...arguments);d(this,"_open$",new U.BehaviorSubject(!1));d(this,"open$",this._open$.pipe(U.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)}}const M="ScriptPanel",m={type:o.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get($),r=t.get(c.ISidebarService);return e.isOpen?(e.close(),r.close()):(e.open(),r.open({header:{title:"script-panel.title"},children:{label:M},width:600})),!0}};var V=Object.getOwnPropertyDescriptor,L=(t,e,r,i)=>{for(var n=i>1?void 0:i?V(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},B=(t,e)=>(r,i)=>e(r,i,t);exports.ScriptEditorService=class extends o.Disposable{constructor(r){super();d(this,"_editorInstance",null);this._configService=r}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(r){return this._editorInstance=r,o.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){const r=this._configService.getConfig(D);window.MonacoEnvironment={getWorkerUrl:r==null?void 0:r.getWorkerUrl}}}};exports.ScriptEditorService=L([B(0,o.IConfigService)],exports.ScriptEditorService);var G=Object.getOwnPropertyDescriptor,A=(t,e,r,i)=>{for(var n=i>1?void 0:i?G(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},j=(t,e)=>(r,i)=>e(r,i,t);const y=o.createIdentifier("univer.uniscript.execution-service");let b=class extends o.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=k.FUniver.newAPI(this._injector),r=new Function("univerAPI",`(() => {${t}})()`);try{return r(e),!0}catch(i){return this._logService.error(i),!1}}};b=A([j(0,o.ILogService),j(1,o.Inject(o.Injector))],b);function H(){const t=h.useRef(null),e=h.useRef(null),r=h.useRef(null),i=c.useDependency(o.LocaleService),n=c.useDependency(c.IShortcutService),s=c.useDependency(exports.ScriptEditorService);h.useEffect(()=>{const C=e.current,p=t.current;let l=null,S=null;if(C&&p){s.requireVscodeEditor();const _=r.current=W.editor.create(C,{value:"",language:"javascript"});S=new ResizeObserver(()=>{let x=requestIdleCallback(()=>{if(!x)return;const{height:T,width:R}=p.getBoundingClientRect();_.layout({width:R,height:T}),x=void 0})}),S.observe(p);let u;l=new o.DisposableCollection,l.add(s.setEditorInstance(_)),l.add(_.onDidFocusEditorWidget(()=>{u=n.forceEscape()})),l.add(_.onDidBlurEditorWidget(()=>{u==null||u.dispose(),u=void 0})),l.add(o.toDisposable(()=>u==null?void 0:u.dispose()))}return()=>{S&&p&&S.unobserve(p),l==null||l.dispose()}},[s,n]);const a=z(r);return v.jsxs("div",{className:"univer-h-full",children:[v.jsx("div",{ref:t,className:"univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden",children:v.jsx("div",{ref:e})}),v.jsx("div",{className:"univer-mt-2.5",children:v.jsx(E.Button,{variant:"primary",onClick:a,children:i.t("script-panel.panel.execute")})})]})}function z(t){const e=c.useDependency(y),r=c.useDependency(c.IMessageService),i=c.useDependency(o.LocaleService);return h.useCallback(()=>{var s;const n=(s=t.current)==null?void 0:s.getModel();n&&e.execute(n.getValue()).then(()=>{r.show({content:i.t("uniscript.message.success"),type:E.MessageType.Success})}).catch(()=>{r.show({content:i.t("uniscript.message.failed"),type:E.MessageType.Error})})},[i,r,t,e])}function K(t){return{id:m.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:F.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission,g.WorksheetSetCellValuePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}}const Y={[c.RibbonStartGroup.OTHERS]:{[m.id]:{order:5,menuItemFactory:K}}};var J=Object.getOwnPropertyDescriptor,Q=(t,e,r,i)=>{for(var n=i>1?void 0:i?J(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},I=(t,e)=>(r,i)=>e(r,i,t);let f=class extends o.Disposable{constructor(t,e,r){super(),this._menuManagerService=t,this._menuManagerService.mergeMenu(Y),this.disposeWithMe(r.register(M,H)),this.disposeWithMe(e.registerCommand(m))}};f=Q([I(0,c.IMenuManagerService),I(1,o.ICommandService),I(2,o.Inject(c.ComponentManager))],f);var X=Object.getOwnPropertyDescriptor,Z=(t,e,r,i)=>{for(var n=i>1?void 0:i?X(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},w=(t,e)=>(r,i)=>e(r,i,t);const ee="UNIVER_UNISCRIPT_PLUGIN";var P;exports.UniverUniscriptPlugin=(P=class extends o.Plugin{constructor(e=O,r,i){super(),this._config=e,this._injector=r,this._configService=i;const{menu:n,...s}=o.merge({},O,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(D,s)}onStarting(){const e=this._injector;[[f],[exports.ScriptEditorService],[$]].forEach(i=>e.add(i)),this.registerExecution()}onSteady(){this._injector.get(f)}registerExecution(){this._injector.add([y,{useClass:b}])}},d(P,"pluginName",ee),P);exports.UniverUniscriptPlugin=Z([w(1,o.Inject(o.Injector)),w(2,o.IConfigService)],exports.UniverUniscriptPlugin);exports.IUniscriptExecutionService=y;exports.ToggleScriptPanelOperation=m;
1
+ "use strict";var N=Object.defineProperty;var q=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var d=(t,e,r)=>q(t,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),c=require("@univerjs/ui"),U=require("rxjs"),v=require("react/jsx-runtime"),E=require("@univerjs/design"),W=require("monaco-editor"),h=require("react"),k=require("@univerjs/core/facade"),F=require("@univerjs/sheets-ui"),g=require("@univerjs/sheets"),D="uniscript.config",O={};class $ extends o.Disposable{constructor(){super(...arguments);d(this,"_open$",new U.BehaviorSubject(!1));d(this,"open$",this._open$.pipe(U.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)}}const M="ScriptPanel",m={type:o.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get($),r=t.get(c.ISidebarService);return e.isOpen?(e.close(),r.close()):(e.open(),r.open({header:{title:"script-panel.title"},children:{label:M},width:600})),!0}};var V=Object.getOwnPropertyDescriptor,L=(t,e,r,i)=>{for(var n=i>1?void 0:i?V(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},B=(t,e)=>(r,i)=>e(r,i,t);exports.ScriptEditorService=class extends o.Disposable{constructor(r){super();d(this,"_editorInstance",null);this._configService=r}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(r){return this._editorInstance=r,o.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){const r=this._configService.getConfig(D);window.MonacoEnvironment={getWorkerUrl:r==null?void 0:r.getWorkerUrl}}}};exports.ScriptEditorService=L([B(0,o.IConfigService)],exports.ScriptEditorService);var G=Object.getOwnPropertyDescriptor,A=(t,e,r,i)=>{for(var n=i>1?void 0:i?G(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},j=(t,e)=>(r,i)=>e(r,i,t);const y=o.createIdentifier("univer.uniscript.execution-service");let b=class extends o.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=k.FUniver.newAPI(this._injector),r=new Function("univerAPI",`(() => {${t}})()`);try{return r(e),!0}catch(i){return this._logService.error(i),!1}}};b=A([j(0,o.ILogService),j(1,o.Inject(o.Injector))],b);function H(){const t=h.useRef(null),e=h.useRef(null),r=h.useRef(null),i=c.useDependency(o.LocaleService),n=c.useDependency(c.IShortcutService),s=c.useDependency(exports.ScriptEditorService);h.useEffect(()=>{const C=e.current,p=t.current;let l=null,S=null;if(C&&p){s.requireVscodeEditor();const _=r.current=W.editor.create(C,{value:"",language:"javascript"});S=new ResizeObserver(()=>{let x=requestIdleCallback(()=>{if(!x)return;const{height:T,width:R}=p.getBoundingClientRect();_.layout({width:R,height:T}),x=void 0})}),S.observe(p);let u;l=new o.DisposableCollection,l.add(s.setEditorInstance(_)),l.add(_.onDidFocusEditorWidget(()=>{u=n.forceEscape()})),l.add(_.onDidBlurEditorWidget(()=>{u==null||u.dispose(),u=void 0})),l.add(o.toDisposable(()=>u==null?void 0:u.dispose()))}return()=>{S&&p&&S.unobserve(p),l==null||l.dispose()}},[s,n]);const a=z(r);return v.jsxs("div",{className:"univer-h-full",children:[v.jsx("div",{ref:t,className:"univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden",children:v.jsx("div",{ref:e})}),v.jsx("div",{className:"univer-mt-2.5",children:v.jsx(E.Button,{variant:"primary",onClick:a,children:i.t("script-panel.panel.execute")})})]})}function z(t){const e=c.useDependency(y),r=c.useDependency(c.IMessageService),i=c.useDependency(o.LocaleService);return h.useCallback(()=>{var s;const n=(s=t.current)==null?void 0:s.getModel();n&&e.execute(n.getValue()).then(()=>{r.show({content:i.t("uniscript.message.success"),type:E.MessageType.Success})}).catch(()=>{r.show({content:i.t("uniscript.message.failed"),type:E.MessageType.Error})})},[i,r,t,e])}function K(t){return{id:m.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:c.MenuItemType.BUTTON,hidden$:c.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:F.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission,g.WorksheetSetCellValuePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}}const Y={[c.RibbonStartGroup.OTHERS]:{[m.id]:{order:2,menuItemFactory:K}}};var J=Object.getOwnPropertyDescriptor,Q=(t,e,r,i)=>{for(var n=i>1?void 0:i?J(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},I=(t,e)=>(r,i)=>e(r,i,t);let f=class extends o.Disposable{constructor(t,e,r){super(),this._menuManagerService=t,this._menuManagerService.mergeMenu(Y),this.disposeWithMe(r.register(M,H)),this.disposeWithMe(e.registerCommand(m))}};f=Q([I(0,c.IMenuManagerService),I(1,o.ICommandService),I(2,o.Inject(c.ComponentManager))],f);var X=Object.getOwnPropertyDescriptor,Z=(t,e,r,i)=>{for(var n=i>1?void 0:i?X(e,r):e,s=t.length-1,a;s>=0;s--)(a=t[s])&&(n=a(n)||n);return n},w=(t,e)=>(r,i)=>e(r,i,t);const ee="UNIVER_UNISCRIPT_PLUGIN";var P;exports.UniverUniscriptPlugin=(P=class extends o.Plugin{constructor(e=O,r,i){super(),this._config=e,this._injector=r,this._configService=i;const{menu:n,...s}=o.merge({},O,this._config);n&&this._configService.setConfig("menu",n,{merge:!0}),this._configService.setConfig(D,s)}onStarting(){const e=this._injector;[[f],[exports.ScriptEditorService],[$]].forEach(i=>e.add(i)),this.registerExecution()}onSteady(){this._injector.get(f)}registerExecution(){this._injector.add([y,{useClass:b}])}},d(P,"pluginName",ee),P);exports.UniverUniscriptPlugin=Z([w(1,o.Inject(o.Injector)),w(2,o.IConfigService)],exports.UniverUniscriptPlugin);exports.IUniscriptExecutionService=y;exports.ToggleScriptPanelOperation=m;
package/lib/es/index.js CHANGED
@@ -169,7 +169,7 @@ function Oe(t) {
169
169
  const xe = {
170
170
  [re.OTHERS]: {
171
171
  [C.id]: {
172
- order: 5,
172
+ order: 2,
173
173
  menuItemFactory: Oe
174
174
  }
175
175
  }
package/lib/index.js CHANGED
@@ -169,7 +169,7 @@ function Oe(t) {
169
169
  const xe = {
170
170
  [re.OTHERS]: {
171
171
  [C.id]: {
172
- order: 5,
172
+ order: 2,
173
173
  menuItemFactory: Oe
174
174
  }
175
175
  }
@@ -1,3 +1,33 @@
1
- import { default as zhCN } from './zh-CN';
2
- declare const locale: typeof zhCN;
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ declare const locale: {
17
+ 'script-panel': {
18
+ title: string;
19
+ tooltip: {
20
+ 'menu-button': string;
21
+ };
22
+ panel: {
23
+ execute: string;
24
+ };
25
+ };
26
+ uniscript: {
27
+ message: {
28
+ success: string;
29
+ failed: string;
30
+ };
31
+ };
32
+ };
3
33
  export default locale;
@@ -1,3 +1,3 @@
1
- import { default as zhCN } from './zh-CN';
2
- declare const locale: typeof zhCN;
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
3
3
  export default locale;
@@ -1,3 +1,3 @@
1
- import { default as zhCN } from './zh-CN';
2
- declare const locale: typeof zhCN;
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
3
3
  export default locale;
@@ -1,3 +1,3 @@
1
- import { default as zhCN } from './zh-CN';
2
- declare const locale: typeof zhCN;
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
3
3
  export default locale;
@@ -1,33 +1,3 @@
1
- /**
2
- * Copyright 2023-present DreamNum Co., Ltd.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- declare const locale: {
17
- 'script-panel': {
18
- title: string;
19
- tooltip: {
20
- 'menu-button': string;
21
- };
22
- panel: {
23
- execute: string;
24
- };
25
- };
26
- uniscript: {
27
- message: {
28
- success: string;
29
- failed: string;
30
- };
31
- };
32
- };
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
33
3
  export default locale;
@@ -1,3 +1,3 @@
1
- import { default as zhCN } from './zh-CN';
2
- declare const locale: typeof zhCN;
1
+ import { default as enUS } from './en-US';
2
+ declare const locale: typeof enUS;
3
3
  export default locale;
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("@univerjs/design"),require("monaco-editor"),require("react"),require("@univerjs/core/facade"),require("@univerjs/sheets-ui"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","react/jsx-runtime","@univerjs/design","monaco-editor","react","@univerjs/core/facade","@univerjs/sheets-ui","@univerjs/sheets"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s.UniverUniscript={},s.UniverCore,s.UniverUi,s.rxjs,s.React,s.UniverDesign,s.monaco,s.React,s.UniverCoreFacade,s.UniverSheetsUi,s.UniverSheets))})(this,function(s,n,a,C,p,P,N,v,R,q,g){"use strict";var ee=Object.defineProperty;var te=(s,n,a)=>n in s?ee(s,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[n]=a;var S=(s,n,a)=>te(s,typeof n!="symbol"?n+"":n,a);var y;const O="uniscript.config",w={};class D extends n.Disposable{constructor(){super(...arguments);S(this,"_open$",new C.BehaviorSubject(!1));S(this,"open$",this._open$.pipe(C.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)}}const b="ScriptPanel",f={type:n.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get(D),i=t.get(a.ISidebarService);return e.isOpen?(e.close(),i.close()):(e.open(),i.open({header:{title:"script-panel.title"},children:{label:b},width:600})),!0}};var W=Object.getOwnPropertyDescriptor,k=(t,e,i,r)=>{for(var c=r>1?void 0:r?W(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},F=(t,e)=>(i,r)=>e(i,r,t);s.ScriptEditorService=class extends n.Disposable{constructor(i){super();S(this,"_editorInstance",null);this._configService=i}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(i){return this._editorInstance=i,n.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){const i=this._configService.getConfig(O);window.MonacoEnvironment={getWorkerUrl:i==null?void 0:i.getWorkerUrl}}}},s.ScriptEditorService=k([F(0,n.IConfigService)],s.ScriptEditorService);var V=Object.getOwnPropertyDescriptor,L=(t,e,i,r)=>{for(var c=r>1?void 0:r?V(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},$=(t,e)=>(i,r)=>e(i,r,t);const E=n.createIdentifier("univer.uniscript.execution-service");let U=class extends n.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=R.FUniver.newAPI(this._injector),i=new Function("univerAPI",`(() => {${t}})()`);try{return i(e),!0}catch(r){return this._logService.error(r),!1}}};U=L([$(0,n.ILogService),$(1,n.Inject(n.Injector))],U);function B(){const t=v.useRef(null),e=v.useRef(null),i=v.useRef(null),r=a.useDependency(n.LocaleService),c=a.useDependency(a.IShortcutService),o=a.useDependency(s.ScriptEditorService);v.useEffect(()=>{const T=e.current,h=t.current;let d=null,m=null;if(T&&h){o.requireVscodeEditor();const I=i.current=N.editor.create(T,{value:"",language:"javascript"});m=new ResizeObserver(()=>{let M=requestIdleCallback(()=>{if(!M)return;const{height:X,width:Z}=h.getBoundingClientRect();I.layout({width:Z,height:X}),M=void 0})}),m.observe(h);let l;d=new n.DisposableCollection,d.add(o.setEditorInstance(I)),d.add(I.onDidFocusEditorWidget(()=>{l=c.forceEscape()})),d.add(I.onDidBlurEditorWidget(()=>{l==null||l.dispose(),l=void 0})),d.add(n.toDisposable(()=>l==null?void 0:l.dispose()))}return()=>{m&&h&&m.unobserve(h),d==null||d.dispose()}},[o,c]);const u=G(i);return p.jsxs("div",{className:"univer-h-full",children:[p.jsx("div",{ref:t,className:"univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden",children:p.jsx("div",{ref:e})}),p.jsx("div",{className:"univer-mt-2.5",children:p.jsx(P.Button,{variant:"primary",onClick:u,children:r.t("script-panel.panel.execute")})})]})}function G(t){const e=a.useDependency(E),i=a.useDependency(a.IMessageService),r=a.useDependency(n.LocaleService);return v.useCallback(()=>{var o;const c=(o=t.current)==null?void 0:o.getModel();c&&e.execute(c.getValue()).then(()=>{i.show({content:r.t("uniscript.message.success"),type:P.MessageType.Success})}).catch(()=>{i.show({content:r.t("uniscript.message.failed"),type:P.MessageType.Error})})},[r,i,t,e])}function A(t){return{id:f.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(t,n.UniverInstanceType.UNIVER_SHEET),disabled$:q.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission,g.WorksheetSetCellValuePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}}const H={[a.RibbonStartGroup.OTHERS]:{[f.id]:{order:5,menuItemFactory:A}}};var z=Object.getOwnPropertyDescriptor,K=(t,e,i,r)=>{for(var c=r>1?void 0:r?z(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},j=(t,e)=>(i,r)=>e(i,r,t);let _=class extends n.Disposable{constructor(t,e,i){super(),this._menuManagerService=t,this._menuManagerService.mergeMenu(H),this.disposeWithMe(i.register(b,B)),this.disposeWithMe(e.registerCommand(f))}};_=K([j(0,a.IMenuManagerService),j(1,n.ICommandService),j(2,n.Inject(a.ComponentManager))],_);var Y=Object.getOwnPropertyDescriptor,J=(t,e,i,r)=>{for(var c=r>1?void 0:r?Y(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},x=(t,e)=>(i,r)=>e(i,r,t);const Q="UNIVER_UNISCRIPT_PLUGIN";s.UniverUniscriptPlugin=(y=class extends n.Plugin{constructor(e=w,i,r){super(),this._config=e,this._injector=i,this._configService=r;const{menu:c,...o}=n.merge({},w,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(O,o)}onStarting(){const e=this._injector;[[_],[s.ScriptEditorService],[D]].forEach(r=>e.add(r)),this.registerExecution()}onSteady(){this._injector.get(_)}registerExecution(){this._injector.add([E,{useClass:U}])}},S(y,"pluginName",Q),y),s.UniverUniscriptPlugin=J([x(1,n.Inject(n.Injector)),x(2,n.IConfigService)],s.UniverUniscriptPlugin),s.IUniscriptExecutionService=E,s.ToggleScriptPanelOperation=f,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
1
+ (function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("react/jsx-runtime"),require("@univerjs/design"),require("monaco-editor"),require("react"),require("@univerjs/core/facade"),require("@univerjs/sheets-ui"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","react/jsx-runtime","@univerjs/design","monaco-editor","react","@univerjs/core/facade","@univerjs/sheets-ui","@univerjs/sheets"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s.UniverUniscript={},s.UniverCore,s.UniverUi,s.rxjs,s.React,s.UniverDesign,s.monaco,s.React,s.UniverCoreFacade,s.UniverSheetsUi,s.UniverSheets))})(this,function(s,n,a,C,p,P,N,v,R,q,g){"use strict";var ee=Object.defineProperty;var te=(s,n,a)=>n in s?ee(s,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[n]=a;var S=(s,n,a)=>te(s,typeof n!="symbol"?n+"":n,a);var y;const O="uniscript.config",w={};class D extends n.Disposable{constructor(){super(...arguments);S(this,"_open$",new C.BehaviorSubject(!1));S(this,"open$",this._open$.pipe(C.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)}}const b="ScriptPanel",f={type:n.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get(D),i=t.get(a.ISidebarService);return e.isOpen?(e.close(),i.close()):(e.open(),i.open({header:{title:"script-panel.title"},children:{label:b},width:600})),!0}};var W=Object.getOwnPropertyDescriptor,k=(t,e,i,r)=>{for(var c=r>1?void 0:r?W(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},F=(t,e)=>(i,r)=>e(i,r,t);s.ScriptEditorService=class extends n.Disposable{constructor(i){super();S(this,"_editorInstance",null);this._configService=i}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(i){return this._editorInstance=i,n.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){const i=this._configService.getConfig(O);window.MonacoEnvironment={getWorkerUrl:i==null?void 0:i.getWorkerUrl}}}},s.ScriptEditorService=k([F(0,n.IConfigService)],s.ScriptEditorService);var V=Object.getOwnPropertyDescriptor,L=(t,e,i,r)=>{for(var c=r>1?void 0:r?V(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},$=(t,e)=>(i,r)=>e(i,r,t);const E=n.createIdentifier("univer.uniscript.execution-service");let U=class extends n.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=R.FUniver.newAPI(this._injector),i=new Function("univerAPI",`(() => {${t}})()`);try{return i(e),!0}catch(r){return this._logService.error(r),!1}}};U=L([$(0,n.ILogService),$(1,n.Inject(n.Injector))],U);function B(){const t=v.useRef(null),e=v.useRef(null),i=v.useRef(null),r=a.useDependency(n.LocaleService),c=a.useDependency(a.IShortcutService),o=a.useDependency(s.ScriptEditorService);v.useEffect(()=>{const T=e.current,h=t.current;let d=null,m=null;if(T&&h){o.requireVscodeEditor();const I=i.current=N.editor.create(T,{value:"",language:"javascript"});m=new ResizeObserver(()=>{let M=requestIdleCallback(()=>{if(!M)return;const{height:X,width:Z}=h.getBoundingClientRect();I.layout({width:Z,height:X}),M=void 0})}),m.observe(h);let l;d=new n.DisposableCollection,d.add(o.setEditorInstance(I)),d.add(I.onDidFocusEditorWidget(()=>{l=c.forceEscape()})),d.add(I.onDidBlurEditorWidget(()=>{l==null||l.dispose(),l=void 0})),d.add(n.toDisposable(()=>l==null?void 0:l.dispose()))}return()=>{m&&h&&m.unobserve(h),d==null||d.dispose()}},[o,c]);const u=G(i);return p.jsxs("div",{className:"univer-h-full",children:[p.jsx("div",{ref:t,className:"univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden",children:p.jsx("div",{ref:e})}),p.jsx("div",{className:"univer-mt-2.5",children:p.jsx(P.Button,{variant:"primary",onClick:u,children:r.t("script-panel.panel.execute")})})]})}function G(t){const e=a.useDependency(E),i=a.useDependency(a.IMessageService),r=a.useDependency(n.LocaleService);return v.useCallback(()=>{var o;const c=(o=t.current)==null?void 0:o.getModel();c&&e.execute(c.getValue()).then(()=>{i.show({content:r.t("uniscript.message.success"),type:P.MessageType.Success})}).catch(()=>{i.show({content:r.t("uniscript.message.failed"),type:P.MessageType.Error})})},[r,i,t,e])}function A(t){return{id:f.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:a.MenuItemType.BUTTON,hidden$:a.getMenuHiddenObservable(t,n.UniverInstanceType.UNIVER_SHEET),disabled$:q.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission,g.WorksheetSetCellValuePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}}const H={[a.RibbonStartGroup.OTHERS]:{[f.id]:{order:2,menuItemFactory:A}}};var z=Object.getOwnPropertyDescriptor,K=(t,e,i,r)=>{for(var c=r>1?void 0:r?z(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},j=(t,e)=>(i,r)=>e(i,r,t);let _=class extends n.Disposable{constructor(t,e,i){super(),this._menuManagerService=t,this._menuManagerService.mergeMenu(H),this.disposeWithMe(i.register(b,B)),this.disposeWithMe(e.registerCommand(f))}};_=K([j(0,a.IMenuManagerService),j(1,n.ICommandService),j(2,n.Inject(a.ComponentManager))],_);var Y=Object.getOwnPropertyDescriptor,J=(t,e,i,r)=>{for(var c=r>1?void 0:r?Y(e,i):e,o=t.length-1,u;o>=0;o--)(u=t[o])&&(c=u(c)||c);return c},x=(t,e)=>(i,r)=>e(i,r,t);const Q="UNIVER_UNISCRIPT_PLUGIN";s.UniverUniscriptPlugin=(y=class extends n.Plugin{constructor(e=w,i,r){super(),this._config=e,this._injector=i,this._configService=r;const{menu:c,...o}=n.merge({},w,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(O,o)}onStarting(){const e=this._injector;[[_],[s.ScriptEditorService],[D]].forEach(r=>e.add(r)),this.registerExecution()}onSteady(){this._injector.get(_)}registerExecution(){this._injector.add([E,{useClass:U}])}},S(y,"pluginName",Q),y),s.UniverUniscriptPlugin=J([x(1,n.Inject(n.Injector)),x(2,n.IConfigService)],s.UniverUniscriptPlugin),s.IUniscriptExecutionService=E,s.ToggleScriptPanelOperation=f,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/uniscript",
3
- "version": "0.7.0",
3
+ "version": "0.8.0-beta.0",
4
4
  "private": false,
5
5
  "description": "UI component library for building exceptional Univer.",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -56,11 +56,11 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "monaco-editor": "0.52.2",
59
- "@univerjs/core": "0.7.0",
60
- "@univerjs/design": "0.7.0",
61
- "@univerjs/sheets": "0.7.0",
62
- "@univerjs/sheets-ui": "0.7.0",
63
- "@univerjs/ui": "0.7.0"
59
+ "@univerjs/core": "0.8.0-beta.0",
60
+ "@univerjs/design": "0.8.0-beta.0",
61
+ "@univerjs/sheets-ui": "0.8.0-beta.0",
62
+ "@univerjs/ui": "0.8.0-beta.0",
63
+ "@univerjs/sheets": "0.8.0-beta.0"
64
64
  },
65
65
  "devDependencies": {
66
66
  "postcss": "^8.5.3",
@@ -69,8 +69,8 @@
69
69
  "tailwindcss": "^3.4.17",
70
70
  "typescript": "^5.8.3",
71
71
  "vite": "^6.3.5",
72
- "vitest": "^3.1.3",
73
- "@univerjs-infra/shared": "0.7.0"
72
+ "vitest": "^3.1.4",
73
+ "@univerjs-infra/shared": "0.8.0-beta.0"
74
74
  },
75
75
  "scripts": {
76
76
  "test": "vitest run",