@univerjs/uniscript 0.6.7 → 0.6.9
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/index.js +236 -0
- package/lib/locale/en-US.js +20 -0
- package/lib/locale/fa-IR.js +20 -0
- package/lib/locale/fr-FR.js +20 -0
- package/lib/locale/ru-RU.js +20 -0
- package/lib/locale/vi-VN.js +20 -0
- package/lib/locale/zh-CN.js +20 -0
- package/lib/locale/zh-TW.js +20 -0
- package/package.json +8 -8
package/lib/index.js
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
var B = Object.defineProperty;
|
2
|
+
var G = (t, e, r) => e in t ? B(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
3
|
+
var p = (t, e, r) => G(t, typeof e != "symbol" ? e + "" : e, r);
|
4
|
+
import { Disposable as _, CommandType as L, toDisposable as j, IConfigService as M, createIdentifier as A, ILogService as q, Inject as E, Injector as N, LocaleService as D, DisposableCollection as z, UniverInstanceType as H, ICommandService as K, Plugin as Y, merge as J } from "@univerjs/core";
|
5
|
+
import { ISidebarService as Q, useDependency as l, IShortcutService as X, IMessageService as Z, getMenuHiddenObservable as ee, MenuItemType as te, RibbonStartGroup as re, IMenuManagerService as ne, ComponentManager as ie } from "@univerjs/ui";
|
6
|
+
import { BehaviorSubject as oe, distinctUntilChanged as se } from "rxjs";
|
7
|
+
import { jsxs as ce, jsx as g } from "react/jsx-runtime";
|
8
|
+
import { Button as ae, MessageType as y } from "@univerjs/design";
|
9
|
+
import { editor as le } from "monaco-editor";
|
10
|
+
import { useRef as f, useEffect as ue, useCallback as pe } from "react";
|
11
|
+
import { FUniver as de } from "@univerjs/core/facade";
|
12
|
+
import { getCurrentRangeDisable$ as ve } from "@univerjs/sheets-ui";
|
13
|
+
import { RangeProtectionPermissionEditPoint as ge, WorksheetEditPermission as he, WorksheetSetCellStylePermission as me, WorksheetSetCellValuePermission as _e, WorkbookEditablePermission as fe } from "@univerjs/sheets";
|
14
|
+
const T = "uniscript.config", O = {};
|
15
|
+
class R extends _ {
|
16
|
+
constructor() {
|
17
|
+
super(...arguments);
|
18
|
+
p(this, "_open$", new oe(!1));
|
19
|
+
p(this, "open$", this._open$.pipe(se()));
|
20
|
+
}
|
21
|
+
get isOpen() {
|
22
|
+
return this._open$.getValue();
|
23
|
+
}
|
24
|
+
dispose() {
|
25
|
+
super.dispose(), this._open$.next(!1), this._open$.complete();
|
26
|
+
}
|
27
|
+
open() {
|
28
|
+
this._open$.next(!0);
|
29
|
+
}
|
30
|
+
close() {
|
31
|
+
this._open$.next(!1);
|
32
|
+
}
|
33
|
+
}
|
34
|
+
const W = "ScriptPanel", C = {
|
35
|
+
type: L.OPERATION,
|
36
|
+
id: "univer.operation.toggle-script-panel",
|
37
|
+
handler: (t) => {
|
38
|
+
const e = t.get(R), r = t.get(Q);
|
39
|
+
return e.isOpen ? (e.close(), r.close()) : (e.open(), r.open({
|
40
|
+
header: { title: "script-panel.title" },
|
41
|
+
children: { label: W },
|
42
|
+
width: 600
|
43
|
+
})), !0;
|
44
|
+
}
|
45
|
+
};
|
46
|
+
var Se = Object.getOwnPropertyDescriptor, Ie = (t, e, r, n) => {
|
47
|
+
for (var i = n > 1 ? void 0 : n ? Se(e, r) : e, o = t.length - 1, s; o >= 0; o--)
|
48
|
+
(s = t[o]) && (i = s(i) || i);
|
49
|
+
return i;
|
50
|
+
}, Pe = (t, e) => (r, n) => e(r, n, t);
|
51
|
+
let h = class extends _ {
|
52
|
+
constructor(e) {
|
53
|
+
super();
|
54
|
+
p(this, "_editorInstance", null);
|
55
|
+
this._configService = e;
|
56
|
+
}
|
57
|
+
dispose() {
|
58
|
+
super.dispose(), this._editorInstance && this._editorInstance.dispose();
|
59
|
+
}
|
60
|
+
setEditorInstance(e) {
|
61
|
+
return this._editorInstance = e, j(() => this._editorInstance = null);
|
62
|
+
}
|
63
|
+
getEditorInstance() {
|
64
|
+
return this._editorInstance;
|
65
|
+
}
|
66
|
+
requireVscodeEditor() {
|
67
|
+
if (!window.MonacoEnvironment) {
|
68
|
+
const e = this._configService.getConfig(T);
|
69
|
+
window.MonacoEnvironment = { getWorkerUrl: e == null ? void 0 : e.getWorkerUrl };
|
70
|
+
}
|
71
|
+
}
|
72
|
+
};
|
73
|
+
h = Ie([
|
74
|
+
Pe(0, M)
|
75
|
+
], h);
|
76
|
+
var Ee = Object.getOwnPropertyDescriptor, Ce = (t, e, r, n) => {
|
77
|
+
for (var i = n > 1 ? void 0 : n ? Ee(e, r) : e, o = t.length - 1, s; o >= 0; o--)
|
78
|
+
(s = t[o]) && (i = s(i) || i);
|
79
|
+
return i;
|
80
|
+
}, x = (t, e) => (r, n) => e(r, n, t);
|
81
|
+
const k = A("univer.uniscript.execution-service");
|
82
|
+
let P = class extends _ {
|
83
|
+
constructor(t, e) {
|
84
|
+
super(), this._logService = t, this._injector = e;
|
85
|
+
}
|
86
|
+
async execute(t) {
|
87
|
+
this._logService.log("[UniscriptExecutionService]", "executing Uniscript...");
|
88
|
+
const e = de.newAPI(this._injector), r = new Function("univerAPI", `(() => {${t}})()`);
|
89
|
+
try {
|
90
|
+
return r(e), !0;
|
91
|
+
} catch (n) {
|
92
|
+
return this._logService.error(n), !1;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
};
|
96
|
+
P = Ce([
|
97
|
+
x(0, q),
|
98
|
+
x(1, E(N))
|
99
|
+
], P);
|
100
|
+
function be() {
|
101
|
+
const t = f(null), e = f(null), r = f(null), n = l(D), i = l(X), o = l(h);
|
102
|
+
ue(() => {
|
103
|
+
const b = e.current, u = t.current;
|
104
|
+
let c = null, d = null;
|
105
|
+
if (b && u) {
|
106
|
+
o.requireVscodeEditor();
|
107
|
+
const v = r.current = le.create(b, {
|
108
|
+
value: "",
|
109
|
+
language: "javascript"
|
110
|
+
});
|
111
|
+
d = new ResizeObserver(() => {
|
112
|
+
let w = requestIdleCallback(() => {
|
113
|
+
if (!w) return;
|
114
|
+
const { height: F, width: V } = u.getBoundingClientRect();
|
115
|
+
v.layout({ width: V, height: F }), w = void 0;
|
116
|
+
});
|
117
|
+
}), d.observe(u);
|
118
|
+
let a;
|
119
|
+
c = new z(), c.add(o.setEditorInstance(v)), c.add(
|
120
|
+
v.onDidFocusEditorWidget(() => {
|
121
|
+
a = i.forceEscape();
|
122
|
+
})
|
123
|
+
), c.add(
|
124
|
+
v.onDidBlurEditorWidget(() => {
|
125
|
+
a == null || a.dispose(), a = void 0;
|
126
|
+
})
|
127
|
+
), c.add(j(() => a == null ? void 0 : a.dispose()));
|
128
|
+
}
|
129
|
+
return () => {
|
130
|
+
d && u && d.unobserve(u), c == null || c.dispose();
|
131
|
+
};
|
132
|
+
}, [o, i]);
|
133
|
+
const s = we(r);
|
134
|
+
return /* @__PURE__ */ ce("div", { className: "univer-h-full", children: [
|
135
|
+
/* @__PURE__ */ g("div", { ref: t, className: "univer-h-[calc(100%-60px)] univer-w-full univer-overflow-hidden", children: /* @__PURE__ */ g("div", { ref: e }) }),
|
136
|
+
/* @__PURE__ */ g("div", { className: "univer-mt-2.5", children: /* @__PURE__ */ g(ae, { type: "primary", size: "small", onClick: s, children: n.t("script-panel.panel.execute") }) })
|
137
|
+
] });
|
138
|
+
}
|
139
|
+
function we(t) {
|
140
|
+
const e = l(k), r = l(Z), n = l(D);
|
141
|
+
return pe(() => {
|
142
|
+
var o;
|
143
|
+
const i = (o = t.current) == null ? void 0 : o.getModel();
|
144
|
+
i && e.execute(i.getValue()).then(() => {
|
145
|
+
r.show({
|
146
|
+
content: n.t("uniscript.message.success"),
|
147
|
+
type: y.Success
|
148
|
+
});
|
149
|
+
}).catch(() => {
|
150
|
+
r.show({
|
151
|
+
content: n.t("uniscript.message.failed"),
|
152
|
+
type: y.Error
|
153
|
+
});
|
154
|
+
});
|
155
|
+
}, [n, r, t, e]);
|
156
|
+
}
|
157
|
+
function ye(t) {
|
158
|
+
return {
|
159
|
+
id: C.id,
|
160
|
+
title: "toggle-script-panel",
|
161
|
+
tooltip: "script-panel.tooltip.menu-button",
|
162
|
+
icon: "CodeSingle",
|
163
|
+
type: te.BUTTON,
|
164
|
+
// FIXME hidden$ and disabled$ are not correctly in doc
|
165
|
+
hidden$: ee(t, H.UNIVER_SHEET),
|
166
|
+
disabled$: ve(t, { workbookTypes: [fe], worksheetTypes: [he, me, _e], rangeTypes: [ge] })
|
167
|
+
};
|
168
|
+
}
|
169
|
+
const Oe = {
|
170
|
+
[re.OTHERS]: {
|
171
|
+
[C.id]: {
|
172
|
+
order: 5,
|
173
|
+
menuItemFactory: ye
|
174
|
+
}
|
175
|
+
}
|
176
|
+
};
|
177
|
+
var xe = Object.getOwnPropertyDescriptor, Ue = (t, e, r, n) => {
|
178
|
+
for (var i = n > 1 ? void 0 : n ? xe(e, r) : e, o = t.length - 1, s; o >= 0; o--)
|
179
|
+
(s = t[o]) && (i = s(i) || i);
|
180
|
+
return i;
|
181
|
+
}, S = (t, e) => (r, n) => e(r, n, t);
|
182
|
+
let m = class extends _ {
|
183
|
+
constructor(t, e, r) {
|
184
|
+
super(), this._menuManagerService = t, this._menuManagerService.mergeMenu(Oe), this.disposeWithMe(r.register(W, be)), this.disposeWithMe(e.registerCommand(C));
|
185
|
+
}
|
186
|
+
};
|
187
|
+
m = Ue([
|
188
|
+
S(0, ne),
|
189
|
+
S(1, K),
|
190
|
+
S(2, E(ie))
|
191
|
+
], m);
|
192
|
+
var $e = Object.getOwnPropertyDescriptor, je = (t, e, r, n) => {
|
193
|
+
for (var i = n > 1 ? void 0 : n ? $e(e, r) : e, o = t.length - 1, s; o >= 0; o--)
|
194
|
+
(s = t[o]) && (i = s(i) || i);
|
195
|
+
return i;
|
196
|
+
}, U = (t, e) => (r, n) => e(r, n, t);
|
197
|
+
const Me = "UNIVER_UNISCRIPT_PLUGIN";
|
198
|
+
var I;
|
199
|
+
let $ = (I = class extends Y {
|
200
|
+
constructor(t = O, e, r) {
|
201
|
+
super(), this._config = t, this._injector = e, this._configService = r;
|
202
|
+
const { menu: n, ...i } = J(
|
203
|
+
{},
|
204
|
+
O,
|
205
|
+
this._config
|
206
|
+
);
|
207
|
+
n && this._configService.setConfig("menu", n, { merge: !0 }), this._configService.setConfig(T, i);
|
208
|
+
}
|
209
|
+
onStarting() {
|
210
|
+
const t = this._injector;
|
211
|
+
[
|
212
|
+
[m],
|
213
|
+
[h],
|
214
|
+
[R]
|
215
|
+
].forEach((r) => t.add(r)), this.registerExecution();
|
216
|
+
}
|
217
|
+
onSteady() {
|
218
|
+
this._injector.get(m);
|
219
|
+
}
|
220
|
+
/**
|
221
|
+
* Allows being overridden, replacing with a new UniscriptExecutionService.
|
222
|
+
*/
|
223
|
+
registerExecution() {
|
224
|
+
this._injector.add([k, { useClass: P }]);
|
225
|
+
}
|
226
|
+
}, p(I, "pluginName", Me), I);
|
227
|
+
$ = je([
|
228
|
+
U(1, E(N)),
|
229
|
+
U(2, M)
|
230
|
+
], $);
|
231
|
+
export {
|
232
|
+
k as IUniscriptExecutionService,
|
233
|
+
h as ScriptEditorService,
|
234
|
+
C as ToggleScriptPanelOperation,
|
235
|
+
$ as UniverUniscriptPlugin
|
236
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const e = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Uniscript",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "Toggle Uniscript Panel"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "Execute Script"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "Execution Success",
|
14
|
+
failed: "Execution Failed"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
e as default
|
20
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const e = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Uniscript",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "نمایش/مخفی کردن پنل Uniscript"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "اجرای اسکریپت"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "اجرای موفق",
|
14
|
+
failed: "اجرای ناموفق"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
e as default
|
20
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const e = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Uniscript",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "Basculer le panneau Uniscript"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "Exécuter le script"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "Exécution réussie",
|
14
|
+
failed: "Échec de l'exécution"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
e as default
|
20
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const e = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Юнискрипт",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "Переключить панель Юнискрипт"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "Выполнить скрипт"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "Выполнение успешно",
|
14
|
+
failed: "Выполнение не удалось"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
e as default
|
20
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const t = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Uniscript",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "Mở/Thu gọn bảng điều khiển Uniscript"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "Thực thi Uniscript"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "Thực thi thành công",
|
14
|
+
failed: "Thực thi thất bại"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
t as default
|
20
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const t = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Uniscript",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "打开收起 Uniscript 面板"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "执行 Uniscript"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "执行成功",
|
14
|
+
failed: "执行失败"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
t as default
|
20
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
const t = {
|
2
|
+
"script-panel": {
|
3
|
+
title: "Uniscript",
|
4
|
+
tooltip: {
|
5
|
+
"menu-button": "打開收起 Uniscript 面板"
|
6
|
+
},
|
7
|
+
panel: {
|
8
|
+
execute: "執行 Uniscript"
|
9
|
+
}
|
10
|
+
},
|
11
|
+
uniscript: {
|
12
|
+
message: {
|
13
|
+
success: "執行成功",
|
14
|
+
failed: "執行失敗"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
};
|
18
|
+
export {
|
19
|
+
t as default
|
20
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@univerjs/uniscript",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.9",
|
4
4
|
"private": false,
|
5
5
|
"description": "UI component library for building exceptional Univer.",
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
@@ -51,16 +51,16 @@
|
|
51
51
|
],
|
52
52
|
"peerDependencies": {
|
53
53
|
"monaco-editor": ">=0.50.0",
|
54
|
-
"react": "
|
54
|
+
"react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc",
|
55
55
|
"rxjs": ">=7.0.0"
|
56
56
|
},
|
57
57
|
"dependencies": {
|
58
58
|
"monaco-editor": "0.52.2",
|
59
|
-
"@univerjs/core": "0.6.
|
60
|
-
"@univerjs/design": "0.6.
|
61
|
-
"@univerjs/sheets
|
62
|
-
"@univerjs/sheets": "0.6.
|
63
|
-
"@univerjs/ui": "0.6.
|
59
|
+
"@univerjs/core": "0.6.9",
|
60
|
+
"@univerjs/design": "0.6.9",
|
61
|
+
"@univerjs/sheets": "0.6.9",
|
62
|
+
"@univerjs/sheets-ui": "0.6.9",
|
63
|
+
"@univerjs/ui": "0.6.9"
|
64
64
|
},
|
65
65
|
"devDependencies": {
|
66
66
|
"postcss": "^8.5.3",
|
@@ -70,7 +70,7 @@
|
|
70
70
|
"typescript": "^5.8.2",
|
71
71
|
"vite": "^6.2.3",
|
72
72
|
"vitest": "^3.0.9",
|
73
|
-
"@univerjs-infra/shared": "0.6.
|
73
|
+
"@univerjs-infra/shared": "0.6.9"
|
74
74
|
},
|
75
75
|
"scripts": {
|
76
76
|
"test": "vitest run",
|