@univerjs/uniscript 0.1.0-beta.1 → 0.1.0-beta.2

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 X=Object.defineProperty;var Z=(t,e,n)=>e in t?X(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var g=(t,e,n)=>(Z(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),a=require("@wendellhu/redi"),d=require("@univerjs/ui"),W=require("rxjs"),_=require("react"),U=require("@univerjs/design"),m=require("@wendellhu/redi/react-bindings"),ee=require("monaco-editor"),h=require("@univerjs/sheets"),te={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}},uniscript:{message:{success:"Execution Success",failed:"Execution Failed"}}},B={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}},uniscript:{message:{success:"执行成功",failed:"执行失败"}}};class H extends c.Disposable{constructor(){super(...arguments);g(this,"_open$",new W.BehaviorSubject(!1));g(this,"open$",this._open$.pipe(W.distinctUntilChanged()))}get isOpen(){return this._open$.getValue()}dispose(){this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}}const z="ScriptPanel",V={type:c.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get(H),n=t.get(d.ISidebarService);return e.isOpen?(e.close(),n.close()):(e.open(),n.open({header:{title:"script-panel.title"},children:{label:z},width:600})),!0}};var G={exports:{}},y={};/**
1
+ "use strict";var W=Object.defineProperty;var z=(t,e,n)=>e in t?W(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var f=(t,e,n)=>(z(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),u=require("@wendellhu/redi"),d=require("@univerjs/ui"),$=require("rxjs"),v=require("react"),I=require("@univerjs/design"),h=require("@wendellhu/redi/react-bindings"),V=require("monaco-editor"),H=require("@univerjs/facade"),G=require("@univerjs/sheets"),J={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}},uniscript:{message:{success:"Execution Success",failed:"Execution Failed"}}},R={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}},uniscript:{message:{success:"执行成功",failed:"执行失败"}}};class T extends c.Disposable{constructor(){super(...arguments);f(this,"_open$",new $.BehaviorSubject(!1));f(this,"open$",this._open$.pipe($.distinctUntilChanged()))}get isOpen(){return this._open$.getValue()}dispose(){this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}}const M="ScriptPanel",q={type:c.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get(T),n=t.get(d.ISidebarService);return e.isOpen?(e.close(),n.close()):(e.open(),n.open({header:{title:"script-panel.title"},children:{label:M},width:600})),!0}};var N={exports:{}},x={};/**
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 re=_,ne=Symbol.for("react.element"),se=Symbol.for("react.fragment"),ie=Object.prototype.hasOwnProperty,oe=re.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ce={key:!0,ref:!0,__self:!0,__source:!0};function J(t,e,n){var r,s={},i=null,o=null;n!==void 0&&(i=""+n),e.key!==void 0&&(i=""+e.key),e.ref!==void 0&&(o=e.ref);for(r in e)ie.call(e,r)&&!ce.hasOwnProperty(r)&&(s[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)s[r]===void 0&&(s[r]=e[r]);return{$$typeof:ne,type:t,key:i,ref:o,props:s,_owner:oe.current}}y.Fragment=se;y.jsx=J;y.jsxs=J;G.exports=y;var f=G.exports;class R extends c.Disposable{constructor(n){super();g(this,"_editorInstance",null);this._config=n}setEditorInstance(n){return this._editorInstance=n,c.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var ae=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(t,e,n,r)=>{for(var s=r>1?void 0:r?le(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&ae(e,n,s),s},q=(t,e)=>(n,r)=>e(n,r,t);let P=class{constructor(t,e,n,r,s){this._workbook=t,this._worksheet=e,this._range=n,this._injector=r,this._commandService=s}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}getValue(){var t;return((t=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:t.v)??null}setBackgroundColor(t){this._commandService.executeCommand(h.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:t}}})}};P=ue([q(3,a.Inject(a.Injector)),q(4,c.ICommandService)],P);var pe=Object.defineProperty,de=Object.getOwnPropertyDescriptor,_e=(t,e,n,r)=>{for(var s=r>1?void 0:r?de(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&pe(e,n,s),s},he=(t,e)=>(n,r)=>e(n,r,t);let D=class{constructor(t,e,n,r){this._workbook=t,this._worksheet=e,this._selections=n,this._injector=r}getActiveRange(){const t=this._selections.find(e=>!!e.primary);return t?this._injector.createInstance(P,this._workbook,this._worksheet,t.range):null}};D=_e([he(3,a.Inject(a.Injector))],D);var ve=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,me=(t,e,n,r)=>{for(var s=r>1?void 0:r?ge(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&ve(e,n,s),s},$=(t,e)=>(n,r)=>e(n,r,t);let C=class{constructor(t,e,n,r,s){this._workbook=t,this._worksheet=e,this._injector=n,this._selectionManagerService=r,this._commandService=s}getSelection(){const t=this._selectionManagerService.getSelections();return t?this._injector.createInstance(D,this._workbook,this._worksheet,t):null}getRange(t,e,n,r){const s={startRow:t,endRow:t+(n??1)-1,startColumn:e,endColumn:e+(r??1)-1};return this._injector.createInstance(P,this._workbook,this._worksheet,s)}setRowHeights(t,e,n){this._commandService.syncExecuteCommand(h.SetWorksheetRowHeightMutation.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[{startRow:t,endRow:t+e-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}],rowHeight:n})}setColumnWidths(t,e,n){this._commandService.syncExecuteCommand(h.SetWorksheetColWidthMutation.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[{startColumn:t,endColumn:t+e-1,startRow:0,endRow:this._worksheet.getRowCount()-1}],colWidth:n})}};C=me([$(2,a.Inject(a.Injector)),$(3,a.Inject(h.SelectionManagerService)),$(4,c.ICommandService)],C);var fe=Object.defineProperty,Se=Object.getOwnPropertyDescriptor,we=(t,e,n,r)=>{for(var s=r>1?void 0:r?Se(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&fe(e,n,s),s},A=(t,e)=>(n,r)=>e(n,r,t);let k=class{constructor(t,e,n){this._workbook=t,this._injector=e,this._commandService=n}getActiveSheet(){const t=this._workbook.getActiveSheet();return t?this._injector.createInstance(C,this._workbook,t):null}create(t,e,n){const r=c.Tools.deepClone(c.DEFAULT_WORKSHEET);return r.rowCount=e,r.columnCount=n,r.name=t,r.id=t.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(h.InsertSheetCommand.id,{unitId:this._workbook.getUnitId(),index:this._workbook.getSheets().length,sheet:r}),this._commandService.syncExecuteCommand(h.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()}),this._injector.createInstance(C,this._workbook,this._workbook.getActiveSheet())}};k=we([A(1,a.Inject(a.Injector)),A(2,c.ICommandService)],k);var Ie=Object.defineProperty,be=Object.getOwnPropertyDescriptor,je=(t,e,n,r)=>{for(var s=r>1?void 0:r?be(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&Ie(e,n,s),s},F=(t,e)=>(n,r)=>e(n,r,t);let O=class{constructor(t,e){this._injector=t,this._univerInstanceService=e}static newInstance(t){return t.createInstance(O)}getCurrentSheet(){const t=this._univerInstanceService.getCurrentUniverSheetInstance();return t?this._injector.createInstance(k,t):null}};O=je([F(0,a.Inject(a.Injector)),F(1,c.IUniverInstanceService)],O);var Pe=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Oe=(t,e,n,r)=>{for(var s=r>1?void 0:r?Ce(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&Pe(e,n,s),s},N=(t,e)=>(n,r)=>e(n,r,t);let E=class extends c.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=O.newInstance(this._injector),n=new Function("Univer",`(() => {${t}})()`);try{return n(e),!0}catch(r){return this._logService.error(r),!1}}};E=Oe([N(0,c.ILogService),N(1,a.Inject(a.Injector))],E);const Ee="univer-script-editor-panel",ye="univer-script-editor-content",Ue="univer-script-editor-actions",I={scriptEditorPanel:Ee,scriptEditorContent:ye,scriptEditorActions:Ue};function $e(){const t=_.useRef(null),e=_.useRef(null),n=_.useRef(null),r=m.useDependency(c.LocaleService),s=m.useDependency(E),i=m.useDependency(d.IShortcutService),o=m.useDependency(R),M=m.useDependency(d.IMessageService);_.useEffect(()=>{const v=e.current,l=t.current;let u=null,S=null;if(v&&l){o.requireVscodeEditor();const w=n.current=ee.editor.create(v,{value:"",language:"javascript"});S=new ResizeObserver(()=>{let T=requestIdleCallback(()=>{if(!T)return;const{height:Y,width:Q}=l.getBoundingClientRect();w.layout({width:Q,height:Y}),T=void 0})}),S.observe(l);let p;u=new c.DisposableCollection,u.add(o.setEditorInstance(w)),u.add(w.onDidFocusEditorWidget(()=>{p=i.forceEscape()})),u.add(w.onDidBlurEditorWidget(()=>{p==null||p.dispose(),p=void 0})),u.add(c.toDisposable(()=>p==null?void 0:p.dispose()))}return()=>{S&&l&&S.unobserve(l),u==null||u.dispose()}},[]);const K=_.useCallback(()=>{var l;const v=(l=n.current)==null?void 0:l.getModel();v&&s.execute(v.getValue()).then(()=>{M.show({content:r.t("uniscript.message.success"),type:U.MessageType.Success})}).catch(()=>{M.show({content:r.t("uniscript.message.failed"),type:U.MessageType.Error})})},[s]);return f.jsxs("div",{className:I.scriptEditorPanel,children:[f.jsx("div",{className:I.scriptEditorContent,ref:t,children:f.jsx("div",{className:I.scriptEditorContainer,ref:e})}),f.jsx("div",{className:I.scriptEditorActions,children:f.jsx(U.Button,{type:"primary",size:"small",onClick:K,children:r.t("script-panel.panel.execute")})})]})}function xe(t){return{id:V.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:d.MenuItemType.BUTTON,positions:[d.MenuPosition.TOOLBAR_START],hidden$:d.getMenuHiddenObservable(t,c.UniverInstanceType.SHEET)}}var Re=Object.defineProperty,De=Object.getOwnPropertyDescriptor,ke=(t,e,n,r)=>{for(var s=r>1?void 0:r?De(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&Re(e,n,s),s},b=(t,e)=>(n,r)=>e(n,r,t);let j=class extends c.Disposable{constructor(t,e,n,r){super(),this._injector=t,this.disposeWithMe(e.addMenuItem(this._injector.invoke(xe))),this.disposeWithMe(r.register(z,$e)),this.disposeWithMe(n.registerCommand(V))}};j=ke([c.OnLifecycle(c.LifecycleStages.Steady,j),b(0,a.Inject(a.Injector)),b(1,d.IMenuService),b(2,c.ICommandService),b(3,a.Inject(d.ComponentManager))],j);var Me=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,We=(t,e,n,r)=>{for(var s=r>1?void 0:r?Te(e,n):e,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(e,n,s):o(s))||s);return r&&s&&Me(e,n,s),s},L=(t,e)=>(n,r)=>e(n,r,t);const qe="uniscript";var x;exports.UniverUniscriptPlugin=(x=class extends c.Plugin{constructor(e,n,r){super(qe),this._config=e,this._injector=n,this._localeService=r}onStarting(e){[[j],[R,{useFactory:()=>e.createInstance(R,this._config)}],[H],[E]].forEach(r=>e.add(r)),this._localeService.load({zhCN:B})}},g(x,"type",c.PluginType.Univer),x);exports.UniverUniscriptPlugin=We([L(1,a.Inject(a.Injector)),L(2,a.Inject(c.LocaleService))],exports.UniverUniscriptPlugin);exports.enUS=te;exports.zhCN=B;
9
+ */var Y=v,K=Symbol.for("react.element"),Q=Symbol.for("react.fragment"),X=Object.prototype.hasOwnProperty,Z=Y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,k={key:!0,ref:!0,__self:!0,__source:!0};function A(t,e,n){var r,i={},s=null,o=null;n!==void 0&&(s=""+n),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(o=e.ref);for(r in e)X.call(e,r)&&!k.hasOwnProperty(r)&&(i[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:K,type:t,key:s,ref:o,props:i,_owner:Z.current}}x.Fragment=Q;x.jsx=A;x.jsxs=A;N.exports=x;var g=N.exports;class j extends c.Disposable{constructor(n){super();f(this,"_editorInstance",null);this._config=n}setEditorInstance(n){return this._editorInstance=n,c.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(t,e,n,r)=>{for(var i=r>1?void 0:r?te(e,n):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&ee(e,n,i),i},w=(t,e)=>(n,r)=>e(n,r,t);let b=class extends c.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=H.FUniver.newAPI(this._injector),n=new Function("univerAPI",`(() => {${t}})()`);try{return n(e),!0}catch(r){return this._logService.error(r),!1}}};b=ne([w(0,c.ILogService),w(1,u.Inject(u.Injector))],b);const re="univer-script-editor-panel",ie="univer-script-editor-content",se="univer-script-editor-actions",E={scriptEditorPanel:re,scriptEditorContent:ie,scriptEditorActions:se};function oe(){const t=v.useRef(null),e=v.useRef(null),n=v.useRef(null),r=h.useDependency(c.LocaleService),i=h.useDependency(b),s=h.useDependency(d.IShortcutService),o=h.useDependency(j),U=h.useDependency(d.IMessageService);v.useEffect(()=>{const _=e.current,l=t.current;let p=null,S=null;if(_&&l){o.requireVscodeEditor();const m=n.current=V.editor.create(_,{value:"",language:"javascript"});S=new ResizeObserver(()=>{let C=requestIdleCallback(()=>{if(!C)return;const{height:F,width:B}=l.getBoundingClientRect();m.layout({width:B,height:F}),C=void 0})}),S.observe(l);let a;p=new c.DisposableCollection,p.add(o.setEditorInstance(m)),p.add(m.onDidFocusEditorWidget(()=>{a=s.forceEscape()})),p.add(m.onDidBlurEditorWidget(()=>{a==null||a.dispose(),a=void 0})),p.add(c.toDisposable(()=>a==null?void 0:a.dispose()))}return()=>{S&&l&&S.unobserve(l),p==null||p.dispose()}},[]);const L=v.useCallback(()=>{var l;const _=(l=n.current)==null?void 0:l.getModel();_&&i.execute(_.getValue()).then(()=>{U.show({content:r.t("uniscript.message.success"),type:I.MessageType.Success})}).catch(()=>{U.show({content:r.t("uniscript.message.failed"),type:I.MessageType.Error})})},[i]);return g.jsxs("div",{className:E.scriptEditorPanel,children:[g.jsx("div",{className:E.scriptEditorContent,ref:t,children:g.jsx("div",{className:E.scriptEditorContainer,ref:e})}),g.jsx("div",{className:E.scriptEditorActions,children:g.jsx(I.Button,{type:"primary",size:"small",onClick:L,children:r.t("script-panel.panel.execute")})})]})}function ce(t){return{id:q.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:d.MenuItemType.BUTTON,positions:[d.MenuPosition.TOOLBAR_START],hidden$:d.getMenuHiddenObservable(t,c.UniverInstanceType.SHEET),disabled$:G.getCurrentSheetDisabled$(t)}}var le=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,ae=(t,e,n,r)=>{for(var i=r>1?void 0:r?pe(e,n):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&le(e,n,i),i},P=(t,e)=>(n,r)=>e(n,r,t);let y=class extends c.Disposable{constructor(t,e,n,r){super(),this._injector=t,this.disposeWithMe(e.addMenuItem(this._injector.invoke(ce))),this.disposeWithMe(r.register(M,oe)),this.disposeWithMe(n.registerCommand(q))}};y=ae([c.OnLifecycle(c.LifecycleStages.Steady,y),P(0,u.Inject(u.Injector)),P(1,d.IMenuService),P(2,c.ICommandService),P(3,u.Inject(d.ComponentManager))],y);var ue=Object.defineProperty,de=Object.getOwnPropertyDescriptor,ve=(t,e,n,r)=>{for(var i=r>1?void 0:r?de(e,n):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&ue(e,n,i),i},D=(t,e)=>(n,r)=>e(n,r,t);const _e="uniscript";var O;exports.UniverUniscriptPlugin=(O=class extends c.Plugin{constructor(e,n,r){super(_e),this._config=e,this._injector=n,this._localeService=r}onStarting(e){[[y],[j,{useFactory:()=>e.createInstance(j,this._config)}],[T],[b]].forEach(r=>e.add(r)),this._localeService.load({zhCN:R})}},f(O,"type",c.PluginType.Univer),O);exports.UniverUniscriptPlugin=ve([D(1,u.Inject(u.Injector)),D(2,u.Inject(c.LocaleService))],exports.UniverUniscriptPlugin);exports.enUS=J;exports.zhCN=R;
package/lib/es/index.js CHANGED
@@ -1,16 +1,17 @@
1
- var Z = Object.defineProperty;
2
- var ee = (t, e, r) => e in t ? Z(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var h = (t, e, r) => (ee(t, typeof e != "symbol" ? e + "" : e, r), r);
4
- import { Disposable as O, CommandType as te, toDisposable as H, ICommandService as E, Tools as re, DEFAULT_WORKSHEET as ne, IUniverInstanceService as oe, ILogService as ie, LocaleService as q, DisposableCollection as se, UniverInstanceType as ce, OnLifecycle as ae, LifecycleStages as le, Plugin as ue, PluginType as pe } from "@univerjs/core";
5
- import { Inject as c, Injector as p } from "@wendellhu/redi";
6
- import { ISidebarService as _e, IShortcutService as he, IMessageService as de, MenuItemType as ve, MenuPosition as me, getMenuHiddenObservable as ge, ComponentManager as fe, IMenuService as Se } from "@univerjs/ui";
7
- import { BehaviorSubject as we, distinctUntilChanged as be } from "rxjs";
8
- import Ie, { useRef as $, useEffect as Pe, useCallback as Ce } from "react";
9
- import { MessageType as T, Button as Oe } from "@univerjs/design";
1
+ var z = Object.defineProperty;
2
+ var V = (t, e, r) => e in t ? z(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var u = (t, e, r) => (V(t, typeof e != "symbol" ? e + "" : e, r), r);
4
+ import { Disposable as P, CommandType as H, toDisposable as T, ILogService as G, LocaleService as M, DisposableCollection as J, UniverInstanceType as Y, OnLifecycle as K, LifecycleStages as Q, ICommandService as X, Plugin as Z, PluginType as k } from "@univerjs/core";
5
+ import { Inject as f, Injector as I } from "@wendellhu/redi";
6
+ import { ISidebarService as ee, IShortcutService as te, IMessageService as re, MenuItemType as ie, MenuPosition as ne, getMenuHiddenObservable as oe, ComponentManager as se, IMenuService as ce } from "@univerjs/ui";
7
+ import { BehaviorSubject as le, distinctUntilChanged as pe } from "rxjs";
8
+ import ae, { useRef as O, useEffect as ue, useCallback as de } from "react";
9
+ import { MessageType as $, Button as ve } from "@univerjs/design";
10
10
  import { useDependency as d } from "@wendellhu/redi/react-bindings";
11
- import { editor as Ee } from "monaco-editor";
12
- import { SetStyleCommand as je, SetWorksheetRowHeightMutation as $e, SetWorksheetColWidthMutation as xe, SelectionManagerService as ye, InsertSheetCommand as Ue, SetWorksheetActivateCommand as Re } from "@univerjs/sheets";
13
- const jt = {
11
+ import { editor as fe } from "monaco-editor";
12
+ import { FUniver as _e } from "@univerjs/facade";
13
+ import { getCurrentSheetDisabled$ as me } from "@univerjs/sheets";
14
+ const Qe = {
14
15
  "script-panel": {
15
16
  title: "Uniscript",
16
17
  tooltip: {
@@ -26,7 +27,7 @@ const jt = {
26
27
  failed: "Execution Failed"
27
28
  }
28
29
  }
29
- }, ke = {
30
+ }, he = {
30
31
  "script-panel": {
31
32
  title: "Uniscript",
32
33
  tooltip: {
@@ -43,11 +44,11 @@ const jt = {
43
44
  }
44
45
  }
45
46
  };
46
- class V extends O {
47
+ class D extends P {
47
48
  constructor() {
48
49
  super(...arguments);
49
- h(this, "_open$", new we(!1));
50
- h(this, "open$", this._open$.pipe(be()));
50
+ u(this, "_open$", new le(!1));
51
+ u(this, "open$", this._open$.pipe(pe()));
51
52
  }
52
53
  get isOpen() {
53
54
  return this._open$.getValue();
@@ -62,19 +63,19 @@ class V extends O {
62
63
  this._open$.next(!1);
63
64
  }
64
65
  }
65
- const z = "ScriptPanel", G = {
66
- type: te.OPERATION,
66
+ const N = "ScriptPanel", A = {
67
+ type: H.OPERATION,
67
68
  id: "univer.operation.toggle-script-panel",
68
69
  handler: (t) => {
69
- const e = t.get(V), r = t.get(_e);
70
+ const e = t.get(D), r = t.get(ee);
70
71
  return e.isOpen ? (e.close(), r.close()) : (e.open(), r.open({
71
72
  header: { title: "script-panel.title" },
72
- children: { label: z },
73
+ children: { label: N },
73
74
  width: 600
74
75
  })), !0;
75
76
  }
76
77
  };
77
- var J = { exports: {} }, j = {};
78
+ var F = { exports: {} }, x = {};
78
79
  /**
79
80
  * @license React
80
81
  * react-jsx-runtime.production.min.js
@@ -84,30 +85,30 @@ var J = { exports: {} }, j = {};
84
85
  * This source code is licensed under the MIT license found in the
85
86
  * LICENSE file in the root directory of this source tree.
86
87
  */
87
- var De = Ie, Me = Symbol.for("react.element"), Te = Symbol.for("react.fragment"), We = Object.prototype.hasOwnProperty, Ae = De.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Fe = { key: !0, ref: !0, __self: !0, __source: !0 };
88
- function K(t, e, r) {
89
- var n, o = {}, i = null, s = null;
90
- r !== void 0 && (i = "" + r), e.key !== void 0 && (i = "" + e.key), e.ref !== void 0 && (s = e.ref);
91
- for (n in e)
92
- We.call(e, n) && !Fe.hasOwnProperty(n) && (o[n] = e[n]);
88
+ var ge = ae, Se = Symbol.for("react.element"), Ee = Symbol.for("react.fragment"), Pe = Object.prototype.hasOwnProperty, xe = ge.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Oe = { key: !0, ref: !0, __self: !0, __source: !0 };
89
+ function L(t, e, r) {
90
+ var i, n = {}, o = null, s = null;
91
+ r !== void 0 && (o = "" + r), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (s = e.ref);
92
+ for (i in e)
93
+ Pe.call(e, i) && !Oe.hasOwnProperty(i) && (n[i] = e[i]);
93
94
  if (t && t.defaultProps)
94
- for (n in e = t.defaultProps, e)
95
- o[n] === void 0 && (o[n] = e[n]);
96
- return { $$typeof: Me, type: t, key: i, ref: s, props: o, _owner: Ae.current };
95
+ for (i in e = t.defaultProps, e)
96
+ n[i] === void 0 && (n[i] = e[i]);
97
+ return { $$typeof: Se, type: t, key: o, ref: s, props: n, _owner: xe.current };
97
98
  }
98
- j.Fragment = Te;
99
- j.jsx = K;
100
- j.jsxs = K;
101
- J.exports = j;
102
- var v = J.exports;
103
- class U extends O {
99
+ x.Fragment = Ee;
100
+ x.jsx = L;
101
+ x.jsxs = L;
102
+ F.exports = x;
103
+ var v = F.exports;
104
+ class b extends P {
104
105
  constructor(r) {
105
106
  super();
106
- h(this, "_editorInstance", null);
107
+ u(this, "_editorInstance", null);
107
108
  this._config = r;
108
109
  }
109
110
  setEditorInstance(r) {
110
- return this._editorInstance = r, H(() => this._editorInstance = null);
111
+ return this._editorInstance = r, T(() => this._editorInstance = null);
111
112
  }
112
113
  getEditorInstance() {
113
114
  return this._editorInstance;
@@ -118,314 +119,147 @@ class U extends O {
118
119
  });
119
120
  }
120
121
  }
121
- var Ne = Object.defineProperty, Le = Object.getOwnPropertyDescriptor, Be = (t, e, r, n) => {
122
- for (var o = n > 1 ? void 0 : n ? Le(e, r) : e, i = t.length - 1, s; i >= 0; i--)
123
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
124
- return n && o && Ne(e, r, o), o;
125
- }, W = (t, e) => (r, n) => e(r, n, t);
126
- let b = class {
127
- constructor(t, e, r, n, o) {
128
- this._workbook = t, this._worksheet = e, this._range = r, this._injector = n, this._commandService = o;
129
- }
130
- getRow() {
131
- return this._range.startRow;
132
- }
133
- getColumn() {
134
- return this._range.startColumn;
135
- }
136
- getWidth() {
137
- return this._range.endColumn - this._range.startColumn + 1;
138
- }
139
- getHeight() {
140
- return this._range.endRow - this._range.startRow + 1;
141
- }
142
- getValue() {
143
- var t;
144
- return ((t = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) == null ? void 0 : t.v) ?? null;
145
- }
146
- setBackgroundColor(t) {
147
- this._commandService.executeCommand(je.id, {
148
- unitId: this._workbook.getUnitId(),
149
- subUnitId: this._worksheet.getSheetId(),
150
- range: this._range,
151
- style: {
152
- type: "bg",
153
- value: {
154
- rgb: t
155
- }
156
- }
157
- });
158
- }
159
- };
160
- b = Be([
161
- W(3, c(p)),
162
- W(4, E)
163
- ], b);
164
- var He = Object.defineProperty, qe = Object.getOwnPropertyDescriptor, Ve = (t, e, r, n) => {
165
- for (var o = n > 1 ? void 0 : n ? qe(e, r) : e, i = t.length - 1, s; i >= 0; i--)
166
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
167
- return n && o && He(e, r, o), o;
168
- }, ze = (t, e) => (r, n) => e(r, n, t);
169
- let R = class {
170
- constructor(t, e, r, n) {
171
- this._workbook = t, this._worksheet = e, this._selections = r, this._injector = n;
172
- }
173
- getActiveRange() {
174
- const t = this._selections.find((e) => !!e.primary);
175
- return t ? this._injector.createInstance(b, this._workbook, this._worksheet, t.range) : null;
176
- }
177
- };
178
- R = Ve([
179
- ze(3, c(p))
180
- ], R);
181
- var Ge = Object.defineProperty, Je = Object.getOwnPropertyDescriptor, Ke = (t, e, r, n) => {
182
- for (var o = n > 1 ? void 0 : n ? Je(e, r) : e, i = t.length - 1, s; i >= 0; i--)
183
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
184
- return n && o && Ge(e, r, o), o;
185
- }, x = (t, e) => (r, n) => e(r, n, t);
186
- let I = class {
187
- constructor(t, e, r, n, o) {
188
- this._workbook = t, this._worksheet = e, this._injector = r, this._selectionManagerService = n, this._commandService = o;
189
- }
190
- getSelection() {
191
- const t = this._selectionManagerService.getSelections();
192
- return t ? this._injector.createInstance(R, this._workbook, this._worksheet, t) : null;
193
- }
194
- getRange(t, e, r, n) {
195
- const o = {
196
- startRow: t,
197
- endRow: t + (r ?? 1) - 1,
198
- startColumn: e,
199
- endColumn: e + (n ?? 1) - 1
200
- };
201
- return this._injector.createInstance(b, this._workbook, this._worksheet, o);
202
- }
203
- setRowHeights(t, e, r) {
204
- this._commandService.syncExecuteCommand($e.id, {
205
- unitId: this._workbook.getUnitId(),
206
- subUnitId: this._worksheet.getSheetId(),
207
- ranges: [
208
- {
209
- startRow: t,
210
- endRow: t + e - 1,
211
- startColumn: 0,
212
- endColumn: this._worksheet.getColumnCount() - 1
213
- }
214
- ],
215
- rowHeight: r
216
- });
217
- }
218
- setColumnWidths(t, e, r) {
219
- this._commandService.syncExecuteCommand(xe.id, {
220
- unitId: this._workbook.getUnitId(),
221
- subUnitId: this._worksheet.getSheetId(),
222
- ranges: [
223
- {
224
- startColumn: t,
225
- endColumn: t + e - 1,
226
- startRow: 0,
227
- endRow: this._worksheet.getRowCount() - 1
228
- }
229
- ],
230
- colWidth: r
231
- });
232
- }
233
- };
234
- I = Ke([
235
- x(2, c(p)),
236
- x(3, c(ye)),
237
- x(4, E)
238
- ], I);
239
- var Ye = Object.defineProperty, Qe = Object.getOwnPropertyDescriptor, Xe = (t, e, r, n) => {
240
- for (var o = n > 1 ? void 0 : n ? Qe(e, r) : e, i = t.length - 1, s; i >= 0; i--)
241
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
242
- return n && o && Ye(e, r, o), o;
243
- }, A = (t, e) => (r, n) => e(r, n, t);
244
- let k = class {
245
- constructor(t, e, r) {
246
- this._workbook = t, this._injector = e, this._commandService = r;
247
- }
248
- getActiveSheet() {
249
- const t = this._workbook.getActiveSheet();
250
- return t ? this._injector.createInstance(I, this._workbook, t) : null;
251
- }
252
- create(t, e, r) {
253
- const n = re.deepClone(ne);
254
- return n.rowCount = e, n.columnCount = r, n.name = t, n.id = t.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(Ue.id, {
255
- unitId: this._workbook.getUnitId(),
256
- index: this._workbook.getSheets().length,
257
- sheet: n
258
- }), this._commandService.syncExecuteCommand(Re.id, {
259
- unitId: this._workbook.getUnitId(),
260
- subUnitId: this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId()
261
- }), this._injector.createInstance(I, this._workbook, this._workbook.getActiveSheet());
262
- }
263
- };
264
- k = Xe([
265
- A(1, c(p)),
266
- A(2, E)
267
- ], k);
268
- var Ze = Object.defineProperty, et = Object.getOwnPropertyDescriptor, tt = (t, e, r, n) => {
269
- for (var o = n > 1 ? void 0 : n ? et(e, r) : e, i = t.length - 1, s; i >= 0; i--)
270
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
271
- return n && o && Ze(e, r, o), o;
272
- }, F = (t, e) => (r, n) => e(r, n, t);
273
- let P = class {
274
- constructor(t, e) {
275
- this._injector = t, this._univerInstanceService = e;
276
- }
277
- static newInstance(t) {
278
- return t.createInstance(P);
279
- }
280
- getCurrentSheet() {
281
- const t = this._univerInstanceService.getCurrentUniverSheetInstance();
282
- return t ? this._injector.createInstance(k, t) : null;
283
- }
284
- };
285
- P = tt([
286
- F(0, c(p)),
287
- F(1, oe)
288
- ], P);
289
- var rt = Object.defineProperty, nt = Object.getOwnPropertyDescriptor, ot = (t, e, r, n) => {
290
- for (var o = n > 1 ? void 0 : n ? nt(e, r) : e, i = t.length - 1, s; i >= 0; i--)
291
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
292
- return n && o && rt(e, r, o), o;
293
- }, N = (t, e) => (r, n) => e(r, n, t);
294
- let C = class extends O {
122
+ var ye = Object.defineProperty, be = Object.getOwnPropertyDescriptor, Ie = (t, e, r, i) => {
123
+ for (var n = i > 1 ? void 0 : i ? be(e, r) : e, o = t.length - 1, s; o >= 0; o--)
124
+ (s = t[o]) && (n = (i ? s(e, r, n) : s(n)) || n);
125
+ return i && n && ye(e, r, n), n;
126
+ }, w = (t, e) => (r, i) => e(r, i, t);
127
+ let E = class extends P {
295
128
  constructor(t, e) {
296
129
  super(), this._logService = t, this._injector = e;
297
130
  }
298
131
  async execute(t) {
299
132
  this._logService.log("[UniscriptExecutionService]", "executing Uniscript...");
300
- const e = P.newInstance(this._injector), r = new Function("Univer", `(() => {${t}})()`);
133
+ const e = _e.newAPI(this._injector), r = new Function("univerAPI", `(() => {${t}})()`);
301
134
  try {
302
135
  return r(e), !0;
303
- } catch (n) {
304
- return this._logService.error(n), !1;
136
+ } catch (i) {
137
+ return this._logService.error(i), !1;
305
138
  }
306
139
  }
307
140
  };
308
- C = ot([
309
- N(0, ie),
310
- N(1, c(p))
311
- ], C);
312
- const it = "univer-script-editor-panel", st = "univer-script-editor-content", ct = "univer-script-editor-actions", f = {
313
- scriptEditorPanel: it,
314
- scriptEditorContent: st,
315
- scriptEditorActions: ct
141
+ E = Ie([
142
+ w(0, G),
143
+ w(1, f(I))
144
+ ], E);
145
+ const Ce = "univer-script-editor-panel", je = "univer-script-editor-content", $e = "univer-script-editor-actions", h = {
146
+ scriptEditorPanel: Ce,
147
+ scriptEditorContent: je,
148
+ scriptEditorActions: $e
316
149
  };
317
- function at() {
318
- const t = $(null), e = $(null), r = $(null), n = d(q), o = d(C), i = d(he), s = d(U), D = d(de);
319
- Pe(() => {
320
- const _ = e.current, a = t.current;
321
- let l = null, m = null;
322
- if (_ && a) {
150
+ function we() {
151
+ const t = O(null), e = O(null), r = O(null), i = d(M), n = d(E), o = d(te), s = d(b), C = d(re);
152
+ ue(() => {
153
+ const a = e.current, c = t.current;
154
+ let l = null, _ = null;
155
+ if (a && c) {
323
156
  s.requireVscodeEditor();
324
- const g = r.current = Ee.create(_, {
157
+ const m = r.current = fe.create(a, {
325
158
  value: "",
326
159
  language: "javascript"
327
160
  });
328
- m = new ResizeObserver(() => {
329
- let M = requestIdleCallback(() => {
330
- if (!M)
161
+ _ = new ResizeObserver(() => {
162
+ let j = requestIdleCallback(() => {
163
+ if (!j)
331
164
  return;
332
- const { height: Q, width: X } = a.getBoundingClientRect();
333
- g.layout({ width: X, height: Q }), M = void 0;
165
+ const { height: B, width: q } = c.getBoundingClientRect();
166
+ m.layout({ width: q, height: B }), j = void 0;
334
167
  });
335
- }), m.observe(a);
336
- let u;
337
- l = new se(), l.add(s.setEditorInstance(g)), l.add(
338
- g.onDidFocusEditorWidget(() => {
339
- u = i.forceEscape();
168
+ }), _.observe(c);
169
+ let p;
170
+ l = new J(), l.add(s.setEditorInstance(m)), l.add(
171
+ m.onDidFocusEditorWidget(() => {
172
+ p = o.forceEscape();
340
173
  })
341
174
  ), l.add(
342
- g.onDidBlurEditorWidget(() => {
343
- u == null || u.dispose(), u = void 0;
175
+ m.onDidBlurEditorWidget(() => {
176
+ p == null || p.dispose(), p = void 0;
344
177
  })
345
- ), l.add(H(() => u == null ? void 0 : u.dispose()));
178
+ ), l.add(T(() => p == null ? void 0 : p.dispose()));
346
179
  }
347
180
  return () => {
348
- m && a && m.unobserve(a), l == null || l.dispose();
181
+ _ && c && _.unobserve(c), l == null || l.dispose();
349
182
  };
350
183
  }, []);
351
- const Y = Ce(() => {
352
- var a;
353
- const _ = (a = r.current) == null ? void 0 : a.getModel();
354
- _ && o.execute(_.getValue()).then(() => {
355
- D.show({
356
- content: n.t("uniscript.message.success"),
357
- type: T.Success
184
+ const W = de(() => {
185
+ var c;
186
+ const a = (c = r.current) == null ? void 0 : c.getModel();
187
+ a && n.execute(a.getValue()).then(() => {
188
+ C.show({
189
+ content: i.t("uniscript.message.success"),
190
+ type: $.Success
358
191
  });
359
192
  }).catch(() => {
360
- D.show({
361
- content: n.t("uniscript.message.failed"),
362
- type: T.Error
193
+ C.show({
194
+ content: i.t("uniscript.message.failed"),
195
+ type: $.Error
363
196
  });
364
197
  });
365
- }, [o]);
366
- return /* @__PURE__ */ v.jsxs("div", { className: f.scriptEditorPanel, children: [
367
- /* @__PURE__ */ v.jsx("div", { className: f.scriptEditorContent, ref: t, children: /* @__PURE__ */ v.jsx("div", { className: f.scriptEditorContainer, ref: e }) }),
368
- /* @__PURE__ */ v.jsx("div", { className: f.scriptEditorActions, children: /* @__PURE__ */ v.jsx(Oe, { type: "primary", size: "small", onClick: Y, children: n.t("script-panel.panel.execute") }) })
198
+ }, [n]);
199
+ return /* @__PURE__ */ v.jsxs("div", { className: h.scriptEditorPanel, children: [
200
+ /* @__PURE__ */ v.jsx("div", { className: h.scriptEditorContent, ref: t, children: /* @__PURE__ */ v.jsx("div", { className: h.scriptEditorContainer, ref: e }) }),
201
+ /* @__PURE__ */ v.jsx("div", { className: h.scriptEditorActions, children: /* @__PURE__ */ v.jsx(ve, { type: "primary", size: "small", onClick: W, children: i.t("script-panel.panel.execute") }) })
369
202
  ] });
370
203
  }
371
- function lt(t) {
204
+ function Ue(t) {
372
205
  return {
373
- id: G.id,
206
+ id: A.id,
374
207
  title: "toggle-script-panel",
375
208
  tooltip: "script-panel.tooltip.menu-button",
376
209
  icon: "CodeSingle",
377
- type: ve.BUTTON,
378
- positions: [me.TOOLBAR_START],
379
- hidden$: ge(t, ce.SHEET)
210
+ type: ie.BUTTON,
211
+ positions: [ne.TOOLBAR_START],
212
+ hidden$: oe(t, Y.SHEET),
213
+ disabled$: me(t)
380
214
  };
381
215
  }
382
- var ut = Object.defineProperty, pt = Object.getOwnPropertyDescriptor, _t = (t, e, r, n) => {
383
- for (var o = n > 1 ? void 0 : n ? pt(e, r) : e, i = t.length - 1, s; i >= 0; i--)
384
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
385
- return n && o && ut(e, r, o), o;
386
- }, S = (t, e) => (r, n) => e(r, n, t);
387
- let w = class extends O {
388
- constructor(t, e, r, n) {
389
- super(), this._injector = t, this.disposeWithMe(e.addMenuItem(this._injector.invoke(lt))), this.disposeWithMe(n.register(z, at)), this.disposeWithMe(r.registerCommand(G));
216
+ var Re = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, Me = (t, e, r, i) => {
217
+ for (var n = i > 1 ? void 0 : i ? Te(e, r) : e, o = t.length - 1, s; o >= 0; o--)
218
+ (s = t[o]) && (n = (i ? s(e, r, n) : s(n)) || n);
219
+ return i && n && Re(e, r, n), n;
220
+ }, g = (t, e) => (r, i) => e(r, i, t);
221
+ let S = class extends P {
222
+ constructor(t, e, r, i) {
223
+ super(), this._injector = t, this.disposeWithMe(e.addMenuItem(this._injector.invoke(Ue))), this.disposeWithMe(i.register(N, we)), this.disposeWithMe(r.registerCommand(A));
390
224
  }
391
225
  };
392
- w = _t([
393
- ae(le.Steady, w),
394
- S(0, c(p)),
395
- S(1, Se),
396
- S(2, E),
397
- S(3, c(fe))
398
- ], w);
399
- var ht = Object.defineProperty, dt = Object.getOwnPropertyDescriptor, vt = (t, e, r, n) => {
400
- for (var o = n > 1 ? void 0 : n ? dt(e, r) : e, i = t.length - 1, s; i >= 0; i--)
401
- (s = t[i]) && (o = (n ? s(e, r, o) : s(o)) || o);
402
- return n && o && ht(e, r, o), o;
403
- }, L = (t, e) => (r, n) => e(r, n, t);
404
- const mt = "uniscript";
226
+ S = Me([
227
+ K(Q.Steady, S),
228
+ g(0, f(I)),
229
+ g(1, ce),
230
+ g(2, X),
231
+ g(3, f(se))
232
+ ], S);
233
+ var De = Object.defineProperty, Ne = Object.getOwnPropertyDescriptor, Ae = (t, e, r, i) => {
234
+ for (var n = i > 1 ? void 0 : i ? Ne(e, r) : e, o = t.length - 1, s; o >= 0; o--)
235
+ (s = t[o]) && (n = (i ? s(e, r, n) : s(n)) || n);
236
+ return i && n && De(e, r, n), n;
237
+ }, U = (t, e) => (r, i) => e(r, i, t);
238
+ const Fe = "uniscript";
405
239
  var y;
406
- let B = (y = class extends ue {
240
+ let R = (y = class extends Z {
407
241
  constructor(t, e, r) {
408
- super(mt), this._config = t, this._injector = e, this._localeService = r;
242
+ super(Fe), this._config = t, this._injector = e, this._localeService = r;
409
243
  }
410
244
  onStarting(t) {
411
245
  [
412
246
  // controllers
413
- [w],
247
+ [S],
414
248
  // services
415
- [U, { useFactory: () => t.createInstance(U, this._config) }],
416
- [V],
417
- [C]
249
+ [b, { useFactory: () => t.createInstance(b, this._config) }],
250
+ [D],
251
+ [E]
418
252
  ].forEach((r) => t.add(r)), this._localeService.load({
419
- zhCN: ke
253
+ zhCN: he
420
254
  });
421
255
  }
422
- }, h(y, "type", pe.Univer), y);
423
- B = vt([
424
- L(1, c(p)),
425
- L(2, c(q))
426
- ], B);
256
+ }, u(y, "type", k.Univer), y);
257
+ R = Ae([
258
+ U(1, f(I)),
259
+ U(2, f(M))
260
+ ], R);
427
261
  export {
428
- B as UniverUniscriptPlugin,
429
- jt as enUS,
430
- ke as zhCN
262
+ R as UniverUniscriptPlugin,
263
+ Qe as enUS,
264
+ he as zhCN
431
265
  };
@@ -18,7 +18,7 @@ import type { IDisposable } from '@wendellhu/redi';
18
18
  export declare class BatchCommandService implements ICommandService {
19
19
  beforeCommandExecuted(listener: CommandListener): IDisposable;
20
20
  registerCommand(command: ICommand<object, boolean>): IDisposable;
21
- registerAsMultipleCommand(command: ICommand<object, boolean>): IDisposable;
21
+ registerMultipleCommand(command: ICommand<object, boolean>): IDisposable;
22
22
  executeCommand<P extends object = object, R = boolean>(id: string, params?: P | undefined, options?: IExecutionOptions | undefined): Promise<R>;
23
23
  syncExecuteCommand<P extends object = object, R = boolean>(id: string, params?: P | undefined, options?: IExecutionOptions | undefined): R;
24
24
  onCommandExecuted(listener: CommandListener): IDisposable;
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings"),require("monaco-editor"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","react","@univerjs/design","@wendellhu/redi/react-bindings","monaco-editor","@univerjs/sheets"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.UniverUniscript={},a.UniverCore,a["@wendellhu/redi"],a.UniverUi,a.rxjs,a.React,a.UniverDesign,a["@wendellhu/redi/react-bindings"],a.monaco,a.UniverSheets))})(this,function(a,c,l,u,M,_,x,f,Y,v){"use strict";var Te=Object.defineProperty;var Me=(a,c,l)=>c in a?Te(a,c,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[c]=l;var S=(a,c,l)=>(Me(a,typeof c!="symbol"?c+"":c,l),l);var T;const Q={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}},uniscript:{message:{success:"Execution Success",failed:"Execution Failed"}}},W={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}},uniscript:{message:{success:"执行成功",failed:"执行失败"}}};class A extends c.Disposable{constructor(){super(...arguments);S(this,"_open$",new M.BehaviorSubject(!1));S(this,"open$",this._open$.pipe(M.distinctUntilChanged()))}get isOpen(){return this._open$.getValue()}dispose(){this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}}const F="ScriptPanel",N={type:c.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:t=>{const e=t.get(A),r=t.get(u.ISidebarService);return e.isOpen?(e.close(),r.close()):(e.open(),r.open({header:{title:"script-panel.title"},children:{label:F},width:600})),!0}};var L={exports:{}},w={};/**
1
+ (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@wendellhu/redi"),require("@univerjs/ui"),require("rxjs"),require("react"),require("@univerjs/design"),require("@wendellhu/redi/react-bindings"),require("monaco-editor"),require("@univerjs/facade"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@wendellhu/redi","@univerjs/ui","rxjs","react","@univerjs/design","@wendellhu/redi/react-bindings","monaco-editor","@univerjs/facade","@univerjs/sheets"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.UniverUniscript={},o.UniverCore,o["@wendellhu/redi"],o.UniverUi,o.rxjs,o.React,o.UniverDesign,o["@wendellhu/redi/react-bindings"],o.monaco,o.UniverFacade,o.UniverSheets))})(this,function(o,s,l,u,w,f,O,h,q,W,z){"use strict";var ae=Object.defineProperty;var de=(o,s,l)=>s in o?ae(o,s,{enumerable:!0,configurable:!0,writable:!0,value:l}):o[s]=l;var m=(o,s,l)=>(de(o,typeof s!="symbol"?s+"":s,l),l);var b;const V={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}},uniscript:{message:{success:"Execution Success",failed:"Execution Failed"}}},C={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}},uniscript:{message:{success:"执行成功",failed:"执行失败"}}};class D extends s.Disposable{constructor(){super(...arguments);m(this,"_open$",new w.BehaviorSubject(!1));m(this,"open$",this._open$.pipe(w.distinctUntilChanged()))}get isOpen(){return this._open$.getValue()}dispose(){this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}}const T="ScriptPanel",R={type:s.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:n=>{const e=n.get(D),i=n.get(u.ISidebarService);return e.isOpen?(e.close(),i.close()):(e.open(),i.open({header:{title:"script-panel.title"},children:{label:T},width:600})),!0}};var M={exports:{}},g={};/**
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 X=_,Z=Symbol.for("react.element"),ee=Symbol.for("react.fragment"),te=Object.prototype.hasOwnProperty,ne=X.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,re={key:!0,ref:!0,__self:!0,__source:!0};function q(t,e,r){var n,i={},s=null,o=null;r!==void 0&&(s=""+r),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(o=e.ref);for(n in e)te.call(e,n)&&!re.hasOwnProperty(n)&&(i[n]=e[n]);if(t&&t.defaultProps)for(n in e=t.defaultProps,e)i[n]===void 0&&(i[n]=e[n]);return{$$typeof:Z,type:t,key:s,ref:o,props:i,_owner:ne.current}}w.Fragment=ee,w.jsx=q,w.jsxs=q,L.exports=w;var g=L.exports;class R extends c.Disposable{constructor(r){super();S(this,"_editorInstance",null);this._config=r}setEditorInstance(r){return this._editorInstance=r,c.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var ie=Object.defineProperty,se=Object.getOwnPropertyDescriptor,oe=(t,e,r,n)=>{for(var i=n>1?void 0:n?se(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ie(e,r,i),i},H=(t,e)=>(r,n)=>e(r,n,t);let I=class{constructor(t,e,r,n,i){this._workbook=t,this._worksheet=e,this._range=r,this._injector=n,this._commandService=i}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getWidth(){return this._range.endColumn-this._range.startColumn+1}getHeight(){return this._range.endRow-this._range.startRow+1}getValue(){var t;return((t=this._worksheet.getCell(this._range.startRow,this._range.startColumn))==null?void 0:t.v)??null}setBackgroundColor(t){this._commandService.executeCommand(v.SetStyleCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),range:this._range,style:{type:"bg",value:{rgb:t}}})}};I=oe([H(3,l.Inject(l.Injector)),H(4,c.ICommandService)],I);var ce=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,le=(t,e,r,n)=>{for(var i=n>1?void 0:n?ae(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ce(e,r,i),i},ue=(t,e)=>(r,n)=>e(r,n,t);let D=class{constructor(t,e,r,n){this._workbook=t,this._worksheet=e,this._selections=r,this._injector=n}getActiveRange(){const t=this._selections.find(e=>!!e.primary);return t?this._injector.createInstance(I,this._workbook,this._worksheet,t.range):null}};D=le([ue(3,l.Inject(l.Injector))],D);var pe=Object.defineProperty,de=Object.getOwnPropertyDescriptor,he=(t,e,r,n)=>{for(var i=n>1?void 0:n?de(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&pe(e,r,i),i},$=(t,e)=>(r,n)=>e(r,n,t);let j=class{constructor(t,e,r,n,i){this._workbook=t,this._worksheet=e,this._injector=r,this._selectionManagerService=n,this._commandService=i}getSelection(){const t=this._selectionManagerService.getSelections();return t?this._injector.createInstance(D,this._workbook,this._worksheet,t):null}getRange(t,e,r,n){const i={startRow:t,endRow:t+(r??1)-1,startColumn:e,endColumn:e+(n??1)-1};return this._injector.createInstance(I,this._workbook,this._worksheet,i)}setRowHeights(t,e,r){this._commandService.syncExecuteCommand(v.SetWorksheetRowHeightMutation.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[{startRow:t,endRow:t+e-1,startColumn:0,endColumn:this._worksheet.getColumnCount()-1}],rowHeight:r})}setColumnWidths(t,e,r){this._commandService.syncExecuteCommand(v.SetWorksheetColWidthMutation.id,{unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[{startColumn:t,endColumn:t+e-1,startRow:0,endRow:this._worksheet.getRowCount()-1}],colWidth:r})}};j=he([$(2,l.Inject(l.Injector)),$(3,l.Inject(v.SelectionManagerService)),$(4,c.ICommandService)],j);var _e=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,fe=(t,e,r,n)=>{for(var i=n>1?void 0:n?ve(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&_e(e,r,i),i},z=(t,e)=>(r,n)=>e(r,n,t);let k=class{constructor(t,e,r){this._workbook=t,this._injector=e,this._commandService=r}getActiveSheet(){const t=this._workbook.getActiveSheet();return t?this._injector.createInstance(j,this._workbook,t):null}create(t,e,r){const n=c.Tools.deepClone(c.DEFAULT_WORKSHEET);return n.rowCount=e,n.columnCount=r,n.name=t,n.id=t.toLowerCase().replace(/ /g,"-"),this._commandService.syncExecuteCommand(v.InsertSheetCommand.id,{unitId:this._workbook.getUnitId(),index:this._workbook.getSheets().length,sheet:n}),this._commandService.syncExecuteCommand(v.SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:this._workbook.getSheets()[this._workbook.getSheets().length-1].getSheetId()}),this._injector.createInstance(j,this._workbook,this._workbook.getActiveSheet())}};k=fe([z(1,l.Inject(l.Injector)),z(2,c.ICommandService)],k);var ge=Object.defineProperty,me=Object.getOwnPropertyDescriptor,Se=(t,e,r,n)=>{for(var i=n>1?void 0:n?me(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ge(e,r,i),i},V=(t,e)=>(r,n)=>e(r,n,t);let b=class{constructor(t,e){this._injector=t,this._univerInstanceService=e}static newInstance(t){return t.createInstance(b)}getCurrentSheet(){const t=this._univerInstanceService.getCurrentUniverSheetInstance();return t?this._injector.createInstance(k,t):null}};b=Se([V(0,l.Inject(l.Injector)),V(1,c.IUniverInstanceService)],b);var we=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,je=(t,e,r,n)=>{for(var i=n>1?void 0:n?Ie(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&we(e,r,i),i},B=(t,e)=>(r,n)=>e(r,n,t);let C=class extends c.Disposable{constructor(t,e){super(),this._logService=t,this._injector=e}async execute(t){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=b.newInstance(this._injector),r=new Function("Univer",`(() => {${t}})()`);try{return r(e),!0}catch(n){return this._logService.error(n),!1}}};C=je([B(0,c.ILogService),B(1,l.Inject(l.Injector))],C);const P={scriptEditorPanel:"univer-script-editor-panel",scriptEditorContent:"univer-script-editor-content",scriptEditorActions:"univer-script-editor-actions"};function be(){const t=_.useRef(null),e=_.useRef(null),r=_.useRef(null),n=f.useDependency(c.LocaleService),i=f.useDependency(C),s=f.useDependency(u.IShortcutService),o=f.useDependency(R),J=f.useDependency(u.IMessageService);_.useEffect(()=>{const m=e.current,p=t.current;let d=null,y=null;if(m&&p){o.requireVscodeEditor();const U=r.current=Y.editor.create(m,{value:"",language:"javascript"});y=new ResizeObserver(()=>{let K=requestIdleCallback(()=>{if(!K)return;const{height:$e,width:ke}=p.getBoundingClientRect();U.layout({width:ke,height:$e}),K=void 0})}),y.observe(p);let h;d=new c.DisposableCollection,d.add(o.setEditorInstance(U)),d.add(U.onDidFocusEditorWidget(()=>{h=s.forceEscape()})),d.add(U.onDidBlurEditorWidget(()=>{h==null||h.dispose(),h=void 0})),d.add(c.toDisposable(()=>h==null?void 0:h.dispose()))}return()=>{y&&p&&y.unobserve(p),d==null||d.dispose()}},[]);const De=_.useCallback(()=>{var p;const m=(p=r.current)==null?void 0:p.getModel();m&&i.execute(m.getValue()).then(()=>{J.show({content:n.t("uniscript.message.success"),type:x.MessageType.Success})}).catch(()=>{J.show({content:n.t("uniscript.message.failed"),type:x.MessageType.Error})})},[i]);return g.jsxs("div",{className:P.scriptEditorPanel,children:[g.jsx("div",{className:P.scriptEditorContent,ref:t,children:g.jsx("div",{className:P.scriptEditorContainer,ref:e})}),g.jsx("div",{className:P.scriptEditorActions,children:g.jsx(x.Button,{type:"primary",size:"small",onClick:De,children:n.t("script-panel.panel.execute")})})]})}function Ce(t){return{id:N.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(t,c.UniverInstanceType.SHEET)}}var Pe=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,Ee=(t,e,r,n)=>{for(var i=n>1?void 0:n?Oe(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Pe(e,r,i),i},O=(t,e)=>(r,n)=>e(r,n,t);let E=class extends c.Disposable{constructor(t,e,r,n){super(),this._injector=t,this.disposeWithMe(e.addMenuItem(this._injector.invoke(Ce))),this.disposeWithMe(n.register(F,be)),this.disposeWithMe(r.registerCommand(N))}};E=Ee([c.OnLifecycle(c.LifecycleStages.Steady,E),O(0,l.Inject(l.Injector)),O(1,u.IMenuService),O(2,c.ICommandService),O(3,l.Inject(u.ComponentManager))],E);var ye=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,xe=(t,e,r,n)=>{for(var i=n>1?void 0:n?Ue(e,r):e,s=t.length-1,o;s>=0;s--)(o=t[s])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ye(e,r,i),i},G=(t,e)=>(r,n)=>e(r,n,t);const Re="uniscript";a.UniverUniscriptPlugin=(T=class extends c.Plugin{constructor(e,r,n){super(Re),this._config=e,this._injector=r,this._localeService=n}onStarting(e){[[E],[R,{useFactory:()=>e.createInstance(R,this._config)}],[A],[C]].forEach(n=>e.add(n)),this._localeService.load({zhCN:W})}},S(T,"type",c.PluginType.Univer),T),a.UniverUniscriptPlugin=xe([G(1,l.Inject(l.Injector)),G(2,l.Inject(c.LocaleService))],a.UniverUniscriptPlugin),a.enUS=Q,a.zhCN=W,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
9
+ */var B=f,H=Symbol.for("react.element"),G=Symbol.for("react.fragment"),J=Object.prototype.hasOwnProperty,Y=B.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,K={key:!0,ref:!0,__self:!0,__source:!0};function N(n,e,i){var t,r={},c=null,p=null;i!==void 0&&(c=""+i),e.key!==void 0&&(c=""+e.key),e.ref!==void 0&&(p=e.ref);for(t in e)J.call(e,t)&&!K.hasOwnProperty(t)&&(r[t]=e[t]);if(n&&n.defaultProps)for(t in e=n.defaultProps,e)r[t]===void 0&&(r[t]=e[t]);return{$$typeof:H,type:n,key:c,ref:p,props:r,_owner:Y.current}}g.Fragment=G,g.jsx=N,g.jsxs=N,M.exports=g;var _=M.exports;class x extends s.Disposable{constructor(i){super();m(this,"_editorInstance",null);this._config=i}setEditorInstance(i){return this._editorInstance=i,s.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var Q=Object.defineProperty,X=Object.getOwnPropertyDescriptor,Z=(n,e,i,t)=>{for(var r=t>1?void 0:t?X(e,i):e,c=n.length-1,p;c>=0;c--)(p=n[c])&&(r=(t?p(e,i,r):p(r))||r);return t&&r&&Q(e,i,r),r},$=(n,e)=>(i,t)=>e(i,t,n);let E=class extends s.Disposable{constructor(n,e){super(),this._logService=n,this._injector=e}async execute(n){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=W.FUniver.newAPI(this._injector),i=new Function("univerAPI",`(() => {${n}})()`);try{return i(e),!0}catch(t){return this._logService.error(t),!1}}};E=Z([$(0,s.ILogService),$(1,l.Inject(l.Injector))],E);const j={scriptEditorPanel:"univer-script-editor-panel",scriptEditorContent:"univer-script-editor-content",scriptEditorActions:"univer-script-editor-actions"};function k(){const n=f.useRef(null),e=f.useRef(null),i=f.useRef(null),t=h.useDependency(s.LocaleService),r=h.useDependency(E),c=h.useDependency(u.IShortcutService),p=h.useDependency(x),F=h.useDependency(u.IMessageService);f.useEffect(()=>{const S=e.current,a=n.current;let d=null,U=null;if(S&&a){p.requireVscodeEditor();const I=i.current=q.editor.create(S,{value:"",language:"javascript"});U=new ResizeObserver(()=>{let L=requestIdleCallback(()=>{if(!L)return;const{height:le,width:ue}=a.getBoundingClientRect();I.layout({width:ue,height:le}),L=void 0})}),U.observe(a);let v;d=new s.DisposableCollection,d.add(p.setEditorInstance(I)),d.add(I.onDidFocusEditorWidget(()=>{v=c.forceEscape()})),d.add(I.onDidBlurEditorWidget(()=>{v==null||v.dispose(),v=void 0})),d.add(s.toDisposable(()=>v==null?void 0:v.dispose()))}return()=>{U&&a&&U.unobserve(a),d==null||d.dispose()}},[]);const pe=f.useCallback(()=>{var a;const S=(a=i.current)==null?void 0:a.getModel();S&&r.execute(S.getValue()).then(()=>{F.show({content:t.t("uniscript.message.success"),type:O.MessageType.Success})}).catch(()=>{F.show({content:t.t("uniscript.message.failed"),type:O.MessageType.Error})})},[r]);return _.jsxs("div",{className:j.scriptEditorPanel,children:[_.jsx("div",{className:j.scriptEditorContent,ref:n,children:_.jsx("div",{className:j.scriptEditorContainer,ref:e})}),_.jsx("div",{className:j.scriptEditorActions,children:_.jsx(O.Button,{type:"primary",size:"small",onClick:pe,children:t.t("script-panel.panel.execute")})})]})}function ee(n){return{id:R.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START],hidden$:u.getMenuHiddenObservable(n,s.UniverInstanceType.SHEET),disabled$:z.getCurrentSheetDisabled$(n)}}var te=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,ie=(n,e,i,t)=>{for(var r=t>1?void 0:t?ne(e,i):e,c=n.length-1,p;c>=0;c--)(p=n[c])&&(r=(t?p(e,i,r):p(r))||r);return t&&r&&te(e,i,r),r},y=(n,e)=>(i,t)=>e(i,t,n);let P=class extends s.Disposable{constructor(n,e,i,t){super(),this._injector=n,this.disposeWithMe(e.addMenuItem(this._injector.invoke(ee))),this.disposeWithMe(t.register(T,k)),this.disposeWithMe(i.registerCommand(R))}};P=ie([s.OnLifecycle(s.LifecycleStages.Steady,P),y(0,l.Inject(l.Injector)),y(1,u.IMenuService),y(2,s.ICommandService),y(3,l.Inject(u.ComponentManager))],P);var re=Object.defineProperty,se=Object.getOwnPropertyDescriptor,oe=(n,e,i,t)=>{for(var r=t>1?void 0:t?se(e,i):e,c=n.length-1,p;c>=0;c--)(p=n[c])&&(r=(t?p(e,i,r):p(r))||r);return t&&r&&re(e,i,r),r},A=(n,e)=>(i,t)=>e(i,t,n);const ce="uniscript";o.UniverUniscriptPlugin=(b=class extends s.Plugin{constructor(e,i,t){super(ce),this._config=e,this._injector=i,this._localeService=t}onStarting(e){[[P],[x,{useFactory:()=>e.createInstance(x,this._config)}],[D],[E]].forEach(t=>e.add(t)),this._localeService.load({zhCN:C})}},m(b,"type",s.PluginType.Univer),b),o.UniverUniscriptPlugin=oe([A(1,l.Inject(l.Injector)),A(2,l.Inject(s.LocaleService))],o.UniverUniscriptPlugin),o.enUS=V,o.zhCN=C,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/uniscript",
3
- "version": "0.1.0-beta.1",
3
+ "version": "0.1.0-beta.2",
4
4
  "description": "UI component library for building exceptional Univer.",
5
5
  "keywords": [],
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -35,36 +35,38 @@
35
35
  ],
36
36
  "private": false,
37
37
  "dependencies": {
38
- "@wendellhu/redi": "^0.12.12",
38
+ "@wendellhu/redi": "^0.12.13",
39
39
  "monaco-editor": "0.45.0",
40
40
  "rxjs": "^7.8.1",
41
- "@univerjs/core": "0.1.0-beta.1",
42
- "@univerjs/design": "0.1.0-beta.1",
43
- "@univerjs/sheets-ui": "0.1.0-beta.1",
44
- "@univerjs/ui": "0.1.0-beta.1",
45
- "@univerjs/sheets": "0.1.0-beta.1"
41
+ "@univerjs/design": "0.1.0-beta.2",
42
+ "@univerjs/facade": "0.1.0-beta.2",
43
+ "@univerjs/core": "0.1.0-beta.2",
44
+ "@univerjs/sheets": "0.1.0-beta.2",
45
+ "@univerjs/ui": "0.1.0-beta.2",
46
+ "@univerjs/sheets-ui": "0.1.0-beta.2"
46
47
  },
47
48
  "devDependencies": {
48
- "@types/react": "^18.2.45",
49
+ "@types/react": "^18.2.46",
49
50
  "@vitejs/plugin-react": "^4.2.1",
50
- "@vitest/coverage-istanbul": "^1.1.0",
51
+ "@vitest/coverage-istanbul": "^1.1.1",
51
52
  "less": "^4.2.0",
52
53
  "typescript": "^5.3.3",
53
54
  "vite": "^5.0.10",
54
- "vite-plugin-dts": "^3.6.4",
55
+ "vite-plugin-dts": "^3.7.0",
55
56
  "vite-plugin-externals": "^0.6.2",
56
- "vitest": "^1.1.0"
57
+ "vitest": "^1.1.1"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "@wendellhu/redi": ">=0.12.12",
60
61
  "monaco-editor": ">=0.44.0",
61
62
  "react": ">=16.9.0",
62
63
  "rxjs": ">=7.0.0",
63
- "@univerjs/core": "0.1.0-beta.1",
64
- "@univerjs/design": "0.1.0-beta.1",
65
- "@univerjs/sheets-ui": "0.1.0-beta.1",
66
- "@univerjs/ui": "0.1.0-beta.1",
67
- "@univerjs/sheets": "0.1.0-beta.1"
64
+ "@univerjs/core": "0.1.0-beta.2",
65
+ "@univerjs/design": "0.1.0-beta.2",
66
+ "@univerjs/facade": "0.1.0-beta.2",
67
+ "@univerjs/sheets": "0.1.0-beta.2",
68
+ "@univerjs/sheets-ui": "0.1.0-beta.2",
69
+ "@univerjs/ui": "0.1.0-beta.2"
68
70
  },
69
71
  "scripts": {
70
72
  "test": "vitest run",
@@ -1,25 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
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
- import { IUniverInstanceService } from '@univerjs/core';
17
- import { Injector } from '@wendellhu/redi';
18
- import { FWorkbook } from './sheet/f-workbook';
19
- export declare class FUniver {
20
- private readonly _injector;
21
- private readonly _univerInstanceService;
22
- static newInstance(injector: Injector): FUniver;
23
- constructor(_injector: Injector, _univerInstanceService: IUniverInstanceService);
24
- getCurrentSheet(): FWorkbook | null;
25
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
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
- import type { ICellV, IRange, Workbook, Worksheet } from '@univerjs/core';
17
- import { ICommandService } from '@univerjs/core';
18
- import { Injector } from '@wendellhu/redi';
19
- export declare class FRange {
20
- private readonly _workbook;
21
- private readonly _worksheet;
22
- private readonly _range;
23
- private readonly _injector;
24
- private readonly _commandService;
25
- constructor(_workbook: Workbook, _worksheet: Worksheet, _range: IRange, _injector: Injector, _commandService: ICommandService);
26
- getRow(): number;
27
- getColumn(): number;
28
- getWidth(): number;
29
- getHeight(): number;
30
- getValue(): ICellV | null;
31
- setBackgroundColor(color: string): void;
32
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
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
- import type { Workbook, Worksheet } from '@univerjs/core';
17
- import type { ISelectionWithStyle } from '@univerjs/sheets';
18
- import { Injector } from '@wendellhu/redi';
19
- import { FRange } from './f-range';
20
- export declare class FSelection {
21
- private readonly _workbook;
22
- private readonly _worksheet;
23
- private readonly _selections;
24
- private readonly _injector;
25
- constructor(_workbook: Workbook, _worksheet: Worksheet, _selections: Readonly<ISelectionWithStyle[]>, _injector: Injector);
26
- getActiveRange(): FRange | null;
27
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
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
- import { ICommandService, type Workbook } from '@univerjs/core';
17
- import { Injector } from '@wendellhu/redi';
18
- import { FWorksheet } from './f-worksheet';
19
- export declare class FWorkbook {
20
- private readonly _workbook;
21
- private readonly _injector;
22
- private readonly _commandService;
23
- constructor(_workbook: Workbook, _injector: Injector, _commandService: ICommandService);
24
- getActiveSheet(): FWorksheet | null;
25
- create(name: string, rows: number, column: number): FWorksheet;
26
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * Copyright 2023-present DreamNum Inc.
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
- import { ICommandService, type Workbook, type Worksheet } from '@univerjs/core';
17
- import { SelectionManagerService } from '@univerjs/sheets';
18
- import { Injector } from '@wendellhu/redi';
19
- import { FRange } from './f-range';
20
- import { FSelection } from './f-selection';
21
- export declare class FWorksheet {
22
- private readonly _workbook;
23
- private readonly _worksheet;
24
- private readonly _injector;
25
- private readonly _selectionManagerService;
26
- private readonly _commandService;
27
- constructor(_workbook: Workbook, _worksheet: Worksheet, _injector: Injector, _selectionManagerService: SelectionManagerService, _commandService: ICommandService);
28
- getSelection(): FSelection | null;
29
- getRange(row: number, col: number, height?: number, width?: number): FRange | null;
30
- setRowHeights(startRow: number, numRows: number, height: number): void;
31
- setColumnWidths(startColumn: number, numColumns: number, width: number): void;
32
- }