@sheetxl/scripting-react 0.8.0-beta.1 → 0.8.0-beta.11

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,41 +1,44 @@
1
1
  (function(){try{if(typeof document<`u`){var e=document.createElement(`style`);e.appendChild(document.createTextNode(`._script-editor_1kuph_5{& .monaco-editor{position:absolute;& .margin-icon{background-position:50%;background-repeat:no-repeat;background-size:contain;width:16px;height:16px;display:block}& .formula{cursor:pointer;background-image:url("data:image/svg+xml;utf8,<svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" fill=\\"grey\\"><path d=\\"m 12.106007,8.1692949 c 0.124174,-0.1578352 0.181773,-0.3565642 0.283755,-0.5271169 0.10273,-0.1715492 0.04413,-0.2027176 -0.129161,-0.2014713 -0.685452,0.00576 -1.371152,-0.00277 -2.056604,0.00501 C 10.021228,7.4479573 9.9586414,7.407817 9.9935503,7.2080883 10.145401,6.3413623 10.291269,5.4736396 10.51219,4.6213758 10.642847,4.1167002 10.782479,3.6117747 11.061498,3.1622046 11.339518,2.7138809 11.726751,2.5974365 12.2035,2.829328 c 0.398455,0.1934923 0.722604,0.4827333 0.990152,0.8340617 0.116944,0.1535968 0.27079,0.2740306 0.449073,0.1715499 0.343348,-0.1974819 0.644807,-0.4383502 0.819599,-0.826332 0.100985,-0.2244112 0.157836,-0.476001 0.04039,-0.7058977 C 14.339646,1.9840253 14.038187,1.7618584 13.707056,1.6394296 13.156999,1.4362128 12.562559,1.4840872 12.017239,1.6758341 11.38789,1.8970037 10.783727,2.2625445 10.259602,2.6724688 10.066109,2.8238217 9.8783519,2.9839017 9.7013165,3.1547035 9.0502751,3.7823067 8.5657962,4.529097 8.2246919,5.3651534 7.9823276,5.9595939 7.7888351,6.5660026 7.6913412,7.2015842 7.673637,7.318528 7.6357391,7.423253 7.5065759,7.4432009 7.3472438,7.4678879 7.1592376,7.4436995 6.9974121,7.4441728 6.6351128,7.4451447 6.2598478,7.3676233 5.9915515,7.6815496 5.8721151,7.8211835 5.7461952,7.9840062 5.6439635,8.1371045 c -0.1009847,0.1518511 -0.093255,0.3002122 0.085027,0.367535 0.1957362,0.073561 0.4528118,0.026182 0.6530361,0.0197 0.2645558,-0.00847 0.5291116,0.00501 0.7936674,-7.476e-4 0.1820229,-0.00374 0.2413669,0.030421 0.2064588,0.2358807 C 7.3487406,8.9587006 7.3095941,9.1492003 7.2804197,9.3464333 7.1804317,10.024404 7.0667304,10.700629 6.9525298,11.376606 6.7936963,12.314146 6.6371075,13.252434 6.4655575,14.188478 6.3017374,15.082631 6.1855427,15.985013 5.983074,16.873433 5.8249883,17.568607 5.7240037,18.277248 5.5556954,18.969682 5.4145655,19.550158 5.293882,20.143601 4.9722259,20.665731 4.7380909,21.045734 4.3959882,21.206312 3.9663652,21.104829 3.5778849,21.012322 3.2115961,20.866205 2.8951763,20.608631 2.6862246,20.438328 2.4473513,20.31141 2.1920214,20.458026 1.9519014,20.595915 1.7791048,20.851743 1.646453,21.088123 1.2205704,21.847879 1.915497,22.569984 2.6655289,22.684434 3.1692071,22.760986 3.666153,22.580208 4.1087416,22.356046 4.6996913,22.056582 5.2103511,21.635437 5.6387269,21.13874 5.9898058,20.731558 6.3575906,20.343327 6.6500737,19.890016 6.8450616,19.58756 7.0238427,19.274881 7.1866655,18.954471 7.7639005,17.817206 8.1227091,16.589926 8.4189318,15.354418 8.5613081,14.760227 8.716401,14.169777 8.8478064,13.572843 9.0268365,12.760724 9.1741996,11.934891 9.3083481,11.114294 9.3749255,10.707112 9.4310263,10.300679 9.5160532,9.8967389 9.5861222,9.5636133 9.6442168,9.2185186 9.6890985,8.8814035 9.7414633,8.4891827 9.990308,8.5136187 10.329668,8.4762164 c 0.286249,-0.03167 0.574492,-0.046376 0.861739,-0.067571 0.230395,-0.016703 0.494951,0.00396 0.711881,-0.088019 0.07754,-0.032911 0.147613,-0.080788 0.202719,-0.1513533 z\\"/><path d=\\"M 22.473802,7.8481382 C 22.426924,7.6912996 22.341898,7.5501696 22.231437,7.4294861 22.130452,7.3192756 21.987827,7.1749046 21.851933,7.1098255 21.411589,6.8988785 20.817398,7.0838898 20.436149,7.3422154 20.23343,7.479854 20.052405,7.6519026 19.871131,7.8167201 19.691352,7.9802913 19.517061,8.1488492 19.35723,8.3321177 19.025101,8.7128687 18.724639,9.1210479 18.436396,9.5354601 18.296263,9.7374301 17.901549,10.472252 17.781115,10.399942 17.654198,10.323892 17.495365,9.5905657 17.435023,9.3843566 17.351243,9.0978583 17.29539,8.8016361 17.161741,8.5323425 16.97922,8.1643081 16.865268,7.7623629 16.608941,7.4307332 16.325934,7.0639457 16.001036,6.9584722 15.558946,7.092371 c -0.43436,0.1314054 -0.78469,0.4049374 -1.128539,0.6819608 -0.503927,0.4056851 -0.879442,0.926319 -1.256951,1.4439609 -0.28226,0.387483 -0.284753,0.3857373 0.04488,0.7380631 0.206458,0.2211702 0.202718,0.2184272 0.389229,-0.00847 0.2663,-0.3251469 0.524872,-0.6595196 0.882433,-0.8934057 0.261315,-0.1713009 0.417904,-0.1368908 0.57948,0.1326518 0.07929,0.1326517 0.146866,0.2752777 0.200225,0.4208957 0.335619,0.9141014 0.590201,1.8541344 0.89191,2.7784594 0.03815,0.117691 -0.01122,0.193991 -0.06707,0.278519 -0.356565,0.538837 -0.719363,1.074182 -1.123054,1.578607 -0.320409,0.401198 -0.643312,0.803891 -1.073932,1.097621 -0.187757,0.128912 -0.40768,0.217679 -0.635831,0.156839 -0.233887,-0.06283 -0.37377,-0.27478 -0.587459,-0.373521 -0.006,-0.003 -0.01272,-0.0052 -0.01895,-0.0079 -0.09974,-0.04064 -0.249845,-0.0389 -0.353074,-0.01571 -0.454059,0.102482 -0.697669,0.614139 -0.790177,1.023813 -0.08379,0.371776 -0.0013,0.778209 0.261315,1.062463 0.228899,0.24785 0.572248,0.351327 0.901634,0.356315 0.189003,0.0028 0.39995,-0.04663 0.57549,-0.11445 0.670241,-0.262062 1.181649,-0.887172 1.605038,-1.441717 0.285501,-0.374517 0.550555,-0.763994 0.829573,-1.143499 0.230645,-0.313677 0.68595,-1.247726 0.81586,-1.250718 0.07854,-0.0017 0.09924,0.185762 0.114199,0.241117 0.03341,0.123675 0.06658,0.247351 0.102232,0.370279 0.167561,0.578481 0.343848,1.156464 0.525122,1.730458 0.120934,0.384242 0.315921,0.782697 0.560779,1.103356 0.07431,0.09749 0.167311,0.190749 0.26306,0.266799 0.371276,0.296972 0.838799,0.27453 1.266177,0.123177 0.191498,-0.06757 0.370029,-0.163071 0.539335,-0.275527 0.781948,-0.519886 1.340732,-1.244235 1.868598,-2.002495 0.124423,-0.178781 0.107467,-0.278769 -0.03441,-0.428127 -0.367286,-0.386237 -0.357062,-0.389727 -0.705149,0.01995 -0.261066,0.306446 -0.527117,0.612643 -0.879442,0.818851 -0.245855,0.144621 -0.413416,0.103229 -0.592696,-0.118439 -0.14861,-0.183518 -0.246353,-0.396709 -0.33138,-0.614886 -0.349831,-0.901136 -0.588954,-1.838675 -0.885177,-2.757515 -0.21743,-0.674231 -0.223414,-0.680464 0.20945,-1.248723 0.447575,-0.587708 0.875703,-1.1968602 1.462163,-1.6613914 0.431119,-0.3416031 0.73183,-0.3226534 1.129037,0.059094 0.0788,0.075801 0.207456,0.1388856 0.316919,0.1476127 0.369781,0.029674 0.691187,-0.3024566 0.880939,-0.5792304 0.188006,-0.2727835 0.259319,-0.6183768 0.163072,-0.9392845 z\\"/></svg>")}& .macro{cursor:pointer;background-image:url("data:image/svg+xml;utf8,<svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" fill=\\"grey\\"><path d=\\"m 7.3808594,2.8925781 c 0.6501558,0 1.3048608,0.1705676 1.8886719,0.5078125 l 9.2343747,5.3242188 c 1.167878,0.6758404 1.882813,1.9216266 1.882813,3.2675786 0,1.306438 -0.674828,2.517089 -1.783203,3.205078 L 9.2617188,20.595703 C 8.1035923,21.277644 6.6635531,21.275631 5.4960937,20.589844 4.3295773,19.917617 3.6132812,18.67473 3.6132813,17.330078 V 6.6660156 c 0,-1.3461361 0.7160606,-2.5932648 1.8828124,-3.265625 C 6.0817308,3.0628871 6.7318751,2.8925781 7.3808594,2.8925781 Z M 7.375,5.1835937 C 7.1238145,5.188954 6.883074,5.2521559 6.6601562,5.3691406 l -0.00781,0.00586 -0.00781,0.00391 C 6.1849913,5.6446615 5.9023438,6.1366335 5.9023437,6.6660156 V 17.330078 c 0,0.524949 0.2791508,1.016586 0.7363282,1.275391 0.4554716,0.266714 1.013907,0.272881 1.4785156,0.0098 l 9.2441405,-5.34375 c 0.450764,-0.263898 0.736328,-0.74603 0.736328,-1.27539 0,-0.52882 -0.290494,-1.018444 -0.742187,-1.277344 L 8.1171875,5.3789062 C 7.8951499,5.2512094 7.6461047,5.183439 7.375,5.1835937 Z\\"/></svg>")}& .autorun{cursor:pointer;background-image:url("data:image/svg+xml;utf8,<svg xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\" fill=\\"grey\\"><path d=\\"m 11.999964,1.7500508 c -0.462401,0 -0.923676,0.3281109 -0.924272,0.9260918 V 13.159721 c -0.0012,1.23176 1.847315,1.231936 1.848545,0 V 2.6761426 c 5.97e-4,-0.598201 -0.461872,-0.9260918 -0.924273,-0.9260918 z m 5.998674,2.6454569 c -0.728133,0.068914 -1.207022,1.0512547 -0.5149,1.63931 1.880223,1.6037705 2.962848,3.9512403 2.962038,6.4226023 -4.23e-4,4.655627 -3.790565,8.443993 -8.445812,8.443993 -4.6552096,0 -8.443993,-3.789762 -8.443993,-8.445813 C 3.5560359,10.008191 4.6172167,7.6804932 6.4634264,6.0784841 7.4240529,5.2735715 6.1821863,3.8462722 5.2535029,4.6829783 -1.9571321,10.940557 2.4945266,22.78839 12.039992,22.749957 21.585452,22.711525 25.944958,10.82919 18.684564,4.6302147 18.515847,4.4852865 18.331563,4.4098479 18.146012,4.3955077 c -0.05049,-0.0039 -0.09883,-0.00459 -0.147374,0 z\\"/></svg>")}}}/*$vite$:1*/`)),document.head.appendChild(e)}}catch(e){console.error(`vite-plugin-css-injected-by-js`,e)}})();
