@sheetxl/scripting-react 0.8.0-beta.2 → 0.8.0-beta.21

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,20 +1,20 @@
1
1
  /**
2
- * @license @sheetxl/scripting-react - Scripting React - Monaco based script editor and scripting UI for SheetXL. - v0.8.0-beta.2
2
+ * @license @sheetxl/scripting-react - Scripting React - Monaco based script editor and scripting UI for SheetXL. - v0.8.0-beta.21
3
3
  *
4
4
  * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
- * License: The license can be found at https://www.sheetxl.com/license.
5
+ * License: SheetXL EULA — https://www.sheetxl.com/eula
6
6
  */
7
7
  import { Suspense as e, forwardRef as t, memo as n, useEffect as r, useMemo as o, useRef as i, useState as s } from "react";
8
8
  import { createRoot as a } from "react-dom/client";
9
9
  import c from "clsx";
10
- import { mergeRefs as l } from "react-merge-refs";
11
- import { CommonUtils as u, TimerUtils as d, defineLazyModule as p, messageKey as g } from "@sheetxl/utils";
12
- import { DocTags as m } from "@sheetxl/scripting";
10
+ import { useMergeRefs as l } from "react-merge-refs";
11
+ import { CommonUtils as u, TimerUtils as d, defineLazyModule as p, messageKey as m } from "@sheetxl/utils";
12
+ import { DocTags as g } from "@sheetxl/scripting";
13
13
  import { IScript as f } from "@sheetxl/sdk";
14
- import { Command as y, lazyComponent as h, useCallbackRef as b, useCommands as w, useImperativeElement as k, useLazyRetry as x, useNotifier as v, useTranslator as S } from "@sheetxl/utils-react";
14
+ import { Command as h, lazyComponent as y, useCallbackRef as b, useCommands as x, useImperativeElement as w, useLazyRetry as v, useNotifier as k, useTranslator as S } from "@sheetxl/utils-react";
15
15
  import { jsx as C, jsxs as N } from "react/jsx-runtime";
