@sheetxl/scripting-mui 0.8.0-beta.1 → 0.8.0-beta.10

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.
@@ -1,22 +1,25 @@
1
1
  /**
2
- * @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.1
2
+ * @license @sheetxl/scripting-mui - Scripting MUI - MUI script workspace, toolbar and run-script plugin for SheetXL. - v0.8.0-beta.10
3
3
  *
4
4
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
5
  * License: The license can be found at https://www.sheetxl.com/license.
6
6
  */
7
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
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";
9
+ import { Box as p, Button as m, CircularProgress as u, Paper as h, Typography as f, useTheme as x } from "@mui/material";
10
+ import { Command as g, CommandButtonType as y, DefaultCommandButtonRegistry as S, DefaultIconService as b, DynamicIcon as v, 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 D, CommandButton as I, CommandPopupButton as L, CommandToolbar as P, ExhibitDivider as $, ExhibitMenuItem as E, OverflowPalette as R, defaultCreatePopupPanel as z } from "@sheetxl/utils-mui";
12
+ import { DefaultTaskPaneRegistry as A, InputClipboardInjector as B, useModelSync as O, useWorkbook as M } from "@sheetxl/react";
13
13
  import { Fragment as W, jsx as j, jsxs as H } from "react/jsx-runtime";
14
14
  import { alpha as U } from "@mui/system";
15
- import { ChainedError as q } from "@sheetxl/utils";
15
+ import { VERSION as q } from "@sheetxl/sdk";
16
+ import { ChainedError as Z } from "@sheetxl/utils";
16
17
  import { ScriptEditor as G, ScriptingReactPlugin as J } from "@sheetxl/scripting-react";
