@sheetxl/scripting-react 0.7.23-beta.2

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.
Files changed (44) hide show
  1. package/LICENSE.md +11 -0
  2. package/README.md +25 -0
  3. package/browser/cjs/BAh9DnP6CTFXt1HI.cjs +1 -0
  4. package/browser/cjs/Bf_pmg4C0o1aKVy-.cjs +2 -0
  5. package/browser/cjs/CsWMPekp2nRo3bHt.cjs +11 -0
  6. package/browser/cjs/index.cjs +9 -0
  7. package/browser/esm/79R_LZrdMANq6eyF.mjs +545 -0
  8. package/browser/esm/C1aR3ISFO7Zp-stK.mjs +17 -0
  9. package/browser/esm/MBTRgCPV6sAugbR3.mjs +1483 -0
  10. package/browser/esm/index.mjs +1215 -0
  11. package/licenses/dependencies.txt +225 -0
  12. package/node/esm/index.mjs +1323 -0
  13. package/package.json +62 -0
  14. package/resources/contents.json +36 -0
  15. package/resources/locales/contents.json +58 -0
  16. package/resources/locales/de/groups.cmd.json +21 -0
  17. package/resources/locales/de/scriptEditor.cmd.json +36 -0
  18. package/resources/locales/de/ui.msg.json +8 -0
  19. package/resources/locales/de/workbookScript.cmd.json +26 -0
  20. package/resources/locales/en/groups.cmd.json +21 -0
  21. package/resources/locales/en/scriptEditor.cmd.json +36 -0
  22. package/resources/locales/en/ui.msg.json +8 -0
  23. package/resources/locales/en/workbookScript.cmd.json +26 -0
  24. package/types/index.d.ts +2 -0
  25. package/types/src/IScriptEditor.d.ts +52 -0
  26. package/types/src/IScriptEditor.d.ts.map +1 -0
  27. package/types/src/MonacoOptions.d.ts +68 -0
  28. package/types/src/MonacoOptions.d.ts.map +1 -0
  29. package/types/src/ScriptEditor.d.ts +73 -0
  30. package/types/src/ScriptEditor.d.ts.map +1 -0
  31. package/types/src/ScriptEditorCommands.d.ts +23 -0
  32. package/types/src/ScriptEditorCommands.d.ts.map +1 -0
  33. package/types/src/ScriptEditorOpener.d.ts +33 -0
  34. package/types/src/ScriptEditorOpener.d.ts.map +1 -0
  35. package/types/src/ScriptingReactPlugin.d.ts +9 -0
  36. package/types/src/ScriptingReactPlugin.d.ts.map +1 -0
  37. package/types/src/WorkbookScriptCommands.d.ts +18 -0
  38. package/types/src/WorkbookScriptCommands.d.ts.map +1 -0
  39. package/types/src/command-catalog/index.d.ts +3 -0
  40. package/types/src/command-catalog/index.d.ts.map +1 -0
  41. package/types/src/index.d.ts +6 -0
  42. package/types/src/index.d.ts.map +1 -0
  43. package/types/src/tsMonarchLanguage.d.ts +19 -0
  44. package/types/src/tsMonarchLanguage.d.ts.map +1 -0