16
- import { DefaultTaskPaneRegistry as E, useModelListener as L, useTaskPaneArea as M, useWorkbook as D } from "@sheetxl/react";
17
- var O = {
16
+ import { DefaultTaskPaneRegistry as E, useModelListener as L, useTaskPaneArea as M, useWorkbook as O } from "@sheetxl/react";
17
+ var I = {
18
18
  defaultToken: "invalid",
19
19
  tokenPostfix: ".ts",
20
20
  keywords: [
@@ -355,7 +355,49 @@ var O = {
355
355
  { include: "common" }
356
356
  ]
357
357
  }
358
- }, T = {
358
+ }, D = /(?:\s|\/\/[^\n]*|\/\*[\s\S]*?\*\/)*/y, $ = /(import\b\s*(?:type\s+(?!from\b))?)(?:([^'";]*?)\s*\bfrom\s*)?(['"])([^'"\n]+)\3[ \t]*;?/y, A = (e) => e.replace(/\s+/g, " ").trim(), R = (e) => {
359
+ const t = [];
360
+ let n = 0;
361
+ for (;;) {
362
+ D.lastIndex = n, D.exec(e), $.lastIndex = D.lastIndex;
363
+ const r = $.exec(e);
364
+ if (!r) return t;
365
+ const o = r[2] ?? "", i = r.index + r[1].length, s = o.indexOf("{"), a = o.lastIndexOf("}"), c = s >= 0 && a > s, l = c ? o.slice(0, s) + o.slice(a + 1) : o;
366
+ t.push({
367
+ start: r.index,
368
+ end: $.lastIndex,
369
+ text: r[0],
370
+ module: r[4],
371
+ quote: r[3],
372
+ typeOnly: /\btype\s+$/.test(r[1]),
373
+ binding: A(l).replace(/\s*,$/, ""),
374
+ names: c ? o.slice(s + 1, a).split(",").map(A).filter(Boolean) : null,
375
+ namesStart: i + s + 1,
376
+ namesEnd: i + a
377
+ }), n = $.lastIndex;
378
+ }
379
+ }, T = (e) => [
380
+ e.typeOnly,
381
+ e.binding,
382
+ e.names?.join(","),
383
+ e.module
384
+ ].join("|"), P = (e) => `${e.typeOnly ? "type " : ""}${e.module}`, F = (e, t, n) => {
385
+ const r = e.slice(t.namesStart, t.namesEnd), o = r.trimEnd();
386
+ if ("" === o.trim()) return {
387
+ offset: t.namesStart,
388
+ text: ` ${n.join(", ")}${"" === r ? " " : ""}`
389
+ };
390
+ const i = t.namesStart + o.length, s = o.endsWith(","), a = o.lastIndexOf("\n");
391
+ if (a < 0) return {
392
+ offset: i,
393
+ text: `${s ? " " : ", "}${n.join(", ")}`
394
+ };
395
+ const c = /^[ \t]*/.exec(o.slice(a + 1))[0];
396
+ return {
397
+ offset: i,
398
+ text: `${s ? "" : ","}\n${c}${n.join(`,\n${c}`)}${s ? "," : ""}`
399
+ };
400
+ }, _ = {
359
401
  lightbulb: { enabled: !1 },
360
402
  tabSize: 2,
361
403
  acceptSuggestionOnCommitCharacter: !0,
@@ -418,32 +460,38 @@ var O = {
418
460
  wordWrapColumn: 80,
419
461
  wordWrapMinified: !0,
420
462
  wrappingIndent: "none"
421
- }, A = "_script-editor_1kuph_5", R = (e) => {
463
+ }, W = "_script-editor_1kuph_5", j = (e) => {
422
464
  const t = e?.getModules();
423
465
  return t ? (t.getByName(f.DEFAULT_MODULE), f.DEFAULT_MODULE) : f.DEFAULT_MODULE;
424
- }, I = (e) => e?.getModules()?.getByName(R(e)) ?? null;
425
- var F, P = p("scripting-react:monaco", async () => (function() {
426
- if ("undefined" == typeof window) return;
427
- const e = window;
428
- if (e.__sxlDefineShim) return;
429
- e.__sxlDefineShim = !0;
430
- const t = [];
431
- let n = null;
432
- const r = (...e) => {
433
- "function" == typeof n ? n(...e) : t.push(e);
434
- };
435
- Object.defineProperty(e, "define", {
436
- configurable: !1,
437
- enumerable: !0,
438
- get: () => "function" == typeof n ? n : r,
439
- set(e) {
440
- if ("function" == typeof e) for (n = e; t.length;) try {
441
- e(...t.shift());
442
- } catch {}
443
- }
444
- });
445
- }(), import("@monaco-editor/react")), { prefetch: !1 }), _ = ({ error: e }) => {
446
- const t = x(), n = S();
466
+ }, V = (e) => e?.getModules()?.getByName(j(e)) ?? null;
467
+ var B, H = p("scripting-react:monaco", async () => {
468
+ (function() {
469
+ if ("undefined" == typeof window) return;
470
+ const e = window;
471
+ if (e.__sxlDefineShim) return;
472
+ e.__sxlDefineShim = !0;
473
+ const t = [];
474
+ let n = null;
475
+ const r = (...e) => {
476
+ "function" == typeof n ? n(...e) : t.push(e);
477
+ };
478
+ Object.defineProperty(e, "define", {
479
+ configurable: !1,
480
+ enumerable: !0,
481
+ get: () => "function" == typeof n ? n : r,
482
+ set(e) {
483
+ if ("function" == typeof e) for (n = e; t.length;) try {
484
+ e(...t.shift());
485
+ } catch {}
486
+ }
487
+ });
488
+ })();
489
+ const [e] = await Promise.all([import("@monaco-editor/react"), Y().catch((e) => {
490
+ console.warn("cant load types", e);
491
+ })]);
492
+ return e;
493
+ }, { prefetch: !1 }), U = ({ error: e }) => {
494
+ const t = v(), n = S();
447
495
  return N("div", {
448
496
  style: {
449
497
  display: "flex",
@@ -459,14 +507,134 @@ var F, P = p("scripting-react:monaco", async () => (function() {
459
507
  children: n("scriptEditor.retry")
460
508
  }) : null]
461
509
  });
462
- }, $ = h(P.load, { renderError: (e) => C(_, { error: e }) }), W = ["define", "require"], V = !1, B = "@0.8.0-beta.2";
463
- "@local" !== B && "@0.0.0" !== B || (B = "");
464
- var U = `https://cdn.jsdelivr.net/npm/@sheetxl/sdk${B}/types/scripting.d.ts`, j = (e) => {
510
+ }, q = y(H.load, { renderError: ({ error: e }) => C(U, { error: e }) }), K = ["define", "require"], z = !1, G = "@0.8.0-beta.21";
511
+ "@local" !== G && "@0.0.0" !== G || (G = "");
512
+ var J = `https://cdn.jsdelivr.net/npm/@sheetxl/sdk${G}/types/scripting.d.ts`, X = null, Z = null, Y = () => (Z || (Z = (async () => await (await fetch(J)).text())().then((e) => (X = e, e))).catch(() => {
513
+ Z = null;
514
+ }), Z), Q = (e) => {
465
515
  try {
466
- e.languages.setMonarchTokensProvider("typescript", O);
516
+ e.languages.setMonarchTokensProvider("typescript", I);
467
517
  } catch (e) {}
468
- }, H = !1;
469
- function K(e, t) {
518
+ }, ee = !1, te = async (e, t, n) => {
519
+ const r = e.getModel();
520
+ if (!r) return;
521
+ const o = await (await (await t.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString()), i = e.getPosition();
522
+ let s = { ...i };
523
+ s.lineNumber = 1, s.column = 1;
524
+ let a = !1;
525
+ for (let e = i.lineNumber; e >= 1; e--) if ("" === r.getLineContent(e).trim()) {
526
+ const t = oe(o, r.getOffsetAt({
527
+ lineNumber: e,
528
+ column: 1
529
+ }), "function");
530
+ if (!t || ie(t)) {
531
+ a = !0, s.lineNumber = e + 1;
532
+ break;
533
+ }
534
+ {
535
+ const n = t.spans[0].start;
536
+ e = r.getPositionAt(n).lineNumber, s.lineNumber = e;
537
+ }
538
+ }
539
+ const c = ((e, t) => {
540
+ const n = R(e), r = n.length > 0 ? n[n.length - 1].end : 0, o = R(t);
541
+ if (0 === o.length) return {
542
+ body: t,
543
+ inserts: [],
544
+ importsEnd: r
545
+ };
546
+ let i = "", s = 0;
547
+ for (const e of o) i += t.slice(s, e.start), s = e.end + (/^[ \t]*\r?\n/.exec(t.slice(e.end))?.[0].length ?? 0);
548
+ i = (i + t.slice(s)).replace(/^(?:[ \t]*\r?\n)+/, "");
549
+ const a = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
550
+ for (const e of n) {
551
+ if (a.add(T(e)), !e.names) continue;
552
+ const t = P(e);
553
+ l.has(t) || l.set(t, e);
554
+ let n = c.get(t);
555
+ n || c.set(t, n = /* @__PURE__ */ new Set());
556
+ for (const t of e.names) n.add(t);
557
+ }
558
+ const u = /* @__PURE__ */ new Map(), d = [], p = /* @__PURE__ */ new Map();
559
+ for (const e of o) {
560
+ if (!e.names || e.binding) {
561
+ const t = T(e);
562
+ if (a.has(t)) continue;
563
+ a.add(t), d.push(e.text);
564
+ continue;
565
+ }
566
+ const t = P(e);
567
+ let n = c.get(t);
568
+ n || c.set(t, n = /* @__PURE__ */ new Set());
569
+ const r = e.typeOnly ? c.get(e.module) : void 0, o = e.names.filter((e) => !n.has(e) && !r?.has(e));
570
+ if (0 === o.length) continue;
571
+ for (const e of o) n.add(e);
572
+ const i = l.get(t);
573
+ if (i) {
574
+ u.set(i, [...u.get(i) ?? [], ...o]);
575
+ continue;
576
+ }
577
+ const s = p.get(t);
578
+ if (s) {
579
+ s.names.push(...o), s.verbatim = !1;
580
+ continue;
581
+ }
582
+ const m = {
583
+ statement: e,
584
+ names: o,
585
+ verbatim: o.length === e.names.length
586
+ };
587
+ p.set(t, m), d.push(m);
588
+ }
589
+ const m = [];
590
+ for (const [t, n] of u) m.push(F(e, t, n));
591
+ if (m.sort((e, t) => e.offset - t.offset), d.length > 0) {
592
+ const t = d.map((e) => {
593
+ if ("string" == typeof e) return e;
594
+ const { statement: t, names: n, verbatim: r } = e;
595
+ if (r) return t.text;
596
+ const { quote: o } = t;
597
+ return `import ${t.typeOnly ? "type " : ""}{ ${n.join(", ")} } from ${o}${t.module}${o};`;
598
+ }).join("\n");
599
+ r > 0 ? m.push({
600
+ offset: r,
601
+ text: `\n${t}`
602
+ }) : m.unshift({
603
+ offset: 0,
604
+ text: `${t}\n${/^[ \t]*\r?\n/.test(e) ? "" : "\n"}`
605
+ });
606
+ }
607
+ return {
608
+ body: i,
609
+ inserts: m,
610
+ importsEnd: r
611
+ };
612
+ })(r.getValue(), n), l = c.importsEnd > 0 ? r.getPositionAt(c.importsEnd).lineNumber : 0;
613
+ let u = c.body, d = "";
614
+ s.lineNumber <= l ? l < r.getLineCount() ? (s.lineNumber = l + 1, d = u.startsWith("\n") ? "" : "\n") : (s.lineNumber = l, s.column = r.getLineMaxColumn(l), d = "\n\n") : !a && !u.startsWith("\n") && s.lineNumber > 1 && (d = "\n");
615
+ let p = !1;
616
+ r.getLineCount() > 1 && (u.endsWith("\n\n") || (u += "\n\n", p = !0));
617
+ const m = r.validatePosition(s), g = new t.Range(m.lineNumber, m.column, m.lineNumber, m.column), f = [];
618
+ for (const e of c.inserts) {
619
+ const n = r.getPositionAt(e.offset);
620
+ n.lineNumber === g.startLineNumber && n.column === g.startColumn ? d = e.text + d : f.push({
621
+ range: new t.Range(n.lineNumber, n.column, n.lineNumber, n.column),
622
+ text: e.text
623
+ });
624
+ }
625
+ const h = d.split("\n").length - 1, y = [{
626
+ range: g,
627
+ text: `${d}${u}`
628
+ }, ...f];
629
+ let b = null;
630
+ r.pushEditOperations([], y, (e) => (b = e[0].range, h > 0 && (b.startLineNumber += h, b.startColumn = 1), p && b.endLineNumber--, [new t.Selection(b.startLineNumber, b.startColumn, b.endLineNumber, b.endColumn)])), e.setSelection({
631
+ startLineNumber: b.endLineNumber,
632
+ startColumn: b.endColumn,
633
+ endLineNumber: b.startLineNumber,
634
+ endColumn: b.startColumn
635
+ });
636
+ };
637
+ function ne(e, t) {
470
638
  let n = null;
471
639
  const r = e.length;
472
640
  for (let o = 0; !n && o < r; o++) {
@@ -475,48 +643,64 @@ function K(e, t) {
475
643
  }
476
644
  return n ? n.getContext() : "formula";
477
645
  }
478
- function q(e, t, n, r, o = []) {
646
+ function re(e, t, n, r, o = []) {
479
647
  if ("function" === r.kind && "export" === r.kindModifiers) {
480
648
  const t = r.spans[0].start, i = e.getPositionAt(t);
481
649
  o.push({
482
650
  name: r.text,
483
- type: K(n, r),
651
+ type: ne(n, r),
484
652
  lineNumber: i.lineNumber
485
653
  });
486
654
  }
487
- if (r.childItems) for (const i of r.childItems) q(e, t, n, i, o);
655
+ if (r.childItems) for (const i of r.childItems) re(e, t, n, i, o);
488
656
  return o;
489
657
  }
490
- function z(e, t, n = "function", r) {
658
+ function oe(e, t, n = "function", r) {
491
659
  const o = e.spans, i = o.length;
492
660
  for (let s = 0; s < i; s++) {
493
661
  const i = o[s];
494
662
  if (i.start <= t && t < i.start + i.length) {
495
663
  if (e.kind === n && (!r || e.kindModifiers === r)) return e;
496
664
  for (const o of e.childItems || []) {
497
- const e = z(o, t, n, r);
665
+ const e = oe(o, t, n, r);
498
666
  if (e) return e;
499
667
  }
500
668
  }
501
669
  return null;
502
670
  }
503
671
  }
504
- function G(e) {
672
+ function ie(e) {
505
673
  return "comment" === e.kind;
506
674
  }
507
- var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { current: null }, re = (e, t) => {
508
- J = {
675
+ var se = null, ae = null, ce = null, le = null, ue = !1, de = !1, pe = !1, me = { current: null }, ge = (e, t) => {
676
+ ae = {
509
677
  editor: e,
510
678
  monaco: t
511
- }, X && (Y = X(e, t));
512
- }, oe = (e) => {
513
- if (te) return;
514
- te = !0, e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
515
- noSemanticValidation: !0,
679
+ }, ce && (le = ce(e, t));
680
+ }, fe = (e) => {
681
+ if (pe) return;
682
+ pe = !0;
683
+ const t = e.languages.typescript;
684
+ t.typescriptDefaults.setCompilerOptions({
685
+ ...t.typescriptDefaults.getCompilerOptions(),
686
+ target: t.ScriptTarget.ES2020,
687
+ lib: [
688
+ "webworker",
689
+ "es2020",
690
+ "esnext.asynciterable"
691
+ ],
692
+ strict: !0,
693
+ downlevelIteration: !0,
694
+ moduleResolution: t.ModuleResolutionKind.NodeJs,
695
+ allowSyntheticDefaultImports: !0,
696
+ baseUrl: "inmemory://model/",
697
+ allowNonTsExtensions: !0
698
+ }), t.typescriptDefaults.setDiagnosticsOptions({
699
+ noSemanticValidation: !1,
516
700
  noSyntaxValidation: !1,
517
701
  diagnosticCodesToIgnore: [2307]
518
- }), e.languages.typescript.typescriptDefaults.setEagerModelSync(!0), e.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: !0 }), j(e), ((e) => {
519
- H || (H = !0, e.languages.registerCompletionItemProvider("typescript", {
702
+ }), t.typescriptDefaults.setEagerModelSync(!0), null !== X && (t.typescriptDefaults.addExtraLib(X, "inmemory://model/sheetxl.d.ts"), t.typescriptDefaults.addExtraLib("declare module '@sheetxl/primitives' { export = SheetXL; }\n", "inmemory://model/sheetxl-module-shims.d.ts")), e.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: !0 }), Q(e), ((e) => {
703
+ ee || (ee = !0, e.languages.registerCompletionItemProvider("typescript", {
520
704
  triggerCharacters: ["@"],
521
705
  provideCompletionItems: (t, n) => {
522
706
  const r = t.getValueInRange({
@@ -535,7 +719,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
535
719
  return n.lastIndexOf("/*") > n.lastIndexOf("*/");
536
720
  })(t, n)) return { suggestions: [] };
537
721
  const i = o[1], s = new e.Range(n.lineNumber, n.column - i.length, n.lineNumber, n.column);
538
- return { suggestions: m.map((t) => ({
722
+ return { suggestions: g.map((t) => ({
539
723
  label: `@${t.name}`,
540
724
  kind: e.languages.CompletionItemKind.Keyword,
541
725
  detail: "sheetxl" === t.group ? "SheetXL" : "JSDoc",
@@ -590,91 +774,53 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
590
774
  }
591
775
  ],
592
776
  colors: {}
593
- });
594
- (async () => {
595
- let t = !1;
596
- try {
597
- const n = await (async () => await (await fetch(U)).text())(), r = e.Uri.parse("inmemory://model/\"sheetxl-models\".d.ts");
598
- let o = e.editor.getModel(r);
599
- o ? t = !0 : o = e.editor.createModel(n, "typescript", r), e.editor.setModelMarkers(o, "default", []);
600
- } catch (e) {
601
- console.warn("cant load types", e);
602
- }
603
- try {
604
- if (e.languages.registerLinkProvider("*", { provideLinks: (t, n) => {
605
- const r = [], o = { links: r }, i = t.getLinesContent(), s = i.length;
606
- for (let n = 1; n <= s; n++) {
607
- const o = i[n - 1], s = e.editor.tokenize(o, "typescript"), a = s[0].length;
608
- for (let i = 0; i < a; i++) {
609
- const a = s[0]?.[i];
610
- if (a && a.type.startsWith("string")) {
611
- let c = a.offset, l = s[0]?.[i + 1]?.offset ?? o.length, u = new e.Range(n, c + 1, n, l + 1), d = t.getValueInRange(u);
612
- const p = d[0];
613
- "`" !== p && "'" !== p && "\"" !== p || (c++, d = d.substring(1));
614
- const g = d[d.length - 1];
615
- "`" !== g && "'" !== g && "\"" !== g || (c++, d = d.substring(0, d.length - 1));
616
- try {
617
- ne.current?.getRanges(d) && r.push({
618
- range: {
619
- endColumn: l,
620
- endLineNumber: n,
621
- startColumn: c,
622
- startLineNumber: n
623
- },
624
- tooltip: `Goto range '${d}'`,
625
- url: `/range/${d}`
626
- });
627
- } catch (e) {}
628
- }
629
- }
630
- }
631
- return o;
632
- } }), e.editor.registerLinkOpener({ open(e) {
633
- if (e?.path?.startsWith("/range/")) {
777
+ }), e.languages.registerLinkProvider("*", { provideLinks: (t, n) => {
778
+ const r = [], o = { links: r }, i = t.getLinesContent(), s = i.length;
779
+ for (let n = 1; n <= s; n++) {
780
+ const o = i[n - 1], s = e.editor.tokenize(o, "typescript"), a = s[0].length;
781
+ for (let i = 0; i < a; i++) {
782
+ const a = s[0]?.[i];
783
+ if (a && a.type.startsWith("string")) {
784
+ let c = a.offset, l = s[0]?.[i + 1]?.offset ?? o.length, u = new e.Range(n, c + 1, n, l + 1), d = t.getValueInRange(u);
785
+ const p = d[0];
786
+ "`" !== p && "'" !== p && "\"" !== p || (c++, d = d.substring(1));
787
+ const m = d[d.length - 1];
788
+ "`" !== m && "'" !== m && "\"" !== m || (c++, d = d.substring(0, d.length - 1));
634
789
  try {
635
- ne.current?.getRanges(e.path.substring(7))?.select();
636
- } catch (e) {
637
- console.warn("invalid range", e);
638
- }
639
- return !0;
790
+ me.current?.getRanges(d) && r.push({
791
+ range: {
792
+ endColumn: l,
793
+ endLineNumber: n,
794
+ startColumn: c,
795
+ startLineNumber: n
796
+ },
797
+ tooltip: `Goto range '${d}'`,
798
+ url: `/range/${d}`
799
+ });
800
+ } catch (e) {}
640
801
  }
641
- return !1;
642
- } }), !t) {
643
- const t = e.languages.typescript.typescriptDefaults.getCompilerOptions();
644
- e.languages.typescript.typescriptDefaults.setCompilerOptions({
645
- ...t,
646
- target: e.languages.typescript.ScriptTarget.ES2020,
647
- lib: [
648
- "webworker",
649
- "es2020",
650
- "esnext.asynciterable"
651
- ],
652
- strict: !0,
653
- downlevelIteration: !0,
654
- moduleResolution: e.languages.typescript.ModuleResolutionKind.NodeJs,
655
- allowSyntheticDefaultImports: !0,
656
- baseUrl: "inmemory://model/",
657
- allowNonTsExtensions: !0
658
- });
659
802
  }
660
- } finally {
661
- (() => {
662
- const t = e.languages.typescript.typescriptDefaults.getDiagnosticsOptions();
663
- e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
664
- ...t,
665
- noSemanticValidation: !1
666
- });
667
- })();
668
803
  }
669
- })();
670
- }, ie = (e) => {
804
+ return o;
805
+ } }), e.editor.registerLinkOpener({ open(e) {
806
+ if (e?.path?.startsWith("/range/")) {
807
+ try {
808
+ me.current?.getRanges(e.path.substring(7))?.select();
809
+ } catch (e) {
810
+ console.warn("invalid range", e);
811
+ }
812
+ return !0;
813
+ }
814
+ return !1;
815
+ } });
816
+ }, he = (e) => {
671
817
  let t = !1;
672
818
  const n = e ? e.length : 0;
673
819
  for (let r = 0; !t && r < n; r++) 8 === e[r].severity && (t = !0);
674
- }, se = () => {
675
- const [t, n] = s(() => Z.props);
676
- return r(() => (Z && (Z.setProps = n), () => {
677
- Z && (Z.setProps = null);
820
+ }, ye = () => {
821
+ const [t, n] = s(() => se.props);
822
+ return r(() => (se && (se.setProps = n), () => {
823
+ se && (se.setProps = null);
678
824
  }), []), C("div", {
679
825
  style: {
680
826
  display: "flex",
@@ -682,90 +828,93 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
682
828
  width: "100%",
683
829
  height: "100%"
684
830
  },
685
- children: C(e, { children: C($, {
831
+ children: C(e, { children: C(q, {
686
832
  theme: t.theme,
687
833
  options: t.options,
688
834
  language: "typescript",
689
835
  value: t.value,
690
836
  onValidate: t.onValidate,
691
837
  beforeMount: t.beforeMount,
692
- onMount: re
838
+ onMount: ge
693
839
  }) })
694
840
  });
695
- }, ae = n(t((e, t) => {
696
- const { className: n, style: p, readOnly: m = !1, darkMode: f, loadingPanel: h, autoFocus: x = !0, frame: E, scripts: M, onStatusChange: O, ...P } = e, _ = S(), $ = i(null), [B, U] = s(!1), H = D(), [K] = w(["insertFunction"]), [te, re] = s({
841
+ }, be = n(t((e, t) => {
842
+ const { className: n, style: p, readOnly: g = !1, darkMode: f, loadingPanel: y, autoFocus: v = !0, frame: E, scripts: M, onStatusChange: I, ...D } = e, $ = S(), A = i(null), [R, T] = s(!1), P = O(), [F] = x(["insertFunction"]), [H, U] = s({
697
843
  message: "Loading",
698
844
  cursor: "",
699
845
  dirty: !1
700
- }), [ae, ce] = s({
846
+ }), [q, G] = s({
701
847
  loading: !1,
702
848
  compiling: !1,
703
849
  errors: [],
704
850
  warnings: []
705
- }), le = b((e) => {
706
- re((t) => {
851
+ }), J = b((e) => {
852
+ U((t) => {
707
853
  const n = {
708
854
  ...t,
709
855
  ...e
710
856
  };
711
- return u.deepEqual(n, t) ? t : (U(n.dirty ?? !1), n);
857
+ return u.deepEqual(n, t) ? t : (T(n.dirty ?? !1), n);
712
858
  });
713
- }, [O]);
859
+ }, [I]);
714
860
  r(() => {
715
- O?.(te);
716
- }, [O, te]);
717
- const ue = v(), de = b(async (e) => {
861
+ I?.(H);
862
+ }, [I, H]);
863
+ const X = k(), Z = b(async (e) => {
718
864
  let t = null, n = null;
719
865
  try {
720
- e && (n = await ue.showBusy(_("scriptEditor.saving")), t = await M.createModule({ source: e })), M.addModule(R(M), t, { replace: !0 }), n?.();
866
+ e && (n = await X.showBusy($("scriptEditor.saving")), t = await M.createModule({ source: e })), M.addModule(j(M), t, { replace: !0 }), n?.();
721
867
  } catch (e) {
722
- n?.(), console.warn("Unable to compile", e), ue.showError(e);
868
+ n?.(), console.warn("Unable to compile", e), X.showError(e);
723
869
  }
724
870
  return t;
725
- }, [M]), pe = b(async () => {
726
- if (!$.current || m) return;
727
- const e = $.current.editor;
871
+ }, [M]), Y = b(async () => {
872
+ if (!A.current || g) return;
873
+ const e = A.current.editor;
728
874
  let t;
729
- if (te.dirty) {
875
+ if (H.dirty) {
730
876
  const n = e.getValue();
731
- await de(n), t = I(M);
877
+ await Z(n), t = V(M);
732
878
  const r = t?.getSource(), o = e.getValue(), i = (r?.length ?? 0) !== n.length || r !== o;
733
- le({ dirty: i });
734
- } else t = I(M);
879
+ J({ dirty: i });
880
+ } else t = V(M);
735
881
  return t;
736
- }, [te, M]);
882
+ }, [H, M]);
737
883
  r(() => {
738
- const e = E?.addListener({ onBeforeHide: async () => (await pe(), !0) });
884
+ const e = E?.addListener({ onBeforeHide: async () => (await Y(), !0) });
739
885
  return () => {
740
886
  e?.();
741
887
  };
742
888
  }, [E]), r(() => {
743
- if (M) return M.addListeners({ onBeforeSearch: () => pe() });
744
- }, [M]), L(H, {
889
+ if (M) return M.addListeners({ onBeforeSearch: () => Y() });
890
+ }, [M]), L(P, {
745
891
  onBeforeSave: async () => {
746
- await pe();
892
+ await Y();
747
893
  },
748
894
  onLoad: () => {
749
- const e = $.current?.editor;
750
- e && e.setValue(I(M)?.getSource() ?? "");
895
+ const e = A.current?.editor;
896
+ e && e.setValue(V(M)?.getSource() ?? "");
751
897
  }
752
898
  });
753
- const ge = b(async (e) => {
899
+ const ee = b(async (e) => {
754
900
  if (!M) return;
755
901
  const t = "string" == typeof e ? { functionName: e } : e ?? {};
756
902
  let n = null;
757
903
  if (t?.declaration || t?.functionName) {
758
904
  const e = t.declaration ? t.declaration.getName() : t.functionName;
759
- (await M.searchFunctions({ name: e })).length > 0 && (n = e);
905
+ (await M.searchFunctions({
906
+ name: e,
907
+ includeHidden: !0
908
+ })).length > 0 && (n = e);
760
909
  }
761
910
  if (n) try {
762
911
  await M.executeMacro(n);
763
912
  } catch (e) {
764
- ue.showError(e);
913
+ X.showError(e);
765
914
  }
766
- }, [M, ue]), [me, fe] = s(!1), ye = b(async () => {
767
- if (!$.current) return null;
768
- const e = $.current, t = e.editor;
915
+ }, [M, X]), [ne, ie] = s(!1), pe = b(async () => {
916
+ if (!A.current) return null;
917
+ const e = A.current, t = e.editor;
769
918
  if (!t) return null;
770
919
  const r = await (async (e, t, n = "export") => {
771
920
  const r = e.getModel();
@@ -775,7 +924,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
775
924
  if (!s) return null;
776
925
  const a = s.startLineNumber === s.endLineNumber && s.startColumn === s.endColumn ? r.getLineCount() : Math.min(s.endLineNumber, r.getLineCount());
777
926
  for (let e = s.startLineNumber; !i && e <= a; e++) {
778
- const t = z(o, r.getOffsetAt({
927
+ const t = oe(o, r.getOffsetAt({
779
928
  lineNumber: e,
780
929
  column: 1
781
930
  }), "function", n);
@@ -783,14 +932,14 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
783
932
  }
784
933
  return i;
785
934
  })(t, e.monaco);
786
- return le({ message: (r ?? "").toUpperCase() }), r ? {
935
+ return J({ message: (r ?? "").toUpperCase() }), r ? {
787
936
  source: t.getValue(),
788
937
  name: r
789
938
  } : null;
790
939
  }, []);
791
- b(d.debounce(pe, 200), []);
792
- const he = b(async (e, t, n) => {
793
- ce((e) => ({
940
+ b(d.debounce(Y, 200), []);
941
+ const ge = b(async (e, t, n) => {
942
+ G((e) => ({
794
943
  ...e,
795
944
  compiling: !0
796
945
  }));
@@ -817,9 +966,9 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
817
966
  });
818
967
  t.editor.setModelMarkers(e, "sheetxl", r);
819
968
  })(e, t, o), async function(e, t, n, r) {
820
- const o = q(e, t, r, await (await (await t.languages.typescript.getTypeScriptWorker())(e.uri)).getNavigationTree(e.uri.toString())).map((e) => {
969
+ const o = re(e, t, r, await (await (await t.languages.typescript.getTypeScriptWorker())(e.uri)).getNavigationTree(e.uri.toString())).map((e) => {
821
970
  let n = null, r = null;
822
- return "formula" === e.type ? (n = "formula.margin-icon", r = _("scriptEditor.glyph.formula")) : "macro" === e.type ? (n = "macro.margin-icon", r = _("scriptEditor.glyph.macro")) : "autoRun" === e.type && (n = "autorun.margin-icon", r = _("scriptEditor.glyph.autoRun")), {
971
+ return "formula" === e.type ? (n = "formula.margin-icon", r = $("scriptEditor.glyph.formula")) : "macro" === e.type ? (n = "macro.margin-icon", r = $("scriptEditor.glyph.macro")) : "autoRun" === e.type && (n = "autorun.margin-icon", r = $("scriptEditor.glyph.autoRun")), {
823
972
  range: new t.Range(e.lineNumber, 1, e.lineNumber, 1),
824
973
  options: {
825
974
  isWholeLine: !1,
@@ -830,32 +979,32 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
830
979
  };
831
980
  });
832
981
  Ee.current && Ee.current.clear(), Ee.current = n.createDecorationsCollection(o);
833
- }(e, t, n, r ? r.getFunctions().getItems() : u.EmptyArray), ce((e) => ({
982
+ }(e, t, n, r ? r.getFunctions().getItems({ includeHidden: !0 }) : u.EmptyArray), G((e) => ({
834
983
  ...e,
835
984
  compiling: !1,
836
985
  errors: o.filter((e) => "error" === e.severity).map((e) => `${e.code}: ${e.message}`),
837
986
  warnings: o.filter((e) => "warning" === e.severity).map((e) => `${e.code}: ${e.message}`)
838
987
  }));
839
- }, [M]), be = b(d.debounce(he, 580), []), we = b(async (e) => {
840
- if (!$.current) return;
841
- const t = $.current.editor.getPosition(), n = { cursor: t ? t.toString() : "" };
842
- void 0 !== e && (n.message = e), le(n);
988
+ }, [M]), be = b(d.debounce(ge, 580), []), xe = b(async (e) => {
989
+ if (!A.current) return;
990
+ const t = A.current.editor.getPosition(), n = { cursor: t ? t.toString() : "" };
991
+ void 0 !== e && (n.message = e), J(n);
843
992
  }, []);
844
- r(() => {}, [ae]);
845
- const ke = i(null), xe = b(async () => {
846
- await pe(), E?.close();
847
- }, [E]), ve = b((e) => {
848
- const t = $.current?.editor;
993
+ r(() => {}, [q]);
994
+ const we = i(null), ve = b(async () => {
995
+ await Y(), E?.close();
996
+ }, [E]), ke = b((e) => {
997
+ const t = A.current?.editor;
849
998
  return !!t && (t.focus(e), !0);
850
- }, [te]), Se = b(async () => {
851
- const e = $.current?.editor, t = e?.getModel(), n = e?.getSelection();
999
+ }, [H]), Se = b(async () => {
1000
+ const e = A.current?.editor, t = e?.getModel(), n = e?.getSelection();
852
1001
  if (!t || !n) return;
853
1002
  const r = n.isEmpty() ? t.getLineContent(n.positionLineNumber) + "\n" : t.getValueInRange(n);
854
1003
  try {
855
1004
  await navigator.clipboard?.writeText(r);
856
1005
  } catch {}
857
1006
  }, []), Ce = b(async () => {
858
- const e = $.current, t = e?.editor, n = t?.getModel(), r = t?.getSelection();
1007
+ const e = A.current, t = e?.editor, n = t?.getModel(), r = t?.getSelection();
859
1008
  if (!n || !r) return;
860
1009
  const o = r.isEmpty() ? new e.monaco.Range(r.positionLineNumber, 1, r.positionLineNumber + 1, 1) : r, i = n.getValueInRange(o);
861
1010
  try {
@@ -869,7 +1018,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
869
1018
  forceMoveMarkers: !0
870
1019
  }]), t.pushUndoStop(), t.focus();
871
1020
  }, []), Ne = b(async () => {
872
- const e = $.current?.editor;
1021
+ const e = A.current?.editor;
873
1022
  if (!e) return;
874
1023
  let t;
875
1024
  try {
@@ -885,22 +1034,28 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
885
1034
  forceMoveMarkers: !0
886
1035
  }]), e.pushUndoStop(), e.focus();
887
1036
  }, []), Ee = i(null), Le = b((e, t) => {
888
- $.current = {
1037
+ A.current = {
889
1038
  monaco: t,
890
1039
  editor: e
891
- }, ne.current = H ?? null;
1040
+ }, me.current = P ?? null;
892
1041
  const n = e.getModel(), r = [];
893
- fe(!0);
894
- const o = I(M)?.getSource() ?? "";
895
- return e.getValue() !== o && e.setValue(o), Q ? (we(""), be(n, t, e), j(t)) : (Q = !0, we("Loading Types"), import("monaco-editor-auto-typings/custom-editor.js").then(async (n) => {
896
- we(""), n.AutoTypings.create(e, {
1042
+ ie(!0);
1043
+ const o = V(M)?.getSource() ?? "";
1044
+ return e.getValue() !== o && e.setValue(o), ue ? (xe(""), be(n, t, e), Q(t)) : (ue = !0, xe("Loading Types"), import("monaco-editor-auto-typings/custom-editor.js").then(async (n) => {
1045
+ xe("");
1046
+ const r = n.AutoTypings, o = new n.JsDelivrSourceResolver(), i = (e) => e.startsWith("@sheetxl/") || e.startsWith("@types/sheetxl__");
1047
+ r.create(e, {
1048
+ sourceResolver: {
1049
+ resolvePackageJson: (e, t, n) => i(e) ? Promise.resolve(void 0) : o.resolvePackageJson(e, t, n),
1050
+ resolveSourceFile: (e, t, n) => i(e) ? Promise.resolve(void 0) : o.resolveSourceFile(e, t, n)
1051
+ },
897
1052
  shareCache: !0,
898
1053
  dontAdaptEditorOptions: !0,
899
1054
  monaco: t,
900
1055
  onUpdate: (e, n) => {
901
- if ("LookedUpPackage" === e.type && void 0 !== e.success) {
1056
+ if ("LookedUpPackage" === e.type && !0 === e.success) {
902
1057
  const e = t.languages.typescript.typescriptDefaults.getDiagnosticsOptions();
903
- t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
1058
+ e.diagnosticCodesToIgnore?.length && t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
904
1059
  ...e,
905
1060
  diagnosticCodesToIgnore: []
906
1061
  });
@@ -910,8 +1065,8 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
910
1065
  "Not implemented yet" === e && (e = "Compile Errors"), console.warn("Error compiling types", e);
911
1066
  }
912
1067
  }).then((n) => {
913
- ke.current = n, be(e.getModel(), t, e), (() => {
914
- if (V) return;
1068
+ we.current = n, be(e.getModel(), t, e), (() => {
1069
+ if (z) return;
915
1070
  const e = (e, t) => {
916
1071
  try {
917
1072
  if (void 0 === t) try {
@@ -923,17 +1078,17 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
923
1078
  }
924
1079
  else globalThis[e] = t;
925
1080
  } catch (e) {}
926
- }, t = W.length;
1081
+ }, t = K.length;
927
1082
  for (let n = 0; n < t; n++) {
928
- const t = W[n];
929
- e(t, F[t]);
1083
+ const t = K[n];
1084
+ e(t, B[t]);
930
1085
  }
931
- F = void 0, V = !0;
932
- })(), j(t);
1086
+ B = void 0, z = !0;
1087
+ })(), Q(t);
933
1088
  });
934
1089
  }).catch((e) => {
935
- Q = !1, we(""), console.warn("Auto typings could not be loaded:", e);
936
- })), ee || (ee = !0, function(e, t) {
1090
+ ue = !1, xe(""), console.warn("Auto typings could not be loaded:", e);
1091
+ })), de || (de = !0, function(e, t) {
937
1092
  t.languages.registerInlayHintsProvider("typescript", { provideInlayHints(e, n, r) {
938
1093
  const o = [];
939
1094
  for (let n = 1; n < e.getLineCount() + 1; n++) {
@@ -962,75 +1117,75 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
962
1117
  label: "Execute",
963
1118
  keybindings: [t.KeyCode.F8],
964
1119
  run: async (e) => {
965
- const t = await ye();
966
- ge(t);
1120
+ const t = await pe();
1121
+ ee(t);
967
1122
  }
968
1123
  })), r.push(e.addAction({
969
1124
  id: "saveScript",
970
1125
  label: "Save Script",
971
1126
  keybindings: [t.KeyMod.CtrlCmd | t.KeyCode.KeyS],
972
1127
  run: (e) => {
973
- pe();
1128
+ Y();
974
1129
  }
975
1130
  })), r.push(e.onMouseDown(async (e) => {
976
1131
  if (e.target.type === t.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
977
1132
  e.event.browserEvent.preventDefault();
978
- const r = e.target.position.lineNumber, o = await (await (await t.languages.typescript.getTypeScriptWorker())(n.uri)).getNavigationTree(n.uri.toString()), i = await pe();
1133
+ const r = e.target.position.lineNumber, o = await (await (await t.languages.typescript.getTypeScriptWorker())(n.uri)).getNavigationTree(n.uri.toString()), i = await Y();
979
1134
  if (!i) return;
980
- const s = i.getFunctions().getItems(), a = q(n, t, s, o).find((e) => e.lineNumber === r);
1135
+ const s = i.getFunctions().getItems({ includeHidden: !0 }), a = re(n, t, s, o).find((e) => e.lineNumber === r);
981
1136
  if (a) {
982
1137
  const t = e.event.browserEvent.button;
983
1138
  if (0 === t) {
984
- if ("macro" === a.type || "autoRun" === a.type) ge({ functionName: a.name });
1139
+ if ("macro" === a.type || "autoRun" === a.type) ee({ functionName: a.name });
985
1140
  else if ("formula" === a.type) {
986
1141
  const e = s?.find((e) => e.getName() === a.name);
987
- e && K?.execute(e);
1142
+ e && F?.execute(e);
988
1143
  }
989
1144
  } else 2 === t && (console.log("Context menu for function:", a.name), e.event.browserEvent.preventDefault());
990
1145
  }
991
1146
  }
992
1147
  })), r.push(e.onDidChangeModelContent(() => {
993
- le({ dirty: !0 }), be(n, t, e);
1148
+ J({ dirty: !0 }), be(n, t, e);
994
1149
  })), r.push(t.editor.onDidChangeMarkers((e) => {
995
1150
  e.some((e) => e.toString() === n.uri.toString());
996
1151
  })), r.push(n.onDidChangeContent((t) => {
997
- const n = I(M)?.getSource(), r = e.getValue(), o = (n?.length ?? 0) !== r.length || n !== r;
998
- le({ dirty: o });
1152
+ const n = V(M)?.getSource(), r = e.getValue(), o = (n?.length ?? 0) !== r.length || n !== r;
1153
+ J({ dirty: o });
999
1154
  })), r.push(e.onDidChangeCursorPosition((e) => {
1000
- we();
1155
+ xe();
1001
1156
  })), () => {
1002
1157
  for (const e of r) try {
1003
1158
  e.dispose();
1004
1159
  } catch {}
1005
1160
  };
1006
- }, [M, H]), Me = o(() => me ? null : h || C("div", {
1161
+ }, [M, P]), Me = o(() => ne ? null : y || C("div", {
1007
1162
  style: {
1008
1163
  position: "absolute",
1009
1164
  width: "100%",
1010
1165
  height: "100%"
1011
1166
  },
1012
- children: _("scriptEditor.loading")
1013
- }), [me, h]), De = o(() => ({
1014
- ...T,
1167
+ children: $("scriptEditor.loading")
1168
+ }), [ne, y]), Oe = o(() => ({
1169
+ ..._,
1015
1170
  fixedOverflowWidgets: !1,
1016
1171
  contextmenu: !1,
1017
- readOnly: m
1018
- }), [m]), Oe = i(null);
1172
+ readOnly: g
1173
+ }), [g]), Ie = i(null);
1019
1174
  r(() => {
1020
1175
  const e = {
1021
1176
  theme: f ? "extended-dark" : "extended",
1022
- options: De,
1023
- value: I(M)?.getSource() ?? "",
1024
- beforeMount: oe,
1025
- onValidate: ie
1177
+ options: Oe,
1178
+ value: V(M)?.getSource() ?? "",
1179
+ beforeMount: fe,
1180
+ onValidate: he
1026
1181
  }, t = ((e) => {
1027
- if (Z) return Z;
1028
- if (!F) {
1029
- F = {};
1030
- const e = W.length;
1182
+ if (se) return se;
1183
+ if (!B) {
1184
+ B = {};
1185
+ const e = K.length;
1031
1186
  for (let t = 0; t < e; t++) {
1032
- const e = W[t];
1033
- F[e] = globalThis[e];
1187
+ const e = K[t];
1188
+ B[e] = globalThis[e];
1034
1189
  }
1035
1190
  }
1036
1191
  const t = document.createElement("div");
@@ -1038,33 +1193,33 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1038
1193
  const n = document.createElement("div");
1039
1194
  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);
1040
1195
  const r = a(n);
1041
- return Z = {
1196
+ return se = {
1042
1197
  root: r,
1043
1198
  hostEl: n,
1044
1199
  stashEl: t,
1045
1200
  props: e,
1046
1201
  setProps: null
1047
- }, r.render(C(se, {})), Z;
1202
+ }, r.render(C(ye, {})), se;
1048
1203
  })(e);
1049
- return t.props = e, t.setProps?.(e), X = (e, t) => Le(e, t), Oe.current?.appendChild(t.hostEl), J && (Y = Le(J.editor, J.monaco)), () => {
1050
- Y?.(), Y = null, X = null, $.current = null, Z?.stashEl.appendChild(Z.hostEl);
1204
+ return t.props = e, t.setProps?.(e), ce = (e, t) => Le(e, t), Ie.current?.appendChild(t.hostEl), ae && (le = Le(ae.editor, ae.monaco)), () => {
1205
+ le?.(), le = null, ce = null, A.current = null, se?.stashEl.appendChild(se.hostEl);
1051
1206
  };
1052
1207
  }, []), r(() => {
1053
- if (!Z) return;
1208
+ if (!se) return;
1054
1209
  const e = {
1055
- ...Z.props,
1210
+ ...se.props,
1056
1211
  theme: f ? "extended-dark" : "extended",
1057
- options: De
1212
+ options: Oe
1058
1213
  };
1059
- Z.props = e, Z.setProps?.(e);
1060
- }, [f, De]), r(() => {
1061
- const e = $.current, t = e?.editor;
1214
+ se.props = e, se.setProps?.(e);
1215
+ }, [f, Oe]), r(() => {
1216
+ const e = A.current, t = e?.editor;
1062
1217
  if (!t) return;
1063
- ne.current = H ?? null;
1064
- const n = I(M)?.getSource() ?? "";
1065
- t.getValue() !== n && (t.setValue(n), be(t.getModel(), e.monaco, t), le({ dirty: !1 }));
1066
- }, [M, H]);
1067
- const Te = N("div", {
1218
+ me.current = P ?? null;
1219
+ const n = V(M)?.getSource() ?? "";
1220
+ t.getValue() !== n && (t.setValue(n), be(t.getModel(), e.monaco, t), J({ dirty: !1 }));
1221
+ }, [M, P]);
1222
+ const De = N("div", {
1068
1223
  style: {
1069
1224
  display: "flex",
1070
1225
  flex: "1 1 100%",
@@ -1074,7 +1229,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1074
1229
  boxSizing: "border-box"
1075
1230
  },
1076
1231
  children: [C("div", {
1077
- ref: Oe,
1232
+ ref: Ie,
1078
1233
  style: {
1079
1234
  display: "flex",
1080
1235
  flex: "1 1 100%",
@@ -1082,68 +1237,32 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1082
1237
  position: "relative"
1083
1238
  }
1084
1239
  }), Me]
1085
- }), Ae = k(t, () => ({
1240
+ }), $e = w(t, () => ({
1086
1241
  isScriptEditorElement: () => !0,
1087
1242
  showCommandPalette: () => {
1088
- $.current?.editor && $.current.editor.trigger("keyboard", "editor.action.quickCommand", null);
1243
+ A.current?.editor && A.current.editor.trigger("keyboard", "editor.action.quickCommand", null);
1089
1244
  },
1090
1245
  getScripts: () => M,
1091
1246
  focus: (e) => {
1092
- ve(e);
1247
+ ke(e);
1093
1248
  },
1094
- close: () => xe(),
1095
- insertSnippet: (e) => $.current?.editor ? (async (e, t, n) => {
1096
- const r = e.getModel();
1097
- if (!r) return;
1098
- const o = await (await (await t.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString()), i = e.getPosition();
1099
- let s = { ...i };
1100
- s.lineNumber = 1, s.column = 1;
1101
- let a = !1;
1102
- for (let e = i.lineNumber; e >= 1; e--) if ("" === r.getLineContent(e).trim()) {
1103
- const t = z(o, r.getOffsetAt({
1104
- lineNumber: e,
1105
- column: 1
1106
- }), "function");
1107
- if (!t || G(t)) {
1108
- a = !0, s.lineNumber = e + 1;
1109
- break;
1110
- }
1111
- {
1112
- const n = t.spans[0].start;
1113
- e = r.getPositionAt(n).lineNumber, s.lineNumber = e;
1114
- }
1115
- }
1116
- let c = n, l = !1;
1117
- !a && !c.startsWith("\n") && s.lineNumber > 1 && (c = "\n" + c, l = !0);
1118
- let u = !1;
1119
- r.getLineCount() > 1 && (c.endsWith("\n\n") || (c += "\n\n", u = !0));
1120
- const d = [{
1121
- range: new t.Range(s.lineNumber, s.column, s.lineNumber, s.column),
1122
- text: `${c}`
1123
- }];
1124
- let p = null;
1125
- r.pushEditOperations([], d, (e) => (p = e[0].range, l && p.startLineNumber++, u && p.endLineNumber--, [new t.Selection(p.startLineNumber, p.startColumn, p.endLineNumber, p.endColumn)])), e.setSelection({
1126
- startLineNumber: p.endLineNumber,
1127
- startColumn: p.endColumn,
1128
- endLineNumber: p.startLineNumber,
1129
- endColumn: p.startColumn
1130
- });
1131
- })($.current.editor, $.current.monaco, e) : Promise.resolve(),
1249
+ close: () => ve(),
1250
+ insertSnippet: (e) => A.current?.editor ? te(A.current.editor, A.current.monaco, e) : Promise.resolve(),
1132
1251
  saveSource: async () => {
1133
- await pe();
1252
+ await Y();
1134
1253
  },
1135
1254
  runAction: (e) => {
1136
- const t = $.current?.editor;
1255
+ const t = A.current?.editor;
1137
1256
  t && (t.focus(), t.trigger("source", e, null));
1138
1257
  },
1139
1258
  copy: () => Se(),
1140
1259
  cut: () => Ce(),
1141
1260
  paste: () => Ne()
1142
- }), [H]), [Re, Ie] = s(null), Fe = b((e) => {
1143
- null !== e && Ie(e);
1144
- }, []), Pe = y.useCommandScope();
1145
- return r(() => {
1146
- if (!Pe || !Re) return;
1261
+ }), [P]), [Ae, Re] = s(null), Te = b((e) => {
1262
+ null !== e && Re(e);
1263
+ }, []), Pe = h.useCommandScope();
1264
+ r(() => {
1265
+ if (!Pe || !Ae) return;
1147
1266
  const e = Pe.contribution();
1148
1267
  return function(e, t) {
1149
1268
  const n = t.scriptEditor, r = t;
@@ -1152,36 +1271,38 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1152
1271
  } }), e.updateCommand("showScriptingCommands", { callback: () => {
1153
1272
  n.showCommandPalette();
1154
1273
  } });
1155
- const o = r?.readOnly ? [g("reason.scriptsReadOnly")] : [];
1274
+ const o = r?.readOnly ? [m("reason.scriptsReadOnly")] : [];
1156
1275
  e.updateCommand("insertScript", {
1157
1276
  disabledReasons: o,
1158
1277
  callback: (e) => n.insertSnippet(e ?? "")
1159
1278
  }), e.updateCommand("saveScripts", {
1160
- disabledReasons: [...o, ...r?.isDirty ? [] : [g("reason.noChangesToSave")]],
1279
+ disabledReasons: [...o, ...r?.isDirty ? [] : [m("reason.noChangesToSave")]],
1161
1280
  callback: async () => {
1162
1281
  await n.saveSource();
1163
1282
  }
1164
1283
  }), 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") });
1165
1284
  }(e, {
1166
- scriptEditor: Re,
1167
- isDirty: B,
1168
- readOnly: m
1285
+ scriptEditor: Ae,
1286
+ isDirty: R,
1287
+ readOnly: g
1169
1288
  }), () => {
1170
1289
  e.remove();
1171
1290
  };
1172
1291
  }, [
1173
1292
  Pe,
1174
- Re,
1175
- B,
1176
- m
1177
- ]), r(() => (x && requestAnimationFrame(() => {
1178
- Ae.current?.focus();
1293
+ Ae,
1294
+ R,
1295
+ g
1296
+ ]), r(() => (v && requestAnimationFrame(() => {
1297
+ $e.current?.focus();
1179
1298
  }), () => {
1180
- $.current?.editor && requestAnimationFrame(() => {
1181
- Ae.current?.contains(document.activeElement) && Ae.current?.focus();
1299
+ A.current?.editor && requestAnimationFrame(() => {
1300
+ $e.current?.contains(document.activeElement) && $e.current?.focus();
1182
1301
  });
1183
- }), []), C("div", {
1184
- className: c("script-editor", A, n),
1302
+ }), []);
1303
+ const Fe = l([$e, Te]);
1304
+ return C("div", {
1305
+ className: c("script-editor", W, n),
1185
1306
  style: {
1186
1307
  display: "flex",
1187
1308
  flexDirection: "row",
@@ -1189,20 +1310,23 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1189
1310
  position: "relative",
1190
1311
  ...p
1191
1312
  },
1192
- ref: l([Ae, Fe]),
1193
- ...P,
1194
- children: Te
1313
+ ref: Fe,
1314
+ ...D,
1315
+ children: De
1195
1316
  });
1196
- })), ce = null, le = (e) => {
1197
- ce = e;
1198
- }, ue = () => ce, de = n((e) => {
1199
- const { scope: t, data: n } = e, { workbook: o } = n, i = v(), s = M(), a = s.getOpen(), c = b(async (e) => {
1317
+ })), xe = null, we = (e) => {
1318
+ xe = e;
1319
+ }, ve = () => xe, ke = n((e) => {
1320
+ const { scope: t, data: n } = e, { workbook: o } = n, i = k(), s = M(), a = s.getOpen(), c = b(async (e) => {
1200
1321
  if (!o) return;
1201
1322
  let t = null;
1202
1323
  const n = o.getScripts();
1203
1324
  if (e?.declaration || e?.functionName) {
1204
1325
  const r = e.declaration ? e.declaration.getName() : e.functionName;
1205
- (await n.searchFunctions({ name: r })).length > 0 && (t = r);
1326
+ (await n.searchFunctions({
1327
+ name: r,
1328
+ includeHidden: !0
1329
+ })).length > 0 && (t = r);
1206
1330
  }
1207
1331
  if (t) try {
1208
1332
  await n.executeMacro(t);
@@ -1211,7 +1335,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1211
1335
  return;
1212
1336
  }
1213
1337
  }, [o, i]), l = b(() => {
1214
- const e = ue();
1338
+ const e = ve();
1215
1339
  e ? o && e({ workbook: o }) : s.getOpen().includes("scriptEditor") ? s.close("scriptEditor") : s.activate("scriptEditor", {});
1216
1340
  }, [o, s]), u = a.includes("scriptEditor");
1217
1341
  return r(() => {
@@ -1235,8 +1359,8 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
1235
1359
  o?.getScripts().start();
1236
1360
  } }), null;
1237
1361
  });
1238
- de.displayName = "WorkbookScriptCommands";
1239
- var pe = {
1362
+ ke.displayName = "WorkbookScriptCommands";
1363
+ var Se = {
1240
1364
  "reason.noChangesToSave": "No changes to save",
1241
1365
  "reason.scriptsReadOnly": "Scripts can't be changed while the workbook structure is protected.",
1242
1366
  "scriptEditor.glyph.autoRun": "Auto Run",
@@ -1245,7 +1369,7 @@ var pe = {
1245
1369
  "scriptEditor.loading": "Loading...",
1246
1370
  "scriptEditor.retry": "Retry",
1247
1371
  "scriptEditor.saving": "Saving Scripts..."
1248
- }, ge = [
1372
+ }, Ce = [
1249
1373
  {
1250
1374
  sourceId: "groups",
1251
1375
  catalog: {
@@ -1327,30 +1451,28 @@ var pe = {
1327
1451
  }
1328
1452
  }
1329
1453
  }
1330
- ], { DefaultCommandCatalogService: me } = y, fe = !1;
1331
- var ye = (e) => {
1454
+ ], { DefaultCommandCatalogService: Ne } = h, Ee = !1;
1455
+ var Le = (e) => {
1332
1456
  const { model: t, entryKey: n, frame: r, ref: o, ...i } = e;
1333
- return C(ae, {
1457
+ return C(be, {
1334
1458
  ref: o,
1335
1459
  frame: r,
1336
1460
  scripts: t?.getScripts(),
1337
1461
  ...i
1338
1462
  });
1339
- }, he = () => {
1463
+ }, Me = () => {
1340
1464
  E.registerTaskPane({
1341
1465
  key: "scriptEditor",
1342
- getTitle: () => "Script (Typescript)",
1343
- getIcon: () => "ScriptRun",
1344
- component: ye,
1466
+ component: Le,
1345
1467
  keepMounted: !0
1346
1468
  }, !0), function() {
1347
- if (fe) return;
1348
- fe = !0;
1349
- const e = me;
1469
+ if (Ee) return;
1470
+ Ee = !0;
1471
+ const e = Ne;
1350
1472
  e.registerFromManifest("@sheetxl/scripting-react", import.meta.url, {
1351
- messages: pe,
1352
- catalogs: ge
1473
+ messages: Se,
1474
+ catalogs: Ce
1353
1475
  }), e.prefetch();
1354
- }(), y.DefaultCommandRegistry.registerDynamic("workbook", de);
1476
+ }(), h.DefaultCommandRegistry.registerDynamic("workbook", ke);
1355
1477
  };
1356
- export { ae as ScriptEditor, he as ScriptingReactPlugin, de as WorkbookScriptCommands, ue as getScriptEditorOpener, le as setScriptEditorOpener };
1478
+ export { be as ScriptEditor, Me as ScriptingReactPlugin, ke as WorkbookScriptCommands, ve as getScriptEditorOpener, we as setScriptEditorOpener };