@univerjs/uniscript 0.25.0 → 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +76 -50
- package/lib/es/index.js +76 -50
- package/lib/index.js +76 -50
- package/lib/types/controllers/components.controller.d.ts +22 -0
- package/lib/types/controllers/uniscript.controller.d.ts +2 -2
- package/lib/types/locale/types.d.ts +18 -0
- package/lib/types/menu/menu.d.ts +2 -1
- package/lib/types/views/components/ScriptEditorPanel.d.ts +1 -1
- package/lib/types/views/components/ScriptEditorPanel.spec.d.ts +16 -0
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
package/lib/cjs/index.js
CHANGED
|
@@ -2,15 +2,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
let _univerjs_core = require("@univerjs/core");
|
|
3
3
|
let _univerjs_ui = require("@univerjs/ui");
|
|
4
4
|
let rxjs = require("rxjs");
|
|
5
|
-
let _univerjs_sheets = require("@univerjs/sheets");
|
|
6
|
-
let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
|
|
7
5
|
let _univerjs_design = require("@univerjs/design");
|
|
8
6
|
let monaco_editor = require("monaco-editor");
|
|
9
7
|
let react = require("react");
|
|
10
8
|
let _univerjs_core_facade = require("@univerjs/core/facade");
|
|
11
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
let _univerjs_sheets = require("@univerjs/sheets");
|
|
11
|
+
let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
|
|
12
12
|
|
|
13
|
-
//#region \0@oxc-project+runtime@0.
|
|
13
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
24
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
37
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
44
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
120
|
+
var version = "1.0.0-alpha.0";
|
|
121
121
|
|
|
122
122
|
//#endregion
|
|
123
123
|
//#region src/config/config.ts
|
|
@@ -126,36 +126,7 @@ const configSymbol = Symbol(UNISCRIPT_PLUGIN_CONFIG_KEY);
|
|
|
126
126
|
const defaultPluginConfig = {};
|
|
127
127
|
|
|
128
128
|
//#endregion
|
|
129
|
-
//#region
|
|
130
|
-
function UniscriptMenuItemFactory(accessor) {
|
|
131
|
-
return {
|
|
132
|
-
id: ToggleScriptPanelOperation.id,
|
|
133
|
-
title: "toggle-script-panel",
|
|
134
|
-
tooltip: "uniscript.tooltip.menu-button",
|
|
135
|
-
icon: "CodeIcon",
|
|
136
|
-
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
137
|
-
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
138
|
-
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
139
|
-
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
140
|
-
worksheetTypes: [
|
|
141
|
-
_univerjs_sheets.WorksheetEditPermission,
|
|
142
|
-
_univerjs_sheets.WorksheetSetCellStylePermission,
|
|
143
|
-
_univerjs_sheets.WorksheetSetCellValuePermission
|
|
144
|
-
],
|
|
145
|
-
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
146
|
-
})
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//#endregion
|
|
151
|
-
//#region src/menu/schema.ts
|
|
152
|
-
const menuSchema = { [_univerjs_ui.RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
|
|
153
|
-
order: 0,
|
|
154
|
-
menuItemFactory: UniscriptMenuItemFactory
|
|
155
|
-
} } };
|
|
156
|
-
|
|
157
|
-
//#endregion
|
|
158
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
129
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
159
130
|
function __decorateParam(paramIndex, decorator) {
|
|
160
131
|
return function(target, key) {
|
|
161
132
|
decorator(target, key, paramIndex);
|
|
@@ -163,7 +134,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
163
134
|
}
|
|
164
135
|
|
|
165
136
|
//#endregion
|
|
166
|
-
//#region \0@oxc-project+runtime@0.
|
|
137
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
167
138
|
function __decorate(decorators, target, key, desc) {
|
|
168
139
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
169
140
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -289,7 +260,7 @@ function ScriptEditorPanel() {
|
|
|
289
260
|
disposableCollection === null || disposableCollection === void 0 || disposableCollection.dispose();
|
|
290
261
|
};
|
|
291
262
|
}, [editorService, shortcutService]);
|
|
292
|
-
const startExecution = useExecution(monacoEditorRef);
|
|
263
|
+
const startExecution = useExecution((0, react.useCallback)(() => monacoEditorRef.current, []));
|
|
293
264
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
294
265
|
className: "univer-h-full",
|
|
295
266
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
@@ -306,13 +277,13 @@ function ScriptEditorPanel() {
|
|
|
306
277
|
})]
|
|
307
278
|
});
|
|
308
279
|
}
|
|
309
|
-
function useExecution(
|
|
280
|
+
function useExecution(getMonacoEditor) {
|
|
310
281
|
const scriptService = (0, _univerjs_ui.useDependency)(IUniscriptExecutionService);
|
|
311
282
|
const messageService = (0, _univerjs_ui.useDependency)(_univerjs_ui.IMessageService);
|
|
312
283
|
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
313
284
|
return (0, react.useCallback)(() => {
|
|
314
|
-
var
|
|
315
|
-
const model = (
|
|
285
|
+
var _getMonacoEditor;
|
|
286
|
+
const model = (_getMonacoEditor = getMonacoEditor()) === null || _getMonacoEditor === void 0 ? void 0 : _getMonacoEditor.getModel();
|
|
316
287
|
if (model) scriptService.execute(model.getValue()).then(() => {
|
|
317
288
|
messageService.show({
|
|
318
289
|
content: localeService.t("uniscript.message.success"),
|
|
@@ -325,13 +296,71 @@ function useExecution(monacoEditorRef) {
|
|
|
325
296
|
});
|
|
326
297
|
});
|
|
327
298
|
}, [
|
|
299
|
+
getMonacoEditor,
|
|
328
300
|
localeService,
|
|
329
301
|
messageService,
|
|
330
|
-
monacoEditorRef,
|
|
331
302
|
scriptService
|
|
332
303
|
]);
|
|
333
304
|
}
|
|
334
305
|
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region src/controllers/components.controller.ts
|
|
308
|
+
/**
|
|
309
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
310
|
+
*
|
|
311
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
312
|
+
* you may not use this file except in compliance with the License.
|
|
313
|
+
* You may obtain a copy of the License at
|
|
314
|
+
*
|
|
315
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
316
|
+
*
|
|
317
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
318
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
319
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
320
|
+
* See the License for the specific language governing permissions and
|
|
321
|
+
* limitations under the License.
|
|
322
|
+
*/
|
|
323
|
+
let ComponentsController = class ComponentsController extends _univerjs_core.Disposable {
|
|
324
|
+
constructor(_componentManager) {
|
|
325
|
+
super();
|
|
326
|
+
this._componentManager = _componentManager;
|
|
327
|
+
this._registerComponents();
|
|
328
|
+
}
|
|
329
|
+
_registerComponents() {
|
|
330
|
+
this.disposeWithMe(this._componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
ComponentsController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))], ComponentsController);
|
|
334
|
+
|
|
335
|
+
//#endregion
|
|
336
|
+
//#region src/menu/menu.ts
|
|
337
|
+
function UniscriptMenuItemFactory(accessor) {
|
|
338
|
+
return {
|
|
339
|
+
id: ToggleScriptPanelOperation.id,
|
|
340
|
+
title: "uniscript.title",
|
|
341
|
+
tooltip: "uniscript.tooltip.menu-button",
|
|
342
|
+
icon: "CodeIcon",
|
|
343
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
344
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
345
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
346
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
347
|
+
worksheetTypes: [
|
|
348
|
+
_univerjs_sheets.WorksheetEditPermission,
|
|
349
|
+
_univerjs_sheets.WorksheetSetCellStylePermission,
|
|
350
|
+
_univerjs_sheets.WorksheetSetCellValuePermission
|
|
351
|
+
],
|
|
352
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
353
|
+
})
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/menu/schema.ts
|
|
359
|
+
const menuSchema = { [_univerjs_ui.RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
|
|
360
|
+
order: 0,
|
|
361
|
+
menuItemFactory: UniscriptMenuItemFactory
|
|
362
|
+
} } };
|
|
363
|
+
|
|
335
364
|
//#endregion
|
|
336
365
|
//#region src/controllers/uniscript.controller.ts
|
|
337
366
|
/**
|
|
@@ -350,19 +379,14 @@ function useExecution(monacoEditorRef) {
|
|
|
350
379
|
* limitations under the License.
|
|
351
380
|
*/
|
|
352
381
|
let UniscriptController = class UniscriptController extends _univerjs_core.Disposable {
|
|
353
|
-
constructor(_menuManagerService, commandService
|
|
382
|
+
constructor(_menuManagerService, commandService) {
|
|
354
383
|
super();
|
|
355
384
|
this._menuManagerService = _menuManagerService;
|
|
356
385
|
this._menuManagerService.mergeMenu(menuSchema);
|
|
357
|
-
this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
|
|
358
386
|
this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
|
|
359
387
|
}
|
|
360
388
|
};
|
|
361
|
-
UniscriptController = __decorate([
|
|
362
|
-
__decorateParam(0, _univerjs_ui.IMenuManagerService),
|
|
363
|
-
__decorateParam(1, _univerjs_core.ICommandService),
|
|
364
|
-
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager))
|
|
365
|
-
], UniscriptController);
|
|
389
|
+
UniscriptController = __decorate([__decorateParam(0, _univerjs_ui.IMenuManagerService), __decorateParam(1, _univerjs_core.ICommandService)], UniscriptController);
|
|
366
390
|
|
|
367
391
|
//#endregion
|
|
368
392
|
//#region src/plugin.ts
|
|
@@ -379,11 +403,13 @@ let UniverUniscriptPlugin = class UniverUniscriptPlugin extends _univerjs_core.P
|
|
|
379
403
|
onStarting() {
|
|
380
404
|
const injector = this._injector;
|
|
381
405
|
[
|
|
406
|
+
[ComponentsController],
|
|
382
407
|
[UniscriptController],
|
|
383
408
|
[ScriptEditorService],
|
|
384
409
|
[ScriptPanelService]
|
|
385
410
|
].forEach((d) => injector.add(d));
|
|
386
411
|
this.registerExecution();
|
|
412
|
+
this._injector.get(ComponentsController);
|
|
387
413
|
}
|
|
388
414
|
onSteady() {
|
|
389
415
|
this._injector.get(UniscriptController);
|
package/lib/es/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { CommandType, Disposable, DisposableCollection, ICommandService, IConfigService, ILogService, Inject, Injector, LocaleService, Plugin, ThemeService, UniverInstanceType, createIdentifier, merge, toDisposable } from "@univerjs/core";
|
|
2
2
|
import { ComponentManager, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, MenuItemType, RibbonOthersGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
3
3
|
import { BehaviorSubject, distinctUntilChanged } from "rxjs";
|
|
4
|
-
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
|
|
5
|
-
import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
|
|
6
4
|
import { Button, MessageType } from "@univerjs/design";
|
|
7
5
|
import { editor } from "monaco-editor";
|
|
8
6
|
import { useCallback, useEffect, useRef } from "react";
|
|
9
7
|
import { FUniver } from "@univerjs/core/facade";
|
|
10
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
|
|
10
|
+
import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
|
|
11
11
|
|
|
12
|
-
//#region \0@oxc-project+runtime@0.
|
|
12
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
23
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
36
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
43
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
119
|
+
var version = "1.0.0-alpha.0";
|
|
120
120
|
|
|
121
121
|
//#endregion
|
|
122
122
|
//#region src/config/config.ts
|
|
@@ -125,36 +125,7 @@ const configSymbol = Symbol(UNISCRIPT_PLUGIN_CONFIG_KEY);
|
|
|
125
125
|
const defaultPluginConfig = {};
|
|
126
126
|
|
|
127
127
|
//#endregion
|
|
128
|
-
//#region
|
|
129
|
-
function UniscriptMenuItemFactory(accessor) {
|
|
130
|
-
return {
|
|
131
|
-
id: ToggleScriptPanelOperation.id,
|
|
132
|
-
title: "toggle-script-panel",
|
|
133
|
-
tooltip: "uniscript.tooltip.menu-button",
|
|
134
|
-
icon: "CodeIcon",
|
|
135
|
-
type: MenuItemType.BUTTON,
|
|
136
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
137
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
138
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
139
|
-
worksheetTypes: [
|
|
140
|
-
WorksheetEditPermission,
|
|
141
|
-
WorksheetSetCellStylePermission,
|
|
142
|
-
WorksheetSetCellValuePermission
|
|
143
|
-
],
|
|
144
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
145
|
-
})
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/menu/schema.ts
|
|
151
|
-
const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
|
|
152
|
-
order: 0,
|
|
153
|
-
menuItemFactory: UniscriptMenuItemFactory
|
|
154
|
-
} } };
|
|
155
|
-
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
128
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
158
129
|
function __decorateParam(paramIndex, decorator) {
|
|
159
130
|
return function(target, key) {
|
|
160
131
|
decorator(target, key, paramIndex);
|
|
@@ -162,7 +133,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
162
133
|
}
|
|
163
134
|
|
|
164
135
|
//#endregion
|
|
165
|
-
//#region \0@oxc-project+runtime@0.
|
|
136
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
166
137
|
function __decorate(decorators, target, key, desc) {
|
|
167
138
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
168
139
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -288,7 +259,7 @@ function ScriptEditorPanel() {
|
|
|
288
259
|
disposableCollection === null || disposableCollection === void 0 || disposableCollection.dispose();
|
|
289
260
|
};
|
|
290
261
|
}, [editorService, shortcutService]);
|
|
291
|
-
const startExecution = useExecution(monacoEditorRef);
|
|
262
|
+
const startExecution = useExecution(useCallback(() => monacoEditorRef.current, []));
|
|
292
263
|
return /* @__PURE__ */ jsxs("div", {
|
|
293
264
|
className: "univer-h-full",
|
|
294
265
|
children: [/* @__PURE__ */ jsx("div", {
|
|
@@ -305,13 +276,13 @@ function ScriptEditorPanel() {
|
|
|
305
276
|
})]
|
|
306
277
|
});
|
|
307
278
|
}
|
|
308
|
-
function useExecution(
|
|
279
|
+
function useExecution(getMonacoEditor) {
|
|
309
280
|
const scriptService = useDependency(IUniscriptExecutionService);
|
|
310
281
|
const messageService = useDependency(IMessageService);
|
|
311
282
|
const localeService = useDependency(LocaleService);
|
|
312
283
|
return useCallback(() => {
|
|
313
|
-
var
|
|
314
|
-
const model = (
|
|
284
|
+
var _getMonacoEditor;
|
|
285
|
+
const model = (_getMonacoEditor = getMonacoEditor()) === null || _getMonacoEditor === void 0 ? void 0 : _getMonacoEditor.getModel();
|
|
315
286
|
if (model) scriptService.execute(model.getValue()).then(() => {
|
|
316
287
|
messageService.show({
|
|
317
288
|
content: localeService.t("uniscript.message.success"),
|
|
@@ -324,13 +295,71 @@ function useExecution(monacoEditorRef) {
|
|
|
324
295
|
});
|
|
325
296
|
});
|
|
326
297
|
}, [
|
|
298
|
+
getMonacoEditor,
|
|
327
299
|
localeService,
|
|
328
300
|
messageService,
|
|
329
|
-
monacoEditorRef,
|
|
330
301
|
scriptService
|
|
331
302
|
]);
|
|
332
303
|
}
|
|
333
304
|
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/controllers/components.controller.ts
|
|
307
|
+
/**
|
|
308
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
309
|
+
*
|
|
310
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
311
|
+
* you may not use this file except in compliance with the License.
|
|
312
|
+
* You may obtain a copy of the License at
|
|
313
|
+
*
|
|
314
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
315
|
+
*
|
|
316
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
317
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
318
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
319
|
+
* See the License for the specific language governing permissions and
|
|
320
|
+
* limitations under the License.
|
|
321
|
+
*/
|
|
322
|
+
let ComponentsController = class ComponentsController extends Disposable {
|
|
323
|
+
constructor(_componentManager) {
|
|
324
|
+
super();
|
|
325
|
+
this._componentManager = _componentManager;
|
|
326
|
+
this._registerComponents();
|
|
327
|
+
}
|
|
328
|
+
_registerComponents() {
|
|
329
|
+
this.disposeWithMe(this._componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))], ComponentsController);
|
|
333
|
+
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/menu/menu.ts
|
|
336
|
+
function UniscriptMenuItemFactory(accessor) {
|
|
337
|
+
return {
|
|
338
|
+
id: ToggleScriptPanelOperation.id,
|
|
339
|
+
title: "uniscript.title",
|
|
340
|
+
tooltip: "uniscript.tooltip.menu-button",
|
|
341
|
+
icon: "CodeIcon",
|
|
342
|
+
type: MenuItemType.BUTTON,
|
|
343
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
344
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
345
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
346
|
+
worksheetTypes: [
|
|
347
|
+
WorksheetEditPermission,
|
|
348
|
+
WorksheetSetCellStylePermission,
|
|
349
|
+
WorksheetSetCellValuePermission
|
|
350
|
+
],
|
|
351
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
352
|
+
})
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/menu/schema.ts
|
|
358
|
+
const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
|
|
359
|
+
order: 0,
|
|
360
|
+
menuItemFactory: UniscriptMenuItemFactory
|
|
361
|
+
} } };
|
|
362
|
+
|
|
334
363
|
//#endregion
|
|
335
364
|
//#region src/controllers/uniscript.controller.ts
|
|
336
365
|
/**
|
|
@@ -349,19 +378,14 @@ function useExecution(monacoEditorRef) {
|
|
|
349
378
|
* limitations under the License.
|
|
350
379
|
*/
|
|
351
380
|
let UniscriptController = class UniscriptController extends Disposable {
|
|
352
|
-
constructor(_menuManagerService, commandService
|
|
381
|
+
constructor(_menuManagerService, commandService) {
|
|
353
382
|
super();
|
|
354
383
|
this._menuManagerService = _menuManagerService;
|
|
355
384
|
this._menuManagerService.mergeMenu(menuSchema);
|
|
356
|
-
this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
|
|
357
385
|
this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
|
|
358
386
|
}
|
|
359
387
|
};
|
|
360
|
-
UniscriptController = __decorate([
|
|
361
|
-
__decorateParam(0, IMenuManagerService),
|
|
362
|
-
__decorateParam(1, ICommandService),
|
|
363
|
-
__decorateParam(2, Inject(ComponentManager))
|
|
364
|
-
], UniscriptController);
|
|
388
|
+
UniscriptController = __decorate([__decorateParam(0, IMenuManagerService), __decorateParam(1, ICommandService)], UniscriptController);
|
|
365
389
|
|
|
366
390
|
//#endregion
|
|
367
391
|
//#region src/plugin.ts
|
|
@@ -378,11 +402,13 @@ let UniverUniscriptPlugin = class UniverUniscriptPlugin extends Plugin {
|
|
|
378
402
|
onStarting() {
|
|
379
403
|
const injector = this._injector;
|
|
380
404
|
[
|
|
405
|
+
[ComponentsController],
|
|
381
406
|
[UniscriptController],
|
|
382
407
|
[ScriptEditorService],
|
|
383
408
|
[ScriptPanelService]
|
|
384
409
|
].forEach((d) => injector.add(d));
|
|
385
410
|
this.registerExecution();
|
|
411
|
+
this._injector.get(ComponentsController);
|
|
386
412
|
}
|
|
387
413
|
onSteady() {
|
|
388
414
|
this._injector.get(UniscriptController);
|
package/lib/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { CommandType, Disposable, DisposableCollection, ICommandService, IConfigService, ILogService, Inject, Injector, LocaleService, Plugin, ThemeService, UniverInstanceType, createIdentifier, merge, toDisposable } from "@univerjs/core";
|
|
2
2
|
import { ComponentManager, IMenuManagerService, IMessageService, IShortcutService, ISidebarService, MenuItemType, RibbonOthersGroup, getMenuHiddenObservable, useDependency } from "@univerjs/ui";
|
|
3
3
|
import { BehaviorSubject, distinctUntilChanged } from "rxjs";
|
|
4
|
-
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
|
|
5
|
-
import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
|
|
6
4
|
import { Button, MessageType } from "@univerjs/design";
|
|
7
5
|
import { editor } from "monaco-editor";
|
|
8
6
|
import { useCallback, useEffect, useRef } from "react";
|
|
9
7
|
import { FUniver } from "@univerjs/core/facade";
|
|
10
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { RangeProtectionPermissionEditPoint, WorkbookEditablePermission, WorksheetEditPermission, WorksheetSetCellStylePermission, WorksheetSetCellValuePermission } from "@univerjs/sheets";
|
|
10
|
+
import { getCurrentRangeDisable$ } from "@univerjs/sheets-ui";
|
|
11
11
|
|
|
12
|
-
//#region \0@oxc-project+runtime@0.
|
|
12
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
23
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
36
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
43
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/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.
|
|
119
|
+
var version = "1.0.0-alpha.0";
|
|
120
120
|
|
|
121
121
|
//#endregion
|
|
122
122
|
//#region src/config/config.ts
|
|
@@ -125,36 +125,7 @@ const configSymbol = Symbol(UNISCRIPT_PLUGIN_CONFIG_KEY);
|
|
|
125
125
|
const defaultPluginConfig = {};
|
|
126
126
|
|
|
127
127
|
//#endregion
|
|
128
|
-
//#region
|
|
129
|
-
function UniscriptMenuItemFactory(accessor) {
|
|
130
|
-
return {
|
|
131
|
-
id: ToggleScriptPanelOperation.id,
|
|
132
|
-
title: "toggle-script-panel",
|
|
133
|
-
tooltip: "uniscript.tooltip.menu-button",
|
|
134
|
-
icon: "CodeIcon",
|
|
135
|
-
type: MenuItemType.BUTTON,
|
|
136
|
-
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
137
|
-
disabled$: getCurrentRangeDisable$(accessor, {
|
|
138
|
-
workbookTypes: [WorkbookEditablePermission],
|
|
139
|
-
worksheetTypes: [
|
|
140
|
-
WorksheetEditPermission,
|
|
141
|
-
WorksheetSetCellStylePermission,
|
|
142
|
-
WorksheetSetCellValuePermission
|
|
143
|
-
],
|
|
144
|
-
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
145
|
-
})
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
//#endregion
|
|
150
|
-
//#region src/menu/schema.ts
|
|
151
|
-
const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
|
|
152
|
-
order: 0,
|
|
153
|
-
menuItemFactory: UniscriptMenuItemFactory
|
|
154
|
-
} } };
|
|
155
|
-
|
|
156
|
-
//#endregion
|
|
157
|
-
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/decorateParam.js
|
|
128
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
|
|
158
129
|
function __decorateParam(paramIndex, decorator) {
|
|
159
130
|
return function(target, key) {
|
|
160
131
|
decorator(target, key, paramIndex);
|
|
@@ -162,7 +133,7 @@ function __decorateParam(paramIndex, decorator) {
|
|
|
162
133
|
}
|
|
163
134
|
|
|
164
135
|
//#endregion
|
|
165
|
-
//#region \0@oxc-project+runtime@0.
|
|
136
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
|
|
166
137
|
function __decorate(decorators, target, key, desc) {
|
|
167
138
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
168
139
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -288,7 +259,7 @@ function ScriptEditorPanel() {
|
|
|
288
259
|
disposableCollection === null || disposableCollection === void 0 || disposableCollection.dispose();
|
|
289
260
|
};
|
|
290
261
|
}, [editorService, shortcutService]);
|
|
291
|
-
const startExecution = useExecution(monacoEditorRef);
|
|
262
|
+
const startExecution = useExecution(useCallback(() => monacoEditorRef.current, []));
|
|
292
263
|
return /* @__PURE__ */ jsxs("div", {
|
|
293
264
|
className: "univer-h-full",
|
|
294
265
|
children: [/* @__PURE__ */ jsx("div", {
|
|
@@ -305,13 +276,13 @@ function ScriptEditorPanel() {
|
|
|
305
276
|
})]
|
|
306
277
|
});
|
|
307
278
|
}
|
|
308
|
-
function useExecution(
|
|
279
|
+
function useExecution(getMonacoEditor) {
|
|
309
280
|
const scriptService = useDependency(IUniscriptExecutionService);
|
|
310
281
|
const messageService = useDependency(IMessageService);
|
|
311
282
|
const localeService = useDependency(LocaleService);
|
|
312
283
|
return useCallback(() => {
|
|
313
|
-
var
|
|
314
|
-
const model = (
|
|
284
|
+
var _getMonacoEditor;
|
|
285
|
+
const model = (_getMonacoEditor = getMonacoEditor()) === null || _getMonacoEditor === void 0 ? void 0 : _getMonacoEditor.getModel();
|
|
315
286
|
if (model) scriptService.execute(model.getValue()).then(() => {
|
|
316
287
|
messageService.show({
|
|
317
288
|
content: localeService.t("uniscript.message.success"),
|
|
@@ -324,13 +295,71 @@ function useExecution(monacoEditorRef) {
|
|
|
324
295
|
});
|
|
325
296
|
});
|
|
326
297
|
}, [
|
|
298
|
+
getMonacoEditor,
|
|
327
299
|
localeService,
|
|
328
300
|
messageService,
|
|
329
|
-
monacoEditorRef,
|
|
330
301
|
scriptService
|
|
331
302
|
]);
|
|
332
303
|
}
|
|
333
304
|
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/controllers/components.controller.ts
|
|
307
|
+
/**
|
|
308
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
309
|
+
*
|
|
310
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
311
|
+
* you may not use this file except in compliance with the License.
|
|
312
|
+
* You may obtain a copy of the License at
|
|
313
|
+
*
|
|
314
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
315
|
+
*
|
|
316
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
317
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
318
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
319
|
+
* See the License for the specific language governing permissions and
|
|
320
|
+
* limitations under the License.
|
|
321
|
+
*/
|
|
322
|
+
let ComponentsController = class ComponentsController extends Disposable {
|
|
323
|
+
constructor(_componentManager) {
|
|
324
|
+
super();
|
|
325
|
+
this._componentManager = _componentManager;
|
|
326
|
+
this._registerComponents();
|
|
327
|
+
}
|
|
328
|
+
_registerComponents() {
|
|
329
|
+
this.disposeWithMe(this._componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
ComponentsController = __decorate([__decorateParam(0, Inject(ComponentManager))], ComponentsController);
|
|
333
|
+
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/menu/menu.ts
|
|
336
|
+
function UniscriptMenuItemFactory(accessor) {
|
|
337
|
+
return {
|
|
338
|
+
id: ToggleScriptPanelOperation.id,
|
|
339
|
+
title: "uniscript.title",
|
|
340
|
+
tooltip: "uniscript.tooltip.menu-button",
|
|
341
|
+
icon: "CodeIcon",
|
|
342
|
+
type: MenuItemType.BUTTON,
|
|
343
|
+
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_SHEET),
|
|
344
|
+
disabled$: getCurrentRangeDisable$(accessor, {
|
|
345
|
+
workbookTypes: [WorkbookEditablePermission],
|
|
346
|
+
worksheetTypes: [
|
|
347
|
+
WorksheetEditPermission,
|
|
348
|
+
WorksheetSetCellStylePermission,
|
|
349
|
+
WorksheetSetCellValuePermission
|
|
350
|
+
],
|
|
351
|
+
rangeTypes: [RangeProtectionPermissionEditPoint]
|
|
352
|
+
})
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/menu/schema.ts
|
|
358
|
+
const menuSchema = { [RibbonOthersGroup.OTHERS]: { [ToggleScriptPanelOperation.id]: {
|
|
359
|
+
order: 0,
|
|
360
|
+
menuItemFactory: UniscriptMenuItemFactory
|
|
361
|
+
} } };
|
|
362
|
+
|
|
334
363
|
//#endregion
|
|
335
364
|
//#region src/controllers/uniscript.controller.ts
|
|
336
365
|
/**
|
|
@@ -349,19 +378,14 @@ function useExecution(monacoEditorRef) {
|
|
|
349
378
|
* limitations under the License.
|
|
350
379
|
*/
|
|
351
380
|
let UniscriptController = class UniscriptController extends Disposable {
|
|
352
|
-
constructor(_menuManagerService, commandService
|
|
381
|
+
constructor(_menuManagerService, commandService) {
|
|
353
382
|
super();
|
|
354
383
|
this._menuManagerService = _menuManagerService;
|
|
355
384
|
this._menuManagerService.mergeMenu(menuSchema);
|
|
356
|
-
this.disposeWithMe(componentManager.register(ScriptPanelComponentName, ScriptEditorPanel));
|
|
357
385
|
this.disposeWithMe(commandService.registerCommand(ToggleScriptPanelOperation));
|
|
358
386
|
}
|
|
359
387
|
};
|
|
360
|
-
UniscriptController = __decorate([
|
|
361
|
-
__decorateParam(0, IMenuManagerService),
|
|
362
|
-
__decorateParam(1, ICommandService),
|
|
363
|
-
__decorateParam(2, Inject(ComponentManager))
|
|
364
|
-
], UniscriptController);
|
|
388
|
+
UniscriptController = __decorate([__decorateParam(0, IMenuManagerService), __decorateParam(1, ICommandService)], UniscriptController);
|
|
365
389
|
|
|
366
390
|
//#endregion
|
|
367
391
|
//#region src/plugin.ts
|
|
@@ -378,11 +402,13 @@ let UniverUniscriptPlugin = class UniverUniscriptPlugin extends Plugin {
|
|
|
378
402
|
onStarting() {
|
|
379
403
|
const injector = this._injector;
|
|
380
404
|
[
|
|
405
|
+
[ComponentsController],
|
|
381
406
|
[UniscriptController],
|
|
382
407
|
[ScriptEditorService],
|
|
383
408
|
[ScriptPanelService]
|
|
384
409
|
].forEach((d) => injector.add(d));
|
|
385
410
|
this.registerExecution();
|
|
411
|
+
this._injector.get(ComponentsController);
|
|
386
412
|
}
|
|
387
413
|
onSteady() {
|
|
388
414
|
this._injector.get(UniscriptController);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Disposable } from '@univerjs/core';
|
|
17
|
+
import { ComponentManager } from '@univerjs/ui';
|
|
18
|
+
export declare class ComponentsController extends Disposable {
|
|
19
|
+
private readonly _componentManager;
|
|
20
|
+
constructor(_componentManager: ComponentManager);
|
|
21
|
+
private _registerComponents;
|
|
22
|
+
}
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Disposable, ICommandService } from '@univerjs/core';
|
|
17
|
-
import {
|
|
17
|
+
import { IMenuManagerService } from '@univerjs/ui';
|
|
18
18
|
export declare class UniscriptController extends Disposable {
|
|
19
19
|
private readonly _menuManagerService;
|
|
20
|
-
constructor(_menuManagerService: IMenuManagerService, commandService: ICommandService
|
|
20
|
+
constructor(_menuManagerService: IMenuManagerService, commandService: ICommandService);
|
|
21
21
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { LocaleLeafKeys } from '@univerjs/core';
|
|
17
|
+
import type enUS from './en-US';
|
|
18
|
+
export type LocaleKey = LocaleLeafKeys<typeof enUS>;
|
package/lib/types/menu/menu.d.ts
CHANGED
|
@@ -15,4 +15,5 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import type { IAccessor } from '@univerjs/core';
|
|
17
17
|
import type { IMenuButtonItem } from '@univerjs/ui';
|
|
18
|
-
|
|
18
|
+
import type { LocaleKey } from '../locale/types';
|
|
19
|
+
export declare function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem<LocaleKey>;
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
export declare function ScriptEditorPanel(): import("react
|
|
16
|
+
export declare function ScriptEditorPanel(): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
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/
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/design"),require("monaco-editor"),require("react"),require("@univerjs/core/facade"),require("react/jsx-runtime"),require("@univerjs/sheets"),require("@univerjs/sheets-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`monaco-editor`,`react`,`@univerjs/core/facade`,`react/jsx-runtime`,`@univerjs/sheets`,`@univerjs/sheets-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverUniscript={},e.UniverCore,e.UniverUi,e.rxjs,e.UniverDesign,e.monaco,e.React,e.UniverCoreFacade,e.React,e.UniverSheets,e.UniverSheetsUi))})(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:`uniscript.title`},children:{label:g},width:600})),!0}};var v=`@univerjs/uniscript`,y=`1.0.0-alpha.0`;let b=`uniscript.config`,x={};function S(e,t){return function(n,r){t(n,r,e)}}function C(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 w=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}}}};w=C([S(0,t.IConfigService)],w);let T=(0,t.createIdentifier)(`univer.uniscript.execution-service`),E=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=s.FUniver.newAPI(this._injector),n=Function(`univerAPI`,`(() => {${e}})()`);try{return n(t),!0}catch(e){return this._logService.error(e),!1}}};E=C([S(0,t.ILogService),S(1,(0,t.Inject)(t.Injector))],E);function D(){let e=(0,o.useRef)(null),r=(0,o.useRef)(null),s=(0,o.useRef)(null),l=(0,n.useDependency)(t.LocaleService),u=(0,n.useDependency)(n.IShortcutService),d=(0,n.useDependency)(w),f=(0,n.useDependency)(t.ThemeService);(0,o.useEffect)(()=>{let n=r.current,i=e.current,o=null,c=null;if(n&&i){d.requireVscodeEditor();let e=s.current=a.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}=i.getBoundingClientRect();e.layout({width:r,height:n}),t=void 0})}),c.observe(i);let r;o=new t.DisposableCollection,o.add(d.setEditorInstance(e)),o.add(e.onDidFocusEditorWidget(()=>{r=u.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&&i&&c.unobserve(i),o==null||o.dispose()}},[d,u]);let p=O((0,o.useCallback)(()=>s.current,[]));return(0,c.jsxs)(`div`,{className:`univer-h-full`,children:[(0,c.jsx)(`div`,{ref:e,className:`univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden`,children:(0,c.jsx)(`div`,{ref:r})}),(0,c.jsx)(`div`,{className:`univer-mt-2.5`,children:(0,c.jsx)(i.Button,{variant:`primary`,onClick:p,children:l.t(`uniscript.panel.execute`)})})]})}function O(e){let r=(0,n.useDependency)(T),a=(0,n.useDependency)(n.IMessageService),s=(0,n.useDependency)(t.LocaleService);return(0,o.useCallback)(()=>{var t;let n=(t=e())==null?void 0:t.getModel();n&&r.execute(n.getValue()).then(()=>{a.show({content:s.t(`uniscript.message.success`),type:i.MessageType.Success})}).catch(()=>{a.show({content:s.t(`uniscript.message.failed`),type:i.MessageType.Error})})},[e,s,a,r])}let k=class extends t.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(g,D))}};k=C([S(0,(0,t.Inject)(n.ComponentManager))],k);function A(e){return{id:_.id,title:`uniscript.title`,tooltip:`uniscript.tooltip.menu-button`,icon:`CodeIcon`,type:n.MenuItemType.BUTTON,hidden$:(0,n.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,u.getCurrentRangeDisable$)(e,{workbookTypes:[l.WorkbookEditablePermission],worksheetTypes:[l.WorksheetEditPermission,l.WorksheetSetCellStylePermission,l.WorksheetSetCellValuePermission],rangeTypes:[l.RangeProtectionPermissionEditPoint]})}}let j={[n.RibbonOthersGroup.OTHERS]:{[_.id]:{order:0,menuItemFactory:A}}},M=class extends t.Disposable{constructor(e,t){super(),this._menuManagerService=e,this._menuManagerService.mergeMenu(j),this.disposeWithMe(t.registerCommand(_))}};M=C([S(0,n.IMenuManagerService),S(1,t.ICommandService)],M);let N=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;[[k],[M],[w],[h]].forEach(t=>e.add(t)),this.registerExecution(),this._injector.get(k)}onSteady(){this._injector.get(M)}registerExecution(){this._injector.add([T,{useClass:E}])}};m(N,`pluginName`,`UNIVER_UNISCRIPT_PLUGIN`),m(N,`packageName`,v),m(N,`version`,y),N=C([S(1,(0,t.Inject)(t.Injector)),S(2,t.IConfigService)],N),e.IUniscriptExecutionService=T,Object.defineProperty(e,"ScriptEditorService",{enumerable:!0,get:function(){return w}}),e.ToggleScriptPanelOperation=_,Object.defineProperty(e,"UniverUniscriptPlugin",{enumerable:!0,get:function(){return N}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/uniscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Monaco-based scripting editor for operating Univer through Facade APIs.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
61
|
"monaco-editor": "0.55.1",
|
|
62
|
-
"@univerjs/core": "0.
|
|
63
|
-
"@univerjs/design": "0.
|
|
64
|
-
"@univerjs/sheets
|
|
65
|
-
"@univerjs/ui": "0.
|
|
66
|
-
"@univerjs/
|
|
62
|
+
"@univerjs/core": "1.0.0-alpha.0",
|
|
63
|
+
"@univerjs/design": "1.0.0-alpha.0",
|
|
64
|
+
"@univerjs/sheets": "1.0.0-alpha.0",
|
|
65
|
+
"@univerjs/sheets-ui": "1.0.0-alpha.0",
|
|
66
|
+
"@univerjs/ui": "1.0.0-alpha.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"postcss": "^8.5.15",
|
|
@@ -71,8 +71,8 @@
|
|
|
71
71
|
"rxjs": "^7.8.2",
|
|
72
72
|
"tailwindcss": "3.4.18",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
|
-
"vitest": "^4.1.
|
|
75
|
-
"@univerjs-infra/shared": "0.
|
|
74
|
+
"vitest": "^4.1.9",
|
|
75
|
+
"@univerjs-infra/shared": "1.0.0-alpha.0"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"test": "vitest run",
|