2
2
  /**
3
- * @license @sheetxl/scripting-react - Scripting React - Monaco based script editor and scripting UI for SheetXL. - v0.8.0-beta.1
3
+ * @license @sheetxl/scripting-react - Scripting React - Monaco based script editor and scripting UI for SheetXL. - v0.8.0-beta.11
4
4
  *
5
5
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
6
6
  * License: The license can be found at https://www.sheetxl.com/license.
7
7
  */
8
- import { n as e } from "./B_Y2Mt7_n3R6KUaa.mjs";
9
- import { Suspense as t, forwardRef as n, lazy as r, memo as i, useEffect as a, useMemo as o, useRef as s, useState as c, version as l } from "react";
10
- import { createRoot as u } from "react-dom/client";
11
- import { CommonUtils as d, TimerUtils as f, messageKey as p } from "@sheetxl/utils";
8
+ import { n as e } from "./todJqKpTFkpVOUC0.mjs";
9
+ import { Suspense as t, forwardRef as n, memo as r, useEffect as i, useMemo as a, useRef as o, useState as s, version as c } from "react";
10
+ import { createRoot as l } from "react-dom/client";
11
+ import { CommonUtils as u, TimerUtils as d, defineLazyModule as f, messageKey as p } from "@sheetxl/utils";
12
12
  import { DocTags as m } from "@sheetxl/scripting";
13
- import { Command as h, useCallbackRef as g, useCommands as ee, useImperativeElement as te, useNotifier as _, useTranslator as ne } from "@sheetxl/utils-react";
14
- import { DefaultTaskPaneRegistry as v, useModelListener as re, useTaskPaneArea as ie, useWorkbook as ae } from "@sheetxl/react";
15
- import { jsx as y, jsxs as oe } from "react/jsx-runtime";
16
- function b(e) {
13
+ import { IScript as h } from "@sheetxl/sdk";
14
+ import { Command as g, lazyComponent as _, useCallbackRef as v, useCommands as ee, useImperativeElement as te, useLazyRetry as y, useNotifier as ne, useTranslator as re } from "@sheetxl/utils-react";
15
+ import { jsx as b, jsxs as ie } from "react/jsx-runtime";
16
+ import { DefaultTaskPaneRegistry as x, useModelListener as ae, useTaskPaneArea as S, useWorkbook as oe } from "@sheetxl/react";
17
+ function C(e) {
17
18
  var t, n, r = "";
18
19
  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 = b(e[t])) && (r && (r += " "), r += n);
22
- } else for (n in e) e[n] && (r && (r += " "), r += n);
20
+ else if (typeof e == "object") {
21
+ if (Array.isArray(e)) {
22
+ var i = e.length;
23
+ for (t = 0; t < i; t++) e[t] && (n = C(e[t])) && (r && (r += " "), r += n);
24
+ } else for (n in e) e[n] && (r && (r += " "), r += n);
25
+ }
23
26
  return r;
24
27
  }
25
28
  function se() {
26
- for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = b(e)) && (r && (r += " "), r += t);
29
+ for (var e, t, n = 0, r = "", i = arguments.length; n < i; n++) (e = arguments[n]) && (t = C(e)) && (r && (r += " "), r += t);
27
30
  return r;
28
31
  }
