@univerjs/uniscript 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -14,11 +14,11 @@
14
14
  Users can write business logic in the code editor to meet more flexible business requirements. For instance, as shown in the illustration, users can write a Uniscript to read identity card numbers from a selected area and validate their legality, and mark the background of invalid identity card numbers with red.
15
15
 
16
16
  :::caution
17
- The Uniscript is currently in the experimental stage, and it is not recommended to use it in production environments. You can refer to the [Roadmap](https://univer.ai/en-us/guides/roadmap/) to understand the iteration plan of Uniscript.
17
+ The Uniscript is currently in the experimental stage, and it is not recommended to use it in production environments. You can refer to the [Roadmap](https://univer.ai/guides/introduction/roadmap/) to understand the iteration plan of Uniscript.
18
18
  :::
19
19
 
20
20
  :::tip
21
- Indeed, Uniscript's Domain-Specific Language (DSL) is a set of Facade APIs that encapsulate the internal implementation details of Univer. This API is defined [here](https://univer.ai/en-us/guides/facade/).
21
+ Indeed, Uniscript's Domain-Specific Language (DSL) is a set of Facade APIs that encapsulate the internal implementation details of Univer. This API is defined [here](https://univer.ai/guides/facade/).
22
22
  :::
23
23
 
24
24
  ## Usage
package/lib/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var W=Object.defineProperty;var z=(n,e,t)=>e in n?W(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var f=(n,e,t)=>(z(n,typeof e!="symbol"?e+"":e,t),t);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"),O=require("@univerjs/design"),h=require("@wendellhu/redi/react-bindings"),V=require("monaco-editor"),G=require("@univerjs/facade"),J={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}},uniscript:{message:{success:"Execution Success",failed:"Execution Failed"}}},Y=J,H={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}},uniscript:{message:{success:"执行成功",failed:"执行失败"}}},R=H;class M 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 T="ScriptPanel",q={type:c.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:n=>{const e=n.get(M),t=n.get(d.ISidebarService);return e.isOpen?(e.close(),t.close()):(e.open(),t.open({header:{title:"script-panel.title"},children:{label:T},width:600})),!0}};var N={exports:{}},I={};/**
1
+ "use strict";var F=Object.defineProperty;var B=(r,e,t)=>e in r?F(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var f=(r,e,t)=>(B(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),a=require("@wendellhu/redi"),u=require("@univerjs/ui"),C=require("rxjs"),d=require("react"),O=require("@univerjs/design"),v=require("@wendellhu/redi/react-bindings"),W=require("monaco-editor"),z=require("@univerjs/facade"),V={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"Toggle Uniscript Panel"},panel:{execute:"Execute Script"}},uniscript:{message:{success:"Execution Success",failed:"Execution Failed"}}},G=V,J={"script-panel":{title:"Uniscript",tooltip:{"menu-button":"打开收起 Uniscript 面板"},panel:{execute:"执行 Uniscript"}},uniscript:{message:{success:"执行成功",failed:"执行失败"}}},D=J;class R extends o.Disposable{constructor(){super(...arguments);f(this,"_open$",new C.BehaviorSubject(!1));f(this,"open$",this._open$.pipe(C.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",T={type:o.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:r=>{const e=r.get(R),t=r.get(u.ISidebarService);return e.isOpen?(e.close(),t.close()):(e.open(),t.open({header:{title:"script-panel.title"},children:{label:M},width:600})),!0}};var q={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 K=v,Q=Symbol.for("react.element"),X=Symbol.for("react.fragment"),Z=Object.prototype.hasOwnProperty,k=K.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,ee={key:!0,ref:!0,__self:!0,__source:!0};function A(n,e,t){var r,i={},s=null,o=null;t!==void 0&&(s=""+t),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(o=e.ref);for(r in e)Z.call(e,r)&&!ee.hasOwnProperty(r)&&(i[r]=e[r]);if(n&&n.defaultProps)for(r in e=n.defaultProps,e)i[r]===void 0&&(i[r]=e[r]);return{$$typeof:Q,type:n,key:s,ref:o,props:i,_owner:k.current}}I.Fragment=X;I.jsx=A;I.jsxs=A;N.exports=I;var g=N.exports;class b extends c.Disposable{constructor(t){super();f(this,"_editorInstance",null);this._config=t}setEditorInstance(t){return this._editorInstance=t,c.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var te=Object.defineProperty,re=Object.getOwnPropertyDescriptor,ne=(n,e,t,r)=>{for(var i=r>1?void 0:r?re(e,t):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&te(e,t,i),i},w=(n,e)=>(t,r)=>e(t,r,n);let x=class extends c.Disposable{constructor(n,e){super(),this._logService=n,this._injector=e}async execute(n){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=G.FUniver.newAPI(this._injector),t=new Function("univerAPI",`(() => {${n}})()`);try{return t(e),!0}catch(r){return this._logService.error(r),!1}}};x=ne([w(0,c.ILogService),w(1,u.Inject(u.Injector))],x);const ie="univer-script-editor-panel",se="univer-script-editor-content",oe="univer-script-editor-actions",E={scriptEditorPanel:ie,scriptEditorContent:se,scriptEditorActions:oe};function ce(){const n=v.useRef(null),e=v.useRef(null),t=v.useRef(null),r=h.useDependency(c.LocaleService),i=h.useDependency(x),s=h.useDependency(d.IShortcutService),o=h.useDependency(b),U=h.useDependency(d.IMessageService);v.useEffect(()=>{const _=e.current,l=n.current;let p=null,S=null;if(_&&l){o.requireVscodeEditor();const m=t.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=t.current)==null?void 0:l.getModel();_&&i.execute(_.getValue()).then(()=>{U.show({content:r.t("uniscript.message.success"),type:O.MessageType.Success})}).catch(()=>{U.show({content:r.t("uniscript.message.failed"),type:O.MessageType.Error})})},[i]);return g.jsxs("div",{className:E.scriptEditorPanel,children:[g.jsx("div",{className:E.scriptEditorContent,ref:n,children:g.jsx("div",{className:E.scriptEditorContainer,ref:e})}),g.jsx("div",{className:E.scriptEditorActions,children:g.jsx(O.Button,{type:"primary",size:"small",onClick:L,children:r.t("script-panel.panel.execute")})})]})}function le(n){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]}}var pe=Object.defineProperty,ae=Object.getOwnPropertyDescriptor,ue=(n,e,t,r)=>{for(var i=r>1?void 0:r?ae(e,t):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&pe(e,t,i),i},P=(n,e)=>(t,r)=>e(t,r,n);let y=class extends c.Disposable{constructor(n,e,t,r){super(),this._injector=n,this.disposeWithMe(e.addMenuItem(this._injector.invoke(le))),this.disposeWithMe(r.register(T,ce)),this.disposeWithMe(t.registerCommand(q))}};y=ue([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 de=Object.defineProperty,ve=Object.getOwnPropertyDescriptor,_e=(n,e,t,r)=>{for(var i=r>1?void 0:r?ve(e,t):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&de(e,t,i),i},D=(n,e)=>(t,r)=>e(t,r,n);const fe="uniscript";var j;exports.UniverUniscriptPlugin=(j=class extends c.Plugin{constructor(e,t,r){super(fe),this._config=e,this._injector=t,this._localeService=r}onStarting(e){[[y],[b,{useFactory:()=>e.createInstance(b,this._config)}],[M],[x]].forEach(r=>e.add(r)),this._localeService.load({zhCN:R})}},f(j,"type",c.PluginType.Univer),j);exports.UniverUniscriptPlugin=_e([D(1,u.Inject(u.Injector)),D(2,u.Inject(c.LocaleService))],exports.UniverUniscriptPlugin);exports.enUS=Y;exports.zhCN=R;
9
+ */var Y=d,H=Symbol.for("react.element"),K=Symbol.for("react.fragment"),Q=Object.prototype.hasOwnProperty,X=Y.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function N(r,e,t){var n,i={},s=null,c=null;t!==void 0&&(s=""+t),e.key!==void 0&&(s=""+e.key),e.ref!==void 0&&(c=e.ref);for(n in e)Q.call(e,n)&&!Z.hasOwnProperty(n)&&(i[n]=e[n]);if(r&&r.defaultProps)for(n in e=r.defaultProps,e)i[n]===void 0&&(i[n]=e[n]);return{$$typeof:H,type:r,key:s,ref:c,props:i,_owner:X.current}}x.Fragment=K;x.jsx=N;x.jsxs=N;q.exports=x;var h=q.exports;class j extends o.Disposable{constructor(t){super();f(this,"_editorInstance",null);this._config=t}setEditorInstance(t){return this._editorInstance=t,o.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var k=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(r,e,t,n)=>{for(var i=n>1?void 0:n?ee(e,t):e,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=(n?c(e,t,i):c(i))||i);return n&&i&&k(e,t,i),i},$=(r,e)=>(t,n)=>e(t,n,r);let y=class extends o.Disposable{constructor(r,e){super(),this._logService=r,this._injector=e}async execute(r){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=z.FUniver.newAPI(this._injector),t=new Function("univerAPI",`(() => {${r}})()`);try{return t(e),!0}catch(n){return this._logService.error(n),!1}}};y=te([$(0,o.ILogService),$(1,a.Inject(a.Injector))],y);const ne="univer-script-editor-panel",re="univer-script-editor-content",ie="univer-script-editor-actions",m={scriptEditorPanel:ne,scriptEditorContent:re,scriptEditorActions:ie};function se(){const r=d.useRef(null),e=d.useRef(null),t=d.useRef(null),n=v.useDependency(o.LocaleService),i=v.useDependency(u.IShortcutService),s=v.useDependency(j);d.useEffect(()=>{const b=e.current,_=r.current;let l=null,g=null;if(b&&_){s.requireVscodeEditor();const S=t.current=W.editor.create(b,{value:"",language:"javascript"});g=new ResizeObserver(()=>{let U=requestIdleCallback(()=>{if(!U)return;const{height:L,width:A}=_.getBoundingClientRect();S.layout({width:A,height:L}),U=void 0})}),g.observe(_);let p;l=new o.DisposableCollection,l.add(s.setEditorInstance(S)),l.add(S.onDidFocusEditorWidget(()=>{p=i.forceEscape()})),l.add(S.onDidBlurEditorWidget(()=>{p==null||p.dispose(),p=void 0})),l.add(o.toDisposable(()=>p==null?void 0:p.dispose()))}return()=>{g&&_&&g.unobserve(_),l==null||l.dispose()}},[s,i]);const c=oe(t);return h.jsxs("div",{className:m.scriptEditorPanel,children:[h.jsx("div",{className:m.scriptEditorContent,ref:r,children:h.jsx("div",{className:m.scriptEditorContainer,ref:e})}),h.jsx("div",{className:m.scriptEditorActions,children:h.jsx(O.Button,{type:"primary",size:"small",onClick:c,children:n.t("script-panel.panel.execute")})})]})}function oe(r){const e=v.useDependency(y),t=v.useDependency(u.IMessageService),n=v.useDependency(o.LocaleService);return d.useCallback(()=>{var s;const i=(s=r.current)==null?void 0:s.getModel();i&&e.execute(i.getValue()).then(()=>{t.show({content:n.t("uniscript.message.success"),type:O.MessageType.Success})}).catch(()=>{t.show({content:n.t("uniscript.message.failed"),type:O.MessageType.Error})})},[n,t,r,e])}function ce(r){return{id:T.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:u.MenuItemType.BUTTON,positions:[u.MenuPosition.TOOLBAR_START]}}var le=Object.defineProperty,pe=Object.getOwnPropertyDescriptor,ae=(r,e,t,n)=>{for(var i=n>1?void 0:n?pe(e,t):e,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=(n?c(e,t,i):c(i))||i);return n&&i&&le(e,t,i),i},E=(r,e)=>(t,n)=>e(t,n,r);let P=class extends o.Disposable{constructor(r,e,t,n){super(),this._injector=r,this.disposeWithMe(e.addMenuItem(this._injector.invoke(ce))),this.disposeWithMe(n.register(M,se)),this.disposeWithMe(t.registerCommand(T))}};P=ae([o.OnLifecycle(o.LifecycleStages.Steady,P),E(0,a.Inject(a.Injector)),E(1,u.IMenuService),E(2,o.ICommandService),E(3,a.Inject(u.ComponentManager))],P);var ue=Object.defineProperty,de=Object.getOwnPropertyDescriptor,ve=(r,e,t,n)=>{for(var i=n>1?void 0:n?de(e,t):e,s=r.length-1,c;s>=0;s--)(c=r[s])&&(i=(n?c(e,t,i):c(i))||i);return n&&i&&ue(e,t,i),i},w=(r,e)=>(t,n)=>e(t,n,r);const _e="uniscript";var I;exports.UniverUniscriptPlugin=(I=class extends o.Plugin{constructor(e,t,n){super(_e),this._config=e,this._injector=t,this._localeService=n}onStarting(e){[[P],[j,{useFactory:()=>e.createInstance(j,this._config)}],[R],[y]].forEach(n=>e.add(n)),this._localeService.load({zhCN:D})}},f(I,"type",o.PluginType.Univer),I);exports.UniverUniscriptPlugin=ve([w(1,a.Inject(a.Injector)),w(2,a.Inject(o.LocaleService))],exports.UniverUniscriptPlugin);exports.enUS=G;exports.zhCN=D;
package/lib/es/index.js CHANGED
@@ -1,16 +1,16 @@
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 G, toDisposable as M, ILogService as J, LocaleService as T, DisposableCollection as Y, OnLifecycle as H, LifecycleStages as K, ICommandService as Q, Plugin as X, PluginType as Z } from "@univerjs/core";
5
- import { Inject as f, Injector as b } from "@wendellhu/redi";
6
- import { ISidebarService as k, IShortcutService as ee, IMessageService as te, MenuItemType as re, MenuPosition as ne, ComponentManager as ie, IMenuService as oe } from "@univerjs/ui";
7
- import { BehaviorSubject as se, distinctUntilChanged as ce } from "rxjs";
8
- import le, { useRef as O, useEffect as pe, useCallback as ae } from "react";
9
- import { MessageType as w, Button as ue } from "@univerjs/design";
10
- import { useDependency as d } from "@wendellhu/redi/react-bindings";
11
- import { editor as de } from "monaco-editor";
12
- import { FUniver as ve } from "@univerjs/facade";
13
- const fe = {
1
+ var B = Object.defineProperty;
2
+ var q = (t, e, r) => e in t ? B(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var u = (t, e, r) => (q(t, typeof e != "symbol" ? e + "" : e, r), r);
4
+ import { Disposable as E, CommandType as z, toDisposable as M, ILogService as V, LocaleService as I, DisposableCollection as G, OnLifecycle as J, LifecycleStages as Y, ICommandService as H, Plugin as K, PluginType as Q } from "@univerjs/core";
5
+ import { Inject as v, Injector as b } from "@wendellhu/redi";
6
+ import { ISidebarService as X, IShortcutService as Z, IMessageService as k, MenuItemType as ee, MenuPosition as te, ComponentManager as re, IMenuService as ne } from "@univerjs/ui";
7
+ import { BehaviorSubject as ie, distinctUntilChanged as oe } from "rxjs";
8
+ import se, { useRef as x, useEffect as ce, useCallback as le } from "react";
9
+ import { Button as pe, MessageType as w } from "@univerjs/design";
10
+ import { useDependency as p } from "@wendellhu/redi/react-bindings";
11
+ import { editor as ae } from "monaco-editor";
12
+ import { FUniver as ue } from "@univerjs/facade";
13
+ const de = {
14
14
  "script-panel": {
15
15
  title: "Uniscript",
16
16
  tooltip: {
@@ -26,7 +26,7 @@ const fe = {
26
26
  failed: "Execution Failed"
27
27
  }
28
28
  }
29
- }, He = fe, _e = {
29
+ }, Ye = de, ve = {
30
30
  "script-panel": {
31
31
  title: "Uniscript",
32
32
  tooltip: {
@@ -42,12 +42,12 @@ const fe = {
42
42
  failed: "执行失败"
43
43
  }
44
44
  }
45
- }, me = _e;
46
- class D extends P {
45
+ }, fe = ve;
46
+ class T extends E {
47
47
  constructor() {
48
48
  super(...arguments);
49
- u(this, "_open$", new se(!1));
50
- u(this, "open$", this._open$.pipe(ce()));
49
+ u(this, "_open$", new ie(!1));
50
+ u(this, "open$", this._open$.pipe(oe()));
51
51
  }
52
52
  get isOpen() {
53
53
  return this._open$.getValue();
@@ -62,19 +62,19 @@ class D extends P {
62
62
  this._open$.next(!1);
63
63
  }
64
64
  }
65
- const N = "ScriptPanel", A = {
66
- type: G.OPERATION,
65
+ const D = "ScriptPanel", N = {
66
+ type: z.OPERATION,
67
67
  id: "univer.operation.toggle-script-panel",
68
68
  handler: (t) => {
69
- const e = t.get(D), r = t.get(k);
69
+ const e = t.get(T), r = t.get(X);
70
70
  return e.isOpen ? (e.close(), r.close()) : (e.open(), r.open({
71
71
  header: { title: "script-panel.title" },
72
- children: { label: N },
72
+ children: { label: D },
73
73
  width: 600
74
74
  })), !0;
75
75
  }
76
76
  };
77
- var F = { exports: {} }, x = {};
77
+ var A = { exports: {} }, P = {};
78
78
  /**
79
79
  * @license React
80
80
  * react-jsx-runtime.production.min.js
@@ -84,23 +84,23 @@ var F = { exports: {} }, x = {};
84
84
  * This source code is licensed under the MIT license found in the
85
85
  * LICENSE file in the root directory of this source tree.
86
86
  */
87
- var he = le, ge = Symbol.for("react.element"), Se = Symbol.for("react.fragment"), Ee = Object.prototype.hasOwnProperty, Pe = he.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, xe = { key: !0, ref: !0, __self: !0, __source: !0 };
88
- function L(t, e, r) {
87
+ var _e = se, me = Symbol.for("react.element"), he = Symbol.for("react.fragment"), ge = Object.prototype.hasOwnProperty, Se = _e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, Ee = { key: !0, ref: !0, __self: !0, __source: !0 };
88
+ function F(t, e, r) {
89
89
  var n, i = {}, o = null, s = null;
90
90
  r !== void 0 && (o = "" + r), e.key !== void 0 && (o = "" + e.key), e.ref !== void 0 && (s = e.ref);
91
91
  for (n in e)
92
- Ee.call(e, n) && !xe.hasOwnProperty(n) && (i[n] = e[n]);
92
+ ge.call(e, n) && !Ee.hasOwnProperty(n) && (i[n] = e[n]);
93
93
  if (t && t.defaultProps)
94
94
  for (n in e = t.defaultProps, e)
95
95
  i[n] === void 0 && (i[n] = e[n]);
96
- return { $$typeof: ge, type: t, key: o, ref: s, props: i, _owner: Pe.current };
96
+ return { $$typeof: me, type: t, key: o, ref: s, props: i, _owner: Se.current };
97
97
  }
98
- x.Fragment = Se;
99
- x.jsx = L;
100
- x.jsxs = L;
101
- F.exports = x;
102
- var v = F.exports;
103
- class I extends P {
98
+ P.Fragment = he;
99
+ P.jsx = F;
100
+ P.jsxs = F;
101
+ A.exports = P;
102
+ var d = A.exports;
103
+ class y extends E {
104
104
  constructor(r) {
105
105
  super();
106
106
  u(this, "_editorInstance", null);
@@ -118,18 +118,18 @@ class I extends P {
118
118
  });
119
119
  }
120
120
  }
121
- var Oe = Object.defineProperty, ye = Object.getOwnPropertyDescriptor, Ie = (t, e, r, n) => {
122
- for (var i = n > 1 ? void 0 : n ? ye(e, r) : e, o = t.length - 1, s; o >= 0; o--)
121
+ var Pe = Object.defineProperty, xe = Object.getOwnPropertyDescriptor, Oe = (t, e, r, n) => {
122
+ for (var i = n > 1 ? void 0 : n ? xe(e, r) : e, o = t.length - 1, s; o >= 0; o--)
123
123
  (s = t[o]) && (i = (n ? s(e, r, i) : s(i)) || i);
124
- return n && i && Oe(e, r, i), i;
124
+ return n && i && Pe(e, r, i), i;
125
125
  }, $ = (t, e) => (r, n) => e(r, n, t);
126
- let E = class extends P {
126
+ let S = class extends E {
127
127
  constructor(t, e) {
128
128
  super(), this._logService = t, this._injector = e;
129
129
  }
130
130
  async execute(t) {
131
131
  this._logService.log("[UniscriptExecutionService]", "executing Uniscript...");
132
- const e = ve.newAPI(this._injector), r = new Function("univerAPI", `(() => {${t}})()`);
132
+ const e = ue.newAPI(this._injector), r = new Function("univerAPI", `(() => {${t}})()`);
133
133
  try {
134
134
  return r(e), !0;
135
135
  } catch (n) {
@@ -137,129 +137,133 @@ let E = class extends P {
137
137
  }
138
138
  }
139
139
  };
140
- E = Ie([
141
- $(0, J),
142
- $(1, f(b))
143
- ], E);
144
- const be = "univer-script-editor-panel", je = "univer-script-editor-content", Ce = "univer-script-editor-actions", h = {
145
- scriptEditorPanel: be,
146
- scriptEditorContent: je,
147
- scriptEditorActions: Ce
140
+ S = Oe([
141
+ $(0, V),
142
+ $(1, v(b))
143
+ ], S);
144
+ const ye = "univer-script-editor-panel", Ie = "univer-script-editor-content", be = "univer-script-editor-actions", m = {
145
+ scriptEditorPanel: ye,
146
+ scriptEditorContent: Ie,
147
+ scriptEditorActions: be
148
148
  };
149
- function we() {
150
- const t = O(null), e = O(null), r = O(null), n = d(T), i = d(E), o = d(ee), s = d(I), j = d(te);
151
- pe(() => {
152
- const a = e.current, c = t.current;
153
- let l = null, _ = null;
154
- if (a && c) {
155
- s.requireVscodeEditor();
156
- const m = r.current = de.create(a, {
149
+ function je() {
150
+ const t = x(null), e = x(null), r = x(null), n = p(I), i = p(Z), o = p(y);
151
+ ce(() => {
152
+ const j = e.current, a = t.current;
153
+ let c = null, f = null;
154
+ if (j && a) {
155
+ o.requireVscodeEditor();
156
+ const _ = r.current = ae.create(j, {
157
157
  value: "",
158
158
  language: "javascript"
159
159
  });
160
- _ = new ResizeObserver(() => {
160
+ f = new ResizeObserver(() => {
161
161
  let C = requestIdleCallback(() => {
162
162
  if (!C)
163
163
  return;
164
- const { height: B, width: q } = c.getBoundingClientRect();
165
- m.layout({ width: q, height: B }), C = void 0;
164
+ const { height: L, width: W } = a.getBoundingClientRect();
165
+ _.layout({ width: W, height: L }), C = void 0;
166
166
  });
167
- }), _.observe(c);
168
- let p;
169
- l = new Y(), l.add(s.setEditorInstance(m)), l.add(
170
- m.onDidFocusEditorWidget(() => {
171
- p = o.forceEscape();
167
+ }), f.observe(a);
168
+ let l;
169
+ c = new G(), c.add(o.setEditorInstance(_)), c.add(
170
+ _.onDidFocusEditorWidget(() => {
171
+ l = i.forceEscape();
172
172
  })
173
- ), l.add(
174
- m.onDidBlurEditorWidget(() => {
175
- p == null || p.dispose(), p = void 0;
173
+ ), c.add(
174
+ _.onDidBlurEditorWidget(() => {
175
+ l == null || l.dispose(), l = void 0;
176
176
  })
177
- ), l.add(M(() => p == null ? void 0 : p.dispose()));
177
+ ), c.add(M(() => l == null ? void 0 : l.dispose()));
178
178
  }
179
179
  return () => {
180
- _ && c && _.unobserve(c), l == null || l.dispose();
180
+ f && a && f.unobserve(a), c == null || c.dispose();
181
181
  };
182
- }, []);
183
- const W = ae(() => {
184
- var c;
185
- const a = (c = r.current) == null ? void 0 : c.getModel();
186
- a && i.execute(a.getValue()).then(() => {
187
- j.show({
182
+ }, [o, i]);
183
+ const s = Ce(r);
184
+ return /* @__PURE__ */ d.jsxs("div", { className: m.scriptEditorPanel, children: [
185
+ /* @__PURE__ */ d.jsx("div", { className: m.scriptEditorContent, ref: t, children: /* @__PURE__ */ d.jsx("div", { className: m.scriptEditorContainer, ref: e }) }),
186
+ /* @__PURE__ */ d.jsx("div", { className: m.scriptEditorActions, children: /* @__PURE__ */ d.jsx(pe, { type: "primary", size: "small", onClick: s, children: n.t("script-panel.panel.execute") }) })
187
+ ] });
188
+ }
189
+ function Ce(t) {
190
+ const e = p(S), r = p(k), n = p(I);
191
+ return le(() => {
192
+ var o;
193
+ const i = (o = t.current) == null ? void 0 : o.getModel();
194
+ i && e.execute(i.getValue()).then(() => {
195
+ r.show({
188
196
  content: n.t("uniscript.message.success"),
189
197
  type: w.Success
190
198
  });
191
199
  }).catch(() => {
192
- j.show({
200
+ r.show({
193
201
  content: n.t("uniscript.message.failed"),
194
202
  type: w.Error
195
203
  });
196
204
  });
197
- }, [i]);
198
- return /* @__PURE__ */ v.jsxs("div", { className: h.scriptEditorPanel, children: [
199
- /* @__PURE__ */ v.jsx("div", { className: h.scriptEditorContent, ref: t, children: /* @__PURE__ */ v.jsx("div", { className: h.scriptEditorContainer, ref: e }) }),
200
- /* @__PURE__ */ v.jsx("div", { className: h.scriptEditorActions, children: /* @__PURE__ */ v.jsx(ue, { type: "primary", size: "small", onClick: W, children: n.t("script-panel.panel.execute") }) })
201
- ] });
205
+ }, [n, r, t, e]);
202
206
  }
203
- function $e(t) {
207
+ function we(t) {
204
208
  return {
205
- id: A.id,
209
+ id: N.id,
206
210
  title: "toggle-script-panel",
207
211
  tooltip: "script-panel.tooltip.menu-button",
208
212
  icon: "CodeSingle",
209
- type: re.BUTTON,
210
- positions: [ne.TOOLBAR_START]
213
+ type: ee.BUTTON,
214
+ positions: [te.TOOLBAR_START]
211
215
  // FIXME hidden$ and disabled$ are not correctly in doc
212
216
  // hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),
213
217
  // disabled$: getCurrentSheetDisabled$(accessor),
214
218
  };
215
219
  }
216
- var Ue = Object.defineProperty, Re = Object.getOwnPropertyDescriptor, Me = (t, e, r, n) => {
217
- for (var i = n > 1 ? void 0 : n ? Re(e, r) : e, o = t.length - 1, s; o >= 0; o--)
220
+ var $e = Object.defineProperty, Ue = Object.getOwnPropertyDescriptor, Re = (t, e, r, n) => {
221
+ for (var i = n > 1 ? void 0 : n ? Ue(e, r) : e, o = t.length - 1, s; o >= 0; o--)
218
222
  (s = t[o]) && (i = (n ? s(e, r, i) : s(i)) || i);
219
- return n && i && Ue(e, r, i), i;
220
- }, g = (t, e) => (r, n) => e(r, n, t);
221
- let S = class extends P {
223
+ return n && i && $e(e, r, i), i;
224
+ }, h = (t, e) => (r, n) => e(r, n, t);
225
+ let g = class extends E {
222
226
  constructor(t, e, r, n) {
223
- super(), this._injector = t, this.disposeWithMe(e.addMenuItem(this._injector.invoke($e))), this.disposeWithMe(n.register(N, we)), this.disposeWithMe(r.registerCommand(A));
227
+ super(), this._injector = t, this.disposeWithMe(e.addMenuItem(this._injector.invoke(we))), this.disposeWithMe(n.register(D, je)), this.disposeWithMe(r.registerCommand(N));
224
228
  }
225
229
  };
226
- S = Me([
227
- H(K.Steady, S),
228
- g(0, f(b)),
229
- g(1, oe),
230
- g(2, Q),
231
- g(3, f(ie))
232
- ], S);
233
- var Te = Object.defineProperty, De = Object.getOwnPropertyDescriptor, Ne = (t, e, r, n) => {
234
- for (var i = n > 1 ? void 0 : n ? De(e, r) : e, o = t.length - 1, s; o >= 0; o--)
230
+ g = Re([
231
+ J(Y.Steady, g),
232
+ h(0, v(b)),
233
+ h(1, ne),
234
+ h(2, H),
235
+ h(3, v(re))
236
+ ], g);
237
+ var Me = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, De = (t, e, r, n) => {
238
+ for (var i = n > 1 ? void 0 : n ? Te(e, r) : e, o = t.length - 1, s; o >= 0; o--)
235
239
  (s = t[o]) && (i = (n ? s(e, r, i) : s(i)) || i);
236
- return n && i && Te(e, r, i), i;
240
+ return n && i && Me(e, r, i), i;
237
241
  }, U = (t, e) => (r, n) => e(r, n, t);
238
- const Ae = "uniscript";
239
- var y;
240
- let R = (y = class extends X {
242
+ const Ne = "uniscript";
243
+ var O;
244
+ let R = (O = class extends K {
241
245
  constructor(t, e, r) {
242
- super(Ae), this._config = t, this._injector = e, this._localeService = r;
246
+ super(Ne), this._config = t, this._injector = e, this._localeService = r;
243
247
  }
244
248
  onStarting(t) {
245
249
  [
246
250
  // controllers
247
- [S],
251
+ [g],
248
252
  // services
249
- [I, { useFactory: () => t.createInstance(I, this._config) }],
250
- [D],
251
- [E]
253
+ [y, { useFactory: () => t.createInstance(y, this._config) }],
254
+ [T],
255
+ [S]
252
256
  ].forEach((r) => t.add(r)), this._localeService.load({
253
- zhCN: me
257
+ zhCN: fe
254
258
  });
255
259
  }
256
- }, u(y, "type", Z.Univer), y);
257
- R = Ne([
258
- U(1, f(b)),
259
- U(2, f(T))
260
+ }, u(O, "type", Q.Univer), O);
261
+ R = De([
262
+ U(1, v(b)),
263
+ U(2, v(I))
260
264
  ], R);
261
265
  export {
262
266
  R as UniverUniscriptPlugin,
263
- He as enUS,
264
- me as zhCN
267
+ Ye as enUS,
268
+ fe as zhCN
265
269
  };
@@ -1,18 +1,4 @@
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 { IOperation } from '@univerjs/core';
1
+ import { IOperation } from '@univerjs/core';
2
+
17
3
  export declare const ScriptPanelComponentName = "ScriptPanel";
18
4
  export declare const ToggleScriptPanelOperation: IOperation;
@@ -1,18 +1,4 @@
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 { IMenuButtonItem } from '@univerjs/ui';
17
- import type { IAccessor } from '@wendellhu/redi';
1
+ import { IAccessor } from '@wendellhu/redi';
2
+ import { IMenuButtonItem } from '@univerjs/ui';
3
+
18
4
  export declare function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem;
@@ -1,21 +1,7 @@
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 { Disposable, ICommandService } from '@univerjs/core';
17
- import { ComponentManager, IMenuService } from '@univerjs/ui';
18
1
  import { Injector } from '@wendellhu/redi';
2
+ import { ComponentManager, IMenuService } from '@univerjs/ui';
3
+ import { Disposable, ICommandService } from '@univerjs/core';
4
+
19
5
  export declare class UniscriptController extends Disposable {
20
6
  private readonly _injector;
21
7
  constructor(_injector: Injector, menuService: IMenuService, commandService: ICommandService, componentManager: ComponentManager);
@@ -1,18 +1,4 @@
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 zhCN from './zh-CN';
1
+ import { default as zhCN } from './zh-CN';
2
+
17
3
  declare const locale: typeof zhCN;
18
4
  export default locale;
@@ -1,21 +1,7 @@
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 { LocaleService, Plugin, PluginType } from '@univerjs/core';
1
+ import { IScriptEditorServiceConfig } from './services/script-editor.service';
17
2
  import { Injector } from '@wendellhu/redi';
18
- import type { IScriptEditorServiceConfig } from './services/script-editor.service';
3
+ import { LocaleService, Plugin, PluginType } from '@univerjs/core';
4
+
19
5
  export interface IUniscriptConfig extends IScriptEditorServiceConfig {
20
6
  }
21
7
  export declare class UniverUniscriptPlugin extends Plugin {
@@ -1,20 +1,6 @@
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 { CommandListener, ICommand, ICommandService, IExecutionOptions } from '@univerjs/core';
17
- import type { IDisposable } from '@wendellhu/redi';
1
+ import { IDisposable } from '@wendellhu/redi';
2
+ import { CommandListener, ICommand, ICommandService, IExecutionOptions } from '@univerjs/core';
3
+
18
4
  export declare class BatchCommandService implements ICommandService {
19
5
  beforeCommandExecuted(listener: CommandListener): IDisposable;
20
6
  registerCommand(command: ICommand<object, boolean>): IDisposable;
@@ -1,21 +1,7 @@
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
- */
1
+ import { editor } from 'monaco-editor';
2
+ import { IDisposable } from '@wendellhu/redi';
16
3
  import { Disposable } from '@univerjs/core';
17
- import type { IDisposable } from '@wendellhu/redi';
18
- import type { editor } from 'monaco-editor';
4
+
19
5
  export interface IScriptEditorServiceConfig {
20
6
  getWorkerUrl(moduleID: string, label: string): string;
21
7
  }
@@ -1,20 +1,6 @@
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 { Disposable, ILogService } from '@univerjs/core';
17
1
  import { Injector } from '@wendellhu/redi';
2
+ import { Disposable, ILogService } from '@univerjs/core';
3
+
18
4
  /**
19
5
  * This service is to
20
6
  */
@@ -1,22 +1,8 @@
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
1
  import { Disposable } from '@univerjs/core';
2
+
17
3
  export declare class ScriptPanelService extends Disposable {
18
4
  private _open$;
19
- open$: import("rxjs").Observable<boolean>;
5
+ open$: import('rxjs').Observable<boolean>;
20
6
  get isOpen(): boolean;
21
7
  dispose(): void;
22
8
  open(): void;
@@ -1,17 +1,3 @@
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 React from 'react';
1
+ import { default as React } from 'react';
2
+
17
3
  export declare function ScriptEditorPanel(): React.JSX.Element;
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
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")):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"],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))})(this,function(o,s,p,v,C,f,I,_,q,W){"use strict";var ae=Object.defineProperty;var ue=(o,s,p)=>s in o?ae(o,s,{enumerable:!0,configurable:!0,writable:!0,value:p}):o[s]=p;var S=(o,s,p)=>(ue(o,typeof s!="symbol"?s+"":s,p),p);var w;const z={"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 D extends s.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(){this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}}const R="ScriptPanel",T={type:s.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:i=>{const e=i.get(D),n=i.get(v.ISidebarService);return e.isOpen?(e.close(),n.close()):(e.open(),n.open({header:{title:"script-panel.title"},children:{label:R},width:600})),!0}};var M={exports:{}},g={};/**
1
+ (function(c,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")):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"],s):(c=typeof globalThis<"u"?globalThis:c||self,s(c.UniverUniscript={},c.UniverCore,c["@wendellhu/redi"],c.UniverUi,c.rxjs,c.React,c.UniverDesign,c["@wendellhu/redi/react-bindings"],c.monaco,c.UniverFacade))})(this,function(c,s,p,d,w,v,U,f,F,q){"use strict";var pe=Object.defineProperty;var ae=(c,s,p)=>s in c?pe(c,s,{enumerable:!0,configurable:!0,writable:!0,value:p}):c[s]=p;var S=(c,s,p)=>(ae(c,typeof s!="symbol"?s+"":s,p),p);var O;const W={"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 b extends s.Disposable{constructor(){super(...arguments);S(this,"_open$",new w.BehaviorSubject(!1));S(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 D="ScriptPanel",R={type:s.CommandType.OPERATION,id:"univer.operation.toggle-script-panel",handler:i=>{const e=i.get(b),n=i.get(d.ISidebarService);return e.isOpen?(e.close(),n.close()):(e.open(),n.open({header:{title:"script-panel.title"},children:{label:D},width:600})),!0}};var T={exports:{}},m={};/**
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 V=f,B=Symbol.for("react.element"),G=Symbol.for("react.fragment"),J=Object.prototype.hasOwnProperty,Y=V.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,H={key:!0,ref:!0,__self:!0,__source:!0};function N(i,e,n){var t,r={},c=null,l=null;n!==void 0&&(c=""+n),e.key!==void 0&&(c=""+e.key),e.ref!==void 0&&(l=e.ref);for(t in e)J.call(e,t)&&!H.hasOwnProperty(t)&&(r[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)r[t]===void 0&&(r[t]=e[t]);return{$$typeof:B,type:i,key:c,ref:l,props:r,_owner:Y.current}}g.Fragment=G,g.jsx=N,g.jsxs=N,M.exports=g;var h=M.exports;class O extends s.Disposable{constructor(n){super();S(this,"_editorInstance",null);this._config=n}setEditorInstance(n){return this._editorInstance=n,s.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var K=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(i,e,n,t)=>{for(var r=t>1?void 0:t?Q(e,n):e,c=i.length-1,l;c>=0;c--)(l=i[c])&&(r=(t?l(e,n,r):l(r))||r);return t&&r&&K(e,n,r),r},$=(i,e)=>(n,t)=>e(n,t,i);let E=class extends s.Disposable{constructor(i,e){super(),this._logService=i,this._injector=e}async execute(i){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=W.FUniver.newAPI(this._injector),n=new Function("univerAPI",`(() => {${i}})()`);try{return n(e),!0}catch(t){return this._logService.error(t),!1}}};E=X([$(0,s.ILogService),$(1,p.Inject(p.Injector))],E);const j={scriptEditorPanel:"univer-script-editor-panel",scriptEditorContent:"univer-script-editor-content",scriptEditorActions:"univer-script-editor-actions"};function Z(){const i=f.useRef(null),e=f.useRef(null),n=f.useRef(null),t=_.useDependency(s.LocaleService),r=_.useDependency(E),c=_.useDependency(v.IShortcutService),l=_.useDependency(O),F=_.useDependency(v.IMessageService);f.useEffect(()=>{const m=e.current,a=i.current;let u=null,U=null;if(m&&a){l.requireVscodeEditor();const x=n.current=q.editor.create(m,{value:"",language:"javascript"});U=new ResizeObserver(()=>{let L=requestIdleCallback(()=>{if(!L)return;const{height:le,width:pe}=a.getBoundingClientRect();x.layout({width:pe,height:le}),L=void 0})}),U.observe(a);let d;u=new s.DisposableCollection,u.add(l.setEditorInstance(x)),u.add(x.onDidFocusEditorWidget(()=>{d=c.forceEscape()})),u.add(x.onDidBlurEditorWidget(()=>{d==null||d.dispose(),d=void 0})),u.add(s.toDisposable(()=>d==null?void 0:d.dispose()))}return()=>{U&&a&&U.unobserve(a),u==null||u.dispose()}},[]);const ce=f.useCallback(()=>{var a;const m=(a=n.current)==null?void 0:a.getModel();m&&r.execute(m.getValue()).then(()=>{F.show({content:t.t("uniscript.message.success"),type:I.MessageType.Success})}).catch(()=>{F.show({content:t.t("uniscript.message.failed"),type:I.MessageType.Error})})},[r]);return h.jsxs("div",{className:j.scriptEditorPanel,children:[h.jsx("div",{className:j.scriptEditorContent,ref:i,children:h.jsx("div",{className:j.scriptEditorContainer,ref:e})}),h.jsx("div",{className:j.scriptEditorActions,children:h.jsx(I.Button,{type:"primary",size:"small",onClick:ce,children:t.t("script-panel.panel.execute")})})]})}function k(i){return{id:T.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:v.MenuItemType.BUTTON,positions:[v.MenuPosition.TOOLBAR_START]}}var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(i,e,n,t)=>{for(var r=t>1?void 0:t?te(e,n):e,c=i.length-1,l;c>=0;c--)(l=i[c])&&(r=(t?l(e,n,r):l(r))||r);return t&&r&&ee(e,n,r),r},P=(i,e)=>(n,t)=>e(n,t,i);let y=class extends s.Disposable{constructor(i,e,n,t){super(),this._injector=i,this.disposeWithMe(e.addMenuItem(this._injector.invoke(k))),this.disposeWithMe(t.register(R,Z)),this.disposeWithMe(n.registerCommand(T))}};y=ne([s.OnLifecycle(s.LifecycleStages.Steady,y),P(0,p.Inject(p.Injector)),P(1,v.IMenuService),P(2,s.ICommandService),P(3,p.Inject(v.ComponentManager))],y);var ie=Object.defineProperty,re=Object.getOwnPropertyDescriptor,se=(i,e,n,t)=>{for(var r=t>1?void 0:t?re(e,n):e,c=i.length-1,l;c>=0;c--)(l=i[c])&&(r=(t?l(e,n,r):l(r))||r);return t&&r&&ie(e,n,r),r},A=(i,e)=>(n,t)=>e(n,t,i);const oe="uniscript";o.UniverUniscriptPlugin=(w=class extends s.Plugin{constructor(e,n,t){super(oe),this._config=e,this._injector=n,this._localeService=t}onStarting(e){[[y],[O,{useFactory:()=>e.createInstance(O,this._config)}],[D],[E]].forEach(t=>e.add(t)),this._localeService.load({zhCN:b})}},S(w,"type",s.PluginType.Univer),w),o.UniverUniscriptPlugin=se([A(1,p.Inject(p.Injector)),A(2,p.Inject(s.LocaleService))],o.UniverUniscriptPlugin),o.enUS=z,o.zhCN=b,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
9
+ */var z=v,V=Symbol.for("react.element"),B=Symbol.for("react.fragment"),G=Object.prototype.hasOwnProperty,J=z.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,Y={key:!0,ref:!0,__self:!0,__source:!0};function M(i,e,n){var t,r={},o=null,l=null;n!==void 0&&(o=""+n),e.key!==void 0&&(o=""+e.key),e.ref!==void 0&&(l=e.ref);for(t in e)G.call(e,t)&&!Y.hasOwnProperty(t)&&(r[t]=e[t]);if(i&&i.defaultProps)for(t in e=i.defaultProps,e)r[t]===void 0&&(r[t]=e[t]);return{$$typeof:V,type:i,key:o,ref:l,props:r,_owner:J.current}}m.Fragment=B,m.jsx=M,m.jsxs=M,T.exports=m;var _=T.exports;class I extends s.Disposable{constructor(n){super();S(this,"_editorInstance",null);this._config=n}setEditorInstance(n){return this._editorInstance=n,s.toDisposable(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){window.MonacoEnvironment||(window.MonacoEnvironment={getWorkerUrl:this._config.getWorkerUrl})}}var H=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Q=(i,e,n,t)=>{for(var r=t>1?void 0:t?K(e,n):e,o=i.length-1,l;o>=0;o--)(l=i[o])&&(r=(t?l(e,n,r):l(r))||r);return t&&r&&H(e,n,r),r},N=(i,e)=>(n,t)=>e(n,t,i);let g=class extends s.Disposable{constructor(i,e){super(),this._logService=i,this._injector=e}async execute(i){this._logService.log("[UniscriptExecutionService]","executing Uniscript...");const e=q.FUniver.newAPI(this._injector),n=new Function("univerAPI",`(() => {${i}})()`);try{return n(e),!0}catch(t){return this._logService.error(t),!1}}};g=Q([N(0,s.ILogService),N(1,p.Inject(p.Injector))],g);const E={scriptEditorPanel:"univer-script-editor-panel",scriptEditorContent:"univer-script-editor-content",scriptEditorActions:"univer-script-editor-actions"};function X(){const i=v.useRef(null),e=v.useRef(null),n=v.useRef(null),t=f.useDependency(s.LocaleService),r=f.useDependency(d.IShortcutService),o=f.useDependency(I);v.useEffect(()=>{const A=e.current,h=i.current;let a=null,P=null;if(A&&h){o.requireVscodeEditor();const x=n.current=F.editor.create(A,{value:"",language:"javascript"});P=new ResizeObserver(()=>{let L=requestIdleCallback(()=>{if(!L)return;const{height:oe,width:le}=h.getBoundingClientRect();x.layout({width:le,height:oe}),L=void 0})}),P.observe(h);let u;a=new s.DisposableCollection,a.add(o.setEditorInstance(x)),a.add(x.onDidFocusEditorWidget(()=>{u=r.forceEscape()})),a.add(x.onDidBlurEditorWidget(()=>{u==null||u.dispose(),u=void 0})),a.add(s.toDisposable(()=>u==null?void 0:u.dispose()))}return()=>{P&&h&&P.unobserve(h),a==null||a.dispose()}},[o,r]);const l=Z(n);return _.jsxs("div",{className:E.scriptEditorPanel,children:[_.jsx("div",{className:E.scriptEditorContent,ref:i,children:_.jsx("div",{className:E.scriptEditorContainer,ref:e})}),_.jsx("div",{className:E.scriptEditorActions,children:_.jsx(U.Button,{type:"primary",size:"small",onClick:l,children:t.t("script-panel.panel.execute")})})]})}function Z(i){const e=f.useDependency(g),n=f.useDependency(d.IMessageService),t=f.useDependency(s.LocaleService);return v.useCallback(()=>{var o;const r=(o=i.current)==null?void 0:o.getModel();r&&e.execute(r.getValue()).then(()=>{n.show({content:t.t("uniscript.message.success"),type:U.MessageType.Success})}).catch(()=>{n.show({content:t.t("uniscript.message.failed"),type:U.MessageType.Error})})},[t,n,i,e])}function k(i){return{id:R.id,title:"toggle-script-panel",tooltip:"script-panel.tooltip.menu-button",icon:"CodeSingle",type:d.MenuItemType.BUTTON,positions:[d.MenuPosition.TOOLBAR_START]}}var ee=Object.defineProperty,te=Object.getOwnPropertyDescriptor,ne=(i,e,n,t)=>{for(var r=t>1?void 0:t?te(e,n):e,o=i.length-1,l;o>=0;o--)(l=i[o])&&(r=(t?l(e,n,r):l(r))||r);return t&&r&&ee(e,n,r),r},j=(i,e)=>(n,t)=>e(n,t,i);let y=class extends s.Disposable{constructor(i,e,n,t){super(),this._injector=i,this.disposeWithMe(e.addMenuItem(this._injector.invoke(k))),this.disposeWithMe(t.register(D,X)),this.disposeWithMe(n.registerCommand(R))}};y=ne([s.OnLifecycle(s.LifecycleStages.Steady,y),j(0,p.Inject(p.Injector)),j(1,d.IMenuService),j(2,s.ICommandService),j(3,p.Inject(d.ComponentManager))],y);var ie=Object.defineProperty,re=Object.getOwnPropertyDescriptor,se=(i,e,n,t)=>{for(var r=t>1?void 0:t?re(e,n):e,o=i.length-1,l;o>=0;o--)(l=i[o])&&(r=(t?l(e,n,r):l(r))||r);return t&&r&&ie(e,n,r),r},$=(i,e)=>(n,t)=>e(n,t,i);const ce="uniscript";c.UniverUniscriptPlugin=(O=class extends s.Plugin{constructor(e,n,t){super(ce),this._config=e,this._injector=n,this._localeService=t}onStarting(e){[[y],[I,{useFactory:()=>e.createInstance(I,this._config)}],[b],[g]].forEach(t=>e.add(t)),this._localeService.load({zhCN:C})}},S(O,"type",s.PluginType.Univer),O),c.UniverUniscriptPlugin=se([$(1,p.Inject(p.Injector)),$(2,p.Inject(s.LocaleService))],c.UniverUniscriptPlugin),c.enUS=W,c.zhCN=C,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/uniscript",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "description": "UI component library for building exceptional Univer.",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,26 +57,25 @@
57
57
  "monaco-editor": ">=0.44.0",
58
58
  "react": ">=16.9.0",
59
59
  "rxjs": ">=7.0.0",
60
- "@univerjs/design": "0.1.4",
61
- "@univerjs/core": "0.1.4",
62
- "@univerjs/facade": "0.1.4",
63
- "@univerjs/ui": "0.1.4"
60
+ "@univerjs/core": "0.1.6",
61
+ "@univerjs/design": "0.1.6",
62
+ "@univerjs/facade": "0.1.6",
63
+ "@univerjs/ui": "0.1.6"
64
64
  },
65
65
  "devDependencies": {
66
- "@types/react": "^18.2.67",
66
+ "@types/react": "^18.2.73",
67
67
  "@wendellhu/redi": "^0.13.0",
68
68
  "less": "^4.2.0",
69
69
  "monaco-editor": "0.47.0",
70
70
  "rxjs": "^7.8.1",
71
- "typescript": "^5.4.2",
72
- "vite": "^5.1.6",
71
+ "typescript": "^5.4.3",
72
+ "vite": "^5.2.7",
73
73
  "vitest": "^1.4.0",
74
- "@univerjs/design": "0.1.4",
75
- "@univerjs/shared": "0.1.4",
76
- "@univerjs/facade": "0.1.4",
77
- "@univerjs/sheets": "0.1.4",
78
- "@univerjs/ui": "0.1.4",
79
- "@univerjs/core": "0.1.4"
74
+ "@univerjs/core": "0.1.6",
75
+ "@univerjs/design": "0.1.6",
76
+ "@univerjs/facade": "0.1.6",
77
+ "@univerjs/shared": "0.1.6",
78
+ "@univerjs/ui": "0.1.6"
80
79
  },
81
80
  "scripts": {
82
81
  "test": "vitest run",