@univerjs/uniscript 0.21.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,61 +1,42 @@
1
1
  # @univerjs/uniscript
2
2
 
3
- ## Package Overview
4
-
5
- | Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
6
- | --- | --- | --- | --- | --- | :---: | :---: |
7
- | `@univerjs/uniscript` | `UniveUniscript` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ⭕️ | ⭕️ |
8
-
9
- ## Introduction
10
-
11
- ![](./assets/uniscript.jpeg)
3
+ [![npm version](https://img.shields.io/npm/v/@univerjs/uniscript?style=flat-square)](https://npmjs.com/package/@univerjs/uniscript)
4
+ [![license](https://img.shields.io/npm/l/@univerjs/uniscript?style=flat-square)](https://npmjs.com/package/@univerjs/uniscript)
5
+ [![downloads](https://img.shields.io/npm/dm/@univerjs/uniscript?style=flat-square)](https://npmjs.com/package/@univerjs/uniscript)
12
6
 
13
- `@univerjs/uniscript` uses the DSL (Domain-Specific Language) provided by `@univerjs/facade` and creates a code editor for Users to write code for operating Univer's data structures and business logic.
7
+ `@univerjs/uniscript` provides a Monaco-based code editor for writing scripts that operate on Univer data structures through the Facade API.
14
8
 
15
- 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.
16
-
17
- > [!CAUTION]
18
- > 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/sheet/roadmap) to understand the iteration plan of Uniscript.
19
-
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://docs.univer.ai/guides/sheets/getting-started/facade).
22
-
23
- ## Usage
9
+ ## Package Overview
24
10
 
25
- ### Installation
11
+ | Package | UMD global | CSS | Locales | Facade entry |
12
+ | --- | --- | :---: | :---: | :---: |
13
+ | `@univerjs/uniscript` | `UniverUniscript` | Yes | Yes | No |
26
14
 
27
- ```shell
28
- # Using npm
29
- npm install @univerjs/uniscript
15
+ ## Installation
30
16
 
31
- # Using pnpm
17
+ ```sh
32
18
  pnpm add @univerjs/uniscript
19
+ # or
20
+ npm install @univerjs/uniscript
33
21
  ```
34
22
 
35
- ### Get the Editor Instance
23
+ Keep all `@univerjs/*` packages on the same version.
36
24
 
37
- The `@univerjs/uniscript` uses [Monaco Editor](https://microsoft.github.io/monaco-editor/) as its code editor. You can obtain an instance of the editor through the following method:
25
+ ## Usage
38
26
 
39
27
  ```ts
40
- const editor = univer.__getInjector().get(ScriptEditorService).getEditorInstance();
41
- ```
28
+ import '@univerjs/uniscript/lib/index.css';
29
+ import EnUS from '@univerjs/uniscript/locale/en-US';
30
+ import { UniverUniscriptPlugin } from '@univerjs/uniscript';
42
31
 
43
- Or inject `ScriptEditorService` into your module to obtain the editor instance.
32
+ univer.registerPlugin(UniverUniscriptPlugin);
44
33
 
45
- ```ts
46
- export class YourModule {
47
- constructor(
48
- @Inject(ScriptEditorService) private readonly _scriptEditorService
49
- ) {}
50
-
51
- private _getEditor() {
52
- return this._scriptEditorService.getEditorInstance();
53
- }
54
- }
34
+ // Merge EnUS into your Univer locale map when this package contributes UI text.
55
35
  ```
56
36
 
57
- <!-- Links -->
58
- [npm-version-shield]: https://img.shields.io/npm/v/@univerjs/uniscript?style=flat-square
59
- [npm-version-link]: https://npmjs.com/package/@univerjs/uniscript
60
- [npm-license-shield]: https://img.shields.io/npm/l/@univerjs/uniscript?style=flat-square
61
- [npm-downloads-shield]: https://img.shields.io/npm/dm/@univerjs/uniscript?style=flat-square
37
+ ## Resources
38
+
39
+ - [Documentation](https://docs.univer.ai)
40
+ - [NPM package](https://npmjs.com/package/@univerjs/uniscript)
41
+ - [GitHub repository](https://github.com/dream-num/univer)
42
+
package/lib/cjs/index.js CHANGED
@@ -10,7 +10,7 @@ let react = require("react");
10
10
  let _univerjs_core_facade = require("@univerjs/core/facade");
11
11
  let react_jsx_runtime = require("react/jsx-runtime");
12
12
 
13
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
13
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
14
14
  function _typeof(o) {
15
15
  "@babel/helpers - typeof";
16
16
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -21,7 +21,7 @@ function _typeof(o) {
21
21
  }
22
22
 
23
23
  //#endregion
24
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
24
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
25
25
  function toPrimitive(t, r) {
26
26
  if ("object" != _typeof(t) || !t) return t;
27
27
  var e = t[Symbol.toPrimitive];
@@ -34,14 +34,14 @@ function toPrimitive(t, r) {
34
34
  }
35
35
 
36
36
  //#endregion
37
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
37
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
38
38
  function toPropertyKey(t) {
39
39
  var i = toPrimitive(t, "string");
40
40
  return "symbol" == _typeof(i) ? i : i + "";
41
41
  }
42
42
 
43
43
  //#endregion
44
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
44
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
45
45
  function _defineProperty(e, r, t) {
46
46
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
47
47
  value: t,
@@ -117,7 +117,7 @@ const ToggleScriptPanelOperation = {
117
117
  //#endregion
118
118
  //#region package.json
119
119
  var name = "@univerjs/uniscript";
120
- var version = "0.21.1";
120
+ var version = "0.22.0";
121
121
 
122
122
  //#endregion
123
123
  //#region src/config/config.ts
@@ -155,7 +155,7 @@ const menuSchema = { [_univerjs_ui.RibbonOthersGroup.OTHERS]: { [ToggleScriptPan
155
155
  } } };
156
156
 
157
157
  //#endregion
158
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
158
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
159
159
  function __decorateParam(paramIndex, decorator) {
160
160
  return function(target, key) {
161
161
  decorator(target, key, paramIndex);
@@ -163,7 +163,7 @@ function __decorateParam(paramIndex, decorator) {
163
163
  }
164
164
 
165
165
  //#endregion
166
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
166
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
167
167
  function __decorate(decorators, target, key, desc) {
168
168
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
169
169
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
package/lib/es/index.js CHANGED
@@ -9,7 +9,7 @@ import { useCallback, useEffect, useRef } from "react";
9
9
  import { FUniver } from "@univerjs/core/facade";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
11
11
 
12
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
12
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
13
13
  function _typeof(o) {
14
14
  "@babel/helpers - typeof";
15
15
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -20,7 +20,7 @@ function _typeof(o) {
20
20
  }
21
21
 
22
22
  //#endregion
23
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
23
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
24
24
  function toPrimitive(t, r) {
25
25
  if ("object" != _typeof(t) || !t) return t;
26
26
  var e = t[Symbol.toPrimitive];
@@ -33,14 +33,14 @@ function toPrimitive(t, r) {
33
33
  }
34
34
 
35
35
  //#endregion
36
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
36
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
37
37
  function toPropertyKey(t) {
38
38
  var i = toPrimitive(t, "string");
39
39
  return "symbol" == _typeof(i) ? i : i + "";
40
40
  }
41
41
 
42
42
  //#endregion
43
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
43
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
44
44
  function _defineProperty(e, r, t) {
45
45
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
46
46
  value: t,
@@ -116,7 +116,7 @@ const ToggleScriptPanelOperation = {
116
116
  //#endregion
117
117
  //#region package.json
118
118
  var name = "@univerjs/uniscript";
119
- var version = "0.21.1";
119
+ var version = "0.22.0";
120
120
 
121
121
  //#endregion
122
122
  //#region src/config/config.ts
@@ -154,7 +154,7 @@ const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.i
154
154
  } } };
155
155
 
156
156
  //#endregion
157
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
157
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
158
158
  function __decorateParam(paramIndex, decorator) {
159
159
  return function(target, key) {
160
160
  decorator(target, key, paramIndex);
@@ -162,7 +162,7 @@ function __decorateParam(paramIndex, decorator) {
162
162
  }
163
163
 
164
164
  //#endregion
165
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
165
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
166
166
  function __decorate(decorators, target, key, desc) {
167
167
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
168
168
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
package/lib/index.js CHANGED
@@ -9,7 +9,7 @@ import { useCallback, useEffect, useRef } from "react";
9
9
  import { FUniver } from "@univerjs/core/facade";
10
10
  import { jsx, jsxs } from "react/jsx-runtime";
11
11
 
12
- //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
12
+ //#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
13
13
  function _typeof(o) {
14
14
  "@babel/helpers - typeof";
15
15
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -20,7 +20,7 @@ function _typeof(o) {
20
20
  }
21
21
 
22
22
  //#endregion
23
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
23
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
24
24
  function toPrimitive(t, r) {
25
25
  if ("object" != _typeof(t) || !t) return t;
26
26
  var e = t[Symbol.toPrimitive];
@@ -33,14 +33,14 @@ function toPrimitive(t, r) {
33
33
  }
34
34
 
35
35
  //#endregion
36
- //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
36
+ //#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
37
37
  function toPropertyKey(t) {
38
38
  var i = toPrimitive(t, "string");
39
39
  return "symbol" == _typeof(i) ? i : i + "";
40
40
  }
41
41
 
42
42
  //#endregion
43
- //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
43
+ //#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
44
44
  function _defineProperty(e, r, t) {
45
45
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
46
46
  value: t,
@@ -116,7 +116,7 @@ const ToggleScriptPanelOperation = {
116
116
  //#endregion
117
117
  //#region package.json
118
118
  var name = "@univerjs/uniscript";
119
- var version = "0.21.1";
119
+ var version = "0.22.0";
120
120
 
121
121
  //#endregion
122
122
  //#region src/config/config.ts
@@ -154,7 +154,7 @@ const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.i
154
154
  } } };
155
155
 
156
156
  //#endregion
157
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
157
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorateParam.js
158
158
  function __decorateParam(paramIndex, decorator) {
159
159
  return function(target, key) {
160
160
  decorator(target, key, paramIndex);
@@ -162,7 +162,7 @@ function __decorateParam(paramIndex, decorator) {
162
162
  }
163
163
 
164
164
  //#endregion
165
- //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
165
+ //#region \0@oxc-project+runtime@0.129.0/helpers/decorate.js
166
166
  function __decorate(decorators, target, key, desc) {
167
167
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
168
168
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/sheets`),require(`@univerjs/sheets-ui`),require(`@univerjs/design`),require(`monaco-editor`),require(`react`),require(`@univerjs/core/facade`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/ui`,`rxjs`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/design`,`monaco-editor`,`react`,`@univerjs/core/facade`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverUniscript={},e.UniverCore,e.UniverUi,e.rxjs,e.UniverSheets,e.UniverSheetsUi,e.UniverDesign,e.monaco,e.React,e.UniverCoreFacade,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=class extends t.Disposable{constructor(...e){super(...e),m(this,`_open$`,new r.BehaviorSubject(!1)),m(this,`open$`,this._open$.pipe((0,r.distinctUntilChanged)()))}get isOpen(){return this._open$.getValue()}dispose(){super.dispose(),this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}};let g=`ScriptPanel`,_={type:t.CommandType.OPERATION,id:`univer.operation.toggle-script-panel`,handler:e=>{let t=e.get(h),r=e.get(n.ISidebarService);return t.isOpen?(t.close(),r.close()):(t.open(),r.open({header:{title:`script-panel.title`},children:{label:g},width:600})),!0}};var v=`@univerjs/uniscript`,y=`0.21.1`;let b=`uniscript.config`;Symbol(b);let x={};function S(e){return{id:_.id,title:`toggle-script-panel`,tooltip:`script-panel.tooltip.menu-button`,icon:`CodeIcon`,type:n.MenuItemType.BUTTON,hidden$:(0,n.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,a.getCurrentRangeDisable$)(e,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission,i.WorksheetSetCellValuePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}}let C={[n.RibbonOthersGroup.OTHERS]:{[_.id]:{order:0,menuItemFactory:S}}};function w(e,t){return function(n,r){t(n,r,e)}}function T(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let E=class extends t.Disposable{constructor(e){super(),this._configService=e,m(this,`_editorInstance`,null)}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(e){return this._editorInstance=e,(0,t.toDisposable)(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){let e=this._configService.getConfig(b);window.MonacoEnvironment={getWorkerUrl:e==null?void 0:e.getWorkerUrl}}}};E=T([w(0,t.IConfigService)],E);let D=(0,t.createIdentifier)(`univer.uniscript.execution-service`),O=class extends t.Disposable{constructor(e,t){super(),this._logService=e,this._injector=t}async execute(e){this._logService.log(`[UniscriptExecutionService]`,`executing Uniscript...`);let t=l.FUniver.newAPI(this._injector),n=Function(`univerAPI`,`(() => {${e}})()`);try{return n(t),!0}catch(e){return this._logService.error(e),!1}}};O=T([w(0,t.ILogService),w(1,(0,t.Inject)(t.Injector))],O);function k(){let e=(0,c.useRef)(null),r=(0,c.useRef)(null),i=(0,c.useRef)(null),a=(0,n.useDependency)(t.LocaleService),l=(0,n.useDependency)(n.IShortcutService),d=(0,n.useDependency)(E),f=(0,n.useDependency)(t.ThemeService);(0,c.useEffect)(()=>{let n=r.current,a=e.current,o=null,c=null;if(n&&a){d.requireVscodeEditor();let e=i.current=s.editor.create(n,{value:``,language:`javascript`,theme:f.darkMode?`vs-dark`:`vs-light`});c=new ResizeObserver(()=>{let t=requestIdleCallback(()=>{if(!t)return;let{height:n,width:r}=a.getBoundingClientRect();e.layout({width:r,height:n}),t=void 0})}),c.observe(a);let r;o=new t.DisposableCollection,o.add(d.setEditorInstance(e)),o.add(e.onDidFocusEditorWidget(()=>{r=l.forceEscape()})),o.add(e.onDidBlurEditorWidget(()=>{r==null||r.dispose(),r=void 0})),o.add((0,t.toDisposable)(()=>r==null?void 0:r.dispose()))}return()=>{c&&a&&c.unobserve(a),o==null||o.dispose()}},[d,l]);let p=A(i);return(0,u.jsxs)(`div`,{className:`univer-h-full`,children:[(0,u.jsx)(`div`,{ref:e,className:`univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden`,children:(0,u.jsx)(`div`,{ref:r})}),(0,u.jsx)(`div`,{className:`univer-mt-2.5`,children:(0,u.jsx)(o.Button,{variant:`primary`,onClick:p,children:a.t(`script-panel.panel.execute`)})})]})}function A(e){let r=(0,n.useDependency)(D),i=(0,n.useDependency)(n.IMessageService),a=(0,n.useDependency)(t.LocaleService);return(0,c.useCallback)(()=>{var t;let n=(t=e.current)==null?void 0:t.getModel();n&&r.execute(n.getValue()).then(()=>{i.show({content:a.t(`uniscript.message.success`),type:o.MessageType.Success})}).catch(()=>{i.show({content:a.t(`uniscript.message.failed`),type:o.MessageType.Error})})},[a,i,e,r])}let j=class extends t.Disposable{constructor(e,t,n){super(),this._menuManagerService=e,this._menuManagerService.mergeMenu(C),this.disposeWithMe(n.register(g,k)),this.disposeWithMe(t.registerCommand(_))}};j=T([w(0,n.IMenuManagerService),w(1,t.ICommandService),w(2,(0,t.Inject)(n.ComponentManager))],j);let M=class extends t.Plugin{constructor(e=x,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},x,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(b,a)}onStarting(){let e=this._injector;[[j],[E],[h]].forEach(t=>e.add(t)),this.registerExecution()}onSteady(){this._injector.get(j)}registerExecution(){this._injector.add([D,{useClass:O}])}};m(M,`pluginName`,`UNIVER_UNISCRIPT_PLUGIN`),m(M,`packageName`,v),m(M,`version`,y),M=T([w(1,(0,t.Inject)(t.Injector)),w(2,t.IConfigService)],M),e.IUniscriptExecutionService=D,Object.defineProperty(e,`ScriptEditorService`,{enumerable:!0,get:function(){return E}}),e.ToggleScriptPanelOperation=_,Object.defineProperty(e,`UniverUniscriptPlugin`,{enumerable:!0,get:function(){return M}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/sheets`),require(`@univerjs/sheets-ui`),require(`@univerjs/design`),require(`monaco-editor`),require(`react`),require(`@univerjs/core/facade`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/ui`,`rxjs`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/design`,`monaco-editor`,`react`,`@univerjs/core/facade`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverUniscript={},e.UniverCore,e.UniverUi,e.rxjs,e.UniverSheets,e.UniverSheetsUi,e.UniverDesign,e.monaco,e.React,e.UniverCoreFacade,e.React))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=class extends t.Disposable{constructor(...e){super(...e),m(this,`_open$`,new r.BehaviorSubject(!1)),m(this,`open$`,this._open$.pipe((0,r.distinctUntilChanged)()))}get isOpen(){return this._open$.getValue()}dispose(){super.dispose(),this._open$.next(!1),this._open$.complete()}open(){this._open$.next(!0)}close(){this._open$.next(!1)}};let g=`ScriptPanel`,_={type:t.CommandType.OPERATION,id:`univer.operation.toggle-script-panel`,handler:e=>{let t=e.get(h),r=e.get(n.ISidebarService);return t.isOpen?(t.close(),r.close()):(t.open(),r.open({header:{title:`script-panel.title`},children:{label:g},width:600})),!0}};var v=`@univerjs/uniscript`,y=`0.22.0`;let b=`uniscript.config`;Symbol(b);let x={};function S(e){return{id:_.id,title:`toggle-script-panel`,tooltip:`script-panel.tooltip.menu-button`,icon:`CodeIcon`,type:n.MenuItemType.BUTTON,hidden$:(0,n.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,a.getCurrentRangeDisable$)(e,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission,i.WorksheetSetCellValuePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}}let C={[n.RibbonOthersGroup.OTHERS]:{[_.id]:{order:0,menuItemFactory:S}}};function w(e,t){return function(n,r){t(n,r,e)}}function T(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let E=class extends t.Disposable{constructor(e){super(),this._configService=e,m(this,`_editorInstance`,null)}dispose(){super.dispose(),this._editorInstance&&this._editorInstance.dispose()}setEditorInstance(e){return this._editorInstance=e,(0,t.toDisposable)(()=>this._editorInstance=null)}getEditorInstance(){return this._editorInstance}requireVscodeEditor(){if(!window.MonacoEnvironment){let e=this._configService.getConfig(b);window.MonacoEnvironment={getWorkerUrl:e==null?void 0:e.getWorkerUrl}}}};E=T([w(0,t.IConfigService)],E);let D=(0,t.createIdentifier)(`univer.uniscript.execution-service`),O=class extends t.Disposable{constructor(e,t){super(),this._logService=e,this._injector=t}async execute(e){this._logService.log(`[UniscriptExecutionService]`,`executing Uniscript...`);let t=l.FUniver.newAPI(this._injector),n=Function(`univerAPI`,`(() => {${e}})()`);try{return n(t),!0}catch(e){return this._logService.error(e),!1}}};O=T([w(0,t.ILogService),w(1,(0,t.Inject)(t.Injector))],O);function k(){let e=(0,c.useRef)(null),r=(0,c.useRef)(null),i=(0,c.useRef)(null),a=(0,n.useDependency)(t.LocaleService),l=(0,n.useDependency)(n.IShortcutService),d=(0,n.useDependency)(E),f=(0,n.useDependency)(t.ThemeService);(0,c.useEffect)(()=>{let n=r.current,a=e.current,o=null,c=null;if(n&&a){d.requireVscodeEditor();let e=i.current=s.editor.create(n,{value:``,language:`javascript`,theme:f.darkMode?`vs-dark`:`vs-light`});c=new ResizeObserver(()=>{let t=requestIdleCallback(()=>{if(!t)return;let{height:n,width:r}=a.getBoundingClientRect();e.layout({width:r,height:n}),t=void 0})}),c.observe(a);let r;o=new t.DisposableCollection,o.add(d.setEditorInstance(e)),o.add(e.onDidFocusEditorWidget(()=>{r=l.forceEscape()})),o.add(e.onDidBlurEditorWidget(()=>{r==null||r.dispose(),r=void 0})),o.add((0,t.toDisposable)(()=>r==null?void 0:r.dispose()))}return()=>{c&&a&&c.unobserve(a),o==null||o.dispose()}},[d,l]);let p=A(i);return(0,u.jsxs)(`div`,{className:`univer-h-full`,children:[(0,u.jsx)(`div`,{ref:e,className:`univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden`,children:(0,u.jsx)(`div`,{ref:r})}),(0,u.jsx)(`div`,{className:`univer-mt-2.5`,children:(0,u.jsx)(o.Button,{variant:`primary`,onClick:p,children:a.t(`script-panel.panel.execute`)})})]})}function A(e){let r=(0,n.useDependency)(D),i=(0,n.useDependency)(n.IMessageService),a=(0,n.useDependency)(t.LocaleService);return(0,c.useCallback)(()=>{var t;let n=(t=e.current)==null?void 0:t.getModel();n&&r.execute(n.getValue()).then(()=>{i.show({content:a.t(`uniscript.message.success`),type:o.MessageType.Success})}).catch(()=>{i.show({content:a.t(`uniscript.message.failed`),type:o.MessageType.Error})})},[a,i,e,r])}let j=class extends t.Disposable{constructor(e,t,n){super(),this._menuManagerService=e,this._menuManagerService.mergeMenu(C),this.disposeWithMe(n.register(g,k)),this.disposeWithMe(t.registerCommand(_))}};j=T([w(0,n.IMenuManagerService),w(1,t.ICommandService),w(2,(0,t.Inject)(n.ComponentManager))],j);let M=class extends t.Plugin{constructor(e=x,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},x,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(b,a)}onStarting(){let e=this._injector;[[j],[E],[h]].forEach(t=>e.add(t)),this.registerExecution()}onSteady(){this._injector.get(j)}registerExecution(){this._injector.add([D,{useClass:O}])}};m(M,`pluginName`,`UNIVER_UNISCRIPT_PLUGIN`),m(M,`packageName`,v),m(M,`version`,y),M=T([w(1,(0,t.Inject)(t.Injector)),w(2,t.IConfigService)],M),e.IUniscriptExecutionService=D,Object.defineProperty(e,`ScriptEditorService`,{enumerable:!0,get:function(){return E}}),e.ToggleScriptPanelOperation=_,Object.defineProperty(e,`UniverUniscriptPlugin`,{enumerable:!0,get:function(){return M}})});
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@univerjs/uniscript",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
- "description": "UI component library for building exceptional Univer.",
6
- "author": "DreamNum <developer@univer.ai>",
5
+ "description": "Monaco-based scripting editor for operating Univer through Facade APIs.",
6
+ "author": "DreamNum Co., Ltd. <developer@univer.ai>",
7
7
  "license": "Apache-2.0",
8
8
  "funding": {
9
9
  "type": "opencollective",
@@ -18,7 +18,11 @@
18
18
  "url": "https://github.com/dream-num/univer/issues"
19
19
  },
20
20
  "keywords": [
21
- "univer"
21
+ "univer",
22
+ "uniscript",
23
+ "scripting",
24
+ "monaco-editor",
25
+ "automation"
22
26
  ],
23
27
  "exports": {
24
28
  ".": {
@@ -55,20 +59,20 @@
55
59
  },
56
60
  "dependencies": {
57
61
  "monaco-editor": "0.55.1",
58
- "@univerjs/core": "0.21.1",
59
- "@univerjs/design": "0.21.1",
60
- "@univerjs/sheets": "0.21.1",
61
- "@univerjs/sheets-ui": "0.21.1",
62
- "@univerjs/ui": "0.21.1"
62
+ "@univerjs/core": "0.22.0",
63
+ "@univerjs/design": "0.22.0",
64
+ "@univerjs/sheets": "0.22.0",
65
+ "@univerjs/sheets-ui": "0.22.0",
66
+ "@univerjs/ui": "0.22.0"
63
67
  },
64
68
  "devDependencies": {
65
- "postcss": "^8.5.10",
69
+ "postcss": "^8.5.14",
66
70
  "react": "18.3.1",
67
71
  "rxjs": "^7.8.2",
68
72
  "tailwindcss": "3.4.18",
69
- "typescript": "^6.0.2",
70
- "vitest": "^4.1.4",
71
- "@univerjs-infra/shared": "0.21.1"
73
+ "typescript": "^6.0.3",
74
+ "vitest": "^4.1.5",
75
+ "@univerjs-infra/shared": "0.22.0"
72
76
  },
73
77
  "scripts": {
74
78
  "test": "vitest run",