29
- function x(e, t) {
32
+ function w(e, t) {
30
33
  if (typeof e == "function") return e(t);
31
34
  e && (e.current = t);
32
35
  }
33
- var ce = parseInt(l.split(".")[0], 10) >= 19 ? function(e) {
36
+ var ce = parseInt(c.split(".")[0], 10) >= 19 ? function(e) {
34
37
  return (t) => {
35
38
  let n = [];
36
39
  for (let r of e) {
37
- let e = x(r, t), i = typeof e == "function";
38
- n.push(i ? e : () => x(r, null));
40
+ let e = w(r, t), i = typeof e == "function";
41
+ n.push(i ? e : () => w(r, null));
39
42
  }
40
43
  return () => {
41
44
  for (let e of n) e();
@@ -43,9 +46,9 @@ var ce = parseInt(l.split(".")[0], 10) >= 19 ? function(e) {
43
46
  };
44
47
  } : function(e) {
45
48
  return (t) => {
46
- for (let n of e) x(n, t);
49
+ for (let n of e) w(n, t);
47
50
  };
48
- }, S = {
51
+ }, T = {
49
52
  defaultToken: "invalid",
50
53
  tokenPostfix: ".ts",
51
54
  keywords: /* @__PURE__ */ "abstract.any.as.asserts.bigint.boolean.break.case.catch.class.continue.const.constructor.debugger.declare.default.delete.do.else.enum.export.extends.false.finally.for.from.function.get.if.implements.import.in.infer.instanceof.interface.is.keyof.let.module.namespace.never.new.null.number.object.out.package.private.protected.public.override.readonly.require.global.return.satisfies.set.static.string.super.switch.symbol.this.throw.true.try.type.typeof.undefined.unique.unknown.var.void.while.with.yield.async.await.of".split("."),
@@ -262,7 +265,48 @@ var ce = parseInt(l.split(".")[0], 10) >= 19 ? function(e) {
262
265
  { include: "common" }
263
266
  ]
264
267
  }
265
- }, le = {
268
+ }, E = /(?:\s|\/\/[^\n]*|\/\*[\s\S]*?\*\/)*/y, D = /(import\b\s*(?:type\s+(?!from\b))?)(?:([^'";]*?)\s*\bfrom\s*)?(['"])([^'"\n]+)\3[ \t]*;?/y, O = (e) => e.replace(/\s+/g, " ").trim(), k = (e) => {
269
+ let t = [], n = 0;
270
+ for (;;) {
271
+ E.lastIndex = n, E.exec(e), D.lastIndex = E.lastIndex;
272
+ let r = D.exec(e);
273
+ if (!r) return t;
274
+ let i = r[2] ?? "", a = r.index + r[1].length, o = i.indexOf("{"), s = i.lastIndexOf("}"), c = o >= 0 && s > o, l = c ? i.slice(0, o) + i.slice(s + 1) : i;
275
+ t.push({
276
+ start: r.index,
277
+ end: D.lastIndex,
278
+ text: r[0],
279
+ module: r[4],
280
+ quote: r[3],
281
+ typeOnly: /\btype\s+$/.test(r[1]),
282
+ binding: O(l).replace(/\s*,$/, ""),
283
+ names: c ? i.slice(o + 1, s).split(",").map(O).filter(Boolean) : null,
284
+ namesStart: a + o + 1,
285
+ namesEnd: a + s
286
+ }), n = D.lastIndex;
287
+ }
288
+ }, A = (e) => [
289
+ e.typeOnly,
290
+ e.binding,
291
+ e.names?.join(","),
292
+ e.module
293
+ ].join("|"), le = (e) => `${e.typeOnly ? "type " : ""}${e.module}`, ue = (e, t, n) => {
294
+ let r = e.slice(t.namesStart, t.namesEnd), i = r.trimEnd();
295
+ if (i.trim() === "") return {
296
+ offset: t.namesStart,
297
+ text: ` ${n.join(", ")}${r === "" ? " " : ""}`
298
+ };
299
+ let a = t.namesStart + i.length, o = i.endsWith(","), s = i.lastIndexOf("\n");
300
+ if (s < 0) return {
301
+ offset: a,
302
+ text: `${o ? " " : ", "}${n.join(", ")}`
303
+ };
304
+ let c = /^[ \t]*/.exec(i.slice(s + 1))[0];
305
+ return {
306
+ offset: a,
307
+ text: `${o ? "" : ","}\n${c}${n.join(`,\n${c}`)}${o ? "," : ""}`
308
+ };
309
+ }, de = {
266
310
  lightbulb: { enabled: !1 },
267
311
  tabSize: 2,
268
312
  acceptSuggestionOnCommitCharacter: !0,
@@ -325,7 +369,10 @@ var ce = parseInt(l.split(".")[0], 10) >= 19 ? function(e) {
325
369
  wordWrapColumn: 80,
326
370
  wordWrapMinified: !0,
327
371
  wrappingIndent: "none"
328
- }, ue = "_script-editor_1kuph_5", C, de = r(async () => (function() {
372
+ }, fe = "_script-editor_1kuph_5", pe = (e) => {
373
+ let t = e?.getModules();
374
+ return t && t.getByName(h.DEFAULT_MODULE), h.DEFAULT_MODULE;
375
+ }, j = (e) => e?.getModules()?.getByName(pe(e)) ?? null, M, me = f("scripting-react:monaco", async () => (function() {
329
376
  if (typeof window > "u") return;
330
377
  let e = window;
331
378
  if (e.__sxlDefineShim) return;
@@ -343,14 +390,145 @@ var ce = parseInt(l.split(".")[0], 10) >= 19 ? function(e) {
343
390
  } catch {}
344
391
  }
345
392
  });
346
- }(), import("./DVwFOTQu-orFdbBG.mjs"))), w = ["define", "require"], fe = !1, T = "@0.8.0-beta.1";
347
- T !== "@local" && T !== "@0.0.0" || (T = "");
348
- var E = `https://cdn.jsdelivr.net/npm/@sheetxl/sdk${T}/types/scripting.d.ts`, D = (e) => {
393
+ }(), import("./DwNnhfNV7R5zmBKY.mjs")), { prefetch: !1 }), N = ({ error: e }) => {
394
+ let t = y(), n = re();
395
+ return ie("div", {
396
+ style: {
397
+ display: "flex",
398
+ flexDirection: "column",
399
+ alignItems: "center",
400
+ justifyContent: "center",
401
+ gap: "8px",
402
+ flex: "1 1 100%"
403
+ },
404
+ children: [b("span", { children: e instanceof Error ? e.message : String(e) }), t ? b("button", {
405
+ type: "button",
406
+ onClick: t,
407
+ children: n("scriptEditor.retry")
408
+ }) : null]
409
+ });
410
+ }, P = _(me.load, { renderError: (e) => b(N, { error: e }) }), F = ["define", "require"], he = !1, I = "@0.8.0-beta.11";
411
+ I !== "@local" && I !== "@0.0.0" || (I = "");
412
+ var L = `https://cdn.jsdelivr.net/npm/@sheetxl/sdk${I}/types/scripting.d.ts`, R = (e) => {
349
413
  try {
350
- e.languages.setMonarchTokensProvider("typescript", S);
414
+ e.languages.setMonarchTokensProvider("typescript", T);
351
415
  } catch {}
352
- }, O = !1;
353
- function pe(e, t) {
416
+ }, z = !1, ge = async (e, t, n) => {
417
+ let r = e.getModel();
418
+ if (!r) return;
419
+ let i = await (await (await t.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString()), a = e.getPosition(), o = { ...a };
420
+ o.lineNumber = 1, o.column = 1;
421
+ let s = !1;
422
+ for (let e = a.lineNumber; e >= 1; e--) if (r.getLineContent(e).trim() === "") {
423
+ let t = H(i, r.getOffsetAt({
424
+ lineNumber: e,
425
+ column: 1
426
+ }), "function");
427
+ if (!t || _e(t)) {
428
+ s = !0, o.lineNumber = e + 1;
429
+ break;
430
+ }
431
+ {
432
+ let n = t.spans[0].start;
433
+ e = r.getPositionAt(n).lineNumber, o.lineNumber = e;
434
+ }
435
+ }
436
+ let c = ((e, t) => {
437
+ let n = k(e), r = n.length > 0 ? n[n.length - 1].end : 0, i = k(t);
438
+ if (i.length === 0) return {
439
+ body: t,
440
+ inserts: [],
441
+ importsEnd: r
442
+ };
443
+ let a = "", o = 0;
444
+ for (let e of i) a += t.slice(o, e.start), o = e.end + (/^[ \t]*\r?\n/.exec(t.slice(e.end))?.[0].length ?? 0);
445
+ a = (a + t.slice(o)).replace(/^(?:[ \t]*\r?\n)+/, "");
446
+ let s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
447
+ for (let e of n) {
448
+ if (s.add(A(e)), !e.names) continue;
449
+ let t = le(e);
450
+ l.has(t) || l.set(t, e);
451
+ let n = c.get(t);
452
+ n || c.set(t, n = /* @__PURE__ */ new Set());
453
+ for (let t of e.names) n.add(t);
454
+ }
455
+ let u = /* @__PURE__ */ new Map(), d = [], f = /* @__PURE__ */ new Map();
456
+ for (let e of i) {
457
+ if (!e.names || e.binding) {
458
+ let t = A(e);
459
+ if (s.has(t)) continue;
460
+ s.add(t), d.push(e.text);
461
+ continue;
462
+ }
463
+ let t = le(e), n = c.get(t);
464
+ n || c.set(t, n = /* @__PURE__ */ new Set());
465
+ let r = e.typeOnly ? c.get(e.module) : void 0, i = e.names.filter((e) => !n.has(e) && !r?.has(e));
466
+ if (i.length === 0) continue;
467
+ for (let e of i) n.add(e);
468
+ let a = l.get(t);
469
+ if (a) {
470
+ u.set(a, [...u.get(a) ?? [], ...i]);
471
+ continue;
472
+ }
473
+ let o = f.get(t);
474
+ if (o) {
475
+ o.names.push(...i), o.verbatim = !1;
476
+ continue;
477
+ }
478
+ let p = {
479
+ statement: e,
480
+ names: i,
481
+ verbatim: i.length === e.names.length
482
+ };
483
+ f.set(t, p), d.push(p);
484
+ }
485
+ let p = [];
486
+ for (let [t, n] of u) p.push(ue(e, t, n));
487
+ if (p.sort((e, t) => e.offset - t.offset), d.length > 0) {
488
+ let t = d.map((e) => {
489
+ if (typeof e == "string") return e;
490
+ let { statement: t, names: n, verbatim: r } = e;
491
+ if (r) return t.text;
492
+ let { quote: i } = t;
493
+ return `import ${t.typeOnly ? "type " : ""}{ ${n.join(", ")} } from ${i}${t.module}${i};`;
494
+ }).join("\n");
495
+ r > 0 ? p.push({
496
+ offset: r,
497
+ text: `\n${t}`
498
+ }) : p.unshift({
499
+ offset: 0,
500
+ text: `${t}\n${/^[ \t]*\r?\n/.test(e) ? "" : "\n"}`
501
+ });
502
+ }
503
+ return {
504
+ body: a,
505
+ inserts: p,
506
+ importsEnd: r
507
+ };
508
+ })(r.getValue(), n), l = c.importsEnd > 0 ? r.getPositionAt(c.importsEnd).lineNumber : 0, u = c.body, d = "";
509
+ o.lineNumber <= l ? l < r.getLineCount() ? (o.lineNumber = l + 1, d = u.startsWith("\n") ? "" : "\n") : (o.lineNumber = l, o.column = r.getLineMaxColumn(l), d = "\n\n") : !s && !u.startsWith("\n") && o.lineNumber > 1 && (d = "\n");
510
+ let f = !1;
511
+ r.getLineCount() > 1 && (u.endsWith("\n\n") || (u += "\n\n", f = !0));
512
+ let p = r.validatePosition(o), m = new t.Range(p.lineNumber, p.column, p.lineNumber, p.column), h = [];
513
+ for (let e of c.inserts) {
514
+ let n = r.getPositionAt(e.offset);
515
+ n.lineNumber === m.startLineNumber && n.column === m.startColumn ? d = e.text + d : h.push({
516
+ range: new t.Range(n.lineNumber, n.column, n.lineNumber, n.column),
517
+ text: e.text
518
+ });
519
+ }
520
+ let g = d.split("\n").length - 1, _ = [{
521
+ range: m,
522
+ text: `${d}${u}`
523
+ }, ...h], v = null;
524
+ r.pushEditOperations([], _, (e) => (v = e[0].range, g > 0 && (v.startLineNumber += g, v.startColumn = 1), f && v.endLineNumber--, [new t.Selection(v.startLineNumber, v.startColumn, v.endLineNumber, v.endColumn)])), e.setSelection({
525
+ startLineNumber: v.endLineNumber,
526
+ startColumn: v.endColumn,
527
+ endLineNumber: v.startLineNumber,
528
+ endColumn: v.startColumn
529
+ });
530
+ };
531
+ function B(e, t) {
354
532
  let n = null, r = e.length;
355
533
  for (let i = 0; !n && i < r; i++) {
356
534
  let r = e[i];
@@ -358,47 +536,47 @@ function pe(e, t) {
358
536
  }
359
537
  return n ? n.getContext() : "formula";
360
538
  }
361
- function k(e, t, n, r, i = []) {
539
+ function V(e, t, n, r, i = []) {
362
540
  if (r.kind === "function" && r.kindModifiers === "export") {
363
541
  let t = r.spans[0].start, a = e.getPositionAt(t);
364
542
  i.push({
365
543
  name: r.text,
366
- type: pe(n, r),
544
+ type: B(n, r),
367
545
  lineNumber: a.lineNumber
368
546
  });
369
547
  }
370
- if (r.childItems) for (let a of r.childItems) k(e, t, n, a, i);
548
+ if (r.childItems) for (let a of r.childItems) V(e, t, n, a, i);
371
549
  return i;
372
550
  }
373
- function A(e, t, n = "function", r) {
551
+ function H(e, t, n = "function", r) {
374
552
  let i = e.spans, a = i.length;
375
553
  for (let o = 0; o < a; o++) {
376
554
  let a = i[o];
377
555
  if (a.start <= t && t < a.start + a.length) {
378
556
  if (e.kind === n && (!r || e.kindModifiers === r)) return e;
379
557
  for (let i of e.childItems || []) {
380
- let e = A(i, t, n, r);
558
+ let e = H(i, t, n, r);
381
559
  if (e) return e;
382
560
  }
383
561
  }
384
562
  return null;
385
563
  }
386
564
  }
387
- function me(e) {
565
+ function _e(e) {
388
566
  return e.kind === "comment";
389
567
  }
390
- var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { current: null }, L = (e, t) => {
391
- M = {
568
+ var U = null, W = null, G = null, K = null, ve = !1, ye = !1, be = !1, q = { current: null }, xe = (e, t) => {
569
+ W = {
392
570
  editor: e,
393
571
  monaco: t
394
- }, N && (P = N(e, t));
395
- }, _e = (e) => {
396
- F || (F = !0, e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
572
+ }, G && (K = G(e, t));
573
+ }, Se = (e) => {
574
+ be || (be = !0, e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
397
575
  noSemanticValidation: !0,
398
576
  noSyntaxValidation: !1,
399
577
  diagnosticCodesToIgnore: [2307]
400
- }), e.languages.typescript.typescriptDefaults.setEagerModelSync(!0), e.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: !0 }), D(e), ((e) => {
401
- O || (O = !0, e.languages.registerCompletionItemProvider("typescript", {
578
+ }), e.languages.typescript.typescriptDefaults.setEagerModelSync(!0), e.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: !0 }), R(e), ((e) => {
579
+ z || (z = !0, e.languages.registerCompletionItemProvider("typescript", {
402
580
  triggerCharacters: ["@"],
403
581
  provideCompletionItems: (t, n) => {
404
582
  let r = t.getValueInRange({
@@ -475,7 +653,7 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
475
653
  }), (async () => {
476
654
  let t = !1;
477
655
  try {
478
- let n = await (async () => await (await fetch(E)).text())(), r = e.Uri.parse("inmemory://model/\"sheetxl-models\".d.ts"), i = e.editor.getModel(r);
656
+ let n = await (async () => await (await fetch(L)).text())(), r = e.Uri.parse("inmemory://model/\"sheetxl-models\".d.ts"), i = e.editor.getModel(r);
479
657
  i ? t = !0 : i = e.editor.createModel(n, "typescript", r), e.editor.setModelMarkers(i, "default", []);
480
658
  } catch (e) {
481
659
  console.warn("cant load types", e);
@@ -493,7 +671,7 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
493
671
  let p = d[d.length - 1];
494
672
  p !== "`" && p !== "'" && p !== "\"" || (c++, d = d.substring(0, d.length - 1));
495
673
  try {
496
- I.current?.getRanges(d) && r.push({
674
+ q.current?.getRanges(d) && r.push({
497
675
  range: {
498
676
  endColumn: l,
499
677
  endLineNumber: n,
@@ -511,7 +689,7 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
511
689
  } }), e.editor.registerLinkOpener({ open(e) {
512
690
  if (e?.path?.startsWith("/range/")) {
513
691
  try {
514
- I.current?.getRanges(e.path.substring(7))?.select();
692
+ q.current?.getRanges(e.path.substring(7))?.select();
515
693
  } catch (e) {
516
694
  console.warn("invalid range", e);
517
695
  }
@@ -528,6 +706,7 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
528
706
  "es2020",
529
707
  "esnext.asynciterable"
530
708
  ],
709
+ strict: !0,
531
710
  downlevelIteration: !0,
532
711
  moduleResolution: e.languages.typescript.ModuleResolutionKind.NodeJs,
533
712
  allowSyntheticDefaultImports: !0,
@@ -545,102 +724,105 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
545
724
  })();
546
725
  }
547
726
  })());
548
- }, ve = (e) => {
727
+ }, Ce = (e) => {
549
728
  let t = !1, n = e ? e.length : 0;
550
729
  for (let r = 0; !t && r < n; r++) e[r].severity === 8 && (t = !0);
551
- }, ye = () => {
552
- let [e, n] = c(() => j.props);
553
- return a(() => (j && (j.setProps = n), () => {
554
- j && (j.setProps = null);
555
- }), []), y("div", {
730
+ }, we = () => {
731
+ let [e, n] = s(() => U.props);
732
+ return i(() => (U && (U.setProps = n), () => {
733
+ U && (U.setProps = null);
734
+ }), []), b("div", {
556
735
  style: {
557
736
  display: "flex",
558
737
  flex: "1 1 100%",
559
738
  width: "100%",
560
739
  height: "100%"
561
740
  },
562
- children: y(t, { children: y(de, {
741
+ children: b(t, { children: b(P, {
563
742
  theme: e.theme,
564
743
  options: e.options,
565
744
  language: "typescript",
566
745
  value: e.value,
567
746
  onValidate: e.onValidate,
568
747
  beforeMount: e.beforeMount,
569
- onMount: L
748
+ onMount: xe
570
749
  }) })
571
750
  });
572
- }, R = i(n((t, n) => {
573
- let { className: r, style: i, readOnly: l = !1, darkMode: m, loadingPanel: v, autoFocus: ie = !0, frame: b, scripts: x, onStatusChange: S, ...de } = t, T = ne(), E = s(null), [O, pe] = c(!1), F = ae(), [L] = ee(["insertFunction"]), [R, z] = c({
751
+ }, J = r(n((t, n) => {
752
+ let { className: r, style: c, readOnly: f = !1, darkMode: m, loadingPanel: h, autoFocus: _ = !0, frame: y, scripts: x, onStatusChange: S, ...C } = t, w = re(), T = o(null), [E, D] = s(!1), O = oe(), [k] = ee(["insertFunction"]), [A, le] = s({
574
753
  message: "Loading",
575
754
  cursor: "",
576
755
  dirty: !1
577
- }), [be, B] = c({
756
+ }), [ue, me] = s({
578
757
  loading: !1,
579
758
  compiling: !1,
580
759
  errors: [],
581
760
  warnings: []
582
- }), V = g((e) => {
583
- z((t) => {
761
+ }), N = v((e) => {
762
+ le((t) => {
584
763
  let n = {
585
764
  ...t,
586
765
  ...e
587
766
  };
588
- return d.deepEqual(n, t) ? t : (pe(n.dirty ?? !1), n);
767
+ return u.deepEqual(n, t) ? t : (D(n.dirty ?? !1), n);
589
768
  });
590
769
  }, [S]);
591
- a(() => {
592
- S?.(R);
593
- }, [S, R]);
594
- let H = _(), xe = g(async (e) => {
770
+ i(() => {
771
+ S?.(A);
772
+ }, [S, A]);
773
+ let P = ne(), I = v(async (e) => {
595
774
  let t = null, n = null;
596
775
  try {
597
- e && (n = await H.showBusy(T("scriptEditor.saving")), t = await x.createModule({ source: e })), x.addModule("scripts", t, { replace: !0 }), n?.();
776
+ e && (n = await P.showBusy(w("scriptEditor.saving")), t = await x.createModule({ source: e })), x.addModule(pe(x), t, { replace: !0 }), n?.();
598
777
  } catch (e) {
599
- n?.(), console.warn("Unable to compile", e), H.showError(e);
778
+ n?.(), console.warn("Unable to compile", e), P.showError(e);
600
779
  }
601
780
  return t;
602
- }, [x]), U = g(async () => {
603
- if (!E.current) return;
604
- let e = E.current.editor, t;
605
- if (R.dirty) {
781
+ }, [x]), L = v(async () => {
782
+ if (!T.current || f) return;
783
+ let e = T.current.editor, t;
784
+ if (A.dirty) {
606
785
  let n = e.getValue();
607
- await xe(n), t = x.getModules().getByName("scripts");
786
+ await I(n), t = j(x);
608
787
  let r = t?.getSource(), i = e.getValue(), a = (r?.length ?? 0) !== n.length || r !== i;
609
- V({ dirty: a });
610
- } else t = x.getModules().getByName("scripts");
788
+ N({ dirty: a });
789
+ } else t = j(x);
611
790
  return t;
612
- }, [R, x]);
613
- a(() => {
614
- let e = b?.addListener({ onBeforeHide: async () => (await U(), !0) });
791
+ }, [A, x]);
792
+ i(() => {
793
+ let e = y?.addListener({ onBeforeHide: async () => (await L(), !0) });
615
794
  return () => {
616
795
  e?.();
617
796
  };
618
- }, [b]), a(() => {
619
- if (x) return x.addListeners({ onBeforeSearch: () => U() });
620
- }, [x]), re(F, {
797
+ }, [y]), i(() => {
798
+ if (x) return x.addListeners({ onBeforeSearch: () => L() });
799
+ }, [x]), ae(O, {
621
800
  onBeforeSave: async () => {
622
- await U();
801
+ await L();
623
802
  },
624
803
  onLoad: () => {
625
- let e = E.current?.editor;
626
- e && e.setValue(x?.getModules().getItems()[0]?.getSource() ?? "");
804
+ let e = T.current?.editor;
805
+ e && e.setValue(j(x)?.getSource() ?? "");
627
806
  }
628
807
  });
629
- let W = g(async (e) => {
808
+ let z = v(async (e) => {
630
809
  if (!x) return;
631
810
  let t = typeof e == "string" ? { functionName: e } : e ?? {}, n = null;
632
811
  if (t?.declaration || t?.functionName) {
633
812
  let e = t.declaration ? t.declaration.getName() : t.functionName;
634
- (await x.searchFunctions({ name: e })).length > 0 && (n = e);
813
+ (await x.searchFunctions({
814
+ name: e,
815
+ includeHidden: !0
816
+ })).length > 0 && (n = e);
635
817
  }
636
818
  if (n) try {
637
819
  await x.executeMacro(n);
638
820
  } catch (e) {
639
- H.showError(e);
821
+ P.showError(e);
640
822
  }
641
- }, [x, H]), [G, Se] = c(!1), Ce = g(async () => {
642
- if (!E.current) return null;
643
- let e = E.current, t = e.editor;
823
+ }, [x, P]), [B, _e] = s(!1), be = v(async () => {
824
+ if (!T.current) return null;
825
+ let e = T.current, t = e.editor;
644
826
  if (!t) return null;
645
827
  let n = await (async (e, t, n = "export") => {
646
828
  let r = e.getModel();
@@ -649,7 +831,7 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
649
831
  if (!o) return null;
650
832
  let s = o.startLineNumber === o.endLineNumber && o.startColumn === o.endColumn ? r.getLineCount() : Math.min(o.endLineNumber, r.getLineCount());
651
833
  for (let e = o.startLineNumber; !a && e <= s; e++) {
652
- let t = A(i, r.getOffsetAt({
834
+ let t = H(i, r.getOffsetAt({
653
835
  lineNumber: e,
654
836
  column: 1
655
837
  }), "function", n);
@@ -657,14 +839,14 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
657
839
  }
658
840
  return a;
659
841
  })(t, e.monaco);
660
- return V({ message: (n ?? "").toUpperCase() }), n ? {
842
+ return N({ message: (n ?? "").toUpperCase() }), n ? {
661
843
  source: t.getValue(),
662
844
  name: n
663
845
  } : null;
664
846
  }, []);
665
- g(f.debounce(U, 200), []);
666
- let we = g(async (e, t, n) => {
667
- B((e) => ({
847
+ v(d.debounce(L, 200), []);
848
+ let xe = v(async (e, t, n) => {
849
+ me((e) => ({
668
850
  ...e,
669
851
  compiling: !0
670
852
  }));
@@ -675,7 +857,7 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
675
857
  declarationsOnly: !0
676
858
  }), !r) return;
677
859
  } catch {}
678
- let i = r ? r.getDiagnostics() : d.EmptyArray;
860
+ let i = r ? r.getDiagnostics() : u.EmptyArray;
679
861
  (function(e, t, n) {
680
862
  let r = (n ?? []).map((n) => {
681
863
  let r = e.getPositionAt(n.start), i = e.getPositionAt(n.start + Math.max(n.length, 1));
@@ -691,9 +873,9 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
691
873
  });
692
874
  t.editor.setModelMarkers(e, "sheetxl", r);
693
875
  })(e, t, i), async function(e, t, n, r) {
694
- let i = k(e, t, r, await (await (await t.languages.typescript.getTypeScriptWorker())(e.uri)).getNavigationTree(e.uri.toString())).map((e) => {
876
+ let i = V(e, t, r, await (await (await t.languages.typescript.getTypeScriptWorker())(e.uri)).getNavigationTree(e.uri.toString())).map((e) => {
695
877
  let n = null, r = null;
696
- return e.type === "formula" ? (n = "formula.margin-icon", r = T("scriptEditor.glyph.formula")) : e.type === "macro" ? (n = "macro.margin-icon", r = T("scriptEditor.glyph.macro")) : e.type === "autoRun" && (n = "autorun.margin-icon", r = T("scriptEditor.glyph.autoRun")), {
878
+ return e.type === "formula" ? (n = "formula.margin-icon", r = w("scriptEditor.glyph.formula")) : e.type === "macro" ? (n = "macro.margin-icon", r = w("scriptEditor.glyph.macro")) : e.type === "autoRun" && (n = "autorun.margin-icon", r = w("scriptEditor.glyph.autoRun")), {
697
879
  range: new t.Range(e.lineNumber, 1, e.lineNumber, 1),
698
880
  options: {
699
881
  isWholeLine: !1,
@@ -703,33 +885,33 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
703
885
  }
704
886
  };
705
887
  });
706
- J.current && J.current.clear(), J.current = n.createDecorationsCollection(i);
707
- }(e, t, n, r ? r.getFunctions().getItems() : d.EmptyArray), B((e) => ({
888
+ Z.current && Z.current.clear(), Z.current = n.createDecorationsCollection(i);
889
+ }(e, t, n, r ? r.getFunctions().getItems({ includeHidden: !0 }) : u.EmptyArray), me((e) => ({
708
890
  ...e,
709
891
  compiling: !1,
710
892
  errors: i.filter((e) => e.severity === "error").map((e) => `${e.code}: ${e.message}`),
711
893
  warnings: i.filter((e) => e.severity === "warning").map((e) => `${e.code}: ${e.message}`)
712
894
  }));
713
- }, [x]), K = g(f.debounce(we, 580), []), q = g(async (e) => {
714
- if (!E.current) return;
715
- let t = E.current.editor.getPosition(), n = { cursor: t ? t.toString() : "" };
716
- e !== void 0 && (n.message = e), V(n);
895
+ }, [x]), J = v(d.debounce(xe, 580), []), Y = v(async (e) => {
896
+ if (!T.current) return;
897
+ let t = T.current.editor.getPosition(), n = { cursor: t ? t.toString() : "" };
898
+ e !== void 0 && (n.message = e), N(n);
717
899
  }, []);
718
- a(() => {}, [be]);
719
- let Te = s(null), Ee = g(async () => {
720
- await U(), b?.close();
721
- }, [b]), De = g((e) => {
722
- let t = E.current?.editor;
900
+ i(() => {}, [ue]);
901
+ let Te = o(null), Ee = v(async () => {
902
+ await L(), y?.close();
903
+ }, [y]), X = v((e) => {
904
+ let t = T.current?.editor;
723
905
  return !!t && (t.focus(e), !0);
724
- }, [R]), Oe = g(async () => {
725
- let e = E.current?.editor, t = e?.getModel(), n = e?.getSelection();
906
+ }, [A]), De = v(async () => {
907
+ let e = T.current?.editor, t = e?.getModel(), n = e?.getSelection();
726
908
  if (!t || !n) return;
727
909
  let r = n.isEmpty() ? t.getLineContent(n.positionLineNumber) + "\n" : t.getValueInRange(n);
728
910
  try {
729
911
  await navigator.clipboard?.writeText(r);
730
912
  } catch {}
731
- }, []), ke = g(async () => {
732
- let e = E.current, t = e?.editor, n = t?.getModel(), r = t?.getSelection();
913
+ }, []), Oe = v(async () => {
914
+ let e = T.current, t = e?.editor, n = t?.getModel(), r = t?.getSelection();
733
915
  if (!n || !r) return;
734
916
  let i = r.isEmpty() ? new e.monaco.Range(r.positionLineNumber, 1, r.positionLineNumber + 1, 1) : r, a = n.getValueInRange(i);
735
917
  try {
@@ -742,8 +924,8 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
742
924
  text: "",
743
925
  forceMoveMarkers: !0
744
926
  }]), t.pushUndoStop(), t.focus();
745
- }, []), Ae = g(async () => {
746
- let e = E.current?.editor;
927
+ }, []), ke = v(async () => {
928
+ let e = T.current?.editor;
747
929
  if (!e) return;
748
930
  let t;
749
931
  try {
@@ -758,16 +940,16 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
758
940
  text: t,
759
941
  forceMoveMarkers: !0
760
942
  }]), e.pushUndoStop(), e.focus();
761
- }, []), J = s(null), je = g((t, n) => {
762
- E.current = {
943
+ }, []), Z = o(null), Ae = v((t, n) => {
944
+ T.current = {
763
945
  monaco: n,
764
946
  editor: t
765
- }, I.current = F ?? null;
947
+ }, q.current = O ?? null;
766
948
  let r = t.getModel(), i = [];
767
- Se(!0);
768
- let a = x?.getModules().getItems()[0]?.getSource() ?? "";
769
- return t.getValue() !== a && t.setValue(a), he ? (q(""), K(r, n, t), D(n)) : (he = !0, q("Loading Types"), import("./Cls8yeIK4VLB6jx7.mjs").then((t) => e(t.default, 1)).then(async (e) => {
770
- q(""), e.AutoTypings.create(t, {
949
+ _e(!0);
950
+ let a = j(x)?.getSource() ?? "";
951
+ return t.getValue() !== a && t.setValue(a), ve ? (Y(""), J(r, n, t), R(n)) : (ve = !0, Y("Loading Types"), import("./ddwGYO4BGXOrUsl5.mjs").then((t) => e(t.default, 1)).then(async (e) => {
952
+ Y(""), e.AutoTypings.create(t, {
771
953
  shareCache: !0,
772
954
  dontAdaptEditorOptions: !0,
773
955
  monaco: n,
@@ -784,8 +966,8 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
784
966
  e === "Not implemented yet" && (e = "Compile Errors"), console.warn("Error compiling types", e);
785
967
  }
786
968
  }).then((e) => {
787
- Te.current = e, K(t.getModel(), n, t), (() => {
788
- if (fe) return;
969
+ Te.current = e, J(t.getModel(), n, t), (() => {
970
+ if (he) return;
789
971
  let e = (e, t) => {
790
972
  try {
791
973
  if (t === void 0) try {
@@ -797,15 +979,17 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
797
979
  }
798
980
  else globalThis[e] = t;
799
981
  } catch {}
800
- }, t = w.length;
982
+ }, t = F.length;
801
983
  for (let n = 0; n < t; n++) {
802
- let t = w[n];
803
- e(t, C[t]);
984
+ let t = F[n];
985
+ e(t, M[t]);
804
986
  }
805
- C = void 0, fe = !0;
806
- })(), D(n);
987
+ M = void 0, he = !0;
988
+ })(), R(n);
807
989
  });
808
- })), ge || (ge = !0, function(e, t) {
990
+ }).catch((e) => {
991
+ ve = !1, Y(""), console.warn("Auto typings could not be loaded:", e);
992
+ })), ye || (ye = !0, function(e, t) {
809
993
  t.languages.registerInlayHintsProvider("typescript", { provideInlayHints(e, n, r) {
810
994
  let i = [];
811
995
  for (let n = 1; n < e.getLineCount() + 1; n++) {
@@ -834,109 +1018,109 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
834
1018
  label: "Execute",
835
1019
  keybindings: [n.KeyCode.F8],
836
1020
  run: async (e) => {
837
- let t = await Ce();
838
- W(t);
1021
+ let t = await be();
1022
+ z(t);
839
1023
  }
840
1024
  })), i.push(t.addAction({
841
1025
  id: "saveScript",
842
1026
  label: "Save Script",
843
1027
  keybindings: [n.KeyMod.CtrlCmd | n.KeyCode.KeyS],
844
1028
  run: (e) => {
845
- U();
1029
+ L();
846
1030
  }
847
1031
  })), i.push(t.onMouseDown(async (e) => {
848
1032
  if (e.target.type === n.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
849
1033
  e.event.browserEvent.preventDefault();
850
- let t = e.target.position.lineNumber, i = await (await (await n.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString()), a = await U();
1034
+ let t = e.target.position.lineNumber, i = await (await (await n.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString()), a = await L();
851
1035
  if (!a) return;
852
- let o = a.getFunctions().getItems(), s = k(r, n, o, i).find((e) => e.lineNumber === t);
1036
+ let o = a.getFunctions().getItems({ includeHidden: !0 }), s = V(r, n, o, i).find((e) => e.lineNumber === t);
853
1037
  if (s) {
854
1038
  let t = e.event.browserEvent.button;
855
1039
  if (t === 0) {
856
- if (s.type === "macro" || s.type === "autoRun") W({ functionName: s.name });
1040
+ if (s.type === "macro" || s.type === "autoRun") z({ functionName: s.name });
857
1041
  else if (s.type === "formula") {
858
1042
  let e = o?.find((e) => e.getName() === s.name);
859
- e && L?.execute(e);
1043
+ e && k?.execute(e);
860
1044
  }
861
1045
  } else t === 2 && (console.log("Context menu for function:", s.name), e.event.browserEvent.preventDefault());
862
1046
  }
863
1047
  }
864
1048
  })), i.push(t.onDidChangeModelContent(() => {
865
- V({ dirty: !0 }), K(r, n, t);
1049
+ N({ dirty: !0 }), J(r, n, t);
866
1050
  })), i.push(n.editor.onDidChangeMarkers((e) => {
867
1051
  e.some((e) => e.toString() === r.uri.toString());
868
1052
  })), i.push(r.onDidChangeContent((e) => {
869
- let n = x.getModules().getByName("scripts")?.getSource(), r = t.getValue(), i = (n?.length ?? 0) !== r.length || n !== r;
870
- V({ dirty: i });
1053
+ let n = j(x)?.getSource(), r = t.getValue(), i = (n?.length ?? 0) !== r.length || n !== r;
1054
+ N({ dirty: i });
871
1055
  })), i.push(t.onDidChangeCursorPosition((e) => {
872
- q();
1056
+ Y();
873
1057
  })), () => {
874
1058
  for (let e of i) try {
875
1059
  e.dispose();
876
1060
  } catch {}
877
1061
  };
878
- }, [x, F]), Me = o(() => G ? null : v || y("div", {
1062
+ }, [x, O]), je = a(() => B ? null : h || b("div", {
879
1063
  style: {
880
1064
  position: "absolute",
881
1065
  width: "100%",
882
1066
  height: "100%"
883
1067
  },
884
- children: T("scriptEditor.loading")
885
- }), [G, v]), Y = o(() => ({
886
- ...le,
1068
+ children: w("scriptEditor.loading")
1069
+ }), [B, h]), Me = a(() => ({
1070
+ ...de,
887
1071
  fixedOverflowWidgets: !1,
888
1072
  contextmenu: !1,
889
- readOnly: l
890
- }), [l]), X = s(null);
891
- a(() => {
1073
+ readOnly: f
1074
+ }), [f]), Ne = o(null);
1075
+ i(() => {
892
1076
  let e = {
893
1077
  theme: m ? "extended-dark" : "extended",
894
- options: Y,
895
- value: x?.getModules()?.getByName("scripts")?.getSource() ?? "",
896
- beforeMount: _e,
897
- onValidate: ve
1078
+ options: Me,
1079
+ value: j(x)?.getSource() ?? "",
1080
+ beforeMount: Se,
1081
+ onValidate: Ce
898
1082
  }, t = ((e) => {
899
- if (j) return j;
900
- if (!C) {
901
- C = {};
902
- let e = w.length;
1083
+ if (U) return U;
1084
+ if (!M) {
1085
+ M = {};
1086
+ let e = F.length;
903
1087
  for (let t = 0; t < e; t++) {
904
- let e = w[t];
905
- C[e] = globalThis[e];
1088
+ let e = F[t];
1089
+ M[e] = globalThis[e];
906
1090
  }
907
1091
  }
908
1092
  let t = document.createElement("div");
909
1093
  t.style.display = "none";
910
1094
  let n = document.createElement("div");
911
1095
  n.style.width = "100%", n.style.height = "100%", n.style.display = "flex", n.style.flex = "1 1 100%", t.appendChild(n), document.body.appendChild(t);
912
- let r = u(n);
913
- return j = {
1096
+ let r = l(n);
1097
+ return U = {
914
1098
  root: r,
915
1099
  hostEl: n,
916
1100
  stashEl: t,
917
1101
  props: e,
918
1102
  setProps: null
919
- }, r.render(y(ye, {})), j;
1103
+ }, r.render(b(we, {})), U;
920
1104
  })(e);
921
- return t.props = e, t.setProps?.(e), N = (e, t) => je(e, t), X.current?.appendChild(t.hostEl), M && (P = je(M.editor, M.monaco)), () => {
922
- P?.(), P = null, N = null, E.current = null, j?.stashEl.appendChild(j.hostEl);
1105
+ return t.props = e, t.setProps?.(e), G = (e, t) => Ae(e, t), Ne.current?.appendChild(t.hostEl), W && (K = Ae(W.editor, W.monaco)), () => {
1106
+ K?.(), K = null, G = null, T.current = null, U?.stashEl.appendChild(U.hostEl);
923
1107
  };
924
- }, []), a(() => {
925
- if (!j) return;
1108
+ }, []), i(() => {
1109
+ if (!U) return;
926
1110
  let e = {
927
- ...j.props,
1111
+ ...U.props,
928
1112
  theme: m ? "extended-dark" : "extended",
929
- options: Y
1113
+ options: Me
930
1114
  };
931
- j.props = e, j.setProps?.(e);
932
- }, [m, Y]), a(() => {
933
- let e = E.current, t = e?.editor;
1115
+ U.props = e, U.setProps?.(e);
1116
+ }, [m, Me]), i(() => {
1117
+ let e = T.current, t = e?.editor;
934
1118
  if (!t) return;
935
- I.current = F ?? null;
936
- let n = x?.getModules().getItems()[0]?.getSource() ?? "";
937
- t.getValue() !== n && (t.setValue(n), K(t.getModel(), e.monaco, t), V({ dirty: !1 }));
938
- }, [x, F]);
939
- let Ne = oe("div", {
1119
+ q.current = O ?? null;
1120
+ let n = j(x)?.getSource() ?? "";
1121
+ t.getValue() !== n && (t.setValue(n), J(t.getModel(), e.monaco, t), N({ dirty: !1 }));
1122
+ }, [x, O]);
1123
+ let Pe = ie("div", {
940
1124
  style: {
941
1125
  display: "flex",
942
1126
  flex: "1 1 100%",
@@ -945,75 +1129,41 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
945
1129
  position: "relative",
946
1130
  boxSizing: "border-box"
947
1131
  },
948
- children: [y("div", {
949
- ref: X,
1132
+ children: [b("div", {
1133
+ ref: Ne,
950
1134
  style: {
951
1135
  display: "flex",
952
1136
  flex: "1 1 100%",
953
1137
  width: "100%",
954
1138
  position: "relative"
955
1139
  }
956
- }), Me]
957
- }), Z = te(n, () => ({
1140
+ }), je]
1141
+ }), Q = te(n, () => ({
958
1142
  isScriptEditorElement: () => !0,
959
1143
  showCommandPalette: () => {
960
- E.current?.editor && E.current.editor.trigger("keyboard", "editor.action.quickCommand", null);
1144
+ T.current?.editor && T.current.editor.trigger("keyboard", "editor.action.quickCommand", null);
961
1145
  },
962
1146
  getScripts: () => x,
963
1147
  focus: (e) => {
964
- De(e);
1148
+ X(e);
965
1149
  },
966
1150
  close: () => Ee(),
967
- insertSnippet: (e) => E.current?.editor ? (async (e, t, n) => {
968
- let r = e.getModel();
969
- if (!r) return;
970
- let i = await (await (await t.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString()), a = e.getPosition(), o = { ...a };
971
- o.lineNumber = 1, o.column = 1;
972
- let s = !1;
973
- for (let e = a.lineNumber; e >= 1; e--) if (r.getLineContent(e).trim() === "") {
974
- let t = A(i, r.getOffsetAt({
975
- lineNumber: e,
976
- column: 1
977
- }), "function");
978
- if (!t || me(t)) {
979
- s = !0, o.lineNumber = e + 1;
980
- break;
981
- }
982
- {
983
- let n = t.spans[0].start;
984
- e = r.getPositionAt(n).lineNumber, o.lineNumber = e;
985
- }
986
- }
987
- let c = n, l = !1;
988
- !s && !c.startsWith("\n") && o.lineNumber > 1 && (c = "\n" + c, l = !0);
989
- let u = !1;
990
- r.getLineCount() > 1 && (c.endsWith("\n\n") || (c += "\n\n", u = !0));
991
- let d = [{
992
- range: new t.Range(o.lineNumber, o.column, o.lineNumber, o.column),
993
- text: `${c}`
994
- }], f = null;
995
- r.pushEditOperations([], d, (e) => (f = e[0].range, l && f.startLineNumber++, u && f.endLineNumber--, [new t.Selection(f.startLineNumber, f.startColumn, f.endLineNumber, f.endColumn)])), e.setSelection({
996
- startLineNumber: f.endLineNumber,
997
- startColumn: f.endColumn,
998
- endLineNumber: f.startLineNumber,
999
- endColumn: f.startColumn
1000
- });
1001
- })(E.current.editor, E.current.monaco, e) : Promise.resolve(),
1151
+ insertSnippet: (e) => T.current?.editor ? ge(T.current.editor, T.current.monaco, e) : Promise.resolve(),
1002
1152
  saveSource: async () => {
1003
- await U();
1153
+ await L();
1004
1154
  },
1005
1155
  runAction: (e) => {
1006
- let t = E.current?.editor;
1156
+ let t = T.current?.editor;
1007
1157
  t && (t.focus(), t.trigger("source", e, null));
1008
1158
  },
1009
- copy: () => Oe(),
1010
- cut: () => ke(),
1011
- paste: () => Ae()
1012
- }), [F]), [Q, Pe] = c(null), Fe = g((e) => {
1013
- e !== null && Pe(e);
1014
- }, []), $ = h.useCommandScope();
1015
- return a(() => {
1016
- if (!$ || !Q) return;
1159
+ copy: () => De(),
1160
+ cut: () => Oe(),
1161
+ paste: () => ke()
1162
+ }), [O]), [Fe, Ie] = s(null), Le = v((e) => {
1163
+ e !== null && Ie(e);
1164
+ }, []), $ = g.useCommandScope();
1165
+ i(() => {
1166
+ if (!$ || !Fe) return;
1017
1167
  let e = $.contribution();
1018
1168
  return function(e, t) {
1019
1169
  let n = t.scriptEditor, r = t;
@@ -1021,62 +1171,75 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
1021
1171
  window?.open("https://www.sheetxl.com/docs/guides/concepts/scripting");
1022
1172
  } }), e.updateCommand("showScriptingCommands", { callback: () => {
1023
1173
  n.showCommandPalette();
1024
- } }), e.updateCommand("insertScript", { callback: (e) => n.insertSnippet(e ?? "") }), e.updateCommand("saveScripts", {
1025
- disabledReasons: r?.isDirty ? [] : [p("reason.noChangesToSave")],
1174
+ } });
1175
+ let i = r?.readOnly ? [p("reason.scriptsReadOnly")] : [];
1176
+ e.updateCommand("insertScript", {
1177
+ disabledReasons: i,
1178
+ callback: (e) => n.insertSnippet(e ?? "")
1179
+ }), e.updateCommand("saveScripts", {
1180
+ disabledReasons: [...i, ...r?.isDirty ? [] : [p("reason.noChangesToSave")]],
1026
1181
  callback: async () => {
1027
1182
  await n.saveSource();
1028
1183
  }
1029
1184
  }), e.updateCommand("copy", { callback: () => n.copy() }), e.updateCommand("cut", { callback: () => n.cut() }), e.updateCommand("paste", { callback: () => n.paste() }), e.updateCommand("selectAll", { callback: () => n.runAction("editor.action.selectAll") }), e.updateCommand("find", { callback: () => n.runAction("actions.find") }), e.updateCommand("findReplace", { callback: () => n.runAction("editor.action.startFindReplaceAction") }), e.updateCommand("goto", { callback: () => n.runAction("editor.action.gotoLine") });
1030
1185
  }(e, {
1031
- scriptEditor: Q,
1032
- isDirty: O
1186
+ scriptEditor: Fe,
1187
+ isDirty: E,
1188
+ readOnly: f
1033
1189
  }), () => {
1034
1190
  e.remove();
1035
1191
  };
1036
1192
  }, [
1037
1193
  $,
1038
- Q,
1039
- O
1040
- ]), a(() => (ie && requestAnimationFrame(() => {
1041
- Z.current?.focus();
1194
+ Fe,
1195
+ E,
1196
+ f
1197
+ ]), i(() => (_ && requestAnimationFrame(() => {
1198
+ Q.current?.focus();
1042
1199
  }), () => {
1043
- E.current?.editor && requestAnimationFrame(() => {
1044
- Z.current?.contains(document.activeElement) && Z.current?.focus();
1200
+ T.current?.editor && requestAnimationFrame(() => {
1201
+ Q.current?.contains(document.activeElement) && Q.current?.focus();
1045
1202
  });
1046
- }), []), y("div", {
1047
- className: se("script-editor", ue, r),
1203
+ }), []);
1204
+ let Re = a(() => ce(ze), ze = [Q, Le]);
1205
+ var ze;
1206
+ return b("div", {
1207
+ className: se("script-editor", fe, r),
1048
1208
  style: {
1049
1209
  display: "flex",
1050
1210
  flexDirection: "row",
1051
1211
  flex: "1 1 100%",
1052
1212
  position: "relative",
1053
- ...i
1213
+ ...c
1054
1214
  },
1055
- ref: ce([Z, Fe]),
1056
- ...de,
1057
- children: Ne
1215
+ ref: Re,
1216
+ ...C,
1217
+ children: Pe
1058
1218
  });
1059
- })), z = null, be = (e) => {
1060
- z = e;
1061
- }, B = () => z, V = i((e) => {
1062
- let { scope: t, data: n } = e, { workbook: r } = n, i = _(), o = ie(), s = o.getOpen(), c = g(async (e) => {
1219
+ })), Y = null, Te = (e) => {
1220
+ Y = e;
1221
+ }, Ee = () => Y, X = r((e) => {
1222
+ let { scope: t, data: n } = e, { workbook: r } = n, a = ne(), o = S(), s = o.getOpen(), c = v(async (e) => {
1063
1223
  if (!r) return;
1064
1224
  let t = null, n = r.getScripts();
1065
1225
  if (e?.declaration || e?.functionName) {
1066
1226
  let r = e.declaration ? e.declaration.getName() : e.functionName;
1067
- (await n.searchFunctions({ name: r })).length > 0 && (t = r);
1227
+ (await n.searchFunctions({
1228
+ name: r,
1229
+ includeHidden: !0
1230
+ })).length > 0 && (t = r);
1068
1231
  }
1069
1232
  if (t) try {
1070
1233
  await n.executeMacro(t);
1071
1234
  } catch (e) {
1072
- i.showError(e);
1235
+ a.showError(e);
1073
1236
  return;
1074
1237
  }
1075
- }, [r, i]), l = g(() => {
1076
- let e = B();
1238
+ }, [r, a]), l = v(() => {
1239
+ let e = Ee();
1077
1240
  e ? r && e({ workbook: r }) : o.getOpen().includes("scriptEditor") ? o.close("scriptEditor") : o.activate("scriptEditor", {});
1078
1241
  }, [r, o]), u = s.includes("scriptEditor");
1079
- return a(() => {
1242
+ return i(() => {
1080
1243
  if (!t) return;
1081
1244
  let e = t.contribution();
1082
1245
  return e.updateCommand("showScriptEditor", {
@@ -1093,19 +1256,21 @@ var j = null, M = null, N = null, P = null, he = !1, ge = !1, F = !1, I = { curr
1093
1256
  r,
1094
1257
  c,
1095
1258
  l
1096
- ]), re(r, { onLoad: () => {
1259
+ ]), ae(r, { onLoad: () => {
1097
1260
  r?.getScripts().start();
1098
1261
  } }), null;
1099
1262
  });
1100
- V.displayName = "WorkbookScriptCommands";
1101
- var H = {
1263
+ X.displayName = "WorkbookScriptCommands";
1264
+ var De = {
1102
1265
  "reason.noChangesToSave": "No changes to save",
1266
+ "reason.scriptsReadOnly": "Scripts can't be changed while the workbook structure is protected.",
1103
1267
  "scriptEditor.glyph.autoRun": "Auto Run",
1104
1268
  "scriptEditor.glyph.formula": "Formula",
1105
1269
  "scriptEditor.glyph.macro": "Macro",
1106
1270
  "scriptEditor.loading": "Loading...",
1271
+ "scriptEditor.retry": "Retry",
1107
1272
  "scriptEditor.saving": "Saving Scripts..."
1108
- }, xe = [
1273
+ }, Oe = [
1109
1274
  {
1110
1275
  sourceId: "groups",
1111
1276
  catalog: {
@@ -1187,29 +1352,29 @@ var H = {
1187
1352
  }
1188
1353
  }
1189
1354
  }
1190
- ], { DefaultCommandCatalogService: U } = h, W = !1, G = (e) => {
1355
+ ], { DefaultCommandCatalogService: ke } = g, Z = !1, Ae = (e) => {
1191
1356
  let { model: t, entryKey: n, frame: r, ref: i, ...a } = e;
1192
- return y(R, {
1357
+ return b(J, {
1193
1358
  ref: i,
1194
1359
  frame: r,
1195
1360
  scripts: t?.getScripts(),
1196
1361
  ...a
1197
1362
  });
1198
- }, Se = () => {
1199
- v.registerTaskPane({
1363
+ }, je = () => {
1364
+ x.registerTaskPane({
1200
1365
  key: "scriptEditor",
1201
1366
  getTitle: () => "Script (Typescript)",
1202
1367
  getIcon: () => "ScriptRun",
1203
- component: G,
1368
+ component: Ae,
1204
1369
  keepMounted: !0
1205
1370
  }, !0), function() {
1206
- if (W) return;
1207
- W = !0;
1208
- let e = U;
1371
+ if (Z) return;
1372
+ Z = !0;
1373
+ let e = ke;
1209
1374
  e.registerFromManifest("@sheetxl/scripting-react", import.meta.url, {
1210
- messages: H,
1211
- catalogs: xe
1375
+ messages: De,
1376
+ catalogs: Oe
1212
1377
  }), e.prefetch();
1213
- }(), h.DefaultCommandRegistry.registerDynamic("workbook", V);
1378
+ }(), g.DefaultCommandRegistry.registerDynamic("workbook", X);
1214
1379
  };
1215
- export { R as ScriptEditor, Se as ScriptingReactPlugin, V as WorkbookScriptCommands, B as getScriptEditorOpener, be as setScriptEditorOpener };
1380
+ export { J as ScriptEditor, je as ScriptingReactPlugin, X as WorkbookScriptCommands, Ee as getScriptEditorOpener, Te as setScriptEditorOpener };