@sheetxl/scripting-mui 0.7.23-beta.2

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.
Files changed (54) hide show
  1. package/LICENSE.md +11 -0
  2. package/README.md +33 -0
  3. package/browser/cjs/index.cjs +1 -0
  4. package/browser/esm/index.mjs +927 -0
  5. package/licenses/dependencies.txt +19 -0
  6. package/node/esm/index.mjs +920 -0
  7. package/package.json +65 -0
  8. package/resources/contents.json +18 -0
  9. package/resources/locales/contents.json +16 -0
  10. package/resources/locales/de/ui.msg.json +14 -0
  11. package/resources/locales/en/ui.msg.json +14 -0
  12. package/types/index.d.ts +2 -0
  13. package/types/src/ScriptingPlugin.d.ts +9 -0
  14. package/types/src/ScriptingPlugin.d.ts.map +1 -0
  15. package/types/src/command/InsertFunctionContribution.d.ts +15 -0
  16. package/types/src/command/InsertFunctionContribution.d.ts.map +1 -0
  17. package/types/src/command/InsertFunctionPopupPanel.d.ts +13 -0
  18. package/types/src/command/InsertFunctionPopupPanel.d.ts.map +1 -0
  19. package/types/src/command/InsertScriptCommandButton.d.ts +15 -0
  20. package/types/src/command/InsertScriptCommandButton.d.ts.map +1 -0
  21. package/types/src/command/RunScriptCommandButton.d.ts +11 -0
  22. package/types/src/command/RunScriptCommandButton.d.ts.map +1 -0
  23. package/types/src/command/RunScriptContribution.d.ts +21 -0
  24. package/types/src/command/RunScriptContribution.d.ts.map +1 -0
  25. package/types/src/command/RunScriptPopupPanel.d.ts +8 -0
  26. package/types/src/command/RunScriptPopupPanel.d.ts.map +1 -0
  27. package/types/src/command/index.d.ts +3 -0
  28. package/types/src/command/index.d.ts.map +1 -0
  29. package/types/src/index.d.ts +5 -0
  30. package/types/src/index.d.ts.map +1 -0
  31. package/types/src/locales/index.d.ts +3 -0
  32. package/types/src/locales/index.d.ts.map +1 -0
  33. package/types/src/template/TemplateSelectPanel.d.ts +41 -0
  34. package/types/src/template/TemplateSelectPanel.d.ts.map +1 -0
  35. package/types/src/template/index.d.ts +2 -0
  36. package/types/src/template/index.d.ts.map +1 -0
  37. package/types/src/toolbar/ScriptEditorToolbar.d.ts +6 -0
  38. package/types/src/toolbar/ScriptEditorToolbar.d.ts.map +1 -0
  39. package/types/src/toolbar/index.d.ts +2 -0
  40. package/types/src/toolbar/index.d.ts.map +1 -0
  41. package/types/src/utils/FetchDirectory.d.ts +20 -0
  42. package/types/src/utils/FetchDirectory.d.ts.map +1 -0
  43. package/types/src/utils/Utils.d.ts +2 -0
  44. package/types/src/utils/Utils.d.ts.map +1 -0
  45. package/types/src/utils/index.d.ts +3 -0
  46. package/types/src/utils/index.d.ts.map +1 -0
  47. package/types/src/workspace/ScriptCommandProvider.d.ts +29 -0
  48. package/types/src/workspace/ScriptCommandProvider.d.ts.map +1 -0
  49. package/types/src/workspace/ScriptTaskPane.d.ts +3 -0
  50. package/types/src/workspace/ScriptTaskPane.d.ts.map +1 -0
  51. package/types/src/workspace/ScriptWorkspace.d.ts +58 -0
  52. package/types/src/workspace/ScriptWorkspace.d.ts.map +1 -0
  53. package/types/src/workspace/index.d.ts +3 -0
  54. package/types/src/workspace/index.d.ts.map +1 -0