17
- var Z = {
18
+ var _ = {
18
19
  "insertFunction.fallbackLabel": "Function",
19
20
  "insertFunction.insertNamed": "Insert {name}",
21
+ "insertScript.fallbackLabel": "Insert Script",
22
+ "insertScript.loading": "Loading...",
20
23
  "runScript.executeNamed": "Execute {name}",
21
24
  "runScript.fallbackLabel": "Macro",
22
25
  "templateSelect.blankSummary": "Start with an empty script.",
@@ -27,12 +30,12 @@ var Z = {
27
30
  "templateSelect.loadFailed": "Failed to load scripts",
28
31
  "templateSelect.title": "Script Template",
29
32
  "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
+ }, { DefaultCommandCatalogService: Q } = g, V = !1;
34
+ function X() {
35
+ V || (V = !0, Q.registerFromManifest("@sheetxl/scripting-mui", import.meta.url, { messages: _ }));
33
36
  }
34
- V();
35
- var X = n(r((e, r) => {
37
+ X();
38
+ var Y = n(r((e, r) => {
36
39
  const { groupKey: n, ...i } = e, a = M(), l = K(), [s, d] = c([]), [m, u] = c(!1);
37
40
  o(() => {
38
41
  const e = a?.getScripts();
@@ -47,19 +50,19 @@ var X = n(r((e, r) => {
47
50
  variant: y.Menuitem,
48
51
  groupKey: "scriptsOptions",
49
52
  shortcut: void 0
50
- }, f = [], g = s ? s.length : 0;
51
- for (let e = 0; e < g; e++) {
53
+ }, f = [], x = s ? s.length : 0;
54
+ for (let e = 0; e < x; e++) {
52
55
  const t = s[e];
53
- f.push(j(D, {
56
+ f.push(j(I, {
54
57
  ...h,
55
58
  commandKey: "executeScript",
56
59
  commandState: { declaration: t },
57
60
  propsTooltip: { description: l("runScript.executeNamed", { name: t.getName() ?? l("runScript.fallbackLabel") }) },
58
- icon: j(b, { iconKey: "ScriptMacro" }),
61
+ icon: j(v, { iconKey: "ScriptMacro" }),
59
62
  label: t.getName() ?? l("runScript.fallbackLabel")
60
63
  }, `macro-${t.getName()}-${e}`));
61
64
  }
62
- const x = H(p, {
65
+ const g = H(p, {
63
66
  ref: r,
64
67
  sx: {
65
68
  display: "flex",
@@ -73,7 +76,7 @@ var X = n(r((e, r) => {
73
76
  flex: "1 1 100%"
74
77
  },
75
78
  children: f
76
- }), j(L, { orientation: "horizontal" })] }) : null, t(D, {
79
+ }), j($, { orientation: "horizontal" })] }) : null, t(I, {
77
80
  ...h,
78
81
  key: "show-editor",
79
82
  commandKey: "showScriptEditor"
@@ -81,48 +84,48 @@ var X = n(r((e, r) => {
81
84
  });
82
85
  return z({
83
86
  ...i,
84
- children: x
87
+ children: g
85
88
  });
86
89
  }));
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, {
90
+ Y.displayName = "RunScriptPopupPanel";
91
+ var ee = n(r((e, t) => {
92
+ const { groupKey: r, disabled: n, ...o } = e, a = N(["showScriptEditor"])[0], l = F("scriptsOptions"), s = i((e) => {
93
+ const t = j(Y, {
94
+ disabled: n,
95
+ groupKey: r,
96
+ ...e
97
+ });
98
+ return z({
99
+ ...e,
100
+ children: t
101
+ });
102
+ }, [n, r]);
103
+ return j(L, {
91
104
  ref: t,
92
105
  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]),
106
+ createPopupPanel: s,
104
107
  selected: a?.getState(),
105
108
  label: l?.getLabel?.(),
106
109
  tooltip: l?.getDescription?.(),
107
110
  quickCommand: "showScriptEditor",
108
111
  ...o
109
112
  });
110
- })), ee = "https://unpkg.com/@sheetxl/scripting-templates/dist", te = (e, t) => {
113
+ })), te = /^\d+\.\d+\.\d+-([0-9A-Za-z-]+)/.exec(q)?.[1], re = `https://unpkg.com/@sheetxl/templates-scripting${te ? `@${te}` : ""}/dist`, ne = (e, t) => {
111
114
  try {
112
115
  return new URL(t).href;
113
116
  } catch {}
114
117
  if (t.startsWith("/") || /^[a-zA-Z]:/.test(t)) return t;
115
118
  let r = e.startsWith("http") ? e : `file:///${e.replace(/\\/g, "/")}`;
116
119
  return r.endsWith("/") || (r += "/"), new URL(t, r).href;
117
- }, re = (e) => {
120
+ }, ie = (e) => {
118
121
  if (e.metadata?.name) return e.metadata.name;
119
122
  let t = (e.path.split("/").pop() || "").replace(/\.[^/.]+$/, "");
120
123
  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
+ }, oe = async (e) => {
125
+ const t = ne(e, "./manifest.json"), r = await fetch(t);
126
+ if (!r.ok) throw new Z(`Failed to retrieve directory at '${e}': ${r.statusText}`);
124
127
  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}'`);
128
+ if (n.trim().toLowerCase().startsWith("<!doctype html") || n.trim().toLowerCase().startsWith("<html")) throw new Z(`Failed to retrieve directory at '${e}'`);
126
129
  let i;
127
130
  try {
128
131
  i = JSON.parse(n);
@@ -131,12 +134,12 @@ var Y = n(r((e, t) => {
131
134
  }
132
135
  const o = i.map(async (t) => {
133
136
  try {
134
- const r = te(e, t.path), n = await fetch(r);
137
+ const r = ne(e, t.path), n = await fetch(r);
135
138
  if (!n.ok) throw new Error(`Failed to fetch file at '${t.path}': ${n.statusText}`);
136
139
  const i = await n.text();
137
140
  let o = t.metadata;
138
141
  return o?.title || (o = {
139
- title: re(t),
142
+ title: ie(t),
140
143
  ...o
141
144
  }), {
142
145
  path: t.path,
@@ -149,23 +152,23 @@ var Y = n(r((e, t) => {
149
152
  return null;
150
153
  });
151
154
  return (await Promise.all(o)).filter((e) => null !== e);
152
- }, ie = { marginRight: "4px" }, oe = "1em", ae = n((e) => {
155
+ }, ae = { marginRight: "4px" }, le = "1em", se = n((e) => {
153
156
  const { disabled: t, snippet: r, description: n, handleInsert: i, sx: o, ...a } = e;
154
157
  let l;
155
158
  const s = r.metadata?.icon;
156
- return l = j(b, "formula" === s ? {
159
+ return l = j(v, "formula" === s ? {
157
160
  iconKey: "ScriptFormula",
158
- size: oe,
159
- style: ie
161
+ size: le,
162
+ style: ae
160
163
  } : "macro" === s ? {
161
164
  iconKey: "ScriptMacro",
162
- size: oe,
163
- style: ie
165
+ size: le,
166
+ style: ae
164
167
  } : {
165
168
  iconKey: "ScriptAutoRun",
166
- size: oe,
167
- style: ie
168
- }), j($, {
169
+ size: le,
170
+ style: ae
171
+ }), j(E, {
169
172
  sx: {
170
173
  maxWidth: "460px",
171
174
  display: "flex",
@@ -206,30 +209,30 @@ var Y = n(r((e, t) => {
206
209
  })]
207
210
  })
208
211
  });
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"]);
212
+ }), ce = n(r((e, r) => {
213
+ const { groupKey: n, disabled: a, scriptPath: l = re, ...s } = e, d = K(), [m, u] = c([]), [h, f] = c(!0), [x] = N(["insertScript"]), g = a || (x?.disabled() ?? !1);
211
214
  o(() => {
212
215
  (async () => {
213
216
  try {
214
- const e = await ne(l);
215
- m(e);
217
+ const e = await oe(l);
218
+ u(e);
216
219
  } catch (e) {} finally {
217
- h(!1);
220
+ f(!1);
218
221
  }
219
222
  })();
220
223
  }, [l]);
221
- const g = i((e) => {
222
- if (u) return j("div", { children: "Loading..." });
224
+ const S = i((e) => {
225
+ if (h) return j("div", { children: d("insertScript.loading") });
223
226
  const r = {
224
227
  variant: y.Menuitem,
225
228
  groupKey: "scriptsOptions",
226
- disabled: a
229
+ disabled: g
227
230
  }, n = (t) => {
228
- f?.execute(t.content), e.closeFloat?.();
231
+ x?.execute(t.content), e.closeFloat?.();
229
232
  }, i = [];
230
- for (let e = 0; e < d.length; e++) {
231
- const t = d[e];
232
- t && i.push(j(ae, {
233
+ for (let e = 0; e < m.length; e++) {
234
+ const t = m[e];
235
+ t && i.push(j(se, {
233
236
  handleInsert: n,
234
237
  snippet: t
235
238
  }, t.path));
@@ -248,13 +251,13 @@ var Y = n(r((e, t) => {
248
251
  flex: "1 1 100%"
249
252
  },
250
253
  children: i
251
- }), j(L, { orientation: "horizontal" })] }) : null,
252
- t(D, {
254
+ }), j($, { orientation: "horizontal" })] }) : null,
255
+ t(I, {
253
256
  ...r,
254
257
  key: "showKeyboardShortcuts",
255
258
  commandKey: "showKeyboardShortcuts"
256
259
  }),
257
- t(D, {
260
+ t(I, {
258
261
  ...r,
259
262
  key: "scriptingHelp",
260
263
  commandKey: "scriptingHelp"
@@ -266,80 +269,81 @@ var Y = n(r((e, t) => {
266
269
  children: o
267
270
  });
268
271
  }, [
269
- a,
272
+ g,
270
273
  n,
271
- u,
272
- f
274
+ h,
275
+ x,
276
+ d
273
277
  ]);
274
- return j(P, {
278
+ return j(L, {
275
279
  ref: r,
276
- disabled: a,
280
+ disabled: g,
277
281
  groupKey: n,
278
- label: f?.getLabel(n) ?? "Insert Script",
279
- tooltip: f?.getDescription(),
280
- createPopupPanel: g,
281
- icon: f?.getIcon() ?? "ScriptInsert",
282
+ label: x?.getLabel(n) ?? d("insertScript.fallbackLabel"),
283
+ tooltip: x?.getDescription(),
284
+ createPopupPanel: S,
285
+ icon: x?.getIcon() ?? "ScriptInsert",
282
286
  ...s
283
287
  });
284
- })), se = n(r((e, t) => {
285
- const { propsCommandButton: r, ...n } = e;
286
- return j(E, {
288
+ })), de = n(r((e, t) => {
289
+ const { propsCommandButton: r, ...n } = e, i = 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(I, {
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(ce, { ...t })
308
+ }) })
309
+ ]
310
+ }) });
311
+ }, []);
312
+ return j(P, {
287
313
  ref: t,
288
314
  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
- }, []),
315
+ renderToolbarPalette: i,
312
316
  ...n
313
317
  });
314
318
  }));
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);
319
+ de.displayName = "ScriptEditorToolbar", X();
320
+ var pe = n(r((e, t) => {
321
+ const { scriptPath: r = re, onScriptSelect: n, disabled: i = !1, sx: a = k.EmptyCssProperties, className: l, buttonMinWidth: s = 210, buttonMinHeight: h = 80, gap: x = 12, ...g } = e, y = K(), [S, b] = c([]), [w, C] = c(!0), [F, N] = c(null);
318
322
  if (o(() => {
319
323
  (async () => {
320
324
  const e = [{
321
325
  path: null,
322
326
  metadata: {
323
- title: x("templateSelect.blankTitle"),
324
- summary: x("templateSelect.blankSummary")
327
+ title: y("templateSelect.blankTitle"),
328
+ summary: y("templateSelect.blankSummary")
325
329
  },
326
330
  content: ""
327
331
  }];
328
332
  try {
329
- w(!0), F(null);
330
- const t = await ne(r);
333
+ C(!0), N(null);
334
+ const t = await oe(r);
331
335
  for (let r = 0; r < t.length; r++) {
332
336
  const n = t[r];
333
337
  n && e.push(n);
334
338
  }
335
339
  } catch (e) {
336
- F(e instanceof Error ? e.message : x("templateSelect.loadFailed")), e instanceof q || console.error("Error loading scripts:", e);
340
+ N(e instanceof Error ? e.message : y("templateSelect.loadFailed")), e instanceof Z || console.error("Error loading scripts:", e);
337
341
  } finally {
338
- S(e), w(!1);
342
+ b(e), C(!1);
339
343
  }
340
344
  })();
341
- }, [r, x]), v) return j(p, {
342
- className: d(a, "script-select"),
345
+ }, [r, y]), w) return j(p, {
346
+ className: d(l, "script-select"),
343
347
  ...g,
344
348
  sx: [{
345
349
  display: "flex",
@@ -348,14 +352,13 @@ var ce = n(r((e, t) => {
348
352
  height: "100%",
349
353
  background: (e) => e.palette.background.paper,
350
354
  zIndex: 1e3,
351
- backgroundImage: B,
352
- ...Array.isArray(i) ? {} : i
353
- }, ...Array.isArray(i) ? i : []],
355
+ ...Array.isArray(a) ? {} : a
356
+ }, ...Array.isArray(a) ? a : []],
354
357
  children: j(u, {})
355
358
  });
356
- let N = null;
357
- C && (N = H(p, {
358
- className: d(a, "script-select", "error-results"),
359
+ let T = null;
360
+ F && (T = H(p, {
361
+ className: d(l, "script-select", "error-results"),
359
362
  ...g,
360
363
  sx: [{
361
364
  display: "flex",
@@ -368,42 +371,40 @@ var ce = n(r((e, t) => {
368
371
  padding: (e) => e.spacing(1),
369
372
  border: (e) => `1px solid ${e.palette.error.main}`,
370
373
  borderBottomLeftRadius: 1,
371
- borderBottomRightRadius: 1,
372
- backgroundImage: B
373
- }, ...Array.isArray(i) ? i : [i]],
374
+ borderBottomRightRadius: 1
375
+ }, ...Array.isArray(a) ? a : [a]],
374
376
  children: [j(f, {
375
377
  color: "error",
376
378
  variant: "h6",
377
379
  component: "div",
378
380
  gutterBottom: !0,
379
- children: x("templateSelect.errorTitle")
381
+ children: y("templateSelect.errorTitle")
380
382
  }), j(f, {
381
383
  color: "error",
382
384
  component: "div",
383
- children: C
385
+ children: F
384
386
  })]
385
387
  }));
386
- const T = (e) => {
388
+ const D = (e) => {
387
389
  const t = e.metadata?.icon;
388
- return "macro" === t ? j(b, {
390
+ return "macro" === t ? j(v, {
389
391
  iconKey: "ScriptMacro",
390
392
  size: "1em"
391
- }) : "formula" === t ? j(b, {
393
+ }) : "formula" === t ? j(v, {
392
394
  iconKey: "ScriptFormula",
393
395
  size: "1em"
394
- }) : "autostart" === t ? j(b, {
396
+ }) : "autostart" === t ? j(v, {
395
397
  iconKey: "ScriptAutoRun",
396
398
  size: "1em"
397
399
  }) : null;
398
400
  };
399
401
  return H(p, {
400
402
  ref: t,
401
- className: d(a, "script-select"),
403
+ className: d(l, "script-select"),
402
404
  sx: {
403
405
  background: (e) => e.palette.background.paper,
404
406
  zIndex: 1e3,
405
- backgroundImage: B,
406
- ...i
407
+ ...a
407
408
  },
408
409
  ...g,
409
410
  children: [H(p, {
@@ -417,36 +418,37 @@ var ce = n(r((e, t) => {
417
418
  j(f, {
418
419
  variant: "h6",
419
420
  gutterBottom: !0,
420
- children: x("templateSelect.title")
421
+ children: y("templateSelect.title")
421
422
  }),
422
423
  j(f, {
423
424
  variant: "body2",
424
425
  component: "div",
425
426
  gutterBottom: !0,
426
427
  sx: { color: "text.secondary" },
427
- children: x("templateSelect.intro")
428
+ children: y("templateSelect.intro")
428
429
  }),
429
430
  j(f, {
430
431
  variant: "body2",
431
432
  component: "div",
432
433
  gutterBottom: !0,
433
434
  sx: { color: "text.secondary" },
434
- children: x("templateSelect.intro2")
435
+ children: y("templateSelect.intro2")
435
436
  }),
436
437
  j(p, {
437
438
  sx: {
438
439
  display: "grid",
439
- gridTemplateColumns: `repeat(auto-fill, minmax(${l}px, 1fr))`,
440
- gap: `${h}px`,
440
+ gridTemplateColumns: `repeat(auto-fill, minmax(${s}px, 1fr))`,
441
+ gap: `${x}px`,
441
442
  padding: 2,
442
443
  paddingLeft: "0px",
443
444
  paddingRight: "0px"
444
445
  },
445
- children: y.map((e, t) => H(m, {
446
+ children: S.map((e, t) => H(m, {
446
447
  variant: "outlined",
448
+ disabled: i,
447
449
  sx: {
448
- minWidth: l,
449
- minHeight: s,
450
+ minWidth: s,
451
+ minHeight: h,
450
452
  display: "flex",
451
453
  flexDirection: "column",
452
454
  justifyContent: "flex-start",
@@ -474,8 +476,8 @@ var ce = n(r((e, t) => {
474
476
  children: [j(f, {
475
477
  variant: "subtitle2",
476
478
  component: "div",
477
- children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") || x("templateSelect.untitled")
478
- }), T(e)]
479
+ children: e.metadata?.title || e.path?.split("/").pop()?.replace(/\.\w+$/, "") || y("templateSelect.untitled")
480
+ }), D(e)]
479
481
  }), e.metadata?.summary && j(f, {
480
482
  variant: "body2",
481
483
  component: "div",
@@ -492,44 +494,44 @@ var ce = n(r((e, t) => {
492
494
  }, `${e.path}-${t}`))
493
495
  })
494
496
  ]
495
- }), N]
497
+ }), T]
496
498
  });
497
499
  }));
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({
500
+ pe.displayName = "TemplateSelectPanel";
501
+ var me = n(r((e, t) => {
502
+ const { className: r, sx: n, propsScriptEditor: l, readOnly: m = !1, frame: u, autoFocusSel: g, autoFocus: y = !0, scripts: S, ...b } = e, v = x(), [w, k] = c(!1), F = s(!1), [N, K] = c({
501
503
  message: "Loading",
502
504
  cursor: "",
503
505
  dirty: !1
504
- }), [D, P] = c(null);
506
+ }), [I, L] = c(null);
505
507
  o(() => {
506
508
  let e = !1;
507
- return P(null), async function() {
509
+ return L(null), async function() {
508
510
  if (S && (await S.start(), !e)) {
509
511
  const e = S.getModules().getItems()[0]?.getSource();
510
- P({ source: e || null });
512
+ L({ source: e || null });
511
513
  }
512
514
  }(), () => {
513
515
  e = !0;
514
516
  };
515
517
  }, [S]);
516
- const E = i((e) => {
518
+ const P = i((e) => {
517
519
  K((t) => ({
518
520
  ...t,
519
521
  ...e
520
522
  }));
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);
523
+ }, []), $ = s(null), [E, R] = c(null), z = s(null), A = C((e) => {
524
+ if (E) return E.focus(e), !0;
525
+ if (g) {
526
+ const t = $.current?.querySelectorAll?.(g);
525
527
  if (t && t.length > 0) return t[0]?.focus?.(e), !0;
526
528
  }
527
- return L.current?.focus?.(e), !1;
529
+ return $.current?.focus?.(e), !1;
528
530
  }, [
529
- $,
530
- x,
531
+ E,
532
+ g,
531
533
  y
532
- ]), A = a(() => j(I, {
534
+ ]), B = a(() => j(D, {
533
535
  transitionDelay: "160ms",
534
536
  style: {
535
537
  position: "absolute",
@@ -550,8 +552,8 @@ var de = n(r((e, t) => {
550
552
  marginTop: (e) => e.spacing(1),
551
553
  marginBottom: (e) => e.spacing(1)
552
554
  },
553
- children: j(se, {})
554
- }), [b]), M = a(() => j(p, {
555
+ children: j(de, {})
556
+ }), [v]), M = a(() => j(p, {
555
557
  className: d("script-status-panel", "status-panel"),
556
558
  sx: {
557
559
  display: "flex",
@@ -564,7 +566,7 @@ var de = n(r((e, t) => {
564
566
  paddingTop: "1px",
565
567
  minHeight: "calc(1em + 8px)",
566
568
  margin: 0,
567
- borderTop: `solid 1px ${b.palette.divider}`
569
+ borderTop: `solid 1px ${v.palette.divider}`
568
570
  },
569
571
  children: H("div", {
570
572
  style: {
@@ -641,34 +643,34 @@ var de = n(r((e, t) => {
641
643
  boxSizing: "border-box"
642
644
  },
643
645
  children: j(G, {
644
- ref: L,
645
- loadingPanel: A,
646
+ ref: $,
647
+ loadingPanel: B,
646
648
  readOnly: m,
647
649
  frame: u,
648
650
  scripts: S,
649
651
  autoFocus: y,
650
- onStatusChange: E,
651
- darkMode: "dark" === b.palette.mode,
652
+ onStatusChange: P,
653
+ darkMode: "dark" === v.palette.mode,
652
654
  ...l
653
655
  })
654
656
  }),
655
657
  M
656
658
  ]
657
659
  }), [
658
- b,
660
+ v,
659
661
  O,
660
662
  M,
661
663
  w,
662
- A,
664
+ B,
663
665
  m,
664
666
  l,
665
667
  y,
666
- x,
668
+ g,
667
669
  u,
668
- E
670
+ P
669
671
  ]), U = a(() => {
670
672
  let e;
671
- return null === D ? A : (null === D.source && (e = j(ce, {
673
+ return null === I ? B : (null === I.source && (e = j(pe, {
672
674
  sx: {
673
675
  display: "flex",
674
676
  flex: "1 1 100%",
@@ -679,8 +681,9 @@ var de = n(r((e, t) => {
679
681
  width: "100%",
680
682
  height: "100%"
681
683
  },
684
+ disabled: m,
682
685
  onScriptSelect: (e) => {
683
- L.current?.insertSnippet(e.content), P({ source: e.content ?? "" }), requestAnimationFrame(() => L.current?.focus());
686
+ $.current?.insertSnippet(e.content), L({ source: e.content ?? "" }), requestAnimationFrame(() => $.current?.focus());
684
687
  }
685
688
  })), j(p, {
686
689
  tabIndex: 0,
@@ -696,7 +699,7 @@ var de = n(r((e, t) => {
696
699
  outline: "none"
697
700
  },
698
701
  onPointerDown: (e) => {
699
- e.isDefaultPrevented() || L.current?.focus();
702
+ e.isDefaultPrevented() || $.current?.focus();
700
703
  },
701
704
  children: H(p, {
702
705
  sx: {
@@ -720,12 +723,13 @@ var de = n(r((e, t) => {
720
723
  O,
721
724
  W,
722
725
  r,
723
- D,
724
- A
726
+ I,
727
+ B,
728
+ m
725
729
  ]), q = T(t, () => ({
726
730
  isScriptWorkspaceElement: () => !0,
727
731
  focus: (e) => {
728
- B(e);
732
+ A(e);
729
733
  }
730
734
  }), []);
731
735
  return j(p, {
@@ -737,52 +741,54 @@ var de = n(r((e, t) => {
737
741
  ...n
738
742
  },
739
743
  ref: q,
740
- ...v,
744
+ ...b,
741
745
  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);
746
+ 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), b?.onFocus?.(e);
743
747
  },
744
748
  onBlur: (e) => {
745
- q?.current?.contains(e.relatedTarget) || q?.current === e.relatedTarget || (z.current = null, F.current = !1, k(!1)), v?.onBlur?.(e);
749
+ q?.current?.contains(e.relatedTarget) || q?.current === e.relatedTarget || (z.current = null, F.current = !1, k(!1)), b?.onBlur?.(e);
746
750
  },
747
751
  children: U
748
752
  });
749
753
  }));
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,
754
+ me.displayName = "ScriptWorkspace";
755
+ var { FocusActivation: ue, CommandScopeProvider: he, CommandAnchorProvider: fe, useCommandScope: xe } = g, ge = { scopeName: "scriptEditor" }, ye = ({ children: e }) => {
756
+ const t = xe(), r = s(null);
757
+ return t ? j(he, {
758
+ spec: ge,
755
759
  elementRef: r,
756
760
  region: !0,
757
- children: j(xe, {
761
+ children: j(Se, {
758
762
  paneRef: r,
759
763
  children: e
760
764
  })
761
765
  }) : 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, {
766
+ }, Se = ({ paneRef: e, children: t }) => {
767
+ const r = xe(), n = a(() => r ? new ue(r.getRoot(), r) : null, [r]);
768
+ return n ? H(fe, {
765
769
  tracker: n,
766
770
  keyBindings: !1,
767
771
  debounce: 100,
768
772
  elementRef: e,
769
- children: [j(O, {}), j("div", {
773
+ children: [j(B, {}), j("div", {
770
774
  className: "script-editor-pane",
771
775
  style: { display: "contents" },
772
776
  ref: e,
773
777
  children: t
774
778
  })]
775
779
  }) : t;
776
- }, ye = (e) => {
777
- const { model: t, entryKey: r, frame: n, ref: i, ...o } = e;
778
- return j(ge, { children: j(de, {
780
+ }, be = (e) => {
781
+ const { model: t, entryKey: r, frame: n, ref: i, ...o } = e, a = M() ?? t;
782
+ O(a, ["onProtectionChange"]);
783
+ const l = a?.getScripts().isReadOnly() ?? !1;
784
+ return j(ye, { children: j(me, {
779
785
  ref: i,
780
- readOnly: !1,
786
+ readOnly: l,
781
787
  frame: n,
782
- scripts: (M() ?? t)?.getScripts(),
788
+ scripts: a?.getScripts(),
783
789
  ...o
784
790
  }) });
785
- }, Se = n((e) => {
791
+ }, ve = n((e) => {
786
792
  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
793
  return o(() => {
788
794
  if (t) return void p(!0);
@@ -804,10 +810,10 @@ var { FocusActivation: pe, CommandScopeProvider: me, CommandAnchorProvider: ue,
804
810
  s,
805
811
  a,
806
812
  n
807
- ]), d ? H(W, { children: [j(L, {}), j(Y, { ...r })] }) : null;
813
+ ]), d ? H(W, { children: [j($, {}), j(ee, { ...r })] }) : null;
808
814
  });
809
- Se.displayName = "RunScriptContribution", V();
810
- var ve = n(r((e, r) => {
815
+ ve.displayName = "RunScriptContribution", X();
816
+ var we = n(r((e, r) => {
811
817
  const { ...n } = e, i = M(), a = K(), [l, s] = c([]);
812
818
  o(() => {
813
819
  const e = i?.getScripts();
@@ -831,12 +837,12 @@ var ve = n(r((e, r) => {
831
837
  }, m = [], u = l ? l.length : 0;
832
838
  for (let e = 0; e < u; e++) {
833
839
  const t = l[e];
834
- m.push(j(D, {
840
+ m.push(j(I, {
835
841
  ...d,
836
842
  commandKey: "insertFunction",
837
843
  commandState: t,
838
844
  propsTooltip: { description: a("insertFunction.insertNamed", { name: t.getName() ?? a("insertFunction.fallbackLabel") }) },
839
- icon: j(b, { iconKey: "FormulaCustom" }),
845
+ icon: j(v, { iconKey: "FormulaCustom" }),
840
846
  label: t.getName() ?? a("insertFunction.fallbackLabel")
841
847
  }, `function-${t.getName()}-${e}`));
842
848
  }
@@ -854,7 +860,7 @@ var ve = n(r((e, r) => {
854
860
  flex: "1 1 100%"
855
861
  },
856
862
  children: m
857
- }), j(L, { orientation: "horizontal" })] }) : null, t(D, {
863
+ }), j($, { orientation: "horizontal" })] }) : null, t(I, {
858
864
  ...d,
859
865
  key: "show-editor",
860
866
  commandKey: "showScriptEditor"
@@ -865,45 +871,45 @@ var ve = n(r((e, r) => {
865
871
  children: h
866
872
  });
867
873
  }));
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, {
874
+ we.displayName = "InsertFunctionPopupPanel";
875
+ var ke = n(r((e, t) => {
876
+ const { disabled: r, groupKey: n, ...o } = e, a = F("customFunctionOptions"), l = i((e) => {
877
+ const t = j(we, {
878
+ disabled: r,
879
+ groupKey: n,
880
+ ...e
881
+ });
882
+ return z({
883
+ ...e,
884
+ children: t
885
+ });
886
+ }, [r, n]);
887
+ return j(L, {
872
888
  ref: t,
873
889
  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]),
890
+ createPopupPanel: l,
885
891
  label: a?.getLabel?.(),
886
892
  tooltip: a?.getDescription?.(),
887
893
  icon: "FormulaCustom",
888
894
  ...o
889
895
  });
890
896
  }));
891
- be.displayName = "InsertFunctionContribution";
892
- var we = () => {
893
- J(), v.register("plugin-scripts", { icons: {} }), A.registerTaskPane({
897
+ ke.displayName = "InsertFunctionContribution";
898
+ var Ce = () => {
899
+ J(), b.register("plugin-scripts", { icons: {} }), A.registerTaskPane({
894
900
  key: "scriptEditor",
895
901
  getTitle: () => "Script (Typescript)",
896
902
  getIcon: () => "ScriptRun",
897
- component: ye,
903
+ component: be,
898
904
  keepMounted: !0
899
905
  }, !0), S.register({ key: "scriptsOptions" }, !0), S.register({ key: "customFunctionOptions" }, !0), S.register({
900
906
  key: "scripting.runScript.home",
901
907
  contributions: { homeToolbar: {} },
902
- render: (t) => e.createElement(Se, { ...t })
908
+ render: (t) => e.createElement(ve, { ...t })
903
909
  }, !0), S.register({
904
910
  key: "scripting.runScript.view",
905
911
  contributions: { viewToolbar: { order: 10 } },
906
- render: (t) => e.createElement(Se, {
912
+ render: (t) => e.createElement(ve, {
907
913
  ...t,
908
914
  groupKey: "view",
909
915
  alwaysShow: !0
@@ -914,7 +920,7 @@ var we = () => {
914
920
  anchor: "formulaCategory.web",
915
921
  order: 1
916
922
  } },
917
- render: (t) => e.createElement(be, { ...t })
923
+ render: (t) => e.createElement(ke, { ...t })
918
924
  }, !0);
919
925
  };
920
- export { le as InsertScriptCommandButton, Y as RunScriptCommandButton, se as ScriptEditorToolbar, ye as ScriptTaskPane, de as ScriptWorkspace, we as ScriptingPlugin };
926
+ export { ce as InsertScriptCommandButton, ee as RunScriptCommandButton, de as ScriptEditorToolbar, be as ScriptTaskPane, me as ScriptWorkspace, Ce as ScriptingPlugin };