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