@@ -0,0 +1,927 @@
1
+ /**
2
+ * @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.7.23-beta.2
3
+ *
4
+ * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
+ * License: The license can be found at https://www.sheetxl.com/license.
6
+ */
7
+ import e, { createElement as t, forwardRef as n, memo as r, useCallback as i, useEffect as a, useMemo as o, useReducer as s, useRef as c, useState as l } from "react";
8
+ import { Box as u, Button as d, CircularProgress as f, Paper as p, Typography as m, useTheme as h } from "@mui/material";
9
+ import { Command as g, CommandButtonType as _, DefaultCommandButtonRegistry as v, DefaultIconService as y, DynamicIcon as b, KeyCodes as x, ReactUtils as S, useCallbackRef as C, useCommandButtonEntry as w, useCommands as T, useImperativeElement as E, useTranslator as D } from "@sheetxl/utils-react";
10
+ import { AnimatedLoadingPanel as ee, CommandButton as O, CommandPopupButton as k, CommandToolbar as A, ExhibitDivider as j, ExhibitMenuItem as M, OverflowPalette as N, defaultCreatePopupPanel as P, raisedSurface as F } from "@sheetxl/utils-mui";
11
+ import { DefaultTaskPaneRegistry as I, InputClipboardInjector as L, useWorkbook as R } from "@sheetxl/react";
12
+ import { Fragment as z, jsx as B, jsxs as V } from "react/jsx-runtime";
13
+ import { alpha as H } from "@mui/system";
14
+ import { ChainedError as U } from "@sheetxl/utils";
15
+ import { ScriptEditor as te, ScriptingReactPlugin as ne } from "@sheetxl/scripting-react";
16
+ function W(e) {
17
+ var t, n, r = "";
18
+ if (typeof e == "string" || typeof e == "number") r += e;
19
+ else if (typeof e == "object") if (Array.isArray(e)) {
20
+ var i = e.length;
21
+ for (t = 0; t < i; t++) e[t] && (n = W(e[t])) && (r && (r += " "), r += n);
22
+ } else for (n in e) e[n] && (r && (r += " "), r += n);
23
+ return r;
24
+ }
25
+ function G() {
26
+ for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = W(e)) && (r && (r += " "), r += t);
27
+ return r;
28
+ }
29
+ var re = {
30
+ "insertFunction.fallbackLabel": "Function",
31
+ "insertFunction.insertNamed": "Insert {name}",
32
+ "runScript.executeNamed": "Execute {name}",
33
+ "runScript.fallbackLabel": "Macro",
34
+ "templateSelect.blankSummary": "Start with an empty script.",
35
+ "templateSelect.blankTitle": "Blank Template...",
36
+ "templateSelect.errorTitle": "Error loading Templates",
37
+ "templateSelect.intro": "Choose from a template to provide a starting point to automate tasks or create user defined functions.",
38
+ "templateSelect.intro2": "Templates provide a foundation to customize and meet your specific needs.",
39
+ "templateSelect.loadFailed": "Failed to load scripts",
40
+ "templateSelect.title": "Script Template",
41
+ "templateSelect.untitled": "Untitled"
42
+ }, { DefaultCommandCatalogService: ie } = g, K = !1;
43
+ function q() {
44
+ K || (K = !0, ie.registerFromManifest("@sheetxl/scripting-mui", import.meta.url, { messages: re }));
45
+ }
46
+ q();
47
+ var J = r(n((e, n) => {
48
+ let { groupKey: r, ...i } = e, o = R(), s = D(), [c, d] = l([]), [f, p] = l(!1);
49
+ a(() => {
50
+ let e = o?.getScripts();
51
+ e && (async () => {
52
+ p(!0);
53
+ let t = await e.searchFunctions({ type: "macro" });
54
+ d(t), p(!1);
55
+ })();
56
+ }, [o]);
57
+ let m = {
58
+ variant: _.Menuitem,
59
+ groupKey: "scriptsOptions",
60
+ shortcut: void 0
61
+ }, h = [], g = c ? c.length : 0;
62
+ for (let e = 0; e < g; e++) {
63
+ let t = c[e];
64
+ h.push(B(O, {
65
+ ...m,
66
+ commandKey: "executeScript",
67
+ commandState: { declaration: t },
68
+ propsTooltip: { description: s("runScript.executeNamed", { name: t.getName() ?? s("runScript.fallbackLabel") }) },
69
+ icon: B(b, { iconKey: "ScriptMacro" }),
70
+ label: t.getName() ?? s("runScript.fallbackLabel")
71
+ }, `macro-${t.getName()}-${e}`));
72
+ }
73
+ let v = V(u, {
74
+ ref: n,
75
+ sx: {
76
+ display: "flex",
77
+ flexDirection: "column",
78
+ flex: "1 1 100%",
79
+ overflow: "hidden"
80
+ },
81
+ children: [h.length > 0 ? V(z, { children: [B(u, {
82
+ sx: {
83
+ overflow: "auto",
84
+ flex: "1 1 100%"
85
+ },
86
+ children: h
87
+ }), B(j, { orientation: "horizontal" })] }) : null, t(O, {
88
+ ...m,
89
+ key: "show-editor",
90
+ commandKey: "showScriptEditor"
91
+ })]
92
+ });
93
+ return P({
94
+ ...i,
95
+ children: v
96
+ });
97
+ }));
98
+ J.displayName = "RunScriptPopupPanel";
99
+ var ae = r(n((e, t) => {
100
+ let { groupKey: n, disabled: r, ...a } = e, o = T(["showScriptEditor"])[0], s = w("scriptsOptions");
101
+ return B(k, {
102
+ ref: t,
103
+ disabled: r,
104
+ createPopupPanel: i((e) => {
105
+ let t = B(J, {
106
+ disabled: r,
107
+ groupKey: n,
108
+ ...e
109
+ });
110
+ return P({
111
+ ...e,
112
+ children: t
113
+ });
114
+ }, [r, n]),
115
+ selected: o?.getState(),
116
+ label: s?.getLabel?.(),
117
+ tooltip: s?.getDescription?.(),
118
+ quickCommand: "showScriptEditor",
119
+ ...a
120
+ });
121
+ })), oe = "https://unpkg.com/@sheetxl/scripting-templates/dist", se = (e, t) => {
122
+ try {
123
+ return new URL(t).href;
124
+ } catch {}
125
+ if (t.startsWith("/") || /^[a-zA-Z]:/.test(t)) return t;
126
+ let n = e.startsWith("http") ? e : `file:///${e.replace(/\\/g, "/")}`;
127
+ return n.endsWith("/") || (n += "/"), new URL(t, n).href;
128
+ }, ce = (e) => {
129
+ if (e.metadata?.name) return e.metadata.name;
130
+ let t = (e.path.split("/").pop() || "").replace(/\.[^/.]+$/, "");
131
+ return e.metadata?.icon === "formula" ? t.toUpperCase() : (t = t.replace(/([a-z])([A-Z])/g, "$1 $2"), t.replace(/[-_]/g, " ").trim().split(/\s+/).map((e) => e.charAt(0).toUpperCase() + e.slice(1)).join(" "));
132
+ }, le = async (e) => {
133
+ let t = se(e, "./manifest.json"), n = await fetch(t);
134
+ if (!n.ok) throw new U(`Failed to retrieve directory at '${e}': ${n.statusText}`);
135
+ let r = await n.text();
136
+ if (r.trim().toLowerCase().startsWith("<!doctype html") || r.trim().toLowerCase().startsWith("<html")) throw new U(`Failed to retrieve directory at '${e}'`);
137
+ let i;
138
+ try {
139
+ i = JSON.parse(r);
140
+ } catch (e) {
141
+ throw Error(`Failed to parse directory: ${e.message}. Ensure the file is valid JSON.`);
142
+ }
143
+ let a = i.map(async (t) => {
144
+ try {
145
+ let n = se(e, t.path), r = await fetch(n);
146
+ if (!r.ok) throw Error(`Failed to fetch file at '${t.path}': ${r.statusText}`);
147
+ let i = await r.text(), a = t.metadata;
148
+ return a?.title || (a = {
149
+ title: ce(t),
150
+ ...a
151
+ }), {
152
+ path: t.path,
153
+ content: i,
154
+ metadata: a
155
+ };
156
+ } catch (e) {
157
+ console.error(e.message);
158
+ }
159
+ return null;
160
+ });
161
+ return (await Promise.all(a)).filter((e) => e !== null);
162
+ }, Y = { marginRight: "4px" }, X = "1em", ue = r((e) => {
163
+ let { disabled: t, snippet: n, description: r, handleInsert: i, sx: a, ...o } = e, s, c = n.metadata?.icon;
164
+ return s = B(b, c === "formula" ? {
165
+ iconKey: "ScriptFormula",
166
+ size: X,
167
+ style: Y
168
+ } : c === "macro" ? {
169
+ iconKey: "ScriptMacro",
170
+ size: X,
171
+ style: Y
172
+ } : {
173
+ iconKey: "ScriptAutoRun",
174
+ size: X,
175
+ style: Y
176
+ }), B(M, {
177
+ sx: {
178
+ maxWidth: "460px",
179
+ display: "flex",
180
+ "*": { lineHeight: "1.2" },
181
+ ...a
182
+ },
183
+ disabled: t,
184
+ icon: s,
185
+ onMouseDown: (e) => {
186
+ e.button === 0 && e.preventDefault();
187
+ },
188
+ onMouseUp: (e) => {
189
+ e.button === 0 && i(n);
190
+ },
191
+ onKeyDown: (e) => {
192
+ e.keyCode !== x.Enter && e.keyCode !== x.Space || i(n);
193
+ },
194
+ ...o,
195
+ children: V(u, {
196
+ sx: {
197
+ display: "flex",
198
+ flex: "1 1 100%",
199
+ flexDirection: "column",
200
+ overflow: "hidden"
201
+ },
202
+ children: [B(m, {
203
+ component: "div",
204
+ children: n.metadata?.title ?? n.path
205
+ }), B(m, {
206
+ variant: "caption",
207
+ component: "div",
208
+ sx: {
209
+ color: (e) => H(e.palette.text.secondary ?? e.palette.text.primary, .6),
210
+ overflow: "hidden",
211
+ textOverflow: "ellipsis"
212
+ },
213
+ children: n.metadata?.summary
214
+ })]
215
+ })
216
+ });
217
+ }), de = r(n((e, n) => {
218
+ let { groupKey: r, disabled: o, scriptPath: s = oe, ...c } = e, [d, f] = l([]), [p, m] = l(!0), [h] = T(["insertScript"]);
219
+ a(() => {
220
+ (async () => {
221
+ try {
222
+ let e = await le(s);
223
+ f(e);
224
+ } catch {} finally {
225
+ m(!1);
226
+ }
227
+ })();
228
+ }, [s]);
229
+ let g = i((e) => {
230
+ if (p) return B("div", { children: "Loading..." });
231
+ let n = {
232
+ variant: _.Menuitem,
233
+ groupKey: "scriptsOptions",
234
+ disabled: o
235
+ }, r = (t) => {
236
+ h?.execute(t.content), e.closeFloat?.();
237
+ }, i = [];
238
+ for (let e = 0; e < d.length; e++) {
239
+ let t = d[e];
240
+ t && i.push(B(ue, {
241
+ handleInsert: r,
242
+ snippet: t
243
+ }, t.path));
244
+ }
245
+ let a = V(u, {
246
+ sx: {
247
+ display: "flex",
248
+ flexDirection: "column",
249
+ flex: "1 1 100%",
250
+ overflow: "hidden"
251
+ },
252
+ children: [
253
+ i.length > 0 ? V(z, { children: [B(u, {
254
+ sx: {
255
+ overflow: "auto",
256
+ flex: "1 1 100%"
257
+ },
258
+ children: i
259
+ }), B(j, { orientation: "horizontal" })] }) : null,
260
+ t(O, {
261
+ ...n,
262
+ key: "showKeyboardShortcuts",
263
+ commandKey: "showKeyboardShortcuts"
264
+ }),
265
+ t(O, {
266
+ ...n,
267
+ key: "scriptingHelp",
268
+ commandKey: "scriptingHelp"
269
+ })
270
+ ]
271
+ });
272
+ return P({
273
+ ...e,
274
+ children: a
275
+ });
276
+ }, [
277
+ o,
278
+ r,
279
+ p,
280
+ h
281
+ ]);
282
+ return B(k, {
283
+ ref: n,
284
+ disabled: o,
285
+ groupKey: r,
286
+ label: h?.getLabel(r) ?? "Insert Script",
287
+ tooltip: h?.getDescription(),
288
+ createPopupPanel: g,
289
+ icon: h?.getIcon() ?? "ScriptInsert",
290
+ ...c
291
+ });
292
+ })), Z = r(n((e, t) => {
293
+ let { propsCommandButton: n, ...r } = e;
294
+ return B(A, {
295
+ ref: t,
296
+ propsCommandButton: n,
297
+ renderToolbarPalette: C((e) => {
298
+ let { propsCommandButton: t, propsCommandPopup: n } = e;
299
+ return B(z, { children: V("div", {
300
+ style: {
301
+ display: "flex",
302
+ flex: "1 1 100%"
303
+ },
304
+ children: [
305
+ B("div", { children: B(N, {
306
+ style: {},
307
+ children: B(O, {
308
+ ...t,
309
+ commandKey: "saveScripts"
310
+ })
311
+ }) }),
312
+ B("div", { style: { flex: "1 1 100%" } }),
313
+ B("div", { children: B(N, {
314
+ style: {},
315
+ children: B(de, { ...t })
316
+ }) })
317
+ ]
318
+ }) });
319
+ }, []),
320
+ ...r
321
+ });
322
+ }));
323
+ Z.displayName = "ScriptEditorToolbar", q();
324
+ var fe = r(n((e, t) => {
325
+ let { scriptPath: n = oe, onScriptSelect: r, sx: i = S.EmptyCssProperties, className: o, buttonMinWidth: s = 210, buttonMinHeight: c = 80, gap: p = 12, ...h } = e, g = D(), [_, v] = l([]), [y, x] = l(!0), [C, w] = l(null);
326
+ if (a(() => {
327
+ (async () => {
328
+ let e = [{
329
+ path: null,
330
+ metadata: {
331
+ title: g("templateSelect.blankTitle"),
332
+ summary: g("templateSelect.blankSummary")
333
+ },
334
+ content: ""
335
+ }];
336
+ try {
337
+ x(!0), w(null);
338
+ let t = await le(n);
339
+ for (let n = 0; n < t.length; n++) {
340
+ let r = t[n];
341
+ r && e.push(r);
342
+ }
343
+ } catch (e) {
344
+ w(e instanceof Error ? e.message : g("templateSelect.loadFailed")), e instanceof U || console.error("Error loading scripts:", e);
345
+ } finally {
346
+ v(e), x(!1);
347
+ }
348
+ })();
349
+ }, [n, g]), y) return B(u, {
350
+ className: G(o, "script-select"),
351
+ ...h,
352
+ sx: [{
353
+ display: "flex",
354
+ justifyContent: "center",
355
+ alignItems: "center",
356
+ height: "100%",
357
+ background: (e) => e.palette.background.paper,
358
+ zIndex: 1e3,
359
+ backgroundImage: F,
360
+ ...Array.isArray(i) ? {} : i
361
+ }, ...Array.isArray(i) ? i : []],
362
+ children: B(f, {})
363
+ });
364
+ let T = null;
365
+ C && (T = V(u, {
366
+ className: G(o, "script-select", "error-results"),
367
+ ...h,
368
+ sx: [{
369
+ display: "flex",
370
+ justifyContent: "center",
371
+ alignItems: "center",
372
+ background: (e) => e.palette.error.light,
373
+ flex: "0",
374
+ zIndex: 1e3,
375
+ flexDirection: "column",
376
+ padding: (e) => e.spacing(1),
377
+ border: (e) => `1px solid ${e.palette.error.main}`,
378
+ borderBottomLeftRadius: 1,
379
+ borderBottomRightRadius: 1,
380
+ backgroundImage: F
381
+ }, ...Array.isArray(i) ? i : [i]],
382
+ children: [B(m, {
383
+ color: "error",
384
+ variant: "h6",
385
+ component: "div",
386
+ gutterBottom: !0,
387
+ children: g("templateSelect.errorTitle")
388
+ }), B(m, {
389
+ color: "error",
390
+ component: "div",
391
+ children: C
392
+ })]
393
+ }));
394
+ let E = (e) => {
395
+ let t = e.metadata?.icon;
396
+ return t === "macro" ? B(b, {
397
+ iconKey: "ScriptMacro",
398
+ size: "1em"
399
+ }) : t === "formula" ? B(b, {
400
+ iconKey: "ScriptFormula",
401
+ size: "1em"
402
+ }) : t === "autostart" ? B(b, {
403
+ iconKey: "ScriptAutoRun",
404
+ size: "1em"
405
+ }) : null;
406
+ };
407
+ return V(u, {
408
+ ref: t,
409
+ className: G(o, "script-select"),
410
+ sx: {
411
+ background: (e) => e.palette.background.paper,
412
+ zIndex: 1e3,
413
+ backgroundImage: F,
414
+ ...i
415
+ },
416
+ ...h,
417
+ children: [V(u, {
418
+ className: "script-select-content",
419
+ sx: {
420
+ p: 3,
421
+ overflow: "auto",
422
+ flex: "1 1 auto"
423
+ },
424
+ children: [
425
+ B(m, {
426
+ variant: "h6",
427
+ gutterBottom: !0,
428
+ children: g("templateSelect.title")
429
+ }),
430
+ B(m, {
431
+ variant: "body2",
432
+ component: "div",
433
+ gutterBottom: !0,
434
+ sx: { color: "text.secondary" },
435
+ children: g("templateSelect.intro")
436
+ }),
437
+ B(m, {
438
+ variant: "body2",
439
+ component: "div",
440
+ gutterBottom: !0,
441
+ sx: { color: "text.secondary" },
442
+ children: g("templateSelect.intro2")
443
+ }),
444
+ B(u, {
445
+ sx: {
446
+ display: "grid",
447
+ gridTemplateColumns: `repeat(auto-fill, minmax(${s}px, 1fr))`,
448
+ gap: `${p}px`,
449
+ padding: 2,
450
+ paddingLeft: "0px",
451
+ paddingRight: "0px"
452
+ },
453
+ children: _.map((e, t) => V(d, {
454
+ variant: "outlined",
455
+ sx: {
456
+ minWidth: s,
457
+ minHeight: c,
458
+ display: "flex",
459
+ flexDirection: "column",
460
+ justifyContent: "flex-start",
461
+ alignItems: "flex-start",
462
+ textAlign: "left",
463
+ padding: 2,
464
+ textTransform: "none",
465
+ overflow: "hidden",
466
+ ...t === 0 && {
467
+ borderStyle: "dashed",
468
+ marginBottom: "8px"
469
+ },
470
+ ...t === 1 && { gridColumn: "1" }
471
+ },
472
+ onClick: () => r?.(e),
473
+ children: [V(u, {
474
+ sx: {
475
+ display: "flex",
476
+ flexDirection: "row",
477
+ justifyContent: "space-between",
478
+ alignItems: "center",
479
+ width: "100%",
480
+ marginBottom: .5
481
+ },
482
+ children: [B(m, {
483
+ variant: "subtitle2",
484
+ component: "div",
485
+ children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") || g("templateSelect.untitled")
486
+ }), E(e)]
487
+ }), e.metadata?.summary && B(m, {
488
+ variant: "body2",
489
+ component: "div",
490
+ sx: {
491
+ color: "text.secondary",
492
+ overflow: "hidden",
493
+ display: "flex",
494
+ flexDirection: "column",
495
+ textOverflow: "ellipsis",
496
+ alignItems: "flex-start"
497
+ },
498
+ children: e.metadata.summary
499
+ })]
500
+ }, `${e.path}-${t}`))
501
+ })
502
+ ]
503
+ }), T]
504
+ });
505
+ }));
506
+ fe.displayName = "TemplateSelectPanel";
507
+ var Q = r(n((e, t) => {
508
+ let { className: n, sx: r, propsScriptEditor: s, readOnly: d = !1, frame: f, autoFocusSel: g, autoFocus: _ = !0, scripts: v, ...y } = e, b = h(), [x, S] = l(!1), w = c(!1), [T, D] = l({
509
+ message: "Loading",
510
+ cursor: "",
511
+ dirty: !1
512
+ }), [O, k] = l(null);
513
+ a(() => {
514
+ let e = !1;
515
+ return k(null), async function() {
516
+ if (v && (await v.start(), !e)) {
517
+ let e = v.getModules().getItems()[0]?.getSource();
518
+ k({ source: e || null });
519
+ }
520
+ }(), () => {
521
+ e = !0;
522
+ };
523
+ }, [v]);
524
+ let A = i((e) => {
525
+ D((t) => ({
526
+ ...t,
527
+ ...e
528
+ }));
529
+ }, []), j = c(null), [M, N] = l(null), P = c(null), F = C((e) => {
530
+ if (M) return M.focus(e), !0;
531
+ if (g) {
532
+ let t = j.current?.querySelectorAll?.(g);
533
+ if (t && t.length > 0) return t[0]?.focus?.(e), !0;
534
+ }
535
+ return j.current?.focus?.(e), !1;
536
+ }, [
537
+ M,
538
+ g,
539
+ _
540
+ ]), I = o(() => B(ee, {
541
+ transitionDelay: "160ms",
542
+ style: {
543
+ position: "absolute",
544
+ width: "100%",
545
+ height: "100%"
546
+ },
547
+ transparentBackground: !1
548
+ }), []), L = o(() => B(p, {
549
+ elevation: 1,
550
+ tabIndex: 0,
551
+ sx: {
552
+ display: "flex",
553
+ alignItems: "center",
554
+ userSelect: "none",
555
+ flexGrow: 1,
556
+ marginLeft: (e) => e.spacing(.5),
557
+ marginRight: (e) => e.spacing(.5),
558
+ marginTop: (e) => e.spacing(1),
559
+ marginBottom: (e) => e.spacing(1)
560
+ },
561
+ children: B(Z, {})
562
+ }), [b]), R = o(() => B(u, {
563
+ className: G("script-status-panel", "status-panel"),
564
+ sx: {
565
+ display: "flex",
566
+ alignItems: "stretch",
567
+ flexDirection: "row",
568
+ flex: "0",
569
+ paddingLeft: "12px",
570
+ paddingRight: "12px",
571
+ gap: "8px",
572
+ paddingTop: "1px",
573
+ minHeight: "calc(1em + 8px)",
574
+ margin: 0,
575
+ borderTop: `solid 1px ${b.palette.divider}`
576
+ },
577
+ children: V("div", {
578
+ style: {
579
+ flex: "1 1 100%",
580
+ display: "flex",
581
+ alignItems: "center",
582
+ flexDirection: "row",
583
+ justifyContent: "center"
584
+ },
585
+ children: [
586
+ B(m, {
587
+ component: "div",
588
+ sx: {
589
+ userSelect: "none",
590
+ whiteSpace: "pre",
591
+ overflow: "hidden",
592
+ textOverflow: "ellipsis",
593
+ flex: "1 1 100%",
594
+ color: (e) => e.palette.text.secondary
595
+ },
596
+ variant: "caption",
597
+ children: T.message
598
+ }),
599
+ B(m, {
600
+ component: "div",
601
+ sx: {
602
+ userSelect: "none",
603
+ whiteSpace: "pre",
604
+ overflow: "hidden",
605
+ textOverflow: "ellipsis",
606
+ flex: "none",
607
+ color: (e) => e.palette.text.secondary
608
+ },
609
+ variant: "caption",
610
+ children: T.dirty ? "Unsaved" : ""
611
+ }),
612
+ B(m, {
613
+ component: "div",
614
+ sx: {
615
+ userSelect: "none",
616
+ whiteSpace: "pre",
617
+ overflow: "hidden",
618
+ textOverflow: "ellipsis",
619
+ flex: "none",
620
+ marginLeft: "8px",
621
+ minWidth: "90px",
622
+ display: "flex",
623
+ justifyContent: "end",
624
+ color: (e) => e.palette.text.secondary
625
+ },
626
+ variant: "caption",
627
+ children: T.cursor
628
+ })
629
+ ]
630
+ })
631
+ }), [T]), z = o(() => V(u, {
632
+ className: G("script-editor-content"),
633
+ sx: {
634
+ display: "flex",
635
+ flex: "1 1 100%",
636
+ width: "100%",
637
+ flexDirection: "column",
638
+ boxSizing: "border-box"
639
+ },
640
+ children: [
641
+ L,
642
+ B(u, {
643
+ sx: {
644
+ display: "flex",
645
+ flex: "1 1 100%",
646
+ width: "100%",
647
+ flexDirection: "row",
648
+ position: "relative",
649
+ boxSizing: "border-box"
650
+ },
651
+ children: B(te, {
652
+ ref: j,
653
+ loadingPanel: I,
654
+ readOnly: d,
655
+ frame: f,
656
+ scripts: v,
657
+ autoFocus: _,
658
+ onStatusChange: A,
659
+ darkMode: b.palette.mode === "dark",
660
+ ...s
661
+ })
662
+ }),
663
+ R
664
+ ]
665
+ }), [
666
+ b,
667
+ L,
668
+ R,
669
+ x,
670
+ I,
671
+ d,
672
+ s,
673
+ _,
674
+ g,
675
+ f,
676
+ A
677
+ ]), H = o(() => {
678
+ let e;
679
+ return O === null ? I : (O.source === null && (e = B(fe, {
680
+ sx: {
681
+ display: "flex",
682
+ flex: "1 1 100%",
683
+ flexDirection: "column",
684
+ overflow: "hidden",
685
+ position: "absolute",
686
+ boxSizing: "border-box",
687
+ width: "100%",
688
+ height: "100%"
689
+ },
690
+ onScriptSelect: (e) => {
691
+ j.current?.insertSnippet(e.content), k({ source: e.content ?? "" }), requestAnimationFrame(() => j.current?.focus());
692
+ }
693
+ })), B(u, {
694
+ tabIndex: 0,
695
+ className: G("script-workspace", n),
696
+ sx: {
697
+ display: "flex",
698
+ flex: "1 1 100%",
699
+ flexDirection: "column",
700
+ overflow: "hidden",
701
+ alignItems: "stretch",
702
+ userSelect: "none",
703
+ flexGrow: 0,
704
+ outline: "none"
705
+ },
706
+ onPointerDown: (e) => {
707
+ e.isDefaultPrevented() || j.current?.focus();
708
+ },
709
+ children: V(u, {
710
+ sx: {
711
+ flex: "1 1 100%",
712
+ position: "relative",
713
+ display: "flex"
714
+ },
715
+ children: [B(u, {
716
+ sx: {
717
+ display: "flex",
718
+ flex: "1 1 100%",
719
+ minWidth: 0,
720
+ minHeight: 0,
721
+ visibility: e ? "hidden" : "visible"
722
+ },
723
+ children: z
724
+ }), e]
725
+ })
726
+ }));
727
+ }, [
728
+ L,
729
+ z,
730
+ n,
731
+ O,
732
+ I
733
+ ]), U = E(t, () => ({
734
+ isScriptWorkspaceElement: () => !0,
735
+ focus: (e) => {
736
+ F(e);
737
+ }
738
+ }), []);
739
+ return B(u, {
740
+ sx: {
741
+ display: "flex",
742
+ flexDirection: "row",
743
+ flex: "1 1 100%",
744
+ position: "relative",
745
+ ...r
746
+ },
747
+ ref: U,
748
+ ...y,
749
+ onFocus: (e) => {
750
+ S(!0), w.current = !0, U.current?.contains(e.target) && e.target !== U.current && N(e.target), e.relatedTarget && !P.current && (P.current = e.relatedTarget), y?.onFocus?.(e);
751
+ },
752
+ onBlur: (e) => {
753
+ U?.current?.contains(e.relatedTarget) || U?.current === e.relatedTarget || (P.current = null, w.current = !1, S(!1)), y?.onBlur?.(e);
754
+ },
755
+ children: H
756
+ });
757
+ }));
758
+ Q.displayName = "ScriptWorkspace";
759
+ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: he, useCommandScope: ge } = g, _e = { scopeName: "scriptEditor" }, ve = ({ children: e }) => {
760
+ let t = ge(), n = c(null);
761
+ return t ? B(me, {
762
+ spec: _e,
763
+ elementRef: n,
764
+ region: !0,
765
+ children: B(ye, {
766
+ paneRef: n,
767
+ children: e
768
+ })
769
+ }) : e;
770
+ }, ye = ({ paneRef: e, children: t }) => {
771
+ let n = ge(), r = o(() => n ? new pe(n.getRoot(), n) : null, [n]);
772
+ return r ? V(he, {
773
+ tracker: r,
774
+ keyBindings: !1,
775
+ debounce: 100,
776
+ elementRef: e,
777
+ children: [B(L, {}), B("div", {
778
+ className: "script-editor-pane",
779
+ style: { display: "contents" },
780
+ ref: e,
781
+ children: t
782
+ })]
783
+ }) : t;
784
+ }, be = (e) => {
785
+ let { model: t, entryKey: n, frame: r, ref: i, ...a } = e;
786
+ return B(ve, { children: B(Q, {
787
+ ref: i,
788
+ readOnly: !1,
789
+ frame: r,
790
+ scripts: (R() ?? t)?.getScripts(),
791
+ ...a
792
+ }) });
793
+ }, $ = r((e) => {
794
+ let { alwaysShow: t = !1, ...n } = e, [r, i] = s((e) => e + 1, 0), [o] = T(["showScriptEditor"], { onChange: () => i() }), c = R(), [u, d] = l(t);
795
+ return a(() => {
796
+ if (t) return void d(!0);
797
+ let e = c?.getScripts();
798
+ if (!e || !o) return void d(!1);
799
+ let n = async () => {
800
+ let t = !1;
801
+ o.getState() || (t = ((await e.searchFunctions({ type: "macro" }))?.length ?? 0) > 0), d(t || !!o.getState());
802
+ };
803
+ n();
804
+ let r = e.addListeners({ onChange: () => {
805
+ n();
806
+ } });
807
+ return () => {
808
+ r();
809
+ };
810
+ }, [
811
+ t,
812
+ c,
813
+ o,
814
+ r
815
+ ]), u ? V(z, { children: [B(j, {}), B(ae, { ...n })] }) : null;
816
+ });
817
+ $.displayName = "RunScriptContribution", q();
818
+ var xe = r(n((e, n) => {
819
+ let { ...r } = e, i = R(), o = D(), [s, c] = l([]);
820
+ a(() => {
821
+ let e = i?.getScripts();
822
+ if (!e) return;
823
+ let t = !1, n = async () => {
824
+ let n = await e.searchFunctions({ type: "formula" });
825
+ t || c(n);
826
+ };
827
+ n();
828
+ let r = e.addListeners({ onChange: () => {
829
+ n();
830
+ } });
831
+ return () => {
832
+ t = !0, r();
833
+ };
834
+ }, [i]);
835
+ let d = {
836
+ variant: _.Menuitem,
837
+ shortcut: void 0
838
+ }, f = [], p = s ? s.length : 0;
839
+ for (let e = 0; e < p; e++) {
840
+ let t = s[e];
841
+ f.push(B(O, {
842
+ ...d,
843
+ commandKey: "insertFunction",
844
+ commandState: t,
845
+ propsTooltip: { description: o("insertFunction.insertNamed", { name: t.getName() ?? o("insertFunction.fallbackLabel") }) },
846
+ icon: B(b, { iconKey: "FormulaCustom" }),
847
+ label: t.getName() ?? o("insertFunction.fallbackLabel")
848
+ }, `function-${t.getName()}-${e}`));
849
+ }
850
+ let m = V(u, {
851
+ ref: n,
852
+ sx: {
853
+ display: "flex",
854
+ flexDirection: "column",
855
+ flex: "1 1 100%",
856
+ overflow: "hidden"
857
+ },
858
+ children: [f.length > 0 ? V(z, { children: [B(u, {
859
+ sx: {
860
+ overflow: "auto",
861
+ flex: "1 1 100%"
862
+ },
863
+ children: f
864
+ }), B(j, { orientation: "horizontal" })] }) : null, t(O, {
865
+ ...d,
866
+ key: "show-editor",
867
+ commandKey: "showScriptEditor"
868
+ })]
869
+ });
870
+ return P({
871
+ ...r,
872
+ children: m
873
+ });
874
+ }));
875
+ xe.displayName = "InsertFunctionPopupPanel";
876
+ var Se = r(n((e, t) => {
877
+ let { disabled: n, groupKey: r, ...a } = e, o = w("customFunctionOptions");
878
+ return B(k, {
879
+ ref: t,
880
+ disabled: n,
881
+ createPopupPanel: i((e) => {
882
+ let t = B(xe, {
883
+ disabled: n,
884
+ groupKey: r,
885
+ ...e
886
+ });
887
+ return P({
888
+ ...e,
889
+ children: t
890
+ });
891
+ }, [n, r]),
892
+ label: o?.getLabel?.(),
893
+ tooltip: o?.getDescription?.(),
894
+ icon: "FormulaCustom",
895
+ ...a
896
+ });
897
+ }));
898
+ Se.displayName = "InsertFunctionContribution";
899
+ var Ce = () => {
900
+ ne(), y.register("plugin-scripts", { icons: {} }), I.registerTaskPane({
901
+ key: "scriptEditor",
902
+ getTitle: () => "Script (Typescript)",
903
+ getIcon: () => "ScriptRun",
904
+ component: be,
905
+ keepMounted: !0
906
+ }, !0), v.register({ key: "scriptsOptions" }, !0), v.register({ key: "customFunctionOptions" }, !0), v.register({
907
+ key: "scripting.runScript.home",
908
+ contributions: { homeToolbar: {} },
909
+ render: (t) => e.createElement($, { ...t })
910
+ }, !0), v.register({
911
+ key: "scripting.runScript.view",
912
+ contributions: { viewToolbar: { order: 10 } },
913
+ render: (t) => e.createElement($, {
914
+ ...t,
915
+ groupKey: "view",
916
+ alwaysShow: !0
917
+ })
918
+ }, !0), v.register({
919
+ key: "scripting.insertFunction.formula",
920
+ contributions: { formulaToolbar: {
921
+ anchor: "formulaCategory.web",
922
+ order: 1
923
+ } },
924
+ render: (t) => e.createElement(Se, { ...t })
925
+ }, !0);
926
+ };
927
+ export { de as InsertScriptCommandButton, ae as RunScriptCommandButton, Z as ScriptEditorToolbar, be as ScriptTaskPane, Q as ScriptWorkspace, Ce as ScriptingPlugin };