@@ -0,0 +1,1323 @@
1
+ /**
2
+ * @license @sheetxl/scripting-react - Scripting React - Monaco based script editor and scripting UI for SheetXL. - v0.7.23-beta.2
3
+ *
4
+ * (C) 2026-present SheetXL Inc. & Michael T. Ford
5
+ * License: The license can be found at https://www.sheetxl.com/license.
6
+ */
7
+ import { Suspense as e, forwardRef as t, lazy as n, memo as r, useEffect as o, useMemo as i, useRef as s, useState as a } from "react";
8
+ import { createRoot as c } from "react-dom/client";
9
+ import l from "clsx";
10
+ import { mergeRefs as u } from "react-merge-refs";
11
+ import { CommonUtils as d, TimerUtils as p, messageKey as g } from "@sheetxl/utils";
12
+ import { DocTags as m } from "@sheetxl/scripting";
13
+ import { Command as f, useCallbackRef as y, useCommands as h, useImperativeElement as b, useNotifier as w, useTranslator as k } from "@sheetxl/utils-react";
14
+ import { DefaultTaskPaneRegistry as x, useModelListener as v, useTaskPaneArea as S, useWorkbook as C } from "@sheetxl/react";
15
+ import { jsx as N, jsxs as E } from "react/jsx-runtime";
16
+ var L = {
17
+ defaultToken: "invalid",
18
+ tokenPostfix: ".ts",
19
+ keywords: [
20
+ "abstract",
21
+ "any",
22
+ "as",
23
+ "asserts",
24
+ "bigint",
25
+ "boolean",
26
+ "break",
27
+ "case",
28
+ "catch",
29
+ "class",
30
+ "continue",
31
+ "const",
32
+ "constructor",
33
+ "debugger",
34
+ "declare",
35
+ "default",
36
+ "delete",
37
+ "do",
38
+ "else",
39
+ "enum",
40
+ "export",
41
+ "extends",
42
+ "false",
43
+ "finally",
44
+ "for",
45
+ "from",
46
+ "function",
47
+ "get",
48
+ "if",
49
+ "implements",
50
+ "import",
51
+ "in",
52
+ "infer",
53
+ "instanceof",
54
+ "interface",
55
+ "is",
56
+ "keyof",
57
+ "let",
58
+ "module",
59
+ "namespace",
60
+ "never",
61
+ "new",
62
+ "null",
63
+ "number",
64
+ "object",
65
+ "out",
66
+ "package",
67
+ "private",
68
+ "protected",
69
+ "public",
70
+ "override",
71
+ "readonly",
72
+ "require",
73
+ "global",
74
+ "return",
75
+ "satisfies",
76
+ "set",
77
+ "static",
78
+ "string",
79
+ "super",
80
+ "switch",
81
+ "symbol",
82
+ "this",
83
+ "throw",
84
+ "true",
85
+ "try",
86
+ "type",
87
+ "typeof",
88
+ "undefined",
89
+ "unique",
90
+ "unknown",
91
+ "var",
92
+ "void",
93
+ "while",
94
+ "with",
95
+ "yield",
96
+ "async",
97
+ "await",
98
+ "of"
99
+ ],
100
+ operators: [
101
+ "<=",
102
+ ">=",
103
+ "==",
104
+ "!=",
105
+ "===",
106
+ "!==",
107
+ "=>",
108
+ "+",
109
+ "-",
110
+ "**",
111
+ "*",
112
+ "/",
113
+ "%",
114
+ "++",
115
+ "--",
116
+ "<<",
117
+ "</",
118
+ ">>",
119
+ ">>>",
120
+ "&",
121
+ "|",
122
+ "^",
123
+ "!",
124
+ "~",
125
+ "&&",
126
+ "||",
127
+ "??",
128
+ "?",
129
+ ":",
130
+ "=",
131
+ "+=",
132
+ "-=",
133
+ "*=",
134
+ "**=",
135
+ "/=",
136
+ "%=",
137
+ "<<=",
138
+ ">>=",
139
+ ">>>=",
140
+ "&=",
141
+ "|=",
142
+ "^=",
143
+ "@"
144
+ ],
145
+ symbols: /[=><!~?:&|+\-*\/\^%]+/,
146
+ escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
147
+ digits: /\d+(_+\d+)*/,
148
+ octaldigits: /[0-7]+(_+[0-7]+)*/,
149
+ binarydigits: /[0-1]+(_+[0-1]+)*/,
150
+ hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
151
+ regexpctl: /[(){}\[\]\$\^|\-*+?\.]/,
152
+ regexpesc: /\\(?:[bBdDfnrstvwWn0\\\/]|@regexpctl|c[A-Z]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})/,
153
+ tokenizer: {
154
+ root: [[/[{}]/, "delimiter.bracket"], { include: "common" }],
155
+ common: [
156
+ [/#?[a-z_$][\w$]*/, { cases: {
157
+ "@keywords": "keyword",
158
+ "@default": "identifier"
159
+ } }],
160
+ [/[A-Z][\w\$]*/, "type.identifier"],
161
+ { include: "@whitespace" },
162
+ [/\/(?=([^\\\/]|\\.)+\/([dgimsuy]*)(\s*)(\.|;|,|\)|\]|\}|$))/, {
163
+ token: "regexp",
164
+ bracket: "@open",
165
+ next: "@regexp"
166
+ }],
167
+ [/[()\[\]]/, "@brackets"],
168
+ [/[<>](?!@symbols)/, "@brackets"],
169
+ [/!(?=([^=]|$))/, "delimiter"],
170
+ [/@symbols/, { cases: {
171
+ "@operators": "delimiter",
172
+ "@default": ""
173
+ } }],
174
+ [/(@digits)[eE]([\-+]?(@digits))?/, "number.float"],
175
+ [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/, "number.float"],
176
+ [/0[xX](@hexdigits)n?/, "number.hex"],
177
+ [/0[oO]?(@octaldigits)n?/, "number.octal"],
178
+ [/0[bB](@binarydigits)n?/, "number.binary"],
179
+ [/(@digits)n?/, "number"],
180
+ [/[;,.]/, "delimiter"],
181
+ [/"([^"\\]|\\.)*$/, "string.invalid"],
182
+ [/'([^'\\]|\\.)*$/, "string.invalid"],
183
+ [
184
+ /"/,
185
+ "string",
186
+ "@string_double"
187
+ ],
188
+ [
189
+ /'/,
190
+ "string",
191
+ "@string_single"
192
+ ],
193
+ [
194
+ /`/,
195
+ "string",
196
+ "@string_backtick"
197
+ ]
198
+ ],
199
+ whitespace: [
200
+ [/[ \t\r\n]+/, ""],
201
+ [
202
+ /\/\*\*(?!\/)/,
203
+ "comment.doc",
204
+ "@jsdoc"
205
+ ],
206
+ [
207
+ /\/\*/,
208
+ "comment",
209
+ "@comment"
210
+ ],
211
+ [/\/\/.*$/, "comment"]
212
+ ],
213
+ comment: [
214
+ [/[^\/*]+/, "comment"],
215
+ [
216
+ /\*\//,
217
+ "comment",
218
+ "@pop"
219
+ ],
220
+ [/[\/*]/, "comment"]
221
+ ],
222
+ jsdoc: [
223
+ [/@(?:param|arg|argument|property|prop|template|typedef)\b/, {
224
+ token: "comment.doc.tag",
225
+ next: "@jsdoc_param"
226
+ }],
227
+ [/@\w+/, "comment.doc.tag"],
228
+ [/\{/, {
229
+ token: "comment.doc.type",
230
+ next: "@jsdoc_type"
231
+ }],
232
+ [/[^\/*@{]+/, "comment.doc"],
233
+ [
234
+ /\*\//,
235
+ "comment.doc",
236
+ "@pop"
237
+ ],
238
+ [/[\/*]/, "comment.doc"]
239
+ ],
240
+ jsdoc_type: [
241
+ [/[^{}]+/, "comment.doc.type"],
242
+ [
243
+ /\{/,
244
+ "comment.doc.type",
245
+ "@push"
246
+ ],
247
+ [
248
+ /\}/,
249
+ "comment.doc.type",
250
+ "@pop"
251
+ ]
252
+ ],
253
+ jsdoc_param: [
254
+ [/\s+/, "comment.doc"],
255
+ [/\{/, {
256
+ token: "comment.doc.type",
257
+ next: "@jsdoc_type"
258
+ }],
259
+ [/\[[^\]]*\]/, {
260
+ token: "comment.doc.name",
261
+ next: "@pop"
262
+ }],
263
+ [/[\w$][\w$.]*/, {
264
+ token: "comment.doc.name",
265
+ next: "@pop"
266
+ }],
267
+ [/(?=\*\/)/, {
268
+ token: "comment.doc",
269
+ next: "@pop"
270
+ }],
271
+ [/./, {
272
+ token: "comment.doc",
273
+ next: "@pop"
274
+ }]
275
+ ],
276
+ regexp: [
277
+ [/(\{)(\d+(?:,\d*)?)(\})/, [
278
+ "regexp.escape.control",
279
+ "regexp.escape.control",
280
+ "regexp.escape.control"
281
+ ]],
282
+ [/(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/, ["regexp.escape.control", {
283
+ token: "regexp.escape.control",
284
+ next: "@regexrange"
285
+ }]],
286
+ [/(\()(\?:|\?=|\?!)/, ["regexp.escape.control", "regexp.escape.control"]],
287
+ [/[()]/, "regexp.escape.control"],
288
+ [/@regexpctl/, "regexp.escape.control"],
289
+ [/[^\\\/]/, "regexp"],
290
+ [/@regexpesc/, "regexp.escape"],
291
+ [/\\\./, "regexp.invalid"],
292
+ [/(\/)([dgimsuy]*)/, [{
293
+ token: "regexp",
294
+ bracket: "@close",
295
+ next: "@pop"
296
+ }, "keyword.other"]]
297
+ ],
298
+ regexrange: [
299
+ [/-/, "regexp.escape.control"],
300
+ [/\^/, "regexp.invalid"],
301
+ [/@regexpesc/, "regexp.escape"],
302
+ [/[^\]]/, "regexp"],
303
+ [/\]/, {
304
+ token: "regexp.escape.control",
305
+ next: "@pop",
306
+ bracket: "@close"
307
+ }]
308
+ ],
309
+ string_double: [
310
+ [/[^\\"]+/, "string"],
311
+ [/@escapes/, "string.escape"],
312
+ [/\\./, "string.escape.invalid"],
313
+ [
314
+ /"/,
315
+ "string",
316
+ "@pop"
317
+ ]
318
+ ],
319
+ string_single: [
320
+ [/[^\\']+/, "string"],
321
+ [/@escapes/, "string.escape"],
322
+ [/\\./, "string.escape.invalid"],
323
+ [
324
+ /'/,
325
+ "string",
326
+ "@pop"
327
+ ]
328
+ ],
329
+ string_backtick: [
330
+ [/\$\{/, {
331
+ token: "delimiter.bracket",
332
+ next: "@bracketCounting"
333
+ }],
334
+ [/[^\\`$]+/, "string"],
335
+ [/@escapes/, "string.escape"],
336
+ [/\\./, "string.escape.invalid"],
337
+ [
338
+ /`/,
339
+ "string",
340
+ "@pop"
341
+ ]
342
+ ],
343
+ bracketCounting: [
344
+ [
345
+ /\{/,
346
+ "delimiter.bracket",
347
+ "@bracketCounting"
348
+ ],
349
+ [
350
+ /\}/,
351
+ "delimiter.bracket",
352
+ "@pop"
353
+ ],
354
+ { include: "common" }
355
+ ]
356
+ }
357
+ }, M = {
358
+ lightbulb: { enabled: !1 },
359
+ tabSize: 2,
360
+ acceptSuggestionOnCommitCharacter: !0,
361
+ acceptSuggestionOnEnter: "on",
362
+ accessibilitySupport: "auto",
363
+ automaticLayout: !0,
364
+ autoIndent: !1,
365
+ codeLens: !0,
366
+ colorDecorators: !0,
367
+ contextmenu: !0,
368
+ cursorBlinking: "blink",
369
+ cursorSmoothCaretAnimation: !1,
370
+ cursorStyle: "line",
371
+ disableLayerHinting: !1,
372
+ disableMonospaceOptimizations: !1,
373
+ dragAndDrop: !0,
374
+ glyphMargin: !0,
375
+ fixedOverflowWidgets: !1,
376
+ folding: !0,
377
+ foldingStrategy: "auto",
378
+ fontLigatures: !1,
379
+ formatOnPaste: !0,
380
+ formatOnType: !1,
381
+ hideCursorInOverviewRuler: !1,
382
+ highlightActiveIndentGuide: !0,
383
+ links: !0,
384
+ lineDecorationsWidth: 8,
385
+ lineNumbersMinChars: 3,
386
+ mouseWheelZoom: !1,
387
+ multiCursorMergeOverlapping: !0,
388
+ multiCursorModifier: "alt",
389
+ overviewRulerBorder: !0,
390
+ overviewRulerLanes: 2,
391
+ quickSuggestions: !0,
392
+ quickSuggestionsDelay: 100,
393
+ readOnly: !1,
394
+ renderControlCharacters: !1,
395
+ renderFinalNewline: !0,
396
+ renderIndentGuides: !0,
397
+ renderLineHighlight: "all",
398
+ renderWhitespace: "none",
399
+ revealHorizontalRightPadding: 30,
400
+ roundedSelection: !0,
401
+ rulers: [],
402
+ scrollBeyondLastColumn: 5,
403
+ scrollBeyondLastLine: !0,
404
+ selectOnLineNumbers: !0,
405
+ selectionClipboard: !0,
406
+ selectionHighlight: !0,
407
+ showLightbulbIconMode: !1,
408
+ showFoldingControls: "mouseover",
409
+ smoothScrolling: !0,
410
+ suggestOnTriggerCharacters: !0,
411
+ wordBasedSuggestions: !0,
412
+ wordSeparators: "~!@#$%^&*()-=+[{]}|;:'\",.<>/?",
413
+ wordWrap: "off",
414
+ wordWrapBreakAfterCharacters: " })]?|&,;",
415
+ wordWrapBreakBeforeCharacters: "{([+",
416
+ wordWrapBreakObtrusiveCharacters: ".",
417
+ wordWrapColumn: 80,
418
+ wordWrapMinified: !0,
419
+ wrappingIndent: "none"
420
+ }, I = "_script-editor_1kuph_5";
421
+ var D, T = n(async () => (function() {
422
+ if ("undefined" == typeof window) return;
423
+ const e = window;
424
+ if (e.__sxlDefineShim) return;
425
+ e.__sxlDefineShim = !0;
426
+ const t = [];
427
+ let n = null;
428
+ const r = (...e) => {
429
+ "function" == typeof n ? n(...e) : t.push(e);
430
+ };
431
+ Object.defineProperty(e, "define", {
432
+ configurable: !1,
433
+ enumerable: !0,
434
+ get: () => "function" == typeof n ? n : r,
435
+ set(e) {
436
+ if ("function" == typeof e) for (n = e; t.length;) try {
437
+ e(...t.shift());
438
+ } catch {}
439
+ }
440
+ });
441
+ }(), import("@monaco-editor/react"))), O = ["define", "require"], A = !1, R = "@0.7.23-beta.2";
442
+ "@local" !== R && "@0.0.0" !== R || (R = "");
443
+ var F = `https://cdn.jsdelivr.net/npm/@sheetxl/sdk${R}/types/scripting.d.ts`, P = (e) => {
444
+ try {
445
+ e.languages.setMonarchTokensProvider("typescript", L);
446
+ } catch (e) {}
447
+ }, $ = !1;
448
+ function W(e, t) {
449
+ let n = null;
450
+ const r = e.length;
451
+ for (let o = 0; !n && o < r; o++) {
452
+ const r = e[o];
453
+ r.getName() === t.text && (n = r);
454
+ }
455
+ return n ? n.getContext() : "formula";
456
+ }
457
+ function _(e, t, n, r, o = []) {
458
+ if ("function" === r.kind && "export" === r.kindModifiers) {
459
+ const t = r.spans[0].start, i = e.getPositionAt(t);
460
+ o.push({
461
+ name: r.text,
462
+ type: W(n, r),
463
+ lineNumber: i.lineNumber
464
+ });
465
+ }
466
+ if (r.childItems) for (const i of r.childItems) _(e, t, n, i, o);
467
+ return o;
468
+ }
469
+ function V(e, t, n = "function", r) {
470
+ const o = e.spans, i = o.length;
471
+ for (let s = 0; s < i; s++) {
472
+ const i = o[s];
473
+ if (i.start <= t && t < i.start + i.length) {
474
+ if (e.kind === n && (!r || e.kindModifiers === r)) return e;
475
+ for (const o of e.childItems || []) {
476
+ const e = V(o, t, n, r);
477
+ if (e) return e;
478
+ }
479
+ }
480
+ return null;
481
+ }
482
+ }
483
+ function B(e) {
484
+ return "comment" === e.kind;
485
+ }
486
+ var H = null, j = null, U = null, K = null, q = !1, z = !1, G = !1, Z = { current: null }, J = (e, t) => {
487
+ j = {
488
+ editor: e,
489
+ monaco: t
490
+ }, U && (K = U(e, t));
491
+ }, X = (e) => {
492
+ if (G) return;
493
+ G = !0, e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
494
+ noSemanticValidation: !0,
495
+ noSyntaxValidation: !1,
496
+ diagnosticCodesToIgnore: [2307]
497
+ }), e.languages.typescript.typescriptDefaults.setEagerModelSync(!0), e.languages.json.jsonDefaults.setDiagnosticsOptions({ validate: !0 }), P(e), ((e) => {
498
+ $ || ($ = !0, e.languages.registerCompletionItemProvider("typescript", {
499
+ triggerCharacters: ["@"],
500
+ provideCompletionItems: (t, n) => {
501
+ const r = t.getValueInRange({
502
+ startLineNumber: n.lineNumber,
503
+ startColumn: 1,
504
+ endLineNumber: n.lineNumber,
505
+ endColumn: n.column
506
+ }), o = /(?:^|\s)@(\w*)$/.exec(r);
507
+ if (!o || !((e, t) => {
508
+ const n = e.getValueInRange({
509
+ startLineNumber: 1,
510
+ startColumn: 1,
511
+ endLineNumber: t.lineNumber,
512
+ endColumn: t.column
513
+ });
514
+ return n.lastIndexOf("/*") > n.lastIndexOf("*/");
515
+ })(t, n)) return { suggestions: [] };
516
+ const i = o[1], s = new e.Range(n.lineNumber, n.column - i.length, n.lineNumber, n.column);
517
+ return { suggestions: m.map((t) => ({
518
+ label: `@${t.name}`,
519
+ kind: e.languages.CompletionItemKind.Keyword,
520
+ detail: "sheetxl" === t.group ? "SheetXL" : "JSDoc",
521
+ documentation: { value: t.description },
522
+ insertText: t.snippet ?? t.name,
523
+ insertTextRules: t.snippet ? e.languages.CompletionItemInsertTextRule.InsertAsSnippet : void 0,
524
+ range: s
525
+ })) };
526
+ }
527
+ }));
528
+ })(e), e.editor.defineTheme("extended", {
529
+ base: "vs",
530
+ inherit: !0,
531
+ rules: [
532
+ {
533
+ token: "comment.doc",
534
+ foreground: "008000"
535
+ },
536
+ {
537
+ token: "comment.doc.tag",
538
+ foreground: "0000FF"
539
+ },
540
+ {
541
+ token: "comment.doc.type",
542
+ foreground: "267F99"
543
+ },
544
+ {
545
+ token: "comment.doc.name",
546
+ foreground: "001080"
547
+ }
548
+ ],
549
+ colors: {}
550
+ }), e.editor.defineTheme("extended-dark", {
551
+ base: "vs-dark",
552
+ inherit: !0,
553
+ rules: [
554
+ {
555
+ token: "comment.doc",
556
+ foreground: "6A9955"
557
+ },
558
+ {
559
+ token: "comment.doc.tag",
560
+ foreground: "569CD6"
561
+ },
562
+ {
563
+ token: "comment.doc.type",
564
+ foreground: "4EC9B0"
565
+ },
566
+ {
567
+ token: "comment.doc.name",
568
+ foreground: "9CDCFE"
569
+ }
570
+ ],
571
+ colors: {}
572
+ });
573
+ (async () => {
574
+ let t = !1;
575
+ try {
576
+ const n = await (async () => await (await fetch(F)).text())(), r = e.Uri.parse("inmemory://model/\"sheetxl-models\".d.ts");
577
+ let o = e.editor.getModel(r);
578
+ o ? t = !0 : o = e.editor.createModel(n, "typescript", r), e.editor.setModelMarkers(o, "default", []);
579
+ } catch (e) {
580
+ console.warn("cant load types", e);
581
+ }
582
+ try {
583
+ if (e.languages.registerLinkProvider("*", { provideLinks: (t, n) => {
584
+ const r = [], o = { links: r }, i = t.getLinesContent(), s = i.length;
585
+ for (let n = 1; n <= s; n++) {
586
+ const o = i[n - 1], s = e.editor.tokenize(o, "typescript"), a = s[0].length;
587
+ for (let i = 0; i < a; i++) {
588
+ const a = s[0]?.[i];
589
+ if (a && a.type.startsWith("string")) {
590
+ 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
+ const p = d[0];
592
+ "`" !== p && "'" !== p && "\"" !== p || (c++, d = d.substring(1));
593
+ const g = d[d.length - 1];
594
+ "`" !== g && "'" !== g && "\"" !== g || (c++, d = d.substring(0, d.length - 1));
595
+ try {
596
+ Z.current?.getRanges(d) && r.push({
597
+ range: {
598
+ endColumn: l,
599
+ endLineNumber: n,
600
+ startColumn: c,
601
+ startLineNumber: n
602
+ },
603
+ tooltip: `Goto range '${d}'`,
604
+ url: `/range/${d}`
605
+ });
606
+ } catch (e) {}
607
+ }
608
+ }
609
+ }
610
+ return o;
611
+ } }), e.editor.registerLinkOpener({ open(e) {
612
+ if (e?.path?.startsWith("/range/")) {
613
+ try {
614
+ Z.current?.getRanges(e.path.substring(7))?.select();
615
+ } catch (e) {
616
+ console.warn("invalid range", e);
617
+ }
618
+ return !0;
619
+ }
620
+ return !1;
621
+ } }), !t) {
622
+ const t = e.languages.typescript.typescriptDefaults.getCompilerOptions();
623
+ e.languages.typescript.typescriptDefaults.setCompilerOptions({
624
+ ...t,
625
+ target: e.languages.typescript.ScriptTarget.ES2020,
626
+ lib: [
627
+ "webworker",
628
+ "es2020",
629
+ "esnext.asynciterable"
630
+ ],
631
+ downlevelIteration: !0,
632
+ moduleResolution: e.languages.typescript.ModuleResolutionKind.NodeJs,
633
+ allowSyntheticDefaultImports: !0,
634
+ baseUrl: "inmemory://model/",
635
+ allowNonTsExtensions: !0
636
+ });
637
+ }
638
+ } finally {
639
+ (() => {
640
+ const t = e.languages.typescript.typescriptDefaults.getDiagnosticsOptions();
641
+ e.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
642
+ ...t,
643
+ noSemanticValidation: !1
644
+ });
645
+ })();
646
+ }
647
+ })();
648
+ }, Y = (e) => {
649
+ let t = !1;
650
+ const n = e ? e.length : 0;
651
+ for (let r = 0; !t && r < n; r++) 8 === e[r].severity && (t = !0);
652
+ }, Q = () => {
653
+ const [t, n] = a(() => H.props);
654
+ return o(() => (H && (H.setProps = n), () => {
655
+ H && (H.setProps = null);
656
+ }), []), N("div", {
657
+ style: {
658
+ display: "flex",
659
+ flex: "1 1 100%",
660
+ width: "100%",
661
+ height: "100%"
662
+ },
663
+ children: N(e, { children: N(T, {
664
+ theme: t.theme,
665
+ options: t.options,
666
+ language: "typescript",
667
+ value: t.value,
668
+ onValidate: t.onValidate,
669
+ beforeMount: t.beforeMount,
670
+ onMount: J
671
+ }) })
672
+ });
673
+ }, ee = r(t((e, t) => {
674
+ const { className: n, style: r, readOnly: m = !1, darkMode: x, loadingPanel: S, autoFocus: L = !0, frame: T, scripts: R, onStatusChange: F, ...$ } = e, W = k(), G = s(null), [J, ee] = a(!1), te = C(), [ne] = h(["insertFunction"]), [re, oe] = a({
675
+ message: "Loading",
676
+ cursor: "",
677
+ dirty: !1
678
+ }), [ie, se] = a({
679
+ loading: !1,
680
+ compiling: !1,
681
+ errors: [],
682
+ warnings: []
683
+ }), ae = y((e) => {
684
+ oe((t) => {
685
+ const n = {
686
+ ...t,
687
+ ...e
688
+ };
689
+ return d.deepEqual(n, t) ? t : (ee(n.dirty ?? !1), n);
690
+ });
691
+ }, [F]);
692
+ o(() => {
693
+ F?.(re);
694
+ }, [F, re]);
695
+ const ce = w(), le = y(async (e) => {
696
+ let t = null, n = null;
697
+ try {
698
+ e && (n = await ce.showBusy(W("scriptEditor.saving")), t = await R.createModule({ source: e })), R.addModule("scripts", t, { replace: !0 }), n?.();
699
+ } catch (e) {
700
+ n?.(), console.warn("Unable to compile", e), ce.showError(e);
701
+ }
702
+ return t;
703
+ }, [R]), ue = y(async () => {
704
+ if (!G.current) return;
705
+ const e = G.current.editor;
706
+ let t;
707
+ if (re.dirty) {
708
+ const n = e.getValue();
709
+ await le(n), t = R.getModules().getByName("scripts");
710
+ const r = t?.getSource(), o = e.getValue(), i = (r?.length ?? 0) !== n.length || r !== o;
711
+ ae({ dirty: i });
712
+ } else t = R.getModules().getByName("scripts");
713
+ return t;
714
+ }, [re, R]);
715
+ o(() => {
716
+ const e = T?.addListener({ onBeforeHide: async () => (await ue(), !0) });
717
+ return () => {
718
+ e?.();
719
+ };
720
+ }, [T]), o(() => {
721
+ if (R) return R.addListeners({ onBeforeSearch: () => ue() });
722
+ }, [R]), v(te, {
723
+ onBeforeSave: async () => {
724
+ await ue();
725
+ },
726
+ onLoad: () => {
727
+ const e = G.current?.editor;
728
+ e && e.setValue(R?.getModules().getItems()[0]?.getSource() ?? "");
729
+ }
730
+ });
731
+ const de = y(async (e) => {
732
+ if (!R) return;
733
+ const t = "string" == typeof e ? { functionName: e } : e ?? {};
734
+ let n = null;
735
+ if (t?.declaration || t?.functionName) {
736
+ const e = t.declaration ? t.declaration.getName() : t.functionName;
737
+ (await R.searchFunctions({ name: e })).length > 0 && (n = e);
738
+ }
739
+ if (n) try {
740
+ await R.executeMacro(n);
741
+ } catch (e) {
742
+ ce.showError(e);
743
+ }
744
+ }, [R, ce]), [pe, ge] = a(!1), me = y(async () => {
745
+ if (!G.current) return null;
746
+ const e = G.current, t = e.editor;
747
+ if (!t) return null;
748
+ const r = await (async (e, t, n = "export") => {
749
+ const r = e.getModel();
750
+ if (!r) return null;
751
+ const o = await (await (await t.languages.typescript.getTypeScriptWorker())(r.uri)).getNavigationTree(r.uri.toString());
752
+ let i = null, s = e.getSelection();
753
+ if (!s) return null;
754
+ const a = s.startLineNumber === s.endLineNumber && s.startColumn === s.endColumn ? r.getLineCount() : Math.min(s.endLineNumber, r.getLineCount());
755
+ for (let e = s.startLineNumber; !i && e <= a; e++) {
756
+ const t = V(o, r.getOffsetAt({
757
+ lineNumber: e,
758
+ column: 1
759
+ }), "function", n);
760
+ t && (i = t.text);
761
+ }
762
+ return i;
763
+ })(t, e.monaco);
764
+ return ae({ message: (r ?? "").toUpperCase() }), r ? {
765
+ source: t.getValue(),
766
+ name: r
767
+ } : null;
768
+ }, []);
769
+ y(p.debounce(ue, 200), []);
770
+ const fe = y(async (e, t, n) => {
771
+ se((e) => ({
772
+ ...e,
773
+ compiling: !0
774
+ }));
775
+ let r = null;
776
+ try {
777
+ if (r = await R.createModule({
778
+ source: n?.getValue(),
779
+ declarationsOnly: !0
780
+ }), !r) return;
781
+ } catch (e) {}
782
+ const o = r ? r.getDiagnostics() : d.EmptyArray;
783
+ (function(e, t, n) {
784
+ const r = (n ?? []).map((n) => {
785
+ const r = e.getPositionAt(n.start), o = e.getPositionAt(n.start + Math.max(n.length, 1));
786
+ return {
787
+ message: `${n.message} (${n.code})`,
788
+ code: n.code,
789
+ severity: "warning" === n.severity ? t.MarkerSeverity.Warning : t.MarkerSeverity.Error,
790
+ startLineNumber: r.lineNumber,
791
+ startColumn: r.column,
792
+ endLineNumber: o.lineNumber,
793
+ endColumn: o.column
794
+ };
795
+ });
796
+ t.editor.setModelMarkers(e, "sheetxl", r);
797
+ })(e, t, o), async function(e, t, n, r) {
798
+ const o = _(e, t, r, await (await (await t.languages.typescript.getTypeScriptWorker())(e.uri)).getNavigationTree(e.uri.toString())).map((e) => {
799
+ let n = null, r = null;
800
+ return "formula" === e.type ? (n = "formula.margin-icon", r = W("scriptEditor.glyph.formula")) : "macro" === e.type ? (n = "macro.margin-icon", r = W("scriptEditor.glyph.macro")) : "autoRun" === e.type && (n = "autorun.margin-icon", r = W("scriptEditor.glyph.autoRun")), {
801
+ range: new t.Range(e.lineNumber, 1, e.lineNumber, 1),
802
+ options: {
803
+ isWholeLine: !1,
804
+ glyphMarginClassName: n,
805
+ glyphMarginHoverMessage: { value: r },
806
+ stickiness: t.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges
807
+ }
808
+ };
809
+ });
810
+ Ce.current && Ce.current.clear(), Ce.current = n.createDecorationsCollection(o);
811
+ }(e, t, n, r ? r.getFunctions().getItems() : d.EmptyArray), se((e) => ({
812
+ ...e,
813
+ compiling: !1,
814
+ errors: o.filter((e) => "error" === e.severity).map((e) => `${e.code}: ${e.message}`),
815
+ warnings: o.filter((e) => "warning" === e.severity).map((e) => `${e.code}: ${e.message}`)
816
+ }));
817
+ }, [R]), ye = y(p.debounce(fe, 580), []), he = y(async (e) => {
818
+ if (!G.current) return;
819
+ const t = G.current.editor.getPosition(), n = { cursor: t ? t.toString() : "" };
820
+ void 0 !== e && (n.message = e), ae(n);
821
+ }, []);
822
+ o(() => {}, [ie]);
823
+ const be = s(null), we = y(async () => {
824
+ await ue(), T?.close();
825
+ }, [T]), ke = y((e) => {
826
+ const t = G.current?.editor;
827
+ return !!t && (t.focus(e), !0);
828
+ }, [re]), xe = y(async () => {
829
+ const e = G.current?.editor, t = e?.getModel(), n = e?.getSelection();
830
+ if (!t || !n) return;
831
+ const r = n.isEmpty() ? t.getLineContent(n.positionLineNumber) + "\n" : t.getValueInRange(n);
832
+ try {
833
+ await navigator.clipboard?.writeText(r);
834
+ } catch {}
835
+ }, []), ve = y(async () => {
836
+ const e = G.current, t = e?.editor, n = t?.getModel(), r = t?.getSelection();
837
+ if (!n || !r) return;
838
+ const o = r.isEmpty() ? new e.monaco.Range(r.positionLineNumber, 1, r.positionLineNumber + 1, 1) : r, i = n.getValueInRange(o);
839
+ try {
840
+ await navigator.clipboard?.writeText(i);
841
+ } catch {
842
+ return;
843
+ }
844
+ t.pushUndoStop(), t.executeEdits("cut", [{
845
+ range: o,
846
+ text: "",
847
+ forceMoveMarkers: !0
848
+ }]), t.pushUndoStop(), t.focus();
849
+ }, []), Se = y(async () => {
850
+ const e = G.current?.editor;
851
+ if (!e) return;
852
+ let t;
853
+ try {
854
+ t = await navigator.clipboard?.readText();
855
+ } catch {
856
+ return;
857
+ }
858
+ if (!t) return;
859
+ const n = e.getSelection();
860
+ e.pushUndoStop(), e.executeEdits("paste", [{
861
+ range: n,
862
+ text: t,
863
+ forceMoveMarkers: !0
864
+ }]), e.pushUndoStop(), e.focus();
865
+ }, []), Ce = s(null), Ne = y((e, t) => {
866
+ G.current = {
867
+ monaco: t,
868
+ editor: e
869
+ }, Z.current = te ?? null;
870
+ const n = e.getModel(), r = [];
871
+ ge(!0);
872
+ const o = R?.getModules().getItems()[0]?.getSource() ?? "";
873
+ return e.getValue() !== o && e.setValue(o), q ? (he(""), ye(n, t, e), P(t)) : (q = !0, he("Loading Types"), import("monaco-editor-auto-typings/custom-editor.js").then(async (n) => {
874
+ he(""), n.AutoTypings.create(e, {
875
+ shareCache: !0,
876
+ dontAdaptEditorOptions: !0,
877
+ monaco: t,
878
+ onUpdate: (e, n) => {
879
+ if ("LookedUpPackage" === e.type && void 0 !== e.success) {
880
+ const e = t.languages.typescript.typescriptDefaults.getDiagnosticsOptions();
881
+ t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
882
+ ...e,
883
+ diagnosticCodesToIgnore: []
884
+ });
885
+ }
886
+ },
887
+ onError: (e) => {
888
+ "Not implemented yet" === e && (e = "Compile Errors"), console.warn("Error compiling types", e);
889
+ }
890
+ }).then((n) => {
891
+ be.current = n, ye(e.getModel(), t, e), (() => {
892
+ if (A) return;
893
+ const e = (e, t) => {
894
+ try {
895
+ if (void 0 === t) try {
896
+ delete globalThis[e];
897
+ } catch (t) {
898
+ try {
899
+ globalThis[e] = void 0;
900
+ } catch (e) {}
901
+ }
902
+ else globalThis[e] = t;
903
+ } catch (e) {}
904
+ }, t = O.length;
905
+ for (let n = 0; n < t; n++) {
906
+ const t = O[n];
907
+ e(t, D[t]);
908
+ }
909
+ D = void 0, A = !0;
910
+ })(), P(t);
911
+ });
912
+ })), z || (z = !0, function(e, t) {
913
+ t.languages.registerInlayHintsProvider("typescript", { provideInlayHints(e, n, r) {
914
+ const o = [];
915
+ for (let n = 1; n < e.getLineCount() + 1; n++) {
916
+ const r = {
917
+ startLineNumber: n,
918
+ startColumn: 1,
919
+ endLineNumber: n,
920
+ endColumn: e.getLineLength(n) + 1
921
+ }, i = e.getValueInRange(r).indexOf("hint");
922
+ -1 !== i && o.push({
923
+ kind: t.languages.InlayHintKind.Type,
924
+ position: {
925
+ lineNumber: r.startLineNumber,
926
+ column: i + 4 + 1
927
+ },
928
+ label: "[hint]"
929
+ });
930
+ }
931
+ return {
932
+ hints: o,
933
+ dispose: () => {}
934
+ };
935
+ } });
936
+ }(0, t)), r.push(e.addAction({
937
+ id: "executeScript",
938
+ label: "Execute",
939
+ keybindings: [t.KeyCode.F8],
940
+ run: async (e) => {
941
+ const t = await me();
942
+ de(t);
943
+ }
944
+ })), r.push(e.addAction({
945
+ id: "saveScript",
946
+ label: "Save Script",
947
+ keybindings: [t.KeyMod.CtrlCmd | t.KeyCode.KeyS],
948
+ run: (e) => {
949
+ ue();
950
+ }
951
+ })), r.push(e.onMouseDown(async (e) => {
952
+ if (e.target.type === t.editor.MouseTargetType.GUTTER_GLYPH_MARGIN) {
953
+ 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 ue();
955
+ if (!i) return;
956
+ const s = i.getFunctions().getItems(), a = _(n, t, s, o).find((e) => e.lineNumber === r);
957
+ if (a) {
958
+ const t = e.event.browserEvent.button;
959
+ if (0 === t) {
960
+ if ("macro" === a.type || "autoRun" === a.type) de({ functionName: a.name });
961
+ else if ("formula" === a.type) {
962
+ const e = s?.find((e) => e.getName() === a.name);
963
+ e && ne?.execute(e);
964
+ }
965
+ } else 2 === t && (console.log("Context menu for function:", a.name), e.event.browserEvent.preventDefault());
966
+ }
967
+ }
968
+ })), r.push(e.onDidChangeModelContent(() => {
969
+ ae({ dirty: !0 }), ye(n, t, e);
970
+ })), r.push(t.editor.onDidChangeMarkers((e) => {
971
+ e.some((e) => e.toString() === n.uri.toString());
972
+ })), r.push(n.onDidChangeContent((t) => {
973
+ const n = R.getModules().getByName("scripts")?.getSource(), r = e.getValue(), o = (n?.length ?? 0) !== r.length || n !== r;
974
+ ae({ dirty: o });
975
+ })), r.push(e.onDidChangeCursorPosition((e) => {
976
+ he();
977
+ })), () => {
978
+ for (const e of r) try {
979
+ e.dispose();
980
+ } catch {}
981
+ };
982
+ }, [R, te]), Ee = i(() => pe ? null : S || N("div", {
983
+ style: {
984
+ position: "absolute",
985
+ width: "100%",
986
+ height: "100%"
987
+ },
988
+ children: W("scriptEditor.loading")
989
+ }), [pe, S]), Le = i(() => ({
990
+ ...M,
991
+ fixedOverflowWidgets: !1,
992
+ contextmenu: !1,
993
+ readOnly: m
994
+ }), [m]), Me = s(null);
995
+ o(() => {
996
+ const e = {
997
+ theme: x ? "extended-dark" : "extended",
998
+ options: Le,
999
+ value: R?.getModules()?.getByName("scripts")?.getSource() ?? "",
1000
+ beforeMount: X,
1001
+ onValidate: Y
1002
+ }, t = ((e) => {
1003
+ if (H) return H;
1004
+ if (!D) {
1005
+ D = {};
1006
+ const e = O.length;
1007
+ for (let t = 0; t < e; t++) {
1008
+ const e = O[t];
1009
+ D[e] = globalThis[e];
1010
+ }
1011
+ }
1012
+ const t = document.createElement("div");
1013
+ t.style.display = "none";
1014
+ const n = document.createElement("div");
1015
+ 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 = c(n);
1017
+ return H = {
1018
+ root: r,
1019
+ hostEl: n,
1020
+ stashEl: t,
1021
+ props: e,
1022
+ setProps: null
1023
+ }, r.render(N(Q, {})), H;
1024
+ })(e);
1025
+ return t.props = e, t.setProps?.(e), U = (e, t) => Ne(e, t), Me.current?.appendChild(t.hostEl), j && (K = Ne(j.editor, j.monaco)), () => {
1026
+ K?.(), K = null, U = null, G.current = null, H?.stashEl.appendChild(H.hostEl);
1027
+ };
1028
+ }, []), o(() => {
1029
+ if (!H) return;
1030
+ const e = {
1031
+ ...H.props,
1032
+ theme: x ? "extended-dark" : "extended",
1033
+ options: Le
1034
+ };
1035
+ H.props = e, H.setProps?.(e);
1036
+ }, [x, Le]), o(() => {
1037
+ const e = G.current, t = e?.editor;
1038
+ if (!t) return;
1039
+ Z.current = te ?? null;
1040
+ const n = R?.getModules().getItems()[0]?.getSource() ?? "";
1041
+ t.getValue() !== n && (t.setValue(n), ye(t.getModel(), e.monaco, t), ae({ dirty: !1 }));
1042
+ }, [R, te]);
1043
+ const Ie = E("div", {
1044
+ style: {
1045
+ display: "flex",
1046
+ flex: "1 1 100%",
1047
+ width: "100%",
1048
+ flexDirection: "row",
1049
+ position: "relative",
1050
+ boxSizing: "border-box"
1051
+ },
1052
+ children: [N("div", {
1053
+ ref: Me,
1054
+ style: {
1055
+ display: "flex",
1056
+ flex: "1 1 100%",
1057
+ width: "100%",
1058
+ position: "relative"
1059
+ }
1060
+ }), Ee]
1061
+ }), De = b(t, () => ({
1062
+ isScriptEditorElement: () => !0,
1063
+ showCommandPalette: () => {
1064
+ G.current?.editor && G.current.editor.trigger("keyboard", "editor.action.quickCommand", null);
1065
+ },
1066
+ getScripts: () => R,
1067
+ focus: (e) => {
1068
+ ke(e);
1069
+ },
1070
+ close: () => we(),
1071
+ insertSnippet: (e) => G.current?.editor ? (async (e, t, n) => {
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(),
1108
+ saveSource: async () => {
1109
+ await ue();
1110
+ },
1111
+ runAction: (e) => {
1112
+ const t = G.current?.editor;
1113
+ t && (t.focus(), t.trigger("source", e, null));
1114
+ },
1115
+ copy: () => xe(),
1116
+ cut: () => ve(),
1117
+ paste: () => Se()
1118
+ }), [te]), [Te, Oe] = a(null), Ae = y((e) => {
1119
+ null !== e && Oe(e);
1120
+ }, []), Re = f.useCommandScope();
1121
+ return o(() => {
1122
+ if (!Re || !Te) return;
1123
+ const e = Re.contribution();
1124
+ return function(e, t) {
1125
+ const n = t.scriptEditor, r = t;
1126
+ e.updateCommand("scriptingHelp", { callback: () => {
1127
+ window?.open("https://www.sheetxl.com/docs/guides/concepts/scripting");
1128
+ } }), e.updateCommand("showScriptingCommands", { callback: () => {
1129
+ n.showCommandPalette();
1130
+ } }), e.updateCommand("insertScript", { callback: (e) => n.insertSnippet(e ?? "") }), e.updateCommand("saveScripts", {
1131
+ disabledReasons: r?.isDirty ? [] : [g("reason.noChangesToSave")],
1132
+ callback: async () => {
1133
+ await n.saveSource();
1134
+ }
1135
+ }), 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
+ }(e, {
1137
+ scriptEditor: Te,
1138
+ isDirty: J
1139
+ }), () => {
1140
+ e.remove();
1141
+ };
1142
+ }, [
1143
+ Re,
1144
+ Te,
1145
+ J
1146
+ ]), o(() => (L && requestAnimationFrame(() => {
1147
+ De.current?.focus();
1148
+ }), () => {
1149
+ G.current?.editor && requestAnimationFrame(() => {
1150
+ De.current?.contains(document.activeElement) && De.current?.focus();
1151
+ });
1152
+ }), []), N("div", {
1153
+ className: l("script-editor", I, n),
1154
+ style: {
1155
+ display: "flex",
1156
+ flexDirection: "row",
1157
+ flex: "1 1 100%",
1158
+ position: "relative",
1159
+ ...r
1160
+ },
1161
+ ref: u([De, Ae]),
1162
+ ...$,
1163
+ children: Ie
1164
+ });
1165
+ })), te = null, ne = (e) => {
1166
+ te = e;
1167
+ }, re = () => te, oe = r((e) => {
1168
+ const { scope: t, data: n } = e, { workbook: r } = n, i = w(), s = S(), a = s.getOpen(), c = y(async (e) => {
1169
+ if (!r) return;
1170
+ let t = null;
1171
+ const n = r.getScripts();
1172
+ if (e?.declaration || e?.functionName) {
1173
+ const r = e.declaration ? e.declaration.getName() : e.functionName;
1174
+ (await n.searchFunctions({ name: r })).length > 0 && (t = r);
1175
+ }
1176
+ if (t) try {
1177
+ await n.executeMacro(t);
1178
+ } catch (e) {
1179
+ i.showError(e);
1180
+ return;
1181
+ }
1182
+ }, [r, i]), l = y(() => {
1183
+ const e = re();
1184
+ e ? r && e({ workbook: r }) : s.getOpen().includes("scriptEditor") ? s.close("scriptEditor") : s.activate("scriptEditor", {});
1185
+ }, [r, s]), u = a.includes("scriptEditor");
1186
+ return o(() => {
1187
+ if (!t) return;
1188
+ const e = t.contribution();
1189
+ return e.updateCommand("showScriptEditor", {
1190
+ callback: () => {
1191
+ l();
1192
+ },
1193
+ state: u
1194
+ }), e.updateCommand("executeScript", { callback: (e) => c(e ?? {}) }), () => {
1195
+ e.remove();
1196
+ };
1197
+ }, [
1198
+ t,
1199
+ u,
1200
+ r,
1201
+ c,
1202
+ l
1203
+ ]), v(r, { onLoad: () => {
1204
+ r?.getScripts().start();
1205
+ } }), null;
1206
+ });
1207
+ oe.displayName = "WorkbookScriptCommands";
1208
+ var ie = {
1209
+ "reason.noChangesToSave": "No changes to save",
1210
+ "scriptEditor.glyph.autoRun": "Auto Run",
1211
+ "scriptEditor.glyph.formula": "Formula",
1212
+ "scriptEditor.glyph.macro": "Macro",
1213
+ "scriptEditor.loading": "Loading...",
1214
+ "scriptEditor.saving": "Saving Scripts..."
1215
+ }, se = [
1216
+ {
1217
+ sourceId: "groups",
1218
+ catalog: {
1219
+ scope: "ui",
1220
+ label: "Interface",
1221
+ tag: "en",
1222
+ version: 1,
1223
+ commands: {
1224
+ customFunctionOptions: {
1225
+ label: "Custom",
1226
+ description: "Insert a custom function."
1227
+ },
1228
+ scriptEditor: {
1229
+ label: "Script (Typescript)",
1230
+ icon: "ScriptRun"
1231
+ },
1232
+ scriptsOptions: {
1233
+ label: "Macros",
1234
+ description: "Run or manage macros."
1235
+ }
1236
+ }
1237
+ }
1238
+ },
1239
+ {
1240
+ sourceId: "scriptEditor",
1241
+ catalog: {
1242
+ scope: "scriptEditor",
1243
+ label: "Script Editor",
1244
+ tag: "en",
1245
+ version: 1,
1246
+ commands: {
1247
+ scriptingHelp: {
1248
+ label: "Scripting Help",
1249
+ description: "Open Documentation For Scripting.",
1250
+ groupLabels: { scriptsOptions: "Help" },
1251
+ icon: "Help"
1252
+ },
1253
+ showScriptingCommands: {
1254
+ label: "Scripting Command Palette",
1255
+ description: "Show commands for scripting.",
1256
+ groupLabels: { scriptsOptions: "Command Palette" },
1257
+ icon: "Keyboard",
1258
+ shortcut: "F1"
1259
+ },
1260
+ insertScript: {
1261
+ label: "Insert Script",
1262
+ description: "Inserts a script from a set of templates.",
1263
+ icon: "ScriptInsert"
1264
+ },
1265
+ saveScripts: {
1266
+ label: "Save Script",
1267
+ description: "Save the current scripts.",
1268
+ icon: "ScriptSave"
1269
+ }
1270
+ }
1271
+ }
1272
+ },
1273
+ {
1274
+ sourceId: "workbookScript",
1275
+ catalog: {
1276
+ scope: "workbook",
1277
+ label: "Workbook",
1278
+ tag: "en",
1279
+ version: 1,
1280
+ commands: {
1281
+ showScriptEditor: {
1282
+ label: "Scripts",
1283
+ description: "Show the script editor.",
1284
+ groupLabels: { scriptsOptions: "Script Editor…" },
1285
+ icon: "ScriptRun",
1286
+ shortcut: ["alt+F11"]
1287
+ },
1288
+ executeScript: {
1289
+ label: "Run Script",
1290
+ description: "Run the last executed script.",
1291
+ icon: "ScriptRun",
1292
+ shortcut: "F8"
1293
+ }
1294
+ }
1295
+ }
1296
+ }
1297
+ ], { DefaultCommandCatalogService: ae } = f, ce = !1;
1298
+ var le = (e) => {
1299
+ const { model: t, entryKey: n, frame: r, ref: o, ...i } = e;
1300
+ return N(ee, {
1301
+ ref: o,
1302
+ frame: r,
1303
+ scripts: t?.getScripts(),
1304
+ ...i
1305
+ });
1306
+ }, ue = () => {
1307
+ x.registerTaskPane({
1308
+ key: "scriptEditor",
1309
+ getTitle: () => "Script (Typescript)",
1310
+ getIcon: () => "ScriptRun",
1311
+ component: le,
1312
+ keepMounted: !0
1313
+ }, !0), function() {
1314
+ if (ce) return;
1315
+ ce = !0;
1316
+ const e = ae;
1317
+ e.registerFromManifest("@sheetxl/scripting-react", import.meta.url, {
1318
+ messages: ie,
1319
+ catalogs: se
1320
+ }), e.prefetch();
1321
+ }(), f.DefaultCommandRegistry.registerDynamic("workbook", oe);
1322
+ };
1323
+ export { ee as ScriptEditor, ue as ScriptingReactPlugin, oe as WorkbookScriptCommands, re as getScriptEditorOpener, ne as setScriptEditorOpener };