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