@sheetxl/scripting-react 0.8.0-beta.6 → 0.8.0-beta.9
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/cjs/index.cjs +14 -6
- package/browser/esm/{YXpKDjWeV_dzuLi0.mjs → BXlrgubW-qeWL1qE.mjs} +1 -1
- package/browser/esm/{EkOdjbs09ctosVEA.mjs → Dgz3ELF6JC8TSoik.mjs} +1 -1
- package/browser/esm/{L6x0JuXd7qiDfvFz.mjs → VaLQTrxEVp8TVw2t.mjs} +2 -2
- package/browser/esm/index.mjs +359 -238
- package/node/esm/index.mjs +358 -234
- package/package.json +7 -6
- package/types/src/mergeImports.d.ts +64 -0
package/node/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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.9
|
|
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.
|
|
@@ -8,13 +8,13 @@ import { Suspense as e, forwardRef as t, memo as n, useEffect as r, useMemo as o
|
|
|
8
8
|
import { createRoot as a } from "react-dom/client";
|
|
9
9
|
import c from "clsx";
|
|
10
10
|
import { mergeRefs as l } from "react-merge-refs";
|
|
11
|
-
import { CommonUtils as u, TimerUtils as d, defineLazyModule as p, messageKey as
|
|
12
|
-
import { DocTags as
|
|
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
|
|
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
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
|
|
17
|
-
var
|
|
16
|
+
import { DefaultTaskPaneRegistry as E, useModelListener as L, useTaskPaneArea as M, useWorkbook as O } from "@sheetxl/react";
|
|
17
|
+
var D = {
|
|
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
|
+
}, 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
|
+
}, _ = {
|
|
359
401
|
lightbulb: { enabled: !1 },
|
|
360
402
|
tabSize: 2,
|
|
361
403
|
acceptSuggestionOnCommitCharacter: !0,
|
|
@@ -418,11 +460,11 @@ var O = {
|
|
|
418
460
|
wordWrapColumn: 80,
|
|
419
461
|
wordWrapMinified: !0,
|
|
420
462
|
wrappingIndent: "none"
|
|
421
|
-
},
|
|
463
|
+
}, W = "_script-editor_1kuph_5", V = (e) => {
|
|
422
464
|
const t = e?.getModules();
|
|
423
465
|
return t ? (t.getByName(f.DEFAULT_MODULE), f.DEFAULT_MODULE) : f.DEFAULT_MODULE;
|
|
424
|
-
},
|
|
425
|
-
var
|
|
466
|
+
}, j = (e) => e?.getModules()?.getByName(V(e)) ?? null;
|
|
467
|
+
var B, U = p("scripting-react:monaco", async () => (function() {
|
|
426
468
|
if ("undefined" == typeof window) return;
|
|
427
469
|
const e = window;
|
|
428
470
|
if (e.__sxlDefineShim) return;
|
|
@@ -442,8 +484,8 @@ var F, P = p("scripting-react:monaco", async () => (function() {
|
|
|
442
484
|
} catch {}
|
|
443
485
|
}
|
|
444
486
|
});
|
|
445
|
-
}(), import("@monaco-editor/react")), { prefetch: !1 }),
|
|
446
|
-
const t =
|
|
487
|
+
}(), import("@monaco-editor/react")), { prefetch: !1 }), H = ({ error: e }) => {
|
|
488
|
+
const t = k(), n = S();
|
|
447
489
|
return N("div", {
|
|
448
490
|
style: {
|
|
449
491
|
display: "flex",
|
|
@@ -459,14 +501,132 @@ var F, P = p("scripting-react:monaco", async () => (function() {
|
|
|
459
501
|
children: n("scriptEditor.retry")
|
|
460
502
|
}) : null]
|
|
461
503
|
});
|
|
462
|
-
},
|
|
463
|
-
"@local" !==
|
|
464
|
-
var
|
|
504
|
+
}, q = h(U.load, { renderError: (e) => C(H, { error: e }) }), K = ["define", "require"], z = !1, G = "@0.8.0-beta.9";
|
|
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) => {
|
|
465
507
|
try {
|
|
466
|
-
e.languages.setMonarchTokensProvider("typescript",
|
|
508
|
+
e.languages.setMonarchTokensProvider("typescript", D);
|
|
467
509
|
} catch (e) {}
|
|
468
|
-
},
|
|
469
|
-
|
|
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) {
|
|
470
630
|
let n = null;
|
|
471
631
|
const r = e.length;
|
|
472
632
|
for (let o = 0; !n && o < r; o++) {
|
|
@@ -475,48 +635,48 @@ function K(e, t) {
|
|
|
475
635
|
}
|
|
476
636
|
return n ? n.getContext() : "formula";
|
|
477
637
|
}
|
|
478
|
-
function
|
|
638
|
+
function ee(e, t, n, r, o = []) {
|
|
479
639
|
if ("function" === r.kind && "export" === r.kindModifiers) {
|
|
480
640
|
const t = r.spans[0].start, i = e.getPositionAt(t);
|
|
481
641
|
o.push({
|
|
482
642
|
name: r.text,
|
|
483
|
-
type:
|
|
643
|
+
type: Q(n, r),
|
|
484
644
|
lineNumber: i.lineNumber
|
|
485
645
|
});
|
|
486
646
|
}
|
|
487
|
-
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);
|
|
488
648
|
return o;
|
|
489
649
|
}
|
|
490
|
-
function
|
|
650
|
+
function te(e, t, n = "function", r) {
|
|
491
651
|
const o = e.spans, i = o.length;
|
|
492
652
|
for (let s = 0; s < i; s++) {
|
|
493
653
|
const i = o[s];
|
|
494
654
|
if (i.start <= t && t < i.start + i.length) {
|
|
495
655
|
if (e.kind === n && (!r || e.kindModifiers === r)) return e;
|
|
496
656
|
for (const o of e.childItems || []) {
|
|
497
|
-
const e =
|
|
657
|
+
const e = te(o, t, n, r);
|
|
498
658
|
if (e) return e;
|
|
499
659
|
}
|
|
500
660
|
}
|
|
501
661
|
return null;
|
|
502
662
|
}
|
|
503
663
|
}
|
|
504
|
-
function
|
|
664
|
+
function ne(e) {
|
|
505
665
|
return "comment" === e.kind;
|
|
506
666
|
}
|
|
507
|
-
var
|
|
508
|
-
|
|
667
|
+
var re = null, oe = null, ie = null, se = null, ae = !1, ce = !1, le = !1, ue = { current: null }, de = (e, t) => {
|
|
668
|
+
oe = {
|
|
509
669
|
editor: e,
|
|
510
670
|
monaco: t
|
|
511
|
-
},
|
|
512
|
-
},
|
|
513
|
-
if (
|
|
514
|
-
|
|
671
|
+
}, ie && (se = ie(e, t));
|
|
672
|
+
}, pe = (e) => {
|
|
673
|
+
if (le) return;
|
|
674
|
+
le = !0, e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
|
|
515
675
|
noSemanticValidation: !0,
|
|
516
676
|
noSyntaxValidation: !1,
|
|
517
677
|
diagnosticCodesToIgnore: [2307]
|
|
518
|
-
}), e.languages.typescript.typescriptDefaults.setEagerModelSync(!0), e.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: !0 }),
|
|
519
|
-
|
|
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", {
|
|
520
680
|
triggerCharacters: ["@"],
|
|
521
681
|
provideCompletionItems: (t, n) => {
|
|
522
682
|
const r = t.getValueInRange({
|
|
@@ -535,7 +695,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
535
695
|
return n.lastIndexOf("/*") > n.lastIndexOf("*/");
|
|
536
696
|
})(t, n)) return { suggestions: [] };
|
|
537
697
|
const i = o[1], s = new e.Range(n.lineNumber, n.column - i.length, n.lineNumber, n.column);
|
|
538
|
-
return { suggestions:
|
|
698
|
+
return { suggestions: g.map((t) => ({
|
|
539
699
|
label: `@${t.name}`,
|
|
540
700
|
kind: e.languages.CompletionItemKind.Keyword,
|
|
541
701
|
detail: "sheetxl" === t.group ? "SheetXL" : "JSDoc",
|
|
@@ -594,7 +754,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
594
754
|
(async () => {
|
|
595
755
|
let t = !1;
|
|
596
756
|
try {
|
|
597
|
-
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");
|
|
598
758
|
let o = e.editor.getModel(r);
|
|
599
759
|
o ? t = !0 : o = e.editor.createModel(n, "typescript", r), e.editor.setModelMarkers(o, "default", []);
|
|
600
760
|
} catch (e) {
|
|
@@ -611,10 +771,10 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
611
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);
|
|
612
772
|
const p = d[0];
|
|
613
773
|
"`" !== p && "'" !== p && "\"" !== p || (c++, d = d.substring(1));
|
|
614
|
-
const
|
|
615
|
-
"`" !==
|
|
774
|
+
const m = d[d.length - 1];
|
|
775
|
+
"`" !== m && "'" !== m && "\"" !== m || (c++, d = d.substring(0, d.length - 1));
|
|
616
776
|
try {
|
|
617
|
-
|
|
777
|
+
ue.current?.getRanges(d) && r.push({
|
|
618
778
|
range: {
|
|
619
779
|
endColumn: l,
|
|
620
780
|
endLineNumber: n,
|
|
@@ -632,7 +792,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
632
792
|
} }), e.editor.registerLinkOpener({ open(e) {
|
|
633
793
|
if (e?.path?.startsWith("/range/")) {
|
|
634
794
|
try {
|
|
635
|
-
|
|
795
|
+
ue.current?.getRanges(e.path.substring(7))?.select();
|
|
636
796
|
} catch (e) {
|
|
637
797
|
console.warn("invalid range", e);
|
|
638
798
|
}
|
|
@@ -667,14 +827,14 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
667
827
|
})();
|
|
668
828
|
}
|
|
669
829
|
})();
|
|
670
|
-
},
|
|
830
|
+
}, me = (e) => {
|
|
671
831
|
let t = !1;
|
|
672
832
|
const n = e ? e.length : 0;
|
|
673
833
|
for (let r = 0; !t && r < n; r++) 8 === e[r].severity && (t = !0);
|
|
674
|
-
},
|
|
675
|
-
const [t, n] = s(() =>
|
|
676
|
-
return r(() => (
|
|
677
|
-
|
|
834
|
+
}, ge = () => {
|
|
835
|
+
const [t, n] = s(() => re.props);
|
|
836
|
+
return r(() => (re && (re.setProps = n), () => {
|
|
837
|
+
re && (re.setProps = null);
|
|
678
838
|
}), []), C("div", {
|
|
679
839
|
style: {
|
|
680
840
|
display: "flex",
|
|
@@ -682,75 +842,75 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
682
842
|
width: "100%",
|
|
683
843
|
height: "100%"
|
|
684
844
|
},
|
|
685
|
-
children: C(e, { children: C(
|
|
845
|
+
children: C(e, { children: C(q, {
|
|
686
846
|
theme: t.theme,
|
|
687
847
|
options: t.options,
|
|
688
848
|
language: "typescript",
|
|
689
849
|
value: t.value,
|
|
690
850
|
onValidate: t.onValidate,
|
|
691
851
|
beforeMount: t.beforeMount,
|
|
692
|
-
onMount:
|
|
852
|
+
onMount: de
|
|
693
853
|
}) })
|
|
694
854
|
});
|
|
695
|
-
},
|
|
696
|
-
const { className: n, style: p, readOnly:
|
|
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"]), [U, H] = s({
|
|
697
857
|
message: "Loading",
|
|
698
858
|
cursor: "",
|
|
699
859
|
dirty: !1
|
|
700
|
-
}), [
|
|
860
|
+
}), [q, G] = s({
|
|
701
861
|
loading: !1,
|
|
702
862
|
compiling: !1,
|
|
703
863
|
errors: [],
|
|
704
864
|
warnings: []
|
|
705
|
-
}),
|
|
706
|
-
|
|
865
|
+
}), Z = b((e) => {
|
|
866
|
+
H((t) => {
|
|
707
867
|
const n = {
|
|
708
868
|
...t,
|
|
709
869
|
...e
|
|
710
870
|
};
|
|
711
|
-
return u.deepEqual(n, t) ? t : (
|
|
871
|
+
return u.deepEqual(n, t) ? t : (R(n.dirty ?? !1), n);
|
|
712
872
|
});
|
|
713
|
-
}, [
|
|
873
|
+
}, [D]);
|
|
714
874
|
r(() => {
|
|
715
|
-
|
|
716
|
-
}, [
|
|
717
|
-
const
|
|
875
|
+
D?.(U);
|
|
876
|
+
}, [D, U]);
|
|
877
|
+
const X = v(), Q = b(async (e) => {
|
|
718
878
|
let t = null, n = null;
|
|
719
879
|
try {
|
|
720
|
-
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?.();
|
|
721
881
|
} catch (e) {
|
|
722
|
-
n?.(), console.warn("Unable to compile", e),
|
|
882
|
+
n?.(), console.warn("Unable to compile", e), X.showError(e);
|
|
723
883
|
}
|
|
724
884
|
return t;
|
|
725
|
-
}, [M]),
|
|
726
|
-
if (
|
|
727
|
-
const e =
|
|
885
|
+
}, [M]), ne = b(async () => {
|
|
886
|
+
if (!A.current || g) return;
|
|
887
|
+
const e = A.current.editor;
|
|
728
888
|
let t;
|
|
729
|
-
if (
|
|
889
|
+
if (U.dirty) {
|
|
730
890
|
const n = e.getValue();
|
|
731
|
-
await
|
|
891
|
+
await Q(n), t = j(M);
|
|
732
892
|
const r = t?.getSource(), o = e.getValue(), i = (r?.length ?? 0) !== n.length || r !== o;
|
|
733
|
-
|
|
734
|
-
} else t =
|
|
893
|
+
Z({ dirty: i });
|
|
894
|
+
} else t = j(M);
|
|
735
895
|
return t;
|
|
736
|
-
}, [
|
|
896
|
+
}, [U, M]);
|
|
737
897
|
r(() => {
|
|
738
|
-
const e = E?.addListener({ onBeforeHide: async () => (await
|
|
898
|
+
const e = E?.addListener({ onBeforeHide: async () => (await ne(), !0) });
|
|
739
899
|
return () => {
|
|
740
900
|
e?.();
|
|
741
901
|
};
|
|
742
902
|
}, [E]), r(() => {
|
|
743
|
-
if (M) return M.addListeners({ onBeforeSearch: () =>
|
|
744
|
-
}, [M]), L(
|
|
903
|
+
if (M) return M.addListeners({ onBeforeSearch: () => ne() });
|
|
904
|
+
}, [M]), L(F, {
|
|
745
905
|
onBeforeSave: async () => {
|
|
746
|
-
await
|
|
906
|
+
await ne();
|
|
747
907
|
},
|
|
748
908
|
onLoad: () => {
|
|
749
|
-
const e =
|
|
750
|
-
e && e.setValue(
|
|
909
|
+
const e = A.current?.editor;
|
|
910
|
+
e && e.setValue(j(M)?.getSource() ?? "");
|
|
751
911
|
}
|
|
752
912
|
});
|
|
753
|
-
const
|
|
913
|
+
const le = b(async (e) => {
|
|
754
914
|
if (!M) return;
|
|
755
915
|
const t = "string" == typeof e ? { functionName: e } : e ?? {};
|
|
756
916
|
let n = null;
|
|
@@ -761,11 +921,11 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
761
921
|
if (n) try {
|
|
762
922
|
await M.executeMacro(n);
|
|
763
923
|
} catch (e) {
|
|
764
|
-
|
|
924
|
+
X.showError(e);
|
|
765
925
|
}
|
|
766
|
-
}, [M,
|
|
767
|
-
if (
|
|
768
|
-
const e =
|
|
926
|
+
}, [M, X]), [de, fe] = s(!1), ye = b(async () => {
|
|
927
|
+
if (!A.current) return null;
|
|
928
|
+
const e = A.current, t = e.editor;
|
|
769
929
|
if (!t) return null;
|
|
770
930
|
const r = await (async (e, t, n = "export") => {
|
|
771
931
|
const r = e.getModel();
|
|
@@ -775,7 +935,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
775
935
|
if (!s) return null;
|
|
776
936
|
const a = s.startLineNumber === s.endLineNumber && s.startColumn === s.endColumn ? r.getLineCount() : Math.min(s.endLineNumber, r.getLineCount());
|
|
777
937
|
for (let e = s.startLineNumber; !i && e <= a; e++) {
|
|
778
|
-
const t =
|
|
938
|
+
const t = te(o, r.getOffsetAt({
|
|
779
939
|
lineNumber: e,
|
|
780
940
|
column: 1
|
|
781
941
|
}), "function", n);
|
|
@@ -783,14 +943,14 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
783
943
|
}
|
|
784
944
|
return i;
|
|
785
945
|
})(t, e.monaco);
|
|
786
|
-
return
|
|
946
|
+
return Z({ message: (r ?? "").toUpperCase() }), r ? {
|
|
787
947
|
source: t.getValue(),
|
|
788
948
|
name: r
|
|
789
949
|
} : null;
|
|
790
950
|
}, []);
|
|
791
|
-
b(d.debounce(
|
|
951
|
+
b(d.debounce(ne, 200), []);
|
|
792
952
|
const he = b(async (e, t, n) => {
|
|
793
|
-
|
|
953
|
+
G((e) => ({
|
|
794
954
|
...e,
|
|
795
955
|
compiling: !0
|
|
796
956
|
}));
|
|
@@ -817,9 +977,9 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
817
977
|
});
|
|
818
978
|
t.editor.setModelMarkers(e, "sheetxl", r);
|
|
819
979
|
})(e, t, o), async function(e, t, n, r) {
|
|
820
|
-
const o =
|
|
980
|
+
const o = ee(e, t, r, await (await (await t.languages.typescript.getTypeScriptWorker())(e.uri)).getNavigationTree(e.uri.toString())).map((e) => {
|
|
821
981
|
let n = null, r = null;
|
|
822
|
-
return "formula" === e.type ? (n = "formula.margin-icon", r =
|
|
982
|
+
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
983
|
range: new t.Range(e.lineNumber, 1, e.lineNumber, 1),
|
|
824
984
|
options: {
|
|
825
985
|
isWholeLine: !1,
|
|
@@ -830,32 +990,32 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
830
990
|
};
|
|
831
991
|
});
|
|
832
992
|
Ee.current && Ee.current.clear(), Ee.current = n.createDecorationsCollection(o);
|
|
833
|
-
}(e, t, n, r ? r.getFunctions().getItems() : u.EmptyArray),
|
|
993
|
+
}(e, t, n, r ? r.getFunctions().getItems() : u.EmptyArray), G((e) => ({
|
|
834
994
|
...e,
|
|
835
995
|
compiling: !1,
|
|
836
996
|
errors: o.filter((e) => "error" === e.severity).map((e) => `${e.code}: ${e.message}`),
|
|
837
997
|
warnings: o.filter((e) => "warning" === e.severity).map((e) => `${e.code}: ${e.message}`)
|
|
838
998
|
}));
|
|
839
|
-
}, [M]), be = b(d.debounce(he, 580), []),
|
|
840
|
-
if (
|
|
841
|
-
const t =
|
|
842
|
-
void 0 !== e && (n.message = e),
|
|
999
|
+
}, [M]), be = b(d.debounce(he, 580), []), xe = b(async (e) => {
|
|
1000
|
+
if (!A.current) return;
|
|
1001
|
+
const t = A.current.editor.getPosition(), n = { cursor: t ? t.toString() : "" };
|
|
1002
|
+
void 0 !== e && (n.message = e), Z(n);
|
|
843
1003
|
}, []);
|
|
844
|
-
r(() => {}, [
|
|
845
|
-
const
|
|
846
|
-
await
|
|
1004
|
+
r(() => {}, [q]);
|
|
1005
|
+
const we = i(null), ke = b(async () => {
|
|
1006
|
+
await ne(), E?.close();
|
|
847
1007
|
}, [E]), ve = b((e) => {
|
|
848
|
-
const t =
|
|
1008
|
+
const t = A.current?.editor;
|
|
849
1009
|
return !!t && (t.focus(e), !0);
|
|
850
|
-
}, [
|
|
851
|
-
const e =
|
|
1010
|
+
}, [U]), Se = b(async () => {
|
|
1011
|
+
const e = A.current?.editor, t = e?.getModel(), n = e?.getSelection();
|
|
852
1012
|
if (!t || !n) return;
|
|
853
1013
|
const r = n.isEmpty() ? t.getLineContent(n.positionLineNumber) + "\n" : t.getValueInRange(n);
|
|
854
1014
|
try {
|
|
855
1015
|
await navigator.clipboard?.writeText(r);
|
|
856
1016
|
} catch {}
|
|
857
1017
|
}, []), Ce = b(async () => {
|
|
858
|
-
const e =
|
|
1018
|
+
const e = A.current, t = e?.editor, n = t?.getModel(), r = t?.getSelection();
|
|
859
1019
|
if (!n || !r) return;
|
|
860
1020
|
const o = r.isEmpty() ? new e.monaco.Range(r.positionLineNumber, 1, r.positionLineNumber + 1, 1) : r, i = n.getValueInRange(o);
|
|
861
1021
|
try {
|
|
@@ -869,7 +1029,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
869
1029
|
forceMoveMarkers: !0
|
|
870
1030
|
}]), t.pushUndoStop(), t.focus();
|
|
871
1031
|
}, []), Ne = b(async () => {
|
|
872
|
-
const e =
|
|
1032
|
+
const e = A.current?.editor;
|
|
873
1033
|
if (!e) return;
|
|
874
1034
|
let t;
|
|
875
1035
|
try {
|
|
@@ -885,15 +1045,15 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
885
1045
|
forceMoveMarkers: !0
|
|
886
1046
|
}]), e.pushUndoStop(), e.focus();
|
|
887
1047
|
}, []), Ee = i(null), Le = b((e, t) => {
|
|
888
|
-
|
|
1048
|
+
A.current = {
|
|
889
1049
|
monaco: t,
|
|
890
1050
|
editor: e
|
|
891
|
-
},
|
|
1051
|
+
}, ue.current = F ?? null;
|
|
892
1052
|
const n = e.getModel(), r = [];
|
|
893
1053
|
fe(!0);
|
|
894
|
-
const o =
|
|
895
|
-
return e.getValue() !== o && e.setValue(o),
|
|
896
|
-
|
|
1054
|
+
const o = j(M)?.getSource() ?? "";
|
|
1055
|
+
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) => {
|
|
1056
|
+
xe(""), n.AutoTypings.create(e, {
|
|
897
1057
|
shareCache: !0,
|
|
898
1058
|
dontAdaptEditorOptions: !0,
|
|
899
1059
|
monaco: t,
|
|
@@ -910,8 +1070,8 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
910
1070
|
"Not implemented yet" === e && (e = "Compile Errors"), console.warn("Error compiling types", e);
|
|
911
1071
|
}
|
|
912
1072
|
}).then((n) => {
|
|
913
|
-
|
|
914
|
-
if (
|
|
1073
|
+
we.current = n, be(e.getModel(), t, e), (() => {
|
|
1074
|
+
if (z) return;
|
|
915
1075
|
const e = (e, t) => {
|
|
916
1076
|
try {
|
|
917
1077
|
if (void 0 === t) try {
|
|
@@ -923,17 +1083,17 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
923
1083
|
}
|
|
924
1084
|
else globalThis[e] = t;
|
|
925
1085
|
} catch (e) {}
|
|
926
|
-
}, t =
|
|
1086
|
+
}, t = K.length;
|
|
927
1087
|
for (let n = 0; n < t; n++) {
|
|
928
|
-
const t =
|
|
929
|
-
e(t,
|
|
1088
|
+
const t = K[n];
|
|
1089
|
+
e(t, B[t]);
|
|
930
1090
|
}
|
|
931
|
-
|
|
932
|
-
})(),
|
|
1091
|
+
B = void 0, z = !0;
|
|
1092
|
+
})(), J(t);
|
|
933
1093
|
});
|
|
934
1094
|
}).catch((e) => {
|
|
935
|
-
|
|
936
|
-
})),
|
|
1095
|
+
ae = !1, xe(""), console.warn("Auto typings could not be loaded:", e);
|
|
1096
|
+
})), ce || (ce = !0, function(e, t) {
|
|
937
1097
|
t.languages.registerInlayHintsProvider("typescript", { provideInlayHints(e, n, r) {
|
|
938
1098
|
const o = [];
|
|
939
1099
|
for (let n = 1; n < e.getLineCount() + 1; n++) {
|
|
@@ -963,74 +1123,74 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
963
1123
|
keybindings: [t.KeyCode.F8],
|
|
964
1124
|
run: async (e) => {
|
|
965
1125
|
const t = await ye();
|
|
966
|
-
|
|
1126
|
+
le(t);
|
|
967
1127
|
}
|
|
968
1128
|
})), r.push(e.addAction({
|
|
969
1129
|
id: "saveScript",
|
|
970
1130
|
label: "Save Script",
|
|
971
1131
|
keybindings: [t.KeyMod.CtrlCmd | t.KeyCode.KeyS],
|
|
972
1132
|
run: (e) => {
|
|
973
|
-
|
|
1133
|
+
ne();
|
|
974
1134
|
}
|
|
975
1135
|
})), r.push(e.onMouseDown(async (e) => {
|
|
976
1136
|
if (e.target.type === t.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
|
|
977
1137
|
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
|
|
1138
|
+
const r = e.target.position.lineNumber, o = await (await (await t.languages.typescript.getTypeScriptWorker())(n.uri)).getNavigationTree(n.uri.toString()), i = await ne();
|
|
979
1139
|
if (!i) return;
|
|
980
|
-
const s = i.getFunctions().getItems(), a =
|
|
1140
|
+
const s = i.getFunctions().getItems(), a = ee(n, t, s, o).find((e) => e.lineNumber === r);
|
|
981
1141
|
if (a) {
|
|
982
1142
|
const t = e.event.browserEvent.button;
|
|
983
1143
|
if (0 === t) {
|
|
984
|
-
if ("macro" === a.type || "autoRun" === a.type)
|
|
1144
|
+
if ("macro" === a.type || "autoRun" === a.type) le({ functionName: a.name });
|
|
985
1145
|
else if ("formula" === a.type) {
|
|
986
1146
|
const e = s?.find((e) => e.getName() === a.name);
|
|
987
|
-
e &&
|
|
1147
|
+
e && P?.execute(e);
|
|
988
1148
|
}
|
|
989
1149
|
} else 2 === t && (console.log("Context menu for function:", a.name), e.event.browserEvent.preventDefault());
|
|
990
1150
|
}
|
|
991
1151
|
}
|
|
992
1152
|
})), r.push(e.onDidChangeModelContent(() => {
|
|
993
|
-
|
|
1153
|
+
Z({ dirty: !0 }), be(n, t, e);
|
|
994
1154
|
})), r.push(t.editor.onDidChangeMarkers((e) => {
|
|
995
1155
|
e.some((e) => e.toString() === n.uri.toString());
|
|
996
1156
|
})), r.push(n.onDidChangeContent((t) => {
|
|
997
|
-
const n =
|
|
998
|
-
|
|
1157
|
+
const n = j(M)?.getSource(), r = e.getValue(), o = (n?.length ?? 0) !== r.length || n !== r;
|
|
1158
|
+
Z({ dirty: o });
|
|
999
1159
|
})), r.push(e.onDidChangeCursorPosition((e) => {
|
|
1000
|
-
|
|
1160
|
+
xe();
|
|
1001
1161
|
})), () => {
|
|
1002
1162
|
for (const e of r) try {
|
|
1003
1163
|
e.dispose();
|
|
1004
1164
|
} catch {}
|
|
1005
1165
|
};
|
|
1006
|
-
}, [M,
|
|
1166
|
+
}, [M, F]), Me = o(() => de ? null : h || C("div", {
|
|
1007
1167
|
style: {
|
|
1008
1168
|
position: "absolute",
|
|
1009
1169
|
width: "100%",
|
|
1010
1170
|
height: "100%"
|
|
1011
1171
|
},
|
|
1012
|
-
children:
|
|
1013
|
-
}), [
|
|
1014
|
-
...
|
|
1172
|
+
children: $("scriptEditor.loading")
|
|
1173
|
+
}), [de, h]), Oe = o(() => ({
|
|
1174
|
+
..._,
|
|
1015
1175
|
fixedOverflowWidgets: !1,
|
|
1016
1176
|
contextmenu: !1,
|
|
1017
|
-
readOnly:
|
|
1018
|
-
}), [
|
|
1177
|
+
readOnly: g
|
|
1178
|
+
}), [g]), De = i(null);
|
|
1019
1179
|
r(() => {
|
|
1020
1180
|
const e = {
|
|
1021
1181
|
theme: f ? "extended-dark" : "extended",
|
|
1022
|
-
options:
|
|
1023
|
-
value:
|
|
1024
|
-
beforeMount:
|
|
1025
|
-
onValidate:
|
|
1182
|
+
options: Oe,
|
|
1183
|
+
value: j(M)?.getSource() ?? "",
|
|
1184
|
+
beforeMount: pe,
|
|
1185
|
+
onValidate: me
|
|
1026
1186
|
}, t = ((e) => {
|
|
1027
|
-
if (
|
|
1028
|
-
if (!
|
|
1029
|
-
|
|
1030
|
-
const e =
|
|
1187
|
+
if (re) return re;
|
|
1188
|
+
if (!B) {
|
|
1189
|
+
B = {};
|
|
1190
|
+
const e = K.length;
|
|
1031
1191
|
for (let t = 0; t < e; t++) {
|
|
1032
|
-
const e =
|
|
1033
|
-
|
|
1192
|
+
const e = K[t];
|
|
1193
|
+
B[e] = globalThis[e];
|
|
1034
1194
|
}
|
|
1035
1195
|
}
|
|
1036
1196
|
const t = document.createElement("div");
|
|
@@ -1038,33 +1198,33 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
1038
1198
|
const n = document.createElement("div");
|
|
1039
1199
|
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
1200
|
const r = a(n);
|
|
1041
|
-
return
|
|
1201
|
+
return re = {
|
|
1042
1202
|
root: r,
|
|
1043
1203
|
hostEl: n,
|
|
1044
1204
|
stashEl: t,
|
|
1045
1205
|
props: e,
|
|
1046
1206
|
setProps: null
|
|
1047
|
-
}, r.render(C(
|
|
1207
|
+
}, r.render(C(ge, {})), re;
|
|
1048
1208
|
})(e);
|
|
1049
|
-
return t.props = e, t.setProps?.(e),
|
|
1050
|
-
|
|
1209
|
+
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)), () => {
|
|
1210
|
+
se?.(), se = null, ie = null, A.current = null, re?.stashEl.appendChild(re.hostEl);
|
|
1051
1211
|
};
|
|
1052
1212
|
}, []), r(() => {
|
|
1053
|
-
if (!
|
|
1213
|
+
if (!re) return;
|
|
1054
1214
|
const e = {
|
|
1055
|
-
...
|
|
1215
|
+
...re.props,
|
|
1056
1216
|
theme: f ? "extended-dark" : "extended",
|
|
1057
|
-
options:
|
|
1217
|
+
options: Oe
|
|
1058
1218
|
};
|
|
1059
|
-
|
|
1060
|
-
}, [f,
|
|
1061
|
-
const e =
|
|
1219
|
+
re.props = e, re.setProps?.(e);
|
|
1220
|
+
}, [f, Oe]), r(() => {
|
|
1221
|
+
const e = A.current, t = e?.editor;
|
|
1062
1222
|
if (!t) return;
|
|
1063
|
-
|
|
1064
|
-
const n =
|
|
1065
|
-
t.getValue() !== n && (t.setValue(n), be(t.getModel(), e.monaco, t),
|
|
1066
|
-
}, [M,
|
|
1067
|
-
const
|
|
1223
|
+
ue.current = F ?? null;
|
|
1224
|
+
const n = j(M)?.getSource() ?? "";
|
|
1225
|
+
t.getValue() !== n && (t.setValue(n), be(t.getModel(), e.monaco, t), Z({ dirty: !1 }));
|
|
1226
|
+
}, [M, F]);
|
|
1227
|
+
const Ie = N("div", {
|
|
1068
1228
|
style: {
|
|
1069
1229
|
display: "flex",
|
|
1070
1230
|
flex: "1 1 100%",
|
|
@@ -1074,7 +1234,7 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
1074
1234
|
boxSizing: "border-box"
|
|
1075
1235
|
},
|
|
1076
1236
|
children: [C("div", {
|
|
1077
|
-
ref:
|
|
1237
|
+
ref: De,
|
|
1078
1238
|
style: {
|
|
1079
1239
|
display: "flex",
|
|
1080
1240
|
flex: "1 1 100%",
|
|
@@ -1082,69 +1242,33 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
1082
1242
|
position: "relative"
|
|
1083
1243
|
}
|
|
1084
1244
|
}), Me]
|
|
1085
|
-
}),
|
|
1245
|
+
}), $e = w(t, () => ({
|
|
1086
1246
|
isScriptEditorElement: () => !0,
|
|
1087
1247
|
showCommandPalette: () => {
|
|
1088
|
-
|
|
1248
|
+
A.current?.editor && A.current.editor.trigger("keyboard", "editor.action.quickCommand", null);
|
|
1089
1249
|
},
|
|
1090
1250
|
getScripts: () => M,
|
|
1091
1251
|
focus: (e) => {
|
|
1092
1252
|
ve(e);
|
|
1093
1253
|
},
|
|
1094
|
-
close: () =>
|
|
1095
|
-
insertSnippet: (e) =>
|
|
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(),
|
|
1254
|
+
close: () => ke(),
|
|
1255
|
+
insertSnippet: (e) => A.current?.editor ? Y(A.current.editor, A.current.monaco, e) : Promise.resolve(),
|
|
1132
1256
|
saveSource: async () => {
|
|
1133
|
-
await
|
|
1257
|
+
await ne();
|
|
1134
1258
|
},
|
|
1135
1259
|
runAction: (e) => {
|
|
1136
|
-
const t =
|
|
1260
|
+
const t = A.current?.editor;
|
|
1137
1261
|
t && (t.focus(), t.trigger("source", e, null));
|
|
1138
1262
|
},
|
|
1139
1263
|
copy: () => Se(),
|
|
1140
1264
|
cut: () => Ce(),
|
|
1141
1265
|
paste: () => Ne()
|
|
1142
|
-
}), [
|
|
1143
|
-
null !== e &&
|
|
1144
|
-
}, []),
|
|
1266
|
+
}), [F]), [Ae, Te] = s(null), Re = b((e) => {
|
|
1267
|
+
null !== e && Te(e);
|
|
1268
|
+
}, []), Fe = y.useCommandScope();
|
|
1145
1269
|
return r(() => {
|
|
1146
|
-
if (!
|
|
1147
|
-
const e =
|
|
1270
|
+
if (!Fe || !Ae) return;
|
|
1271
|
+
const e = Fe.contribution();
|
|
1148
1272
|
return function(e, t) {
|
|
1149
1273
|
const n = t.scriptEditor, r = t;
|
|
1150
1274
|
e.updateCommand("scriptingHelp", { callback: () => {
|
|
@@ -1152,36 +1276,36 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
1152
1276
|
} }), e.updateCommand("showScriptingCommands", { callback: () => {
|
|
1153
1277
|
n.showCommandPalette();
|
|
1154
1278
|
} });
|
|
1155
|
-
const o = r?.readOnly ? [
|
|
1279
|
+
const o = r?.readOnly ? [m("reason.scriptsReadOnly")] : [];
|
|
1156
1280
|
e.updateCommand("insertScript", {
|
|
1157
1281
|
disabledReasons: o,
|
|
1158
1282
|
callback: (e) => n.insertSnippet(e ?? "")
|
|
1159
1283
|
}), e.updateCommand("saveScripts", {
|
|
1160
|
-
disabledReasons: [...o, ...r?.isDirty ? [] : [
|
|
1284
|
+
disabledReasons: [...o, ...r?.isDirty ? [] : [m("reason.noChangesToSave")]],
|
|
1161
1285
|
callback: async () => {
|
|
1162
1286
|
await n.saveSource();
|
|
1163
1287
|
}
|
|
1164
1288
|
}), 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
1289
|
}(e, {
|
|
1166
|
-
scriptEditor:
|
|
1167
|
-
isDirty:
|
|
1168
|
-
readOnly:
|
|
1290
|
+
scriptEditor: Ae,
|
|
1291
|
+
isDirty: T,
|
|
1292
|
+
readOnly: g
|
|
1169
1293
|
}), () => {
|
|
1170
1294
|
e.remove();
|
|
1171
1295
|
};
|
|
1172
1296
|
}, [
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
]), r(() => (
|
|
1178
|
-
|
|
1297
|
+
Fe,
|
|
1298
|
+
Ae,
|
|
1299
|
+
T,
|
|
1300
|
+
g
|
|
1301
|
+
]), r(() => (k && requestAnimationFrame(() => {
|
|
1302
|
+
$e.current?.focus();
|
|
1179
1303
|
}), () => {
|
|
1180
|
-
|
|
1181
|
-
|
|
1304
|
+
A.current?.editor && requestAnimationFrame(() => {
|
|
1305
|
+
$e.current?.contains(document.activeElement) && $e.current?.focus();
|
|
1182
1306
|
});
|
|
1183
1307
|
}), []), C("div", {
|
|
1184
|
-
className: c("script-editor",
|
|
1308
|
+
className: c("script-editor", W, n),
|
|
1185
1309
|
style: {
|
|
1186
1310
|
display: "flex",
|
|
1187
1311
|
flexDirection: "row",
|
|
@@ -1189,13 +1313,13 @@ var Z = null, J = null, X = null, Y = null, Q = !1, ee = !1, te = !1, ne = { cur
|
|
|
1189
1313
|
position: "relative",
|
|
1190
1314
|
...p
|
|
1191
1315
|
},
|
|
1192
|
-
ref: l([
|
|
1193
|
-
...
|
|
1194
|
-
children:
|
|
1316
|
+
ref: l([$e, Re]),
|
|
1317
|
+
...I,
|
|
1318
|
+
children: Ie
|
|
1195
1319
|
});
|
|
1196
|
-
})),
|
|
1197
|
-
|
|
1198
|
-
},
|
|
1320
|
+
})), ye = null, he = (e) => {
|
|
1321
|
+
ye = e;
|
|
1322
|
+
}, be = () => ye, xe = n((e) => {
|
|
1199
1323
|
const { scope: t, data: n } = e, { workbook: o } = n, i = v(), s = M(), a = s.getOpen(), c = b(async (e) => {
|
|
1200
1324
|
if (!o) return;
|
|
1201
1325
|
let t = null;
|
|
@@ -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 =
|
|
1338
|
+
const e = be();
|
|
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
|
-
|
|
1239
|
-
var
|
|
1362
|
+
xe.displayName = "WorkbookScriptCommands";
|
|
1363
|
+
var we = {
|
|
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
|
-
},
|
|
1372
|
+
}, ke = [
|
|
1249
1373
|
{
|
|
1250
1374
|
sourceId: "groups",
|
|
1251
1375
|
catalog: {
|
|
@@ -1327,30 +1451,30 @@ var pe = {
|
|
|
1327
1451
|
}
|
|
1328
1452
|
}
|
|
1329
1453
|
}
|
|
1330
|
-
], { DefaultCommandCatalogService:
|
|
1331
|
-
var
|
|
1454
|
+
], { DefaultCommandCatalogService: ve } = y, Se = !1;
|
|
1455
|
+
var Ce = (e) => {
|
|
1332
1456
|
const { model: t, entryKey: n, frame: r, ref: o, ...i } = e;
|
|
1333
|
-
return C(
|
|
1457
|
+
return C(fe, {
|
|
1334
1458
|
ref: o,
|
|
1335
1459
|
frame: r,
|
|
1336
1460
|
scripts: t?.getScripts(),
|
|
1337
1461
|
...i
|
|
1338
1462
|
});
|
|
1339
|
-
},
|
|
1463
|
+
}, Ne = () => {
|
|
1340
1464
|
E.registerTaskPane({
|
|
1341
1465
|
key: "scriptEditor",
|
|
1342
1466
|
getTitle: () => "Script (Typescript)",
|
|
1343
1467
|
getIcon: () => "ScriptRun",
|
|
1344
|
-
component:
|
|
1468
|
+
component: Ce,
|
|
1345
1469
|
keepMounted: !0
|
|
1346
1470
|
}, !0), function() {
|
|
1347
|
-
if (
|
|
1348
|
-
|
|
1349
|
-
const e =
|
|
1471
|
+
if (Se) return;
|
|
1472
|
+
Se = !0;
|
|
1473
|
+
const e = ve;
|
|
1350
1474
|
e.registerFromManifest("@sheetxl/scripting-react", import.meta.url, {
|
|
1351
|
-
messages:
|
|
1352
|
-
catalogs:
|
|
1475
|
+
messages: we,
|
|
1476
|
+
catalogs: ke
|
|
1353
1477
|
}), e.prefetch();
|
|
1354
|
-
}(), y.DefaultCommandRegistry.registerDynamic("workbook",
|
|
1478
|
+
}(), y.DefaultCommandRegistry.registerDynamic("workbook", xe);
|
|
1355
1479
|
};
|
|
1356
|
-
export {
|
|
1480
|
+
export { fe as ScriptEditor, Ne as ScriptingReactPlugin, xe as WorkbookScriptCommands, be as getScriptEditorOpener, he as setScriptEditorOpener };
|